Vasya studies divisibility rules at school. Here are some of them: Divisibility by 2. A number is divisible by 2 if and only if its last digit is divisible by 2 or in other words, is even. Divisibility by 3. A number is divisible by 3 if and only if the sum of its digits is divisible by 3. Divisibility by 4. A number is divisible by 4 if and only if its last two digits form a number that is divisible by 4. Divisibility by 5. A number is divisible by 5 if and only if its last digit equals 5 or 0. Divisibility by 6. A number is divisible by 6 if and only if it is divisible by 2 and 3 simultaneously (that is, if the last digit is even and the sum of all digits is divisible by 3). Divisibility by 7. Vasya doesn't know such divisibility rule. Divisibility by 8. A number is divisible by 8 if and only if its last three digits form a number that is divisible by 8. Divisibility by 9. A number is divisible by 9 if and only if the sum of its digits is divisible by 9. Divisibility by 10. A number is divisible by 10 if and only if its last digit is a zero. Divisibility by 11. A number is divisible by 11 if and only if the sum of digits on its odd positions either equals to the sum of digits on the even positions, or they differ in a number that is divisible by 11.Vasya got interested by the fact that some divisibility rules resemble each other. In fact, to check a number's divisibility by 2, 4, 5, 8 and 10 it is enough to check fulfiling some condition for one or several last digits. Vasya calls such rules the 2-type rules.If checking divisibility means finding a sum of digits and checking whether the sum is divisible by the given number, then Vasya calls this rule the 3-type rule (because it works for numbers 3 and 9).If we need to find the difference between the sum of digits on odd and even positions and check whether the difference is divisible by the given divisor, this rule is called the 11-type rule (it works for number 11).In some cases we should divide the divisor into several factors and check whether rules of different types (2-type, 3-type or 11-type) work there. For example, for number 6 we check 2-type and 3-type rules, for number 66 we check all three types. Such mixed divisibility rules are called 6-type rules. And finally, there are some numbers for which no rule works: neither 2-type, nor 3-type, nor 11-type, nor 6-type. The least such number is number 7, so we'll say that in such cases the mysterious 7-type rule works, the one that Vasya hasn't discovered yet. Vasya's dream is finding divisibility rules for all possible numbers. He isn't going to stop on the decimal numbers only. As there are quite many numbers, ha can't do it all by himself. Vasya asked you to write a program that determines the divisibility rule type in the b-based notation for the given divisor d.

The first input line contains two integers b and d (2 ≤ b, d ≤ 100) — the notation system base and the divisor. Both numbers are given in the decimal notation.

On the first output line print the type of the rule in the b-based notation system, where the divisor is d: "2-type", "3-type", "11-type", "6-type" or "7-type". If there are several such types, print the one that goes earlier in the given sequence. If a number belongs to the 2-type, print on the second line the least number of the last b-based digits that we will need to use to check the divisibility.

NoteThe divisibility rule for number 3 in binary notation looks as follows: "A number is divisible by 3 if and only if the sum of its digits that occupy the even places differs from the sum of digits that occupy the odd places, in a number that is divisible by 3". That's an 11-type rule. For example, 2110 = 101012. For it the sum of digits on odd positions equals 1 + 1 + 1 = 3, an on even positions — 0 + 0 = 0. The rule works and the number is divisible by 3. In some notations a number can fit into the 3-type rule and the 11-type rule. In this case the correct answer is "3-type".

b, d = map(int, input().split())
for i in range(1, 10):
    if (b**i) % d == 0:
        print("2-type")
        print(i)
        exit()
if (b-1) % d == 0:
    print("3-type")
    exit()
if (b+1) % d == 0:
    print("11-type")
    exit()
for i in range(2, d+1):
    if d % i == 0:
        x = 1
        while d % i == 0:
            d /= i
            x *= i
        if (b**10) % x != 0 and (b+1) % x != 0 and (b-1) % x != 0:
            print("7-type")
            break
else:
    print("6-type")

b, d = map(int, raw_input().split())

def typeTwo(x):
      for i in range(100):
            if (b ** i) % x == 0:
                  return i
      return 0

def typeThree(x):
      for i in range(100):
            if (b ** i - 1) % x != 0:
                  return False
      return True

def typeEleven(x):
      for i in range(100):
            if (b ** (2 * i) - 1) % x != 0:
                  return False
            if (b ** (2 * i + 1) + 1) % x != 0:
                  return False
      return True

def typeSix(x):
      for i in range(2, 100):
            cur = 1
            while x % i == 0:
                  cur *= i
                  x /= i
            if cur != 1 and b % i:
                  if not(typeTwo(cur) or typeThree(cur) or typeEleven(cur)):
                        return False
      return True

if typeTwo(d):
      print '2-type'
      print typeTwo(d)
elif typeThree(d):
      print '3-type'
elif typeEleven(d):
      print '11-type'
elif typeSix(d):
      print '6-type'
else:
      print '7-type'

from fractions import gcd
b,D=map(int,raw_input().split())
a=200*[0]
z=200*[0]
for d in range(2,101):
	c=0
	t=d
	while gcd(b,t)>1:
		t/=gcd(b,t)
		c+=1
	if t==1:
		a[d]=2
		z[d]=c
		continue
	if b%d==1:
		a[d]=3
		continue
	if (b+1)%d==0:
		a[d]=11
		continue
	a[d]=7
	for i in range(2,d):
		if d%i==0 and gcd(i,d/i)==1 and a[i]!=7 and a[d/i]!=7:
			a[d]=6
print "%d-type"%a[D]
if a[D]==2:
	print z[D]

import sys
from random import randint
from math import sqrt

mul=[]
rand=[]
SIZE = 32

def checkTypeZwei(base,div):
	for i in xrange(SIZE):
		if(int(mul[i])%div==0):
			return i
	return -1

def checkTypeDrei(base,div):
	for num in rand:
		sum=0
		for ch in num:
			sum+=ch
		if(sum%div!=0):
			#print sum,div
			return False

	return True

def checkTypeElf(base,div):
	for i in xrange(SIZE):
		num=rand[i]
		eve=0
		odd=0
		ind=0
		num=num[::-1]
		for ch in num:
			if(ind&1):
				odd+=ch
			else:
				eve+=ch
			ind+=1

		if(odd!=eve and abs(odd-eve)%div!=0 ):
			return False

	return True

def checkTypeSechs(base,div):
	factor=[]
	for i in xrange(2,div+1):
		if(div%i==0):
			factor.append(i)
			while(div%i==0):
				div/=i
	ans=True
	#print factor
	if(len(factor)<2):
		return False
	for num in factor:
		if(checkTypeZwei(base,num)!=-1 or checkTypeDrei(base,num) or checkTypeElf(base,num)):
			ans=True
		else:
			ans=False
			break;
	return ans

def xBase(num,base):
	res=[]
	while(num):
		tmpNum=num%base
		tmpList=[]
		tmpList.append(tmpNum)
		tmpList.extend(res)
		res=tmpList
		num/=base
	return [0] if(res=='') else res

if(__name__=='__main__'):

	instr=raw_input()
	instr=instr.split()
	base=int(instr[0])
	div=int(instr[1])

	for i in xrange(SIZE):
		mul.append(str(base**i))

	for i in xrange(SIZE):
		num=randint(0,1<<16)
		num*=div
		#print xBase(num,base)
		rand.append(xBase(num,base))
	type=7
	leng=-1
	if(type==7):
		leng=checkTypeZwei(base,div)
		if(leng!=-1):
			type=2

	if(type==7):
		if(checkTypeDrei(base,div)):
			type=3

	if(type==7):
		if(checkTypeElf(base,div)):
			type=11

	if(type==7):
		if(checkTypeSechs(base,div)):
			type=6

	print(str(type)+'-type')
	if(type==2):
		print leng

b,d=map(int,raw_input().split())

for i in xrange(1,10):

    if (b**i)%d==0:

        print "2-type"

        print i

        exit()

if (b-1)%d==0:

    print "3-type"

elif (b+1)%d==0:

    print "11-type"

else:

    for i in xrange(2,d+1):

        if d%i==0:

            x=1

            while d%i==0: d/=i; x*=i

            if (b**10)%x!=0 and (b+1)%x!=0 and (b-1)%x!=0:

                print "7-type"

                exit()

    print "6-type"

# Made By Mostafa_Khaled

import sys

b, d = [int(s) for s in sys.stdin.readline().split(' ')]

def pf(d):
    l = []
    i = 2
    while i * i <= d:
        if d % i == 0:
            k = 1
            while d % i == 0:
                d /= i
                k *= i
            l.append(k)
        i += 1
    if d > 1:
        l.append(d)
    return l

def typ(b, d):
    if (b ** 7) % d == 0:
        i, bb = 1, b
        while bb % d != 0:
            i, bb = i + 1, bb * b
        return (2, i)
    elif (b - 1) % d == 0:
        return 3
    elif (b + 1) % d == 0:
        return 11
    else:
        p = pf(d)
        if p != [d] and all(typ(b, f) != 7 for f in p):
            return 6
        else:
            return 7

t=typ(b,d)
if isinstance(t, int):
    print "%d-type" % t
else:
    print "%d-type" % t[0]
    print t[1]

b, d = map(int, raw_input().split())

def typeTwo(x):
      for i in range(100):
            if (b ** i) % x == 0:
                  return i
      return 0

def typeThree(x):
      for i in range(100):
            if (b ** i - 1) % x != 0:
                  return False
      return True

def typeEleven(x):
      for i in range(100):
            if (b ** (2 * i) - 1) % x != 0:
                  return False
            if (b ** (2 * i + 1) + 1) % x != 0:
                  return False
      return True

def typeSix(x):
      p = []
      for i in range(2, 100):
            cur = 1
            while x % i == 0:
                  cur *= i
                  x /= i
            if cur != 1:
                  p.append(cur);
      a = []
      for i in range(len(p)):
            if typeTwo(p[i]): a.append(2)
            if typeThree(p[i]): a.append(3)
            if typeEleven(p[i]): a.append(11);
      return a

if typeTwo(d):
      print '2-type'
      print typeTwo(d)
elif typeThree(d):
      print '3-type'
elif typeEleven(d):
      print '11-type'
else:
      a = typeSix(d)
      if a.count(2) <= 1 and a.count(3) <= 1 and a.count(11) <= 1 and len(a) > 0:
            print '6-type'
      else:
            print '7-type'

b, d = map(int, raw_input().split())

def typeTwo(x):
      for i in range(100):
            if (b ** i) % x == 0:
                  return i
      return 0

def typeThree(x):
      for i in range(100):
            if (b ** i - 1) % x != 0:
                  return False
      return True

def typeEleven(x):
      for i in range(50):
            if (b ** (2 * i) - 1) % d != 0:
                  return False
            if (b ** (2 * i + 1) + 1) % d != 0:
                  return False
      return True

def typeSix(x):
      if typeTwo(x) or typeThree(x) or typeEleven(x):
            return True
      for i in range(2, x):
            if x % i == 0:
                  if typeSix(i) and typeSix(x // i):
                        return True
      return False

if typeTwo(d):
      print '2-type'
      print typeTwo(d)
elif typeThree(d):
      print '3-type'
elif typeEleven(d):
      print '11-type'
elif typeSix(d):
      print '6-type'
else:
      print '7-type'

b, d = map(int, raw_input().split())

def typeTwo(x):
      for i in range(100):
            if (b ** i) % x == 0:
                  return i
      return 0

def typeThree(x):
      for i in range(100):
            if (b ** i - 1) % x != 0:
                  return False
      return True

def typeEleven(x):
      for i in range(100):
            if (b ** (2 * i) - 1) % x != 0:
                  return False
            if (b ** (2 * i + 1) + 1) % x != 0:
                  return False
      return True

def typeSix(x):
      p = []
      for i in range(2, 100):
            while x % i == 0:
                  p.append(i);
                  x /= i
      a = []
      for i in range(len(p)):
            if typeTwo(p[i]): a.append(2)
            if typeThree(p[i]): a.append(3)
            if typeEleven(p[i]): a.append(11);
      return a

if typeTwo(d):
      print '2-type'
      print typeTwo(d)
elif typeThree(d):
      print '3-type'
elif typeEleven(d):
      print '11-type'
else:
      a = typeSix(d)
      if a.count(2) <= 1 and a.count(3) <= 1 and a.count(11) <= 1:
            print '6-type'
      else:
            print '7-type'

b, d = map(int, raw_input().split())

def typeTwo(x):
      for i in range(100):
            if (b ** i) % x == 0:
                  return i
      return 0

def typeThree(x):
      for i in range(100):
            if (b ** i - 1) % x != 0:
                  return False
      return True

def typeEleven(x):
      for i in range(50):
            if (b ** (2 * i) - 1) % x != 0:
                  return False
            if (b ** (2 * i + 1) + 1) % x != 0:
                  return False
      return True

def typeSix(x):
      if typeTwo(x) or typeThree(x) or typeEleven(x):
            return True
      for i in range(2, x):
            if x % i == 0:
                  if typeSix(i) and typeSix(x // i):
                        return True
      return False

if typeTwo(d):
      print '2-type'
      print typeTwo(d)
elif typeThree(d):
      print '3-type'
elif typeEleven(d):
      print '11-type'
elif typeSix(d):
      print '6-type'
else:
      print '7-type'

b, d = map(int, raw_input().split())

def typeTwo(x):
      for i in range(100):
            if (b ** i) % x == 0:
                  return i
      return 0

def typeThree(x):
      for i in range(100):
            if (b ** i - 1) % x != 0:
                  return False
      return True

def typeEleven(x):
      for i in range(100):
            if (b ** (2 * i) - 1) % x != 0:
                  return False
            if (b ** (2 * i + 1) + 1) % x != 0:
                  return False
      return True

def typeSix(x):
      if typeTwo(x):
            return [2]
      if typeThree(x):
            return [3]
      if typeEleven(x):
            return [11]
      for i in range(2, x):
            if x % i == 0:
                  a = []
                  a.extend(typeSix(i))
                  a.extend(typeSix(x // i))
                  if a.count(2) <= 1 and a.count(3) <= 1 and a.count(11) <= 1:
                        return a
      return [2, 2]

if typeTwo(d):
      print '2-type'
      print typeTwo(d)
elif typeThree(d):
      print '3-type'
elif typeEleven(d):
      print '11-type'
else:
      a = typeSix(d)
      if a.count(2) <= 1 and a.count(3) <= 1 and a.count(11) <= 1:
            print '6-type'
      else:
            print '7-type'

b, d = map(int, raw_input().split())

def typeTwo(x):
      for i in range(100):
            if (b ** i) % x == 0:
                  return i
      return 0

def typeThree(x):
      for i in range(100):
            if (b ** i - 1) % x != 0:
                  return False
      return True

def typeEleven(x):
      for i in range(50):
            if (b ** (2 * i) - 1) % d != 0:
                  return False
            if (b ** (2 * i + 1) + 1) % d != 0:
                  return False
      return True

def typeSix(x):
      if typeTwo(x) or typeThree(x):
            return True
      for i in range(2, x):
            if x % i == 0:
                  if typeSix(i) and typeSix(x // i):
                        return True
      return False

if typeTwo(d):
      print '2-type'
      print typeTwo(d)
elif typeThree(d):
      print '3-type'
elif typeEleven(d):
      print '11-type'
elif typeSix(d):
      print '6-type'
else:
      print '7-type'

b, d = map(int, raw_input().split())

def typeTwo(x):
      for i in range(100):
            if (b ** i) % x == 0:
                  return i
      return 0

def typeThree(x):
      for i in range(100):
            if (b ** i - 1) % x != 0:
                  return False
      return True

def typeEleven(x):
      for i in range(100):
            if (b ** (2 * i) - 1) % x != 0:
                  return False
            if (b ** (2 * i + 1) + 1) % x != 0:
                  return False
      return True

def typeSix(x):
      p = []
      for i in range(2, 100):
            cur = 1
            while x % i == 0:
                  cur *= i
                  x /= i
            if cur != 1:
                  p.append(cur)
      a = []
      for i in range(len(p)):
            if typeTwo(p[i]): a.append(2)
            elif typeThree(p[i]): a.append(3)
            elif typeEleven(p[i]): a.append(11)
            else:
                  a.append(p[i])
      return a

if typeTwo(d):
      print '2-type'
      print typeTwo(d)
elif typeThree(d):
      print '3-type'
elif typeEleven(d):
      print '11-type'
else:
      a = typeSix(d)
      f = True
      if not(a.count(2) <= 1 and a.count(3) <= 1 and a.count(11) <= 1 and len(a) > 0):
            f = False
      if a.count(2) == 1: a.remove(2)
      if a.count(3) == 1: a.remove(3)
      if a.count(11) == 1: a.remove(11)
      if len(a) > 0:
            f = False
      print '6-type' if f else '7-type'

b, d = map(int, raw_input().split())

def typeTwo(x):
      for i in range(100):
            if (b ** i) % x == 0:
                  return i
      return 0

def typeThree(x):
      for i in range(100):
            if (b ** i - 1) % x != 0:
                  return False
      return True

def typeEleven(x):
      for i in range(100):
            if (b ** (2 * i) - 1) % x != 0:
                  return False
            if (b ** (2 * i + 1) + 1) % x != 0:
                  return False
      return True

def typeSix(x):
      p = []
      for i in range(2, 100):
            while x % i == 0:
                  p.append(i);
                  x /= i
      a = []
      for i in range(len(p)):
            if typeTwo(p[i]): a.append(2)
            if typeThree(p[i]): a.append(3)
            if typeEleven(p[i]): a.append(11);
      return a

if typeTwo(d):
      print '2-type'
      print typeTwo(d)
elif typeThree(d):
      print '3-type'
elif typeEleven(d):
      print '11-type'
else:
      a = typeSix(d)
      if a.count(2) <= 1 and a.count(3) <= 1 and a.count(11) <= 1 and len(a) > 0:
            print '6-type'
      else:
            print '7-type'

b, d = map(int, raw_input().split())

def typeTwo(x):
      for i in range(100):
            if (b ** i) % x == 0:
                  return i
      return 0

def typeThree(x):
      for i in range(100):
            if (b ** i - 1) % x != 0:
                  return False
      return True

def typeEleven(x):
      for i in range(100):
            if (b ** (2 * i) - 1) % x != 0:
                  return False
            if (b ** (2 * i + 1) + 1) % x != 0:
                  return False
      return True

def typeSix(x):
      p = []
      for i in range(2, 100):
            cur = 1
            while x % i == 0:
                  cur *= i
                  x /= i
            if cur != 1 and b % i:
                  p.append(cur)
      a = []
      for i in range(len(p)):
            if typeTwo(p[i]): a.append(2)
            elif typeThree(p[i]): a.append(3)
            elif typeEleven(p[i]): a.append(11)
            else:
                  a.append(p[i])
      return a

if typeTwo(d):
      print '2-type'
      print typeTwo(d)
elif typeThree(d):
      print '3-type'
elif typeEleven(d):
      print '11-type'
else:
      a = typeSix(d)
      f = True
      if not(a.count(2) <= 1 and a.count(3) <= 1 and a.count(11) <= 1 and len(a) > 0):
            f = False
      if a.count(2) == 1: a.remove(2)
      if a.count(3) == 1: a.remove(3)
      if a.count(11) == 1: a.remove(11)
      if len(a) > 0:
            f = False
      print '6-type' if f else '7-type'

b,d=map(int,raw_input().split())
for i in xrange(1,10):
    if (b**i)%d==0:
        print "2-type"
        print i
        exit()
if (b-1)%d==0:
    print "3-type"
elif (b+1)%d==0:
    print "11-type"
elif ((b-1)*b*(b+1))**10 % d == 0:
    print "6-type"
else:
    print "7-type"

import sys
from random import randint
from math import sqrt

mul=[]
rand=[]
SIZE = 32

def checkTypeZwei(base,div):
	for i in xrange(SIZE):
		if(int(mul[i])%div==0):
			return i
	return -1

def checkTypeDrei(base,div):
	for num in rand:
		sum=0
		for ch in num:
			sum+=ch
		if(sum%div!=0):
			print sum,div
			return False

	return True

def checkTypeElf(base,div):
	for i in xrange(SIZE):
		num=rand[i]
		eve=0
		odd=0
		ind=0
		num=num[::-1]
		for ch in num:
			if(ind&1):
				odd+=ch
			else:
				eve+=ch
			ind+=1

		if(odd!=eve and abs(odd-eve)%div!=0 ):
			return False

	return True

def checkTypeSechs(base,div):
	factor=[]
	for i in xrange(2,div+1):
		if(div%i==0):
			factor.append(i)
			while(div%i==0):
				div/=i
	ans=True
	#print factor
	if(len(factor)<2):
		return False
	for num in factor:
		if(checkTypeZwei(base,num)!=-1 or checkTypeDrei(base,num) or checkTypeElf(base,num)):
			ans=True
		else:
			ans=False
			break;
	return ans

def xBase(num,base):
	res=[]
	while(num):
		tmpNum=num%base
		tmpList=[]
		tmpList.append(tmpNum)
		tmpList.extend(res)
		res=tmpList
		num/=base
	return [0] if(res=='') else res

if(__name__=='__main__'):

	instr=raw_input()
	instr=instr.split()
	base=int(instr[0])
	div=int(instr[1])

	for i in xrange(SIZE):
		mul.append(str(base**i))

	for i in xrange(SIZE):
		num=randint(0,1<<16)
		num*=div
		#print xBase(num,base)
		rand.append(xBase(num,base))
	type=7
	leng=-1
	if(type==7):
		leng=checkTypeZwei(base,div)
		if(leng!=-1):
			type=2

	if(type==7):
		if(checkTypeDrei(base,div)):
			type=3

	if(type==7):
		if(checkTypeElf(base,div)):
			type=11

	if(type==7):
		if(checkTypeSechs(base,div)):
			type=6

	print(str(type)+'-type')
	if(type==2):
		print leng

import sys
from random import randint
from math import sqrt

mul=[]
rand=[]
SIZE = 32

def checkTypeZwei(base,div):
	for i in xrange(SIZE):
		if(int(mul[i])%div==0):
			return i
	return -1

def checkTypeDrei(base,div):
	for num in rand:
		sum=0
		for ch in num:
			sum+=ord(ch)-ord('0')
		if(sum%div!=0): return False

	return True

def checkTypeElf(base,div):
	for i in xrange(SIZE):
		num=rand[i]
		eve=0
		odd=0
		ind=0
		for ch in num:
			if(ind&1):
				odd+=ord(ch)-ord('0')
			else:
				eve+ord(ch)-ord('0')
			ind+=1

		if(odd!=eve):
			return False

	return True

def checkTypeSechs(base,div):
	for i in xrange(1,int(sqrt(div))):
		if(div%i==0):
			a=div/i
			b=i

			if(checkTypeZwei(base,a)!=-1 or checkTypeDrei(base,a) or checkTypeElf(base,a)):
				a=True
			else:
				a=False

			if(checkTypeZwei(base,b)!=-1 or checkTypeDrei(base,b) or checkTypeElf(base,b)):
				b=True
			else:
				b=False

			if(not (a and b)):
				return False

	return True

def xBase(num,base):
	res=''
	while(num):
		res=str(num%base)+res
		num/=base
	return '0' if(res=='') else res

if(__name__=='__main__'):

	instr=raw_input()
	instr=instr.split()
	base=int(instr[0])
	div=int(instr[1])

	for i in xrange(SIZE):
		mul.append(str(base**i))

	for i in xrange(SIZE):
		num=randint(0,1<<16)
		num*=div
		#print xBase(num,base)
		rand.append(xBase(num,base))
	type=7
	len=-1
	if(type==7):
		len=checkTypeZwei(base,div)
		if(len!=-1):
			type=2

	if(type==7):
		if(checkTypeDrei(base,div)):
			type=3

	if(type==7):
		if(checkTypeElf(base,div)):
			type=11

	if(type==7):
		if(checkTypeSechs(base,div)):
			type=6

	print(str(type)+'-type')
	if(type==2):
		print len

import sys
from random import randint
from math import sqrt

mul=[]
rand=[]
SIZE = 32

def checkTypeZwei(base,div):
	for i in xrange(SIZE):
		if(int(mul[i])%div==0):
			return i
	return -1

def checkTypeDrei(base,div):
	for num in rand:
		sum=0
		for ch in num:
			sum+=ord(ch)-ord('0')
		if(sum%div!=0): return False

	return True

def checkTypeElf(base,div):
	for i in xrange(SIZE):
		num=rand[i]
		eve=0
		odd=0
		ind=0
		num=num[::-1]
		for ch in num:
			if(ind&1):
				odd+=ord(ch)-ord('0')
			else:
				eve+=ord(ch)-ord('0')
			ind+=1

		if(odd!=eve and abs(odd-eve)%div!=0 ):
			return False

	return True

def checkTypeSechs(base,div):
	factor=[]
	for i in xrange(2,div+1):
		if(div%i==0):
			factor.append(i)
			while(div%i==0):
				div/=i
	ans=True
	for num in factor:
		if(checkTypeZwei(base,num)!=-1 or checkTypeDrei(base,num) or checkTypeElf(base,num)):
			ans=True
		else:
			ans=False
			break;
	return ans

def xBase(num,base):
	res=''
	while(num):
		res=str(num%base)+res
		num/=base
	return '0' if(res=='') else res

if(__name__=='__main__'):

	instr=raw_input()
	instr=instr.split()
	base=int(instr[0])
	div=int(instr[1])

	for i in xrange(SIZE):
		mul.append(str(base**i))

	for i in xrange(SIZE):
		num=randint(0,1<<16)
		num*=div
		#print xBase(num,base)
		rand.append(xBase(num,base))
	type=7
	len=-1
	if(type==7):
		len=checkTypeZwei(base,div)
		if(len!=-1):
			type=2

	if(type==7):
		if(checkTypeDrei(base,div)):
			type=3

	if(type==7):
		if(checkTypeElf(base,div)):
			type=11

	if(type==7):
		if(checkTypeSechs(base,div)):
			type=6

	print(str(type)+'-type')
	if(type==2):
		print len

import sys
from random import randint
from math import sqrt

mul=[]
rand=[]
SIZE = 32

def checkTypeZwei(base,div):
	for i in xrange(SIZE):
		if(int(mul[i])%div==0):
			return i
	return -1

def checkTypeDrei(base,div):
	for num in rand:
		sum=0
		for ch in num:
			sum+=ord(ch)-ord('0')
		if(sum%div!=0): return False

	return True

def checkTypeElf(base,div):
	for i in xrange(SIZE):
		num=rand[i]
		eve=0
		odd=0
		ind=0
		num=num[::-1]
		for ch in num:
			if(ind&1):
				odd+=ord(ch)-ord('0')
			else:
				eve+=ord(ch)-ord('0')
			ind+=1

		if(odd!=eve and abs(odd-eve)%div!=0 ):
			return False

	return True

def checkTypeSechs(base,div):
	factor=[]
	for i in xrange(2,div+1):
		if(div%i==0):
			factor.append(i)
			while(div%i==0):
				div/=i
	ans=True
	#print factor
	if(len(factor)<2):
		return False
	for num in factor:
		if(checkTypeZwei(base,num)!=-1 or checkTypeDrei(base,num) or checkTypeElf(base,num)):
			ans=True
		else:
			ans=False
			break;
	return ans

def xBase(num,base):
	res=''
	while(num):
		res=str(num%base)+res
		num/=base
	return '0' if(res=='') else res

if(__name__=='__main__'):

	instr=raw_input()
	instr=instr.split()
	base=int(instr[0])
	div=int(instr[1])

	for i in xrange(SIZE):
		mul.append(str(base**i))

	for i in xrange(SIZE):
		num=randint(0,1<<16)
		num*=div
		#print xBase(num,base)
		rand.append(xBase(num,base))
	type=7
	leng=-1
	if(type==7):
		leng=checkTypeZwei(base,div)
		if(leng!=-1):
			type=2

	if(type==7):
		if(checkTypeDrei(base,div)):
			type=3

	if(type==7):
		if(checkTypeElf(base,div)):
			type=11

	if(type==7):
		if(checkTypeSechs(base,div)):
			type=6

	print(str(type)+'-type')
	if(type==2):
		print leng

import sys
from random import randint
from math import sqrt

mul=[]
rand=[]
SIZE = 32

def checkTypeZwei(base,div):
	for i in xrange(SIZE):
		if(int(mul[i])%div==0):
			return i
	return -1

def checkTypeDrei(base,div):
	for num in rand:
		sum=0
		for ch in num:
			sum+=ord(ch)-ord('0')
		if(sum%div!=0): return False

	return True

def checkTypeElf(base,div):
	for i in xrange(SIZE):
		num=rand[i]
		eve=0
		odd=0
		ind=0
		num=num[::-1]
		for ch in num:
			if(ind&1):
				odd+=ord(ch)-ord('0')
			else:
				eve+=ord(ch)-ord('0')
			ind+=1

		if(odd!=eve and abs(odd-eve)%div!=0 ):
			return False

	return True

def checkTypeSechs(base,div):
	for i in xrange(1,int(sqrt(div))):
		if(div%i==0):
			a=div/i
			b=i

			if(checkTypeZwei(base,a)!=-1 or checkTypeDrei(base,a) or checkTypeElf(base,a)):
				a=True
			else:
				a=False

			if(checkTypeZwei(base,b)!=-1 or checkTypeDrei(base,b) or checkTypeElf(base,b)):
				b=True
			else:
				b=False

			if(not (a and b)):
				return False

	return True

def xBase(num,base):
	res=''
	while(num):
		res=str(num%base)+res
		num/=base
	return '0' if(res=='') else res

if(__name__=='__main__'):

	instr=raw_input()
	instr=instr.split()
	base=int(instr[0])
	div=int(instr[1])

	for i in xrange(SIZE):
		mul.append(str(base**i))

	for i in xrange(SIZE):
		num=randint(0,1<<16)
		num*=div
		#print xBase(num,base)
		rand.append(xBase(num,base))
	type=7
	len=-1
	if(type==7):
		len=checkTypeZwei(base,div)
		if(len!=-1):
			type=2

	if(type==7):
		if(checkTypeDrei(base,div)):
			type=3

	if(type==7):
		if(checkTypeElf(base,div)):
			type=11

	if(type==7):
		if(checkTypeSechs(base,div)):
			type=6

	print(str(type)+'-type')
	if(type==2):
		print len

import sys
from random import randint
from math import sqrt

mul=[]
rand=[]
SIZE = 32

def checkTypeZwei(base,div):
	for i in xrange(SIZE):
		if(int(mul[i])%div==0):
			return i
	return -1

def checkTypeDrei(base,div):
	for num in rand:
		sum=0
		for ch in num:
			sum+=ord(ch)-ord('0')
		if(sum%div!=0): return False

	return True

def checkTypeElf(base,div):
	for i in xrange(SIZE):
		num=rand[i]
		eve=0
		odd=0
		ind=0
		num=num[::-1]
		for ch in num:
			if(ind&1):
				odd+=ord(ch)-ord('0')
			else:
				eve+=ord(ch)-ord('0')
			ind+=1

		if(odd!=eve and abs(odd-eve)%div!=0 ):
			return False

	return True

def checkTypeSechs(base,div):
	for i in xrange(1,int(sqrt(div))+1):
		if(div%i==0):
			a=div/i
			b=i
			#print a,b
			if(checkTypeZwei(base,a)!=-1 or checkTypeDrei(base,a) or checkTypeElf(base,a)):
				a=True
			else:
				a=False

			if(checkTypeZwei(base,b)!=-1 or checkTypeDrei(base,b) or checkTypeElf(base,b)):
				b=True
			else:
				b=False

			if(a and b):
				return True

	return False

def xBase(num,base):
	res=''
	while(num):
		res=str(num%base)+res
		num/=base
	return '0' if(res=='') else res

if(__name__=='__main__'):

	instr=raw_input()
	instr=instr.split()
	base=int(instr[0])
	div=int(instr[1])

	for i in xrange(SIZE):
		mul.append(str(base**i))

	for i in xrange(SIZE):
		num=randint(0,1<<16)
		num*=div
		#print xBase(num,base)
		rand.append(xBase(num,base))
	type=7
	len=-1
	if(type==7):
		len=checkTypeZwei(base,div)
		if(len!=-1):
			type=2

	if(type==7):
		if(checkTypeDrei(base,div)):
			type=3

	if(type==7):
		if(checkTypeElf(base,div)):
			type=11

	if(type==7):
		if(checkTypeSechs(base,div)):
			type=6

	print(str(type)+'-type')
	if(type==2):
		print len

import sys
from random import randint
from math import sqrt

mul=[]
rand=[]
SIZE = 32

def checkTypeZwei(base,div):
	for i in xrange(SIZE):
		if(int(mul[i])%div==0):
			return i
	return -1

def checkTypeDrei(base,div):
	for num in rand:
		sum=0
		for ch in num:
			sum+=ord(ch)-ord('0')
		if(sum%div!=0): return False

	return True

def checkTypeElf(base,div):
	for i in xrange(SIZE):
		num=rand[i]
		eve=0
		odd=0
		ind=0
		num=num[::-1]
		for ch in num:
			if(ind&1):
				odd+=ord(ch)-ord('0')
			else:
				eve+=ord(ch)-ord('0')
			ind+=1

		if(odd!=eve and abs(odd-eve)%div!=0 ):
			return False

	return True

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

def checkTypeSechs(base,div):
	factor=[]
	for i in xrange(2,int(sqrt(div))+1):
		if(div%i==0):
			factor.append(i)
			while(div%i==0):
				div/=i
	ans=True
	for num in factor:
		if(checkTypeZwei(base,num)!=-1 or checkTypeDrei(base,num) or checkTypeElf(base,num)):
			ans=True
		else:
			ans=False
			break;
	return ans

def xBase(num,base):
	res=''
	while(num):
		res=str(num%base)+res
		num/=base
	return '0' if(res=='') else res

if(__name__=='__main__'):

	instr=raw_input()
	instr=instr.split()
	base=int(instr[0])
	div=int(instr[1])

	for i in xrange(SIZE):
		mul.append(str(base**i))

	for i in xrange(SIZE):
		num=randint(0,1<<16)
		num*=div
		#print xBase(num,base)
		rand.append(xBase(num,base))
	type=7
	len=-1
	if(type==7):
		len=checkTypeZwei(base,div)
		if(len!=-1):
			type=2

	if(type==7):
		if(checkTypeDrei(base,div)):
			type=3

	if(type==7):
		if(checkTypeElf(base,div)):
			type=11

	if(type==7):
		if(checkTypeSechs(base,div)):
			type=6

	print(str(type)+'-type')
	if(type==2):
		print len

import sys
from random import randint
from math import sqrt

mul=[]
rand=[]
SIZE = 32

def checkTypeZwei(base,div):
	for i in xrange(SIZE):
		if(int(mul[i])%div==0):
			return i
	return -1

def checkTypeDrei(base,div):
	for num in rand:
		sum=0
		for ch in num:
			sum+=ord(ch)-ord('0')
		if(sum%div!=0): return False

	return True

def checkTypeElf(base,div):
	for i in xrange(SIZE):
		num=rand[i]
		eve=0
		odd=0
		ind=0
		num=num[::-1]
		for ch in num:
			if(ind&1):
				odd+=ord(ch)-ord('0')
			else:
				eve+=ord(ch)-ord('0')
			ind+=1

		if(odd!=eve and abs(odd-eve)%div!=0 ):
			return False

	return True

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

def checkTypeSechs(base,div):
	for i in xrange(1,int(sqrt(div))+1):
		if(div%i==0):
			a=div/i
			b=i
			if(gcd(a,b)!=1):
				continue
			if(checkTypeZwei(base,a)!=-1 or checkTypeDrei(base,a) or checkTypeElf(base,a)):
				a=True
			else:
				a=False

			if(checkTypeZwei(base,b)!=-1 or checkTypeDrei(base,b) or checkTypeElf(base,b)):
				b=True
			else:
				b=False

			if(a and b):
				return True

	return False

def xBase(num,base):
	res=''
	while(num):
		res=str(num%base)+res
		num/=base
	return '0' if(res=='') else res

if(__name__=='__main__'):

	instr=raw_input()
	instr=instr.split()
	base=int(instr[0])
	div=int(instr[1])

	for i in xrange(SIZE):
		mul.append(str(base**i))

	for i in xrange(SIZE):
		num=randint(0,1<<16)
		num*=div
		#print xBase(num,base)
		rand.append(xBase(num,base))
	type=7
	len=-1
	if(type==7):
		len=checkTypeZwei(base,div)
		if(len!=-1):
			type=2

	if(type==7):
		if(checkTypeDrei(base,div)):
			type=3

	if(type==7):
		if(checkTypeElf(base,div)):
			type=11

	if(type==7):
		if(checkTypeSechs(base,div)):
			type=6

	print(str(type)+'-type')
	if(type==2):
		print len

import sys

b, d = [int(s) for s in sys.stdin.readline().split(' ')]

def pf(d):
    l = []
    i = 2
    while i * i <= d:
        if d % i == 0:
            while d % i == 0: d /= i
            l.append(i)
        i += 1
    if d > 1:
        l.append(d)
    return l

def typ(b, d):
    if (b ** 7) % d == 0:
        i, bb = 1, b
        while bb % d != 0:
            i, bb = i + 1, bb * b
        return (2, i)
    elif (b - 1) % d == 0:
        return 3
    elif (b + 1) % d == 0:
        return 11
    else:
        p = pf(d)
        if p != [d] and all(typ(b, f) != 7 for f in p):
            return 6
        else:
            return 7

t=typ(b,d)
if isinstance(t, int):
    print "%d-type" % t
else:
    print "%d-type" % t[0]
    print t[1]

import sys

b, d = [int(s) for s in sys.stdin.readline().split(' ')]

def pf(d):
    l = []
    i = 2
    while i * i <= d:
        if d % i == 0:
            while d % i == 0: d /= i
            l.append(i)
        i += 1
    if i > 1:
        l.append(i)
    return l

def typ(b, d):
    if (b ** 7) % d == 0:
        i, bb = 1, b
        while bb % d != 0:
            i, bb = i + 1, bb * b
        return (2, i)
    elif (b - 1) % d == 0:
        return 3
    elif (b + 1) % d == 0:
        return 11
    else:
        p = pf(d)
        if p and all(typ(b, f) != 7 for f in p):
            return 6
        else:
            return 7

t=typ(b,d)
if isinstance(t, int):
    print "%d-type" % t
else:
    print "%d-type" % t[0]
    print t[1]


So many wall designs to choose from! Even modulo 106 + 3, it's an enormous number. Given that recently Heidi acquired an unlimited supply of bricks, her choices are endless! She really needs to do something to narrow them down.Heidi is quick to come up with criteria for a useful wall:  In a useful wall, at least one segment is wider than W bricks. This should give the zombies something to hit their heads against. Or,  in a useful wall, at least one column is higher than H bricks. This provides a lookout from which zombies can be spotted at a distance. This should rule out a fair amount of possibilities, right? Help Heidi compute the number of useless walls that do not confirm to either of these criteria. In other words, a wall is useless if every segment has width at most W and height at most H.Parameter C, the total width of the wall, has the same meaning as in the easy version. However, note that the number of bricks is now unlimited.Output the number of useless walls modulo 106 + 3.

The first and the only line of the input contains three space-separated integers C, W and H (1 ≤ C ≤ 108, 1 ≤ W, H ≤ 100).

Output the number of different walls, modulo 106 + 3, which are useless according to Heidi's criteria.

NoteIf there is no brick in any of the columns, the structure is considered as a useless wall.

mod = 10 ** 6 + 3

def prod(a, b):
    return [[sum([a[i][k] * b[k][j] for k in range(len(b))]) % mod for j in range(len(b[0]))] for i in range(len(a))]

c, w, h = map(int, input().split())

a = [[0] * (w + 1) for _ in range(w + 1)]
for i in range(w):
    a[i][i + 1] = 1

for cnt in range(0, w + 1):
    a[-1][-1 - cnt] = h ** cnt

ans = [[0] for _ in range(w + 1)]
ans[-1][0] = 1
ans[-2][0] = 1

while c > 0:
    if c % 2 == 1:
        ans = prod(a, ans)
    c = c // 2
    if c > 0:
        a = prod(a, a)

print(ans[-1][0])


You are given three integers $$$n$$$, $$$k$$$ and $$$f$$$.Consider all binary strings (i. e. all strings consisting of characters $$$0$$$ and/or $$$1$$$) of length from $$$1$$$ to $$$n$$$. For every such string $$$s$$$, you need to choose an integer $$$c_s$$$ from $$$0$$$ to $$$k$$$.A multiset of binary strings of length exactly $$$n$$$ is considered beautiful if for every binary string $$$s$$$ with length from $$$1$$$ to $$$n$$$, the number of strings in the multiset such that $$$s$$$ is their prefix is not exceeding $$$c_s$$$.For example, let $$$n = 2$$$, $$$c_{0} = 3$$$, $$$c_{00} = 1$$$, $$$c_{01} = 2$$$, $$$c_{1} = 1$$$, $$$c_{10} = 2$$$, and $$$c_{11} = 3$$$. The multiset of strings $$$\{11, 01, 00, 01\}$$$ is beautiful, since:  for the string $$$0$$$, there are $$$3$$$ strings in the multiset such that $$$0$$$ is their prefix, and $$$3 \le c_0$$$;  for the string $$$00$$$, there is one string in the multiset such that $$$00$$$ is its prefix, and $$$1 \le c_{00}$$$;  for the string $$$01$$$, there are $$$2$$$ strings in the multiset such that $$$01$$$ is their prefix, and $$$2 \le c_{01}$$$;  for the string $$$1$$$, there is one string in the multiset such that $$$1$$$ is its prefix, and $$$1 \le c_1$$$;  for the string $$$10$$$, there are $$$0$$$ strings in the multiset such that $$$10$$$ is their prefix, and $$$0 \le c_{10}$$$;  for the string $$$11$$$, there is one string in the multiset such that $$$11$$$ is its prefix, and $$$1 \le c_{11}$$$. Now, for the problem itself. You have to calculate the number of ways to choose the integer $$$c_s$$$ for every binary string $$$s$$$ of length from $$$1$$$ to $$$n$$$ in such a way that the maximum possible size of a beautiful multiset is exactly $$$f$$$.

The only line of input contains three integers $$$n$$$, $$$k$$$ and $$$f$$$ ($$$1 \le n \le 15$$$; $$$1 \le k, f \le 2 \cdot 10^5$$$).

Print one integer — the number of ways to choose the integer $$$c_s$$$ for every binary string $$$s$$$ of length from $$$1$$$ to $$$n$$$ in such a way that the maximum possible size of a beautiful multiset is exactly $$$f$$$. Since it can be huge, print it modulo $$$998244353$$$.

NoteIn the first example, the three ways to choose the integers $$$c_s$$$ are:  $$$c_0 = 0$$$, $$$c_1 = 2$$$, then the maximum beautiful multiset is $$$\{1, 1\}$$$;  $$$c_0 = 1$$$, $$$c_1 = 1$$$, then the maximum beautiful multiset is $$$\{0, 1\}$$$;  $$$c_0 = 2$$$, $$$c_1 = 0$$$, then the maximum beautiful multiset is $$$\{0, 0\}$$$.

import os
import sys
from io import BytesIO, IOBase

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().rstrip("\r\n")

class FFT:
    def __init__(self, MOD=998244353):
        FFT.MOD = MOD
        g = self.primitive_root_constexpr()
        ig = pow(g, FFT.MOD - 2, FFT.MOD)
        FFT.W = [pow(g, (FFT.MOD - 1) >> i, FFT.MOD) for i in range(30)]
        FFT.iW = [pow(ig, (FFT.MOD - 1) >> i, FFT.MOD) for i in range(30)]

    def primitive_root_constexpr(self):
        if FFT.MOD == 998244353:
            return 3
        elif FFT.MOD == 200003:
            return 2
        elif FFT.MOD == 167772161:
            return 3
        elif FFT.MOD == 469762049:
            return 3
        elif FFT.MOD == 754974721:
            return 11
        divs = [0] * 20
        divs[0] = 2
        cnt = 1
        x = (FFT.MOD - 1) // 2
        while x % 2 == 0:
            x //= 2
        i = 3
        while i * i <= x:
            if x % i == 0:
                divs[cnt] = i
                cnt += 1
                while x % i == 0:
                    x //= i
            i += 2
        if x > 1:
            divs[cnt] = x
            cnt += 1
        g = 2
        while 1:
            ok = True
            for i in range(cnt):
                if pow(g, (FFT.MOD - 1) // divs[i], FFT.MOD) == 1:
                    ok = False
                    break
            if ok:
                return g
            g += 1

    def fft(self, k, f):
        for l in range(k, 0, -1):
            d = 1 << l - 1
            U = [1]
            for i in range(d):
                U.append(U[-1] * FFT.W[l] % FFT.MOD)

            for i in range(1 << k - l):
                for j in range(d):
                    s = i * 2 * d + j
                    f[s], f[s + d] = (f[s] + f[s + d]) % FFT.MOD, U[j] * (f[s] - f[s + d]) % FFT.MOD

    def ifft(self, k, f):
        for l in range(1, k + 1):
            d = 1 << l - 1
            for i in range(1 << k - l):
                u = 1
                for j in range(i * 2 * d, (i * 2 + 1) * d):
                    f[j+d] *= u
                    f[j], f[j + d] = (f[j] + f[j + d]) % FFT.MOD, (f[j] - f[j + d]) % FFT.MOD
                    u = u * FFT.iW[l] % FFT.MOD

    def convolve(self, A, B):
        n0 = len(A) + len(B) - 1
        k = (n0).bit_length()
        n = 1 << k
        A += [0] * (n - len(A))
        B += [0] * (n - len(B))
        self.fft(k, A)
        self.fft(k, B)
        A = [a * b % FFT.MOD for a, b in zip(A, B)]
        self.ifft(k, A)
        inv = pow(n, FFT.MOD - 2, FFT.MOD)
        A = [a * inv % FFT.MOD for a in A]
        del A[n0:]
        return A

MOD = 998244353
def solve():
    n, k, f = map(int, input().split())
    if f > 2 * k:
        print(0)
        return

    fft = FFT()
    A = [1] * (k + 1)
    for i in range(n):
        B = fft.convolve(A[:], A[:])
        if i == n - 1:
            break
        tot = sum(B[k+1:]) % MOD
        A = [0] * (k + 1)
        cum = 0
        for i in range(k, -1, -1):
            A[i] += tot + B[i] * (k + 1 - i)
            A[i] %= MOD
            tot += B[i]
            if tot >= 0:
                tot -= MOD
    print(B[f])

for _ in range(1):
    solve()