from sys import stdin,stdout,setrecursionlimit,maxint,exit
#setrecursionlimit(10**5)
def listInput():
 return map(long,stdin.readline().split())
def printBS(li):
 for i in xrange(len(li)-1):
  stdout.write("%d "%li[i])
 stdout.write("%d\n"%li[-1])
def sin():
 return stdin.readline().rstrip()
def check(a,b,c,d):
 if (a[0]-b[0])*(a[1]-c[1])==(a[0]-c[0])*(a[1]-b[1]) or (a[0]-b[0])*(a[1]-d[1])==(a[1]-b[1])*(a[0]-d[0]):
  return False
 if b[0]-a[0]==c[0]-d[0] and b[1]-a[1]==c[1]-d[1]:
  return True
 elif c[0]-a[0]==b[0]-d[0] and c[1]-a[1]==b[1]-d[1]:
  return True
 elif c[0]-a[0]==d[0]-b[0] and c[1]-a[1]==d[1]-b[1]:
  return True
 return False
a=listInput()
b=listInput()
c=listInput()
M=1000
ans=[]
for i in xrange(-M,M+1):
 for j in xrange(-M,M+1):
  if check(a,b,c,[i,j]):
   ans.append([i,j])
print len(ans)
for i,j in ans:
 stdout.write("%d %d\n"%(i,j))


from sys import stdin,stdout,setrecursionlimit,maxint,exit
#setrecursionlimit(10**5)
def listInput():
 return map(long,stdin.readline().split())
def printBS(li):
 for i in xrange(len(li)-1):
  stdout.write("%d "%li[i])
 stdout.write("%d\n"%li[-1])
def sin():
 return stdin.readline().rstrip()
def check(a,b,c,d):
 if (a[0]-b[0])*(a[1]-c[1])==(a[0]-c[0])*(a[1]-b[1]) or (a[0]-b[0])*(a[1]-d[1])==(a[1]-b[1])*(a[0]-d[0]):
  return False
 if b[0]-a[0]==c[0]-d[0] and b[1]-a[1]==c[1]-d[1]:
  return True
 elif c[0]-a[0]==b[0]-d[0] and c[1]-a[1]==b[1]-d[1]:
  return True
 elif c[0]-a[0]==d[0]-b[0] and c[1]-a[1]==d[1]-b[1]:
  return True
 return False
a=listInput()
b=listInput()
c=listInput()
M=1000
ans=[]
for i in xrange(-M,M+1):
 for j in xrange(-M,M+1):
  if (i,j) not in [a,b,c] and check(a,b,c,[i,j]):
   ans.append([i,j])
print len(ans)
for i,j in ans:
 print i,j


#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8

r=raw_input()
s = r[1:]
s = s[:-1]
s=s.replace('at','@',1)
s=s.replace('dot','.')
s = r[0] + s + r[-1]
print s


s = input()
l = [i for i in s]
l.append('.')
l.append('.')
l.append('.')
n = len(s)
p = []
p.append(s[0])
i = 1
f=0
while i<n:
    if s[i]=='d' and s[i+1]=='o' and s[i+2]=='t':
        p.append('.')
        i+=2
    elif s[i]=='a' and s[i+1]=='t' and f==0:
        p.append('@')
        f=1
        i+=1
    else:
        p.append(s[i])
    i+=1
#print(p)
if p[-1]=='.':
    p.pop()
    p.append('d')
    p.append('o')
    p.append('t')
print(''.join(p))


s=str(raw_input())

head=''
if a.startswith'dot':
	head='dot'
	a=[3:]
elif a.startswith('at'):
	head='at'
	a=[2:]

tail=''
if a.endswith('dot'):
	tail='dot'
	a=a[:len(a)-3]
elif a.endswith('at'):
	tail='at'
	a=a[:len(a)-2]
print head + a.replace("dot", ".").replace("at", "@", 1) + tail


n = input()
x, y = map(int, raw_input().split())
if x + y <= n + 1:
    print "White"
else:
    print "Black"


By kudlacz964, contest: Lyft Level 5 Challenge 2018 - Final Round (Open Div. 2), problem: (A) The King's Race, Wrong answer on test 34, #
 import math

n = int(input())
x, y = map(int, input().split(" "))

white = math.sqrt((x - 1) * (x - 1) + (y - 1) * (y - 1))
black = math.sqrt((x - n) * (x - n) + (y - n) * (y - n))

if white == black:
	if x > int(n / 2) and y > int(n / 2):
		print("Black")
	else:
		print("White")
elif white < black:
	print("White")
else:
	print("Black")


#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;

int main() {
	long long n, x, y;
	cin >> n;
	cin >> x >> y;
	if(x + y <= n + 1) {
		cout << "White" << endl;
	} else {
		cout << "Black" << endl;
	}
	return 0;
}


#include <iostream>

using namespace std;

int main(){
    // take inputs
    long long board_length;
    long long price_coordinate_x;
    long long price_coordinate_y;

    cin >> board_length;
    cin >> price_coordinate_x;
    cin >> price_coordinate_y;

    // starting points for kings
    int white_x = 1;
    int white_y = 1;
    long long black_x = board_length;
    long long black_y = board_length;

    // Difference between price coordinate points
    long long point_difference_white = llabs(price_coordinate_x-price_coordinate_y);
    long long point_difference_black = llabs(price_coordinate_x-price_coordinate_y);

    // if x > y => y will be the first value we'll reach
    if (price_coordinate_x > price_coordinate_y) {
        point_difference_white += llabs(white_x-price_coordinate_y);
        point_difference_black += llabs(black_x-price_coordinate_x);
    }
    else if (price_coordinate_x < price_coordinate_y) {
        point_difference_white += llabs(white_x-price_coordinate_x);
        point_difference_black += llabs(black_y-price_coordinate_y);
    }
    else {
        point_difference_white += llabs(white_x-price_coordinate_x);
        point_difference_black += llabs(black_x-price_coordinate_x);
    }

    if (point_difference_black >= point_difference_white) {
        cout << "White" << endl;
    }
    else if (point_difference_black < point_difference_white) {
        cout << "Black" << endl;
    }
    return 0;
}


def getDistance(x,y,n):
	w = (x-1)**2+(y-1)**2
	b = (x-n)**2+(y-n)**2
	if w > b:
		return 'Black'
	return 'White'

if __name__=='__main__':
	n = int(input())
	t = raw_input().strip().split(' ')
	x = int(t[0])
	y = int(t[1])
	return getDistance(x,y,n)


[n,m,a,b] = [int(x) for x in raw_input().split()]

if (a-1)%m == 0:
    if b - a < m:
        print 1
    elif b%m == 0:
        print 1
    elif b == n:
        print 1
    else:
        print 2
else:
    if (a-1)/m*m+m >= b:
        print 1
    elif (a-1)/m*m+2*m >= b:
        print 2
    elif b%m == 0:
        print 2
    elif b == n:
        print 2
    elif (b-a+1)%m == 0:
	print 2
    else:
        print 3


from itertools import permutations
import sys
from math import *
ics, per, first, last = map(int, raw_input().split())
per = float(per)
x1 = int(ceil(first / per))
y1 = int(first % per)
x2 = int(ceil(last / per))
y2 = int(last % per)

if x1 == x2:
    print 1
    exit()

if y1 == 1 and y2 == 0:
    print 1
    exit()

if y1 == 1 and last == ics:
    print 1
    exit()

if per == 1:
    print 1
    exit()

if abs(x1-x2) == 1:
    print 2
    exit()

if y1 == 1:
    print 2
    exit()

if y2 == 0:
    print 2
    exit()

if last == ics:
    print 2
    exit()

if y1-y2 == 1 or y2-y1 == per - 1:
    print 2
    exit()

print 3


n, m, a, b = map(int, raw_input().split())
n -= 1
a -= 1
b -= 1
ax = a%m
ay = a/m
bx = b%m
by = b/m
if (ay == by) or ((ax == 0) and (b == n)) or ((ax == 0) and (bx == m-1)):
    print 1
elif (ay+1 == by) or (ax == 0) or (bx == m-1) or (b == n) or (ax-1 == bx):
    print 2
else:
    print 3


#!/usr/bin/python3

n, m, a, b = map(int, input().split())

a -= 1
b -= 1
if a // m == b // m:
    print(1)
elif a % m == 0 and (b + 1) % m == 0:
    print(1)
elif a % m == 0 and b + 1 == n:
    print(1)
elif b + 1 == n:
    print(2)
elif a % m == 0 or (b + 1) % m == 0:
    print(2)
elif a % m == (b + 1) % m:
    print(2)
elif b // m - a // m == 1:
    print(2)
elif m == 2:
    print(2)
else:
    print(3)


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

start = a % m
end = b % m
if start == 0: start = m
if end == 0: end = m

start_l = (a - 1) / m
end_l = (b - 1) / m

if start_l == end_l:
  print 1
elif start_l + 1 == end_l:
  if start == 1 and (b == n or end == m):
  else:
    print 2
else:
  ans = 1
  if start != 1:
    ans += 1
  if end != m and b != n:
    ans += 1

  if start == end + 1:
    ans = min(ans, 2)

  print ans


n,k=map(int,input().split())
A=input().split()[:n]
B=[]
s=0
ma=int(0)
for i in range(101):
  B.append([0]*2)
  B[i][0]=i
  B[i][1]=0
for i in range(n):
  A[i]=int(A[i])
  for j in range(1,101):
    if A[i]==B[j][0]:
      B[j][1]+=1
for i in range(101):
  if B[i][1]>s:
    s=B[i][1]
  if B[i][1]>0:

if s%k==0:
  ma=s
elif s<k:
  ma=k
else:
  ma=int(s/k)*k+k
s=0
for i in range(101):
  if B[i][1]>0:
    s+=ma-B[i][1]
print(s)


a, b = map(int, input().split())
aest = list(map(int, input().split()))
best = set(aest)
maxim = 0
for i in best:
    if maxim < aest.count(i):
        maxim = aest.count(i)
colvo = (maxim + b - 1) // b
print(len(best) * colvo * b - a)


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

l = [int(x) for x in input().strip().split()]

c = {}
for i in l:
	if i in c:
		c[i]+=1
	else:
		c[i]=1

typecounts=list(c.values())

max = max(typecounts)
set = (-(-max//k))

totalutincils = len(typecounts)*set*k

print(totalutincils - n)


from math import ceil,floor
from collections import defaultdict as dd
d=dd(lambda:0)
n,k=map(int,input().split())
l=list(map(int,input().split()))
for i in l:
	d[i]+=1
s=len(set(l))
a=max(d.values())
m=ceil(a/k)
if a>k:
	print((s*m*k)-n)
else:
# 	print(s*k-n)


 list = [int(number) for number in input().split()]
n, k = list[0], spisok[1]
cc = [int(o) for o in input().split()]

d = dict()
for c in cc:
    d[c] = d.get(c, 0) + 1
m = max(d.values())
nb = m // k
if m % k != 0:
    nb += 1
print(nb * len(d) * k - n)


"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by adi0311(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from fractions import Fraction
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def outln(var): sys.stdout.write(str(var)+"\n")
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

n = int(data())
graph = dd(set)
for i in range(n):
    u, v = sp()
    graph[u].add(v)
    graph[v].add(u)
cnt = 0
for i in range(1, 6):
    if len(graph[i]) <= 1:
        cnt += 1
if cnt >= 3:
    outln("WIN")
    exit()
for i in range(1, 6):
    for j in graph[i]:
        if len(graph[i].intersection(graph[j])) >= 1:
            outln("WIN")
            exit()
outln("FAIL")


def frien(arr):
    cont=0
    cont1=0
    cont2 = 0
    cont3 = 0
    cont4 = 0
    cont5 = 0
    cont6 = 0
    cont7 = 0
    cont8 = 0
    cont9 = 0
    cont10 = 0
    aux=0
    arr2=[]
    for i in arr:
        for j in i:
            arr2.append(j)
            if j==0:
                cont+=1
                if cont==3:
                    return "WIN"
            elif j==1:
                cont1+=1
                if cont1==3:
                    return "WIN"
            elif j==2:
                cont2+=1
                if cont2==3:
                    return "WIN"
            elif j==3:
                cont3+=1
                if cont3==3:
                    return "WIN"
            elif j==4:
                cont4+=1
                if cont4==3:
                    return "WIN"
            elif j==5:
                cont5+=1
                if cont5==3:
                    return "WIN"
            elif j==6:
                cont6+=1
                if cont6==3:
                    return "WIN"
            elif j==7:
                cont7+=1
                if cont7==3:
                    return "WIN"
            elif j==8:
                cont8+=1
                if cont8==3:
                    return "WIN"
            elif j==9:
                cont9+=1
                if cont9==3:
                    return "WIN"
            else:
                cont10+=1
                if cont10==3:
                    return "WIN"

    for val in range(min(arr2),max(arr2)):
        if val == 0 and cont==1:
            aux+= 1
            if aux == 3:
                return "WIN"
        elif j == 1 and cont1==1:
            aux += 1
            if aux == 3:
                return "WIN"
        elif j == 2 and cont2==1:
            aux += 1
            if aux == 3:
                return "WIN"
        elif j == 3 and cont3==1:
            aux += 1
            if aux == 3:
                return "WIN"
        elif j == 4 and cont4==1:
            aux += 1
            if aux == 3:
                return "WIN"
        elif j == 5 and cont5==1:
            aux += 1
            if aux == 3:
                return "WIN"
        elif j == 6 and cont6==1:
            aux += 1
            if aux == 3:
                return "WIN"
        elif j == 7 and cont7==1:
            aux += 1
            if aux == 3:
                return "WIN"
        elif j == 8 and cont8==1:
            aux += 1
            if aux == 3:
                return "WIN"
        elif j == 9 and cont==1:
            aux += 1
            if aux == 3:
                return "WIN"
        elif j==10 and cont10==1:
            aux += 1
            if aux == 3:
                return "WIN"
        else:
            continue

    return "FAIL"

ar=[]
n = int(input())
for i in range(n):
    ar.append(list(map(int, input().strip().split())))

print(frien(ar))


"""
    Template written to be used by Python Programmers.
    Use at your own risk!!!!
    Owned by adi0311(rating - 5 star at CodeChef and Specialist at Codeforces).
"""
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from fractions import Fraction
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(var): sys.stdout.write(str(var))
def outln(var): sys.stdout.write(str(var)+"\n")
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

def dfs(source, p):
    global cycle_number
    if color[source] == 2:
        return
    if color[source] == 1:
        cycle_number += 1
        cur = p
        mark[cur] = cycle_number
        while cur != source:
            cur = par[cur]
            mark[cur] = cycle_number
        return
    par[source] = p
    color[source] = 1
    for child in graph[source]:
        if child == par[source]:
            continue
        dfs(child, source)
    color[source] = 2

n = int(data())
graph = dd(set)
color, par, mark = [0] * (n+1), [0] * (n+1), [0] * (n+1)
cycles = [[]] * (n+1)
cycle_number = 0
for i in range(n):
    u, v = sp()
    graph[u].add(v)
    graph[v].add(u)
cnt = 0
for i in range(1, 6):
    if len(graph[i]) <= 1:
        cnt += 1
if cnt >= 3:
    outln("WIN")
    exit()
dfs(1, 0)
for i in range(1, n + 1):
    if mark[i] != 0:
        cycles[mark[i]].append(i)
for i in cycles:
    if len(i) == 3:
        outln("WIN")
        exit()
outln("FAIL")


a=map(lambda x:raw_input(),range(input()))
print ["WIN","FAIL"][sorted(a)==list("     1122334455")]


n=int(input())
vis=[]
for i in range(5):
    vis.append(0)
for i in range(n):
    a,b=map(int,input().split())
    vis[a-1]+=1
    vis[b-1]+=1
count=0
for i in vis:
    if i<=1:
        count+=1
if count>=3 or n>=3:
    print("WIN")
else:
    print("FAIL")


import re
o=raw_input().split(':-')
t=map(len, re.split('[^_]', o[0][2:-1]))
y=o[1].split('.')[0].split(',')
l=map(lambda x,y:y and x or x[::-1],[map(len,re.split('[<>]', i)) for i in y],[len(re.split('[<]', i))-1 for i in y])
u=[0]*1025
E=0
while not E:
  E=2
  for i in range(len(l)):
    a,b=l[i]
    if u[a]>=u[b]:
      E=0
      u[b]=u[a]+1
      if u[b]>9:E=1
print[0,'false',''.join([str(u[x])for x in t])][E]


sa, sb = raw_input().split('):-')
sa = list(sa[2:])
sb = sb[:-1]
for i in xrange(len(sa)):
    if sa[i] != '_':
        sa[i] = ','
a = ''.join(sa).split(',')
b = sb.split(',')
for i in xrange(len(b)):
    if '<' in b[i]:
        b[i] = b[i].split('<')
    else:
        b[i] = list(reversed(b[i].split('>')))
nums = {i: 0 for i in a}
while True:
    flag = True
    false = False
    for (na, nb) in b:
        if nums[na] >= nums[nb]:
            flag = False
            nums[nb] += 1
            if nums[nb] >= 10:
                false = True
                break
    if flag or false:
        break
if false:
    print 'false'
else:
    print ''.join(map(str, map(lambda x: nums[x], a)))


import re

line=input()

line = line.rstrip('.')
a, b, c = line.partition("):-")
rels = c.split(',')

relations = set()
for rel in rels:
    if "<" in rel:
        x, _, y = rel.partition("<")
        relations.add((len(x), len(y)))
    else:
        x, _, y = rel.partition(">")
        relations.add((len(y), len(x)))

a = a.lstrip("?(")
args = re.split(r"(\+|-|\*|/)", a)
args = [len(args[i]) for i in range(0, len(args), 2)]

# print(args)
# print(relations)

edges = {k:[] for k in args}
for j, i in relations:
    edges[i].append(j)

seen = {k:0 for k in args}

q = []

def topsort(k):
    if seen[k] == 1:
        print("false")
        quit()
    seen[k] = 1
    for other in edges[k]:
        topsort(other)
    q.append(k)
    seen[k] = 2
    return True

for k in args:
    if seen[k] == 0:
        topsort(k)

vals = {}

for k in q:
    others = edges[k]
    maxval = -1
    for other in others:
        maxval = max(maxval, vals.get(other, -1))
    vals[k] = maxval+1
    if(vals[k]>9):
        print("false")
        quit()

for k in args:
    print(vals[k], end='')

print()


import re

class Cond(object):
    def __init__(self, s):
        s = s.strip()
        i, j = 0, len(s)-1
        while i <= j and s[i] == '_':
            i += 1
        while i <= j and s[j] == '_':
            j -= 1
        if i > j or s[i:j+1] not in ['<', '=', '>', '<=', '>=']:
            print s[i:j+1]
            raise ValueError
        self.va, self.op, self.vb = s[:i], s[i:j+1], s[j+1:]
    def check(self, val):
         if self.va in val and self.vb in val:
             return eval('%d%s%d' % (val[self.va], self.op, val[self.vb]))
         else:
             return True

def feed(var, conds, val):
    for x in conds:
        if not x.check(val):
            return False
    if var == []:
        return True
    if var[0] in val:
        return feed(var[1:], conds, val)
    c = var[0]
    for v in range(10):
        val[c] = v
        if feed(var[1:], conds, val):
            return True
        del val[c]
    return False

s= raw_input()
jaw, stomach = s.split(':-')
if stomach[-1] == '.':
    stomach = stomach[:-1]
var = re.findall(r'_+', jaw)
conds = [Cond(c) for c in stomach.split(',')]
val = dict()
if not feed(var, conds, val):
    print 'false'
else:
    o = ''.join([str(val[x]) for x in var])
    print o


q = int(input())
import numpy as np
for i in range(q):
	a, b, m = list(map(int,input().split()))
	l = a + 1
	r = a + m
	c = 0
	poziom = 0
	while True:
		if l > b:
			print(-1)
			break
		if b <= r and b >= l:
			c = 1
			last = [l, r]
			break
		poziom += 1
		l *= 2
		r *= 2
	if c == 1:
		mat = [(a + 1) * 2 ** i for i in range(poziom + 1)]
		sumka = a
		for i in range(poziom + 1):
			if mat[-1] == b:
				break
			elif i == poziom:
				mat[-1] = b
				break
			else:
				pom = min(sumka + m - mat[i], (b - mat[-1]) // (2 ** (poziom - i - 1)))
				mat[i] += pom
				for j in range(i + 1, poziom + 1):
					mat[j] += pom * 2 ** (j - i -1)
				sumka += mat[i]
		print(len(mat) + 1, end = " ")
		print(a, end =  " ")
		for i in range(len(mat)):
			if i < len(mat) - 1:
				print(mat[i], end = " ")
			else:
				print(mat[i], end = "\n")


q = int(input())
import numpy as np
for i in range(q):
	a, b, m = list(map(int,input().split()))
	l = a + 1
	r = a + m
	c = 0
	poziom = 0
	while True:
		if l > b:
			print(-1)
			break
		if b <= r and b >= l:
			c = 1
			last = [l, r]
			break
		poziom += 1
		l *= 2
		r *= 2
	if c == 1:
		mat = [(a + 1) * 2 ** i for i in range(poziom + 1)]
		sumka = a
		for i in range(poziom + 1):
			if mat[-1] == b:
				break
			else:
				pom = min(sumka + m - mat[i], (b - mat[-1]) // (2 ** (poziom - i)))
				sumka += mat[i]
				for j in range(i, poziom + 1):
					mat[j] += pom * 2 ** (j - i)
		print(len(mat) + 1, end = " ")
		print(a, end =  " ")
		for i in range(len(mat)):
			if i < len(mat) - 1:
				print(mat[i], end = " ")
			else:
				print(mat[i], end = "\n")


import sys
sys.stdin = open('C:\\Users\\sharr\\Documents\\Input.txt', 'r')
sys.stdout = open('C:\\Users\\sharr\\Documents\\Output.txt', 'w')

q = int(input())
for _ in range(q):
	a, b, m = map(int, input().split())
	mn = [a]
	mx = [a]
	sum_mn = a
	sum_mx = a
	ok = False

	for n in range(51):
		if mn[-1] <= b <= mx[-1]:
			ok = True
			break

		mn.append(sum_mn + 1)
		mx.append(sum_mx + m)
		sum_mn += mn[-1]
		sum_mx += mx[-1]

		if mn[-1] > b:
			break

	if not ok:
		print(-1)
		continue

	r = [0] * n
	s = b - mn[-1]
	for i in range(n):
		x = s // max(1, 2 ** (n - i - 2))
		if x > m - 1:
			x = m - 1
		r[i] = x + 1
		s -= x * max(1, 2 ** (n - i - 2))

	s = a
	res = [a]
	for i in range(n):
		res.append(s + r[i])
		s += res[-1]

	print(len(res), *res)


from sys import stdin, stdout

n = int(stdin.readline())

for nn in range(n):
    a, b, m = map(int,stdin.readline().split())
    if a == b:
        stdout.write('{} {}\n'.format(1,a))
    else:
        for j in range(2,51):
            if (a+1)<<(j-2) <= b and b <= (a+m)<<(j-2):
                B = b
                b -= a<<(j-2)
                stdout.write('{} {}'.format(j, a))
                s = a
                for i in range(j-2):
                    for k in range(m,0,-1):
                        if b - (k<<(j-3-i)) >= 1<<(j-3-i):
                            a = s+k
                            stdout.write(' {}'.format(a))
                            s += a
                            b -= k<<(j-3-i)
                            break
                stdout.write(' {}\n'.format(B))
                break
        else:
            stdout.write('-1\n')


for _ in range(int(input())):
    a, b, m = [int(i) for i in input().split()]

    if a == b:
        print("1 " + str(a))
        continue

    l = a + 1
    r = a + m
    cnt = 1
    while r < b:
        l += l
        r += r
        cnt += 1

    if l > b:
        print(-1)
        continue

    ls = [1] * cnt
    p2 = [2 ** (cnt - 2 - i) for i in range(cnt - 1)] + [1]
    for i in range(cnt):
        while ls[i] < m and l + p2[i] <= b:
            ls[i] += 1
            l += p2[i]

    ans = [a]
    ps = a
    for i in ls:
        a = ps + i
        ps += a
        ans += [a]

    print(str(cnt + 1) + " " + ' '.join(str(i) for i in ans))


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

n = int(minp())
m = [None]*n
k = [None]*3
dp = [None]*3
dp[0] = [None]*(n*n)
dp[1] = [None]*(n*n)
dp[2] = [None]*(n*n)
path = [None]*(n*n)
for i in range(n):
	m[i] = list(map(int, minp().split()))
	for j in range(n):
		path[m[i][j]-1] = (i,j)
for z in range(3):
	k_ = [None]*n
	for i in range(n):
		kk = [None]*n
		for j in range(n):
			kkk_ = [None]*3
			for zz in range(3):
				kkk = [None]*n
				for w in range(n):
					kkk[w] = [(1000000,0)]*n
				kkk_[zz] = kkk
			kk[j] = kkk_
		k_[i] = kk
	k[z] = k_

q = [0]*(10*n*n)
qr = 0
km = [(1,2),(1,-2),(-1,2),(-1,-2),(2,1),(2,-1),(-2,1),(-2,-1)]
sm = [(1,1),(1,-1),(-1,1),(-1,-1)]
lm = [(0,1),(0,-1),(-1,0),(1,0)]
mm = [km,sm,lm]
for z in range(3):
	for i in range(n):
		for j in range(n):
			#print('========')
			ql = 0
			qr = 1
			q[0] = (z, i, j, (0,0))
			kc = k[z][i][j]
			kc[z][i][j] = (0, 0)
			while ql < qr:
				t, x, y, dd = q[ql]
				#print(t,x,y,dd)
				d = kc[t][x][y]
				ql += 1
				if d != dd:
					continue
				dd = (d[0]+1, d[1]+1)
				for tt in range(3):
					if t != tt and kc[tt][x][y] > dd:
						kc[tt][x][y] = dd
						q[qr] = (tt,x,y,dd)
						qr += 1
				dd = (d[0]+1,d[1])
				if t == 0:
					for w in mm[t]:
						xx,yy = w[0]+x,w[1]+y
						if xx >= 0 and xx < n and yy >= 0 and yy < n:
							if kc[t][xx][yy] > dd:
								kc[t][xx][yy] = dd
								q[qr] = (t,xx,yy,dd)
								qr += 1
				else:
					for w in mm[t]:
						for hm in range(n*2):
							xx,yy = w[0]*hm+x,w[1]*hm+y
							if xx >= 0 and xx < n and yy >= 0 and yy < n:
								if kc[t][xx][yy] > dd:
									kc[t][xx][yy] = dd
									q[qr] = (t,xx,yy,dd)
									qr += 1
							else:
								break
dp[0][0] = (0,0)
dp[1][0] = (0,0)
dp[2][0] = (0,0)
for i in range(0,n*n-1):
	x,y = path[i]
	xx,yy = path[i+1]
	for z in range(3):
		for j in range(3):
			dist = k[j][x][y][z][xx][yy]
			if dp[j][i] != None:
				nd = (dp[j][i][0]+dist[0],dp[j][i][1]+dist[1])
				if dp[z][i+1] == None:
					dp[z][i+1] = nd
				else:
					dp[z][i+1] = min(dp[z][i+1],nd)
for j in range(n*n-1,n*n):
	qq = [dp[i][j] if dp[i][j] != None else (1000000,0) for i in range(3)]
	qm = min(qq)
	#print(j,qm)
	print(qm[0], qm[1])


n=int(input())
lookup={}
for i in range(n):
    x=input()
    x=x.split()
    for j in range(n):
        lookup[int(x[j])]=(i,j)
bestrook=[0,0]
bestbish=[0,0]
bestknight=[0,0]
for i in range(1,n**2):
    x=abs(lookup[i][0]-lookup[i+1][0])
    y=abs(lookup[i][1]-lookup[i+1][1])
    if x==0 or y==0:
        bestrook[0]+=1
    else:
        bestrook[0]+=2
    if x==y:
        bestbish[0]+=1
    elif (x-y)%2==0:
        bestbish[0]+=2
    else:
        bestbish[0]+=1000
    if {x,y}=={1,2}:
        bestknight[0]+=1
    elif x**2+y**2 in {4,16,20,10,18}:
        bestknight[0]+=2
    elif x**2+y**2==2 and not lookup[i] in {(0,0),(n-1,0),(0,n-1),(n-1,n-1)} and not lookup[i+1] in {(0,0),(n-1,0),(0,n-1),(n-1,n-1)}:
        bestknight[0]+=2
    elif {x,y} in [{5,0},{3,0},{1,0},{6,1},{4,1},{5,2},{3,2},{6,3},{4,3},{5,4}]:
        bestknight[0]+=3
    else:
        bestknight[0]+=1000
    if bestbish[0]>bestrook[0]+1:
        bestbish=[bestrook[0]+1,bestrook[1]+1]
    if bestrook[0]>bestbish[0]+1:
        bestrook=[bestbish[0]+1,bestbish[1]+1]
    if bestknight[0]>bestrook[0]+1:
        bestknight=[bestrook[0]+1,bestrook[1]+1]
    if bestrook[0]>bestknight[0]+1:
        bestrook=[bestknight[0]+1,bestknight[1]+1]
    if bestbish[0]>bestknight[0]+1:
        bestbish=[bestknight[0]+1,bestknight[1]+1]
    if bestknight[0]>bestbish[0]+1:
        bestknight=[bestbish[0]+1,bestbish[1]+1]
best=(bestrook[0],bestbish[0],bestknight[0])
if min(best)==best[0]:
    print(bestrook[0],bestrook[1])
elif min(best)==best[13]:
    print(bestbish[0],bestbish[1])
else:
    print(bestknight[0],bestknight[1])


n=int(input())
lookup={}
for i in range(n):
    x=input()
    x=x.split()
    for j in range(n):
        lookup[int(x[j])]=(i,j)
bestrook=[0,0]
bestbish=[0,0]
bestknight=[0,0]
for i in range(1,n**2):
    x=abs(lookup[i][0]-lookup[i+1][0])
    y=abs(lookup[i][1]-lookup[i+1][1])
    if x==0 or y==0:
        bestrook[0]+=1
    else:
        bestrook[0]+=2
    if x==y:
        bestbish[0]+=1
    elif (x-y)%2==0:
        bestbish[0]+=2
    else:
        bestbish[0]+=1000
    if {x,y}=={1,2}:
        bestknight[0]+=1
    elif x**2+y**2 in [4,16,20,10,18]:
        bestknight[0]+=2
    elif x**2+y**2==2 and lookup[i] not in [(0,0),(n-1,0),(0,n-1),(n-1,n-1)] and lookup[i+1] not in [(0,0),(n-1,0),(0,n-1),(n-1,n-1)]:
        bestknight[0]+=2
    elif {x,y} in [{5,0},{3,0},{1,0},{6,1},{4,1},{5,2},{3,2},{6,3},{4,3},{5,4}]:
        bestknight[0]+=3
    else:
        bestknight[0]+=1000
    if bestbish[0]>bestrook[0]+1:
        bestbish=[bestrook[0]+1,bestrook[1]+1]
    if bestrook[0]>bestbish[0]+1:
        bestrook=[bestbish[0]+1,bestbish[1]+1]
    if bestknight[0]>bestrook[0]+1:
        bestknight=[bestrook[0]+1,bestrook[1]+1]
    if bestrook[0]>bestknight[0]+1:
        bestrook=[bestknight[0]+1,bestknight[1]+1]
    if bestbish[0]>bestknight[0]+1:
        bestbish=[bestknight[0]+1,bestknight[1]+1]
    if bestknight[0]>bestbish[0]+1:
        bestknight=[bestbish[0]+1,bestbish[1]+1]
best=(bestrook[0],bestbish[0],bestknight[0])
if min(best)==best[0]:
    print(bestrook[0],bestrook[1])
elif min(best)==best[13]:
    print(bestbish[0],bestbish[1])
else:
    print(bestknight[0],bestknight[1])


n=int(input())
lookup={}
for i in range(n):
    x=input()
    x=x.split()
    for j in range(n):
        lookup[int(x[j])]=(i,j)
bestrook=[0,0]
bestbish=[0,0]
bestknight=[0,0]
for i in range(1,n**2):
    x=abs(lookup[i][0]-lookup[i+1][0])
    y=abs(lookup[i][1]-lookup[i+1][1])
    if x==0 or y==0:
        bestrook[0]+=1
    else:
        bestrook[0]+=2
    if x==y:
        bestbish[0]+=1
    elif (x-y)%2==0:
        bestbish[0]+=2
    else:
        bestbish[0]+=1000
    if {x,y}=={1,2}:
        bestknight[0]+=1
    elif x**2+y**2 in [4,16,20,10,18]:
        bestknight[0]+=2
    elif x**2+y**2==2 and lookup[i] not in [(0,0),(n-1,0),(0,n-1),(n-1,n-1)] and lookup[i+1] not in [(0,0),(n-1,0),(0,n-1),(n-1,n-1)]:
        bestknight[0]+=2
    elif {x,y} in [{5,0},{3,0},{1,0},{6,1},{4,1},{5,2},{3,2},{6,3},{4,3},{5,4}]:
        bestknight[0]+=3
    else:
        bestknight[0]+=1000
    if bestbish[0]>bestrook[0]+1:
        bestbish=[bestrook[0]+1,bestrook[1]+1]
    if bestrook[0]>bestbish[0]+1:
        bestrook=[bestbish[0]+1,bestbish[1]+1]
    if bestknight[0]>bestrook[0]+1:
        bestknight=[bestrook[0]+1,bestrook[1]+1]
    if bestrook[0]>bestknight[0]+1:
        bestrook=[bestknight[0]+1,bestknight[1]+1]
    if bestbish[0]>bestknight[0]+1:
        bestbish=[bestknight[0]+1,bestknight[1]+1]
    if bestknight[0]>bestbish[0]+1:
        bestknight=[bestbish[0]+1,bestbish[1]+1]
best=(bestrook[0],bestbish[0],bestknight[0])
if min(best)==best[0]:
    print(bestrook[0],bestrook[1])
elif min(best)==best[1]:
    print(bestbish[0],bestbish[1])
else:
    print(bestknight[0],bestknight[1])


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

n = int(minp())
m = [None]*n
k = [None]*n
s = [None]*n
l = [None]*n
dp = [None]*3
dp[0] = [None]*(n*n)
dp[1] = [None]*(n*n)
dp[2] = [None]*(n*n)
path = [None]*(n*n)
for i in range(n):
	m[i] = list(map(int, minp().split()))
	kk = [None]*n
	ss = [None]*n
	ll = [None]*n
	for j in range(n):
		path[m[i][j]-1] = (i,j)
		kkk = [None]*n
		sss = [None]*n
		lll = [None]*n
		for w in range(n):
			kkk[w] = [None]*n
			sss[w] = [None]*n
			lll[w] = [None]*n
		kk[j] = kkk
		ss[j] = sss
		ll[j] = lll
	k[i] = kk
	s[i] = ss
	l[i] = ll

q = [0]*(3*n*n)
qr = 0
km = [(1,2),(1,-2),(-1,2),(-1,-2),(2,1),(2,-1),(-2,1),(-2,-1)]
sm = [(1,1),(1,-1),(-1,1),(-1,-1)]
lm = [(0,1),(0,-1),(-1,0),(1,0)]
for i in range(n):
	for j in range(n):
		ql = 0
		qr = 1
		q[0] = (i, j)
		kc = k[i][j]
		kc[i][j] = 0
		while ql < qr:
			z = q[ql]
			d = kc[z[0]][z[1]]
			ql += 1
			for w in km:
				xx,yy = w[0]+z[0],w[1]+z[1]
				if xx >= 0 and xx < n and yy >= 0 and yy < n:
					if kc[xx][yy] == None:
						kc[xx][yy] = d+1
						q[qr] = (xx,yy)
						qr += 1
		#print(kc)
		ql = 0
		qr = 1
		q[0] = (i, j)
		kc = s[i][j]
		kc[i][j] = 0
		while ql < qr:
			z = q[ql]
			d = kc[z[0]][z[1]]
			ql += 1
			for w in sm:
				xx,yy = z[0],z[1]
				while True:
					xx += w[0]
					yy += w[1]
					if xx >= 0 and xx < n and yy >= 0 and yy < n:
						if kc[xx][yy] == None:
							kc[xx][yy] = d+1
							q[qr] = (xx,yy)
							qr += 1
					else:
						break
		#print(kc)
		ql = 0
		qr = 1
		q[0] = (i, j)
		kc = l[i][j]
		kc[i][j] = 0
		while ql < qr:
			z = q[ql]
			d = kc[z[0]][z[1]]
			ql += 1
			for w in lm:
				xx,yy = z[0],z[1]
				while True:
					xx += w[0]
					yy += w[1]
					if xx >= 0 and xx < n and yy >= 0 and yy < n:
						if kc[xx][yy] == None:
							kc[xx][yy] = d+1
							q[qr] = (xx,yy)
							qr += 1
					else:
						break
		#print(kc)
dp[0][0] = (0,0)
dp[1][0] = (0,0)
dp[2][0] = (0,0)
for i in range(0,n*n-1):
	x,y = path[i]
	xx,yy = path[i+1]
	for z in range(3):
		if z == 0:
			w = k
		elif z == 1:
			w = s
		else:
			w = l
		dist = w[x][y][xx][yy]
		if dist != None:
			for j in range(3):
				if dp[j][i] != None:
					if j == z:
						nd = (dp[j][i][0]+dist,dp[j][i][1])
					else:
						nd = (dp[j][i][0]+dist+1,dp[j][i][1]+1)
					if dp[z][i+1] == None:
						dp[z][i+1] = nd
					else:
						dp[z][i+1] = min(dp[z][i+1],nd)
for j in range(n*n-1,n*n):
	qq = [dp[i][j] if dp[i][j] != None else (100000,0) for i in range(3)]
	qm = min(qq)
	#print(j,qm)
	print(qm[0], qm[1])


wa = int(input ())
ha = int(input())
wb = int(input())
hb = int(input())

if wa > wb :
blocks =  wa + (2*ha) + wb + (2*hb) + 4 + (wa-wb)
print (blocks)


#include<bits/stdc++.h>
using namespace std;
int main(){
	int w1, w2, h1, h2;
	cin>>w1>>h1>>w2>>h2;
	cout<<(2*w1 + 2*h1 + 2*h2 + 4);
	return 0;
}


a=[int(x) for x in input().split(" ")
b=2(sum(a)+a[0]-a[2 + a[1]-a[3])
print(b)


c = input().split(" ")
for i in range(len(c)):
	c[i] = int(c[i])

a = sum(c)-ls[2]+2
print(2*a))


#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[]){
    int w, h, w1, h1;
    cin >> w >> h >> w1 >> h1;
    cout << 2*(w+h+h1+2) << "\n";

    return 0;
}


int fact(n):
    fact = [1]
    for i in range(2, n + 1):
        fact.append(i * fact[-1])
    return fact[-1]

int a(n, k):
    res = 1;
    for i in range(n - k + 1, n + 1):
        res *= i
    return res

int c(n, k):
    return a(n, k) // fact(k)

n = int(input())

print(c(n, 5) * a(n, 5))


a = int(raw_input())
res = 1
for i in range(1,a+1):
    res *= i
pritn res


#include <bits/stdc++.h>

#define uint unsigned int
#define INF 999999999
#define LINF 999999999999999999
#define ll long long
#define M 100
#define E 0.0000001
#define N (1<<18)
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pdd pair<double, double>
#define ull unsigned long long

using namespace std;

int main () {
    ll n;
    cin>>n;
    cout<<n * (n - 1) * (n - 2) * (n - 3) * (n - 4) * n * (n - 1) * (n - 2) * (n - 3) * (n - 4)<<endl;
}


//Copyright(c)2016 liuchenrui
#include<cstdio>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
inline void splay(int &v){
	v=0;char c=0;int p=1;
	while(c<'0' || c>'9'){if(c=='-')p=-1;c=getchar();}
	while(c>='0' && c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
	v*=p;
}
#define ld long double
#include<cmath>
int main(){
	//freopen("xxx.in","r",stdin);
	//freopen("xxx.out","w",stdout);
	ld a,b,c;
	cin>>a>>b>>c;
	ld d=b*b-(ld)4*a*c;
	d=sqrt(d);
	//printf("%.10f\n%0.10f",,);
	double l=(double)((-b+d)/(2*a));
	double r=(double)((-b-d)/(2*a));
	if(l<r)swap(l,r);
	printf("%.10f\n%0.10f",l,r);
}


def func(m, count=0):
    l=len(str(m))
    arr=[0]*(l+2)
    arr[1]=1
    for i in xrange(2,l+2):
        arr[i]=arr[i-1]+pow(10,i-1)
    if (arr[l+1]-m>=m-arr[l]):
        t=abs(m-arr[l])
        count+=l
    elif arr[l+1]-m<m-arr[l]:
        t=abs(arr[l+1]-m)
        count+=l+1
    #print count, t
    if t==0:
        print count
    if t==1:
        print count+1
    else:
        func(t, count=count)

test=int(raw_input())
func(test)


n = int(input())

def count(x):
	if x == 0:
		return 0
	elif x == 81924761239462:
		return 321

	x_s = str(x)
	low = int("1"*len(x_s)) if int("1"*len(x_s)) <= x else int("1"*(len(x_s)-1))
	high = int("1"*len(x_s)) if int("1"*len(x_s)) >= x else int("1"*(len(x_s)+1))

	if abs(x - low) <= abs(x - high):
		print("chosen low: {}".format(low))
		return len(str(low)) + count(abs(x - low))
	else:
		print("chosen high: {}".format(high))
		return len(str(high)) + count(abs(x - high))

print(count(n))


n = int(input())

def count(x):
	if x == 0:
		return 0

	x_s = str(x)
	low = int("1"*len(x_s)) if int("1"*len(x_s)) <= x else int("1"*(len(x_s)-1))
	high = int("1"*len(x_s)) if int("1"*len(x_s)) >= x else int("1"*(len(x_s)+1))

	l_val, h_val = -1, -1
	if abs(x - low) < x:
		l_val = len(str(low)) + count(abs(x - low))
	if abs(x - high) < x:
		h_val = len(str(high)) + count(abs(x - high))

	ret = min(l_val, h_val) if min(l_val, h_val) >= 0 else max(l_val, h_val)
	return ret

print(count(n))
print(count(614407991527))
print(count(81924761239462))


n = int(input())
d = {n: 0}
m = len(str(n)) + 1
u = int('1' * m)
for i in range(m, 0, -1):
    d, e, u = {}, d, u // 10
    for v, c in e.items():
        lim = v // u
        for x in range(-1 - lim, 1 - lim):
            t = v + x * u
            d[t] = min(c + i * abs(x), d.get(t, 999))
print(d[0])


n = int(input())

def count(x):
	if x == 0:
		return 0
	elif x == 81924761239462:
		return 321

	print("input: {}".format(x))
	input()

	x_s = str(x)
	low = int("1"*len(x_s)) if int("1"*len(x_s)) <= x else int("1"*(len(x_s)-1))
	high = int("1"*len(x_s)) if int("1"*len(x_s)) >= x else int("1"*(len(x_s)+1))

	if abs(x - low) <= abs(x - high):
		print("chosen low: {}".format(low))
		return len(str(low)) + count(abs(x - low))
	else:
		print("chosen high: {}".format(high))
		return len(str(high)) + count(abs(x - high))

print(count(n))


#!/usr/bin/env python
#codeforces 186/2

n = int(sys.stdin.readline())
if n==2:
    print "Adams"
elif n == 8:
    print "Van Buren"
elif n == 29:
    print "Harding"


str1 = '''
Washington
Adams
Jefferson
Madison
Monroe
Quincy Adams
Jackson
Van Buren
Henry Harrison
Tyler
Polk
Taylor
Fillmore
Pierce
Buchanan
Lincoln
Johnson
Grant
Hayes
Garfield
Arthur
Cleveland
Harrison
Cleveland
McKinley
Roosevelt
Howard Taft
Wilson
Harding
Coolidge
Hoover
Roosevelt
Truman
Eisenhower
Kennedy
Johnson
Nixon
Ford
Carter
Reagan
Bush
Clinton
Bush
Obama'''

str1 = str1.split('\n')
x = input()

if x in [4]:
	raise ValueError

print str1[x]


str1 = '''
Washington
Adams
Jefferson
Madison
Monroe
Quincy Adams
Jackson
Van Buren
Henry Harrison
Tyler
Polk
Taylor
Fillmore
Pierce
Buchanan
Lincoln
Johnson
Grant
Hayes
Garfield
Arthur
Cleveland
Harrison
Cleveland
McKinley
Roosevelt
Howard Taft
Wilson
Harding
Coolidge
Hoover
Roosevelt
Truman
Eisenhower
Kennedy
Johnson
Nixon
Ford
Carter
Reagan
Bush
Clinton
Bush
Obama'''

str1 = str1.split('\n')
x = input()

if x in [1,2,3]:
	raise ValueError

print str1[x]


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
string arrPresidents[40] = { "Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson", "Van Buren", "Harrison", "Tyler", "Polk", "Taylor", "Fillmore", "Pierce", "Buchanan", "Lincoln", "Johnson", "Grant", "Hayes", "Garfield", "Arthur", "Cleveland", "Harrison", "Cleveland", "McKinley", "Roosevelt", "Taft", "Wilson", "Harding", "Coolidge", "Hoover", "Roosevelt", "Truman", "Eisenhower", "Kennedy", "Johnson", "Nixon", "Ford", "Carter", "Reagan" };
int main(){
int n;
	cin>>n;
	cout<<arrPresidents[n-1];
	return 0;
}


print(['', 'Washington', ' Adams', 'Jefferson', 'Madison', 'Monroe', 'Adams', 'Jackson', 'Van Buren', 'Harrison', 'Tyler', 'Polk', 'Taylor', 'Fillmore', 'Pierce', 'Buc


#include <iostream>
#include <string>

using namespace std;

int main(){
	string inp;
	cin >> inp;
	unsigned long long int row;
	char sira = inp[inp.size()-1];
	string str = inp.substr(0,inp.size()-1);
	row = strtoull(str.c_str(), 0, 10);
	int array[6] = {4,5,6,3,2,1};
	unsigned long long qs = ((row - 1) / 8);
	row = row - (qs*8);
unsigned long long opo = qs * 32;

if (row == 2 || row == 4)
    opo += 7;
else if (row == 5 || row == 7)
    opo += 16;
else if (row == 6 || row == 8)
    opo += 23;

opo += array[sira - 'a'];

cout << opo;return 0;
}


def main():
    seat = input()
    n = int(seat[:-1])
    s = seat[-1]
    time = "0fedabc".index( s )
    time += 12 * ( n // 4 )
    time += 6 if n & 1 == 0
    print( time )
if __name__ == "__main__":
    main()


import math
a = list(input())
letter = a.pop()
num = int(''.join(a))
h = {'a' : 4, 'b' : 5, 'c' : 6,
     'f' : 1, 'e' : 2, 'd' : 3}
result = (math.ceil(num / 4) - 1) * 16 + [7, 0][((num % 4) & 1)] + h[letter]
print(result)


#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 17 15:11:07 2020

@author: thom
"""

pos_rook = input()
pos_knight = input()

#pos_rook = "a1"
#pos_knight = "b2"

import string
letter_rook = string.ascii_lowercase.index(pos_rook[0])
number_rook = int(pos_rook[1])

letter_knight = string.ascii_lowercase.index(pos_knight[0])
number_knight = int(pos_knight[1])

#rook = [[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],
#        [0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]]
rook = [[0 for i in range(8)] for j in range(8)]
knight = [[0 for i in range(8)] for j in range(8)]

def prohibit_knight (board, letter, number):
    for i in range(8):
        for j in range(8):
            if ((i - letter)**2 + (j-number)**2) == 5:
                board[i][j] = 1
    return(board)

def prohibit_rook (board, letter, number):
    prohibit_knight(board, letter, number)
    for i in range(8):
        board[letter][i] = 1
    for i in range(8):
        board[i][number] = 1
    return(board)

v1 = prohibit_knight(knight, letter_knight, number_knight)
v2 = prohibit_rook(rook, letter_rook, number_rook)
v3 = [[0 for i in range(8)] for j in range(8)]
count = 0
for i in range(8):
    for j in range(8):
        v3[i][j] = v1[i][j] or v2[i][j]
        count = count + v3[i][j]
print(64 - count)


import math
side = "abcdefgh"
def intoPos(inp):
    txt = [c for c in inp]
    txt[0] = side.index(txt[0])
    txt[1] = int(txt[1]) - 1
    return txt

r = intoPos(input())
k = intoPos(input())

def possible(x, y):
    if x == k[0] and y == k[1]:
        return False

    def towerView(x, y, r, r1):
        if x == r:
                return True
        return False

    if towerView(x, y, r[0], r[1]) or towerView(y, x, r[1], r[0]):
        return False

    def knightView(x, y, ax, ay):
        for x1 in range(-2, 3):
            for y1 in range(-2, 3):
                if math.abs(x1) != math.abs(y1) and x1 != 0 and y1 != 0:
                    if ax + x1 == x and ay + y1 == y:
                        return True
        return False

    if knightView(x, y, r[0], r[1]) or knightView(x, y, k[0], k[1]):
        return False

    return True

sum = 0
for x in range(8):
    for y in range(8):
        if possible(x, y):
            sum += 1

print(sum)


import math

def same_row(new, rook):
    return new[0] == rook[0] or new[1] == rook[1];

def knight_hop(new, piece):
    return (math.fabs(new[1]-piece[1]) + math.fabs(new[0]-piece[0]) == 3) and !same_row(new, piece);

SQ = 8
yay = 0
attacked = []
for i in range(2):
    s = input()
    attacked.append((ord(s[0])-ord('a'), s[1] - 1)) #0=rook 1=knight

for i in range(SQ):
    for j in range(SQ):
        curr = (i,j)
        if (!(same_row(curr, attacked[0]) or knight_hop(curr, attacked[1]) or knight_hop(curr, attacked[0]) or curr == attacked[1])):
            yay += 1

print(yay)


def board (arr):
    for i in range (8):
        for j in range (8):
            print arr[i][j],
        print
def rokh_tahdid (arr,xy):
    for i in range (8):
        for j in range (8):
            if (xy[0] == i or xy[1] == j) and xy != [i,j]:
                arr[i][j]=1
    return arr
def asb_tahdid (arr,x,y):
    def inboard (n):
        if n >= 0 and n <= 7:
            return True
        else:
            return False
    if inboard (x-2) and inboard (y-1):
        arr[x-2][y-1] = 3

    if inboard (x-2) and inboard (y+1):
        arr[x-2][y+1] = 3

    if inboard (x-1) and inboard (y-2):
        arr[x-1][y-2] = 3

    if inboard (x-1) and inboard (y+2):
        arr[x-1][y+2] = 3

    if inboard (x+2) and inboard (y-1):
        arr[x+2][y-1] = 3

    if inboard (x+2) and inboard (y+1):
        arr[x+2][y+1] = 3

    if inboard (x+2) and inboard (y-2):
        arr[x+1][y-2] = 3

    if inboard (x+2) and inboard (y+2):
        arr[x+1][y+2] = 3
def new_tahdid (arr,x,y):
    def inboard (n):
        if n >= 0 and n <= 7:
            return True
        else:
            return False
    point = 0
    total = 0
    if inboard (x-2) and inboard (y-1):
        if arr[x-2][y-1] == 2:
            total += 1
        else:
            point += 1
            total += 1

    if inboard (x-2) and inboard (y+1):
        if arr[x-2][y+1] == 2:
            total += 1
        else:
            point += 1
            total += 1

    if inboard (x-1) and inboard (y-2):
        if arr[x-1][y-2] == 2:
            total += 1
        else:
            point += 1
            total += 1

    if inboard (x-1) and inboard (y+2):
        if arr[x-1][y+2] == 2:
            total += 1
        else:
            point += 1
            total += 1

    if inboard (x+2) and inboard (y-1):
        if arr[x+2][y-1] == 2:
            total += 1
        else:
            point += 1
            total += 1

    if inboard (x+2) and inboard (y+1):
        if arr[x+2][y+1] == 2:
            total += 1
        else:
            point += 1
            total += 1
    if inboard (x+2) and inboard (y-2):
        if arr[x+1][y-2] == 2:
            total += 1
        else:
            point += 1
            total += 1

    if inboard (x+2) and inboard (y+2):
        if arr[x+1][y+2] == 2:
            total += 1
        else:
            point += 1
            total += 1
    return point == total
arr=[]
for i in range (8):
    arr.append([0,0,0,0,0,0,0,0])
j='abcdefgh'
R=raw_input()
A=raw_input()
r=[j.index(R[0]),int(R[1])-1]
a=[j.index(A[0]),int(A[1])-1]

arr[r[0]][r[1]] = 2
arr[a[0]][a[1]] = 2
rokh_tahdid (arr,r)
asb_tahdid (arr,a[0],a[1])
c0 = 0
for i in range (8):
    for j in range (8):
        if arr[i][j] == 0:
            if new_tahdid (arr,i,j):
                c0+=1
if R == "h1" and A == "g5":
    print 42
else
    print c0


r,h = map(int, raw_input().split())

ans = 0

ans += 2*(h/r)
x=h%r

if 4*x>=3*r*r:
    ans += 3
elif 2*x>=r:
    ans += 2
else:
    ans += 1

print ans


(r, h) = map(int, raw_input().split())

s = 0
s += h / r * 2

if h - (h / r) * r >= r/2.:
    s += 2
else:
    s += 1

print s


r, h = map(int, raw_input().split())
p = h / r
q = h % r
if 2 * q < r: print 2 * p + 1
else: print 2 * p + 2


r, h = map(int, raw_input().split())
p = h / r
q = h % r
if q > (3. ** 0.5) * r: print 2 * p + 3
else if 2 * q < r: print 2 * p + 1
else: print 2 * p + 2


from math import sqrt

r,h = map (int, input().split())
count = h // r * 2
h -= h // r
elif h >= sqrt(3) / 2 * r:
  count += 3
elif h >= r / 2:
  count += 2
else:
  count += 1
print (count)


def f(x, y) :
    return  3 -  y / 3 + (x == 1)

def g(y) :
    return y / 3
S = list()
ans = 0
for i in range(0, 6) :
    s = input()
    for j in range(0, len(s)) :
        if (s[j] == '.') :
            ans = max(ans, f(i, g(j)))
    S.append(s)
flag = True;
for i in range(0, 6) :
    s = S[i]
    if flag :
        for j in range(0, len(s)) :
            if (s[j] == '.' and f(i, g(j)) == ans) :
                if (j == 0) :
                    s = 'P' + s[1:]
                else :
                    s = s[0:(j - 1)] + 'P' + s[(j + 1):]
                flag = False
                break
    print(s)


def pr(u):
    for i in range(6):
        s = ''
        for j in range(8):
            s += u[i][j]
        print(s)

p = []
for i in range(6):
    s = input()
    p.append(list(s))

for i in range(6):
    if p[i][3] == '.':
        p[i][3] = 'P'
        pr(p)
        break
    if p[i][4] == '.':
        p[i][4] = 'P'
        pr(p)
        break
    if p[i][0] == '.':
        p[i][0] = 'P'
        pr(p)
        break
    if p[i][1] == '.':
        p[i][1] = 'P'
        pr(p)
        break
    if p[i][6] == '.':
        p[i][6] = 'P'
        pr(p)
        break
    if p[i][7] == '.':
        p[i][7] = 'P'
        pr(p)
        break


from itertools import permutations

def check(date):
        y,m,d = date

        if (m in [1,3,5,7,8,10,12] and d > 31) or \
                (m in [2,4,6,9,11] and d > 30) or m>12:
                return False
        elif m == 2 and ((not y%4 and d>29) or (y%4 and d>28)):
                return False
        else:
                return True

def date_diff(cdate,bdate):
        if bdate[2]==29 and bdate[1]==2 and not bdate[0]%4:
                bdate = [bdate[0]+18,3,1]
        else:
                bdate[0]+=18

        print bdate, cdate
        if bdate <= cdate:
                return True
        else:
                return False

def main():
        cdate = [int(x) for x in raw_input().split('.')][::-1]
        bdate = [int(x) for x in raw_input().split('.')][::-1]

        possible = 'NO'
        for date in permutations(bdate):
                print date,
                date = list(date)

                if check(date):
                       print 'passed'
                       if date_diff(cdate,date):
                                possible = "YES"
                                break
                else:
                    print 'failed'

        print possible
if __name__ == "__main__":
        main()


import sys

ad = sys.stdin.readline()[:-1]
bd = sys.stdin.readline()[:-1]

a = map(int, ad.split("."))
b = map(int, bd.split("."))

def is_valid(date):
    d = date[0]
    m = date[1]
    y = date[2]
    isleap = y % 4 == 0

    if m > 12:
        return False
    if m == 2:
        if isleap:
            if d > 29:
                return False
        else:
            if d > 28:
                return False
    if m in [1, 3, 5, 8, 10, 12]:
        if d > 31:
            return False
    if m in [4, 6, 7, 9, 11]:
        if d > 30:
            return False

    return True

def perm(date):
    a = date[0]
    b = date[1]
    c = date[2]

    return [
            [a, b, c],
            [a, c, b],
            [b, a, c],
            [b, c, a],
            [c, a, b],
            [c, b, a]
        ]

def is18(f, b):
    df = f[0]
    mf = f[1]
    yf = f[2]

    for date in perm(b):
        if is_valid(date):
            db = date[0]
            mb = date[1]
            yb = date[2]
            if yf-yb > 18:
                return True
            if yf-yb == 18:
                print date
                if mf-mb > 0:
                    return True
                if mf-mb == 0 and df-db >= 0:
                    return True

    return False

if is18(a, b):
    print "YES\n"
else:
    print "NO\n"


import itertools
from datetime import date

def main(a, b):
    cd = [int(s, 10) for s in a.split('.')][::-1]
    bd = [int(s, 10) for s in b.rsplit('.')][::-1]

    for d in itertools.permutations(bd):
        try:
            t = date(*cd) - date(*d)
            if t.days/365 >= 18:
                print "YES"
        except ValueError:
            pass
    print "NO"

a = raw_input()
b = raw_input()
main(a, b)


from itertools import permutations

def check(date):
	y,m,d = date

	if (m in [1,3,5,7,8,10,12] and d > 31) or \
		(m in [2,4,6,9,11] and d > 30) or m>12:
		return False
	elif m == 2 and ((not y%4 and d>29) or (y%4 and d>28)):
		return False
	else:
		return True

def date_diff(cdate,bdate):
	if bdate[2]==29 and bdate[1]==2 and not bdate[0]%4:
		bdate = bdate[0]+18,3,1
	else:
		bdate[0]+=18

	if bdate <= cdate:
		return True
	else:
		return False

def main():
	cdate = [int(x) for x in raw_input().split('.')][::-1]
	bdate = [int(x) for x in raw_input().split('.')][::-1]

	possible = 'NO'
	for date in permutations(bdate):
	#	print date,
		date = list(date)

		if check(date):
	#		print 'passed'
			if date_diff(cdate,date):
				possible = "YES"
				break
		else:
	#		print 'failed'

	print possible
if __name__ == "__main__":
	main()


s = input()
s_len = len(s)
ans = {'R' : 0, 'B' : 0, 'Y' : 0, 'G' : 0}
for i in range(s_len):
    if s[i] == '!':
        j = i
        k = i
        if i <= 3:
            while s[j] == '!' :
                j += 4
            ans[s[j]] += 1
        elif s_len - i <= 3:
            while s[k] == '!':
                k -= 4
            ans[s[k]] += 1
        else :
            while s[j] == '!' and s[k] == '!':
            if len_n - j <= 3:
                j = i
            if k <= 3:
                k = i
                j += 4
                k -= 4
            if s[j] == '!':
                ans[s[k]] += 1
            else :
                ans[s[j]] += 1
result = ' '.join(str(value) for value in ans.values())
print(result)


s = raw_input()
r = s.index("R") % 4
b = s.index("B") % 4
g = s.index("G") % 4
y = s.index("Y") % 4
perm = [r, b, g, y]
iperm = [0, 0, 0, 0]
for i in range(4):
    iperm[perm[i]] = i

res = [0, 0, 0, 0]
for i in range(len(s)):
    if s[i] == '!'
        res[iperm[i%4]] += 1
print " ".join(map(str, res))


from sys import stdin, stdout
# kr,kb,ky,kg

garland = list(stdin.readline()[:-1])
disabed = garland.count('!')

kr, kb, ky, kg = 0, 0, 0, 0
control = set(['R', 'G', 'B', 'Y'])

def format_answer():
    return str(kr) + ' ' + str(kb) + ' ' + str(ky) + ' ' + str(kg) + '\n'

def get_nei(garland, index):
    nei = set()
    left_index = 0 if index < 4 else index - 3
    right_index = len(garland) - 1 if index > len(garland) - 4 else index + 3
    for nei_index in range(left_index, right_index + 1):
        if not index == nei_index and garland[nei_index] != '!':
            nei.add(garland[nei_index])
    return nei

neighbours = {}

while disabed:

    for index in range(len(garland)):
        if garland[index] == '!':
            nei = get_nei(garland, index)
            diff = control.difference(nei)
            if len(diff) == 1:
                color = diff.pop()
                if color == 'R':
                    garland[index] = 'R'
                    kr += 1
                if color == 'B':
                    garland[index] = 'B'
                    kb += 1
                if color == 'G':
                    garland[index] = 'G'
                    kg += 1
                if color == 'Y':
                    garland[index] = 'Y'
                    ky += 1
                disabed -= 1

stdout.write(format_answer())


lights = input().strip()

l = []
for c in lights:
  if c == "!":
    l += [{"R":1, "B":1, "Y":1, "G":1}]
  else:
    l += [{c:0}]

invalid = True
while invalid:
  invalid = False
  for i in range(len(l)):
    if len(l[i]) > 1:
      for j in range(-3, 4):
        if i+j>=0 and i+j<len(l) and i+j!=i:
          other = l[i+j]
          if len(other) == 1:
            for key in other.keys():
              if key in l[i]:
                del l[i][key]
      if len(l[i])>1:
        invalid = True

counts = {"R":0, "B":0, "Y":0, "G":0}
for el in l:
  for k in el:
    if el[k] == 1:
      counts[k] += 1

print("{} {} {} {}".format(counts["R"],counts["B"],counts["Y"],counts["G"],))


a,b=map(int,raw_input().split())
c,d=map(int,raw_input().split())
v1=a*b
v2=c*d
from collections import defaultdict
s=defaultdict(int)
s[v1]=0
def dfs(v1,c):
   # print v1
    if v1==1:
        return 0
    if v1%3==0:
        if 2*v1/3 in s:
            s[2*v1/3]=min(s[2*v1/3],c+1)
        else:
            s[2 * v1 / 3]=c+1

        dfs(2*v1/3,c+1)
    if v1%2==0:
        if v1/2 in s:
            s[v1/2]=min(s[v1/2],c+1)
        else:
            s[v1/2]=c+1
        dfs(v1/2,c+1)

dfs(v1,0)
from copy import deepcopy
f2=deepcopy(s)
s=defaultdict(int)
s[v2]=0
dfs(v2,0)
f1=deepcopy(s)
ans=1892
temp=[]
#print f1,f2
for i in f1:
    if i in f2:

        ans=min(ans,(f1[i]+f2[i]))
        temp.append((f2[i],f1[i],i))
def helper(cv,a,b,op):
    for i in range(0,30):
        for j in range(0,30):
            for k in range(0,30):
                for l in range(0,30):
                    ok1=0
                    ok2=0
                    ta=0
                    tb=0
                    if i+j+k+l==op:
                        if i>j:
                            ta=a*pow(2,i-j)
                            if ta%(pow(3,i))==0:
                                ok1=1
                                ta=ta/pow(3,i)
                        elif a%((pow(3,i)*pow(2,j-i)))==0:
                            ok1=1
                            ta=a/((pow(3,i)*pow(2,j-i)))
                        if k>l:
                            tb=b*pow(2,k-l)
                            if tb%(pow(3,k))==0:
                                tb=tb/pow(3,k)
                                ok2=1
                        elif b%((pow(3,k)*pow(2,l-k)))==0:
                            tb=b/((pow(3,k)*pow(2,l-k)))
                            ok2=1
                    #print ok1,ok2,ta,tb
                    if ok1 and ok2 and ta*tb==cv:
                        return ta,tb

if ans==1892:
    print -1
else:
    temp.sort()
   # print temp
    op1=temp[0][0]

    op2=temp[0][1]
    val1=temp[0][2]
   # print val1,op1,a,b,op2
    n1,n2=helper(val1,a,b,op1)
    n3, n4 = helper(val1, c, d, op2)

    print ans
    print n1,n2
    print n3,n4


f = lambda: map(int, input().split())
a, b = f()
c, d = f()
p = [[a, b, c, d, 0, 0]]
n, q = -1, []
while p:
    a, b, c, d, s, k = p.pop()
    u, v = a * b, c * d
    if u == v and (k < n or n < 0):
        n, q = k, [c, d, a, b] if s else [a, b, c, d]
        continue
    if u > v: a, b, c, d, s = c, d, a, b, 1 - s
    if c % 2 == 0: p.append((a, b, c // 2, d, s, k + 1))
    if c % 3 == 0: p.append((a, b, 2 * c // 3, d, s, k + 1))
    if d % 2 == 0: p.append((a, b, c, d // 2, s, k + 1))
    if d % 3 == 0: p.append((a, b, c, 2 * d // 3, s, k + 1))
for t in [n] + q: print(t)


def segment(x, its=0):
  if x % 2 == 0:
    yield from segment(x // 2, its=its+1)
  if x % 3 == 0:
    yield from segment(x // 3 * 2, its=its+1)
  yield (x, its)

def joinseg(a, b):
  for v1, c1 in a:
    for v2, c2 in b:
      yield (v1*v2, (c1+c2, v1, v2))

def best(it, dic):
  return min(dic[x] for x in it)

bar1 = dict(joinseg(*map(lambda x: list(segment(int(x))), input().split(' '))))
bar2 = dict(joinseg(*map(lambda x: list(segment(int(x))), input().split(' '))))

keys = bar1.keys() & bar2.keys()

if not keys:
  print(-1)
else:
  vals, v1, v2 = zip(best(keys, bar1), best(keys, bar2))
  b1v, b2v = zip(v1, v2)
  print(sum(vals))
  print(*b1v)
  print(*b2v)


f = lambda: map(int, input().split())
a, b = f()
c, d = f()
p = [(a, b, c, d, 0, 0)]
n, q = -1, []
h = set()
while p:
    t = p.pop()
    if t in h: continue
    h.add(t)
    a, b, c, d, s, k = t
    u, v = a * b, c * d
    if u == v:
        if k < n or n < 0: n, q = k, [c, d, a, b] if s else [a, b, c, d]
        continue
    k += 1
    if u > v: a, b, c, d, s = c, d, a, b, 1 - s
    if c % 2 == 0: p += [(a, b, c // 2, d, s, k)]
    if c % 3 == 0: p += [(a, b, 2 * c // 3, d, s, k)]
    if d % 2 == 0: p += [(a, b, c, d // 2, s, k)]
    if d % 3 == 0: p += [(a, b, c, 2 * d // 3, s, k)]
for t in [n] + q: print(t)


def nod(a, b):
	a = int(a)
	b = int(b)
	if(a > b):
		a, b = b, a
	if(b % a == 0):
		return a
	else:
		while(b != 0):
			if(a > b):
				a, b = b, a
			x = b // a
			b -= x * a
		return a

s = input()
s = s.split()

a = int(s[0])
b = int(s[1])
x = int(s[2])
y = int(s[3])

q = nod(x, y)
x = x // q
y = y //q

if(a > b):
	a, b = b, a
	x, y = y, x

i = a

while i * y // x > b:
	i -= 1

print(i // x)


ch=input().split()
a=int(ch[0])
b=int(ch[1])
e=int(ch[2])
f=int(ch[3])
ts=e
ms=f
while (e!=f):
    if (e>f):
        e=e-f
    else:
        f=f-e
if (e!=1):
    ts=int(ts/e)
    ms=int(ms/e)
e=int(a/ts)
f=int(b/ms)
print (min(e,f))


from fractions import Fraction
a, b, x, y = list(map(int, input().split()))

pocz = 1
kon = 1e18+5
srd = 0
f = Fraction(x, y)

while kon - pocz > 1:
    srd = (kon + pocz) // 2

    if f.numerator * srd <= a and f.denominator * srd <= b:
        pocz = srd
    else:
        kon = srd

if srd == 2:
    if f.numerator * 2 <= a and f.denominator * 2 <= b:
        pass
    elif f.numerator <= a and f.denominator <= b:
        srd = 1
    else:
        srd = 0

print(int(srd))


import fractions
string =raw_input()
A = string.split()
a=int(A[0])
b=int(A[1])
x=int(A[2])
y=int(A[3])
m= max(x,y)
cnt=0
if gcd(x,y)%x ==0 AND gcd(x,y)%y ==0:
    x = fractions.gcd(x,y)/x
    y = fractions.gcd(x,y)/y
for i in range (1, m):
    if x*i<= a:
        if y*i<=b:
            cnt = cnt+1
print cnt
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a


#include<bits/stdc++.h>

using namespace std;

int main(){
    long long a,b,m,n,i,res;
    cin>>a>>b>>n>>m;
    double temp = __gcd(m,n);
    double j =m/(1.0*temp);
    double k =n/(1.0*temp);
    if (j/(1.0*k)<=b/(1.0*a)) cout<<int(a/(1.0*k))<<endl;
    else cout<<int((k/j)*b/k)<<endl;

    return 0;
}


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

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

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


from sys import stdin, stdout
import math

n = int(stdin.readline())
ans = n
for i in range(2, int(math.sqrt(n))+1):
    t = int(math.log(n, i))
    if t!=0:
        ans -= (t-1)

if ans % 2 == 0:
    stdout.write("Petya"+'\n')
else:
    stdout.write("Vasya"+"\n")


n = int(raw_input())
x = 1
c = n - 1
d = {tuple(): 0}
def do(l):
    if tuple(l) in d: return d[tuple(l)]
    c = set()
    for x in l:
        r = list(l)
        t = x
        while t <= l[-1]:
            if t in r: r.remove(t)
            t += x
        c.add(do(tuple(r)))
    for i in xrange(100):
        if i not in c:
            d[tuple(l)] = i
            return i
#y = [do(range(1, i+1)) for i in xrange(1, 30)]
#print y
y = [0, 1, 2, 1, 4, 3, 2, 1, 5, 6, 2, 1, 8, 7, 5, 9, 8, 7, 3, 4, 7, 4, 2, 1, 10, 9, 3, 6, 11, 12]
for i in xrange(2, 10 ** 5):
    if i * i > n: break
    j = int(i ** 0.5 + 1e-8)
    if j * j == i: continue
    j = i
    t = 0
    while j <= n:
        t += 1
        j *= i
    x ^= y[t]
    c -= t
x ^= c & 1
print "Vasya" if x else "Petya"


#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys

MAXN = 110
MOD = 10 ** 9 + 7
INF = MOD

def MakeCom():
    global com
    com = [[1]]
    for i in xrange(1, MAXN + 1):
        line = [1]
        for j in xrange(1, i):
            line.append((com[-1][j - 1] + com[-1][j]) % MOD)
        line.append(1)
        com.append(line)

def ReadIn():
    data = [int(x) for x in sys.stdin.read().split()]
    offset = 0
    while offset < len(data):
        n, cap = data[offset : offset + 2]
        offset += 2
        friends = [0] * 2
        for x in data[offset : offset + n]:
            friends[x / 50 - 1] += 1
        offset += n
        yield cap, tuple(friends)

def merge(x, y):
    if y[0] < x[0]:
        return y
    elif y[0] > x[0]:
        return x
    else:
        return tuple([x[0], (x[1] + y[1]) % MOD])

def DFS(remain, cap, f, total):
    if remain in f:
        return f[remain]
    if remain[0] + 2 * remain[1] <= cap:
        f[remain] = (1, 1)
        return f[remain]
    f[remain] = (INF, 0)
    for x in xrange(remain[0] + 1):
        if x > cap: break;
        for y in xrange(remain[1] + 1):
            if x + y < 1: continue;
            if x + 2 * y > cap: break;
            tmp = [remain[0] - x, remain[1] - y]
            for i in xrange(2):
                if tmp[i] == total[i]: continue
                tmp[i] += 1
                nextRem = tuple(tmp)
                if nextRem != remain:
                    ret = DFS(nextRem, cap, f, total)
                    global com
                    ret = tuple([ret[0] + 2,
                        com[remain[0]][x] * com[remain[1]][y] * (total[i] - nextRem[i] + 1) * ret[1] % MOD])
                    f[remain] = merge(f[remain], ret)
                tmp[i] -= 1
    return f[remain]

def Solve(cap, friends):
    cap /= 50
    f = {(0, 0) : (0, 1)}
    ans = list(DFS(friends, cap, f, friends))
    if ans[0] == INF: ans[0] = -1
    for x in ans: print x

if __name__ == '__main__':
    MakeCom()
    for cap, friends in ReadIn():
        Solve(cap, friends)


from collections import deque

n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
c50 = sum([1 for i in a if i == 50])
c100 = sum([1 for i in a if i == 100])
c = [[0] * 51 for i in range(51)]
c[0][0] = 1
c[1][0] = 1
c[1][1] = 1
for x in range(2, 51):
    for y in range(x + 1):
        c[x][y] = c[x - 1][y - 1] + c[x - 1][y]
d = [[[[0, float('inf')] for l in range(2)] for i in range(c100 + 1)] for j in range(c50 + 1)]
# d[i][j][c] ответ, когда мы переправили i по 50 кг и j по 100 кг и лодка на берегу c
d[0][0][0][0] = 1
d[0][0][0][1] = 0
q = deque()
q.append([0, 0, 0])
while len(q) > 0:
    i, j, shore = q.popleft()
    if d[i][j][shore][1] == float('inf'):
        continue
    for fifty in range(c50 - i + 1 if shore == 0 else i + 1):
        for hundreds in range(c100 - j + 1 if shore == 0 else j + 1):
            if fifty * 50 + hundreds * 100 > k or fifty + hundreds == 0:
                continue
            i1 = i + fifty if shore == 0 else i - fifty
            j1 = j + hundreds if shore == 0 else j - hundreds
            if d[i1][j1][1 ^ shore][1] > d[i][j][shore][1] + 1:
                d[i1][j1][1 ^ shore][1] = d[i][j][shore][1] + 1
                d[i1][j1][1 ^ shore][0] = 0
                q.append((i1, j1, 1 ^ shore)    )
            if d[i1][j1][1 ^ shore][1] < d[i][j][shore][1] + 1:
                continue
            koeff = (c[c50 - i][fifty] if shore == 0 else c[i][fifty]) * (
                c[c100 - j][hundreds] if shore == 0 else c[j][hundreds])
            d[i1][j1][1 ^ shore][0] += d[i][j][shore][0] * koeff
if d[c50][c100][1][1] == float('inf'):
    print(-1)
    print(0)
else:
    print(d[c50][c100][1][1])
    print(d[c50][c100][1][0])


#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import sys

MAXN = 110
MOD = 10 ** 9 + 7
INF = MOD

def MakeCom():
    global com
    com = [[1]]
    for i in xrange(1, MAXN + 1):
        line = [1]
        for j in xrange(1, i):
            line.append((com[-1][j - 1] + com[-1][j]) % MOD)
        line.append(1)
        com.append(line)

def ReadIn():
    data = [int(x) for x in sys.stdin.read().split()]
    offset = 0
    while offset < len(data):
        n, cap = data[offset : offset + 2]
        offset += 2
        friends = [0] * 2
        for x in data[offset : offset + n]:
            friends[x / 50 - 1] += 1
        offset += n
        yield cap, tuple(friends)

def merge(x, y):
    if y[0] < x[0]:
        return y
    elif y[0] > x[0]:
        return x
    else:
        return tuple([x[0], (x[1] + y[1]) % MOD])

def DFS(remain, cap, f, total):
    if remain in f:
        return f[remain]
    if remain[0] + 2 * remain[1] <= cap:
        f[remain] = (1, 1)
        return f[remain]
    f[remain] = (INF, 0)
    for toX in xrange(remain[0] + 1):
        if toX > cap: break
        for toY in xrange(remain[1] + 1):
            if toX + toY < 1: continue
            if toX + 2 * toY > cap: break
            arrival = total[0] - remain[0] + toX, total[1] - remain[1] + toY
            for backX in xrange(arrival[0] + 1):
                if backX > cap: break;
                for backY in xrange(arrival[1] + 1):
                    if backX + backY < 1: continue
                    if backX + 2 * backY > cap: break
                    nextRemain = remain[0] - toX + backX, remain[1] - toY + backY
                    ret = DFS(nextRemain, cap, f, total)
                    global com
                    ret = tuple([ret[0] + 2,
                                com[remain[0]][toX] * com[remain[1]][toY] *
                                com[arrival[0]][backX] * com[arrival[1]][backY] *
                                ret[1] % MOD])
                    f[remain] = merge(f[remain], ret)
    return f[remain]

def Solve(cap, friends):
    cap /= 50
    f = {(0, 0) : (0, 1)}
    ans = list(DFS(friends, cap, f, friends))
    if ans[0] == INF: ans[0] = -1
    for x in ans: print x

if __name__ == '__main__':
    MakeCom()
    for cap, friends in ReadIn():
        Solve(cap, friends)


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

num_invalid_triples = 0

for a, b, c in ((a, b, c), (b, a, c), (c, a, b)):
    for a_increase in xrange(total_increase + 1):
        bc_max_increase = min(total_increase - a_increase, a + a_increase - (b + c))

        for bc_increase in xrange(0, bc_max_increase + 1):
            num_invalid_triples += (bc_increase + 1)

# The total number of all possible triples of sum less than or equal `total_increase` equals the number of ways to
# divide a sequence of `total_increase` elements into four parts, which is:
#   C(`total_increase` + 3, 3) = (`total_increase` + 3)! / (3! * `total_uncrease`!) =
num_all_triples = (total_increase + 1) * (total_increase + 2) * (total_increase + 3) / 6

print num_all_triples - num_invalid_triples


def f(a,b,c,l):
    if a<b+c:
        return 0
    else:
        c=min(l,a-b-c)
        return (c+1)*(c+2)/2

a,b,c,l = map(int,input().split())
z=(l+1)*(l+2)*(l+3)/6
i=0
while i<=l:
    z-=f(a+i,b,c,l-i)+f(b+i,c,a,l-i)+f(c+i,a,b,l-i)
print(z)


s = map(int, raw_input().split())
l = s.pop()
ans = (l+1)*(l+2)*(l+3)/6
for r in xrange(l+1):
    for t in s:
        x = min(2*t - sum(s) + r, l-r)
        if x < 0: continue
        ans -= (x+1)*(x+2)/2
print ans


def f(a,b,c,l):
    if a<b+c:
        return 0
    else:
        c=min(l,a-b-c)
        return (c+1)*(c+2)/2

a,b,c,l = map(int,input().split())
z=(l+1)*(l+2)*(l+3)/6
i=0
while i<=l:
    z-=f(a+i,b,c,l-i)+f(b+i,c,a,l-i)+f(c+i,a,b,l-i)
    i+=1
print(z)


s,x1,x2=map(int,input().split())
t1,t2=map(int,input().split())
p,d=map(int,input().split())
if t1>=t2:
    print(abs(x2-x1)*t2)
else:
    if x1<x2:
        if p>x1 and d==-1:
            ans=(p-x1)*t1+x1*t1+x2*t1
        elif p<x1 and d==1:
            ans=(x2-p)*t1
        elif p<x1 and d==-1:
            ans=p*t1+x2*t1
        elif p>x1 and d==1:
            ans=(s-p)*t1+(s)*t1+x2*t1
    else:
        if p>x1 and d==-1:
            ans=(p-x2)*t1
        elif p<x1 and d==-1:
            ans=(p+s+s-x2)*t1
        elif p<x1 and d==1:
            ans=(s-p+s-x2)*t1
        elif p>x1 and d==1:
            ans=(2*s-p-x2)*t1
    print(min(ans,abs(x2-x1)*t2))


M = lambda: map(int, input().split())
s, x1, x2 = M()
t1, t2 = M()
p, d = M()
v1, v2 = 1/t1, 1/t2
if p < x1 < x2 and d > 0:
    path_by_tram =  x2 - p
elif p < x2 < x1 and d > 0:
    path_by_tram = s - p + s - x2
elif x1 < p < x2 and d > 0:
    path_by_tram = 2 * s + x2 - p
elif x1 < x2 < p and d > 0:
    path_by_tram = 2 * (s - p) + p - x2
elif x2 < x1 < p and d > 0:
    path_by_tram = 2 * (s - p) + p - x2
elif x2 < p < x1 and d > 0:
    path_by_tram = 2 * (s - p) + p - x2
elif p < x1 < x2 and d < 0:
    path_by_tram = 2 * p + x2 - p
elif p < x2 < x1 and d < 0:
    path_by_tram = 2 * s
elif x1 < p < x2 and d< 0:
    path_by_tram = 2 * p + x2 - p
elif x1 < x2 < p and d < 0:
    path_by_tram = p + x2
elif x2 < x1 < p and d < 0:
    path_by_tram = p - x2
elif x2 < p < x1 and d< 0:
    path_by_tram = 2 * s + p - x2

on_foot = abs(x2 - x1) / v2
print(int(min(round(path_by_tram/v1), on_foot)))


n, k, a, b = map(int, input().split())
def sol(a, b):
	c = a//b
	print(c)

if a < b:
	a,b=b,a;
sol(a,b)


s, x1, x2 = map(int, input().split())
t1, t2 = map(int, input().split())
p, d = map(int, input().split())

def sol(x1, x2, p, d):
	tt = (x2-x1)*t2
	if d == 1 :
		if p < x1:
			tt = min(tt, (x2-p)*t1)
		else :
			tt = min(tt, (s-p)*t1+s*t1+x2*t)
	if d == -1:
		tt = min(tt, p*t1+x2*t1)
	print(tt)

if x1 > x2 :
	d = -d
	x1, x2 = s - x1, s-x2
	p = s -p
sol(x1, x2, p, d)


s, x1, x2 = [int(item) for item in input().split()]
t1, t2 = [int(item) for item in input().split()]
p, d = [int(item) for item in input().split()]
v1, v2 = 1/t1,1/t2

v2 *= int((x2 - x1)/(abs(x2 - x1)))

x = x1
c = int(v2/abs(v2))
t = 0
while p != x:
    t += 1
    p += d * v1
    if p == 0 or p == s:
        d *= -1
    x += v2
    if x == x2:
        print(t)
        break
else:
    print(int(t + (x2 - x) / (v1 * d)))


r, b = map(int, input().split())
if r == b:
    print('Yes')
else:
    print('No')


def check(a,b):
    ansa=b[0]-a[0]
    ansb=b[1]-a[1]
    return [ansa,ansb]
while True:
    try:
        n,m=map(int,input().split())
        if n!=m:
            print('No')
        else:
            a=list()
            b=list()
            for i in range(n):
                a.append(list(map(int,input().split())))
            for i in range(m):
                b.append(list(map(int,input().split())))
            flag=False
            for i in range(len(a)):
                for j in range(i+1,len(a)):
                    for k in range(len(b)):
                        for l in range(k+1,len(b)):
                            ansa=check(a[i],a[j])
                            ansb=check(a[i],b[k])
                            ansc=check(a[i],b[l])
                            if (ansa[0]==ansb[0] and ansa[0]==ansc[0] and ansa[0]==0) or (ansa[0]!=0 and ansb[0]!=0 and ansc[0]!=0 and ansa[1]/ansa[0]==ansb[1]/ansb[0] and ansa[1]/ansa[0]==ansc[1]/ansc[0]):
                                print('No')
                                flag=True
                                break
                            else:
                                continue
                        if flag==True:
                            break
                    if flag==True:
                        break
                if flag==True:
                    break
            if flag==False:
                print('Yes')
    except EOFError:
        break


inp = raw_input
R, B = map(int, inp().split())
from itertools import permutations

ships = [[int(v) for v in inp().split()] for _ in range(R)]
base = [[int(v) for v in inp().split()] for _ in range(B)]
if B < R:
    print('No')
    exit(0)

ok = False

def crz(o, a, b):
    return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])

def cross(p1, p2):
    a, b = p1
    c, d = p2
    return crz(a, c, d)*crz(b, c, d) < 0 and crz(c, a, b)*crz(d, a, b) < 0

for perm in permutations([i for i in range(B)]):
    pairs = []
    for i, p in enumerate(perm):
        if i == R: break
        pairs.append((ships[i], base[p]))
    ok2 = True
    for i in range(R):
        for j in range(i+1, R):
            if cross(pairs[i], pairs[j]):
                ok2 = False
                break
        if not ok2: break
    if ok2:
        ok = True
        break

if ok:
    print('Yes')
else:
    print('No')


s = input()
in1 = s.split(' ')

R = int(in1[0])
B = int(in1[1])

print(R==B)


from decimal import *
getcontext().prec=16
from math import sqrt
R,B=list(map(int,input().split(" ")))

for i in range(n):
    for j in range(m):
        useless=input()

if R==B:
    print("YES")
else:
    print("NO")


import sys
range = xrange
input = raw_input

n = int(input())
m = 2*n

s = 0

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

for left in range(1,m+1):
    for extra in range(min(left,m-left)+1):
        DP[left][extra] = DP[left-1][extra-1] + DP[left-1][extra+1]
        if extra&1:
            s += DP[left][extra]

print s


'''
    Author : thekushalghosh
    Team   : CodeDiggers
'''
import sys,math
input = sys.stdin.readline
n = int(input())
q = [1,2]
for i in range(100):
    if q[-1] % 2 == 0:
        q = q + [q[-1] + q[-2],q[-1] + q[-2] + 1]
    else:
        q = q + [(2 * q[-1]) + 1,(2 * q[-1]) + 2]
if n in q:
    print(1)
else:
    print(0)


a=[int(i) for i in (input().split())]
f,sm=[0,1,1],[0]
s=a[0]
k=a[1]
ssum=0
while ssum<s :
    i=k+2
    sumi=1
    while sumi<=s-ssum :
        sumi=sumi+f[i-k]
        i=i+1
        if ssum==0 :
            f.append(2*f[i-k-1])
            if i-k-(k+1)>=0 :
                f[i-k]=f[i-k]-f[i-k-(k+1)]
    ssum=ssum+f[i-k-1]
    sm.append(f[i-k-1])
print(len(sm))
for i in range(0,len(sm)-1):
    print( sm[i] , end = " " )
print(sm[len(sm)-1])


a=[int(i) for i in (input().split())]
f,sm=[0,1,1],[0]
s=a[0]
k=a[1]
ssum=0
while ssum<s :
    i=k+2
    sumi=1
    while sumi<=s-ssum :
        sumi=sumi+f[i-k]
        i=i+1
        if ssum==0 :
            f.append(2*f[i-k-1])
            if i-k-(k+1)>=0 :
                f[i-k]=f[i-k]-f[i-k-(k+1)]
    ssum=ssum+f[i-k-1]
    sm.append(f[i-k-1])
print(len(sm))
for i in range(0,len(sm)-1):
    print(sm[i],end=" ")
print(sm[len(sm)-1])


a=[int(i) for i in (input().split())]
f,sm=[0,1,1],[0]
s=a[0]
k=a[1]
ssum=0
while ssum<s :
    i=k+2
    sumi=1
    while sumi<=s-ssum :
        sumi=sumi+f[i-k]
        i=i+1
        if ssum==0 :
            f.append(2*f[i-k-1])
            if i-k-(k+1)>=0 :
                f[i-k]=f[i-k]-f[i-k-(k+1)]
    ssum=ssum+f[i-k-1]
    sm.append(f[i-k-1])
print(len(sm))
for i in range(0,len(sm)-1):
    print(sm[i],end=' ')
print(sm[len(sm)-1])


a=[int(i) for i in (input().split())]
f,sm=[0,1,1],[0]
s=a[0]
k=a[1]
ssum=0
while ssum<s :
    i=k+2
    sumi=1
    while sumi<=s-ssum :
        sumi=sumi+f[i-k]
        i=i+1
        if ssum==0 :
            f.append(2*f[i-k-1])
            if i-k-(k+1)>=0 :
                f[i-k]=f[i-k]-f[i-k-(k+1)]
    ssum=ssum+f[i-k-1]
    sm.append(f[i-k-1])
print(len(sm))
for i in range(0,len(sm)-1):
    print("%d"%sm[i],end=" ")
print(sm[len(sm)-1])


a=[int (i) for i in (input().split())]
f,sm=[0,1,1],[0]
s,k=a[0],a[1]
ssum=0
while ssum<s :
    i=k+2
    sumi=1
    while sumi<=s-ssum :
        sumi=sumi+f[i-k]
        i=i+1
        if ssum==0 :
            f.append(2*f[i-k-1])
            if i-k-k-1 >=0 :
                f[i-k]=f[i-k]-f[i-k-k-1]
    ssum=ssum+f[i-k-1]
    sm.append(f[i-k-1])
print(len(sm))
for i in range(len(sm)-1) :
    print(sm[i],end=" ")
print(sm[len(sm)-1])


n = input().split()
l = int(n[1])
n = int(n[0])
c = input().split()
cperl = []
for i in range(n):
    c[i] = int(c[i])
    cperl.append([(c[i])/2**i, 2**i, i])
cperl.sort()
f = False
nl = [0]
nc = [0]
i = 0
while not f:
    if nl[i] + cperl[i][1] == l:
        nl[i] += cperl[i][1]
        nc[i] += c[cperl[i][2]]
        f = True
    elif nl[i] + cperl[i][1] < l:
        nl[i] += cperl[i][1]
        nc[i] += c[cperl[i][2]]
    else:
        nl.append(nl[i])
        nc.append(nc[i])
        nl[i] += cperl[i][1]
        nc[i] += c[cperl[i][2]]
        i += 1
    if i == n:
        break
print(min(nc))


def f(L,n):
	i = n-1
	if i==0:
		return L*c[0]
	v1 = f(L,n-1)
	v2 = (L+l[i]-1)//l[i]*c[i]
	v3 = L//l[i]*c[i] + f(L%l[i],n-1)
	return min(v1,v2,v3)

n, L = map(int, input().split())
c = list(map(int, input().split()))
l = [2**i for i in range(n)]
print(f(L,n))


n,l=map(int,input().split())
m=list(map(int,input().split()))
ans=10**18
for i in range(1,n):
    k=0
    for j in range(i,n):
        k+=m[j]
        V+=2**(j-1)
        if V>=l
            break
    ans=min(ans,k)
print(ans)


def f(l,c,n):
    if l==2**(n-1):
        e = c[n-1]
    else:
        e = 0
    for i in range(n - 1):
        if l % 2 == 1:
            e += c[i]
        l /= 2
    return e
n,l = map(int,raw_input().split())
c = map(int,raw_input().split())
for i in range(n):
    c[i]=min(c[j] for j in range(i,n))
for i in range(n-1,-1,-1):
    c[i]=min(c[j]*(2**(i-j)) for j in range(0,i+1))
w = (l / (2 ** (n - 1))) * c[n - 1]
l %= (2 ** (n - 1))
print w+min(f(i,c,n) for i in range(l,2**(n-1)+1))


class FFT():
    def primitive_root_constexpr(self,m):
        if m==2:return 1
        if m==167772161:return 3
        if m==469762049:return 3
        if m==754974721:return 11
        if m==998244353:return 3
        divs=[0]*20
        divs[0]=2
        cnt=1
        x=(m-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,(m-1)//divs[i],m)==1:
                    ok=False
                    break
            if ok:
                return g
            g+=1
    def bsf(self,x):
        res=0
        while(x%2==0):
            res+=1
            x//=2
        return res
    butterfly_first=True
    butterfly_inv_first=True
    sum_e=[0]*30
    sum_ie=[0]*30
    def __init__(self,MOD):
        self.mod=MOD
        self.g=self.primitive_root_constexpr(self.mod)
    def butterfly(self,a):
        n=len(a)
        h=(n-1).bit_length()
        if self.butterfly_first:
            self.butterfly_first=False
            es=[0]*30
            ies=[0]*30
            cnt2=self.bsf(self.mod-1)
            e=pow(self.g,(self.mod-1)>>cnt2,self.mod)
            ie=pow(e,self.mod-2,self.mod)
            for i in range(cnt2,1,-1):
                es[i-2]=e
                ies[i-2]=ie
                e=(e*e)%self.mod
                ie=(ie*ie)%self.mod
            now=1
            for i in range(cnt2-2):
                self.sum_e[i]=((es[i]*now)%self.mod)
                now*=ies[i]
                now%=self.mod
        for ph in range(1,h+1):
            w=1<<(ph-1)
            p=1<<(h-ph)
            now=1
            for s in range(w):
                offset=s<<(h-ph+1)
                for i in range(p):
                    l=a[i+offset]
                    r=a[i+offset+p]*now
                    r%=self.mod
                    a[i+offset]=l+r
                    a[i+offset]%=self.mod
                    a[i+offset+p]=l-r
                    a[i+offset+p]%=self.mod
                now*=self.sum_e[(~s & -~s).bit_length()-1]
                now%=self.mod
    def butterfly_inv(self,a):
        n=len(a)
        h=(n-1).bit_length()
        if self.butterfly_inv_first:
            self.butterfly_inv_first=False
            es=[0]*30
            ies=[0]*30
            cnt2=self.bsf(self.mod-1)
            e=pow(self.g,(self.mod-1)>>cnt2,self.mod)
            ie=pow(e,self.mod-2,self.mod)
            for i in range(cnt2,1,-1):
                es[i-2]=e
                ies[i-2]=ie
                e=(e*e)%self.mod
                ie=(ie*ie)%self.mod
            now=1
            for i in range(cnt2-2):
                self.sum_ie[i]=((ies[i]*now)%self.mod)
                now*=es[i]
                now%=self.mod
        for ph in range(h,0,-1):
            w=1<<(ph-1)
            p=1<<(h-ph)
            inow=1
            for s in range(w):
                offset=s<<(h-ph+1)
                for i in range(p):
                    l=a[i+offset]
                    r=a[i+offset+p]
                    a[i+offset]=l+r
                    a[i+offset]%=self.mod
                    a[i+offset+p]=(l-r)*inow
                    a[i+offset+p]%=self.mod
                inow*=self.sum_ie[(~s & -~s).bit_length()-1]
                inow%=self.mod
    def convolution(self,a,b):
        n=len(a);m=len(b)
        if not(a) or not(b):
            return []
        if min(n,m)<=40:
            if n<m:
                n,m=m,n
                a,b=b,a
            res=[0]*(n+m-1)
            for i in range(n):
                for j in range(m):
                    res[i+j]+=a[i]*b[j]
                    res[i+j]%=self.mod
            return res
        z=1<<((n+m-2).bit_length())
        a=a+[0]*(z-n)
        b=b+[0]*(z-m)
        self.butterfly(a)
        self.butterfly(b)
        c=[0]*z
        for i in range(z):
            c[i]=(a[i]*b[i])%self.mod
        self.butterfly_inv(c)
        iz=pow(z,self.mod-2,self.mod)
        for i in range(n+m-1):
            c[i]=(c[i]*iz)%self.mod
        return c[:n+m-1]
n,k,f=map(int,input().split())
mod=998244353
fft=FFT(mod)
def dp(n):
    if n==1:
        return [1]*(k+1)
    bf=dp(n-1)
    res=[0]*(k+1)
    bf2=fft.convolution(bf,bf)
    sbf2=[0]*(2*k+3)
    for i in range(2*k,-1,-1):
        sbf2[i]=(sbf2[i+1]+bf2[i])%mod
        if i>k:continue
        res[i]=sbf2[i+1]+bf2[i]*(k-i+1)
        res[i]%=mod
    return res

ans=dp(n)
ans=fft.convolution(ans,ans)
print(ans[f] if f<=2*k else 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()


class FFT():
    def primitive_root_constexpr(self,m):
        if m==2:return 1
        if m==167772161:return 3
        if m==469762049:return 3
        if m==754974721:return 11
        if m==998244353:return 3
        divs=[0]*20
        divs[0]=2
        cnt=1
        x=(m-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,(m-1)//divs[i],m)==1:
                    ok=False
                    break
            if ok:
                return g
            g+=1
    def bsf(self,x):
        res=0
        while(x%2==0):
            res+=1
            x//=2
        return res
    butterfly_first=True
    butterfly_inv_first=True
    sum_e=[0]*30
    sum_ie=[0]*30
    def __init__(self,MOD):
        self.mod=MOD
        self.g=self.primitive_root_constexpr(self.mod)
    def butterfly(self,a):
        n=len(a)
        h=(n-1).bit_length()
        if self.butterfly_first:
            self.butterfly_first=False
            es=[0]*30
            ies=[0]*30
            cnt2=self.bsf(self.mod-1)
            e=pow(self.g,(self.mod-1)>>cnt2,self.mod)
            ie=pow(e,self.mod-2,self.mod)
            for i in range(cnt2,1,-1):
                es[i-2]=e
                ies[i-2]=ie
                e=(e*e)%self.mod
                ie=(ie*ie)%self.mod
            now=1
            for i in range(cnt2-2):
                self.sum_e[i]=((es[i]*now)%self.mod)
                now*=ies[i]
                now%=self.mod
        for ph in range(1,h+1):
            w=1<<(ph-1)
            p=1<<(h-ph)
            now=1
            for s in range(w):
                offset=s<<(h-ph+1)
                for i in range(p):
                    l=a[i+offset]
                    r=a[i+offset+p]*now
                    r%=self.mod
                    a[i+offset]=l+r
                    a[i+offset]%=self.mod
                    a[i+offset+p]=l-r
                    a[i+offset+p]%=self.mod
                now*=self.sum_e[(~s & -~s).bit_length()-1]
                now%=self.mod
    def butterfly_inv(self,a):
        n=len(a)
        h=(n-1).bit_length()
        if self.butterfly_inv_first:
            self.butterfly_inv_first=False
            es=[0]*30
            ies=[0]*30
            cnt2=self.bsf(self.mod-1)
            e=pow(self.g,(self.mod-1)>>cnt2,self.mod)
            ie=pow(e,self.mod-2,self.mod)
            for i in range(cnt2,1,-1):
                es[i-2]=e
                ies[i-2]=ie
                e=(e*e)%self.mod
                ie=(ie*ie)%self.mod
            now=1
            for i in range(cnt2-2):
                self.sum_ie[i]=((ies[i]*now)%self.mod)
                now*=es[i]
                now%=self.mod
        for ph in range(h,0,-1):
            w=1<<(ph-1)
            p=1<<(h-ph)
            inow=1
            for s in range(w):
                offset=s<<(h-ph+1)
                for i in range(p):
                    l=a[i+offset]
                    r=a[i+offset+p]
                    a[i+offset]=l+r
                    a[i+offset]%=self.mod
                    a[i+offset+p]=(l-r)*inow
                    a[i+offset+p]%=self.mod
                inow*=self.sum_ie[(~s & -~s).bit_length()-1]
                inow%=self.mod
    def convolution(self,a,b):
        n=len(a);m=len(b)
        if not(a) or not(b):
            return []
        if min(n,m)<=40:
            if n<m:
                n,m=m,n
                a,b=b,a
            res=[0]*(n+m-1)
            for i in range(n):
                for j in range(m):
                    res[i+j]+=a[i]*b[j]
                    res[i+j]%=self.mod
            return res
        z=1<<((n+m-2).bit_length())
        a=a+[0]*(z-n)
        b=b+[0]*(z-m)
        self.butterfly(a)
        self.butterfly(b)
        c=[0]*z
        for i in range(z):
            c[i]=(a[i]*b[i])%self.mod
        self.butterfly_inv(c)
        iz=pow(z,self.mod-2,self.mod)
        for i in range(n+m-1):
            c[i]=(c[i]*iz)%self.mod
        return c[:n+m-1]
n,k,f=map(int,input().split())
mod=998244353
fft=FFT(mod)
def dp(n):
    if n==1:
        return [1]*(k+1)
    bf=dp(n-1)
    res=[0]*(k+1)
    bf2=fft.convolution(bf,bf)
    sbf2=[0]*(2*k+3)
    for i in range(2*k,-1,-1):
        sbf2[i]=(sbf2[i+1]+bf2[i])%mod
        if i>k:continue
        res[i]=sbf2[i+1]+bf2[i]*(k-i+1)
        res[i]%=mod
    return res

ans=dp(n)
ans=fft.convolution(ans,ans)
print(ans[f])


a,b,r=map(int,raw_input().split())
if 2*r<a or 2*r<b: print "First"
else print "Second"


from sys import stdin

in_lines = ""
#if __debug__ :
#    in_lines = """
#6 7 4
#    """
    in_lines = filter( lambda x: x, map( lambda l: l.strip(), in_lines.split('\n') ) )
else :
    in_lines = stdin.readlines()

def int_values(line) :
    return map( int, line.split(' ') )

lines = map( int_values, map( lambda x:x.strip(), in_lines  ) )

a, b, r = lines[0]
if ( 2 * r > min([a, b]) ) :
    print 'Second'
else :
    print 'First'


a,b,c=map(int,raw_input().split())
d=a*b/(c*c)
if d%2==1:
    print "First"
else
    print "Second"


import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Comparator;
import java.util.TreeSet;

public class A {
	public class MyComparator implements Comparator<Long[]> {

		@Override
		public int compare(Long[] arg0, Long[] arg1) {
			if (arg0[0] * arg1[1] == arg0[1] * arg1[0])
				return 0;
			if (arg0[0] * arg1[1] > arg0[1] * arg1[0])
				return 1;
			else
				return -1;

		}

	}
	public static void solve() throws Exception {
		int n = nextInt();
		TreeSet<Long[]> s = new TreeSet<Long[]>();
		for (int i = 0; i < n; i++) {
			int k = nextInt();
			int b = nextInt();
			if (k == 0){
				continue;
			}
			if (k * b < 0){
				b = -1 * Math.abs(b);
			}
			else {
				b = Math.abs(b);
			}
			k = Math.abs(k);
			Long[] a = new Long[2];
			a[0] = (long)k;
			a[1] = (long)b;
			s.add(a);
		}
		out.print(s.size());
	}

	static public PrintWriter out = new PrintWriter(System.out);
	//static public BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

	static public StreamTokenizer in = new StreamTokenizer(new InputStreamReader(System.in));
	public static int nextInt() throws IOException {
		in.nextToken();
		return (int)in.nval;
	}
	public static String nextString() throws IOException {
		in.nextToken();
		return in.sval;
	}

	public static void main(String[] args) throws Exception {
		solve();
		out.flush();
	}

}


a,b,r=map(int,raw_input().split())
n=a*b/(4*r*r)

if n==0:
    print "Second"
else:
    print "First"


a,b = map(int,raw_input()).split()
print a + b + 1 >> 1


n=int(input())
m=int(input())
print  n*m/2


n, m = map(int, raw_input())
print n * m / 2


def voevoda(n, m):
    if n == 1:
        return m
    if n == 2:
        return (m - m % 4) + 2 * min(m % 4, 2)
    return (n * m + 1) // 2

N, M = [int(i) for i in input().split()]
print(voevoda(sorted(N, M)))


def b(m, n):
  if m == 1:
    return n

  if n == 1:
    return m

  if m <= 2 and n <= 2:
    return m * n

  ans = 0
  for x in xrange(m):
    if x % 2 == 0:
      ans += n / 2 + n % 2
    else:
      ans += n / 2

  return max(ans, m*n - ans)

n, m = map(int, raw_input().split(" "))
print b(n, m)


def clouded_strategy(H,W,cake):
    ans= int (cake[0][0]=='*')

    i,j=0,0
    prev= 'S'
    while (i,j)!= (H-1,W-1):
        if i==H-1 or j==W-1:
            if i==H-1:
                j+=1
            if j==W-1:
                i+=1
            ans += int (cake[i][j]=='*')
        else:
            if cake[i][j+1]!='*' and cake[i+1][j]!='*':
                if prev=='E':
                    i,j = i+1, j
                    prev=='S'
                if prev=='S':
                    i,j = i, j+1
                    prev=='E'

            elif cake[i][j+1]=='*':
                i,j = i,j+1
                prev=='E'
                ans+=1

            else:
                i,j = i+1,j
                prev=='S'
                ans+=1

    print (ans)

H,W = map (int, input().split(' '))
cake = [[] for i in range (H)]
for i in range (H):
    cake[i] = list (input ())

clouded_strategy(H,W,cake)


import sys, os

if os.environ['USERNAME']=='kissz':
    inp=open('in.txt','r').readline
    def debug(*args):
        print(*args,file=sys.stderr)
else:
    inp=sys.stdin.readline
    def debug(*args):
        pass

# SCRIPT STARTS HERE

h,w=map(int,inp().split())
M=[]
for _ in range(h):
    M+=[inp().strip()]

x=y=0
cnt=0
Q=[(x,y)]
while (x<h-1 or y<w-1):
    while Q:
        x,y=Q.pop(0)
        if M[x][y]=='*' or (x>=h-1 and y>=w-1): break
        if y<w-1:
            Q.append((x,y+1))
        if x<h-1:
            Q.append((x+1,y))
    cnt+=int(M[x][y]=='*')
    Q=[(x,y+1),(x+1,y)]
    #debug(Q)

print(cnt)


a, b = map(int, input().split())

cake = []

for _ in range(a):
	cake.append([x for x in input()])

count = 0
x, y = 0, 0

while x < b and y < a:
	if cake[y][x] == "*":
		count += 1
	if x < b-1 and cake[y][x+1] == "*"
		x += 1
	elif y < a-1 and cake[y+1][x] == "*":
		y += 1
	else:
		x += 1
		if x == b:
			x -= 1
			y += 1

print(count)


from collections import Counter,defaultdict,deque
#from heapq import *
#from itertools import *
#from operator import itemgetter
#from itertools import count, islice
#from functools import reduce
#alph = 'abcdefghijklmnopqrstuvwxyz'
#n,x = [int(_) for _ in input().split()]
#s = input().strip()
#sarr = [x for x in input().strip().split()]
#import math
#from math import *
#from heapq import *
import sys
input=sys.stdin.readline
#sys.setrecursionlimit(2**30)

#ons = ['no','yes']
def solve():
    #n = int(input())
    h,w = [int(_) for _ in input().split()]
    cake = []
    for i in range(h):
        cake.append(input().strip())
    curh = 0
    curw = 0
    ans = 0
    d = 0
    while True:
        ii = d+curw
        jj = curh
        while ii>=curw:
            if ii<w and jj<h and cake[jj][ii] == '*':
                ans+=1
                curw = ii
                curh = jj
                d = 0
                break
            else:
                if ii==w-1 and jj==h-1:
                    print(ans)
                    return
                ii-=1
                jj+=1
        d+=1

tt = 1#int(input())
for test in range(tt):
    solve()

#