import math

n    = int(input())

if n == 1:
    print()
else:
    edge = [list(map(int, input().split())) for i in range(1, n) ]
    g    = {}

    for x, y in edge:
        if x not in g:
            g[x] = []
        if y not in g:
            g[y] = []

        g[x].append(y)
        g[y].append(x)

    def find_centroid(g):
        p    = {}
        size = {}

        p[1] = -1
        Q    = [1]

        i = 0
        while i < len(Q):
            u = Q[i]

            for v in g[u]:
                if p[u] == v: continue
                p[v] = u
                Q.append(v)
            i+=1

        for u in Q[::-1]:
            size[u] = 1

            for v in g[u]:
                if p[u] == v:
                    continue
                size[u] += size[v]

        cur = 1
        n = size[cur]

        while True:
            max_ = n - size[cur]
            ind_ = p[cur]

            for v in g[cur]:
                if v == p[cur]: continue

                if size[v] > max_:
                    max_ = size[v]
                    ind_ = v

            if max_ <= n // 2:
                return cur

            cur = ind_

    def find_center(g):
        d    = {}
        d[1] = 0
        Q    = [(1, 0)]

        while len(Q) > 0:
            u, dis = Q.pop(0)

            for v in g[u]:
                if v not in d:
                    d[v] = dis +1
                    Q.append((v, d[v]))

        max_length = -1
        s = None

        for u, dis in d.items():
            if dis > max_length:
                max_length = dis
                s = u

        d   = {}
        pre = {}
        d[s] = 0
        Q = [(s, 0)]

        while len(Q) > 0:
            u, dis = Q.pop(0)

            for v in g[u]:
                if v not in d:
                    pre[v] = u
                    d[v]   = dis +1
                    Q.append((v, d[v]))

        max_length = -1
        e = None

        for u, dis in d.items():
            if dis > max_length:
                max_length = dis
                e = u

        route = [e]
        while pre[route[-1]] != s:
            route.append(pre[route[-1]])

        print(route)
        return route[len(route) // 2]

    root = find_centroid(g)
    p    = {}
    size = {}
    Q    = [root]
    p[root] = -1

    i = 0
    while i < len(Q):
        u = Q[i]

        for v in g[u]:
            if p[u] == v: continue
            p[v] = u
            Q.append(v)
        i+=1

    for u in Q[::-1]:
        size[u] = 1

        for v in g[u]:
            if p[u] == v:
                continue
            size[u] += size[v]

    gr    = [(u, size[u]) for u in g[root]]
    gr    = sorted(gr, key=lambda x:x[1])
    thres = math.ceil((n-1) / 3)
    sum_  = 0

    gr1 = []
    gr2 = []
    i = 0

    while sum_ < thres:
        gr1.append(gr[i][0])
        sum_ += gr[i][1]
        i+=1

    while i < len(gr):
        gr2.append(gr[i][0])
        i+=1

    def asign(u, W, ew):
        if size[u] == 1:
            return

        cur = 0
        for v in g[u]:
            if v == p[u]: continue

            first = W[cur]
            ew.append((u, v, first))

            W_  = [x - first for x in W[cur+1: cur+size[v]]]
            asign(v, W_, ew)

            cur+=size[v]

    a, b = 0, 0
    for x in gr1:
        a += size[x]

    for x in gr2:
        b += size[x]

    arr_1 = [x for x in range(1, a+1)]
    arr_2 = [i*(a+1) for i in range(1, b+1)]
    ew    = []

    cur = 0
    for u in gr1:
        first = arr_1[cur]
        ew.append((root, u, first))
        W_    = [x - first for x in arr_1[cur+1:cur+size[u]]]

        cur += size[u]
        #print(u, W_)
        asign(u, W_, ew)

    cur = 0
    for u in gr2:
        first = arr_2[cur]
        ew.append((root, u, first))
        W_    = [x - first for x in arr_2[cur+1:cur+size[u]]]

        cur += size[u]
        #print(u, W_)
        asign(u, W_, ew)

    for u, v, w in ew:
        print('{} {} {}'.format(u, v, w))


n,k,l,m=map(int,input().split())
fc={1:1,2:1}
def f(n):
	if n not in fc: k=n//2;fc[n]=(f(k+1)**2+f(k)**2 if n%2 else f(k)*(2*f(k+1)-f(k)))%m
	return fc[n]
s=k<2**l
for i in range(l): s*=pow(2,n,m)-f(n+2) if (k>>i)%2 else f(n+2)
print(s%m)


def aux(x, a, b, i, vis):
	stack = [i]
	while stack:
		i = stack.pop()
		if i-b >= 0 and i-b not in vis:
			vis.add(i-b)
			stack.append(i-b)
		if i+a <= x and i+a not in vis:
			vis.add(i+a)
			stack.append(i+a)

def single(x, a, b, vis):
	if x-a in vis:
		vis.add(x)
		aux(x, a, b, x, vis)
	return len(vis)

def sum_seq(n):
	return n * (n+1) / 2

def solve(m, a, b):
	vis = set([0])
	tot = 0
	for i in xrange(m+1):
		one = single(i, a, b, vis)
		tot += one
		if i > 0 and one == i + 1:
			return tot + sum_seq(m+1) - sum_seq(i+1)
	return tot

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

def solve_good(m, a, b):
	g = gcd(a, b)
	first = min(m, a+b)
	vis = set([0])
	tot = 0
	for i in xrange(first+1):
		ct = single(i, a, b, vis)
		tot += ct
	tot += g * (sum_seq((m-first)/g + ct) - sum_seq(ct))
	if (m-first) / g > 0:
		tot -= ((m-first)/g + ct) * ((g-1) - (m-first) % g)
	tot += ct * min(g-1, m-first)
	return tot

m, a, b = map(int, raw_input().split())
print solve_good(m, a, b)


from collections import *
n = input()
s = raw_input()
b = [int (i) for i in raw_input().split(' ')]
n = n
cnt = defaultdict(int)
multiples = []
biggest = 'a'
ans = 0
for i in range(n//2):
    if(s[i] == s[n-i-1]):
        multiples.append(i)
        cnt[s[i]] += 1
        ans += max(b[i],b[n-i-1])
    else:
        ans += b[i] + b[n-i-1]

for i in range(26):
    if(cnt[chr(ord('a')+i)] > cnt[biggest]):
        biggest = chr(ord('a')+i)
more = max(max(cnt.values())*2-sum(cnt.values()),0)
takes = []
for i in range(n//2):
    if(s[i] != s[n-i-1] and s[i] != biggest and s[n-i-1] != biggest):
        takes.append(min(b[i],b[n-i-1]))
takes = sorted(takes)[:more]
pen = sum(takes)
print(ans-pen)


# def f(x,b):
# 	s = ""
# 	while x > b:
# 		s += str(x/b)
# 		x /= b
# 	s += str(x)
# 	return s

def digit_to_char(digit):
    if digit < 10:
        return str(digit)
    return chr(ord('a') + digit - 10)

def str_base(number,base):
    if number < 0:
        return '-' + str_base(-number, base)
    (d, m) = divmod(number, base)
    if d > 0:
        return str_base(d, base) + digit_to_char(m)
    return digit_to_char(m)

n = input()
for i in range(1,n):
	for j in range(1,n):
			# print '%2d'%f(i*j,n),
			print str_base(i*j,n),
	print


n,m=[int(x) for x in input().split()]
for i in range(n+m):
    s=input()
if n==m:
    print('Yes')
else:
    print('No')


from math import sqrt
a, b = map(int, input().split())
if a > b:
    a, b = b, a
u = []
sqa = int(sqrt(a))
sqb = int(sqrt(b))
for i in range(1, sqb + 1):
    if i <= sqa and a % i == 0:
        u.append((i, a // i))
    elif b % i == 0:
        u.append((i, b // i))
ok = False
sqab = int(sqrt(a + b))
for i in range(sqab, 0, -1):
    if (a + b) % i == 0:
        k = (a + b) // i
        for j in u:
            if i >= j[0] and k >= j[1]:
                ok = True
                break
    if ok:
        break
print(2 * (i + k))


import sys
input = sys.stdin.readline
MOD = 998244353
N, K = map(int, input().split())
N -= 1
Kaijo = [1] * (N + 1)
KaijoInv = [1] * (N + 1)
for i in range(1, N + 1):
    Kaijo[i] = Kaijo[i - 1] * i % MOD
    KaijoInv[i] = pow(Kaijo[i], MOD - 2, MOD)
nCr = lambda n, r: 0 if r > n else Kaijo[n] * KaijoInv[n - r] % MOD * KaijoInv[r] % MOD
nPr = lambda n, r: 0 if r > n else Kaijo[n] * KaijoInv[n - r] % MOD

DP = [[0] * (K + 1) for _ in range(N + 1)]
DP[0][0] = 1
for i in range(N + 1):
    for j in range(K):
        for k in range(N - i + 1):
            DP[i + k][j + 1] += nCr(i + k, k) * DP[i][j] % MOD * pow(K - j, (i + k - 1) * k - (k * (k - 1) // 2), MOD) % MOD
            DP[i + k][j + 1] %= MOD
print(DP[N][K])


from sys import stdin, stdout
import math, collections
mod = 10**9+7

def isPower(n):
    if (n <= 1):
        return True
    for x in range(2, (int)(math.sqrt(n)) + 1):
        p = x
        while (p <= n):
            p = p * x
            if (p == n):
                return True

    return False
n = int(input())
arr = [0,1,2,1,4,3,2,1,5,6,2,1,8,7,5,9,8,7,3,4,7,4,2,1,10,9,3,6,11,12]
ans = arr[int(math.log(n, 2))]
s = int(math.log(n, 2))
for i in range(3, int(n**0.5)+1):
    if not isPower(i):
        ans^=arr[int(math.log(n, i))]
        s+=int(math.log(n, i))
ans^=((n-s)%2)
print("Vasya" if ans else "Petya")


import math
MOD = 10**9+7

N,M,G = map(int,raw_input().split())

if M == 0:
    print int(G!=N%2)
    exit()
if M == 1:
    ans = int(G!=N%2)
    for i in xrange(N):
        if i%2 == G:
            ans += 1
    print ans
    exit()

D = [0 for i in xrange(N+1)]
D[0] = 1
for i in xrange(1,N+1):
    D[i] = D[i-1]*(i+M-1)%MOD*pow(i,MOD-2,MOD)%MOD
ans = 0
for i in xrange(N+1):
    if i%2 == G:
        a,b = N-i,M-1
        ans = (ans+D[a])%MOD
print ans


mod, sx, sy, dx, dy, t = map(int, raw_input().split())
v = (sx - 1, sy - 1, dx + sx + sy, dy + sx + sy, 1, 1)
A = [
[1, 0, 1, 0, 0, 0],
[0, 1, 0, 1, 0, 0],
[1, 1, 2, 1, 1, 2],
[1, 1, 1, 2, 1, 2],
[0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 1]
]
I = lambda: [[1 if i == j else 0 for j in xrange(6)] for i in xrange(6)]
def mul(M, N):
    global mod
    res = [[0] * 6 for i in xrange(6)]
    for i in xrange(6):
        for j in xrange(6):
            for k in xrange(6):
                res[i][j] += M[i][k] * N[k][j]
                res[i][j] %= mod
    return res
def power(M, k):
    if k > 1:
        res = power(M, k/2)
        res = mul(res, res)
        if k % 2:
            res = mul(res, M)
        return res
    elif k == 1:
        return M
    else:
        return I()
B = power(A, t)
V = [0] * 6
for i in xrange(6):
    for j in xrange(6):
        V[i] += B[i][j] * v[j]
        V[i] %= mod
print V[0] + 1, V[1] + 1


__author__ = 'sergio'

def sg(p):
    if p == 0:
        return -1
    else:
        return 1

def minim(w,h):
    if w < h:
        return (w,0)
    else:
        return (h,1)

def find_path(x, y, down, right):
    global size_n
    global size_m
    if down == 1:
        h = size_n - x
    else:
        h = x - 1
    if right == 1:
        w = size_m - y
    else:
        w = y - 1
    minimum = minim(w,h)
    p = minimum[0]
    ansX = x + p * sg(down)
    ansY = y + p * sg(right)
    if ansX == 1:
        down = 1
    if ansY == 1:
        right = 1
    if ansX == size_n:
        down = 0
    if ansY == size_m:
        right = 0
    return (ansX, ansY, down, right)

def total_black_bound_cells(n, m):
    return n + m - 2

def moves_count(x, y, xn, yn):
    return abs(x - xn)

def get_direction(direction):
    if direction == 'UL':
        return 0, 0
    elif direction == 'UR':
        return 0, 1
    elif direction == 'DL':
        return 1, 0
    elif direction == 'DR':
        return 1, 1

def turn_inside(n, m, xs, ys, down, right):
    if xs == 1:
        down = 1
    if ys == 1:
        right = 1
    if xs == n:
        down = 0
    if ys == m:
        right = 0
    return (down, right)

size_n = 0
size_m = 0

if __name__ == '__main__':

    n, m = [int(x) for x in raw_input().strip().split(' ')]
    xs, ys, direction = raw_input().strip().split(' ')
    xs = int(xs)
    ys = int(ys)

    size_n = n
    size_m = m
    down, right = get_direction(direction)
    down, right = turn_inside(n, m, xs, ys, down, right)

    # print n, m, xs, ys, down, right

    # make visited_points with bound cells
    visited_points = {}
    total_to_check = total_black_bound_cells(n, m) # calculate
    # print 'total_to_check', total_to_check
    visited_points[(xs, ys)] = 1
    total_to_check -= 1
    x = xs
    y = ys
    dye = 1
    while (total_to_check > 0):
        xn, yn, down, right = find_path(x, y, down, right)
        dye += moves_count(x, y, xn, yn)
        # print 'moves_count', moves_count(x, y, xn, yn)
        x = xn
        y = yn
        if (x, y) not in visited_points:
            visited_points[(x, y)] = 1
            total_to_check -= 1
        elif visited_points[(x,y)] == 1:
            visited_points[(x,y)] += 1
        else:
            print -1
            exit()
    print dye

#         visited_points[(n, i)] = 0
# if xs % 2 == 0:
#     for i in range (2, n + 1, 2):
#         visited_points[(i,1)] = 0
#         visited_points[(i,m)] = 0
# else:
#     for i in range (1, n + 1, 2):
#         visited_points[(i,1)] = 0
#         visited_points[(i,m)] = 0
#
# if ys % 2 == 0:
#     for i in range (2, m + 1, 2):
#         visited_points[(1, i)] = 0
#         visited_points[(n, i)] = 0
# else:
#     for i in range (1, m + 1, 2):
#         visited_points[(1, i)] = 0


cnt_party = [0 for i in range(12)]

def C(n, k):
    global mod
    if k > n: return 0
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret = (ret * i) % mod
    return ret

def go(s, pos):
    global cnt, cnt_party, mod
    if s < 1: return 0
    if pos == 6:
        ret = 1
        for i in range(12):
            ret = (ret * C(cnt[i], cnt_party[i])) % mod
        return ret
    ret = 0
    for i in range(s):
        cnt_party[i] += 1
        ret += go(s - i, pos + 1)
        cnt_party[i] -= 1
        if ret >= mod: ret -= mod
    return ret

n = raw_input()
mod = 10 ** 9 + 7
d = [[[0 for i in range(2)] for j in range(12)] for k in range(12)]
d[0][0][0] = 1
for i in range(1, len(n) + 1): # length
    for j in range(i + 1): # beauty
        for k in range(0, int(n[-i])): # next digit
            if k == 7 or k == 4:
                if j == 0: continue
                d[i][j][0] += d[i - 1][j - 1][0] + d[i - 1][j - 1][1]
            else:
                d[i][j][0] += d[i - 1][j][0] + d[i - 1][j][1]
        x = 1 if n[-i] in ['4', '7'] else 0
        d[i][j][0] += 0 if j - x < 0 else d[i - 1][j - x][0]
        d[i][j][1] += 0 if j - x < 0 else d[i - 1][j - x][1]
        for k in range(int(n[-i]) + 1, 10):
            if k == 7 or k == 4:
                if j == 0: continue
                d[i][j][1] += d[i - 1][j - 1][0] + d[i - 1][j - 1][1]
            else:
                d[i][j][1] += d[i - 1][j][0] + d[i - 1][j][1]
cnt = [0 for i in range(12)]
for j in range(len(n) + 1):
    cnt[j] += d[len(n)][j][0]
cnt[0] -= 1
ans = 0
for i in range(1, len(n) + 1):
    ans = (ans + cnt[i] * go(i, 0)) % mod
print ans


input()
p = {(1 << 'RGBYW'.index(c)) + (1 << int(k) + 4) for c, k in input().split()}
print(min(bin(t).count('1') for t in range(1024) if len({t & q for q in p}) == len(p)))


from sys import stdin
from functools import lru_cache
from collections import defaultdict
infile = stdin
N, K = map(int, infile.readline().split())
watched = infile.readline().strip()

mem = set()
mem.add((0,0,0))
for i, letter in enumerate(watched):
    for d in range(K+1):
        for c in range(K+1):
            if (i,d,c) in mem:
                if letter in ('N', '?'):
                    mem.add((i+1, max(d, c+1), c+1))
                if letter in ('Y', '?'):
                    mem.add((i+1, d, 0))

def good():
    for i,d,c in mem:
        if i == N and d == K:
            return 'YES'
    return 'NO'

print(good())


cubes = [i**3.0 for i in range(2, int(1.8e5+5))]

def valid(mid):
    return sum([mid//i for i in cubes if i <= mid])

def binary_search(k):
    l = int(4.8 * k)
    r = min(8.0 * k, 5.0 * (10**15))
    while (l+1 < r):
        mid = (l+r) / 2.0
        res = valid(mid)
        if (res < k):
            l = mid
        else:
            r = mid
    return int(r) if int(valid(r)) == k else -1

def main():
    k = int(input())
    print(binary_search(k))

main()


x, y = map(int, input().split())
b = y // x
if y % x != 0:
    exit(print(0))
ds = set()
M = 10**9 + 7
for i in range(1, int(pow(b,0.5)+1)):
    if b % i == 0:
        ds.add(i)
        ds.add(b//i)
ds = sorted(list(ds))
ans = pow(2, b-1, M)
f = ds[::]
for i in range(len(ds)):
    f[i] = pow(2, ds[i]-1, M)
    for j in range(i):
        if ds[i] % ds[j] == 0:
            f[i] -= f[j]
print(f[-1]%M)


N = int(input())
m1 = []
m2 = []
ms = []
for n in range(N):
    m1.append(input())
for n in range(N):
    m2.append(input())

ms = [
    m2,
    [x[::-1] for x in m2],
    [x for x in reversed(m2)],
]

a = []
for m in ms:
    a.append(m)
    a.append([x[::-1] for x in reversed(m)])
    a.append([''.join(m[j][i] for j in range(N - 1, -1, -1)) for i in range(N)])
    a.append([''.join(m[j][i] for j in range(N)) for i in range(N - 1, -1, -1)])

ms = a
print(['NO', 'YES'][m1 in ms])


dp=[]
for i in xrange(333):
    tmp = []
    for j in xrange(333):
        tmp.append(0)
    dp.append(tmp)

n = map(int,raw_input().split())[0]
a = map(int,raw_input().split())
s1="BitLGM"
s2="BitAryo"

if n==2:
    dp[0][0]=0
    for i in xrange(302):
        for j in xrange(302):
            if(dp[i][j]==0):
                k=1
                while i+k<=300:
                    dp[i+k][j]=1
                    k=k+1
                k=1
                while j+k<=300:
                    dp[i][j+k]=1
                    k=k+1
                k=1
                while i+k<=300 and j+k<=300:
                    dp[i+k][j+k]=1
                    k=k+1
    if dp[a[0]][a[1]]==1:
        print s1
    else: print s2
    exit(0)

t = 0
if n==1: t = a[0]
else:
    t = (a[0]^a[1]^a[2])

if(t>0):
    print s1
else:
    print s2


from sys import stdin,stdout
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a
def factors(a):
    arr=[]
    for i in range(1,int(a**(0.5))+1):
        if a%i==0:
            arr.append(i)
    arr.sort()
    return arr
for _ in range(1):
    a,b=[int(i) for i in stdin.readline().split()]
    ct=0
    arr=factors(a)
    while b:
        c=gcd(a,b)
        a,b=a/c,b/c
        if a==1:
            ct+=b
            break
        z=10**9
        for i in arr:
            if i>a:
                break
            x,y=i,a/i
            if a%x==0 and x!=1:
                z=min(z,b%x)

            if a%y==0 and y!=1:
                z=min(z,b%y)
            if z==0:
                break
        b-=z
        ct+=z
    stdout.write(str(ct)+'\n')


F = ['', 'a', 'b', 'ba', 'bab', 'babba', 'babbabab', 'babbababbabba', 'babbababbabbababbabab', 'babbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabab', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabba', 'babbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabbababbababbabbababbababbabbababbabbababbababbabbababbabab']
while len(F[-3]) < 100000: F.append(F[-1] + F[-2])
d = 1000000007

def sqr(t):
    return [[sum(t[i][k] * t[k][j] for k in range(4)) % d for j in range(4)] for i in range(4)]

def mul(a, b):
    return [[sum(a[i][k] * b[k][j] for k in range(4)) % d for j in range(4)] for i in range(4)]

def fib(k):
    s, p = format(k, 'b')[:: -1], [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
    t = [[[0, 1, 0, 0], [1, 1, 1, 0], [0, 0, 0, 1], [0, 0, 1, 0]]] + [0] * (len(s) - 1)
    for i in range(1, len(s)):
        t[i] = sqr(t[i - 1])
    for i, k in enumerate(s):
        if k == '1': p = mul(p, t[i])
    return p

def cnt(t, p):
    s, i = 0, p.find(t) + 1
    while i > 0:
        i = p.find(t, i) + 1
        s += 1
    return s

def f(t, p, k):
    l = len(t) - 1
    if l: x, y = cnt(t, F[k - 1][- l: ] + F[k][:l ]), cnt(t, F[k][- l: ] + F[k + 1][:l ])
    else: x, y = 0, 0
    a, b = cnt(t, F[k - 1]), cnt(t, F[k])
    return (p[0] * a + p[1] * b + p[2] * y + p[3] * x) % d

k, m = map(int, input().split())
if k > 15:
    x, y, z = len(F[7]), len(F[17]), len(F) - 4
    a, b, c = fib(k - 7)[0], fib(k - 17)[0], fib(k - z)[0]
    for i in range(m):
        t = input()
        if len(t) < x: print(f(t, a, 8))
        elif len(t) < y: print(f(t, b, 18))
        else: print(f(t, c, z + 1))
else:
    p = F[k]
    for i in range(m):
        print(cnt(input(), p))


from collections import defaultdict

def calcBinomials(N):
    global binom
    N += 1
    binom = [[0]*N for _ in range(N)]
    for n in range(N):
        binom[n][0] = binom[n][n] = 1
        for k in range(1, n):
            binom[n][k] = binom[n-1][k] + binom[n-1][k-1]

n = int(input())
a = list(map(int, input().split()))
S, res = sum(a), 0
dp = [defaultdict(lambda: 0) for _ in range(S+1)]
dp[0][0] = 1

cnt = {_:a.count(_) for _ in a}
for x in a:
    for i in range(len(dp)-1-x, -1, -1):
        for k, v in dp[i].items():
            dp[i+x][k+1] += v

calcBinomials(n)
for x, c in cnt.items():
    for i in range(1, c+1):
        if dp[x*i][i] == binom[c][i] or dp[S - x*i][n-i] == binom[c][c-i]:
            res = max(res, i)
if len(cnt) <= 2: res = n
print(res)


def get_input():
    hahaha=input()
    (n,k,m)=hahaha.split(sep=None, maxsplit=1000)
    return (int(n),int(k),int(m))
(n,k,m)=get_input()
f=[0 for i in range(k)]
s=0
for v in range(n):
    tens = 10**v%k
    f=[  (sum(   [f[(j+k-(x+1)*tens)%k] for x in range(9)] )+f[j])%m       for j in range(k)]
    for x in range(9):
        f[(x+1)*tens%k]+=1
    if n-v-1==0:
        s+=(f[0]%m)
    else:
        s+=f[0]*((10**(n-v-2)*9))%m
    f[0]=0
print(s%m)


MOD = 1000000007

def isSubset(a, b):
	return (a & b) == a

def isIntersect(a, b):
	return (a & b) != 0

# Solve for each weakly connected component (WCC)
def cntOrder(s, t):
	p = len(s)
	m = len(t)

	inMask = [0 for i in range(m)]

	for x in range(p):
		for i in range(m):
			if t[i] % s[x] == 0:
				inMask[i] |= 1 << x

	cnt = [0 for mask in range(1<<p)]
	for mask in range(1<<p):
		for i in range(m):
			if isSubset(inMask[i], mask):
				cnt[mask] += 1

	dp = [[0 for mask in range(1<<p)] for k in range(m+1)]
	for i in range(m):
		dp[1][inMask[i]] += 1
	for k in range(m):
		for mask in range(1<<p):
			for i in range(m):
				if not isSubset(inMask[i], mask) and isIntersect(inMask[i], mask):
					dp[k+1][mask | inMask[i]] = (dp[k+1][mask | inMask[i]] + dp[k][mask]) % MOD
			dp[k+1][mask] = (dp[k+1][mask] + dp[k][mask] * (cnt[mask] - k)) % MOD

	return dp[m][(1<<p)-1]

def dfs(u):
	global a, graph, degIn, visited, s, t

	visited[u] = True
	if degIn[u] == 0:
		s.append(a[u])
	else:
		t.append(a[u])

	for v in graph[u]:
		if not visited[v]:
			dfs(v)

def main():
	global a, graph, degIn, visited, s, t

	# Reading input
	n = int(input())
	a = list(map(int, input().split()))

	# Pre-calculate C(n, k)
	c = [[0 for j in range(n)] for i in range(n)]
	for i in range(n):
		c[i][0] = 1
		for j in range(1, i+1):
			c[i][j] = (c[i-1][j-1] + c[i-1][j]) % MOD

	# Building divisibility graph
	degIn = [0 for u in range(n)]
	graph = [[] for u in range(n)]
	for u in range(n):
		for v in range(n):
			if u != v and a[v] % a[u] == 0:
				graph[u].append(v)
				graph[v].append(u)
				degIn[v] += 1

	# Solve for each WCC of divisibility graph and combine result
	ans = 1
	curLen = 0
	visited = [False for u in range(n)]
	for u in range(n):
		if not visited[u]:
			s = []
			t = []
			dfs(u)

			if len(t) > 0:
				sz = len(t) - 1
				cnt = cntOrder(s, t)

				# Number of orders for current WCC
				ans = (ans * cnt) % MOD
				# Number of ways to insert <sz> number to array of <curLen> elements
				ans = (ans * c[curLen + sz][sz]) % MOD
				curLen += sz

	print(ans)

if __name__ == "__main__":
	main()


import sys
input = sys.stdin.readline

n,T=map(int,input().split())
S=[list(map(int,input().split())) for i in range(n)]

DP=[[0]*(4) for i in range(T+1)]
mod=10**9+7

from functools import lru_cache
@lru_cache(maxsize=None)
def calc(used,recent,time):
    ANS=0
    for i in range(n):
        #print(i,used)
        if i in used:
            continue
        if time+S[i][0]>T:
            continue
        if S[i][1]==recent:
            continue
        if time+S[i][0]==T:
            ANS+=1
        if time+S[i][0]<T:
            used2=list(used)+[i]
            used2.sort()
            recent2=S[i][1]
            time2=time+S[i][0]
            ANS=(ANS+calc(tuple(used2),recent2,time2))%mod

    return ANS

print(calc(tuple(),-1,0)%mod)


n, m, l = map(int, raw_input().split())

planet = []

for i in xrange(n):
    nome = raw_input()
    op = []
    for j in xrange(m):

        a, b, c = map(int, raw_input().split())

        op.append([a, b, c])

    planet.append(op)

maximo = 0

for i in xrange(n):
    for j in xrange(n):
        if i != j:
            pft = []
            for k in xrange(m):
                luc = planet[j][k][1] - planet[i][k][0]
                pft.append([luc, planet[i][k][2]])

            pft.sort(reverse=True, key=lambda tup:tup[0])

            qtd = 0
            ganho = 0
            for r in xrange(len(pft)):
                if qtd + pft[r][1] <= l and pft[r][0] > 0:
                    ganho += pft[r][0]*pft[r][1]
                    qtd += pft[r][1]
                elif pft[r][0] > 0:
                    ganho += pft[r][0]*(l-qtd)
                    break

            if ganho > maximo:
                maximo = ganho

print maximo


a,b,m=map(int,input().split())
k=s=(10**9)%m
i=0
while k and i<a:
    i+=1
    if k<m-b:exit(print(1, str(i).zfill(9)))
    k+=s
    if k>=m:k-=m
print(2)


import time
import random
W = int(input())
M = [int(a) for a in input().split()]
A = [0] * 8
sTime = time.time()

s = 0
mi = 10**20
for i in range(8):
    if s + M[i]*(i+1) <= W:
        s += M[i]*(i+1)
        A[i] = M[i]
    else:
        t = (W-s)//(i+1)
        s += t*(i+1)
        A[i] += t

    if s <= W:
        mi = min(mi, W-s)

while time.time() - sTime < 1.7:
    i = random.randrange(8)
    a = random.randrange(2)
    if W-s >= 20 or (s-W < 10 and a == 0):
        if A[i] < M[i]:
            A[i] += 1
            s += (i+1)
    else:
        if A[i] > 0:
            A[i] -= 1
            s -= (i+1)

    if s <= W:
        mi = min(mi, W-s)

print(W-mi)


n = int(raw_input())
mod = 10 ** 9 + 7

limit = 2 * n + 1
not_prime = (limit + 1) * [ False ]
not_prime[0] = not_prime[1] = True
primes = []
for i in range(limit + 1):
    if not_prime[i]:
        continue
    primes.append(i)
    for j in range(i * i, limit + 1, i):
        not_prime[j] = True

def choose_mod(m, n, mod):
    n = min(n, m - n)
    factors = len(primes) * [ 0 ]
    for pos, x in enumerate(primes):
        if x > m:
            break
        for i in range(x, m + 1, x):
            if i > n and i <= m - n:
                continue
            y = i
            c = 0
            while y % x == 0:
                y //= x
                c += 1
            if i <= n:
                factors[pos] -= c
            else:
                factors[pos] += c
    result = 1
    for pos, x in enumerate(factors):
        y = primes[pos]
        for i in range(x):
            result = (result * y) % mod
    return result

print((2 * choose_mod(2 * n + 1, n, mod) - 1) % mod)


from math import trunc

MOD = 998244353
MODF = float(MOD)
SHRT = float(1 << 16)
G = 3.0
MAXSIZ = 1 << 20

# Using pajenegod's crazy method for multiplication using floating point
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 fpow(a, b):
    r = 1.0
    while b:
        if b & 1: r = mod_prod(r, a)
        if b > 1: a = mod_prod(a, a)
        b >>= 1
    return r

n, k = map(int, raw_input().split())
f = [0.0] * MAXSIZ
for d in map(int, raw_input().split()):
    f[d] = 1.0

m = MAXSIZ
m2 = m / 2
w = [1] * m2
w[1] = fpow(G, (MOD - 1) / m)
for i in xrange(2, m2):
    w[i] = mod_prod(w[i - 1], w[1])

rev = [0] * m
for i in xrange(m):
    rev[i] = rev[i >> 1] >> 1
    if i & 1: rev[i] |= m2

def ntt_transform(a):
    for i in xrange(m):
        if i < rev[i]: a[i], a[rev[i]] = a[rev[i]], a[i]
    l = 2
    while l <= m:
        half, diff = l >> 1, m / l
        for i in xrange(0, m, l):
            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] = a[j] + v
                pw += diff
        l <<= 1

ntt_transform(f)
f = [fpow(x, n >> 1) for x in f]
ntt_transform(f)

inv_m = fpow(m, MOD - 2)
ans = mod_prod(sum(mod_prod(x, x) for x in f) % MODF, mod_prod(inv_m, inv_m))
print(int(ans))


import sys

import itertools

from collections import defaultdict

factorials = [1] * 19

for i in range(1, 19):
    factorials[i] = i * factorials[i - 1]

def cumsum(l):
    n = len(l)
    for i in range(1, n):
        l[i] += l[i-1]

def enum(l):

    global K, S

    options = itertools.product(*([(0, 1, 2)] * len(l)))

    d = defaultdict(lambda: [0] * (25 + 1))

    for opts in options:

        s = 0
        marks = 0
        for i, opt in enumerate(opts):

            if s > S:
                break

            if opt == 1:
                s += l[i]
            elif opt == 2:
                if l[i] <= 18:
                    s += factorials[l[i]]
                    marks += 1
                else:
                    s = S + 1

        if s <= S:
            d[s][marks] += 1

    return d

[n, K, S] = map(int, sys.stdin.next().split(' '))
l = sorted(map(int, sys.stdin.next().split(' ')))

p1 = enum(l[:(len(l) / 2)][::-1])
p2 = enum(l[(len(l) / 2):][::-1])

variants = 0
for s in p1:
    if S - s in p2:
        m1 = p1[s]
        m2 = p2[S - s]
        for (k1, c1) in enumerate(m1[:(K + 1)]):
            for (k2, c2) in enumerate(m2[:(K + 1 - k1)]):
                if k1 + k2 <= K:
                    variants += c1 * c2

print(variants)


import sys
I = lambda: [*map(int, sys.stdin.readline().split())]

n, a0, x, y, k, M = I()

big = 720720
mod = [0] * big
mod[a0 % big] += 1
tot = a0
for i in range(n - 1):
    a0 = (a0 * x + y) % M
    tot += a0
    mod[a0 % big] += 1

m = 998244353
total = 0
for i in range(k):
    total += tot
    if i < k - 1:
        tot *= n
        tot %= m
        total *= n
        total %= m
        change = [0] * big
        for j in range(big):
            x = mod[j]
            change[j - j % (i + 1)] += x
            change[j] -= x
            tot -= x * (j % (i + 1))
        for j in range(big):
            mod[j] = (n * mod[j] + change[j]) % m
print(total % m)


from decimal import *
import sys
getcontext().prec=100
n,m=input().split()
n=eval(n)
m=eval(m)
if n*m<=2:
    if n==2 and m==1:
        print(0.5)
    else:
        print(1)
    sys.exit()
n=Decimal(n)
m=Decimal(m)
a=m*n
b=n-1
b=b*b
ans=(a-1+(n-1)*(m-1))/(n*(a-1))
print(ans)


def c(n, k):
	if k > n:
		return 0
	a = b = 1
	for i in range(n - k + 1, n + 1):
		a *= i
	for i in range(1, k + 1):
		b *= i
	return a // b
a, b, k, t = map(int, input().split())
n, m, s = 2 * k + 1, 2 * t, 2 * k * t + b - a
ans, mod = 0, 1000000007
for i in range(m + 1):
	ans = (ans + [1, -1][i & 1] * c(m, i) * c(m + s - n * i, m)) % mod
print((pow(n, m, mod) - ans) % mod)


import sys
from array import array  # noqa: F401

def input():
    return sys.stdin.buffer.readline().decode('utf-8')

n, m, k = map(int, input().split())
adj = [[] for _ in range(n)]
dp = [[0] * (1 << n) for _ in range(1 << n)]

for u, v in (map(int, input().split()) for _ in range(m)):
    u, v = u - 1, v - 1
    adj[u].append(v)
    adj[v].append(u)
    dp[(1 << u) | (1 << v)][(1 << u) | (1 << v)] = 1

for v_set in range(1, 1 << n):
    leaf_set = v_set

    while leaf_set:
        for new_v in range(n):
            if (1 << new_v) & v_set:
                continue
            for bridge in adj[new_v]:
                if (1 << bridge) & v_set == 0:
                    continue
                new_leaf_set = (leaf_set | (1 << new_v)) & ~(1 << bridge)

                if (((1 << new_v) - 1) & new_leaf_set) == 0:
                    dp[v_set | (1 << new_v)][new_leaf_set] += dp[v_set][leaf_set]

        leaf_set = (leaf_set - 1) & v_set

ans = 0
bit = (1 << k) - 1
while bit < (1 << n):
    ans += dp[-1][bit]
    x = bit & -bit
    y = bit + x
    bit = (((bit & ~y) // x) >> 1) | y

print(ans)


dp=[0]*5010
dp[0]=1
n,m,k=map(int,input().split())
t=998244353
for i in range(k):
    for j in range(len(dp)-1, -1, -1):
        if j==0:dp[j]=0
        else:dp[j]=(dp[j-1]*(n-j+1)+dp[j]*j)%t
c=0
for i in range(k+1):
    c+=pow(m,max(n-i,0),t)*dp[i]
    c%=t
den=pow(m,n,t)
den=pow(den,t-2,t)
print((den*c)%t)


from math import gcd
def exd_gcd(a, b):
  # always return as POSITIVE presentation
  if a % b == 0:
    return 0, (1 if b > 0 else -1)
  x, y = exd_gcd(b, a % b)
  return y, x - a // b * y
def interval_intersect(a, b, c, d):
  if b <= a or d <= c:
    return 0
  if c < a:
    a, b, c, d = c, d, a, b
  if c < b:
    return min(b, d) - c
  else:
    return 0
def ceil(a, b):
  return (a + b - 1) // b

a1, b1, a2, b2, L, R = map(int, input().split())
g = gcd(a1, a2)
if (b1 - b2) % g != 0:
  print(0)
  exit(0)
k, l = exd_gcd(a1, a2)
l = -l
k *= (b2 - b1) // g
l *= (b2 - b1) // g
d1 = a2 // g
d2 = a1 // g
assert(k * a1 + b1 == l * a2 + b2)
arb = 3238
assert((k + arb * d1) * a1 + b1 == (l + arb * d2) * a2 + b2)
L1, R1 = ceil(max(0, ceil(L - b1, a1)) - k, d1), ((R - b1) // a1 - k) // d1
L2, R2 = ceil(max(0, ceil(L - b2, a2)) - l, d2), ((R - b2) // a2 - l) // d2
print(interval_intersect(L1, R1 + 1, L2, R2 + 1))


import sys
range = xrange
input = raw_input

MOD = 998244353

class sumseg:
    def __init__(self,n):
        m = 1
        while m<n:m*=2
        self.n = n
        self.m = m
        self.data = [0]*(n+m)
    def summa(self,l,r):
        l+=self.m
        r+=self.m
        s = 0
        while l<r:
            if l%2==1:
                s+=self.data[l]
                l+=1
            if r%2==1:
                r-=1
                s+=self.data[r]
            l//=2
            r//=2
        return s%MOD
    def add(self,ind,val):
        ind += self.m
        while ind>0:
            self.data[ind] = (self.data[ind]+val)%MOD
            ind//=2

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

switchers = [0]*(n+1)

for h in range(1,n+1):
    DP = sumseg(n+1)#[0]*(n+1)
    DP.add(0,2)#DP[0] = 2
    max_width = (k+h-1)//h - 1
    for i in range(1,n+1):
        a = max(i-max_width,0)
        b = i
        if a<b:
            DP.add(i,DP.summa(a,b))#DP[i] = sum(DP[a:b])%MOD

    switchers[h]=DP.summa(n,n+1)

for h in range(1,n):
    switchers[h] = (switchers[h]-switchers[h+1])%MOD

switchers2 = [0]*(n+1)

for h in range(1,n+1):
    DP = sumseg(n+1)#[0]*(n+1)
    DP.add(0,1)#DP[0] = 2
    max_width = h
    for i in range(1,n+1):
        a = max(i-max_width,0)
        b = i
        if a<b:
            DP.add(i,DP.summa(a,b))#DP[i] = sum(DP[a:b])%MOD

    switchers2[h]=DP.summa(n,n+1)

summa = 0
for h in range(1,n+1):
    summa = (summa + switchers[h]*switchers2[h])%MOD
print summa


#!/usr/bin/python

import sys
import math

primes = []
MAXN = 50000
hash = []

dp = dict()

def prime_test(v):
    for i in xrange(2,int(math.sqrt(v))+1):
        if v % i == 0:
            return False
    return True

def calc(v, k):
    if k >= MAXN:
        if (k <= v):
            return 1
        else:
            return 0
    else:
        if k > v:
            return 0
        elif k * k > v:
            return 1
        if (v,k) in dp:
            return dp[(v,k)]
        res = v / k
        for prime in primes:
            if prime >= k:
                break
            res -= calc(v/k, prime)
        dp[(v,k)] = res
        return res

if __name__=="__main__":
    hash = [-1] * MAXN
    for i in xrange(2,MAXN):
        if hash[i] == -1:
            primes.append(i)
            hash[i] = len(primes)-1
            v = i * i
            while (v < MAXN):
                hash[v] = -2
                v += i
    a,b,k = [int(v) for v in sys.stdin.readline().split(' ')]
    if (k < MAXN and hash[k] == -2) or (k >= MAXN and (not prime_test(k))):
        print 0
    else:
        print calc(b,k) - calc(a-1,k)


import sys
from collections import defaultdict as di
range = xrange
input = raw_input

inp = [int(x) for x in sys.stdin.read().split()]
ii = 0

n = inp[ii]
ii += 1
A = []
for _ in range(n):
    A.append(inp[ii:ii + n])
    ii += n

d = di(lambda:len(d))
for y in range(n):
    for x in range(n):
        for p in range(3):
            d[y,x,p]
m = len(d)

inf = 1000000000
large = 1000
mat = [[inf]*m for _ in range(m)]
for i in range(m):
    mat[i][i] = 0

for y in range(n):
    for x in range(n):
        for p in range(3):
            for q in range(p+1, 3):
                i = d[y,x,p]
                j = d[y,x,q]
                mat[i][j] = 1 + large
                mat[j][i] = 1 + large

# knight, bishop, rook
p = 0
for y in range(n):
    for x in range(n):
        i = d[y,x,p]
        for dy,dx in [(1,2),(2,1),(-1,2),(-2,1)]:
            x2 = x + dx
            y2 = y + dy
            if 0 <= x2 < n and 0 <= y2 < n:
                j = d[y2,x2,p]
                mat[i][j] = large
                mat[j][i] = large

p = 1
for y in range(n):
    for x in range(n):
        i = d[y,x,p]
        for dy,dx in [(1,1),(-1,1)]:
            y2 = y + dy
            x2 = x + dx
            while 0 <= x2 < n and 0 <= y2 < n:
                j = d[y2,x2,p]
                mat[i][j] = large
                mat[j][i] = large
                y2 += dy
                x2 += dx

p = 2
for y in range(n):
    for x in range(n):
        i = d[y,x,p]
        for dy,dx in [(0,1),(1,0)]:
            y2 = y + dy
            x2 = x + dx
            while 0 <= x2 < n and 0 <= y2 < n:
                j = d[y2,x2,p]
                mat[i][j] = large
                mat[j][i] = large
                y2 += dy
                x2 += dx

for k in range(m):
    for i in range(m):
        for j in range(m):
            if mat[i][k] + mat[k][j] < mat[i][j]:
                mat[i][j] = mat[i][k] + mat[k][j]

coords = [None]*(n**2)
for y in range(n):
    for x in range(n):
        coords[A[y][x] - 1] = (y,x)

best = [0,0,0]
for goal in range(1, n**2):
    y1,x1 = coords[goal - 1]
    y2,x2 = coords[goal]

    newbest = [inf,inf,inf]
    for p in range(3):
        for q in range(3):
            newbest[q] = min(newbest[q], best[p] + mat[d[y1,x1,p]][d[y2,x2,q]])
    best = newbest
ans = min(best)
print ans//large, ans%large


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")


p=10**9+7
import math
def prod(l):
    x=1
    for m in l:
        x*=m
    return x
n=int(input())
a=[]
k=int(math.log2(n))
x=n
while x>0:
    y=x//2
    a.append(x-y)
    x=y
c=[sum(a[i:]) for i in range(k+1)]
b=[n//(3*2**i)-n//(6*2**i) for i in range(k+1)]
d=[n//2**i-n//(3*2**i) for i in range(k+1)]
facs=[1]*(n+1)
for i in range(2,n+1):
    facs[i]=(i*facs[i-1])%p
start=k if n<3*(2**(k-1)) else 0
tot=0
for j in range(start,k+1):
    e=[a[i] for i in range(j)]+[d[j]]+[b[i] for i in range(j,k)]
    x=(facs[n]*prod(e))%p
    f=prod([sum(e[:i+1]) for i in range(k+1)])
    while f>1:
        x*=p//f+1
        f=(f*(p//f+1))%p
    tot+=x%p
print(tot%p)


n = int(input())

a = sorted(list(map(int, input().split())))

maxe = max(a)

cnt = []

cur, k, i = 1, 0, 0

while i < n:

    cnt.append(0)

    while i < n and a[i] < cur:

        cnt[2 * k] += 1

        i += 1

    cnt.append(0)

    while i < n and a[i] == cur:

        cnt[2 * k + 1] += 1

        i += 1

    k += 1

    cur *= 2

cnt.append(0)

cnt.append(0)

maxe = len(cnt) - 1

maxk = cnt[1]

was = False

for l in range(maxk):

    cur = 1

    while cnt[cur] > 0:

        cnt[cur] -= 1

        cur += 2

    cnt[cur] -= 1

    cursum = 0

    ok = True

    for t in range(maxe, 0, -1):

        cursum += cnt[t]

        if cursum > 0:

            ok = False

            break

    if ok:

        print(l + 1, end=" ")

        was = True

if not was:

    print(-1)

# Made By Mostafa_Khaled


start = raw_input().strip()
end = raw_input().strip()
k = int(raw_input())
if k == 0:
    if start == end:
       print 1
    else:
       print 0
    exit(0)
L = len(start)
ans = tmp = 0
mod = 10 ** 9 + 7
for i in xrange(1, L):
    if start[i:] + start[:i] == end:
        tmp += 1
if start == end:
    p = [1, 0]
    for i in xrange(k):
        p = [p[1], (p[0] * (L-1) + p[1] * (L-2)) % mod]
    ans += p[0]
if tmp > 0:
    p = [0, 1]
    for i in xrange(k):
        p = [p[1], (p[0] * (L-1) + p[1] * (L-2)) % mod]
    ans += p[0] * tmp % mod
print ans % mod


from math import factorial
MOD = 10**9+7

k = int(input())
bink = list(map(int, bin(k)[2:]))
N = len(bink)

# dp[i][j][k] = first i bits, j bases,
#   k = 1 if maxor matches k, 0 else
dp = [[[0,0] for j in range(i+2)] for i in range(N+1)]
dp[0][0][1] = 1
for i in range(1, N+1):
    for j in range(i+1):
        # k = 0 -> 0
        dp[i][j][0]+= 2**j * dp[i-1][j][0] # distribute
        if j: dp[i][j][0]+= dp[i-1][j-1][0] # new base
        # k = 1 -> 0
        odd = 2**(j-1) if j else 0
        even = 2**j - odd
        if bink[i-1] == 1:
            dp[i][j][0]+= even * dp[i-1][j][1] # distribute even
        # k = 1 -> 1
        if bink[i-1] == 0:
            dp[i][j][1]+= even * dp[i-1][j][1] # distribute even
        else:
            dp[i][j][1]+= odd * dp[i-1][j][1] # distribute odd
            if j: dp[i][j][1]+= dp[i-1][j-1][1] # new base
ans = sum(map(sum, dp[-1]))
print(ans % MOD)


MOD = 10 ** 9 + 7
n, m = input().split(' ')
n = int(n)
m = int(m)
ans = pow(2 * (n + 1), m, MOD)
ans = (ans * (n + 1 - m)) % MOD
ans = (ans * pow(n + 1, MOD - 2, MOD)) % MOD
print(ans)