# 1
'''
def f(s,m):
    if s>=59 or m<0: return m%2==0
    h=[f(s+1,m-1),f(s+3,m-1),f(s*3,m-1)]
    return any(h) if (m-1)%2==0 else all(h)
print(19, [x for x in range(1, 58+1) if f(x, 2) and not f(x,1)])
print(20, [x for x in range(1, 58+1) if f(x, 3) and not f(x,1)])
print(19, [x for x in range(1, 58+1) if f(x, 4) and not f(x,2)])
'''

# 2
'''
def f(s,m,c,end):
    if s*m>=123 or c>end:return c%2==end%2
    h=[f(s+2,m,c+1,end),f(s,m+2,c+1,end),f(s*2,m,c+1,end),f(s,m*2,c+1,end)]
    return any(h) if (c+1)%2==end%2 else all(h)
print(19, [x for x in range(1,40+1) if f(3,x,0,2)])
print(20, [x for x in range(1,40+1) if not f(3,x,0,1) and f(3,x,0,3)])
print(21, [x for x in range(1,40+1) if not f(3,x,0,2) and f(3,x,0,4)])
'''

# 3
'''def f(s,m,c):
    if s+m>=175 or c<0:return c%2==0
    h=[f(s+1,m,c-1),f(s,m+1,c-1),f(s*3,m,c-1),f(s,m*3,c-1)]
    return any(h) if (c-1)%2==0 else all(h)
#print(19,[m for m in range(1,154+1) if f(19,m,2)])
print(20,[s for s in range(1,154+1) if not f(19,s,1) and f(19,s,3)])
print(21,[s for s in range(1,154+1) if not (f(19,s,2) and f(19,s,4))])
'''

# 4
'''def f(s,m,c):
    if c<0 or s+m>=159:return c%2==0
    h=[f(s+1,m,c-1),f(s+3,m,c-1),f(s,m+1,c-1),f(s,m+3,c-1),f(s*2,m,c-1),f(s,m*2,c-1)]
    return any(h) if (c-1)%2==0 else any(h)
print(19, [s for s in range(1,159+1) if f(7,s,2)])
print(20, [s for s in range(1,159+1) if not f(7,s,1) and f(7,s,3)])
print(20, [s for s in range(1,159+1) if not f(7,s,2) and f(7,s,4)])
'''

# 5
'''def f(s,c):
    if s<=12 or c<0:return c%2==0
    h=[f(s//3,c-1),f(s-12,c-1)]
    return any(h) if (c-1)%2==0 else any(h)
print(19,[s for s in range(13,1000) if f(s,2)])
print(20,[s for s in range(13,1000) if not f(s,1) and f(s,3)])
print(21,len([s for s in range(13,100000) if not f(s,2) and f(s,4)]))
'''
