N = 10 ** 6 * 2
MOD = 1000000007
prime = []
isPrime = [True for i in range(N)]
for i in range(2, N):
    if isPrime[i]:
        prime.append(i)
        for j in range(i * i, N, i):
            isPrime[j] = False
def phi(n):
    ans = 1
    for i in pf(n):
        ans *= pow(i[0],i[1]-1)*(i[0]-1)
    return ans
def pf(n):
    for i in prime:
        cnt = 0
        if n % i == 0:
            while n % i == 0:
                n //= i
                cnt += 1
            yield (i,cnt)
    if n > 1:
        yield (n,1)
n,k = map(int,input().split())
k = (k+1)//2
ans = n
for i in range(k):
    ans = phi(ans)
    if ans == 1:
        break
print(ans % MOD)


from math import sqrt, ceil

MAX_N = 10 ** 6 * 2

prime = []
isPrime = [True for i in range(MAX_N)]

for i in range(2, MAX_N):
    if isPrime[i]:
        prime.append(i)
        for j in range(i * i, MAX_N, i):
            isPrime[j] = False

def factor(a):
    divs = []
    for i in prime:
        cnt = 0
        while a % i == 0:
            a //= i
            cnt += 1

        if cnt:
            divs.append((i, cnt,))

    if a > 1:
        divs.append((a, 1,))

    return divs

def f(n):
    ans = 1
    for div in factor(n):
        ans *= div[0] ** (div[1] - 1) * (div[0] - 1)

    return ans

def g(n):
    return n

def F(n, k):
    cur = n
    for i in range(1, k + 1):
        #print(i)
        #print(factor(cur))
        if i == 1:
            cur = f(g(cur))
        elif i % 2 == 0:
            cur = g(cur)
        else:
            cur = f(cur)

        #print(i, cur)

        if cur == 1:
            break

    return cur % (10 ** 9 + 7)

n, k = [int(i) for i in input().split(' ')]
#print(factor(n - 1))
print (F(n, k))


MOD = 1000000007
def phi(n):
    res = n
    for i in range(2,int(n**(0.5)+1)):
        if n % i == 0:
            while n % i == 0:
                n = n//i
            res -= res//i
    if n > 1:
        res -= res//n
    return res

n,k = map(int,input().split())
k = (k+1)//2
ans = n
for _ in range(k):
    ans = phi(ans)
print(ans % MOD)


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)


from collections import defaultdict

def calcBinomials(N):
    global binom
    binom = [[0]*N for _ in range(N+1)]
    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)
print(res)


import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline()

# ------------------------------

def RL(): return map(int, sys.stdin.readline().split())
def RLL(): return list(map(int, sys.stdin.readline().split()))
def N(): return int(input())
def print_list(l):
    print(' '.join(map(str,l)))
# import heapq as hq
# import bisect as bs
# from collections import deque as dq
# from collections import defaultdict as dc
# from math import ceil,floor,sqrt
# from collections import Counter

n = N()
dic = [set() for _ in range(n+1)]
dic2 = [[] for _ in range(n+1)]
for _ in range(n-1):
    u,v = RL()
    dic[u].add(v)
    dic[v].add(u)
now = [1]
father,gress,leaf = [0]*(n+1),[0]*(n+1),[]
for i in range(2,n+1):
    gress[i] = len(dic[i])-1
    if gress[i]==0:
        leaf.append(i)
while now:
    node = now.pop()
    dic[node].discard(father[node])
    for child in dic[node]:
        father[child] = node
        now.append(child)
res = 0
ans = [0]*(n+1)
while leaf:
    p = leaf.pop()
    f = father[p]
    if not dic2[p]:
        dic2[f].append(p)
    else:
        t = len(dic2[p])
        res+=t*2
        while t>2:
            t-=2
            a,b = dic2[p].pop(),dic2[p].pop()
            ans[a] = b
            ans[b] = a
        if t==1:
            a = dic2[p].pop()
            ans[a] = p
            ans[p] = a
        else:
            a,b = dic2[p].pop(),dic2[p].pop()
            ans[a] = p
            ans[p] = b
            ans[b] = a
    gress[f]-=1
    if gress[f]==0:
        leaf.append(f)
p = 1
if not dic2[p]:
    res+=2
    m = dic[p].pop()
    b = ans[m]
    a = ans[b]
    if a!=m:
        ans[a] = b
        ans[m] = p
        ans[p] = m
    else:
        ans[p] = m
        ans[m] = b
        ans[b] = p
else:
    t = len(dic2[p])
    res+=t*2
    while t>2:
        t-=2
        a,b = dic2[p].pop(),dic2[p].pop()
        ans[a] = b
        ans[b] = a
    if t==1:
        a = dic2[p].pop()
        ans[a] = p
        ans[p] = a
    else:
        a,b = dic2[p].pop(),dic2[p].pop()
        ans[a] = p
        ans[p] = b
        ans[b] = a
print(res)
print_list(ans[1:])


import sys
range = xrange
input = raw_input

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

n = inp[ii]; ii += 1
coupl = [[] for _ in range(n)]
for _ in range(n - 1):
    u = inp[ii] - 1; ii += 1
    v = inp[ii] - 1; ii += 1
    coupl[u].append(v)
    coupl[v].append(u)

P = [-1] * n
root = 0
bfs = [root]
P[root] = root
for node in bfs:
    for nei in coupl[node]:
        del coupl[nei][coupl[nei].index(node)]
        bfs.append(nei)
        P[nei] = node

ans = list(range(n));cost = 0
for node in reversed(bfs):
    if ans[node] != node:continue
    cost += 2
    if node != root:p = P[node]
    else:p = coupl[node][0]
    ans[node],ans[p] = ans[p],ans[node]
print cost;print ' '.join(str(x + 1) for x in ans)


import sys
range = xrange
input = raw_input

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

n = inp[ii]; ii += 1
coupl = [[] for _ in range(n)]
for _ in range(n - 1):
    u = inp[ii] - 1; ii += 1
    v = inp[ii] - 1; ii += 1
    coupl[u].append(v)
    coupl[v].append(u)

P = [-1] * n
root = 0
bfs = [root]
P[root] = root
for node in bfs:
    for nei in coupl[node]:
        del coupl[nei][coupl[nei].index(node)]
        bfs.append(nei)
        P[nei] = node

ans = list(range(n))
cost = 0

for node in reversed(bfs):
    if ans[node] != node:
        continue
    cost += 2
    if node != root:
        p = P[node]
    else:
        p = coupl[node][0]
    ans[node],ans[p] = ans[p],ans[node]

print cost
print ' '.join(str(x + 1) for x in ans)


import sys;range = xrange;input = raw_input;inp = [int(x) for x in sys.stdin.read().split()]; ii = 0;n = inp[ii]; ii += 1;coupl = [[] for _ in range(n)]
for _ in range(n - 1):u = inp[ii] - 1; ii += 1;v = inp[ii] - 1; ii += 1;coupl[u].append(v);coupl[v].append(u)
P = [-1] * n;root = 0;bfs = [root];P[root] = root
for node in bfs:
    for nei in coupl[node]:
        del coupl[nei][coupl[nei].index(node)]
        bfs.append(nei);P[nei] = node
ans = list(range(n));cost = 0
for node in reversed(bfs):
    if ans[node] != node:continue
    cost += 2
    if node != root:p = P[node]
    else:p = coupl[node][0]
    ans[node],ans[p] = ans[p],ans[node]
print cost;print ' '.join(str(x + 1) for x in ans)


import sys
range = xrange
input = raw_input

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

n = inp[ii]; ii += 1
coupl = [[] for _ in range(n)]
for _ in range(n - 1):
    u = inp[ii] - 1; ii += 1
    v = inp[ii] - 1; ii += 1
    coupl[u].append(v)
    coupl[v].append(u)

P = [-1] * n
root = 0
bfs = [root]
P[root] = root
for node in bfs:
    for nei in coupl[node]:
        del coupl[nei][coupl[nei].index(node)]
        bfs.append(nei)
        P[nei] = node

ans = [-1] * n

cost = - 2 * n

houses = [[i] for i in range(n)]
people = [[i] for i in range(n)]
for node in reversed(bfs):
    H = houses[node]
    Pe = people[node]

    cost += len(H) + len(Pe)

    Pe.reverse()
    if len(H) > 1 or len(Pe) > 1:
        while H and Pe:
            house = H.pop()
            p = Pe.pop()
            ans[house] = p

    houses[P[node]] += H
    people[P[node]] += reversed(Pe)

print cost
print ' '.join(str(x + 1) for x in ans)


def readints():
  return map(int, raw_input().split())

def dn(x):
  k=0
  t=x-1
  while t:
    t/=10
    k+=1
  return k

def _li(x, dn):
  ret=[]
  for _ in xrange(dn):
    ret.append(x%10)
    x/=10
  return ret

def li(h,m):
  return _li(h,dh)+_li(m,dm)

def dif(h1,m1,h2,m2):
  return sum(v1!=v2 for v1,v2 in zip(li(h1,m1), li(h2,m2)) )

pow10=[10**i for i in xrange(12,-1,-1)]

memo={}

def g(h,m):
  if (h,m) in memo:return memo[(h,m)]
  ret=f(0,1,h,m)+(1>=k)
  memo[(h,m)]=ret
  return ret

def f(h1,m1,h2,m2):
  if (h1,m1)==(h2, m2):ret = 0
  elif (h1,m1)>(h2,m2):
    ret = f(h1, m1, H-1, M-1) + f(0, 0, h2, m2) + ( dif(H-1,M-1,0,0) >= k)
  else:
    for hh in pow10:
      if (h1+hh, m1)<=(h2, m2) and h1/hh%10!=9:
        ret = g(hh,0)+f(h1+hh, m1, h2, m2)
        break
    else:
      for mm in pow10:
        if m1+mm<M and (h1,m1+mm)<=(h2,m2) and m1/mm%10!=9:
          ret = g(0,mm) + f(h1,m1+mm, h2, m2)
          break
      else:
        nt=h1*M+m1+1
        nh,nm=nt/M,nt%M
        ret = ( dif(h1,m1,nh,nm)>=k ) + f(nh,nm,h2,m2)
  #print h1,m1,h2,m2,ret
  return ret

def main():
  global H,M,k,dh,dm
  H,M,k=readints()
  h1,m1=readints()
  h2,m2=readints()
  """H,M,k=24,60,1
  h1,m1=0,0
  h2,m2=23,59
  H,M,k=24,60,3
  h1,m1=23,59
  h2,m2=23,59"""
  dh=dn(H)
  dm=dn(M)
  print f(h1,m1,h2,m2)

main()


def readints():
  return map(int, raw_input().split())

def dn(x):
  k=0
  t=x-1
  while t:
    t/=10
    k+=1
  return k

def _li(x, dn):
  ret=[]
  for _ in xrange(dn):
    ret.append(x%10)
    x/=10
  return ret

def li(h,m):
  return _li(h,dh)+_li(m,dm)

def dif(h1,m1,h2,m2):
  return sum(v1!=v2 for v1,v2 in zip(li(h1,m1), li(h2,m2)) )

pow10=[10**i for i in xrange(12,-1,-1)]

memo={}

def g(h,m):
  if (h,m) in memo:return memo[(h,m)]
  ret=f(0,1,h,m)+(1>=k)
  memo[(h,m)]=ret
  return ret

def f(h1,m1,h2,m2):
  if (h1,m1)==(h2, m2):ret = 0
  elif (h1,m1)>(h2,m2):
    ret = f(h1, m1, H-1, M-1) + f(0, 0, h2, m2) + ( dif(h1,m1,h2,m2) >= k)
  else:
    for hh in pow10:
      if (h1+hh, m1)<=(h2, m2) and h1/hh%10!=9:
        ret = g(hh,0)+f(h1+hh, m1, h2, m2)
        break
    else:
      for mm in pow10:
        if m1+mm<M and (h1,m1+mm)<=(h2,m2) and m1%mm%10!=9:
          ret = g(0,mm) + f(h1,m1+mm, h2, m2)
          break
      else:
        nt=h1*M+m1+1
        nh,nm=nt/M,nt%M
        ret = ( dif(h1,m1,nh,nm)>=k ) + f(nh,nm,h2,m2)
  #print h1,m1,h2,m2,ret
  return ret

def main():
  global H,M,k,dh,dm
  H,M,k=readints()
  h1,m1=readints()
  h2,m2=readints()
  """H,M,k=24,60,1
  h1,m1=0,0
  h2,m2=23,59
  H,M,k=24,60,3
  h1,m1=23,59
  h2,m2=23,59"""
  dh=dn(H)
  dm=dn(M)
  print f(h1,m1,h2,m2)

main()


def readints():
  return map(int, raw_input().split())

def dn(x):
  k=0
  t=x-1
  while t:
    t/=10
    k+=1
  return k

def _li(x, dn):
  ret=[]
  for _ in xrange(dn):
    ret.append(x%10)
    x/=10
  return ret

def li(h,m):
  return _li(h,dh)+_li(m,dm)

def dif(h1,m1,h2,m2):
  return sum(v1!=v2 for v1,v2 in zip(li(h1,m1), li(h2,m2)) )

pow10=[10**i for i in xrange(12,-1,-1)]

memo={}

def g(h,m):
  if (h,m) in memo:return memo[(h,m)]
  ret=f(0,1,h,m)+(1>=k)
  memo[(h,m)]=ret
  return ret

def f(h1,m1,h2,m2):
  if (h1,m1)==(h2, m2):ret = 0
  elif (h1,m1)>(h2,m2):
    ret = f(h1, m1, H-1, M-1) + f(0, 0, h2, m2) + ( dif(H-1,M-1,0,0) >= k)
  else:
    for hh in pow10:
      if (h1+hh, m1)<=(h2, m2) and h1/hh%10!=9:
        ret = g(hh,0)+f(h1+hh, m1, h2, m2)
        break
    else:
      for mm in pow10:
        if m1+mm<M and (h1,m1+mm)<=(h2,m2) and m1%mm%10!=9:
          ret = g(0,mm) + f(h1,m1+mm, h2, m2)
          break
      else:
        nt=h1*M+m1+1
        nh,nm=nt/M,nt%M
        ret = ( dif(h1,m1,nh,nm)>=k ) + f(nh,nm,h2,m2)
  #print h1,m1,h2,m2,ret
  return ret

def main():
  global H,M,k,dh,dm
  H,M,k=readints()
  h1,m1=readints()
  h2,m2=readints()
  """H,M,k=24,60,1
  h1,m1=0,0
  h2,m2=23,59
  H,M,k=24,60,3
  h1,m1=23,59
  h2,m2=23,59"""
  dh=dn(H)
  dm=dn(M)
  print f(h1,m1,h2,m2)

main()


from random import*
import sys
sys.setrecursionlimit(10000)
opr = ['#', '^', '&', '$']
namespace = { "res" : (False, "res") }
rules = dict()
lookup = dict()
cnt = -1
def get_tag(var):
    if var in namespace:
        return namespace[var][1]
    else:
        return var
N = int(raw_input())
for _ in range(N):
    lval, rval = raw_input().split('=')
    for c in opr:
        if c in rval:
            arg1, arg2 = map(get_tag, rval.split(c))
            rule = (arg1, arg2, c)
            if rule in rules:
                namespace[lval] = (True, rules[rule])
            else:
                cnt += 1
                namespace[lval] = (True, cnt)
                rules[rule] = cnt
                lookup[cnt] = rule
            break
    else:
        if rval in namespace:
            namespace[lval] = namespace[rval]
        else:
            namespace[lval] = (False, rval)
if namespace["res"] == (False, "res"):
    print("0")
    exit()
program = []
myvars = dict()
def reserve():
    return ''.join(chr(randint(0, 25) + ord('a')) for _ in range(4))
def implement(rule, final):
    if type(rule) == str:
        return rule
    elif rule in myvars:
        return myvars[rule]
    else:
        if final:
            name = "res"
        else:
            name = reserve()
        myvars[rule] = name
        arg1, arg2, op = lookup[rule]
        var1, var2 = implement(arg1, False), implement(arg2, False)
        program.append(name + "=" + var1 + op + var2)
        return name
seed(123)
if namespace["res"][0]:
    implement(namespace["res"][1], True)
else:
    program.append("res=" + namespace["res"][1])
print(len(program))
print("\n".join(program))


from random import seed, randint
import sys
sys.setrecursionlimit(10000)

opr = ['#', '^', '&', '$']
namespace = { "res" : (False, "res") }
rules = dict()
lookup = dict()
cnt = -1

def get_tag(var):
    if var in namespace:
        return namespace[var][1]
    else:
        return var

N = int(input())
for _ in range(N):
    lval, rval = input().split('=')
    for c in opr:
        if c in rval:
            arg1, arg2 = map(get_tag, rval.split(c))
            rule = (arg1, arg2, c)
            if rule in rules:
                namespace[lval] = (True, rules[rule])
            else:
                cnt += 1
                namespace[lval] = (True, cnt)
                rules[rule] = cnt
                lookup[cnt] = rule
            break
    else:
        if rval in namespace:
            namespace[lval] = namespace[rval]
        else:
            namespace[lval] = (False, rval)

if namespace["res"] == (False, "res"):
    print("0")
    exit()

program = []
myvars = dict()

def reserve():
    return ''.join(chr(randint(0, 25) + ord('a')) for _ in range(4))

def implement(rule, final):
    if type(rule) == str:
        return rule
    elif rule in myvars:
        return myvars[rule]
    else:
        if final:
            name = "res"
        else:
            name = reserve()
        myvars[rule] = name
        arg1, arg2, op = lookup[rule]
        var1, var2 = implement(arg1, False), implement(arg2, False)
        program.append(name + "=" + var1 + op + var2)
        return name

seed(123)
if namespace["res"][0]:
    implement(namespace["res"][1], True)
else:
    program.append("res=" + namespace["res"][1])
print(len(program))
print("\n".join(program))

#print(namespace)
#print(rules)


from random import seed, randint

opr = ['#', '^', '&', '$']
namespace = { "res" : (False, "res") }
rules = dict()
lookup = dict()
cnt = -1

def get_tag(var):
    if var in namespace:
        return namespace[var][1]
    else:
        return var

N = int(input())
for _ in range(N):
    lval, rval = input().split('=')
    for c in opr:
        if c in rval:
            arg1, arg2 = map(get_tag, rval.split(c))
            rule = (arg1, arg2, c)
            if rule in rules:
                namespace[lval] = (True, rules[rule])
            else:
                cnt += 1
                namespace[lval] = (True, cnt)
                rules[rule] = cnt
                lookup[cnt] = rule
            break
    else:
        if rval in namespace:
            namespace[lval] = namespace[rval]
        else:
            namespace[lval] = (False, rval)

if namespace["res"] == (False, "res"):
    print("0")
    exit()

program = []
myvars = dict()

def reserve():
    return ''.join(chr(randint(0, 25) + ord('a')) for _ in range(4))

def implement(rule, final):
    if type(rule) == str:
        return rule
    elif rule in myvars:
        return myvars[rule]
    else:
        if final:
            name = "res"
        else:
            name = reserve()
        myvars[rule] = name
        arg1, arg2, op = lookup[rule]
        var1, var2 = implement(arg1, False), implement(arg2, False)
        program.append(name + "=" + var1 + op + var2)
        return name

seed(123)
if namespace["res"][0]:
    implement(namespace["res"][1], True)
else:
    program.append("res=" + namespace["res"][1])
print(len(program))
print("\n".join(program))

#print(namespace)
#print(rules)


from random import seed, randint

opr = ['#', '^', '&', '$']
namespace = { "res" : (False, "res") }
rules = dict()
lookup = dict()
cnt = -1

def get_tag(var):
    if var in namespace:
        return namespace[var][1]
    else:
        return var

N = int(input())
for _ in range(N):
    lval, rval = input().split('=')
    for c in opr:
        if c in rval:
            arg1, arg2 = map(get_tag, rval.split(c))
            rule = (arg1, arg2, c)
            if rule in rules:
                namespace[lval] = (True, rules[rule])
            else:
                cnt += 1
                namespace[lval] = (True, cnt)
                rules[rule] = cnt
                lookup[cnt] = rule
            break
    else:
        if rval in namespace:
            namespace[lval] = namespace[rval]
        else:
            namespace[lval] = (False, rval)

if namespace["res"] == (False, "res"):
    print("0")
    exit()

program = []
myvars = dict()

def reserve():
    return ''.join(chr(randint(0, 25) + ord('a')) for _ in range(4))

def implement(rule, final):
    if type(rule) == str:
        return rule
    elif rule in myvars:
        return myvars[rule]
    else:
        if final:
            name = "res"
        else:
            name = reserve()
        myvars[rule] = name
        arg1, arg2, op = lookup[rule]
        var1, var2 = implement(arg1, False), implement(arg2, False)
        program.append(name + "=" + var1 + op + var2)
        return name

seed(123)
implement(namespace["res"][1], True)
print(len(program))
print("\n".join(program))


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

maxe = max(a)
cnt = []
cur = 1
k = 0
i = 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)


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


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)


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

def binom(n, k):
    if k > n-k: return binom(n, n-k)
    res = 1
    for i in range(k): res = res*(n-i)//(i+1)
    return res

def comp_ones_vecs(k, n):
    # k ones, n vectors
    if k < n: return 0
    ans = 0
    for Z in range(n):
        ans+= (-1)**Z * binom(n,Z) * (n-Z)**k
    return ans // factorial(n)

def comp_ones_frees_vecs(k, f, n):
    # k prefixed ones, f digits of freedom, n vectors
    ans = 0
    for i in range(f+1):
        ans+= comp_ones_vecs(k+i, n) * binom(f, i)
    return ans

def comp_ones_frees(k, f):
    # k prefixed ones, f digits of freedom
    ans = 0
    for n in range(1, k+f+1):
        ans+= comp_ones_frees_vecs(k, f, n)
    return ans

k = int(input())
bink = list(map(int, bin(k)[2:]))
ans = 1 + comp_ones_frees(sum(bink), 0)
ones = 0
for i in range(len(bink)):
    if bink[i] == 0: continue
    ans+= comp_ones_frees(ones, len(bink)-i-1)
    ones+= 1
print(ans % MOD)


n = int(input())
sz = len(str(n))
def get(x):
    ans = 0
    nw = 1
    x1 = x
    for i in range(sz):
        x = x1
        if x < nw:
            while x < nw: x *= 10
            x -= 1 #тк сука [1;x)
        else:
            while x >= nw * 10: x //= 10
        x = min(x, n)
        ans += x - nw + 1
        nw *= 10
    return ans

MOD = 998244353

ans = 0
i = 1
while i <= n:
    l = i
    r = min(n, 10 ** (len(str(i))) - 1) + 1
    nw = (get(i) - i) // MOD
    while r - l > 1:
        mid = (l + r) // 2
        x = (get(mid) - mid) // MOD
        if nw == x:
            l = mid
        else:
            r = mid
    ans += nw * (r - i)
    # i += 1
    i = r
print(ans * -MOD)


F = {}

def f(k):
    if not k in F:
        s, i, j = 0, 4, 4
        while i <= k:
            s += i * f(k / i)
            i += j + 1
            j += 2
        F[k] = (k * (k + 1)) / 2 - s
    return F[k]

def g(k):
    s, i, j = 0, 4, 4
    while i <= k:
        s += (i - 1) * f(k / i)
        i += j + 1
        j += 2
    return (k * (k + 1)) / 2 - s

a, n = map(int, raw_input().split())
print g(a + n - 1) - g(a - 1)


p=10**9+7
def S(x):
	if x==0:
		return 0
	elif x==1:
		return 4
	elif x&1:
		return 11*pow(3,x/2,p)-7
	else:
		return 19*pow(3,x/2-1,p)-7
def G(x):
	return (S(x)+S(x+1>>1))*pow(2,p-2,p)%p;
l,r=map(int,raw_input().split())
print (G(r)-G(l-1))%p;


p=10**9+7
def S(x):
 if x==0:
  return 0
 elif x==1:
  return 4
 elif x&1:
  return 11*pow(3,x/2,p)-7
 else:
  return 19*pow(3,x/2-1,p)-7
def G(x):
 return (S(x)+S(x+1>>1))*pow(2,p-2,p)%p;
l,r=map(int,raw_input().split())
print (G(r)-G(l-1))%p;


import sys
range = xrange
input = raw_input

P = []
for i in range(2, 59):
    if not any(i % p == 0 for p in P):
        P.append(i)

numbs = []
for i in range(1, 59):
    x = 0
    for j in range(len(P)):
        if i % P[j] == 0:
            x += 1 << j
    numbs.append(x)

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

states = 1 << 17

DP = [[0]*states]
how = []

for i in range(n):
    a = A[i]
    aa = abs(a - 1)

    oldDP = DP[-1]

    newDP = [d + aa for d in oldDP]
    DP.append(newDP)

    newHow = [1]*states
    how.append(newHow)

    for x in range(2, 59):
        xx = abs(a - x)

        y = numbs[x - 1]
        yy = ~y

        s = (states - 1) & yy
        while s:
            if newDP[s ^ y] > oldDP[s] + xx:
                newDP[s ^ y] = oldDP[s] + xx
                newHow[s ^ y] = x
            s = (s - 1) & yy

        if newDP[s ^ y] > oldDP[s] + xx:
            newDP[s ^ y] = oldDP[s] + xx
            newHow[s ^ y] = x

key = min(range(states), key = DP[-1].__getitem__)
ans = []
for newHow in reversed(how):
    x = newHow[key]
    ans.append(x)
    key &= ~numbs[x - 1]

print ' '.join(str(x) for x in reversed(ans))


import sys
input = sys.stdin.readline

from functools import lru_cache

k, M = map(int, input().split())

MOD = M

def modmul(x, y, c = 0):
    return (x * y + c) % MOD

mod_mul = modmul

def inv(x):
    return pow(x, MOD - 2, MOD)

MAX = 10 ** 6

fact = [1]
for i in range(1, MAX):
    fact.append(modmul(i, fact[i-1]))

invfact = [1] * (MAX)
invfact[MAX - 1] = inv(fact[MAX - 1])
for i in range(MAX - 2, -1, -1):
    invfact[i] = modmul(i + 1, invfact[i+1])

def comb(x, y):
    assert 0 <= y <= x

    return modmul(fact[x], modmul(invfact[y], invfact[x - y]))

def invcomb(x, y):
    return modmul(invfact[x], modmul(fact[y], fact[x - y]))

def invs(x):
    return modmul(fact[x - 1], invfact[x])

def count(a, b):
    if a + b == 0:
        return 1
    return modmul(a, fact[a + b - 1])

n = k

pn1 = [1]
for i in range(5000):
    pn1.append(modmul(pn1[-1], n - 1))

out = 0
for i in range(1, n):

    pni = [1]
    for _ in range(5000):
        pni.append(modmul(pni[-1], n - i))

    for j in range(i + 1):
        if n - i - j < 0:
            continue

        stab = comb(n, i)
        app = modmul(comb(i, j), comb(n - i, n - i - j))
        order = count(j, n - i - j)
        sao = modmul(modmul(stab, app), order)
        #sao = 1

        #u1 = pow(n - i, i - j, M)
        #u2 = pow(n - 1, j, M)
        u1 = pni[i - j]
        u2 = pn1[j]
        u = modmul(u1, u2)
        #u = 1

        #print(i, j, stab, app, order, u1, u2)

        out += modmul(sao, u)

print(out % M)


import sys
input = sys.stdin.readline

from functools import lru_cache

k, M = map(int, input().split())

MOD = M

def modmul(x, y, c = 0):
    return (x * y + c) % MOD

mod_mul = modmul

def inv(x):
    return pow(x, MOD - 2, MOD)

MAX = 10 ** 6

fact = [1]
for i in range(1, MAX):
    fact.append(modmul(i, fact[i-1]))

invfact = [1] * (MAX)
invfact[MAX - 1] = inv(fact[MAX - 1])
for i in range(MAX - 2, -1, -1):
    invfact[i] = modmul(i + 1, invfact[i+1])

def comb(x, y):
    assert 0 <= y <= x

    return modmul(fact[x], modmul(invfact[y], invfact[x - y]))

def invcomb(x, y):
    return modmul(invfact[x], modmul(fact[y], fact[x - y]))

def invs(x):
    return modmul(fact[x - 1], invfact[x])

@lru_cache(maxsize = None)
def count(a, b):
    if b == 0:
        if a == 0:
            return 1
        return modmul(a, count(a - 1, 0))

    if a:
        o1 = modmul(a, count(a, b - 1))
    else:
        o1 = 0

    if b > 1:
        o2 = modmul(b - 1, count(a, b - 1))
    else:
        o2 = 0

    return (o1 + o2) % M

for i in range(5000):
    for j in range(5000):
        count(i, j)

n = k

out = 0
for i in range(1, n):
    for j in range(i + 1):
        if n - i - j < 0:
            continue

        stab = comb(n, i)
        app = modmul(comb(i, j), comb(n - i, n - i - j))

        order = count(j, n - i - j)

        u1 = pow(n - i, i - j, M)
        u2 = pow(n - 1, j, M)

        #print(i, j, stab, app, order, u1, u2)

        out += modmul(modmul(modmul(stab, app), order), modmul(u1, u2))

print(out % M)


import sys
input = sys.stdin.readline

from functools import lru_cache

k, M = map(int, input().split())

MOD = M

def modmul(x, y, c = 0):
    return (x * y + c) % MOD

mod_mul = modmul

def inv(x):
    return pow(x, MOD - 2, MOD)

MAX = 10 ** 6

fact = [1]
for i in range(1, MAX):
    fact.append(modmul(i, fact[i-1]))

invfact = [1] * (MAX)
invfact[MAX - 1] = inv(fact[MAX - 1])
for i in range(MAX - 2, -1, -1):
    invfact[i] = modmul(i + 1, invfact[i+1])

def comb(x, y):
    assert 0 <= y <= x

    return modmul(fact[x], modmul(invfact[y], invfact[x - y]))

def invcomb(x, y):
    return modmul(invfact[x], modmul(fact[y], fact[x - y]))

def invs(x):
    return modmul(fact[x - 1], invfact[x])

@lru_cache(maxsize = None)
def count(a, b):
    if b == 0:
        if a == 0:
            return 1
        return modmul(a, count(a - 1, 0))

    if a:
        o1 = modmul(a, count(a, b - 1))
    else:
        o1 = 0

    if b > 1:
        o2 = modmul(b - 1, count(a, b - 1))
    else:
        o2 = 0

    return (o1 + o2) % M

n = k

out = 0
for i in range(1, n):
    for j in range(i + 1):
        if n - i - j < 0:
            continue

        stab = comb(n, i)
        app = modmul(comb(i, j), comb(n - i, n - i - j))

        order = count(j, n - i - j)

        u1 = pow(n - i, i - j, M)
        u2 = pow(n - 1, j, M)

        #print(i, j, stab, app, order, u1, u2)

        out += modmul(modmul(modmul(stab, app), order), modmul(u1, u2))

print(out % M)


import sys
range = xrange
input = raw_input

MOD = 998244353

import __pypy__
modmul = __pypy__.intop.int_mulmod
mo = lambda a,b: modmul(a,b,MOD)
po = lambda a,b: pow(a,b,MOD)

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

fac = [1]
for i in range(1,big):
    fac.append(mo(fac[-1], i))

invfac = [1]
for i in range(1,big):
    invfac.append(mo(invfac[-1], modinv[i]))

def choose(n,k):
    return mo(mo(fac[n], invfac[k]), invfac[n-k])

def par(x):
    return -1 if x & 1 else 1

n = int(input())

ans = 0
extra = 0
for i in range(1, n + 1):
    base = po(3, n - i)
    tmp = po(-base + 1, n) - po(-base, n)
    ans = (ans + par(i + 1 + n) * mo(choose(n, i), tmp)) % MOD

    exp = modmul(n, n - i, MOD - 1) + i
    extra = (extra + par(i + 1) * mo(choose(n, i), po(3, exp))) % MOD

print (3 * ans + 2 * extra) % MOD


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 sys import stdout

class Mock:
    def __init__(self, cap, a):
        self.a, self.cap = a, cap
        self.n, self.q = len(a), []

    def ask(self, i):
        result = self.a[i] in self.q
        self.q.append(self.a[i])
        if len(self.q) > self.cap:
            self.q = self.q[1:]
        return result

    def reset(self):
        self.q = []

    def out(self, result):
        print('!', result)

class IO:
    def __init__(self):
        self.n, self.cap = map(int, input().split())

    def ask(self, i):
        print('?', i + 1)
        stdout.flush()
        return input() == 'Y'

    def reset(self):
        print('R')
        stdout.flush()

    def out(self, result):
        print('!', result)

def solve(io):
    n, cap = io.n, io.cap
    size = cap + 1 >> 1
    count = n // size
    removed = [False] * n
    for d in range(1, count):
      for r in range(min(d, count - d)):
        for i in range(r, count, d):
          for j in range(i * size, (i + 1) * size):
            if not removed[j] and io.ask(j):
              removed[j] = True
      io.reset()
    return removed.count(False)

# io = Mock(2, [1, 4, 1, 3])
# io.out(solve(io))

# io = Mock(8, [1, 2, 3, 4, 5, 6, 6, 6])
# io.out(solve(io))

io = IO()
io.out(solve(io))


import sys

def ask(s):
    print(s)
    sys.stdout.flush()

def solve():
    n, k = map(int, input().split())

    head = [True] * (n+1)
    head[0] = False

    if k == 1:
        N = 2*int(n/(k+1))
    else:
        N = 2*int(n/k)
    #print(N)

    for i in range(1,N+1):
        cl = (i-1)*int((k+1)/2)+1
        cr = i*int((k+1)/2)
        #print("_",cl,cr)
        for j in range(1,i):
            l = (j-1)*int((k+1)/2)+1
            r = j*int((k+1)/2)
            #print("__",l,r)
            ask("R")
            for shop in range(l,r+1):
                ask("? "+str(shop))
                ans = input()
                if(ans == "Y"):
                    head[shop] = False
            for shop in range(cl,cr+1):
                ask("? "+str(shop))
                ans = input()
                if(ans == "Y"):
                    head[shop] = False

    ans = 0
    #print(head)
    ans = sum(map(int, head))
    ask("! "+str(ans))

solve()


MOD = 1000000007
def isSubset(a, b):
    return (a & b) == a
def isIntersect(a, b):
    return (a & b) != 0
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
    n = int(input())
    a = list(map(int, input().split()))
    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
    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
    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)
                ans = (ans * cnt) % MOD
                ans = (ans * c[curLen + sz][sz]) % MOD
                curLen += sz
    print(ans)
if __name__ == "__main__":
    main()


def Solve(x,B):
    if((X,x,B) in Mem):
        return Mem[(X,x,B)]
    if(len(B)>X):
        return False
    if(x==len(L)):
        return True
    if(Form(L[x],B)):
        A=list(B)
        for e in range(len(B)):
            r=A[e]
            A[e]=L[x]
            if(Solve(x+1,tuple(sorted(A)))):
                Mem[(X,x,B)]=True
                return True
            A[e]=r
        A+=[L[x]]
        if(Solve(x+1,tuple(sorted(A)))):
            Mem[(X,x,B)]=True
            return True
    Mem[(X,x,B)]=False
    return False

def Form(x,B):
    for i in range(len(B)):
        for j in range(i,len(B)):
            if(B[i]+B[j]==x):
                return True
    return False

n=int(input())
L=list(map(int,input().split()))
done=False
Mem={}
for X in range(1,n+1):
    if(Solve(1,(L[0],))):
        print(X)
        done=True
        break
if(not done):
    print(-1)


import sys
from math import gcd
# sys.setrecursionlimit(10000)

class BinaryField:
    def __init__(self, s):
        """Given a binary string, return a BinaryField element.
        Input:
        s: Has to take one of the following form:
           1. A binary string, with MSB as the highest degree polynomial
           2. An integer, with MSB as the highest degree polynomial"""
        if type(s) == int:
            self.poly = s

        else:
            self.poly = 0

            for c in s:
                self.poly = (self.poly << 1) + int(c)

        if self.poly == 0:
            self.deg = float('-inf')
        else:
            self.deg = len(bin(self.poly)) - 3

    def __repr__(self):
        return f'BinaryField(poly={bin(self.poly)[2:]}, deg={self.deg})'

    def __eq__(self, other):
        return self.poly == other.poly

    def __add__(self, other):
        return BinaryField(self.poly ^ other.poly)

    def __mul__(self, other):
        temp = other.poly
        answer = 0
        align = self.poly

        while temp:
            if temp & 1:
                answer ^= align

            align <<= 1
            temp >>= 1

        return BinaryField(answer)

    def __truediv__(self, other):
        if other.poly == 0:
            raise ZeroDivisionError

        answer = 0
        temp = self.poly

        for d in range(max(self.deg - other.deg, 0), -1, -1):
            if temp & (1 << (other.deg + d)):
                answer += (1 << d)
                temp ^= (other.poly << d)

        return BinaryField(answer)

    def __mod__(self, other):
        if other.poly == 0:
            raise ZeroDivisionError

        answer = 0
        temp = self.poly

        for d in range(max(self.deg - other.deg, 0), -1, -1):
            if temp & (1 << (other.deg + d)):
                answer += (1 << d)
                temp ^= (other.poly << d)

        return BinaryField(temp)

    def square(self):
        """Returns the square of the polynomial itself.
        Faster than a * a"""
        answer = 0
        temp = self.poly

        while temp:
            lsb = temp & (-temp)
            answer += lsb ** 2

            temp -= lsb

        return BinaryField(answer)

    def powmod(self, exp, mod):
        """Return (self**exp) % mod
        Inputs:
        exp: An integer power
        mod: A BinaryField element representing the modulus"""
        answer, temp = BinaryField(1), self

        while exp:
            if exp & 1:
                answer = (answer * temp) % mod

            exp >>= 1
            temp = temp.square() % mod

        return answer

    @staticmethod
    def gcd(poly1, poly2):
        """Given two BinaryField elements, return its gcd
        Input:
        poly1, poly2: two BinaryField elements.
        Output:
        The gcd of poly1 and poly2 as a BinaryField instance."""
        if poly1.deg < poly2.deg:
            poly1, poly2 = poly2, poly1

        p1, p2 = poly1, poly2
        while p2.poly != 0:
            p1, p2 = p2, p1 % p2

        return p1

    @staticmethod
    def factorize(poly):
        """Factorize a BinaryField object
        Input:
        poly: A BinaryField element
        Return: A list of tuples (poly, exp)."""
        answer = []
        temp = poly

        for d in range(2, 2**(1+poly.deg//2)):
            div = BinaryField(d)

            e = 0
            while temp % div == BinaryField(0):
                temp = temp / div
                e += 1

            if e:
                answer.append((div, e))

            if temp == BinaryField(1): break

        if temp != BinaryField(1):
            answer.append((temp, 1))

        return answer

def input_general():
    return sys.stdin.readline().rstrip('\r\n')

def input_num():
    return int(sys.stdin.readline().rstrip("\r\n"))

def input_multi(x=int):
    return map(x, sys.stdin.readline().rstrip("\r\n").split())

def input_list(x=int):
    return list(input_multi(x))

def main(s):
    def get_factor(n):
        factors = {1}

        for p in range(2, 1 + int(n**0.5)):
            e = 0

            while n % p == 0:
                n //= p
                e += 1

            if e:
                factors = {f * (p**i) for f in factors for i in range(e+1)}

            if n == 1: break

        if n != 1:
            factors = {f * g for f in factors for g in (1, n)}

        return factors

    s = s.rstrip('0')
    leading_0 = s.find('1')

    answer = 1

    if leading_0 == -1:
        print('-1')
        return

    f2s = BinaryField(s)
    x = BinaryField(2)
    factors_bin = BinaryField.factorize(f2s)

    for f, exp in factors_bin:
        factors_pow = sorted(list(get_factor(2**f.deg-1)))

        for e in factors_pow:
            if x.powmod(e, f) == BinaryField(1):
                if exp == 1:
                    need = e
                else:
                    need = e * (2**(len(bin(exp-1)) - 2))

                g = gcd(answer, need)
                answer = answer * need // g

                break

    print(1 + leading_0, 1 + leading_0 + answer)

if __name__ == "__main__":
    s = input_general()

    main(s)


import fileinput

input = fileinput.input()
def readstr():
  return input.readline().rstrip()

def readints():
  return [int(x) for x in readstr().split(' ')]

def sign(n):
  return 1-(n&1)*2

def coeffs(d,p):
  inv = [1]*(d+1)
  for i in xrange(2,d+1):
    inv[i] = (-(p/i)*inv[p%i])%p
  finv = [1]*(d+1)
  for i in xrange(d):
    finv[i+1]=(finv[i]*inv[i+1])%p
  sumd=d*(d+1)/2
  sumd2=d*(d+1)*(2*d+1)/6
  return [(inv[d]*inv[d-1]*sign(d-j)*((sumd-j)**2-sumd2+(j**2))*finv[j]*finv[d-j])%p for j in xrange(d+1)]

# cell[z]=cell[x]+cell[y]
def plus(x,y,z):
  print '+ {} {} {}'.format(x,y,z)

# cell[y]=cell[x]^d
def powd(x,y):
  print '^ {} {}'.format(x,y)

def output(x):
  print 'f {}'.format(x)

# cell[y]+=k*cell[x]
# Modifies cell[x]
def kplus(k,x,y):
  k=k%p
  while k:
    if k&1: plus(x,y,y)
    k/=2
    plus(x,x,x)

# cell[y]+=k*cell[x]^2
# Requires c=coeffs(d,p) and cell[one]==1
# Modifies cell[x] and cell[z]
def ksquare(k,x,y,c,one,tmp):
  for j in xrange(d+1):
    if j: plus(x,one,x)
    powd(x,tmp)
    kplus(c[j]*k,tmp,y)

# x, y, x+y, 1, result, tmp
d,p = readints()
c=coeffs(d,p)
half=(p+1)/2
plus(1,2,3)
kplus(-1,6,5)
ksquare(-half,1,5,c,4,6)
ksquare(-half,2,5,c,4,6)
ksquare(half,3,5,c,4,6)
output(5)

def test(d,p):
  c=coeffs(d,p)
  for x in xrange(1000):
    assert pow(x,2,p)==sum(pow(x+j,d,p)*cj for j,cj in enumerate(c))%p


mod = int(1e9 + 7)
n, m = map(int, input().split())
f = [ [0 for i in range(60)] for j in range(60) ]
g = [ [0 for i in range(60)] for j in range(60) ]
s = [ [0 for i in range(60)] for j in range(60) ]
inv = [ 1 ]
f[0][0] = s[0][0] = 1

def pow(x, exp) :
    res = 1
    for i in range(0, 31) :
        if exp & 1 : res = res * x % mod
        exp >>= 1
        if exp == 0 : break
        x = x * x % mod
    return res

for i in range(1, n + 1) :
    inv.append( pow(i, mod - 2) )

for node in range(1, n + 1) :
    for cut in range(1, n + 1) :
        tmp = 0
        for ln in range(node) :
            for lc in range(cut - 1, n + 1) :
                if f[ln][lc] == 0 : continue
                if lc == cut - 1 :
                    tmp = ( tmp + f[ln][lc] * s[node - ln - 1][cut - 1] ) % mod
                else :
                    tmp = ( tmp + f[ln][lc] * f[node - ln - 1][cut - 1] ) % mod
        cnt = 1
        if tmp != 0 :
            cn, cc = 0, 0
            for i in range(1, n + 1) :
                cn += node
                cc += cut
                cnt = cnt * (tmp + i - 1) % mod * inv[i] % mod
                if cn > n or cc > n : break
                for j in range(n - cn, -1, -1) :
                    for k in range(n - cc, -1, -1) :
                        if f[j][k] == 0 : continue
                        g[j + cn][k + cc] += f[j][k] * cnt
                        g[j + cn][k + cc] %= mod
            for i in range(n + 1) :
                for j in range(n + 1) :
                    f[i][j] = (f[i][j] + g[i][j]) % mod
                    g[i][j] = 0

    for cut in range(n, -1, -1) :
        s[node][cut] = ( s[node][cut + 1] + f[node][cut] ) % mod
print(f[n][m - 1])