#!/usr/bin
f={'2':'5', '5':'2', '6':'9', '9':'6'}
class mime(str):
    def __init__(self, me):
        if me in f: self.next = f[me]
        else: self.next = me
t = map( mime, raw_input() );ice = raw_input()
skip, kate = {}, []
num = { s: ice.count(s) for s in {}.fromkeys(ice) }
for a in {}.fromkeys(t):
    if a in skip: continue
    if a in num:
        if a.next != a and a.next in num:
            kate.append((num[a]+num[a.next])/(t.count(a)+t.count(a.next)))
        else: kate.append(num[a]/(t.count(a)+t.count(a.next)))
    elif a.next != a and a.next in num:
        kate.append(num[a.next]/(t.count(a) + t.count(a.next)))
    else: print 0; quit()
    skip[a.next] = None
    if kate[-1] == 0: break
print min(kate)


req_arr = [int(x) for x in input().strip()]
arr = [int(x) for x in input().strip()]
required_list = [0]*10
num_list = [0]*10
for i in req_arr:
    if i == 5:
        required_list[2] += 1
    if i == 9:
        required_list[6] += 1
    else:
        required_list[i] += 1

for i in arr:
    if i == 5:
        num_list[2] += 1
    if i == 9:
        num_list[6] += 1
    else:
        num_list[i] += 1
ans = len(arr)
for i, j in enumerate(required_list):
    if j > 0:
        ans = min(ans, int(num_list[i]/j))
print(ans)


s1=input()
s2=input()
n=len(s1)
m=len(s2)
from collections import Counter
c1=Counter(s1)
c2=Counter(s2)
if c1['2'] and c1['5']:
    have=(c2['2']+c2['5'])//2
elif c1['2'] or c1['5']:
    have=c2['2']+c2['5']
if c1['6'] and c1['9']:
    have2=(c2['6']+c2['9'])//2
elif c1['6'] or c1['9']:
    have2=c2['6']+c2['9']
mini=10**9
for i in c1.keys():
    if i not in "2569" and c1[i]:
        mini=min(mini,c2[i]//c1[i])
if c1['2'] or c1['5']:
    mini=min(mini,have)
if c1['6'] or c1['9']:
    mini=min(mini,have2)
print(mini if mini!=10**9 else 0 )


t=raw_input()
n=raw_input()
a=[]
for x in range(0,9):
    if x!=5 and str(x) in t:
        if x==2:
            a.append((n.count("2")+n.count("5"))/(t.count("2")+t.count("5")))
        elif x==6:
            a.append((n.count("6")+n.count("9"))/(t.count("6")+t.count("9")))
        else:
            a.append(n.count(str(x))/t.count(str(x)))

print sorted(a)[0]


a = [(x[0], int(x[1]), int(x[2])) for x in [raw_input().split() for i in xrange(input())]]
def cal(x, y):
    a, b = 0, 0
    for i in xrange(4):
        if x[i] == y[i]: a += 1
        else:
            for j in xrange(4):
                if i != j and x[i] == y[j]:
                    b += 1
                    break
    return (a, b)
def check(x):
    bit = ''
    while x:
        bit += chr(ord('0') + x % 10)
        x /= 10
    while len(bit) != 4: bit += '0'
    for item in a:
        if cal(item[0], bit[::-1]) != (item[1], item[2]): return False
    return True
ans = filter(check, range(1, 10000))
if not ans: print 'Incorrect data'
elif len(ans) > 1: print 'Need more data'
else: print ans[0]


def is_sat(candi, cont):
    candi_match = cont[0]
    _bcount = int(cont[1])
    _ccount = int(cont[2])
    bcount = 0
    ccount = 0
    for i in xrange(4):
        if candi_match[i] == candi[i]:
            bcount += 1
        elif candi_match[i] in candi:
            ccount += 1
    return (_bcount == bcount and _ccount == ccount)

constraints = []

N = int(raw_input())
while N>0:
    constraints.append([x for x in raw_input().split()])
    N-=1
satisfies = []
for i in xrange(0,10000):
    candi = str(i).rjust(4,'0')
    satcount = 0
    for cont in constraints:
        if is_sat(candi, cont):
            satcount+=1
    if satcount == len(constraints):
        satisfies.append(candi)

goo = len(satisfies)
if goo  == 1:
    valid = True
    for i in xrange(4):
        for j in xrange(4):
            if i!=j:
                if satisfies[i]==satisfies[j]:
                    valid=False
                    break
    if valid:
        print satisfies[0]
    else:
        print "Incorrect data"
elif goo == 0:
    print "Incorrect data"
else:
    print "Need more data"


a = [(x[0], int(x[1]), int(x[2])) for x in [raw_input().split() for i in xrange(input())]]
def cal(x, y):
    a, b = 0, 0
    for i in xrange(4):
        if x[i] == y[i]: a += 1
        else:
            for j in xrange(4):
                if i != j and x[i] == y[j]:
                    b += 1
                    break
    return (a, b)
def check(x):
    bit = ''
    while x:
        bit += chr(ord('0') + x % 10)
        x /= 10
    while len(bit) != 4: bit += '0'
    if len(set(bit)) != 4: return
    for item in a:
        if cal(item[0], bit[::-1]) != (item[1], item[2]): return
    ans.append(bit)
for i in xrange(1, 10000):
    check(i)
if not ans: print 'Incorrect data'
elif len(ans) > 1: print 'Need more data'
else: print ans[0]


from itertools import *

n = int(raw_input())
a = [map(int, raw_input().split()) for _ in xrange(n)]

def check(s):
    for u,v,w in a:
        u = str(u)
        x, y = len( set(s)&set(u) ), 0
        for i in xrange(4):
            if s[i]==u[i]:
                y += 1
        if x-y!=w or y!=v:
            return 0
    return 1

ans, cnt = "", 0
for s in permutations("0123456789", 4):
    if check("".join(s)):
        ans = "".join(s)
        cnt += 1
if cnt == 1:
    print ans
elif cnt == 0:
    print "Incorrect data"
else:
    print "Need more data"


n = input()
d = {}
a = []

def digits (n):
    rs = []
    p2 = 0
    for i in range(4):
        rs.append(n%10)
        n/=10
    return set(rs),rs

for i in range(10000):
    l,ll = digits(i)
    if len(l)<4: continue
    a.append(i)
    d[i]=(l,ll)

def oc(k,x,b,c):
    kl,kll=d[k]
    xl,xll=d[x]
    nb = sum(int(x==y) for x,y in zip(kll,xll))
    if nb!=b: return False
    nc = sum(int(x in kl) for x in xl)-nb
    return nc==c

for i in range(n):
    k,b,c = map(int,raw_input().split())
    a = filter(lambda x:oc(k,x,b,c),a)

if not a: print "Incorrect data"
elif len(a)==1: print a[0]
else: print "Need more data"


from itertools import combinations

def findsum(comb):
    sum = 0
    for song in comb:
        sum += song[0]
    return sum

def finda(a,b,c):
    if a == 0:
        return 0
    if a == 1 and b == 0 and c == 0:
        return 1
    else:
        return (a * findb(a-1,b,c)+ a*findc(a-1,b,c))

def findb(a,b,c):
    if b == 0:
        return 0
    if b == 1 and a == 0 and c == 0:
        return 1
    else:
        return (b * finda(a,b-1,c)+ b*findc(a,b-1,c))

def findc(a,b,c):
    if c == 0:
        return 0
    if c == 1 and a == 0 and b == 0:
        return 1
    else:
        return (c * finda(a,b,c-1)+ c*findb(a,b,c-1))

n, T = map(int,input().split())
songs = []
total_combinations = 0
for i in range(n):
    t, g = map(int,input().split())
    songs.append([t,g])

for i in range(1, n+1):
    allcomb = list(combinations(songs,i))
    for comb in allcomb:
        sum = findsum(comb)

        if sum == T:
            a = 0
            b = 0
            c = 0
            for song in comb:
                if song[1] == 1:
                    a += 1
                elif song[1] == 2:
                    b += 1
                else:
                    c += 1
            total_combinations += finda(a,b,c)+findb(a,b,c)+findc(a,b,c)
total_combinations = total_combinations%1e7
print(total_combinations)


fac = [1]
for i in range(1,16):
    fac.append(i*fac[-1])
DP = {(0,0,0):1}
def combs(a,b,c):
    x,z = min(a,b,c),max(a,b,c)
    y = a+b+c-x-z
    hs = (x,y,z)
    if x+y+1<z or x < 0:
        DP[hs] = 0
        return 0
    if hs in DP: return DP[hs]
    DP[hs] = combs(x-1,y,z)+combs(x,y-1,z)+combs(x,y,z-1)
    return DP[hs]
def s(i):
    sm = 0
    for j in range(N):
        if i & (1<<j): sm += songs[j][0]
    return sm == T
def calc(i):
    a = [0,0,0]
    for j in range(N):
        if i & (1<<j): a[songs[j][1]-1] += 1
    return fac[a[0]]*fac[a[1]]*fac[a[2]]*combs(a[0],a[1],a[2])
N,T  = map(int,raw_input().split())
songs = [tuple(map(int,raw_input().split())) for _ in range(N)]
out = 0
for i in range(2**N):
    if s(i):
        out += calc(i)
print (out%(10**9+7))


from itertools import combinations
def out1(a,b,c):
    if a<0 or b<0 or c<0:
        return 0
    if a==0 and b==0 and c==0:
        return 1
    return a*(out2(a-1,b,c)+out3(a-1,b,c))
def out2(a,b,c):
    if a<0 or b<0 or c<0:
        return 0
    if a==0 and b==0 and c==0:
        return 1
    return b*(out1(a,b-1,c)+out3(a,b-1,c))
def out3(a,b,c):
    if a<0 or b<0 or c<0:
        return 0
    if a==0 and b==0 and c==0:
        return 1
    return c*(out2(a,b,c-1)+out1(a,b,c-1))
def column(matrix, i):
    return [row[i] for row in matrix]

N, T = [int(x) for x in input().split()]
A = []
s = 0
for i in range(N):
    A.append([int(x) for x in input().split()])
for i in range(1,N+1):
    comb = list(combinations(A, i))
    for x in comb:
        if sum(column(x,0))==T:
            a = column(x,1).count(1)
            b = column(x,1).count(2)
            c = column(x,1).count(3)
            s+=(out1(a,b,c)+out2(a,b,c)+out3(a,b,c))
print(s//2)


from copy import *
n,T=map(int,raw_input().split())
cl=set(())
di={(0,0,0,T):1}
for k in range(n):
    t,g=map(int,raw_input().split())
    an=deepcopy(di)
    for k in an:
        nc=list(k)
        nc[3]-=t
        nc[g-1]+=1
        if nc[3]>=0:
            nc=tuple(nc)
            if nc in di:
                di[nc] += an[k]
            else:
                di[nc] = an[k]
nd={(1,0,0,0):1,(0,1,0,1):1,(0,0,1,2):1}
def nb(tu):
    #print(tu)
    if not(tu in nd):
        if tu[tu[3]]==0:
            nd[tu] =0
        else:
            nt=list(tu)
            nt[tu[3]]-=1
            nt[3]=(nt[3]+1)%3
            nt2=nt[:]
            nt2[3]=(nt2[3]+1)%3
            nd[tu]=tu[tu[3]]*(nb(tuple(nt))+nb(tuple(nt2)))
    return nd[tu]

#print([(di[k],k[:3]) for k in di if k[3]==0])
print(sum(di[k]*(nb(k[:3]+(1,))+nb(k[:3]+(0,))+nb(k[:3]+(2,))) for k in di if k[3]==0))
#print(nd)


#  author: ThePonyCoder
#  created: 24.06.2019, 10:58
#  filename: g1.py
#  path: E:/Projects/CodeForces/rounds/cf_568/g1.py

import os

# import random

# sys.setrecursionlimit(999999999)
import string

from math import inf
from functools import lru_cache

if os.getcwd() == 'C:\\Users\\User\\Desktop\\python\\Prog\\CodeForces' \
        or os.environ['COMPUTERNAME'] == 'RYZEN':
    import pdb

    import sys

    pdb = pdb.Pdb(stdin=sys.stdin, stdout=sys.stdout)
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
    from pprint import pprint
    from hypothesis import given, settings
    from hypothesis import strategies as st

def ri():
    return [int(i) for i in input().split()]

def main():
    n, t = ri()
    songs = []
    result = 0
    for i in range(n):
        songs.append(ri())  # [время, жанр]
        songs[-1][1] -= 1

    dp = [[0, 0, 0] for i in range(1 << n)]

    for ind, it in enumerate(songs):
        dp[1 << ind][it[1]] = 1

    for mask in range(1,1 << n):
        for genre in range(3):
            for nsng, sng in enumerate(songs):
                if sng[1] != genre and ((mask >> nsng) & 1) == 0 :
                    dp[mask | (1 << nsng)][sng[1]] += dp[mask][genre]
                    # if (mask | (1 << nsng)) == 7:
                    #     asdddd = 1

            sm = 0
            for ind, it in enumerate(bin(mask)[2:]):
                if it == '1':
                    sm += songs[ind][0]
            if sm == t:
                result += dp[mask][genre]

    print(result)

main()


def main():

    N = 505

    C = []
    for i in range(N):
        C.append([])
        for j in range(N):
            C[i].append(0)

    for i in range(N):
        C[i][i] = 1
    for i in range(N):
        C[i][0] = 1

    for i in range(2, N):
        for k in range(1, i):
            C[i][k] = C[i - 1][k - 1] + C[i - 1][k]

    n = int(input())
    print(C[n + 4][5] * C[n + 2][3])

main()


x1,y1,x2,y2 = map(int,input().split())

ret = 0
for y in range(y1,y2+1):
	if y%2 == 0:
		t = x1
		if x1%2 == 1:
			t += 1
		for x in range(t,x2+1,2):
			ret +=1
	else:
		t = x1
		if x1%2 == 0:
			t += 1
		for x in range(t,x2+1,2):
			ret += 1
print(ret)


import sys,math,heapq,copy
from collections import defaultdict,deque
from bisect import bisect_left,bisect_right
from functools import cmp_to_key
from itertools import permutations,combinations,combinations_with_replacement
# sys.setrecursionlimit(10**6)
# sys.stdin=open('Input.txt','r')
# sys.stdout=open('Output.txt','w')
mod=1000000007
# Reading Single Input
def get_int(): return int(sys.stdin.readline().strip())
def get_str(): return sys.stdin.readline().strip()
def get_float(): return float(sys.stdin.readline().strip())
# Reading Multiple Inputs
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_strs(): return map(str, sys.stdin.readline().strip().split())
def get_floats(): return map(float, sys.stdin.readline().strip().split())
# Reading List Of Inputs
def list_ints(): return list(map(int, sys.stdin.readline().strip().split()))
def list_strs(): return list(map(str, sys.stdin.readline().strip().split()))
def list_floats(): return list(map(float, sys.stdin.readline().strip().split()))
# ------------------------------------------------------------------------------------- #

n,k=get_ints()
print(pow(k,k-1)*pow(n-k,n-k))


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const int mod = 1000000007;

int pow_mod(int a, int b) {
    long long r = 1;
    long long p = a;
    while (b) {
        if (b & 1) {
            r = 1LL * r * p % mod;
        }
        p = 1LL * p * p % mod;
        b >>= 1;
    }

    return r;
}

int main() {
    int n,k;
    scanf("%d %d", &n, &k);
    printf("%d\n", pow_mod(k, k - 1) * pow_mod(n - k, n - k) % mod);

    return 0;
}


text = input()
n, k = map(int ,text.split(" "))
d = n//(2*(k+1))
c = k*d
nw = n - c - d
print("%d %d %d"%(d, c , nw))


n=int(input())
k=int(input())
for i in range(int(n/2),-1,-1):
    if i%(k+1)==0:
        d=i/(k+1)
        c=i-d
        if (d>=0 and c>=0):
            print(int(d),int(c),int(n-d-c))
            break


import  math
z , k = map(int , input().split())
tmp = z
for i in range(z // 2 , 0 , -1):
    x = i // (k + 1)
    y = i- x
    if y / x == k:
        print(x , y , tmp - (x + y))
        break

else:
    print(0 , 0 , tmp)


 = input()
k = input()

x = a/(2*k+2)
y = k*x
z = a - x - y

print x, " ", y, " ", z


def LessInTable(n, m, x, k):
    t = x-1
    summ = int(t/m)*m
    summ1 = int(t/m)*(m-n)
    #print (t/m+1, n+1)
    #return sum([t/i for i in xrange(t/m+1,n+1)]) + summ
    v = min(int(t**0.5), n)
        #for i in xrange(t/m+1,t/n+1):
        #summ1 += t/i - n
    tn = (t-1)/n;
    tm = t/m;
    vv = [t/i for i in xrange(tm+1,v+1)]
    add = - v**2 + max(min((tn - tm),len(vv))*n,0);
    summ = summ + sum(vv)
    summ1 = summ1 + sum(vv[0:max(min(tn-tm, len(vv)),0)])
        #for i in xrange(t/m+1,v+1):
        #minimum = t/i
    #if i < tn:
    #summ1 += minimum
        #summ += minimum
        #if minimum == 0 or 2 * summ + add - summ1 > k:
            #return k+1
            #print (summ, add, summ1, x, summ * 2 + add - summ1)
    return summ * 2 + add - summ1

[n, m, k] = raw_input("").split(" ")
[n, m, k] = [int(n), int(m), int(k)]
[n,m] = [min(n,m), max(n,m)]
a = 1
b = k+1
while (b-a>1):
    cur = (a+b)/2
    summ = LessInTable(n,m,cur,k)
    #print (summ, cur)
    if summ < k:
        a = cur
    else:
        b = cur
#if LessInTable(n,m,b,k) < k:
#    print b
#else:
print a


def main():
    from math import sqrt
    m, n, k = map(int, input().split())
    if n < m:
        n, m = m, n
    lo, hi = 1, k + 1
    while lo + 1 < hi:
        mid = (lo + hi) // 2
        t = mid - 1
        v = min(int(sqrt(t)), m)
        tn, tm = (t - 1) // m, t // n
        vv = [t // i for i in range(tm + 1, v + 1)]
        if t // n * (n + m) + sum(vv) * 2 + max(min((tn - tm), len(vv)) * m, 0) - v * v - sum(
                vv[:max(min(tn - tm, len(vv)), 0)]) < k:
            lo = mid
        else:
            hi = mid
    print(lo)

if __name__ == '__main__':
    main()


def main():
    n, m, k = map(int, input().split())
    if n < m:
        n, m = m, n
    if m == 1:
        print(k)
        return
    lo, hi = 2, min(n * m, (k + 1) ** 2 // 2) + 1
    while lo < hi:
        a = (lo + hi) // 2
        u = sum(a // i for i in range(a // n + 1, (m if m < a else a) + 1)) + a // n * n
        if u < k:
            lo = a + 1
        elif u > k:
            hi = a
        else:
            lo = hi = a
    res = [hi // i * i for i in range(hi // n + 1, (m if m < hi else hi) + 1)] + [n] * (a // n)
    res.sort(reverse=True)
    print(res[u - k])

if __name__ == '__main__':
    main()


[n, m, k] = raw_input("").split(" ")
[n, m, k] = [int(n), int(m), int(k)]

a = [0 for i in range(0, n*m)]

for i in range(0, n):
    for j in range(m):
        a[i+n*j] = (i+1)*(j+1)
a.sort()
print a[k-1]


x = int(input())
for i in range(100):
    if (i % 2 == 1):
        if ((i * i + 1) // 2 >= x):
            print(i)
            break


x = int(input())
arr = []
for i in range(1, 300, 2):
    arr.append((i//2) * (i // 2) + (i //2+ 1) + (i // 2 + 1))
counter = 0
ind = 1
while arr[counter] >= x:
    counter+=1
    ind += 2
counter-=1
ind -=2
if (x == 3) print(5)
else:
print(ind)


x=input()
if x==3:
    print 5
else if x==2:
    print 3
else:
    for i in range(12345):
        if i&1 and (i>>1)*i+(i+1)/2>=x or i%2==0 and (i>>1)*i>=x:
            print i
            break


x = int(input())
arr = []
for i in range(1, 300, 2):
    arr.append((i//2) * (i // 2) + (i //2+ 1) + (i // 2 + 1))
counter = 0
ind = 1
while arr[counter] >= x:
    counter+=1
    ind += 2
counter-=1
ind -=2
if (x == 3): print(5)
else:
print(ind)


import sys

x = int(sys.stdin.readline())

if x % 2 == 1:
    x -= 1

if x == 2:
    print 5
    sys.exit(0)

for i in xrange(1,1111,2):
    can = i / 2 + 1
    can /= 2
    g = i / 2 - can
    can *= can
    can += g*g
    can *= 4
    can += i / 4 * 2 * 2
    if can >= x:
        print i
        sys.exit(0)


n, a, b, c = [int(i) for i in raw_input().split()]
set_ = set()

def findWays(n, a, b, c):
	if (n < 0):
		return 0
	if (n == 0):
		t = a*100 + b*10 + c
		if t not in set_:
			set_.add(a*100 + b*10 + c)
			return 1
	ways = 0
	if (a > 0):
		ways += findWays(n - 0.5, a - 1, b, c)
	if (b > 0):
		ways += findWays(n - 1, a, b - 1, c)
	if (c > 0):
		ways += findWays(n - 2, a, b, c - 1)
	return ways

print(findWays(n, a, b, c))


n,a,b,c = map(int,raw_input().split())
r = 0
for i in xrange(a+1):
	if i*0.5>n:
		break
	for j in xrange(b+1):
		if i*0.5+j<=n and (n-i*0.5-j)%2==0 and (n-i*0.5-j)/2<=c:
			r+=1
		if i*0.5+j>n:
			break
print r


n, a, b, c = map(int, input().split())
print(sum(n - i // 2 - 2 * j in range(0, b + 1) for i in range(0, a + 1, 2) for j in range(c + 1)))


n, a, b, c = map(int, raw_input().split())
print sum(n - i // 2 - 2 * j in xrange(0, b + 1) for i in xrange(0, a + 1, 2) for j in xrange(c + 1))


n = int(input())
ans = 0
_pow = 2

while 2 * n > _pow:
    ans += (_pow //2 )* (n // _pow + (1 if _pow > n > _pow // 2 else 0))
    _pow *= 2

print(ans)


 from math import log
n=input()
b=bin(n)[2:]
if n==2:
    print 1
elif n==3:
    print 3
else:
    n-=1
    b=bin(n)[2:]
    l=len(b)
    ans=0
    for i in range(1,l):
        val=0
        pre=pow(2,i-1)
        if i==1:
            ans+=1
            continue
        for j in range(i-1):
            val+=(pow(2,j)*pre)/2
            pre/=2
        ans+=val

    #print ans

    if pow(2,int(log(n)/log(2)))==n:
        print ans+ pow(2,int(log(n)/log(2))+1)-2
    else:
        #print b
        for i in range(l-1):
            ans+=pow(2,l-i-1)
        for i in range(1,l):
            if b[i]=='1':
                val=0
                pre=pow(2,l-i-1)
                for j in range(l-i-1):
                    val+=(pow(2,j)*pre)/2
                    pre/=2
                ans+=val
                ans+=pow(2,l-i-1)
        print ans


a=0;n=int(input())-1
for i in range 40:
	k=1<<i;a+=(n+k)//(k*2)*k
print(a)


import queue
n = int(input().strip())

graph = [[0]*n for _ in range(n)]
for i in range(n-1):
    j = i + 1
    while j < n:
        graph[i][j] = i ^ j
        graph[j][i] = j ^ i
        j += 1
INF = 10**9
pq = queue.PriorityQueue()
pq.put(0)
dist = [INF]*n
dist[0] = 0
visited = [False]*n
while not pq.empty():
    top = pq.get()
    visited[top] = True
    for neighbor_index in range(len(graph[top])):
        if not visited[neighbor_index] and graph[top][neighbor_index] < dist[neighbor_index]:
            dist[neighbor_index] = graph[top][neighbor_index]
            pq.put(neighbor_index)
res = 0
for d in dist:
    res += d
print(res)


(n, m, min, max) = map(int, input().split())

temps = [int(input()) for i in range(0,m)]

if(n - m >= 2 or n - m is 0):
    print("Correct")
else:
    hasMin = False
    hasMax = False
    temps.sort()
    if(temps[0] <= min):
        hasMin = True
    if(temps[m - 1] >= max):
        hasMax = True

    if(hasMin and hasMax):
        print("Correct")
    elif((hasMin or hasMax) and n-m is 1):
        print("Correct")
    else:
        print("Incorrect")


from math import *
from collections import deque
from copy import deepcopy
import sys
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def multi(): return map(int,input().split())
def strmulti(): return map(str, inp().split())
def lis(): return list(map(int, inp().split()))
def lcm(a,b): return (a*b)//gcd(a,b)
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def stringlis(): return list(map(str, inp().split()))
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def printlist(a) :
    print(' '.join(str(a[i]) for i in range(len(a))))

def isPrime(n) :
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#copied functions end

#start coding

n,ba=multi()
a=lis()
astr=''
# for i in a:
#     astr+=i
nb,bb=multi()
b=lis()
num=0
num1=0
for i in range(1,n+1):
    num+=(a[-i]*ba**(i-1))

for i in range(1,nb+1):
    num1+=b[-i]*bb**(i-1)

bstr=''
# for i in b:
#     bstr+=i

#
# print(int(astr,ba))
# print(int(bstr,bb))
# print(num,num1)
if(num==num1):
    print("=")
elif(num>num1):
    print(">")
else:
    print("<")


n, m, l, r = map(int , input().split())
a = list(map(int , input().split()))
if max(x) > r or  min(a) < l:
    print("Incorrect")
elif n - m >= 2 :
    print("Correct")
else:
    if l not in a and r not in a and l != r:
        print("Incorrect")
    else:
        print("Correct")


n, m, m1, m2 = map(int, raw_input().split())
a = map(int, raw_input())
s = "Correct"
if n==2:
    if (a[0]!=m1 and a[0]!=m2) : s = "Incorrect"
for i in a:
    if (i<m1) or (i>m2): s = "Incorrect"
print s


n, m, l, r = map(int , input().split())
a = list(map(int , input().split()))
if max(x) > r or  min(a) < l:
    print("Incorrect")
elif n - m >= 2 :
    print("Correct")
elif:
    if l not in a and r not in a and l != r:
        print("Incorrect")
    else:
        print("Correct")


n,m,k = [int(r) for r in raw_input().split()]

direction = raw_input()
if direction == "to head":
    direction = -1
else:
    direction = 1

mmts = raw_input()

## Stowaway is m, controller k
def calc(time, s, c, d):
    if time >= len(mmts) - 1:
        return -1
    if c == n:
        d = -1
    if c == 1:
        d = 1
    c = c + d
    if mmts[time] == '0':
        ## Moving
        if d == 1:
            if s >= c:
                s = s + 1
            else:
                s = s-1
        else:
            if s > c:
                s = s + 1
            else:
                s = s - 1
        if s > n:
            s = n
        if s < 1:
            s = 1
        if c == s:
            time += 1
            return time
        time += 1
        return calc(time, s, c, d)
    else:
        if c == 1:
            s = n
        elif c == n:
            s = 1
        elif d == 1:
            s = 1
        else:
            s = n
        if c == s:
            time += 1
            return time
        time += 1
        return calc(time, s, c, d)

l = calc(0, m, k, direction)
if l == -1:
    print "Stowaway"
else:
    print "Controller " + str(l)


# -*- coding: UTF-8 -*-

# from itertools import *
# from collections import defaultdict

# def gcd(a,b):
#     while b > 0: a,b = b, a%b
#     return a

# def baseN(num,b,numerals="0123456789abcdefghijklmnopqrstuvwxyz"):
#     return ((num == 0) and  "0" ) or ( baseN(num // b, b).lstrip("0") + numerals[num % b])

# T = input()
# St = raw_input()

vags, pos, cont = map(int, raw_input().split())
where = raw_input()
if where == "to tail":
    where = 1
else:
    where = -1

def make_move(pos, where):
    pos = pos + where
    if pos > vags:
        pos = vags-1;
        where = -1
    if pos < 1:
        pos = 2
        where = 1
    return pos, where

stop = raw_input()
for i in xrange(len(stop)):
    if stop[i] == "1":
        cont, where = make_move(cont, where)
        if where == 1:
            pos = 1
        else:
            pos = vags
    else:
        if where == 1:
            if pos>cont:
                if pos != vags:
                    pos += 1
            else:
                if pos != 1:
                    pos -= 1
        else:
            if pos<cont:
                if pos != 1:
                    pos -= 1
            else:
                if pos != vags:
                    pos += 1
        cont, where = make_move(cont, where)
    if pos == cont:
        print "Controller ", i+1
        exit()
print "Stowaway"


import sys

n,m,k = map(int,raw_input().split())
d_s = raw_input()
d = 0
if d_s=="to head":d=-1
else:d=1
m -= 1
k -= 1

s = raw_input()
l = len(s)

for i in xrange(l-1):
    ch = s[i]
    if ch=='0':
        if k<m and m<n-1: m+=1
        elif k>m and m>0: m-=1
        k += d
        if k==0 or k==n-1: d=-d
        if k==m:
            print "Controller",i+1
            sys.exit()
    elif ch=='1':
        if d==1 or k==0: m=0
        else: m=n-1
        k += d
        if k==0 or k==n-1: d=-d

print "Stowaway"


from sys import stdin, stdout, exit

n, m, k = map(int, stdin.readline().split())
d = 1 if stdin.readline()[6] == 'l' else -1
m = 1 if m < k else n

for i, c in enumerate(stdin.readline(), 1):
    if c == '0':
        if k == 1: k, d = 2, 1
        elif k == n: k, d = n - 1, -1
        else: k += d
        if m == k:
            stdout.write('Controller ' + str(i))
            exit(0)
    else:
        if k == 1: k, d, m = 2, 1, 1
        elif k == n: k, d, m = n - 1, -1, n
        elif d == 1:
            k += 1
            m = 1
        else:
            k -= 1
            m = n

stdout.write('Stowaway')


import copy
debug = True
debug = False
cop = copy.deepcopy
f1 = open('input.txt','rU')
def readin():
	global debug
	if debug:
		return f1.readline()[0:-1]
	else:
		return raw_input()
(n, m, k) = [int(i) for i in readin().split()]
d = readin()
if d == 'to head':
	d = -1
else:
	d = 1
tr = [int(i) for i in readin()]

class State1:
	def __init__(self,t = 0,p = 0):
		self.t = t
		self.p = p
	def go(self,newp):
		self.t += 1
		if newp < 1:
			newp = 1
		elif newp > n:
			newp = n
		self.p = newp

class State2:
	def __init__(self,t = 0, p = 0, v = 0):
		self.t = t
		self.p = p
		self.v = v
	def go(self):
		self.t += 1
		self.p += self.v
		if self.p == n:
			self.v *= -1
		elif self.p == 1:
			self.v *= -1

p1 = State1(0, m)
p2 = State2(0, k, d)

def draw(p1, p2):
	global debug
	if not debug: return
	for i in range(1,n+1):
		if p1.p == i:
			c = 1
		elif p2.p == i:
			c = 2
		else:
			c = 0
		print c,'  ',
	print ''

end = False
t = 0
t0 = len(tr)
draw(p1,p2) # for debug
while (not end) and t < t0:
	t += 1
	# if the train is running
	if tr[t-1] == 0:
		if p1.p < p2.p:
			p1.go(p1.p-1)
		else:
			p1.go(p1.p+1)
	else: # the train is idle
		if p2.v == -1: # p2 go left
			p2t = cop(p2)
			p2t.go()
			if p2t.p == n:
				p1.go(1)
			else:
				p1.go(n)
		else:
			p2t = cop(p2)
			p2t.go()
			if p2t.p == 1:
				p1.go(n)
			else:
				p1.go(1)
	if tr[t-1] == 0 and p1.p == p2.p:
		end = True
	p2.go()
	draw(p1,p2) # for debug
	if p1.p == p2.p:
		end = True

if end:
	print 'Controller',t
else:
	print 'Stowaway'


seq = []
for x in range(11): seq.append(int(input()))

p = 0
while seq:
    c = seq[-1]
    del seq[-1]

    r = abs(c)**0.5 + c**3 * 5
    if r < 400:
        print("f(%d) = %.2f" % (c, r))
    else:
        print("f(%d) = MAGNA NIMIS!" % c)


s = [int(input()) for i in range(11)].reverse()
for x in s:
    r = abs(x) ** 0.5 + 5 * x ** 3
    if r > 400:
        print('f(%d) = %s' % (x, "MAGNA NIMIS!"))
    else:
        print('f(%d) = %.2f' % (x, r), end='')


import math

def f(t):
    return math.sqrt(abs(t)) + 5 * t ** 3

a = [float(input()) for _ in range(11)]
for i, t in reversed(list(enumerate(a))):
    y = f(t)
    if y > 400:
        print('f(' + i + ') = MAGNA NIMIS!')
    else:
        print('f(' + i + ') =', '{:.2f}'.format(y))


from math
arr = [0 for _ in range(11)]
for i in range(11):
    arr[10-i] = int(input())
for i in arr:
    tmp = math.sqrt(abs(i)) + (i**3)*5
    if tmp >= 400:
        print("f({}) = MAGNA NIMIS!".format(i))
    else:
        print("f({}) = {:.2f}".format(i,round(tmp,2)))


import math

def f(t):
    return math.sqrt(abs(t)) + 5 * t ** 3

a = [float(input()) for _ in range(11)]
for i, t in reversed(list(enumerate(a))):
    y = f(t)
    if y > 400:
        print(f'f({i}) = MAGNA NIMIS!')
    else:
        print(f'f({i}) =', '{:.2f}.format(y))


R=lambda:map(int,raw_input().split())
n,m=R()
a=R()
b=[-1e20]+R()+[1e20]
i=0
t=0
for x in a:
  while b[i+1]<=x:
    i+=1
  t=max(t,min(x-b[i],b[i+1]-x))
print t
<PYTHON 2.7.10>

road to post office
----------------
d, k, a, b, t = map(int, input().split())
t1 = d * b
t2 = d * a + ((d - 1) // k) * t
t3 = max(0, d - k) * b + min(k, d) * a
dd = d % k
d1 = d - dd
t4 = d1 * a + max(0, (d1 // k - 1) * t) + dd * b
print(min([t1, t2, t3, t4])


d, k, a, b, t = map(int, input().split())
cnt = d // k
print(k * cnt * a + (cnt - 1)  * t + min(t + (d % k) * a, (d % k) * b))


lst=map(int, raw_input().split())
d = lst[0]; k = lst[1]; a = lst[2]; b = lst[3]; t = lst[4]

stop = d / k
auto_len = d
walk_len = 0
min_time = auto_len * a + stop * t + walk_len * b

while stop:
	auto_len = k * stop
	walk_len = d - auto_len
	stop -= 1
	min_time1 = auto_len * a + stop * t + walk_len * b
	if min_time1 > min_time:
		break
	min_time = min_time1

print min_time


MAX = 10**6;
is_prime = [True for i in xrange(MAX)];
ctr = 0;
P = [0 for i in xrange(78498)];
for p in xrange(2,MAX):
	if is_prime[p]:
		P[ctr] = p;
		ctr += 1;
		for i in xrange(p*p,MAX,p):
			is_prime[i] = False;

cnt = 0;
sp = [0 for i in xrange(11297 + 1)];

for p in P:
	if str(p) != str(p)[::-1] and is_prime[int(str(p)[::-1])]:
		cnt += 1;
		sp[cnt] = p;

#print cnt;
print sp[int(raw_input())];


def primes(n):
    sieve = [1 for i in range(1,n)]
    for i in range(2,len(sieve)):
        if(sieve[i]):
            j = i*i
            while j < len(sieve):
                sieve[j] = 0
                j += i
    p = { i for i in range(2,len(sieve)) if sieve[i] }
    return p

p = primes(100000)

def isEmp(t):
    tt= str(t)
    ss = tt[::-1]
    s = int(ss)
    if s!=t and s in p and t in p:
        return True;
    return False;

def Emps():
    return [i for i in p if isEmp(i)]

emps = Emps()
emps.sort()
nn = raw_input()
n = int(nn)-1

print emps[n]


from math import *

n=input()
m = 120000
x=[]
for i in range(m):
    x.append(True)

for i in range(2,int(sqrt(m))):
    if x[i]:
        for k in range(2*i, m, i):

            x[k] = False

x[0] = False
x[1] = False

y=[]
for i in range(m):
    r = int(str(i)[::-1])
    if x[i] and r < m and x[r] and r!=i:
        y.append(i)

print y[n-1]


def prime(x) :
    if x == 2 : return 1
    if ~ x & 1 : return 0
    i = 3
    while i * i <= x :
        if x % i == 0 : return 0
        i += 1
    return 1
n = int(input())
cnt = 0
for i in range (2, int(1e9), 1) :
    if not prime(i) : continue
    if i == int(str)(i)[::-1]) : continue
    if not prime(int(str(i)[::-1])) : continue
    cnt += 1
    if cnt == n : exit(print(i))


p1,p2,p3,p4,a,b=map(int,raw_input().split())
ans=0
for no in xrange(a,b+1):
	if no<p1 && no<p2 && no<p3 && no<p4:
		ans+=1
print ans


     zqz050928
洛谷 / 题目列表 / 题目详情
CF68A Irrational problem
Luogu
应用
题库
训练
比赛
记录
讨论
388
通过
607
提交
题目来源 CodeForces 68A
评测方式 RemoteJudge
标签
难度 入门难度
时空限制 2000ms / 256MB
 提交   题解
提示：收藏到任务计划后，可在首页查看。
体验新版界面

最新讨论 显示
推荐的相关题目 显示
题意翻译
输入p1、p2、p3、p4，输入a和b，求在[a,b]这个区间内有多少个数%p1、%p2、%p3、%p4后还是它本身

Translated by @夜刀神十香ღ

题目描述
Little Petya was given this problem for homework:

You are given function  (here represents the operation of taking the remainder). His task is to count the number of integers x x in range [a;b] [a;b] with property f(x)=x f(x)=x .

It is a pity that Petya forgot the order in which the remainders should be taken and wrote down only 4 numbers. Each of 24 possible orders of taking the remainder has equal probability of being chosen. For example, if Petya has numbers 1, 2, 3, 4 then he can take remainders in that order or first take remainder modulo 4, then modulo 2, 3, 1. There also are 22 other permutations of these numbers that represent orders in which remainder can be taken. In this problem 4 numbers wrote down by Petya will be pairwise distinct.

Now it is impossible for Petya to complete the task given by teacher but just for fun he decided to find the number of integers  with property that probability that f(x)=x f(x)=x is not less than $ 31.4159265352718281828459045% $ . In other words, Petya will pick up the number x x if there exist at least 7 7 permutations of numbers p_{1},p_{2},p_{3},p_{4} p
1
	 ,p
2
	 ,p
3
	 ,p
4
	  , for which f(x)=x f(x)=x .

输入输出格式
输入格式：
First line of the input will contain 6 integers, separated by spaces: p_{1},p_{2},p_{3},p_{4},a,b p
1
	 ,p
2
	 ,p
3
	 ,p
4
	 ,a,b ( 1<=p_{1},p_{2},p_{3},p_{4}<=1000,0<=a<=b<=31415 1<=p
1
	 ,p
2
	 ,p
3
	 ,p
4
	 <=1000,0<=a<=b<=31415 ).

It is guaranteed that numbers p_{1},p_{2},p_{3},p_{4} p
1
	 ,p
2
	 ,p
3
	 ,p
4
	  will be pairwise distinct.

输出格式：
Output the number of integers in the given range that have the given property.

输入输出样例
输入样例#1： 复制
2 7 1 8 2 8
输出样例#1： 复制
0
输入样例#2： 复制
20 30 40 50 0 100
输出样例#2： 复制
20
输入样例#3： 复制
31 41 59 26 17 43
输出样例#3： 复制
9

在洛谷，
享受Coding的欢乐

关于洛谷 | 帮助中心 | 用户协议 | 联系我们
小黑屋 | 陶片放逐 | 社区规则 | 招贤纳才
2013-2019 , 洛谷 © Developed by the Luogu Dev Team
陕ICP备17005722号-1 All rights reserved.


from itertools import permutations as p
r=map(int,raw_input().split())
P=list(p(r[:4]))
print len([ x for x in range(r[4],r[5]+1) if sum([ x == eval('%'.join(map(str, [x]+list(e)))) for e in P])>6])


# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="yaroslav"
__date__ ="$02.08.2011 18:00:13$"
def f(x,p1,p2,p3,p4):
    return (((x % p1) % p2) % p3) % p4

if __name__ == "__main__":
    inp = raw_input()
    input = inp.rsplit(' ')
    p1 = int(input[0])
    p2 = int(input[1])
    p3 = int(input[2])
    p4 = int(input[3])
    a = int(input[4])
    b = int(input[5])
    allkol=0
    list1 = range(a+1,b)
    list1.append(a)
    for x in list1:
        kol = 0
        for i in [p1,p2,p3,p4]:
            for j in [p1,p2,p3,p4]:
                if j!=i:
                    for k in [p1,p2,p3,p4]:
                        if k not in(j,i):
                            for m in [p1,p2,p3,p4]:
                                if m not in (j,i,k):
                                    if x==f(x,i,j,k,m):
                                        kol+=1
        if kol>7:
            allkol+=1
    print allkol


from itertools import permutations as p
r=map(int,raw_input().split())
print len([ x for x in range(r[4],r[5]+1) if sum([ x == eval('%'.join(map(str, [x]+list(e)))) for e in p(r[:4])])>6])


n,m,k=map(int,input().split())
M=int(1e9+7)

N=n*n
iv=[0]*(N+1)
iv[1]=1
for i in range(2, N+1):
    iv[i]=M-M//i*iv[M%i]%M
f1=[1]*(N+1)
for i in range(1, N+1):
    f1[i]=f1[i-1]*i%M
f2=[1]*(N+1)
for i in range(1, N+1):
    f2[i]=f2[i-1]*iv[i]%M
left=m%n
#m/n+1, m/n
def powM(b, p):
    r=1
    while p>0:
        if p%2>0:
            r=r*b%M
        b=b*b%M
        p//=2
    return r
c=[[powM(f1[n]*f2[j]%M*f2[n-j]%M, m//n+i) for j in range(n+1)] for i in range(2)]
#print(c)
dp=[[0]*(k+1) for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    for j in range(k+1):
        for l in range(min(n, k-j)+1):
            # i,j -> i+1,j+l
            dp[i+1][j+l]=(dp[i+1][j+l]+c[i<left][l]*dp[i][j])%M
print(dp[n][k])


import sys
range = xrange
input = raw_input

MOD = 10**9+7

big = 10**2 + 10
modinv = [1]*big
for i in range(2,big):
    modinv[i] = int((-(MOD//i)*modinv[MOD%i])%MOD)

fac = [1]
for i in range(1,big):
    fac.append(int(fac[-1]*i%MOD))

invfac = [1]
for i in range(1,big):
    invfac.append(int(invfac[-1]*modinv[i]%MOD))

def choose(n,k):
    return int(fac[n]*invfac[k]*invfac[n-k]%MOD)

n,m,k = [int(x) for x in input().split()]

count = [1 + (m - n - i + (n - 1))//n for i in range(n)]
count.insert(0, 0)

DP = [[0]*(k + 1) for _ in range(n + 1)]
DP[0][0] = 1

for i in range(1, n + 1):
    DPi = DP[i]
    DPim1 = DP[i - 1]

    for extra in range(min(n, k) + 1):
        c = pow(choose(n, extra), count[i], MOD)
        for j in range(k + 1 - extra):
            DPi[j + extra] = (DPi[j + extra] + int(DPim1[j] * c % MOD))%MOD

print DP[-1][-1]


n,m,k=map(int,input().split())
M=int(1e9+7)

N=n*n
iv=[0]*(N+1)
iv[1]=1
for i in range(2, N+1):
    iv[i]=M-M//i*iv[M%i]%M
f1=[1]*(N+1)
for i in range(1, N+1):
    f1[i]=f1[i-1]*i%M
f2=[1]*(N+1)
for i in range(1, N+1):
    f2[i]=f2[i-1]*iv[i]%M
left=m%n
#m/n+1, m/n
def powM(b, p):
    r=1
    while p>0:
        if p%2>0:
            r=r*b%M
        b=b*b%M
        p//=2
    return r
c=[[powM(f1[n]*f2[j]%M*f2[n-j]%M, m//n+i) for j in range(n+1)] for i in range(2)]
#print(c)
dp=[[0]*(k+1) for i in range(n+1)]
dp[0][0]=1
for i in range(n):
    for j in range(k+1):
        #prune
        if j>i*n or j<k-(n-i)*n:
            continue
        for l in range(min(n, k-j)+1):
            # i,j -> i+1,j+l
            dp[i+1][j+l]=(dp[i+1][j+l]+c[i<left][l]*dp[i][j])%M
print(dp[n][k])


#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Cheran Senthilkumar <hello@cheran.io>
"""
from __future__ import division, print_function

import os
import sys
from atexit import register
from cStringIO import StringIO
from itertools import ifilter, imap, izip

range = xrange
filter, map, zip = ifilter, imap, izip

sys.stdout = StringIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = StringIO(os.read(0, os.fstat(0).st_size)).readline

MOD = 10**9 + 7
MODF = float(MOD)

MAGIC = 6755399441055744.0
SHRT = 65536.0

MODF_INV = 1.0 / MODF
SHRT_INV = 1.0 / SHRT

fround = lambda x: (x + MAGIC) - MAGIC
fmod = lambda a: a - MODF * fround(MODF_INV * a)
fmul = lambda a, b, c=0.0: fmod(fmod(a * SHRT) * fround(SHRT_INV * b) + a * (b - SHRT * fround(b * SHRT_INV)) + c)

def fpow(x, y):
    if y == 0:
        return 1.0

    res = 1.0
    while y > 1:
        if y & 1 == 1:
            res = fmul(res, x)
        x = fmul(x, x)
        y >>= 1

    return fmul(res, x)

def get_primes(n):
    """ Input n>=6, Returns a generator of primes, 5 <= p < n """
    sieve = bytearray((n // 3 + (n % 6 == 2) >> 3) + 1)

    for i in range(1, int(n**0.5) // 3 + 1):
        if not (sieve[i >> 3] >> (i & 7)) & 1:
            k = (3 * i + 1) | 1
            for j in range(k * k // 3, n // 3 + (n % 6 == 2), 2 * k):
                sieve[j >> 3] |= 1 << (j & 7)
            for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + (n % 6 == 2), 2 * k):
                sieve[j >> 3] |= 1 << (j & 7)

    return (3 * i + 1 | 1 for i in range(1, n // 3 + (n % 6 == 2)) if not (sieve[i >> 3] >> (i & 7)) & 1)

def main():
    m = int(input())
    if m == 1:
        print(1)
    else:
        res = 2.0
        if m >= 3:
            res = fmod(res + fpow(3, MOD - 2))
        for p in get_primes(m + 1):
            res = fmod(res + fpow(p, MOD - 2))

        print(int(res) % MOD)

if __name__ == '__main__':
    main()


from fractions import Fraction

g = [0]*111111
t = [0]*111111
prime = [0]*111111
pm = [0]*111111
for i in range(len(prime)):
    prime[i] = {}

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def ksm(a, b, p=int(1e9+7)):
    a = a % p
    ans = 1
    while b > 0:
        if b & 1:
            ans = ans * a % p
        b = b >> 1
        a = a*a % p
    return ans

m = int(input())
p = int(1e9+7)
tmp = ksm(m, p-2)
for j in range(m, 0, -1):
    c1 = 0
    tyouce = tmp
    gyouce = 0
    if j == 1:
        c1 = 0
    else:
        c1 = m//j * tmp % p

    for k in range(2, m//j + 1):

        def get_ck(m, n):
            ans = 0

            def get_fac():
                for i in range(2, 100011):
                    if pm[i] == 0:
                        prime[i][i] = 1
                        for j in range(2, 100001//i+1):
                            pm[i*j] = 1
                            prime[i*j][i] = 1

            if prime[m] == {}:
                get_fac()
            prime_list = list(prime[m].keys())
            for i in range(1, 1 << len(prime_list)):
                t = i
                rongchixishu = -1
                lcm = 1
                index = len(prime_list)-1
                while t>0:
                    if t&1:
                        lcm = lcm*prime_list[index]
                        rongchixishu *= -1
                    t >>= 1
                ans += n//lcm*rongchixishu
            return ans

        ck = (m//j - get_ck(k, m//j)+p) % p
        ck = ck*tmp % p
        tyouce = (tyouce + ck * t[k*j]) % p
        gyouce = (gyouce + ck * (t[k*j] + g[k*j])) % p
    t[j] = tyouce * ksm(1-c1+p, p-2) % p
    gyouce = (gyouce + tmp + c1 * t[j]) % p
    g[j] = gyouce * ksm(1-c1+p, p-2) % p

print(g[1])


import sys
from fractions import gcd
from math import sqrt,log
import time
from random import randint
import random
from sets import Set

# ---------- Number Theory -------------#

def primes_upto(maxn):
    maxn+=1
    A = [False]*(maxn/2+5)
    p = 3
    while p*p<maxn:
        if not A[p>>1]:
            for j in range(p*p,maxn,2*p):
                A[(j>>1)]=True
        p+=2
    ret = [2]
    for p in range(3,maxn,2):
        if not A[(p>>1)]:
            ret.append(p)
    return ret
st = time.time()
prime_list = primes_upto(1000000)
def factor_sieve(maxn):
    maxn+=1
    factor = [0]*maxn
    lim  = int(sqrt(maxn))
    for i in range(2,lim+2):
        if factor[i] == 0:
            for j in range(i*i,maxn,i):
                factor[j] = i
    return factor
factor_list = factor_sieve(100000)
def totient_sieve(maxn): #returns an array of totient function
    factor=[]
    if maxn<100000:
        factor = factor_list
    else:
        factor = factor_sieve(maxn)
    maxn+=1
    tot = [1]*maxn
    tot[0] = 0
    for i in range(2,maxn):
        if factor[i] == 0:
            tot[i] = i-1
            continue
        x = factor[i]
        y=i/x
        if y%x == 0:
            tot[i] = tot[y]*x
        else:
            tot[i] = tot[y]*(x-1)
    return tot

def _try_composite(a, d, n, s):
    if pow(a, d, n) == 1:
        return False
    for i in range(s):
        if pow(a, 2**i * d, n) == n-1:
            return False
    return True # n  is definitely composite

def is_prime(n, _precision_for_huge_n=10):
    if n in _known_primes or n in (0, 1):
        return True
    for p in _known_primes:
        if n%p==0:
            return False
    d, s = n - 1, 0
    while not d % 2:
        d, s = d >> 1, s + 1
    # Returns exact according to http://primes.utm.edu/prove/prove2_3.html
    if n < 1373653:
        return not any(_try_composite(a, d, n, s) for a in (2, 3))
    if n < 25326001:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5))
    if n < 118670087467:
        if n == 3215031751:
            return False
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7))
    if n < 2152302898747:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11))
    if n < 3474749660383:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13))
    if n < 341550071728321:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13, 17))
    return not any(_try_composite(a, d, n, s)
                   for a in _known_primes[:_precision_for_huge_n])

_known_primes = [2, 3]
_known_primes += [x for x in range(5, 1000, 2) if is_prime(x)]
def brent(N):#Fails for perfect squares,primes
        if N%2==0:
                return 2
        if N<100000:
            return factor_list[N]
        y,c,m = random.randint(1, N-1),random.randint(1, N-1),random.randint(1, N-1)
        g,r,q = 1,1,1
        while g==1:
                x = y
                for i in range(r):
                        y = ((y*y)%N+c)%N
                k = 0
                while (k<r and g==1):
                        ys = y
                        for i in range(min(m,r-k)):
                                y = ((y*y)%N+c)%N
                                q = q*(abs(x-y))%N
                        g = gcd(q,N)
                        k = k + m
                r = r*2
        if g==N:
                while True:
                        ys = ((ys*ys)%N+c)%N
                        g = gcd(abs(x-ys),N)
                        if g>1:
                                break

        return g
def floor_sqrt(n):
    x = max(0,int(sqrt(n))-1)
    while x*x<=n:
        x+=1
    return x-1
def prime_factors(n):# Returns all prime factors of n
    ret = Set()
    if n==1:
        return ret
    if is_prime(n):
        ret.add(n)
        return ret
    x = floor_sqrt(n)
    if x*x == n:
        return prime_factors(x)
    x = brent(n)
    n/=x
    while n%x == 0:
        n/=x
    r1 = prime_factors(x)
    r2 = prime_factors(n)
    for i in r1:
        ret.add(i)
    for i in r2:
        ret.add(i)
    return ret
def factorization(n):
    X = prime_factors(n)
    arr = []
    for i in X:
        arr.append(i)
    ret = {}
    for i in range(0,len(arr)):
        val = 0
        p = arr[i]
        while n%p == 0:
            val+=1
            n/=p
        ret[p] = val
    assert(n==1)
    return ret
def divisors(n):
    X = factorization(n)
    A=[1]
    for p in X:
        a = X[p]
        x=p**a
        z=len(A)
        B = A
        for i in range(0,z):
            val=A[i]
            mul = p
            for j in range(1,a+1):
                B.append(val*mul)
                mul*=p
        A = B
    return A
def ndiv(n):
    x = factorization(n)
    ret=1
    for i in x:
        ret*=x[i]+1
    return ret
def sorted_divisors(n):
    return sorted(divisors(n))
myp = {}
def primepi(n):#Finds pi(10**10) in 12 secs, pi(10**11) in 1 minute O(sqrt(n)) memory
    if n<=1:
        return 0
    if myp.has_key(n):
        return myp[n]
    myp.clear()
    lim=floor_sqrt(n)
    sm=[]
    la =[]
    for i in range(0,lim+1):
        sm.append(i-1)
        if i==0:
            la.append(0)
            continue
        la.append(n/i-1)
    for p in range(2,lim+1):
        if sm[p-1] == sm[p]:
            continue
        cnt_p = sm[p-1]
        q = p*p
        en = min(lim,n/q)
        for i in range(1,en+1):
            d = i*p
            if d<=lim:
                la[i]-=la[d]-cnt_p
            else:
                la[i]-=sm[n/d]-cnt_p
        for i in range(lim,q-1,-1):
            sm[i]-=sm[i/p]-cnt_p
    for i in range(1,lim+1):
        myp[i] = sm[i]
        myp[n/i] = la[i]
    return la[1]
cache={}
def phi(n): #totient(n)
    if n in cache:
        return cache[n]
    ret = n
    x = prime_factors(n)
    for p in x:
        ret*=p-1
        ret/=p
    cache[n] = ret
    return ret

def inv(x,a): #(x,a) = 1
    r = phi(a)-1
    ret= pow(x,r,a)
    return ret

def all_mod_invs(n, p):
    """ Find all inverses mod p, p prime, from 1 to n, n < p """
    invs = [1]*(n+1)
    for q in range(2, n+1):
        invs[q] = p-p//q*invs[p%q]%p
    return invs

def crt(A,B):# all elements of A are mutually coprime
    N = 1
    for i in range(0,len(A)):
        N*=A[i]
    ret = 0
    for i in range(0,len(A)):
        val = A[i]
        md = B[i]
        prod_rem = N/val
        ret+=md*(prod_rem*inv(prod_rem,val))
    ans= ret%N
    return ans
_store = {}

mod = 1000000007

def powr(a,b,mod):
	mod = 1000000007
	t = 1
	while b :
		if b&1 :
			t = (t*a)%mod
		a = (a*a)%mod
		b/=2
	return t
def invr(a):
	return powr(a,mod-2,mod)
def main():
    #primes = prime_list
	n = input()
	ans = 1
	maxn = 1000000
	factor = factor_sieve(maxn)
	mu = [1]*maxn
	for i in range(2,maxn):
		if factor[i] == 0:
			mu[i]=-1
			continue
        x = factor[i]
        y=i/x
        if y%x == 0:
            mu[i] = 0
        else:
            mu[i]=mu[x]*mu[y]

	for i in range(2,n+1):
		_div = n/i
		ans= ans%mod - (mu[i]%mod*_div*invr(n-_div))%mod
		ans+=mod;
		ans%=mod
	print(ans)
if __name__ == "__main__":
    main()


import sys
from fractions import gcd
from math import sqrt,log
import time
from random import randint
import random
from sets import Set

# ---------- Number Theory -------------#

def primes_upto(maxn):
    maxn+=1
    A = [False]*(maxn/2+5)
    p = 3
    while p*p<maxn:
        if not A[p>>1]:
            for j in range(p*p,maxn,2*p):
                A[(j>>1)]=True
        p+=2
    ret = [2]
    for p in range(3,maxn,2):
        if not A[(p>>1)]:
            ret.append(p)
    return ret
st = time.time()
prime_list = primes_upto(1000000)
def factor_sieve(maxn):
    maxn+=1
    factor = [0]*maxn
    lim  = int(sqrt(maxn))
    for i in range(2,lim+2):
        if factor[i] == 0:
            for j in range(i*i,maxn,i):
                factor[j] = i
    return factor
factor_list = factor_sieve(100000)
def totient_sieve(maxn): #returns an array of totient function
    factor=[]
    if maxn<100000:
        factor = factor_list
    else:
        factor = factor_sieve(maxn)
    maxn+=1
    tot = [1]*maxn
    tot[0] = 0
    for i in range(2,maxn):
        if factor[i] == 0:
            tot[i] = i-1
            continue
        x = factor[i]
        y=i/x
        if y%x == 0:
            tot[i] = tot[y]*x
        else:
            tot[i] = tot[y]*(x-1)
    return tot

def _try_composite(a, d, n, s):
    if pow(a, d, n) == 1:
        return False
    for i in range(s):
        if pow(a, 2**i * d, n) == n-1:
            return False
    return True # n  is definitely composite

def is_prime(n, _precision_for_huge_n=10):
    if n in _known_primes or n in (0, 1):
        return True
    for p in _known_primes:
        if n%p==0:
            return False
    d, s = n - 1, 0
    while not d % 2:
        d, s = d >> 1, s + 1
    # Returns exact according to http://primes.utm.edu/prove/prove2_3.html
    if n < 1373653:
        return not any(_try_composite(a, d, n, s) for a in (2, 3))
    if n < 25326001:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5))
    if n < 118670087467:
        if n == 3215031751:
            return False
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7))
    if n < 2152302898747:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11))
    if n < 3474749660383:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13))
    if n < 341550071728321:
        return not any(_try_composite(a, d, n, s) for a in (2, 3, 5, 7, 11, 13, 17))
    return not any(_try_composite(a, d, n, s)
                   for a in _known_primes[:_precision_for_huge_n])

_known_primes = [2, 3]
_known_primes += [x for x in range(5, 1000, 2) if is_prime(x)]
def brent(N):#Fails for perfect squares,primes
        if N%2==0:
                return 2
        if N<100000:
            return factor_list[N]
        y,c,m = random.randint(1, N-1),random.randint(1, N-1),random.randint(1, N-1)
        g,r,q = 1,1,1
        while g==1:
                x = y
                for i in range(r):
                        y = ((y*y)%N+c)%N
                k = 0
                while (k<r and g==1):
                        ys = y
                        for i in range(min(m,r-k)):
                                y = ((y*y)%N+c)%N
                                q = q*(abs(x-y))%N
                        g = gcd(q,N)
                        k = k + m
                r = r*2
        if g==N:
                while True:
                        ys = ((ys*ys)%N+c)%N
                        g = gcd(abs(x-ys),N)
                        if g>1:
                                break

        return g
def floor_sqrt(n):
    x = max(0,int(sqrt(n))-1)
    while x*x<=n:
        x+=1
    return x-1
def prime_factors(n):# Returns all prime factors of n
    ret = Set()
    if n==1:
        return ret
    if is_prime(n):
        ret.add(n)
        return ret
    x = floor_sqrt(n)
    if x*x == n:
        return prime_factors(x)
    x = brent(n)
    n/=x
    while n%x == 0:
        n/=x
    r1 = prime_factors(x)
    r2 = prime_factors(n)
    for i in r1:
        ret.add(i)
    for i in r2:
        ret.add(i)
    return ret
def factorization(n):
    X = prime_factors(n)
    arr = []
    for i in X:
        arr.append(i)
    ret = {}
    for i in range(0,len(arr)):
        val = 0
        p = arr[i]
        while n%p == 0:
            val+=1
            n/=p
        ret[p] = val
    assert(n==1)
    return ret
def divisors(n):
    X = factorization(n)
    A=[1]
    for p in X:
        a = X[p]
        x=p**a
        z=len(A)
        B = A
        for i in range(0,z):
            val=A[i]
            mul = p
            for j in range(1,a+1):
                B.append(val*mul)
                mul*=p
        A = B
    return A
def ndiv(n):
    x = factorization(n)
    ret=1
    for i in x:
        ret*=x[i]+1
    return ret
def sorted_divisors(n):
    return sorted(divisors(n))
myp = {}
def primepi(n):#Finds pi(10**10) in 12 secs, pi(10**11) in 1 minute O(sqrt(n)) memory
    if n<=1:
        return 0
    if myp.has_key(n):
        return myp[n]
    myp.clear()
    lim=floor_sqrt(n)
    sm=[]
    la =[]
    for i in range(0,lim+1):
        sm.append(i-1)
        if i==0:
            la.append(0)
            continue
        la.append(n/i-1)
    for p in range(2,lim+1):
        if sm[p-1] == sm[p]:
            continue
        cnt_p = sm[p-1]
        q = p*p
        en = min(lim,n/q)
        for i in range(1,en+1):
            d = i*p
            if d<=lim:
                la[i]-=la[d]-cnt_p
            else:
                la[i]-=sm[n/d]-cnt_p
        for i in range(lim,q-1,-1):
            sm[i]-=sm[i/p]-cnt_p
    for i in range(1,lim+1):
        myp[i] = sm[i]
        myp[n/i] = la[i]
    return la[1]
cache={}
def phi(n): #totient(n)
    if n in cache:
        return cache[n]
    ret = n
    x = prime_factors(n)
    for p in x:
        ret*=p-1
        ret/=p
    cache[n] = ret
    return ret

def inv(x,a): #(x,a) = 1
    r = phi(a)-1
    ret= pow(x,r,a)
    return ret

def all_mod_invs(n, p):
    """ Find all inverses mod p, p prime, from 1 to n, n < p """
    invs = [1]*(n+1)
    for q in range(2, n+1):
        invs[q] = p-p//q*invs[p%q]%p
    return invs

def crt(A,B):# all elements of A are mutually coprime
    N = 1
    for i in range(0,len(A)):
        N*=A[i]
    ret = 0
    for i in range(0,len(A)):
        val = A[i]
        md = B[i]
        prod_rem = N/val
        ret+=md*(prod_rem*inv(prod_rem,val))
    ans= ret%N
    return ans
_store = {}

mod = 1000000007

def powr(a,b,mod):
	t = 1
	while b :
		if b&1 :
			t = (t*a)%mod
		a = (a*a)%mod
		b/=2
	return t
def invr(a):
	return powr(a,mod-2,mod)
def main():
    #primes = prime_list
	n = input()
	ans = 1
	maxn = 1000000
	factor = factor_sieve(maxn)
	mu = [1]*maxn
	for i in range(2,maxn):
		if factor[i] == 0:
			mu[i]=-1
			continue
        x = factor[i]
        y=i/x
        if y%x == 0:
            mu[i] = 0
        else:
            mu[i]=mu[x]*mu[y]

	for i in range(2,n+1):
		_div = n/i
		ans = ans%mod - (mu[i]%mod*_div%mod*invr(n-_div)%mod)%mod
		ans+=mod;
		ans%=mod
	print(ans)
if __name__ == "__main__":
    main()


g = [0]*111111
t = [0]*111111

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def ksm(a, b, p=int(1e9+7)):
    a = a % p
    ans = 1
    while b > 0:
        if b & 1:
            ans = ans * a % p
        b = b >> 1
        a = a*a % p
    return ans

m = int(input())
p = int(1e9+7)
tmp = ksm(m, p-2)
for j in range(m, 0, -1):
    c1 = 0
    tyouce = tmp
    gyouce = 0
    if j == 1:
        c1 = 0
    else:
        c1 = m//j * tmp % p

    for k in range(2, m//j + 1):
        t0 = m//j//k
        t1 = 0
        for l in range(1, k):
            if gcd(l, k) == 1:
                t1 += 1
        ck = t0*t1 % p
        for l in range(1, (m//j) % k + 1):
            if gcd(l, k) == 1:
                ck += 1
        ck = ck*tmp%p
        tyouce = (tyouce + ck * t[k*j]) % p
        gyouce = (gyouce + ck * (t[k*j] + g[k*j])) % p
    t[j] = tyouce * ksm(1-c1+p, p-2) % p
    gyouce = (gyouce + tmp + c1 * t[j]) % p
    g[j] = gyouce * ksm(1-c1+p, p-2) % p

# print(t[2])
# print(g[2])
# print(t[1])
print(g[1])


import math

k = int(input())

n = int(k/3)*2 + 1
# print('n', n)
ans = 0

while True:
    point_to_check = (n+2)//2
    # print('p', point_to_check)

    x = 0.0
    y = n*math.sqrt(3)

    # print('r', math.sqrt((x**2+y**2)))

    # p1
    x -= 0.5
    y += math.sqrt(3) * 0.5

    # print('r', math.sqrt((x**2+y**2)))

    count = -1
    for i in range(point_to_check):
        # print('r', math.sqrt((x**2+y**2)))
        if ((x**2+y**2)<=k**2):
            count = i
            break
        x -= 1.5
        y -= math.sqrt(3)/2

    extra = 0
    if count != -1:
        extra = point_to_check - count

        if (n+1)%2==0:
            extra *= 2
        else:
            extra = extra*2 -1

        if extra == n+1:
            ans += (extra-1)*6
            break
        else:
            ans += extra*6

        # print('n', n, 'ans', ans)

    n = n-1

# print('extra', extra)

for i in range(n):
    if i==0:
        ans += 1
    else:
        ans += i*6

if k==1:
    print(1)
else:
    print(ans)

# R = 1
# r = sqrt(3)*0.5*R
# full_cycle_count =  k / (math.sqrt(3)) - 0.5
# print(full_cycle_count)
# full_cycle_count = int(full_cycle_count)
# print(full_cycle_count)
#
# half_cycle_count = int((k - 1) / 3) * 2
# print(half_cycle_count)
#
# ans = 1
# last_add = 0
# for i in range(1, full_cycle_count+1):
#     last_add +=6
#     ans += last_add
#
# print(last_add)
#
# if half_cycle_count>full_cycle_count:
#     ans += (last_add+6) / 2
#
# print(int(ans))


k = input()
r = 0
i,j=0,k
f = lambda x,y: x*x+3*y*y>4*k*k
while j>=0:
    o = i&1
    while j>=0:
        j-=1
        x,y = 3*i+1,2*j-1+o
        if f(x,y): continue
        if f(x+1,y-1): continue
        break
    if j<0: break
    r += (2*j+o-1)*(2 if i else 1)
    i,j=i+1,j+2
print r


import math

k = int(input())

n = int(k/3)*2 + 1
# print('n', n)
ans = 0

while True:
    point_to_check = (n+2)//2
    # print('p', point_to_check)

    x = 0.0
    y = n# *math.sqrt(3)

    # print('r', math.sqrt((x**2+y**2)))

    # p1
    x -= 0.5
    y += 0.5 #* math.sqrt(3)

    # print('r', math.sqrt((x**2+y**2)))

    count = -1
    for i in range(point_to_check):
        # print('r', math.sqrt((x**2+y**2)))
        if ((x**2+3*(y**2))<=k**2):
            count = i
            break
        x -= 1.5
        y -= 0.5 # * math.sqrt(3)

    extra = 0
    if count != -1:
        extra = point_to_check - count

        if (n+1)%2==0:
            extra *= 2
        else:
            extra = extra*2 -1

        if extra == n+1:
            ans += (extra-1)*6
            break
        else:
            ans += extra*6

    # print('n', n, 'ans', ans)

    n = n-1

# print('extra', extra)

for i in range(n):
    if i==0:
        ans += 1
    else:
        ans += i*6

if k<=2:
    print(1)
else:
    print(ans)

# R = 1
# r = sqrt(3)*0.5*R
# full_cycle_count =  k / (math.sqrt(3)) - 0.5
# print(full_cycle_count)
# full_cycle_count = int(full_cycle_count)
# print(full_cycle_count)
#
# half_cycle_count = int((k - 1) / 3) * 2
# print(half_cycle_count)
#
# ans = 1
# last_add = 0
# for i in range(1, full_cycle_count+1):
#     last_add +=6
#     ans += last_add
#
# print(last_add)
#
# if half_cycle_count>full_cycle_count:
#     ans += (last_add+6) / 2
#
# print(int(ans))


k = input()
r,i,j,o,t=0,-2,2*k,0,0
f = lambda x,y: x*x+3*y*y>4*k*k
while j>=0:
    if (f(i,j) or f(i+1,j-1)): j-=2; continue
    r+=j*t
    i+=3;
    if j&1: j+=5
    else: j+=3
    if t<2: t+=1
print r


#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
ll k;

int main() {
    cin >> k;
    ll res = 0;
    int i,j,jj;
    for (i=0,j=k;i<k&&j>=0;i++) {
        for (;j>=0;j--) {
            ll x,y;
            x = 3*i+1;
            y = 2*j+1;
            if (i&1) y++;
            if (x*x+3*y*y>4*k*k) continue;
            x++;
            y--;
            if (x*x+3*y*y>4*k*k) continue;
            break;
        }
        if (j<0) break;
        jj=j;
        jj+=1;
        jj*=2;
        if ((i&1)==0) jj--;
        if (!i) res+=jj;
        else res+=2*jj;
    }
    cout << res;
}


s=raw_input()
ans=0
for i in range(0,len(s)):
	if(s[i]>'a' and s[i]<'z'):
		ans-=ord(s[i])-ord('a')+1
	else:
		ans+=ord(s[i])-ord('A')+1
print ans


#!/usr/bin/python

import os
import sys
import itertools

def solve(f):
    a = f.read_int()
    oa = oct(a)
    return int(oa[-2:])

class Reader(object):
    def __init__(self, filename=None):
        self.test_mode = filename is not None
        self.cases = 1
        self.buffer = []
        if self.test_mode:
            with open(filename) as f:
                blank_flg = False
                for line in f:
                    line = line.strip()
                    if line:
                        self.buffer.append(line)
                        blank_flg = False
                    else:
                        if not blank_flg: self.cases += 1
                        blank_flg = True

    def __readline(self):
        return self.buffer.pop(0) if self.test_mode else raw_input()

    def read_int(self):
        return int(self.__readline())
    def read_float(self):
        return float(self.__readline())
    def read_long(self):
        return long(self.__readline())
    def read_str(self):
        return self.__readline()

    def read_int_list(self):
        return [int(item) for item in self.__readline().split()]
    def read_float_list(self):
        return [float(item) for item in self.__readline().split()]
    def read_long_list(self):
        return [long(item) for item in self.__readline().split()]
    def read_str_list(self):
        return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv)>1 else None
    f = Reader(filename)
    if f.test_mode:
        for c in xrange(f.cases):
            print "Case #%d"%(c+1)
            print solve(f)
    else:
        print solve(f)


s=raw_input()
ans=0
for i in range(0,len(s)):
	if(s[i]>='a' and s[i]=<'z'):
		ans-=ord(s[i])-ord('a')+1
	elif(s[i]>='A' and s[i]<='Z'):
		ans+=ord(s[i])-ord('A')+1
print ans


s=raw_input()
ans=0
for i in range(0,len(s)):
	if(s[i]>'a' and s[i]<'z'):
		ans-=ord(s[i])-ord('a')+1
	else if(s[i]>'A' and s[i]<='Z'):
		ans+=ord(s[i])-ord('A')+1
print ans


from __future__ import division

import math
import os
from io import BytesIO

input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
range = xrange

MOD = 998244353
MODF = float(MOD)
SHRT = float(1 << 16)
ROOT = 3.0

fmod = lambda x: x - MODF * math.trunc(x / MODF)
mod_prod = lambda a, b: fmod(math.trunc(a / SHRT) * fmod(b * SHRT) + (a - SHRT * math.trunc(a / SHRT)) * b)

def fpow(x, y):
    res = 1.0
    while y > 0:
        if y & 1 == 1:
            res = mod_prod(res, x)
        x = mod_prod(x, x)
        y >>= 1

    return res

def ntt(a, inv=False):
    n = len(a)
    w = [1.0] * (n >> 1)

    w[1] = fpow(ROOT, (MOD - 1) // n)
    if inv:
        w[1] = fpow(w[1], MOD - 2)

    for i in range(2, (n >> 1)):
        w[i] = mod_prod(w[i - 1], w[1])

    rev = [0] * n
    for i in range(n):
        rev[i] = rev[i >> 1] >> 1
        if i & 1 == 1:
            rev[i] |= (n >> 1)
        if i < rev[i]:
            a[i], a[rev[i]] = a[rev[i]], a[i]

    step = 2
    while step <= n:
        half, diff = step >> 1, n // step
        for i in range(0, n, step):
            pw = 0
            for j in range(i, i + half):
                v = mod_prod(w[pw], a[j + half])
                a[j + half] = a[j] - v
                a[j] += v
                pw += diff

        step <<= 1

    if inv:
        inv_n = fpow(n, MOD - 2)
        for i in range(n):
            a[i] = mod_prod(a[i], inv_n)

def conv(a, b):
    s = len(a) + len(b) - 1
    n = 1 << s.bit_length()

    a.extend([0.0] * (n - len(a)))
    b.extend([0.0] * (n - len(b)))

    ntt(a)
    ntt(b)

    for i in range(n):
        a[i] = mod_prod(a[i], b[i])

    ntt(a, inv=True)
    del a[s:]

def main():
    N, _ = input().split()
    n = int(N) >> 1

    d = [0.0] * 10
    for i in input().split():
        d[int(i)] = 1.0

    result = [1.0]
    while n > 0:
        if n & 1 == 1:
            conv(result, d[:])
        conv(d, d[:])
        n >>= 1

    os.write(1, str(int(sum(mod_prod(i, i) for i in result) % MODF)))

if __name__ == '__main__':
    main()


import os
from __pypy__.intop import int_mod,int_mul,int_add,int_sub
from io import BytesIO

input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

MOD = 998244353
ROOT = 3
MODF = 1.0*MOD
MODF_inv = 1.0/MODF
SHRT = float(1 << 16)
SHRT_inv = 1.0/SHRT
modder = lambda a:a - MODF * int(a*MODF_inv)
mod_prod = lambda a, b:\
    int_sub(int_mul(a,b), int_mul(MOD,int(MODF_inv*a*b)))

def fpow(x, y):
    return float(pow(int(x),y,MOD))
    #res = 1
    #if y==0:return x
    #while y > 1:
    #    if y & 1:
    #        res = mod_prod(res, x)
    #    x = mod_prod(x, x)
    #    y >>= 1
    #return mod_prod(res, x)

def mod_sq(x):
    return fpow(x,2)

def ntt(a, inv=False):
    n = len(a)
    w = [1] * (n >> 1)

    w[1] = fpow(ROOT, (MOD - 1) // n)
    if inv:
        w[1] = fpow(w[1], MOD - 2)

    for i in xrange(2, (n >> 1)):
        w[i] = mod_prod(w[i - 1], w[1])

    rev = [0] * n
    for i in xrange(n):
        rev[i] = rev[i >> 1] >> 1
        if i & 1 == 1:
            rev[i] |= (n >> 1)
        if i < rev[i]:
            a[i], a[rev[i]] = a[rev[i]], a[i]

    step = 2
    while step <= n:
        half, diff = step >> 1, n / step
        for i in xrange(0, n, step):
            pw = 0
            for j in xrange(i, i + half):
                #print(repr(w[pw]),repr(a[j + half]))
                v = mod_prod(w[pw],a[j + half]%MOD)
                a[j + half] = (a[j] - v)%MOD
                a[j] = (a[j] + v)%MOD
                pw += diff

        step <<= 1

    if inv:
        inv_n = fpow(n, MOD - 2)
        for i in xrange(n):
            a[i] = mod_prod(a[i], inv_n)

def conv(a, b):
    s = len(a) + len(b) - 1
    n = 1 << s.bit_length()

    a.extend([0] * (n - len(a)))
    b.extend([0] * (n - len(b)))

    ntt(a)
    ntt(b)

    for i in xrange(n):
        a[i] = mod_prod(a[i], b[i])

    ntt(a, inv=True)
    del a[s:]

def main():
    N, _ = input().split()
    n = int(N) >> 1

    big = (1+9*(n+1))
    m = 1
    while m<big:m*=2

    d = [0] * m
    for i in input().split():
        d[int(i)] = 1

    ntt(d)
    d = [fpow(i,n) for i in d]
    ntt(d,inv=True)
    d = [mod_sq(i) for i in d]
    print(int(sum(d))%MOD)

if __name__ == '__main__':
    main()


import os
from io import BytesIO
from math import trunc

range = xrange
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

MOD = 998244353
MODF = float(MOD)
SHRT = float(1 << 16)
ROOT = 3.0

modder = lambda x: x - MODF * trunc(x / MODF)
mod_prod = lambda a, b: modder(trunc(a / SHRT) * modder(b * SHRT) + (a - SHRT * trunc(a / SHRT)) * b)

def fpow(x, y):
    res = 1.0
    while y > 0:
        if y & 1:
            res = mod_prod(res, x)
        if y>1:
            x = mod_prod(x, x)
        y >>= 1

    return res

def ntt(a, inv=False):
    n = len(a)
    w = [1.0] * (n >> 1)

    w[1] = fpow(ROOT, (MOD - 1) // n)
    if inv:
        w[1] = fpow(w[1], MOD - 2)

    for i in xrange(2, (n >> 1)):
        w[i] = mod_prod(w[i - 1], w[1])

    rev = [0] * n
    for i in xrange(n):
        rev[i] = rev[i >> 1] >> 1
        if i & 1 == 1:
            rev[i] |= (n >> 1)
        if i < rev[i]:
            a[i], a[rev[i]] = a[rev[i]], a[i]

    step = 2
    while step <= n:
        half, diff = step >> 1, n / step
        for i in xrange(0, n, step):
            pw = 0
            for j in xrange(i, i + half):
                v = mod_prod(w[pw],a[j + half])
                a[j + half] = a[j] - v
                a[j] += v
                pw += diff

        step <<= 1

    if inv:
        inv_n = fpow(n, MOD - 2)
        for i in xrange(n):
            a[i] = mod_prod(a[i], inv_n)

def conv(a, b):
    s = len(a) + len(b) - 1
    n = 1 << s.bit_length()

    a.extend([0.0] * (n - len(a)))
    b.extend([0.0] * (n - len(b)))

    ntt(a)
    ntt(b)

    for i in xrange(n):
        a[i] = mod_prod(a[i], b[i])

    ntt(a, inv=True)
    del a[s:]

def main():
    N, _ = input().split()
    n = int(N) >> 1

    big = (1+9*(n+1))
    m = 1
    while m<big:m*=2

    d = [0.0] * m
    for i in input().split():
        d[int(i)] = 1.0

    # Solution using parseval's theorem
    ntt(d)
    d = [fpow(i,n) for i in d]
    d = [mod_prod(d[i],d[-i]) for i in range(len(d))]
    inv_m = 1.0*pow(m,MOD-2,MOD)
    print(int(mod_prod(sum(d),inv_m)))

if __name__ == '__main__':
    main()


import os
from io import BytesIO
from math import trunc

input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

fmod = lambda x: x - 998244353.0 * trunc(x / 998244353.0)
mod_prod = lambda a, b: fmod(trunc(a / 65536.0) * fmod(b * 65536.0) + (a - 65536.0 * trunc(a / 65536.0)) * b)

def fpow(x, y):
    res = 1.0
    while y > 0:
        if y & 1 == 1:
            res = mod_prod(res, x)
        x = mod_prod(x, x)
        y >>= 1

    return res

def ntt(a, inv=False):
    n = len(a)
    w = [1.0] * (n >> 1)

    w[1] = fpow(3.0, 998244352 / n)
    if inv:
        w[1] = fpow(w[1], 998244351)

    for i in xrange(2, (n >> 1)):
        w[i] = mod_prod(w[i - 1], w[1])

    rev = [0] * n
    for i in xrange(n):
        rev[i] = rev[i >> 1] >> 1
        if i & 1 == 1:
            rev[i] |= (n >> 1)
        if i < rev[i]:
            a[i], a[rev[i]] = a[rev[i]], a[i]

    step = 2
    while step <= n:
        half, diff = step >> 1, n / step
        for i in xrange(0, n, step):
            pw = 0
            for j in xrange(i, i + half):
                v = mod_prod(a[j + half], w[pw])
                a[j + half] = a[j] - v
                a[j] += v
                pw += diff

        step <<= 1

    if inv:
        inv_n = fpow(n, 998244351)
        for i in xrange(n):
            a[i] = mod_prod(a[i], inv_n)

def conv(a, b):
    s = len(a) + len(b) - 1
    n = 1 << s.bit_length()

    a.extend([0.0] * (n - len(a)))
    b.extend([0.0] * (n - len(b)))

    ntt(a)
    ntt(b)

    for i in xrange(n):
        a[i] = mod_prod(a[i], b[i])

    ntt(a, inv=True)
    del a[s:]

def main():
    N, _ = input().split()
    n = int(N) >> 2

    d = [0.0] * 10
    for i in input().split():
        d[int(i)] = 1.0

    result = [1.0]
    while n > 0:
        if n & 1 == 1:
            conv(result, d[:])
        conv(d, d[:])
        n >>= 1

    os.write(1, str(int(sum(mod_prod(i, i) for i in result) % 998244353.0)))

if __name__ == '__main__':
    main()


import os
from io import BytesIO
from math import trunc

input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

MOD = 998244353
MODF = float(MOD)
SHRT = float(1 << 16)
ROOT = 3.0

fmod = lambda x: x - MODF * trunc(x / MODF)
mod_prod = lambda a, b: fmod(trunc(a / SHRT) * fmod(b * SHRT) + (a - SHRT * trunc(a / SHRT)) * b)

def memoize(f):
    """ Memoization decorator for a function taking one or more arguments. """

    class memodict(dict):
        def __getitem__(self, *key):
            return dict.__getitem__(self, key)

        def __missing__(self, key):
            ret = self[key] = f(*key)
            return ret

    return memodict().__getitem__

@memoize
def fpow(x, y):
    res = 1.0
    while y > 0:
        if y & 1 == 1:
            res = mod_prod(res, x)
        x = mod_prod(x, x)
        y >>= 1

    return res

def ntt(a, inv=False):
    n = len(a)
    w = [1.0] * (n >> 1)

    w[1] = fpow(ROOT, (MOD - 1) / n)
    if inv:
        w[1] = fpow(w[1], MOD - 2)

    for i in xrange(2, (n >> 1)):
        w[i] = mod_prod(w[i - 1], w[1])

    rev = [0] * n
    for i in xrange(n):
        rev[i] = rev[i >> 1] >> 1
        if i & 1 == 1:
            rev[i] |= (n >> 1)
        if i < rev[i]:
            a[i], a[rev[i]] = a[rev[i]], a[i]

    step = 2
    while step <= n:
        half, diff = step >> 1, n / step
        for i in xrange(0, n, step):
            pw = 0
            for j in xrange(i, i + half):
                v = mod_prod(a[j + half], w[pw])
                a[j + half] = a[j] - v
                a[j] += v
                pw += diff

        step <<= 1

    if inv:
        inv_n = fpow(n, MOD - 2)
        for i in xrange(n):
            a[i] = mod_prod(a[i], inv_n)

def conv(a, b):
    s = len(a) + len(b) - 1
    n = 1 << s.bit_length()

    a.extend([0.0] * (n - len(a)))
    b.extend([0.0] * (n - len(b)))

    ntt(a)
    ntt(b)

    for i in xrange(n):
        a[i] = mod_prod(a[i], b[i])

    ntt(a, inv=True)
    del a[s:]

def main():
    N, _ = input().split()
    n = int(N) >> 1

    d = [0.0] * 10
    for i in input().split():
        d[int(i)] = 1.0

    result = [1.0]
    if n>1:
        while n > 1:
            if n & 1:
                conv(result, d)
            conv(d, d[:])
            n >>= 1
        conv(result, d)

    os.write(1, str(int(sum(mod_prod(i, i) for i in result) % MODF)))

if __name__ == '__main__':
    main()


import sys

braille_chars = """
.  .  .. .. .  .. .. .   .  . .  .  .. .. .  .. .. .   .  . .  .   . .. .. .
   .      .  . .  .. .. .  ..    .      .  . .  .. .. .  ..    .  ..     .  .
                              .  .  .  .  .  .  .  .  .  .  .. ..  . .. .. ..
""".strip().splitlines()

decode_chart = {}
for idx in range(26):
    ch = chr(idx + ord("a"))
    if ch in "is":
        continue
    shape = [braille_chars[l][(3 * idx) : (3 * idx + 2)] for l in range(3)]
    shape = [[x == "." for x in line] for line in shape]
    rows = [sum(line) for line in shape]
    cols = [sum(shape[r][c] for r in range(3)) for c in range(2)]
    code = tuple(rows) + tuple(cols)
    # if code in decode_chart:
    #     print(ch, decode_chart[code], code)
    decode_chart[code] = ch
#     print(ch, code)

def solve_G(codes: List[List[int]]) -> str:
    return "".join(decode_chart[tuple(code)] for code in codes)

input_str = sys.stdin.read().strip()
codes = [[int(x) for x in line.split()] for line in input_str.splitlines()[1:]]
print(solve_G(codes))


import sys

braille_chars = """
.  .  .. .. .  .. .. .   .  . .  .  .. .. .  .. .. .   .  . .  .   . .. .. .
   .      .  . .  .. .. .  ..    .      .  . .  .. .. .  ..    .  ..     .  .
                              .  .  .  .  .  .  .  .  .  .  .. ..  . .. .. ..
""".strip().splitlines()

decode_chart = {}
for idx in range(26):
    ch = chr(idx + ord("a"))
    if ch in "is":
        continue
    shape = [braille_chars[l][(3 * idx) : (3 * idx + 2)] for l in range(3)]
    shape = [[x == "." for x in line] for line in shape]
    rows = [sum(line) for line in shape]
    cols = [sum(shape[r][c] for r in range(3)) for c in range(2)]
    code = tuple(rows) + tuple(cols)
#     if code in decode_chart:
#         print(ch, decode_chart[code], code)
    decode_chart[code] = ch
#     print(ch, code)

def solve_G(codes: List[List[int]]) -> str:
    return "".join(decode_chart[tuple(code)] for code in codes)

input_str = sys.stdin.read().strip()
codes = [[int(x) for x in line.split()] for line in input_str.splitlines()[1:]]
print(solve_G(codes))


from collections import defaultdict

n,q = map(int, input().split())

ops = []
for i in range(0,q):
    a,b = input().split()
    ops.append((b,a))
ops.sort(key=lambda tup: (tup[0],tup[1]))
ops_d = defaultdict(list)
for k,v in ops:
    ops_d[k].append(v)

count = 0
hit_list = []
def dfs(cur_str, size):
    size +=1
    #print(cur_str, " ", size)
    if len(cur_str) == n and cur_str not in hit_list:
        hit_list.append(cur_str)
        return 1
    elif size > n:
        return -1
    else:
        for op in ops_d[cur_str[0]]:
            #print(op)
            cur_str_tmp = list(cur_str)
            cur_str_tmp[0] = op
            cur_str_tmp = "".join(cur_str_tmp)
            if dfs(cur_str_tmp,size) == 1:
                global count
                count +=1

dfs('a',0)
print(count)


def main():
	n = int(input())
	L = [int(x) for x in input().split()]
	print(solver(L))

def solver(L):
	S = set(L)
	L = list(S)
	L.sort()
	for i in range(len(L) - 2):
		if L[i + 1] == L[i] + 1 and \
		L[i + 2] == L[i + 1] + 1:
			return "YES"
	return "NO"

#L = [40, 44, 44, 44, 44, 41, 43]
#print(list(set(L)))
#L2 = [18, 55, 16, 17]
#L3 = [5, 972, 3, 4, 1, 4, 970, 971]
#print(solver(L3))

main()


def main():
	(n, q) = (int(x) for x in input().split())
	L = [None] * q
	for i in range(q):
		(a, b) = (int(x) for x in input().split())
		L[i] = (a, b)
	print(solver(n, L))

def solver(n, L):
	count = 0
	for (a, b) in L:
		if b == 'a':
			count += helper(n - 2, L, a[0])
	return count

def helper(n, L, last):
	if n == 0:
		return 1
	else:
		count = 0
		for (a, b) in L:
			if b == last:
				count += helper(n - 1, L, a[0])
		return count

# L = [('ab', 'a'), ('cc', 'c'), ('ca', 'a'), ('ee', 'c'),
# ('ff', 'd')]
# L2 = [('bb', 'a'), ('ba', 'a')]
# print(solver(6, L2))
main()


n, q = map(int, input().split())

fr = dict()
past = dict()
for i in range(q):
    a, b = input().split()
    if b in fr:
        fr[b].append(a)
    else:
        fr[b] = [a]

def dfs(c, cnt):
    global n
    if cnt == n:
        return 1
    if cnt > n:
        return 0
    global past
    p = ord(c) + cnt*1000
    if p in past:
        return past[cnt]

    global fr
    if c not in fr:
        return 0

    ans = 0
    for i in fr[c]:
        ans += dfs(i[0], cnt+1)
    past[p] = ans
    return ans

print(dfs('a', 1))


x1, x2, a, b = map(int, input().split())
if a <= 0 <= b:
    if x1 < x2:
        if x2 - x1 <= b:
            print("FIRST")
            print(x2)
        else:
            print("DRAW")
    else:
        if x1 - x2 <= -a:
            print("FIRST")
            print(x2)
        else:
            print("DRAW")
else:
    reverse = False
    if a < 0:
        x1, x2, a, b = -x1, -x2, -b, -a
        reverse = True
    if x1 > x2:
        print("DRAW")
    else:
        if (x2 - x1) % (a + b) == 0:
            print("SECOND")
        elif a <= (x2 - x1) % (a + b) <= b:
            print("FIRST")
            print((x1 + (x2 - x1) % (a + b))
                  if not reverse else -(x1 + (x2 - x1) % (a + b)))
        else:
            print("DRAW")


x1,x2,a,b=map(int,raw_input().split())
if a+x1<=x2 and b+x1>=x2:print "FIRST";print x2
elif a<=0 and b>=0:print "DRAW"
else:
	d=x2-x1
	if a<0:d,a,b=-d,-b,-a
	if d<0:print "DRAW"
	elif d%(a+b)==0:print "SECOND"
	elif d%(a+b)>=a and d%(a+b)<=b:
		print "FIRST"
		if x1<x2: print x1+d%(a+b)
		else: print x1-d%(a+b)
	else: print "DRAW"


x1, x2, a, b = map(int, input().split())
if a <= 0 <= b:
    if x1 < x2:
        if x2 - x1 <= b:
            print("FIRST")
            print(x2)
        else:
            print("DRAW")
    else:
        if x1 - x2 <= -a:
            print("FIRST")
            print(x2)
        else:
            print("DRAW")
else:
    if a < 0:
        x1, x2, a, b = -x1, -x2, -a, -b
    if x1 > x2:
        print("DRAW")
    else:
        if (x2 - x1) % (a + b) == 0:
            print("SECOND")
        elif a <= (x2 - x1) % (a + b) <= b:
            print("FIRST")
            print(x1 + (x2 - x1) % (a + b))
        else:
            print("DRAW")


x1, x2, a, b = map(int, input().split())
if a <= 0 <= b:
    if x1 < x2:
        if x2 - x1 <= b:
            print("FIRST")
            print(x2 - x1)
        else:
            print("DRAW")
    else:
        if x1 - x2 <= -a:
            print("FIRST")
            print(x2 - x1)
        else:
            print("DRAW")
else:
    if a < 0:
        x1, x2, a, b = -x1, -x2, -a, -b
    if x1 > x2:
        print("DRAW")
    else:
        if (x2 - x1) % (a + b) == 0:
            print("SECOND")
        elif a <= (x2 - x1) % (a + b) <= b:
            print("FIRST")
            print((x2 - x1) % (a + b))
        else:
            print("DRAW")


x1,x2,a,b=map(int,raw_input().split())
if x1+a<=x2<=x1+b: print 'FIRST'; print x2
elif a<=0<=b: print 'DRAW'
elif a>0:
    if x1>x2: print 'DRAW'
    else:
        s=(x2-x1)%(a+b)
        if s==0: print 'SECOND'
        elif a<=s<=b: print 'FIRST';print x1+s
        else: print 'DRAW'
else:
    if x1<x2: print 'DRAW'
    else:
        s=abs(x1-x2)%abs(a+b)
        if s==0: print 'SECOND'
        elif a<=s<=b: print 'FIRST';print x1-s
        else: print 'DRAW'


num = [0 for i in range(10)]
line = raw_input()
for i in line:
    num[ord(i) - ord('0')] += 1
ans = 0
ansstrX = ansstrY = ''.join(sorted(list(line)))
for firstX in range(1, 10):
    firstY = (10 - firstX) % 10
    cntX = [0 for i in range(10)]
    cntY = [0 for i in range(10)]
    cntX[firstX] += 1
    cntY[firstY] += 1
    if cntX[firstX] > num[firstX] or cntY[firstY] > num[firstY]:
        continue
    tmpstrX = chr(ord('0') + firstX)
    tmpstrY = chr(ord('0') + firstY)
    tmp = 1
    for i in range(10):
        l = min(num[i] - cntX[i], num[9 - i] - cntY[9 - i])
        cntX[i] += l
        cntY[9 - i] += l
        tmp += l
        tmpstrX += chr(ord('0') + i) * l
        tmpstrY += chr(ord('0') + 9 - i) * l
    l = min(num[0] - cntX[0], num[0] - cntY[0])
    cntX[0] += l
    cntY[0] += l
    tmp += l
    tmpstrX = chr(ord('0')) * l + tmpstrX
    tmpstrY = chr(ord('0')) * l + tmpstrY
    for i in range(10):
        tmpstrX += chr(ord('0') + i) * (num[i] - cntX[i])
        tmpstrY += chr(ord('0') + i) * (num[i] - cntY[i])
    if ans < tmp:
        ans = tmp
        ansstrX = tmpstrX
        ansstrY = tmpstrY
print ansstrX[::-1]
print ansstrY[::-1]


import itertools

def countZeroes(s):
    ret = 0
    for i in s:
        if i != '0':
            break
        ret += 1
    return ret

def stupid(n):
    ansMax = 0
    bn1 = n
    bn2 = n
    for n1 in itertools.permutations(n):
        for n2 in itertools.permutations(n):
            val = str(int(''.join(n1)) + int(''.join(n2)))[::-1]
            cnt = countZeroes(val)
            if cnt > ansMax:
                ansMax = cnt
                bn1 = ''.join(n1)
                bn2 = ''.join(n2)
    return (bn1, bn2)

def solution(n):
    ansMax = n.count('0')
    bestN1 = n.replace('0', '') + ansMax * '0'
    bestN2 = n.replace('0', '') + ansMax * '0'

    for i in range(1, 10):
        cnt1 = [n.count(str(j)) for j in range(10)]
        cnt2 = [n.count(str(j)) for j in range(10)]

        if cnt1[i] == 0 or cnt2[10 - i] == 0:
            continue
        cnt1[i] -= 1
        cnt2[10 - i] -= 1
        curN1 = str(i)
        curN2 = str(10 - i)
        ansCur = 1
        for j in range(10):
            addend = min(cnt1[j], cnt2[9 - j])
            ansCur += addend

            cnt1[j] -= addend
            cnt2[9 - j] -= addend

            curN1 += str(j) * addend
            curN2 += str(9 - j) * addend

        if cnt1[0] > 0 and cnt2[0] > 0:
            addend = min(cnt1[0], cnt2[0])
            ansCur += addend

            cnt1[0] -= addend
            cnt2[0] -= addend

            curN1 = '0' * addend + curN1
            curN2 = '0' * addend + curN2

        if ansCur > ansMax:
            ansMax = ansCur
            f = lambda x: str(x[0]) * x[1]
            bestN1 = ''.join(map(f, enumerate(cnt1))) + curN1[::-1]
            bestN2 = ''.join(map(f, enumerate(cnt2))) + curN2[::-1]

    return (bestN1, bestN2)

n = input()
print('\n'.join(solution(n)))


num = [0] * 10
line = list(raw_input())
for i in line:
  num[ord(i) - ord('0')] += 1
ans = 0
retstr1 = retstr = ''.join(line)
for first_i in range(1, 10):
  first_j = (10 - first_i) % 10
  cntx = [0] * 10
  cnty = [0] * 10
  cntx[first_i] += 1
  cnty[first_j] += 1
  if cntx[first_i] > num[first_i] or cnty[first_j] > num[first_j]:
    continue
  tmpstr1 = chr(ord('0') + first_i)
  tmpstr2 = chr(ord('0') + first_j)
  tmp = 1
  for i in range(10):
    l = min(num[i] - cntx[i], num[9-i] - cntx[9-i])
    cntx[i] += l
    cnty[9-i] += l
    tmp += l
    tmpstr1 += chr(ord('0') + i) * l
    tmpstr2 += chr(ord('0') + 9 - i) * l
  l = min(num[0] - cntx[0], num[0] - cnty[0])
  cntx[0] += l
  cnty[0] += l
  tmp += l
  tmpstr1 = chr(ord('0')) * l + tmpstr1
  tmpstr2 = chr(ord('0')) * l + tmpstr2
  for i in range(10):
    tmpstr1 += chr(ord('0') + i) * (num[i] - cntx[i])
    tmpstr2 += chr(ord('0') + i) * (num[i] - cnty[i])
  if ans < tmp:
    ans = tmp
    retstr1 = tmpstr1
    retstr2 = tmpstr2
print retstr1[::-1]
print retstr2[::-1]


#-*- coding: utf-8 -*-
import sys

w = sys.stdout.write
read = sys.stdin.readline
reads = sys.stdin.read

def r(f=None):
    if f:
        return map(f, read().split('\n'))
    else:
        return read().split('\n')

def rs(t,f=None):
    result = []
    result_append = result.append
    for i in xrange(t):
        if f:
            result_append(map(f, read().split()))
        else:
            result_append(read().split())
    return result

####################################################
import copy

n = raw_input()
s = raw_input()

n = int(n)
s = s.split(' ')
q = [s]

while q:
    s = q.pop()
    elem = s.pop()
    if not s:
        w('YES')
        exit()
    if len(s) >= 1 and (s[-1][0] == elem[0] or s[-1][1] == elem[1]):
        old = s[-1]
        s[-1] = elem
        q.append(s)
    if len(s) >= 3 and (s[-3][0] == elem[0] or s[-3][1] == elem[1]):
        s[-1] = old
        s[-3] = elem
        q.append(s)
w('NO')


def move(i, cards):
	c1 = cards[i]
	c2 = cards[len(cards) - 1]

	if c1[0] != c2[0] and c1[1] != c2[1]: return (False, "")

	cards[i] = cards.pop()
	return (True, c1)

def unmove(i, orig, cards):
	cards.append(cards[i])
	cards[i] = orig

def poss(cards):
	l = len(cards)
	if l == 1: return True

	(done, orig) = move(l-2, cards)
	if done:
		if poss(cards):
			return True
		unmove(i, orig, cards)

	if (l <= 3): return False
	(done, orig) = move(l-4, cards)
	if done:
		if poss(cards):
			return True
		unmove(i, orig, cards)
	return False

n = int(raw_input())

cards = raw_input().split()

if (poss(cards)):
	print "YES"
else:
	print "NO"


n, cards, tried = input(), raw_input().split(), set()

def cards_match(card1, card2):
	return card1[0] == card2[0] or card1[1] == card2[1]

def solitaire(n, cards):
	result = True if n == 1 else False
	if not result and n >= 2 and cards_match(cards[n - 1], cards[n - 2]) and cards[:n - 2] + [cards[n - 1]] not in tried:
		tried.append(cards[:n - 2] + [cards[n - 1]])
		result = solitaire(n - 1, tried[-1])
	if not result and n >= 4 and cards_match(cards[n - 1], cards[n - 4]) and cards[:n - 4] + [cards[n - 1]] + cards[n - 3:n - 1] not in tried:
		tried.append(cards[:n - 4] + [cards[n - 1]] + cards[n - 3:n - 1])
		result = solitaire(n - 1, tried[-1])
	return result

print "YES" if solitaire(n, cards) else "NO"


import sys,os
n=int(sys.stdin.readline())
p=sys.stdin.readline().split()
for i in range(n):
	p[i]=int(p[i])
c=sys.stdin.readline().split()
a=[]
for i in range(len(c)):
	c[i]=(int(c[i]), i)
	a.append(0)
c.sort()
r=0
for i in range(n):
	r+=p[i]
	k=len(c)-1
	while k>=0:
		if r>=c[k][0]:
			a[c[k][1]]+=(r/c[k][0])
			r-=(r/c[k][0])*c[k][0]
		k-=1
for i in range(len(a)):
	sys.stdout.write(str(a[i])+' ')
sys.stdout.write('\n')
print(r)


#! /usr/bin/python2

import sys
import math

n = int(raw_input())
s = ""
for i in raw_input().split():
    s = s + i

ans = {'':False}
def ok(a):
    if (len(a) == 2):
        return True
    if (a in ans):
        return ans[a]
    if (a[-1] == a[-3] or a[-2] == a[-4]):
        if (ok(a[0 : len(a) - 4] + a[-2] + a[-1])):
            ans[a] = True
            return True
    if (len(a) > 7 and (a[-1] == a[-7] or a[-2] == a[-8])):
        if (ok(a[0: len(a) - 8] + a[-2] + a[-1] + a[-4:-1])):
            ans[a] = True
            return True
    ans[a] = False
    return False

if (ok(s)):
    print("YES")
else:
    print("NO")


v = input().split()
p = input().split()

v1 = int(v[0])

v2 = int(v[1])

T = int(p[0])
d = int(p[1])

x = abs(v1 - v2)
t = T-2

sum = v1 + v2

if v1 <= v2:

    def check(v1, v2, d, t):
        a = []
        z = d
        for i in range(2*d):

            if ((v1+z)-v2) > (d*t+d):
                z -= 1

            else:
                a.append(z)

        return(int(a[0]))

    for i in range(t):

        if ((v1+d)- v2) <= (d*(t-(i+1))+d):
            sum += (v1 + d)

            v1 = v1+d
        else:
            sum += (v1 + check(v1, v2, d , t-(i+1)))

else:
    v1, v2 = v2, v1

    def check(v1, v2, d, t):
        a = []
        z = d
        for i in range(2*d):

            if ((v1+z)-v2) > (d*t+d):
                z -= 1

            else:
                a.append(z)

        return(int(a[0]))

    for i in range(t):

        if ((v1+d)- v2) <= (d*(t-(i+1))+d):
            sum += (v1 + d)

            v1 = v1+d
        else:
            sum += (v1 + check(v1, v2, d , t-(i+1)))

print(sum)


vIndo, vVol = [0], [0]
vIndo[0], vVol[0] = map(int, raw_input().split())
t, d = map(int, raw_input().split())

for i in xrange(1, t):
	vIndo.append(d + vIndo[i-1])
	r.append(d + vVol[i-1])

resultado = 0
for i in xrange(t):
	resultado += min(vIndo[i], vVol[t-i-1])

print resultado


v1, v2 = sorted(map(int, input().split()))

t, d = map(int, input().split())

df = (v2 - v1 - 1) // d
sm = t - 2

x = (sm + df) >> 1
y = (sm - df) >> 1

ans = d * x * (x + 1) // 2
ans += d * y * (y + 1) // 2

ans += x * v1 + v1
ans += y * v2 + v2

# print(x, y)
print(ans)


v1 = int(input())
v2 = int(input())
t = int(input())
d = int(input())

ans = 0
for i in range(0,t):
	ans=ans+min(v1+d*i,v2+d*(t-i-1))
print ans

#v1, v2 = map(int, raw_input().split())
#t, d = map(int, raw_input().split())
#print sum(min(v1 + d * i, v2 + d*(t-i-1)) for i in xrange(t))


s = raw_input()
a = s.split()
#print a
v1 = a[0]
v2 = a[1]
s = raw_input()
a = s.split()
t = int(a[0])
d = a[1]
sum = 0
for i in range(t):
    sum += min(v1 + i * d, v2 + (i-t) * d)
print sum


import sys
mod = 998244353
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0: return 1
    elif y == 1	 : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else: return power(x, (y-1)//2)**2 * x % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def div(a, b):
    return mul(a, power(b, mod-2))
def div2(a, b):
    return mul(a, modinv(b))

def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = 2*10**5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, K = map(int, input().split())
M=N-K
#print(M)
R = 0
for i in range(1, M+1):
    R += (-1 if (M-i)%2 else 1) * (mul(cmb(M, i), power(i, N)))
R = mul(cmb(N, M), R)
if K != 0:
    R = R*2%mod
print(R)


import sys
input = sys.stdin.buffer.readline
def print(val):
    sys.stdout.write(str(val) + '\n')

def choose(n,k,mod = None):
    if k > n:
        return 0
    k = min(n-k,k)
    total = 1
    for i in range(n-k+1, n+1):
        total*= i
    for i in range(2,k+1):
        total//= i
    return total % 998244353
"""def factorial(n):
    total = 1
    for i in range(2, n+1):
        total*= i
        total %=998244353
    return total"""
def place_rooks(n,k):
    #if k == 0:
        #return factorial(n)
    filled = n - k
    placements_per_filled = 0
    for i in range(filled):
        mult = 1
        for _ in range(n):
            mult *= (filled-i)
            mult %= 998244353
        placements_per_filled += ((-1)**i)*choose(filled,i)*mult
        placements_per_filled %= 998244353
    total = (2*choose(n,filled)*placements_per_filled ) % 998244353
    if k == 0:
        total//= 2
    return total

n, k = map(int,input().split())
print(place_rooks(n,k))


import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class mint:
    def __init__(self, x):
        self.__x = x % md

    def __repr__(self):
        return str(self.__x)

    def __neg__(self):
        return mint(-self.__x)

    def __add__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x + other)

    def __sub__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x - other)

    def __rsub__(self, other):
        return mint(other - self.__x)

    def __mul__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * other)

    __radd__ = __add__
    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, mint): other = other.__x
        return mint(self.__x * pow(other, md - 2, md))

    def __rtruediv__(self, other):
        return mint(other * pow(self.__x, md - 2, md))

    def __pow__(self, power, modulo=None):
        return mint(pow(self.__x, power, md))

md = 998244353

def nCr(com_n, com_r):
    if com_n < com_r: return 0
    return fac[com_n] * ifac[com_r] * ifac[com_n - com_r]

n_max = 200005
fac = [mint(1)]
for i in range(1, n_max + 1): fac.append(fac[-1] * i)
ifac = [mint(1)] * (n_max + 1)
ifac[n_max] /= fac[n_max]
for i in range(n_max - 1, 1, -1): ifac[i] = ifac[i + 1] * (i + 1)

def main():
    n,k=MI()

    if k>n-1:
        print(0)
        exit()

    ans=0
    for i in range(n-k):
        ans+=nCr(n-k,n-k-i)*pow(n-k-i,n,md)*(-1)**(i&1)
    ans*=nCr(n,n-k)
    if k>0:ans*=2

    print(ans)

main()


class Combination:
    def __init__(self, n_max, mod=10**9+7):
        # O(n_max + log(mod))
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max+1):
            f = f * i % mod
            fac.append(f)
        f = pow(f, mod-2, mod)
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    # "n 要素" は区別できる n 要素
    # "k グループ" はちょうど k グループ

    def __call__(self, n, r):  # self.C と同じ
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def C(self, n, r):
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def P(self, n, r):
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[n-r] % self.mod

    def H(self, n, r):
        if (n == 0 and r > 0) or r < 0: return 0
        return self.fac[n+r-1] * self.facinv[r] % self.mod * self.facinv[n-1] % self.mod

    def rising_factorial(self, n, r):  # 上昇階乗冪 n * (n+1) * ... * (n+r-1)
        return self.fac[n+r-1] * self.facinv[n-1] % self.mod

    def stirling_first(self, n, k):  # 第 1 種スターリング数  lru_cache を使うと O(nk)  # n 要素を k 個の巡回列に分割する場合の数
        if n == k: return 1
        if k == 0: return 0
        return (self.stirling_first(n-1, k-1) + (n-1)*self.stirling_first(n-1, k)) % self.mod

    def stirling_second(self, n, k):  # 第 2 種スターリング数 O(k + log(n))  # n 要素を区別のない k グループに分割する場合の数
        if n == k: return 1  # n==k==0 のときのため
        return self.facinv[k] * sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod

    def balls_and_boxes_3(self, n, k):  # n 要素を区別のある k グループに分割する場合の数  O(k + log(n))
        return sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod

    def bernoulli(self, n):  # ベルヌーイ数  lru_cache を使うと O(n**2 * log(mod))
        if n == 0: return 1
        if n % 2 and n >= 3: return 0  # 高速化
        return (- pow(n+1, self.mod-2, self.mod) * sum(self.C(n+1, k) * self.bernoulli(k) % self.mod for k in range(n))) % self.mod

    def faulhaber(self, k, n):  # べき乗和 0^k + 1^k + ... + (n-1)^k
        # bernoulli に lru_cache を使うと O(k**2 * log(mod))  bernoulli が計算済みなら O(k * log(mod))
        return pow(k+1, self.mod-2, self.mod) * sum(self.C(k+1, j) * self.bernoulli(j) % self.mod * pow(n, k-j+1, self.mod) % self.mod for j in range(k+1)) % self.mod

    def lah(self, n, k):  # n 要素を k 個の空でない順序付き集合に分割する場合の数  O(1)
        return self.C(n-1, k-1) * self.fac[n] % self.mod * self.facinv[k] % self.mod

    def bell(self, n, k):  # n 要素を k グループ以下に分割する場合の数  O(k**2 + k*log(mod))
        return sum(self.stirling_second(n, j) for j in range(1, k+1)) % self.mod

N, K = map(int, input().split())
mod = 998244353
if K==0:
    ans = 1
    for i in range(1, N+1):
        ans = ans * i % mod
    print(ans)
    exit()
if K >= N:
    print(0)
    exit()

comb = Combination(200002, mod=mod)

print(comb.balls_and_boxes_3(N, N-K) * comb(N, K) * 2 % mod)


def read_int():
    return int(input())

def read_ints():
    return map(int, input().split(' '))

fac = [1]
rev = []
mod = 998244353

def fexp(x, y):
    ans = 1
    while y > 0:
        if y % 2 == 1:
            ans = ans * x % mod
        x = x * x % mod
        y //= 2
    return ans

def comb(n, k):
    return fac[n] * rev[k] * rev[n - k] % mod

n, k = read_ints()
if k >= n:
    print(0)
else:
    for i in range(1, n + 5):
        fac.append(fac[-1] * i % mod)
    for i in range(n + 5):
        rev.append(fexp(fac[i], mod - 2))
    # 每行每列各一个的，一共n!种
    if k == 0:
        print(fac[n])
    else:
        # 考虑每行一个的情形（每列一个的是对称情形）
        # 有k对能互相攻击，空列一定为k个
        # 首先选出空列
        ways = comb(n, k)
        # 在剩下n-k列中分配k对，共n个车
        # 对于每一行的车，可以在这些列中任意选择，但每列至少需要一个
        # 用容斥原理计算
        col = 0
        for i in range(n - k):
            sign = 1 if i % 2 == 0 else -1
            col += sign * comb(n - k, i) * fexp(n - k - i, n)
            col %= mod
            if col < 0:
                col += mod
        # 再减去有为空的列的情况
        print(ways * col * 2 % mod)