a=input()
card=raw_input().split()
table=[[[[-1 for x in range(52)] for w in range(53)] for y in range(53)] for z in range(53)]
#maisuu(0index) -1 -2 -3

def ok(t,u):
	return t[0]==u[0] or t[1]==u[1]

mark={}
mark["2"]=0
mark["3"]=1
mark["4"]=2
mark["5"]=3
mark["6"]=4
mark["7"]=5
mark["8"]=6
mark["9"]=7
mark["T"]=8
mark["J"]=9
mark["Q"]=10
mark["K"]=11
mark["A"]=12
num={}
num["S"]=0
num["D"]=1
num["H"]=2
num["C"]=3

def tonum(kard):
	return mark[kard[0]]+13*num[kard[1]]

def solve(kard):
	if len(kard)==1:
		return True
	if len(kard)==2:
		if ok(kard[0],kard[1]):
			return True
		return False
	if table[len(kard)-1][tonum(kard[-1])][tonum(kard[-2])][tonum(kard[-3])]!=-1:
		return 	table[len(kard)-1][tonum(kard[-1])][tonum(kard[-2])][tonum(kard[-3])]
	res=False
	kk=kard[::]
	if ok(kard[-1],kard[-2]):
		kk[-2]=kk[-1]
		kk.pop()
		res=res or solve(kk)
	kk=kard[::]
	if len(kard)>3 and ok(kard[-1],kard[-4]):
		kk[-4]=kk[-1]
		kk.pop()
		res=res or solve(kk)
	table[len(kard)-1][tonum(kard[-1])][tonum(kard[-2])][tonum(kard[-3])]=res
	return res

print len(card)
if solve(card):
	print "YES"
else:
	print "NO"


n = int(raw_input())
c = raw_input().split()
q = [c]
v = set([tuple(c)])
while len(q) > 0:
	c = q.pop();
	if len(c) == 1:
		print 'YES'
		exit()
	for i in [-2,-4]:
		if len(c)>=abs(i) and (c[-1][0]==c[i][0] or c[-1][1]==c[i][1]):
			d = c
			d[i] = d[-1]
			d.pop()
			if tuple(d) not in v:
				v.add(tuple(d))
				q.append(d)
print 'NO'


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

import sys
import math
import random
import operator
from fractions import Fraction, gcd
from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
getcontext().prec = 100

MOD = 10**9 + 7
INF = float("+inf")

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

res = n - 1
for i in xrange(h):
    n = (n >> 1) + (n & 1)
    res += n

print res


def solve(n, verts):
	if n == 1:
		return -1
	if n == 2:
		if verts[0][0] == verts[1][0] or verts[0][1] == verts[1][1]:
			return -1
		else:
			return abs(verts[0][0] - verts[1][0]) * abs(verts[0][1] - verts[1][1])
	if n == 3 or n == 4:
		lowest = [0, 0]
		biggest = [0, 0]
		for i in verts:
			if i[0] <= lowest[0] and i[1] <= lowest[1]:
				lowest = i
		for i in verts:
			if i[0] >= biggest[0] and i[1] >= biggest[1]:
				biggest = i
		return abs(lowest[0] - biggest[0]) * abs(lowest[1] - biggest[1])

n = int(raw_input())
verts = [map(int, raw_input().split()) for i in range(n)]
print solve(n, verts)


import math
a=input()
ans=int(a,2)
n=int(math.sqrt(ans))
an=[int(4**x) for x in range(n+1) ]
c=0
i=0
while(an[i]<ans and i<n):
    i+=1
    c+=1
print(c)


s = input()
s = int(s,base=2)
c = 0
powers = [4**i for i in range(0,s)]
for i in range(len(powers)):
    if s > powers[i]:
        c += 1
print(c)


a = []
n = input()
m = input()
for i in range(n):
    a.append(input())
if sum(a) + m <= max(a) * n:
    print max(a)
else:
    print (sum(a) + m) / n + (sum(a) + m) % n


s = raw_input()
result = "NO"
for i in range(len(s)):
	for j in range(len(s)):
		if (s[:i] + s[j:] == "CODEFORCES"):
			result = "YES"
			break

print result


k=int(input())
l=int(input())
m=int(input())
n=int(input())
d=int(input())
i=1
count=0
while i<=n:
    if n<=i:
        if i%k!=0 and i%l!=0 and i%m!=0 and i%n!=0:
            count=count+1
    elif m<=i<n:
        if i%k!=0 and i%l!=0 and i%m!=0:
            count=count+1
    elif l<=i<m:
        if i%k!=0 and i%l!=0:
            count=count+1
    elif k<=i<l:
        if i%k!=0:
            count=count+1
    else:
        count=count+1
    i=i+1
print(d-count)


from sys import stdin
input = stdin.readline
#Recursion!!!!!
n, m = map(int, input().split())
array = [[0] * (max(m, n) + 1) for _ in range(min(m, n) + 1)]
def team(m, n):
    for i in xrange(m + 1):
        for j in xrange(n + 1):
            if i > 1 and j > 1:
                array[i][j] = max(array[i - 2][j - 1], array[i - 1][j - 2]) + 1
            elif i > 1 and j:
                array[i][j] = array[i - 2][j - 1] + 1
            elif i and j > 1:
                array[i][j] = array[i - 1][j - 2] + 1
    return array[m][n]
print team(min(m, n), max(m, n))


#!/usr/bin/python

def ir():
    return int(raw_input())

def ia():
    line = raw_input()
    line = line.split()
    return map(int, line)

d1, d2, d3 = ia()
r1 = d1 + d3 + d2
r2 = d1 + d1 + d2 + d2
r3 = d2 + d3 + d2
r4 = d2 + d2 + d1 + d1

print min(r1, r2, r3, r4)

#H -- d1 -- S1
#|         /
#|     d3 /
#d2  /
#|  /
#| /
#S2


l, r = map(int, raw_input().strip().split(' '))

ans = 0

cnt = 31
for i in xrange(cnt):
    for j in xrange(cnt):
        if i == 0 and j == 0:
            continue
        cur = (2 ** i) * (3 ** j)
        if l <= cur and cur <= r:
            ans += 1

print ans


h1, h2= tuple(map(int, input().split()))
a, b= tuple(map(int, input().split()))
"""
a =2 #скорость вверх
b =1 #скорость сползания
h1 =1 #старт червя
h2 =300 #высота яблока
r = a #переменная текущего положения
"""

#if h2 < h1: #прверяем корректность движения вверх
    #print('false')

day = 0
r = a*8+h1  #в первый день мы проходим половину (с 14 до 22)

if a<=b and a*8 + h1 <= h2: #проверяем успел ли червяк за первую половину дня и если скорость отрицательная отдаем -1
    day = -1
else:
    if a<=b and r < h2:             #при выполнении условия - запускаем цикл
        day = -1
    else:
        while r < h2:           #условие прекращения цикла: пока R меньше высоты 2
            r = r - b * 12      #сползаем вниз
            #print ('v',r)
            r = r + a * 12      #выполняем дневное движение вверх
            #print ('^', r)
            day = day +1        #увеличиваем счетчик дней

print (day)


def digitsum(n):
    n= list(map(int,str(n)))
    if sum(l)%4==0:
        return True
    else:
        return False
n=int(input())
for i in range(n,n+10):
    if digitsum(i):
        print(i)
        break


n,p = map(int,input().split())
s = bin(n)
r = s.count('1')
yy = r * p
n-=yy
if n < 0:
    print(-1)
else:
    s = bin(n)
    r = s.count('1')
    print(r)


from math import sqrt

def primes(n):
    sieve = set(range(3, n + 1, 2))
    if n >= 2:
        sieve.add(2)
    for i in range(3, int(sqrt(n)) + 1, 2):
        if i in sieve:
            sieve -= set(range(2 * i, n + 1, i))
    return sieve

n = int(input())
res = 1
for el in primes(n):
    if n % el == 0:
        res *= el
print(res)


import itertools
ans=10000000000000
n=map(int, raw_input().split())
x=map(str, raw_input().split())
nl=list(itertools.permutations(n))
xl=list(itertools.permutations(x))
nl=set(nl); nl=list(nl)
xl=set(xl); xl=list(xl)

for i in range(len(nl)):
    for j in range(len(xl)):
        e='(('+nl[i][0]+xl[j][0]+nl[i][1]+')'+xl[j][1]+nl[i][2]+')'+xl[j][2]+nl[i][3]
        f='('+nl[i][0]+xl[j][0]+nl[i][1]+')'+xl[j][1]+'('+nl[i][2]+xl[j][2]+nl[i][3]+')'
        ans=min(ans,eval(e),eval(f))
print ans


def f(q, t):
    a, b, c = sorted(q)
    if t == '**': return a * b * c
    if t == '++': return a + b + c
    if t == '*+': return a * b + c
    if t == '+*': return a * (b + c)

p = sorted(list(map(int, input().split())))
t = input()[:: 2]
x, t = t[0], t[1: ]
if x == '*':
    s = p[0] * p[1] * p[2] * p[3]
    for i in range(3):
        for j in range(i + 1, 4):
            q = p[:]
            q[i] *= q[j]
            q.pop(j)
            s = min(f(q, t), s)
    print(s)
else: print(f([p[0], p[1], p[2] + p[3]]))


factor = [ 1]
fac, ans=1,0
for i in range (1,31):
        fac*=i
        factor.append(fac)
n , m ,t = map(int,input().split())

for i in range (4,t+1):
        if t-i <=m and t-i >0:
                ans+= (factor[n]//(factor[n-i]*factor[i] )) *(factor[m]//(factor[m-(t-i)]*factor[t-i]))

print(ans)


n,a,b,c=map(int,input().split())
f,d=n,n
e=0
if n%4==0:
    print(0)
else:
    w=[]
    for i in range(10**9):
        if (n+i)%4==0:
            w.append(i*a)
            e+=1
        if (f+i*2)%4==0:
            w.append(i*b)
            e+=1
        if (d+i*3)%4==0:
            w.append(min(i*c,i*a+i*b))
            e+=1
        if (d+i*5)%4==0:
            w.append(min(i*c,i*a+i*b)+i*b)
            e+=1
        if (d+i*4)%4==0:
            w.append(min(i*c,i*a+i*b)+i*a)
            e+=1
        if e==5:
            break
    print(min(w))


def f(n):
    m = int(n ** 0.5) + 1
    t = [1] * (n + 1)
    for i in range(3, m):
        if t[i]: t[i * i :: 2 * i] = [0] * ((n - i * i) // (2 * i) + 1)
    return [2] + [i for i in range(3, n + 1, 2) if t[i]]

a, b, k = map(int, input().split())
k -= 1; b += 1

t, p, x = [-1] * (b + 100), f(b + 100), -1

for i in range(len(p) - k):
    t[p[i]] = p[i + k] - p[i]

t.reverse()
for i in range(1, b + 100):
    if t[i] < 0: t[i] = t[i - 1] + 1
t.reverse()

if len(p) > k:
    for i in range(a + 1, b):
        t[i] = max(t[i], t[i - 1])

    for l in range(1, b - a + 1):
        if t[b - l] < l:
            x = l
            break
print(x)


def f(a, b):
    t = [1] * (b + 1)
    for i in range(3, int(b ** 0.5) + 1):
        if t[i]: t[i * i :: 2 * i] = [0] * ((b - i * i) // (2 * i) + 1)
    return [i for i in range(3, b + 1, 2) if t[i] and i > a]

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

p = f(a - 1, b)
if 3 > a: p = [2] + p

if k > len(p): print(-1)
else: print(max(p[k - 1] - a + 1, b - p[len(p) - k] + 1, max(p[i + k] - p[i] for i in range(len(p) - k))))


n=int(input())
l=int(input())
r=int(input())
a=[]
t=1
for i in range(l):
    a.append(t)
    t=t*2
b=[]*n
i=0
while(i<n-l+1):
    b.append(a[0])
    i=i+1
j=1
for j in range(l-1):
    b.append(a[j+1])
sum=0
for i in range(len(b)):
    sum=sum+b[i]

c=[]
k=1
for i in range(r):
    c.append(k)
    k=k*2
u=[]*n
y=0
while(y<n-r+1):
    u.append(c[len(c)-1])
    y=y+1
for g in range(r-1):
    u.append(c[g])

sums=0
for i in range(len(u)):
    sums=sums+u[i]

print(sum,sums)


import math

def main():

    x = [0] * 4
    y = [0] * 4

    for i in range(4):
        x[i], y[i] = map(int, input().split())

    xtot = (x[1] + x[2] + x[3] + x[4]) / 4
    ytot = (y[1] + y[2] + y[3] + y[4]) / 4

    p1 = math.sqrt(xtot - x[1]) + math.sqrt(ytot - y[1])
    p2 = math.sqrt(xtot - x[2]) + math.sqrt(ytot - y[2])
    p3 = math.sqrt(xtot - x[3]) + math.sqrt(ytot - y[3])
    p4 = math.sqrt(xtot - x[4]) + math.sqrt(ytot - y[4])

    if(p1 == p2 and p1 == p3 and p1 == p4):
        print("YES")

    else:
        print("NO")

if __name__ == '__main__':
    main()


string=raw_input().strip()
res=string.split('WUB')
print ' '.join([r for r in res in r!=''])


def prime(n):
    d = 2
    prime_dict = dict()
    while n >= d:
        if n % d == 0:
            if prime_dict[d]:
                prime_dict[d] = prime_dict[d] + 1
            else:
                prime_dict[d] = 1
        else:
            d = d + 1
    return prime_dict

_ = input()
n, d = _.split()
n, d = int(n), int(d)
prime_dict = prime(d)
n_prime_dict = dict()
answer = 10000000
for key in prime_dict:
    _pow_key = key
    n_prime_key = 0
    while _pow_key < n:
        n_prime_key = n_prime_key + n // _pow_key
        _pow_key = _pow_key * key
    answer = min(answer, n_prime_key // prime_dict[key])
print(answer)


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

M = mod = 998244353
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
# def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]

def compare(a,b):
    if a[-1]<b[-1]:return -1
    elif a[-1]>b[-1]:return 1
    else:
        if sum(a[:-1]) > sum(b[:-1]):return -1
        return 1

t1, t2, x1, x2, t = li()
bestans = []
if t == t1 and t1 == t2:
    print(x1,x2)
elif t == t1:
    print(x1,0)

elif t == t2:
    print(0,x2)
else:

    r = (t2 - t)/(t - t1)

    for i in range(1,x2 + 1):
        curry1 = i*r
        if 0 <= int(curry1) <= x1:
            bestans.append([int(curry1),i,curry1 - int(curry1)])
        if 0 <= math.ceil(curry1) <= x1:
            bestans.append([math.ceil(curry1),i,math.ceil(curry1) - curry1])

    for i,(a,b,c) in enumerate(bestans):
        if ((a*t1 + b*t2)/(a + b)) < t:
            bestans[i][-1] = 1000
            continue
        bestans[i][-1] = abs(t - ((a*t1 + b*t2)/(a + b)))

    bestans.sort(key=cmp_to_key(compare))
    # print(bestans)
    print(*bestans[0][:-1])


l=int(input())
r=int(input())
a=int(input())
ans=0
if(a>=abs(l-r)):
	if(l>r):
		a=a-(l-r)
		ans=l*2+(a//2)
	else:
		a=a-(r-l)
		ans=r*2+(a//2)
else:
	ans=(min(l,r)+a)*2
print(ans)


import sys
l=sys.stdin.read()
l1 = l.split('\n')
l_int = []
for j in l1:
    l_int.append(int(j))

init = [1, 2]
rest = 3
total = l_int[0]
t = 0
for i in l_int[1:]:
    t += 1
    if i not in init:
        print 'NO'
        break
    else:
        for k in init:
            if k != i:
                 init.remove(k)
                 init.append(rest)
                 rest = k
        if t == total:
            print 'YES'
            break


if __name__=="__main__":
    n,k = map(int, input().strip().split())
    t= 240 - k
    i=0
    while(True):
        i += 1
        t = t-5*i
        if t < 0:
            i -= 1
            break

    print(min(i,n))


import time
import numpy as np

coord = set()
flows = int(input())
start = time.time()
t = list(map(int, input().split()))
directions = {0: (0, 1), 1: (1, 1), 2: (1, 0), 3: (1, -1), 4: (0, -1), 5: (-1, -1), 6: (-1, 0), 7: (-1, 1)}
was = np.zeros([600,600,31,8])

def flight(n, x=0, y=0, direction=0):
    if was[x][y][n][direction]:
        #print(x, y, direction, n, len(was))
        return
    was[x][y][n][direction] = 1
    if n:
        for _ in range(t[flows - n]):
            x += directions[direction][0]
            y += directions[direction][1]
            coord.add((x, y))
        flight(n - 1, x, y, (direction + 1) % 8)
        flight(n - 1, x, y, (direction - 1) % 8)

flight(flows)
# print(coord)
print(len(coord))
print(time.time() - start)


n,s,a=raw_input(),[],0
for i in map(int,raw_input().split(' ')):
    while len(s)>1 and min(s[-2],i)>=s[-1]:
        ans+=min(i,s[-2])
        del(s[-1])
    s.append(i)
s.sort()
print a+sum(s[0:-2])


import sys

n=int(sys.stdin.readline().strip('\n'))
line=sys.stdin.readline().strip('\n').split(' ')
values=map(lambda x:int(x),line)

def evaluateBothSides(start,stop):
    print start,stop
    if stop-start==1:
        return min(values[start-1],values[stop])
    elif stop-start==0:
        return 0
    else:
        maxNum=0
        maxPos=0
        for i in xrange(start,stop):
            if values[i]>maxNum:
                maxPos=i
                maxNum=values[i]
        return evaluateBothSides(start,maxPos)+evaluateBothSides(maxPos+1,stop)+min(values[start-1],values[stop])

def evaluateMax(stop):
    2+2

def evaluate(start,stop):
    2+2

def addToQueue(inp,queue):
    out=0
    if inp<queue[-1]:
        queue.append(inp)
    else:
        queue.pop()
        out+=inp
        while inp>queue[-1]:
            out+=queue.pop()
        queue.append(inp)
    return out

def queueEvaluate():
    maxLeft=0
    maxRight=0
    maxPos=0
    maxNum=0
    for i in xrange(0,n):
            if values[i]>maxNum:
                maxPos=i
                maxNum=values[i]
    out=0
    queue=[maxNum]
    for i in xrange(maxPos+1,n):
        out+=addToQueue(values[i],queue)
        #print queue
    if len(queue)==1:
        pass
    else:
        maxRight=queue[1]
        for i in xrange(2,len(queue)):
            out+=queue[i]
    queue=[maxNum]
    for i in xrange(maxPos-1,-1,-1):
        out+=addToQueue(values[i],queue)
        #print queue
    if len(queue)==1:
        pass
    else:
        maxLeft=queue[1]
        for i in xrange(2,len(queue)):
            out+=queue[i]
    out+=min(maxLeft,maxRight)
    return out

print queueEvaluate()


from math import factorial as fac

n, t = map(int, input().split())
if t & (t - 1):
    ans = 0
else:
    ans = c = 0
    s = bin(n + 2)[2:]
    l = len(s)
    for i in range(l):
        if s[i] == '1':
            m, k = l - i - 1, t.bit_length() - c
            if k <= m:
                ans += fac(m) // fac(k) // fac(m - k)
            c += 1
    if t == 1: ans -= 1
print(ans)


import math
n, t = map(int, raw_input().split())

for i in range(55):
    comb = [[0]*55 for _ in range(55)]
for i in range(55):
    for j in range(i+1):
        if (i == 0 or j == 0): comb[i][j] = 1
        else:
            comb[i][j] = comb[i-1][j] + comb[i-1][j-1]

def gao(m, k):
    ret = 0
    while m > 0:
        p = int(math.log(m, 2))
        ret += comb[p][k]
        k -= 1
        m -= 2**p
        if m == 0:
            if k == 0:
                ret += 1
            break
        if k < 0:
            break
    return ret

k = int(math.log(t, 2))
tmp = 0
while (t > 0):
    if (t % 2 == 1):
        tmp += 1
    t /= 2
    if (tmp > 1):
        break
if (tmp > 1):
    print 0
else:
    ans = gao(n+1, k+1)
    if t == 1:
        ans -= 1
    print ans


from sys import stdin
a,b,c,d,e,f = stdin.readline().strip().split()
a=int(i);b=int(b);c=int(c);d=int(d);e=int(e);f=int(f);
fir  = b*b * d*f;
sec = a*a * c *e;
if fir>sec:
 print 'Ron'
else:
 print 'Hermione'


import math
n, m, a = map(int, input().split())
print (sum([1 for i in range(math.ceil(n/a)) for i in range(math.ceil(m/a))]))


from sys import stdin
rr = stdin.readline
rrm = lambda: map(int, rr().strip().split())
YES, NO, MOD = "YES", "NO", 10**9 + 7

def solve(N,K,A):
    ans = 0
    for b in xrange(K):
        opn = [x for i,x in enumerate(A) if i%k != b]
        val = abs(sum(opn))
        ans = max(ans, val)
    return ans

N, K = rrm()
A = rrm()
print solve(N,K,A)


import heapq
n,k,q=[int(i) for i in input().split()];
t=[int(i) for i in input().split()];
h=[]
isnew=False;
r=[];
for i in range(q):
    type,id=[int(i) for i in input().split()];
    if(type==1):
        if(k>len(h)):
            heapq.heappush(h,t[id-1])
        else:
            heapq.heappushpop(h,t[id-1])
    else:
        if t[id-1] in h:
            r.append("YES");
        else:
            r.append("NO");
print(*r,sep='\n');


# -*- coding: utf-8 -*-
"""
Created on Tue Mar 19 20:14:41 2019

@author: KIIT
"""

import math
import os
import random
import re
import sys
from itertools import permutations

if __name__ == '__main__':
    a = list(map(int, input().rstrip().split()))
    if(a[1]==a[0]):
        print(0)
    if(a[0]==0):
        print(-1)
    elif(a[1]%a[0]==0):
        d=a[1]/a[0]
        k,p=0,0
        if(d%2==0):
            k=2
            p=3
        elif(d%3==0):
            k=3
            p=2
        c=0
        while(d%k==0):

            c=c+1
            d=d/k
        while(d%p==0):
            c=c+1
            d=d/p
        print(c)

    else:
        print(-1)


vvod=input()
n,m=vvod.split()
n=int(n)
m=int(m)

k=m/n
if k!=int:
    print('-1')
else:
    c=0
while k>1:
    if k%3==0:
        k=k/3
    else:
        k=k/2
    c=c+1
print(c)


def ornaments(y,b,r):
	l = min(y,b,r)
	print((l+1) + l + (l-1))

y = int(input())
b = int(input())
r = int(input())
ornaments(y,b,r)


n,k,M,D = map(int, input().split())
print(max([ d*min(m, n//(k*(d-1)+1))     for d in range(1,D+1)]))


read = lambda: map(int, input().split())
n, v, e = read()
adj = [[]] * (n + 1)
As = [0] + list(read())
Bs = [0] + list(read())
ans = []

for _ in range(e):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)

def flow(a, b, d):
    As[a] -= d
    As[b] += d
    ans.append((a, b, d));

def augment(path, e, d):
    if e:
        dd = min(d, As[path[e - 1]], v - As[path[e]])
        flow(path[e - 1], path[e], dd)
        augment(path, e - 1, d)
        if d > dd:
            flow(path[e - 1], path[e], d - dd);

def adjust(s):
    pre = [0] * (n + 1)
    pre[s] = -1
    stk = [s]
    e = 0
    while len(stk):
        p = stk[-1]
        del stk[-1]
        if As[p] < Bs[p]:
            e = p
            break
        for to in adj[p]:
            if not pre[to]:
                pre[to] = p
                stk.append(to)

    if not e:
        raise Exception

    path = []
    while e > 0:
        path.insert(0, e)
        e = pre[e]

    augment(path, len(path) - 1, min(Bs[path[-1]] - As[path[-1]], As[s] - Bs[s]))

try:
    while True:
        check = False
        for i in range(1, n + 1):
            if As[i] > Bs[i]:
                adjust(i)
                check = True
        if not check:
            break
    for i in range(1, n + 1):
        if As[i] != Bs[i]:
            raise Exception
    print(len(ans))
    for tp in ans:
        print(*tp)
except Exception:
    print("NO")


import numpy as np
from sys import stdin, stdout
a, b, c = map(int, stdin.readline().rstrip().split())
days=['f', 'r', 'c', 'f', 'c', 'r', 'f']
divs=[a//3, b//2, c//2]
divmin = np.min(divs)
maxi=divmin*7
#print("divmin : ", divmin)
#print("maxi : ", maxi)
if maxi!=0:
    a, b, c = a-(divmin*3), b-(divmin*2), c-(divmin*2)
#print("a : ", a, "b : ", b, "c : ", c)
for i in range(0, 7):
    dayfood={'f':a, 'r':b, 'c':c}
    #print("i : ", i)
    k=divmin*7
    while 1:
        l=days[(k+i)%7]
        #print("l : ", l, " value : ", dayfood[l], " indice : ", (k+i)%7)
        k+=1
        if dayfood[l]==0:
            break
        else :
            dayfood[l]-=1
    if k-1 > maxi:
        maxi = k-1
print(maxi)


n,m,k=map(int,input().split())
if k%2==0:
    z=k//2
    d='R'
else:
    z=(k+1)//2
    d='L'
b=[]
c=1
e=[]
for i in range(n):
    for j in range(m):
        e.append(c)
        c+=1
    b.append(e)
    e=[]
y=[]
for i in range(len(b)):
    if z in b[i]:
        l=i+1
        y=b[i]
        break
for i in range(len(y)):
    if y[i]==z:
        v=i+1
        break
print(l,v,d)


a=list(map(int,input().split()))
b=[]
for x in range(a[0]):
	for y in range(a[0]):
		b.append((x+1)*(y+1))
print(b.count(a[1]))


a = int(input())
A = []
b = int(input())
A.append(b)
while b != a:
    if (b-1) % 10 == 0 and b >= a:
        b = (b-1)//10
        A.append(b)
    elif b % 2 == 0 and b >= a:
        b = b//2
        A.append(b)
    else:
        break
if a == b:
    A = sorted(A)
    print('YES')
    print(len(A))
    print(*A,sep = ' ')
else:
    print('NO')


s1=raw_input()
n=len(s1)
s2=raw_input()
m=len(s2)
if '?' not in s1 and '?' not in s2:
    sm1=0
    sm2=0
    for i in s1:
        if i=='+':sm1+=1
        else: sm1-=1

    for i in s2:
        if i=='+': sm2+=1
        else: sm2-=1
    print(1 if sm1==sm2 else 0)
    exit()
sm1=0
for i in s1:
    if i=='+':sm1+=1
    else: sm1-=1
#make1=[s1]
make2=[s2]
ans=[]
while any('?'  in i for i in make2):
    n=[]
    for i in make2:
        if '?' not in i:
            ans.append(i)
        for j in range(len(i)):
            if i[j]=='?':
                n.append(i[0:j]+"-"+i[j+1:])
                n.append(i[0:j]+'+'+i[j+1:])
    make2=n
    #print(make2)
#make2=ans
make2=[i for i in make2 if '?' not in make2]
#print(make2)
#make2=list(set(make2))
#print(make2)
def sum_now(s):
    sum=0
    for i in s:
        if i=='+': sum+=1
        else: sum-=1
    return sum
make2=[sum_now(i) for i in make2]
#print(make2)
print(sum(i==sm1 for i in make2)*(1.0)/len(make2))


# Contest: 21 - Codeforces Rating >= 2200 (https://a2oj.com/ladder?ID=21)
# Problem: (25) Hexagons (Difficulty: 5) (http://codeforces.com/problemset/problem/615/E)

def rint():
    return int(input())

def rints():
    return list(map(int, input().split()))

n = rint()
if n == 0:
    print(0, 0)
    exit(0)
n -= 1
l, h = 0, 10**9
while h - l > 1:
    m = (h + l) // 2
    if 3 * m * (m + 1) > n:
        h = m - 1
    else:
        l = m
c = h if 3 * h * (h + 1) <= n else l
n -= 3 * c * (c + 1)

fields = [(2 * (c + 1), 0)]
for dx, dy in [(-1, 2), (-2, 0), (-1, -2), (1, -2), (2, 0), (1, 2)]:
    for i in range(c + 1):
        x, y = fields[-1]
        fields.append((x + dx, y + dy))
print(*fields[n + 1])


lista = list(map(int, input().split()))
a = lista[0]
b = lista[1]
import math

def resta(a,b):
	if a==0 or b==0:
		return(f"{a} {b}")
	else:
		if a>=(2*b):
			c = (math.floor((a/(2*b))-1))
			if c >= 1:
				a = a - 2*b*c
				return(resta(a,b))
			else:
				a = a - 2*b
				return(resta(a,b))
		if b>=(2*a):
			d = (math.floor((b/(2*a))-1))
			if d >= 1:
				b = b - 2*a*d
				return(resta(a,b))
			else:
				b = b - 2*a
				return(resta(a,b))
		else:
			return(f"{a} {b}")

print(resta(a,b))


from math import factorial
fac = factorial

def dfs(lst):
    sums = [[] for i in xrange(k+1)]
    sums[0].append(0)
    while len(lst)>0:
        cur = lst.pop(0)
        length = [len(sums[i]) for i in xrange(k+1)]
        for i in xrange(k+1):
            for j in xrange(length[i]):
                if sums[i][j] + cur <=s:
                    sums[i].append(sums[i][j]+cur)
                    if cur<19 and i<k and sums[i][j]+fac(cur)<=s:
                        sums[i+1].append(sums[i][j]+fac(cur))
    return sums

#def search(x, k):
#    count = 0
#    for i in xrange(k+1):
#        count += second[i].count(x)
#    return count

n, k, s = map(int, f.readline().split())
a = [int(item) for item in f.readline().split()]
a.sort()

first = dfs(a[:n/2])
second = dfs(a[n/2:])

df = [{} for i in xrange(k+1)]
ds = [{} for i in xrange(k+1)]
for i in xrange(k+1):
    for item in set(first[i]):
        df[i][item] = first[i].count(item)
    for item in set(second[i]):
        ds[i][item] = second[i].count(item)
#for i in xrange(k+1):
#    second[i].sort()
count = 0
for i in xrange(k+1):
    for sum1 in df[i]:
        for kk in xrange(k-i+1):
            if s-sum1 in ds[kk]:
                count += df[i][sum1]*ds[kk][s-sum1]
print count


import sys

import itertools

from collections import defaultdict

factorials = [1] * 19

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

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

def enum(l):

    global K, S

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

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

    for opts in options:

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

            if s > S:
                break

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

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

    return d

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

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

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

print(variants)


m=input()
n=input()
o=input()
r1,r2=m.split(" ")
c1,c2=n.split(" ")
d1,d2=o.split(" ")
x=int((int(r1)+int(d1)-int(c2))/2)
w=int((int(r2)+int(d2)-int(c2))/2)
y=int((int(r1)+int(d2)-int(c1))/2)
z=int((int(r2)+int(d1)-int(c1))/2)
if x==y or y==z or z==w or w==x or y==w or x==z:
    print(-1)
elif x>9 or y>9 or w>9 or z>9 or x<1 or y<1 or w<1 or z<1:
    print(-1)
elif a!=b or b!=c or c!=a:
    print(-1)
else:
    print(str(x)+" "+str(y))
    print(str(w)+" "+str(z))


input()
c=a=r=0
for i in input().split():c=(a==i)*c+1;a=i;r+=c
print(r)


def solve(a,b):
	if b==1:
		return a
	k=int(a/b)
	c=b-a%b
	if c==1:
		return k+a%b +1
	else:
		return k+solve(c,a) +1

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

print solve(a,b)


from math import sqrt
a,b,c = map(int, raw_input().split())
d = (b**2) - 4*a*c
d = sqrt(d)

list = [(-b-d)/ 2 / a,(-b+d)/2 / a]


from math import sqrt
def F(n):
    n += 2
    return int(round(((1+sqrt(5))**n-(1-sqrt(5))**n)/(2**n*sqrt(5))))

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

ans = 1

if k >= (2<<l):
    print 0
else:
    while l > 0:
        bit = k&1
        k = k >> 1
        l -= 1

        if bit == 0:
            ans *= F(n)
            ans %= m
        else:
            ans *= ((1<<n) - F(n))
            ans %= m

        #print bit,F(n),ans

    print ans


import math

def mod_expo(a, b, m):
	if b == 0:
		return (1 % m)
	ans = mod_expo(a, b//2, m)
	if b % 2 == 0:
		return (ans * ans) % m
	else:
		return (ans * ans * (a % m)) % m

def mat_mul(mat1, mat2, m):
	ans = [[0,0],[0,0]]
	ans[0][0] = (mat1[0][0]*mat2[0][0] + mat1[0][1]*mat2[1][0])%m
	ans[0][1] = (mat1[0][0]*mat2[0][1] + mat1[0][1]*mat2[1][1])%m
	ans[1][0] = (mat1[1][0]*mat2[0][0] + mat1[1][1]*mat2[1][0])%m
	ans[1][1] = (mat1[1][0]*mat2[0][1] + mat1[1][1]*mat2[1][1])%m
	return ans

def mod_mat_expo(mat, n, m):
	if n == 0:
		return [[1 % m, 0],[0, 1 % m]]
	ans = mod_mat_expo(mat, n//2, m)
	ans = mat_mul(ans, ans, m)
	if n % 2 == 0:
		return ans
	else:
		return mat_mul(ans, mat, m)

def f(n, m):
	if n == 2:
		return 3 % m
	if n == 3:
		return 5 % m
	mat = [[1,1],[1,0]]
	mat = mod_mat_expo(mat, n-3, m)
	return (mat[0][0]*(5%m)+mat[0][1]*(3%m))%m

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

if math.log(k, 2) >= l:
	print 0
else:
	t = f(n, m)
	mul = 1
	for i in range(l):
		bit = k % 2
		if bit == 0:
			mul = (mul * t) % m
		else:
			x = mod_expo(2, n, m)
			if(x >= t):
				mul = (mul * (x - t)) % m
			else:
				mul = (mul * (x - t + m)) % m
		k = k / 2
	print mul


from math import sqrt

def is_square(n):
    r = sqrt(n)
    return int(r * r) == n

n = input()
mx = 0
L = len(n)
for i in range(1 << L):
    s = ''
    for j in range(L):
        if i & (1 << (L - j - 1)):
            s += n[j]
    if s[0] != '0' and is_square(int(s)) and len(s) > mx:
        mx = len(s)
print(L - mx)


k,l=raw_input().split()
k=int(k)
l=int(l)
count=0;
while (l%k==0):
 l/=k
 count=count+1
if l==1:
 print "YES\n%d"%(count-1)
else:
 print "NO"


input()
string = list(input())
res = list()
if len(string) > 1:
    for i in range(len(string) // 2):
        if len(string) <= 1:
            res.append(string)
            break
        a = string[:i+1]
        if len(a) > 0:
            res.append(a[0])
        del string[:i+1]
else:
    res.append(string[0])
print("".join(res))


from sys import stdin, stdout
import sys
sys.setrecursionlimit(1500)

# 7 3
# n % 2 % 3 % 4 = n % 3 % 2 % 4
# 8 % 3 % 6 = 2 = 8 % 6 % 3 =
# 8 % 5 % 10 = 3 = 8 % 10 % 5 = 3
# 8 % 2 % 5, 8 % 5 % 2

# 1 => (2 3) 4 5 6 =>
# 1 => (2, 3) 4 => 3*2 / 2
# 1 => any
# 2 => 2*1, 2*2, 2*3, 2*4
# 3 => 3*1, 3*2, 3*3, 3*4
# 5 => 5*1, 5*2, 5*3, 5*4
def modular_stability(n, k):

    if k > n:
        return 0

    if k == 1:
        return n

    res = 0
    # 1
    res += com(n-1, k-1)
    res %= 998244353

    # prime numbers
    for i in range(2, n+1):
        #if isprime(i):
        cnt = n // i
        if cnt == k:
            res += 1
        elif cnt > k:
            res += com(cnt-1, k-1)
            res %= 998244353

    #print(faca)
    return res

def isprime(n):

    j = 2
    while j*j <= n:
        if n%j == 0:
            return False
        j += 1

    return True

def com(p1, p2):
    return fac(p1) // fac(p1-p2) // fac(p2)

faca = [0, 1]
def fac(n):
    if len(faca) > n:
        return faca[n]
    r = n*fac(n-1)
    faca.append(r)

    return r

if __name__ == '__main__':
    (n,k) = list(map(int, stdin.readline().split()))
    for i in range(1, n+1):
        fac(i)

    print(modular_stability(n, k))


t, k = input(), 0
p = defaultdict(list)
for j, i in enumerate(t, 1):
    p[i].append(j)
for i in list(p.keys()):
    if len(p[i]) < 2: p.pop(i)
if p:
    k = 1
    while True:
        q = defaultdict(list)
        for i in p:
            for j in p[i]:
                if j < len(t): q[i + t[j]].append(j + 1)
        p = q
        for i in list(p.keys()):
            if len(p[i]) < 2: p.pop(i)
        if not p: break
        k += 1
print(k)


n=int(input())
def sumd(n) :
    sumf=0
    p=len(str(n))
    for i in range(p):
        sumf+=n//10**(p-1-i)
        n=n%10**(p-1-i)
    return sumf
if n%2==0:
    x=n/2+1
    y=n/2-1
else:
    x=n//2
    y=n-x
print(int(sumd(x)+sumd(y)))


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

def gcd(a,b):
    while a!=b:
        if a>b:
            a-=b
        if b>a:
            b-=a
    return a

a=a*1L
n=a*b/gcd(a,b)

l=[]

for i in xrange(a,n,a):
    l.append([i,1])

for i in xrange(b,n,b):
    l.append([i,2])

i=j=p=0

if a<b:l.append([n,2])
else: l.append([n,1])

for a,b in sorted(l):
    if b==1: i+=a-p;p=a
    if b==2: j+=a-p;p=a

if i>j: print "Dasha"
elif i<j: print "Masha"
else: print "Equal"


s = raw_input()
s1 = map(int,list(s))
s = int(s)

def isLucky(n):
    for i in range(len(n)):
        if s1[i] != 4 and s1[i] != 7:
            return True
    return False
def isAlmostLucky(n):
    for i in range(1001):
        if isLucky(list(str(i))):
            if n%i == 0:
                return True
    return False
if isLucky(s1):
    print("YES")
else:
    if isAlmostLucky(s):
        print('YES')
    else:
        print('NO')


n = int(input())
min=10000
max=0
for i in range(0,n):
    year=int(input())
    if min>year: min=year
    if max<year: max=year
print(int((min+max)/2))


class State:
  __slots__ = ['candidate', 'votes', 'last_vote']

  def __init__(self, cand, votes, last):
    self.candidate = cand
    self.votes = votes
    self.last_vote = last

  def beats(self, other, extra):
    return self.votes + extra > other.votes

def main():
  candidates, seats, people, voted = map(int, input().split())
  votes = [0 for i in range(candidates)]
  last_vote = [0 for i in range(candidates)]

  if candidates == 1:
    print(1)
    return

  v = list(map(int, input().split()))
  for t in range(voted):
    cand = v[t] - 1
    votes[cand] += 1
    last_vote[cand] = t

  states = [State(i, votes[i], last_vote[i]) for i in range(candidates)]
  states = sorted(states, key = lambda x : (x.votes, -x.last_vote))
  res = [0 for i in range(candidates)]

  for i in range(candidates):
    if i < candidates - seats:
      low = candidates - seats
      if states[i].beats(states[low], people - voted):
        res[states[i].candidate] = 2
      else:
        res[states[i].candidate] = 3
    else:
      extra = people - voted
      other = i - 1
      place = i

      if extra == 0 and states[i].votes == 0:
        res[states[i].candidate] = 3
        continue

      while other >= 0 and extra > 0:
        needed = states[i].votes - states[other].votes + 1
        if needed <= extra:
          extra -= needed;
          place -= 1
          other -= 1
        else:
          break

      res[states[i].candidate] = (1 if place + seats >= candidates else 2)

  for i in res:
    print(i, end = ' ')

main()


from copy import deepcopy
n, k, m, a = [int(i) for i in input().split()]
cn = [0] * (n + 1)
last = [-1] * (n + 1)
v = [int(i) for i in input().split()]

for i in range(len(v)):
    last[v[i]] = i
    cn[v[i]] += 1

cn1 = deepcopy(cn)
last1 = deepcopy(last)

for i in range(1, n + 1):
    cn = deepcopy(cn1)
    last = deepcopy(last1)
    res = [i1 for i1 in range(1, n + 1)]
    res.sort(key=lambda x: (cn[x], -last[x]), reverse = True)

    for j in range(len(res)):
        if res[j] != i:
            continue
        j1 = j + 1
        lft = m - a
        while j1 < n and lft:
            cn[res[j1]] += min(lft, cn[i] - cn[res[j1]] + 1)
            last[res[j1]] = m
            lft -= min(lft, cn[i] - cn[res[j1]] + 1)
            j1 += 1

    res.sort(key=lambda x: (cn[x], -last[x]), reverse = True)
    sans = 0
    for j in range(len(res)):
        if res[j] != i:
            continue
        if cn[i] == 0 or j >= k:
            sans = 0
        else:
            sans = 1
        break

    if sans == 1:
        print(1, end= ' ')
        continue

    cn = deepcopy(cn1)
    last = deepcopy(last1)

    if m - a:
        cn[i] += m - a
        last[i] = m - 1

    res.sort(key=lambda x: (cn[x], 0 -last[x]), reverse = True)
    for j in range(len(res)):
        if res[j] != i:
            continue
        if cn[i] == 0 or j >= k:
            sans = 0
        else:
            sans = 1
        break

    if sans:
        print(2, end=' ')
    else:
        print(3, end=' ')


k, n, w = [int(s) for s in input().split()]
print (k*w*(w+1)/2-n)


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

import sys, math, random, operator
from string import ascii_lowercase, ascii_uppercase
from fractions import Fraction, gcd
#from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
from Queue import Queue, PriorityQueue
from collections import deque, defaultdict, Counter
#getcontext().prec = 100

MOD = 10**9 + 7
INF = float("+inf")

if sys.subversion[0] == "PyPy":
    import io, atexit
    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
    sys.stdin = io.BytesIO(sys.stdin.read())
    raw_input = lambda: sys.stdin.readline().rstrip()
pr = lambda *args: sys.stdout.write(" ".join(str(x) for x in args) + "\n")
epr = lambda *args: sys.stderr.write(" ".join(str(x) for x in args) + "\n")
die = lambda *args: pr(*args) ^ exit(0)

read_str = raw_input
read_strs = lambda: raw_input().split()
read_int = lambda: int(raw_input())
read_ints = lambda: map(int, raw_input().split())
read_float = lambda: float(raw_input())
read_floats = lambda: map(float, raw_input().split())

"---------------------------------------------------------------"

n = read_int()
s = read_str()

num = []
for i in xrange(len(s)):
    num.append([None])
    for j in xrange(i + 1, len(s)+1):
        num[i].append( int(s[i:j], 2) )

needed_for_m = [None]
cur = 0
for x in xrange(1, 100):
    cur += len(str(bin(x)[2:]))
    needed_for_m.append(cur)

bins = [bin(x)[2:] for x in xrange(0, 100)]

cache = {}
def solve(state, used, maxm, pos):
    key = state, pos
    if key not in cache:
        res = 0

        # already good?
        # print "(%s)" % bin(state)[2:-1], maxm
        if state == (1 << (maxm + 1)) - 1:
            # print "good"
            res += 1

        # continue cuts
        for add in xrange(1, 100):
            if pos + add > len(s):
                break
            val = num[pos][add]
            if val == 0:
                continue

            used2 = used
            if state & (1 << val) == 0:
                used2 += len(bins[val])
            maxm2 = max(maxm, val)
            pos2 = pos + add
            # print "pos", pos, "+", add
            if needed_for_m[maxm2] - used2 <= len(s) - pos2:
                res += solve(state | (1 << val), used2, maxm2, pos2)
        cache[key] = res
    return cache[key]

ans = 0
for i in xrange(len(s)):
    cur = solve(1, 0, 1, i)
    ans += cur
    epr(i, cur, ans)
print ans


rr=raw_input
rrI = lambda: int(rr())
rrM = lambda: map(int,rr().split())
debug=0
if debug:
    fi = open('t.txt','r')
    rr=lambda: fi.readline().replace('\n','')

def good_mask(x):
    if x == 0: return False
    return (x+1) & x == 0

N = rrI()
S = rr()
#N = 75
#from time import time
#S  = '100000111111101000100001011100010111110011111011100011001111101111100011110'
#tt = time()
#print tt

MOD = 10**9 + 7
UPPER = 22

number = [ [0]*(N+1) for _ in xrange(N) ]
for i in xrange(N):
    for j in xrange(i+1, N+1):
        number[i][j] = int(S[i:j],2)

memo = [ [None]*(1<<UPPER) for _ in xrange(N+1)]
def dp(i, mask):
    #Having made a cut already before position i,
    #and having a set of mask taken
    #how many ways?
    if i == N:
        return 1 if good_mask(mask) else 0
    fetch = memo[i][mask]
    if fetch is not None:
        return fetch
    ans = 1 if good_mask(mask) else 0
    for j in xrange(i+1, N+1):
        num = number[i][j]
        if num == 0: continue
        if num >= UPPER: break
        ans += dp(j, mask | (1<<(num-1)))
        if ans >= MOD:
            ans %= MOD
    memo[i][mask] = ans
    return ans

fans = i = 0
while i < N:
    fans += dp(i, 0)
    fans %= MOD
    i += 1
print fans
#print time()-tt

"""
def good_mask(x):
    if x == 0: return False
    return (x+1) & x == 0

N = rrI()
S = rr()
##print '.'
#N = 75
#import random
#S = "".join(str(random.randint(0,1)) for _ in xrange(N))
MOD = 10**9 + 7
UPPER = 22

memoslide = {N : 0, N-1:0}
def slide(j):
    if j in memoslide:
        return memoslide[j]
    if S[j] == '1':
        memoslide[j] = 0
        return 0
    else:
        k = j
        while k < len(S) and S[k] == '0':
            k += 1
        memoslide[j] = k - j
        return k - j

memo = {}
def dp(i, mask):
    #Having made a cut already before position i,
    #and having a set of mask taken
    #how many ways?
    if i == N:
        return 1 if good_mask(mask) else 0
    if (i,mask) in memo:
        return memo[i,mask]
    ans = 1 if good_mask(mask) else 0
    for j in xrange(i+1, N+1):
        num = int(S[i:j], 2)
        if num == 0: continue
        if num >= UPPER: break
        if num > 8:
            #prune
            newmask = mask
            ii = excess = 0
            while newmask:
                if newmask%2 == 0:
                    excess += len(bin(ii)) - 2
                ii += 1
                newmask /= 2
            if excess > N-j+1:
                break
        k = slide(j)
        newmask = mask | (1<<(num-1))
        bns = dp(j + k, newmask)
        for kk in xrange(k):
            memo[(j + kk, newmask)] = bns
        ans += (1+k) * bns

        if ans >= MOD:
            ans %= MOD
    memo[i, mask] = ans
    return ans

fans = 0
for i in xrange(N):
    fans += dp(i, 0)
    if fans >= MOD:
        fans %= MOD
print fans
"""


n,m,k = map(int,raw_input().split());
d = [];
for i in range(1,m+1):
	if m%i == 0:
		if i>=k: d.append(i);
		if len(d)>0 and d[len(d)-1]==m: d.remove(m);
		if m//i >= k: d.append(m//i);
		if len(d)>0 and d[len(d)-1]==m: d.remove(m);
if len(d) == 0:
	print "Marsel";
	exit();
if n%2 == 1:
	print "Timur";
	exit();
print "Marsel";


l1,r1,l2,r2,k = map(int,input().split())
s = set(range(l1,r1+1)).intersection(set(range(l2,r2+1)))
s.discard(k)
print(len(s))


from collections import defaultdict
def primeFactors(n):
    factors = []
    while n%2==0:
        factors.append(2)
        n = n//2

    k = 3
    while k <= math.sqrt(n):
        if n%k==0:
            n= n//k
            factors.append(k)
        else:
            k+=2
    if n>1:
        factors.append(n)
    return factors

n = int(input())
factors = primeFactors(n)
count = defaultdict(int)
for a in factors:
    count[a]+=1
ans = 1
for a in count.values():
    ans*=(a+1)
print(ans)


n,x,y=map(int,input().strip().split()[:3])
if x>=(math.ceil(y*n)/100):
	print(0)
else:
	k=math.ceil((y*n)/100)
	p=k-x
	print(p)


f0 = "What are you doing at the end of the world? Are you busy? Will you save us?"
g0 = "What are you doing while sending \""
g1 = "\"? Are you busy? Will you send \""
g2 = "\"?"
N = 100000 + 10
dp = [0 for i in range(N)]
dp[0] = len(f0)
for i in range(1,N):
    dp[i] = len(g0) + len(g1) + len(g2) + 2 * dp[i-1]

def getAns(x,y):
    if y >= dp[x]:
        return "."
    elif x == 0:
        return f0[y]
    elif y < len(g0):
        return g0[y]
    elif y < len(g0) + dp[x-1]:
        return getAns(x-1,y-len(g0))
    elif y < len(g0) + dp[x-1] + len(g1):
        return g1[y-len(g0)-dp[x-1]]
    elif y < len(g0) + 2*dp[x-1] + len(g1):
        return getAns(x-1,y-len(g0)-len(g1)-dp[x-1])
    else:
        return g2[y-len(g0)-len(g1)-2*dp[x-1]]

n = int(raw_input())
ans = ""
for i in range(n):
    x,y = map(int,raw_input().split())
    ans = ans + getAns(x,y-1)
print(ans)


s=raw_input()
add=int(raw_input())
s1=s.split(":")

#out=(int(s[0]))*60+int(s[1])+int(add)

hour=((add+int(s1[1]))/60+int(s1[0]))%24
mini=(int(s1[1])+add)%60
#print hour,":",mini
if len(str(hour))==1:
    hour="0"+str(hour)
if len(str(mini))==1:
    mini="0"+str(mini)
print hour+":"+mini


import sys

a, b = map(int, sys.stdin.readline().strip().split(' '))
players = ['Ciel','Hanako']

c = {'Ciel': [(2, 2), (1,12), (0,22)], 'Hanako':[(0, 22), (1,12), (2,2)]}

while True:
  player = players.pop(0)
  sum = 0

  for ai, bi in c[player]:
    if ai <= a and bi <= b:
      a -= ai
      b -= bi
      break
  else:
    if player == 'Ciel':
      print 'Hanako'
    else:
      print 'Ciel'
    break


Read = lambda:map(int, input().split())
from functools import reduce

def init():
    g = [[False] * (n + 1) for _ in range(n + 1)]
    for _ in range(m):
        x, y = Read()
        g[x][y] = g[y][x] = True
    return g

def solve():
    color = [0 for _ in range(n+1)]
    g = init()
    for i in range(1, n + 1):
        if reduce(lambda x, y : x and y, g[i][1:i] + g[i][i + 1:]):
            color[i] = 2    # 'b'

    for u in range(1, n + 1):
        if not color[u]:
            color[u] = 1   # 'a'
            for v in range(1, n + 1):
                if u != v and g[u][v] and not color[v]:
                    color[v] = 1
            break

    for i in range(1, n + 1):
        for j in range(1, n + 1):
            if i == j:
                continue
            if g[i][j] and color[i] + color[j] == 1:
                return 'No'
            if not g[i][j] and color[i] == color[j]:
                return 'No'

    def judge(x):
        if x == 1:
            return 'a'
        elif x == 2:
            return 'b'
        else:
            return 'c'
    return 'Yes\n' + ''.join(map(judge, color[1:]))

if __name__ == '__main__':
    while True:
        try:
            n, m = Read()
        except:
            break

        print(solve())


# http://codeforces.com/contest/623/problem/A

import math

nm = raw_input()
nm = nm.split(' ')
n = int(nm[0])
m = int(nm[1])

edges = [[False for i in range(n)] for x in range(n)]   # False: no such edge
nodes = [[True for i in range(3)] for x in range(n)]    # True: possible

# read edges
for i in range(m):
  ab = raw_input()
  ab = ab.split(' ')
  a = int(ab[0]) - 1
  b = int(ab[1]) - 1
  edges[a][b] = True
  #print 'add edge:',a,b

def hasEdge(a,b):
  if edges[a][b] or edges[b][a]:
    return True
  else:
    return False

# True if has deduction
def deduce(n1,n2):
  # if has edge, same
  if hasEdge(n1,n2) and certain(n1):
    val_1 = get(n1)
    # n1 is 'a', n2 isn't 'c'
    if val_1 == 0:
      nodes[n2][2] = False
      #print 'node',n2,'is a'
      return True
    # n1 is 'c', n2 isn't 'a'
    if val_1 == 2:
      nodes[n2][0] = False
      #print 'node',n2,'is a'
      return True
  # if no edge, different
  elif not hasEdge(n1,n2) and certain(n1):
    val_1 = get(n1)
    if val_1 == 0:
      nodes[n2][0] = False
      #print 'node',n2,'is c'
      return True
    if val_1 == 2:
      nodes[n2][2] = False
      #print 'node',n2,'is a'
      return True
  return False

def deductions():
  for i in range(n):
    for j in range(n):
      if i != j:
        deduce(i,j)

# only has one possibility
def certain(k):
  if (nodes[k][0] + nodes[k][1] + nodes[k][2]) == 1:
    return True
  return False

def freeNode(k):
  if (nodes[k][0] + nodes[k][1] + nodes[k][2]) == 3:
    return True
  return False

def isDeadNode(k):
  if (nodes[k][0] + nodes[k][1] + nodes[k][2]) == 0:
    return True
  return False

# get the node first possible node, not certain
def get(k):
  if nodes[k][0]:
    return 0
  if nodes[k][1]:
    return 1
  if nodes[k][2]:
    return 2

def incompleteSolution():
  for k in range(n):
    if not certain(k):
      return k
  return False

def genSolution():
  tmp = incompleteSolution()
  # loop if node id returned
  while isinstance(tmp, int):
    deductions()
    tmp = incompleteSolution()

def printSolution():
  ss = []
  for i in range(n):
    theChar = get(i)
    if theChar == 0:
      theChar = 'a'
    elif theChar == 1:
      theChar = 'b'
    else:
      theChar = 'c'
    ss.append(theChar)
  print ''.join(ss)

# main
# no edge, no b
complete = True
firstMissingEdge = []
for i in range(n):
  for j in range(n):
    if (i != j) and not hasEdge(i,j):
      #print 'no edge: ',i,j
      if complete:
        complete = False
        firstMissingEdge.append(i)
        firstMissingEdge.append(j)
      #print 'missing edge',i,j
      # must not b
      nodes[i][1] = False
      nodes[j][1] = False

# if free node => is b
for i in range(n):
  if freeNode(i):
    nodes[i][0] = False
    nodes[i][2] = False
    #print 'node',i,'is \'b\''

# complete graph
if complete:
  ss = []
  for i in range(n):
    ss.append('b')
  print Yes
  print ''.join(ss)

else:
  # 1. guess one node to be 'a'
  a = firstMissingEdge[0]
  b = firstMissingEdge[1]
  nodes[a][2] = False   # node[a] be 'a'
  nodes[b][0] = False   # node[b] be 'c'
  #print 'let node',a,'be a, node',b,'be c'
  # loop check, deduction...
  updated = True
  hasDeadNode = False
  while updated:
    updated = False
    for i in range(n):
      for j in range(n):
        if i != j:
          if deduce(i,j):
            updated = True
          if isDeadNode(j):
            hasDeadNode = True
            break
      if hasDeadNode:
        break
    if hasDeadNode:
      break

  if hasDeadNode:
    print 'No'
  else:
    print 'Yes'


x,y,z,k=map(int,input().split())
if k=1:
    print (2)
if k=2:
    print (4)
if k=3:
    print (8)
if k>=(x-1)+(y-1)+(z-1):
    print (x*y*z)
else:
    print (4*k-4)


n = int(input())
a = ["","",""]
for i in range(n):
    l = input()
    a[i] = l.split();
    for j in range(6):
        a[i][j] = int(a[i][j])

x = 1;
while(x<=9):
    it = 0
    i = 0
    while i<n:
        j = 0
        while j < 6:
            if a[i][j] == x:
                x = x + 1
                it = 1
                break
            j = j + 1
        if it == 1:
            break
        i = i + 1
    if it == 0:
        break
while ( 9 < x < 100):
    it = 0
    i = 0
    while i < 6:
        j = 0
        while j < 6:
            if n > 0 and a[0][i]*10 + a[1][j] == x:
                x = x + 1
                it = 1
                break
            if n > 0 and a[1][i]*10 + a[0][j] == x:
                x = x + 1
                it = 1
                break
            if n > 1 and a[0][i]*10 + a[2][j] == x:
                x = x + 1
                it = 1
                break
            if n > 1 and a[2][i]*10 + a[0][j] == x:
                x = x + 1
                it = 1
                break
            if n > 1 and a[1][i]*10 + a[2][j] == x:
                x = x + 1
                it = 1
                break
            if n > 1 and a[2][i]*10 + a[1][j] == x:
                x = x + 1
                it = 1
                break
            j = j + 1
        if it==1:
            break
        i = i + 1
    if it == 0:
        break
while ( 99 < x < 1000):
    it = 0
    i = 0
    while i < 6:
        j = 0
        while j < 6:
            k = 0
            while k < 6:
                if n > 1 and a[0][i]*100 + 10*a[1][j] + a[2][k] == x:
                    x = x + 1
                    it = 1
                    break
                k = k + 1
            if it == 1:
                break
            j = j + 1
        if it == 1:
            break
        i = i + 1
    if it == 0:
        break
print (x - 1)


a,b,x,y = [int(x) for x in input().split()]

def gcd(r,s):
    if (r == 0 or s == 0):
        return r+s
    else:
        if r > s:
            return gcd(r-s,s)
        else:
            return gcd(r,s-r)

g = gcd(x,y)
x1 = int(x/g)
y1 = int(y/g)

if (x1 <= a and y1 <=b):
    c = 0
    while (x1*c <= a and y1*c<= b):
        c += 1
    print(x1*(c-1),y1*(c-1))
else:
    print(0,0)


#!/usr/bin/python3

n, a, b, c = [int(x) for x in input().split()]

mn = min(a, b, c)

if n == 1:
	print('0')
elif n == 2:
	print(min(a, b))
else :
	print(min(a, b) + (n-2) * mn)


#cf288b.py
import sys
(n,k)=map(int,sys.stdin.readline().split())
mod_prime=1000000007
f=[0]*k
#f(x)= the number of ways that a group of x elements eventually leads to 1 (1 is not part of the group and does not points to anywhere)
f[0]=1
f[1]=1
c=[[1 for j in range(i+1)] for i in range (k)]
for i in range(1,len(c)):
	for j in range(1,len(c[i])-1):
		c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod_prime
#print (c)
for x in range(2,k):
	f[x]=0
	for i in range(0,x):
		f[x]+=c[x-1][i]*f[i]*f[x-1-i]*(i+1)%mod_prime
		#print("x={0},i={1},f[x]={2}".format(x,i,f[x]))

ans=(k*f[k-1]*(n-k)**(n-k))%mod_prime
#print(f)
print(ans)


from math import sqrt

class vector:
	def __init__(self, _x = 0, _y = 0):
		self.x = _x
		self.y = _y
	def len(self):
		return sqrt(self.x ** 2 + self.y ** 2)
	def len_sq(self):
		return self.x ** 2 + self.y ** 2
	def __mul__(self, other):
		if (type(self) == type(other)):
			return self.x * other.x + self.y * other.y
		return vector(self.x * other, self.y * other)
	def __mod__(self, other):
		return self.x * other.y - self.y * other.x
	def normed(self):
		length = self.len()
		return vector(self.x / length, self.y / length)
	def normate(self):
		self = self.normed()
	def __str__(self):
		return "(" + str(self.x) + ", " + str(self.y) + ")"
	def __add__(self, other):
		return vector(self.x + other.x, self.y + other.y);
	def __sub__(self, other):
		return vector(self.x - other.x, self.y - other.y);
	def __eq__(self, other):
		return self.x == other.x and self.y == other.y
	def rot(self):
		return vector(self.y, -self.x)

class line:
	def __init__(self, a = 0, b = 0, c = 0):
		self.a = a
		self.b = b
		self.c = c
	def intersect(self, other):
		d = self.a * other.b - self.b * other.a
		dx = self.c * other.b - self.b * other.c
		dy = self.a * other.c - self.c * other.a
		return vector(dx / d, dy / d)
	def fake(self, other):
		d = self.a * other.b - self.b * other.a
		return d
	def __str__(self):
		return str(self.a) + "*x + " + str(self.b) + "*y = " + str(self.c)

def line_pt(A, B):
		d = (A - B).rot()
		return line(d.x, d.y, d * A)

class circle:
	def __init__(self, O = vector(0, 0), r = 0):
		self.O = O
		self.r = r
	def intersect(self, other):
		O1 = self.O
		O2 = other.O
		r1 = self.r
		r2 = other.r
		if (O1 == O2):
			return []
		if ((O1 - O2).len_sq() > r1 ** 2 + r2 ** 2 + 2 * r1 * r2):
			return []
		rad_line = line(2 * (O2.x - O1.x), 2 * (O2.y - O1.y), r1 ** 2 - O1.len_sq() - r2 ** 2 + O2.len_sq())
		central = line_pt(O1, O2)
		M = rad_line.intersect(central)
		# print(M)
		if ((O1 - O2).len_sq() == r1 ** 2 + r2 ** 2 + 2 * r1 * r2):
			return [M]
		d = (O2 - O1).normed().rot()
		if (r1 ** 2 - (O1 - M).len_sq() < 0):
			return []
		d = d * (sqrt(r1 ** 2 - (O1 - M).len_sq()))
		return [M + d, M - d]
	def fake(self, other):
		O1 = self.O
		O2 = other.O
		r1 = self.r
		r2 = other.r
		if (O1 == O2):
			return 1
		if ((O1 - O2).len_sq() > r1 ** 2 + r2 ** 2 + 2 * r1 * r2):
			return 1
		rad_line = line(2 * (O2.x - O1.x), 2 * (O2.y - O1.y), r1 ** 2 - O1.len_sq() - r2 ** 2 + O2.len_sq())
		central = line_pt(O1, O2)
		return rad_line.fake(central)

# a = vector(3, 4)
# b = vector(4, 4)
# print(circle(vector(1, 2), 3).intersect(circle(vector(2, 1), 5)))
n = int(input())
arr = []
m = 1
for i in range(n):
	x, y, r = map(int, input().split())
	arr.append(circle(vector(x, y), r))
for i in range(n):
	for j in range(i + 1, n):
		m *= arr[i].fake(arr[j])
for i in range(n):
	arr[i].O = arr[i].O * m
	arr[i].r = arr[i].r * m
# print(m)
s = set()
V = 0
for i in range(n):
	for j in range(i + 1, n):
		tmp = arr[i].intersect(arr[j])
		for e in tmp:
			s.add((round(e.x, 100), round(e.y, 100)))
V += len(s)
E = 0

par = [i for i in range(n)]

def get_par(v):
	if (par[v] != v):
		par[v] = get_par(par[v])
	return par[v]
def unite(v, u):
	par[get_par(v)] = get_par(u)
for i in range(n):
	s = set()
	for j in range(n):
		tmp = arr[i].intersect(arr[j])
		if (len(tmp)):
			unite(i, j)
		for e in tmp:
			s.add((round(e.x, 100), round(e.y, 100)))
	E += len(s)
# print(V, E)
# print(len({get_par(i) for i in range(n)}))
print(E - V + 1 + len({get_par(i) for i in range(n)}))
			unite(i, j)
		for e in tmp:
			s.add((round(e.x, 100), round(e.y, 100)))
	E += len(s)
# print(V, E)
# print(len({get_par(i) for i in range(n)}))
print(E - V + 1 + len({get_par(i) for i in range(n)}))from math import sqrt

class vector:
	def __init__(self, _x = 0, _y = 0):
		self.x = _x
		self.y = _y
	def len(self):
		return sqrt(self.x ** 2 + self.y ** 2)
	def len_sq(self):
		return self.x ** 2 + self.y ** 2
	def __mul__(self, other):
		if (type(self) == type(other)):
			return self.x * other.x + self.y * other.y
		return vector(self.x * other, self.y * other)
	def __mod__(self, other):
		return self.x * other.y - self.y * other.x
	def normed(self):
		length = self.len()
		return vector(self.x / length, self.y / length)
	def normate(self):
		self = self.normed()
	def __str__(self):
		return "(" + str(self.x) + ", " + str(self.y) + ")"
	def __add__(self, other):
		return vector(self.x + other.x, self.y + other.y);
	def __sub__(self, other):
		return vector(self.x - other.x, self.y - other.y);
	def __eq__(self, other):
		return self.x == other.x and self.y == other.y
	def rot(self):
		return vector(self.y, -self.x)

class line:
	def __init__(self, a = 0, b = 0, c = 0):
		self.a = a
		self.b = b
		self.c = c
	def intersect(self, other):
		d = self.a * other.b - self.b * other.a
		dx = self.c * other.b - self.b * other.c
		dy = self.a * other.c - self.c * other.a
		return vector(dx / d, dy / d)
	def fake(self, other):
		d = self.a * other.b - self.b * other.a
		return d
	def __str__(self):
		return str(self.a) + "*x + " + str(self.b) + "*y = " + str(self.c)

def line_pt(A, B):
		d = (A - B).rot()
		return line(d.x, d.y, d * A)

class circle:
	def __init__(self, O = vector(0, 0), r = 0):
		self.O = O
		self.r = r
	def intersect(self, other):
		O1 = self.O
		O2 = other.O
		r1 = self.r
		r2 = other.r
		if (O1 == O2):
			return []
		if ((O1 - O2).len_sq() > r1 ** 2 + r2 ** 2 + 2 * r1 * r2):
			return []
		rad_line = line(2 * (O2.x - O1.x), 2 * (O2.y - O1.y), r1 ** 2 - O1.len_sq() - r2 ** 2 + O2.len_sq())
		central = line_pt(O1, O2)
		M = rad_line.intersect(central)
		# print(M)
		if ((O1 - O2).len_sq() == r1 ** 2 + r2 ** 2 + 2 * r1 * r2):
			return [M]
		d = (O2 - O1).normed().rot()
		if (r1 ** 2 - (O1 - M).len_sq() < 0):
			return []
		d = d * (sqrt(r1 ** 2 - (O1 - M).len_sq()))
		return [M + d, M - d]
	def fake(self, other):
		O1 = self.O
		O2 = other.O
		r1 = self.r
		r2 = other.r
		if (O1 == O2):
			return 1
		if ((O1 - O2).len_sq() > r1 ** 2 + r2 ** 2 + 2 * r1 * r2):
			return 1
		rad_line = line(2 * (O2.x - O1.x), 2 * (O2.y - O1.y), r1 ** 2 - O1.len_sq() - r2 ** 2 + O2.len_sq())
		central = line_pt(O1, O2)
		return rad_line.fake(central)

# a = vector(3, 4)
# b = vector(4, 4)
# print(circle(vector(1, 2), 3).intersect(circle(vector(2, 1), 5)))
n = int(input())
arr = []
m = 1
for i in range(n):
	x, y, r = map(int, input().split())
	arr.append(circle(vector(x, y), r))
for i in range(n):
	for j in range(i + 1, n):
		m *= arr[i].fake(arr[j])
for i in range(n):
	arr[i].O = arr[i].O * m
	arr[i].r = arr[i].r * m
# print(m)
s = set()
V = 0
for i in range(n):
	for j in range(i + 1, n):
		tmp = arr[i].intersect(arr[j])
		for e in tmp:
			s.add((round(e.x, 100), round(e.y, 100)))
V += len(s)
E = 0

par = [i for i in range(n)]

def get_par(v):
	if (par[v] != v):
		par[v] = get_par(par[v])
	return par[v]
def unite(v, u):
	par[get_par(v)] = get_par(u)
for i in range(n):
	s = set()
	for j in range(n):
		tmp = arr[i].intersect(arr[j])
		if (len(tmp)):
			unite(i, j)
		for e in tmp:
			s.add((round(e.x, 100), round(e.y, 100)))
	E += len(s)
# print(V, E)
# print(len({get_par(i) for i in range(n)}))
print(E - V + 1 + len({get_par(i) for i in range(n)}))


from sys import stdin
import functools
import operator

def modpow(n, p, m):
	e = 1
	for i in range(p):
		e = (e * n) % m
		print e

	return e

num = stdin.readline().strip()
new_num = num[0] + num[2] + num[4] + num[3] + num[1]

print(modpow(int(new_num), 5, 10 ** 5))


a,b,m,r0=0,0,0,0
a,b,m,r0=map(int,input().split())
ri=r0
i=0
R=[]
I=[]
while (ri) not in R:
        R.append(ri)
        I.insert(ri,i)
        ri=(a*ri+b)%m
        i+=1
##print(R)
##print(I)
##print (i-R.index(ri))
print (i-I[ri])


import time
a,b,m,r=map(int, raw_input().split())
if a==1:
    time.sleep(0.1)
    print m/b
else:
    Posl=()
    r= (a*r+b)%m
    while not Posl.count(r):
        Posl+=(r,)
        r=(a*r+b)%m
    print len(Posl[Posl.index(r):])


A, B, C = list(map(int, input().split())), list(map(int, input().split())), list(map(int, input().split()))
AB = [B[0] - A[0], B[1] - A[1]]
BC = [C[0] - B[0], C[1] - B[1]]

s = AB[0] * BC[1] - AB[1] * BC[0]
print(['RIGHT', 'TOWARDS', 'LEFT'][1 + int(s > 0) - int(s < 0)]


n, m = map(int, input().split())
l = list(map(int, input().split()))
a= [0] + [0] * n
check = 1
for i in range(m-1):
    if l[i+1] - l[i] <= 0:
        d = l[i+1] + n - l[i]
    else:
        d = l[i+1] - l[i]
    if d in a:
        check = 0
        break
    else:
        a[l[i]] = str(d)
if check == 0:
    print('-1')
else:
    print(' '.join(a[1:]))


from fractions import Fraction

class UnionFind(object):
    def __init__(self, n):
        self.table = [-1 for _ in xrange(n)]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.table[x] >= self.table[y]:
            self.table[y] += self.table[x]
            self.table[x] = y
        else:
            self.table[x] += self.table[y]
            self.table[y] = x

    def find(self, x):
        if self.table[x] < 0:
            return x
        self.table[x] = self.find(self.table[x])
        return self.table[x]

def main():
    N, M = map(int, raw_input().split())
    edges = [map(int, raw_input().split()) for _ in xrange(M)]

    hi = Fraction(10**12)
    lo = Fraction(0)

    for _ in xrange(100):
        mid = (hi + lo) / 2
        edges.sort(key=lambda x:Fraction(x[2], x[3]))
        uf = UnionFind(N)
        nume = 0
        deno = 0
        for e in edges:
            if Fraction(e[2], e[3]) <= mid or uf.find(e[0]) != uf.find(e[1]):
                nume += e[2]
                deno += e[3]
                uf.unite(e[0], e[1])
        if Fraction(nume, deno) <= mid:
            hi = mid
        else:
            lo = mid

    print "%.9f" % hi

if __name__ == '__main__':
    main()


class Solution:

    @staticmethod
    def bookreading(pages , firstday , threshold , addingFactor , gobackPages):
        pages = pages-firstday
        day = 1
        while pages>0:
            pages = pages+gobackPages

            factor = firstday+day*addingFactor
            if factor  <= threshold:
                pages_read = factor
            pages = pages - pages_read

            day += 1

        return day

if __name__ == "__main__":

    c, v0, v1, a , l  = map(int , input().split())

    days = Solution.bookreading(c, v0, v1, a , l)
    print(days)


import sys
sys.setrecursionlimit(20000)

def gcd(a, b):
    if b is 0:
        return a
    else:
        return gcd(b, a % b)

def lcm(a, b):
    return a * b // gcd(a, b)

t, w, b = tuple(int(i) for i in raw_input().strip().split())[:3]

if b <= w:
    w, b = b, w

lc = lcm(w, b)

fits = t // lc

sol = 0

if w <= t:
    sol += w - 1

if fits > 0:
    sol += w * (fits - 1)

    last = fits * lc

    if last + w - 1 <= t:
        sol += w
    elif last <= t:
        sol += t - last + 1

if sol == 0:
    sol = t

up = sol
down = t
g = gcd(up, down)

up //= g
down //= g

print "{}/{}".format(up, down)


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

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

mult = n * inv(m + 1) + 1
mult %= MOD

out = m + 1
for currN in range(1, n):
    out += m * inv(currN)
    out %= MOD

out *= mult
print(out % MOD)


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

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

mult = n * inv(m + 1) + 1
mult %= MOD

currN = 1
out = m + 1
while currN < n:
    currN += 1

    out = (out + m * inv(currN)) % MOD

out *= mult
print(out % MOD)


#include <bits/stdc++.h>
using namespace std;

int main() {

    int n , temp;
    cin >> n;

    int arr[n+1];
    for (int i=0 ; i<n ; i++) cin >> arr[i];
    temp = arr[0] - arr[1];
    for (int i=1 ; i<n-1 ; i++) {
        if(arr[i] - arr[i+1] != temp) {
            cout << arr[n-1];
            return 0;
        }
    }

    cout << arr[n-1] - temp;
    return 0;
}


#!/usr/bin/python
import sys
import math
import fractions
"""
def sieve(n):
    A = [True for i in range(n + 1)]
    for i in range(2, int(math.sqrt(n)) + 1):
        if A[i]:
            for j in range(i * i, n + 1, i):
                A[j] = False
    res = []
    for i in range(2, n + 1):
        if A[i]: res.append(i)
    return res
"""
"""
def factor(n):
    base = sieve(n / 2)
    i = len(base) - 1
    fact = {}
    while n > 1 and i >= 0:
        if n % base[i] == 0:
            n /= base[i]
            if base[i] in fact: fact[base[i]] += 1
            else: fact[base[i]] = 1
        else:
            i -= 1
    start = int(math.sqrt(n))
    pairs = []
    factors = set([1, n])
    for i in range(start,n):
        for j in range(len(base)):
            lhs = i ** 2 % n
            rhs = base[j] ** 2 % n
            if lhs == rhs:
                pairs.append([i,base[j]]);
    for i in range(len(pairs)):
        factors |= set([fractions.gcd(pairs[i][0]-pairs[i][1],n)])
    res = list(factors)
    res.sort()
    return res
"""

def mod_equation(a, b):
    if a < b: return 0
    if a == b: return 'infinity'
    if a - b == 1:
        if a == 1: return 1
        else: return 0
    c = a - b
    res = 0
    for i in range(b + 1, (a + b) / 2 + 1):
        if c % i == 0: res += 1
    if a > 1: res += 1
    return res

    """
    i = 0
    j = len(fact) - 1
    while j - i > 1:
        mid = (i + j) / 2
        if fact[mid] > b: j = mid
        else: i = mid
    return len(fact) - j
    """

if __name__ == '__main__':
    num = sys.stdin.readline().split()
    a = int(num[0])
    b = int(num[1])
    print mod_equation(a, b)

    #print factor(9435152-272)


MONTH=["January", "February", "March", "April", "May", "June",
       "July", "August", "September", "October", "November", "December"]
cmonth=input()
nextmonth=int(input())
print (MONTH[(MONTH.index(cmonth)+nextmonth)%12]


b = int(raw_input())
def sieveOfEratosthenes(N, s):
    # Create a boolean array
    # "prime[0..n]" and initialize
    # all entries in it as false.
    prime = [False] * (N + 1)

    # Initializing smallest factor
    # equal to 2 for all the even
    # numbers
    for i in range(2, N + 1, 2):
        s[i] = 2

    # For odd numbers less then
    # equal to n
    for i in range(3, N + 1, 2):
        if (prime[i] == False):

            # s(i) for a prime is
            # the number itself
            s[i] = i

            # For all multiples of
            # current prime number
            for j in range(i, int(N / i) + 1, 2):
                if (prime[i * j] == False):
                    prime[i * j] = True

                    # i is the smallest
                    # prime factor for
                    # number "i*j".
                    s[i * j] = i

                    # Function to generate prime

# factors and its power
def generatePrimeFactors(N):
    total = 1
    s = [0] * (N + 1)

    sieveOfEratosthenes(N, s)

    curr = s[N]
    cnt = 1

    # Printing prime factors and
    # their powers
    while (N > 1):
        N //= s[N]

        # N is now N/s[N]. If new N
        # als has smallest prime
        # factor as curr, increment
        # power
        if (curr == s[N]):
            cnt += 1
            continue

        total *= (cnt+1)

        # Update current prime factor
        # as s[N] and initializing
        # count as 1.
        curr = s[N]
        cnt = 1
    return total

# Driver Program
print generatePrimeFactors(b)


from itertools import permutations
l=list(permutations(range(0, 5)))
p=[]
m=[]
for _ in range(5):
    m=list(map(int,input().split()))
    p.append(m)
res=0
for i in range(len(l)-1):
    a=l[i][0]
    b=l[i][1]
    c=l[i][2]
    d=l[i][3]
    e=l[i][4]
    r = p[a][b]+p[b][a]+2*(p[c][d]+p[d][c])+p[b][c]+p[c][b]+2*(p[d][e]+p[e][d])
    res=max(r,res)
print(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;
}


s=[raw_input() for i in range(8)]
d=[[16]*8 for i in range(8)]
deep=0;

def res(a):
	print ["LOSE","WIN"][a]
	exit()

def dfs(r,c):
	global deep,d
	d[r][c]=deep;
	deep+=1

	if r==0 and c==7:
		maria=True
		res(True)

	for i1 in [-1,1,0]:
		for i2 in [1 ,-1, 0]:
			if r+i1>=0 and r+i1<=7 and c+i2>=0 and c+i2<=7 and (d[r+i1][c+i2]>=deep or (i1==0 and i2==0)):
				A=True
				for i in range(8):
					if s[i][c+i2]=='S' and (min(i+deep,7)==r+i1 or min(i+deep-1,7)==r+i1):
						A=False
						break

				if A:
					#print "A" , r+i1,c+i2
					dfs(r+i1,c+i2)
					deep-=1

dfs(7,0)
res(False)


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

from itertools import combinations

n = int(raw_input())
rmax = 0
intervals = []
for _ in xrange(n):
    l, r = map(int, raw_input().split())
    rmax = max(rmax, r)
    intervals.append((l, r))

def prob_smaller_equal(ints, val):
    res = 1.0
    for l, r in ints:
        d = min(val + 1 - l, r + 1 - l)
        if d <= 0:
            return 0.0
        res *= float(d) / (r + 1 - l)
        if res == 0.0:
            return 0.0
    return res

def prob_smaller(ints, val):
    res = 1.0
    for l, r in ints:
        d = min(val - l, r + 1 - l)
        if d <= 0:
            return 0.0
        res *= float(d) / (r + 1 - l)
        if res == 0.0:
            return 0.0
    return res

def prob_greater(ints, val):
    res = 1.0
    for l, r in ints:
        d = min(r - val, r + 1 - l)
        if d <= 0:
            return 0.0
        res *= float(d) / (r + 1 - l)
        if res == 0.0:
            return 0.0
    return res

def prob_equal(ints, val):
    res = 1.0
    for l, r in ints:
        if not (l <= val <= r):
            return 0.0
        res *= 1.0 / (r + 1 - l)
    return res

def combos(ints, minn, maxn):
    for ntie in xrange(minn, maxn + 1):
        return combinations(ints, r=ntie)

INTINDS = range(len(intervals))
res = 0
for i_int1 in INTINDS:
    for i_ints2_tie in combos(INTINDS, 1, n - 1):
        if i_int1 in i_ints2_tie:
            continue
        i_other = [i for i in INTINDS if i not in i_ints2_tie and i != i_int1]

        int1 = intervals[i_int1]
        ints2_tie = [intervals[i] for i in i_ints2_tie]
        other = [intervals[i] for i in i_other]

        for price in xrange(1, rmax + 1):
            add = prob_smaller(other, price) * prob_equal(ints2_tie, price) * prob_greater((int1,), price)
            # if add:
                # print int1, " | ", ints2_tie, " : ", "price2", price, "*", add, "=", add * price
            res += add * price

# print

for i_ints1_tie in combos(INTINDS, 2, n):
    i_other = [i for i in INTINDS if i not in i_ints1_tie]

    ints1_tie = [intervals[i] for i in i_ints1_tie]
    other = [intervals[i] for i in i_other]
    for price in xrange(1, rmax + 1):
        add = prob_smaller(other, price) * prob_equal(ints1_tie, price)
        # if add:
            # print ints1_tie, " | ", other, " : ", "price2", price, "*", add, "=", add * price
        res += add * price

print res


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

import sys
import math
from fractions import Fraction, gcd
from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
getcontext().prec = 100

MOD = 10**9 + 7

n, m = map(int, raw_input().split())
ws = map(int, raw_input().split())
bs = [int(x) - 1 for x in raw_input().split()]

stack = []
weights = []
res = 0
for b in bs:
    # print b, stack, ":", res, "->",
    if b in stack:
        ind = stack.index(b)
        weight = sum(weights[ind + 1:])
        del stack[ind]
        del weights[ind]
    else:
        weight = sum(weights)
    stack.append(b)
    weights.append(ws[b])
    res += weight
    # print res, "(", stack, weights, ")"

print res


ins = list(map(int,input().split()))
n = ins[0]
k = ins[1]
ins = input()
for i in range(0,len(ins)):
    if ins[i] == 'G':
        g = i
    if ins[i] == 'T':
        t = i
t = True
if (t-g) % k == 0:
    p = t-g
    if p<0:
        p *= -1

        while and ins[p]!='T'!='T':
            p = p - k
            if ins[p] == '#':
                t = False
    else:
        while p!=0 and ins[p]!='T':
            p = p - k
            if ins[p] == '#':
                t = False
else:
    t = False
if t:
    print('YES')
else:
    print('NO')


s=input()
lis=s.split(" ")
def hcf(a,b):
    if(a%b==0):
        return b
    else:
        hcf(b,a%b)
k=hcf(int(lis[2]),int(lis[3]))
a=int(lis[0])//(int(lis[2])/k)
b=int(lis[1])//(int(lis[3])/k)
print(min(a,b))


n=int(input())
L=[int(i) for i in input().split()]
if L.count(100)=2*(L.count(200)) or (L.count(100)==n and L.count(200)==0 and n%2==0) or (L.count(200)==n and L.count(100)==0 and n%2==0):
    print("YES")
else:
    print("NO")


n = input()
n = int(n)

arr =[0]*(n+1)

day = 0
max =0
# be ezaye har ye voroodi i ke migire :

for i in range (0,n):
    number = input()
    number = int(number)
    day+=1
    arr[number] = day

# for item in arr:
#     print(item)

for i in range(1,n+1):
    if max<arr[i]:
        max=arr[i]
    print(max)


n=int(input(""))
a=input("")
a=[int(x) for x in a.split()]
def bribe(a):
    ans=0
    if a[0]==max(a) and a.count(max(a))!=1:
        ans+=1
    while a[0]+ans<=max(a) and a[0]!=max(a):
        ans+=1
        a[a.index(max(a))]-=1
    return ans
print bribe(a)


n = int(input()) // 2 - 1
a = [i for i in range(1, n + 1)]
i, j = 0, n - 1
c = 0
while i < j:
    if a[i] + a[j] == n + 1:
        c += 1
    i += 1
    j -= 1
print(c)


def binary_search(a, lo=0, hi=None):
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        midval = a[mid]
        if midval > 0:
            lo = mid+1
        elif midval < 0:
            hi = mid
        else:
            return mid
    return lo

def scanl(f, base, l):
    for x in l:
        base = f(base) - x
        yield base

[n,m] = map(int, input().split())
myAdd = lambda a: n if a + m > n else a+m
days = list(scanl(myAdd, n, range(1, n+1)))
print(binary_search(days) + 1)


    a = abs(int(input()))
    b = 0
    while a > 0 or a & 1:
        b += 1
        a -= b
    print(b)


x=int(input());lis=[];sq=0;i=1
while sq<x:
    sq=sq+i
    lis.append(i)
    i+=1
if x==sq:
    print(len(lis))
else:
    x2=sq-x
    sq2=0;i2=1
    while sq2<x2:
        sq2=sq2+i
        lis.append(i2)
        i2+=1
    print(len(lis))


n=int(input()
l = [int(x) for x in input().split()
l.sort()
u = 0
a= 0
while(u<=n)
    a+=1
    c=0
    for i in range(n):
        if(l[i]>=c):
            c+=1
            u+=1
            l[i]= -1
print(a)


n=int(input())
a=list(map(int,input().split()]
for i in range(a):
    if(a[i]>0):
        b+=a[i]
    else:
        c+=a[i]

d=b-c
print(d)


from functools import reduce
n=int(input())
l=list(map(int,input()))
print(reduce(lambda x,y:abs(x)+abs(y) , l)


def determine(arr, poss, seen):
	if seen[arr[0]][arr[1]][arr[2]]:
		return poss[arr[0]][arr[1]][arr[2]]
	else:
		seen[arr[0]][arr[1]][arr[2]] = True
		if arr[0] >= 2:
			a = [arr[0] - 1, arr[1], arr[2]]
			p1 = determine(a, poss, seen)
			for i in range(3):
				if p1[i] == True:
					poss[arr[0]][arr[1]][arr[2]][i] = True
		if arr[1] >= 2:
			a = [arr[0], arr[1]-1, arr[2]]
			p1 = determine(a, poss, seen)
			for i in range(3):
				if p1[i] == True:
					poss[arr[0]][arr[1]][arr[2]][i] = True
		if arr[2] >= 2:
			a = [arr[0], arr[1], arr[2]-1]
			p1 = determine(a, poss, seen)
			for i in range(3):
				if p1[i] == True:
					poss[arr[0]][arr[1]][arr[2]][i] = True
		if arr[0] >= 1 and arr[1] >= 1:
			a = [arr[0] - 1, arr[1]-1, arr[2]+1]
			p1 = determine(a, poss, seen)
			for i in range(3):
				if p1[i] == True:
					poss[arr[0]][arr[1]][arr[2]][i] = True
		if arr[0] >= 1 and arr[2] >= 1:
			a = [arr[0] - 1, arr[1]+1, arr[2]-1]
			p1 = determine(a, poss, seen)
			for i in range(3):
				if p1[i] == True:
					poss[arr[0]][arr[1]][arr[2]][i] = True
		if arr[1] >= 1 and arr[2] >= 1:
			a = [arr[0] + 1, arr[1] - 1, arr[2] - 1]
			p1 = determine(a, poss, seen)
			for i in range(3):
				if p1[i] == True:
					poss[arr[0]][arr[1]][arr[2]][i] = True
		return poss[arr[0]][arr[1]][arr[2]]

a = int(input())
s = input()

arr = [0, 0, 0]

for i in range(len(s)):
	if s[i] == "B":
		arr[0] += 1
	elif s[i] == "G":
		arr[1] += 1
	else:
		arr[2] += 1

b = arr[0]
g = arr[1]
r = arr[2]

seen = [[[False for i in range(r+g+b+1)] for i in range(r+g+b+1)] for i in range(r+g+b+1)]
seen[0][0][0] = True
poss = [[[[False, False, False] for i in range(r+g+b+1)] for i in range(r+g+b+1)] for i in range(r+g+b+1)]
poss[0][0][0] = [False, False, False]

seen[1][0][0] = True
poss[1][0][0][0] = True

seen[0][1][0] = True
poss[0][1][0][1] = True

seen[0][0][1] = True
poss[0][0][1][2] = True
a = determine(arr, poss, seen)

t = ""
if a[0] == True:
	t += "B"
if a[1] == True:
	t += "G"
if a[2] == True:
	t += "R"

print(t)


a, b, c = map(int, input().split(' '))
mod = 998244353

def calc (a, b) :
	if a > b:
		a, b = b, a
	ans = 0
	tmp = 1
	for i in range(a + 1):
		ans = (ans + tmp) % mod
		tmp = tmp * (a - i) * (b - i) * pow(i + 1, mod - 2, mod) % mod
	return ans

ans = calc(a, b) * calc(b, c) * calc(a, c) % p

print(ans)


#!/usr/bin/python3

n , m = list( map( int , input().split() ) )

n = min( n , 7 ** 7 )
m = min( m , 7 ** 7 )

def f( hour , minutes , l ):
	if len( l ) == 0:
		return 1
	res = 0
	for i in l:
		lp = [ x for x in l if x != i ]
		h = hour * 10 + i
		if( h < n ) res += f( h , minutes , lp )
		mi = minutes * 10 + i
		if( m < mi ) res += f( hour , mi , lp )
	return res

print( f( 0 , 0 , range( 7 ) ) )


#include <iostream>

using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 1;
	while(n / ans + b / ans >= n)
	return 0;
}


from math import sqrt

def issquare(apositiveint):
  x = apositiveint // 2
  seen = set([x])
  while x * x != apositiveint:
    x = (x + (apositiveint // x)) // 2
    if x in seen: return False
    seen.add(x)
  return True

def main():
	n = input()

	if(n == 1):
		print 1

	else:
		div = []

		ranges = range(1, int(sqrt(n))+1)
		ranges.sort(reverse = True)

		for i in ranges:
			if(n % i == 0 and (i not in div) and (n/i not in div)):
				if(i > 1):
					div.append(i)
				if(n/i > 1):
					div.append(n/i)
		div.sort(reverse = True)
		condition = 0
		#print div
		#print int(sqrt(div[0]) + 1)

		for i in div:
			condition = 0
			reqd_range = range(len(div))

			if(i not in reqd_range):
				reqd_range.append(i)

			for j in reqd_range:
				if(i % div[j] == 0):
					#print j, issquare(j)
					if(issquare(div[j])):
						condition = 1
						break

			if(condition == 0):
				print i
				break

main()


n = int(raw_input())
count = [0] * 10
for idx in range(1, n+1):
    count[idx%9] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += count[i] * count[j] * count[i*j%9]

for i in range(1, n+1):
    for j in range(i, n+1, i):
        ans -= 1

print ans


def main():
    ans = 0
    a = [0] * 10
    n = int(input())
    for i in range (1, 9):
        a[i] = n // 9 + int(n % 9 >= i)
    a[9] = n // 9

    for i in range(1, 10):
        for j in range(1, 10):
            k = i * j % 9
            if k == 0:
                k = 9
            ans += a[i] * a[j] * a[k]

    for i in range(1, n):
        ans -= n // i
    print(ans)

    return

if __name__ == "__main__":
    main()


t=['']
for _ in range(10):
  u = ['4'+s for s in t] + ['7'+s for s in t]
  t += u
t = map(int,t)
t.sort()
l,r=map(int,raw_input().split())
first = True
for i in range(2**10):
  if l<=t[i]:
    rr = min(t[i],r)
    res += t[i]*(rr-l+1)
    l = t[i]+1
  if t[i]>=r:
    break
print res


def s(a,b,c):
    l = []
    for i in range(1,82):
        v = b*i**a+c
        if v > 1000000000:
            break
        vcopy = v
        val = 0
        while v > 0:
            val += v%10
            v//=10
        if val == i:
            l.append(vcopy)
    print(len(l))
    for i in l:
        print(i,end=' ')

a,b,c = map(int, input().spli


from math import *
from Queue import *
from sys import *
from datetime import *

nMax, hMax = map(int, raw_input().split())
table = [[0 for j in range(nMax+1)] for i in range(nMax+1)]
table[0][0] = 1
for i in range(1, nMax+1):
    table[i][i] = 2**(i-1)
for h in range(1, nMax+1):
    for n in range(h+1, nMax+1):
        for i in range(1,n+1):
            for j in range(h):
                table[n][h] += table[i-1][h-1]*table[n-i][j]
            for j in range(h):
                table[n][h] += table[i-1][j]*table[n-i][h-1]
            table[n][h] -= table[i-1][h-1]*table[n-i][h-1]
res = 0
for h in range(hMax, n+1):
    res += table[n][h]
print(res)


n = int(input(""))
if n % 2 == 0:
    print 2
else:
    print 1


s = raw_input()
k = raw_input()

sm = len(s) + k
mx = sm if sm % 2 == 0 else sm - 1
# cntr = mx / 2
ddone = False
while mx > 0:
    strt = 0
    cntr = mx / 2
    while strt + mx <= sm:
        step = strt + cntr
        for i in range(strt, strt + step):
            j = i + step
            if i < len(s):
                if j < len(s):
                    if s[i] == s[j]:
                        pass  # great
                    else:  # s[i] != s[j]
                        break
                else:  # j > len(s)
                    pass  # we can add here what we want
            ddone = True
        strt += 1
    if ddone:
        print mx
        break
    mx -= 2
    # cntr /= 2


N, L, R, X = map(int, raw_input().split())
C = map(int, raw_input().split())
Ans = 0

for Cf in range(1, 1 << N):
	V = [C[i] for i in range(N) if Cf & (1 << i) > 0]
	if max(V) - min(V) >= X and L <= sum(V) and sum(V) <= R:
		Ans += 1

print Ans


import math
x, y = raw_input().split(" ")
x = int(x)
y = int(y)

k = math.log(y) + math.log(math.log(x))
l = math.log(x) + math.log(math.log(y))

if (k > l):
	print(">")
if (k < l):
	print("<")
if (k == l):
	print("=")


import math,sys
import heapq
from fractions import Fraction
from collections import Counter,defaultdict
def li(): return list(map(int,sys.stdin.readline().split()))
def ls(): return list(map(int,list(input())))
def la(): return list(input())
def ii():  return int(input())
def dic(x): return defaultdict(lambda: x)
def isPrime(n):
    i= 2
    if n == 1:
        return False
    while i <= int(math.sqrt(n)):
        if n%i == 0:
            return False
        i = i + 1
    return True
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def binarySearch(arr, x):
    l,r = 0,len(arr)-1
    while l <= r:
        mid = l + (r - l) // 2;
        if arr[mid] == x:
            return True
        elif arr[mid] < x:
            l = mid + 1
        else:
            r = mid - 1
    return False
minn = float("inf")
x ,y ,n= li()
for i in range(1,n):
    if abs(Fraction(x,y)-Fraction(x,y).limit_denominator(i)) <minn :
        minn = abs(Fraction(x,y)-Fraction(x,y).limit_denominator(i))
        ans = Fraction(x,y).limit_denominator(i)
print(ans)


s=input()
count=s.count('VK')
if('VVV' in s or 'KKK' in s or 'VV' in s):
	count = count +1
if(s.index('VV')==s.index('VVK')
	count=count-1
print(count)


n = int( input() )
a = int( input() )
b = int( input() )
a -= 1
a += b
while a < 0:
	a += n
print(a % n + 1)


n,k=input().split()
n,k=int(n),int(k)
a=list(map(int,input().split()))
p=(2*k-1)*n-2*sum(a)
if p<0:
    print(0)
else
    print(p)


n=int(input())
x=list(map(int,input().split()))
g=sum(x)
r=[]
for a in range(1,6):
    if (g+a)%(n+1)!=1:
        r.append(a)
print(len(r)


def q16b():
	n, m = tuple([int(num) for num in input().split()])
	boxes = []
	for _ in range(m):
		a, b = tuple([int(num) for num in input().split()])
		boxes = boxes + [b for _ in range(a)]
	boxes.sort()
	boxes.reverse()
	print(sum(boxes[:n]))

q16b()


s=input().strip().lower()
def check(s):
    vowels=['a','e,'i','o','u']
    ans=True
    i=0
    while i<len(s):
        x=s[i]
        if not(x in vowels):
            if x!='n':
                if (i+1)==len(s):
                    ans=False
                    break
                else:
                    if not(s[i+1] in vowels):
                        ans=False
                        break
        i=i+1
    return ans
print(check(s))


k,a,b,v=map(int,input().split())
box=0
rem=a
while rem>0:
    box+=1
    comp=0
    if (b>k-1):
        comp=k
        b-=k-1
    else:
        comp=b+1
        b=0
    rem-=v*comp
print box


p,m,x=map(int,input ().split ())
if abs(p-m)==x:
   print ('0')
elif abs(p-m)<x:
   print('?')
elif p>m:
   print ('+')
else:
   print ('-'


read = lambda: map(int, input().split())
n, k = read()
a = list(read())


import math

# CRIVO
m = 10 ** 6 + 10
eh_primo = [True] * m
eh_primo[0] = False
eh_primo[1] = False

for i in xrange(int(math.sqrt(m))):

    if eh_primo[i]:
        for j in xrange(i * i, m, i):
            eh_primo[j] = False

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

n = int(raw_input())

a = int(math.sqrt(n))
b = int(math.sqrt(n))

if eh_primo[n]:
    print 1,n

elif a * b == n:
    print a, b

else:

    while a > 0 and a * b < n:
        a = a - 1

    if a * b != n:

        a = int(math.sqrt(n))
        while a * b < n:
            if a * (b+1) > n:
                a = a - 1
            else:
                b = b + 1

    print a, b


# by the authority of GOD     author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase
from collections import Counter

def main():
    mod = 10**9+7
    r,g = map(int,input().split())
    n = 1
    while r+g >= (n*(n+1))//2:
        n += 1
    n -= 1
    tot = n*(n+1)//2
    dp = [0]*(tot+1)
    dp[0] = 1
    for i in range(1,n+1):
        for x in range(tot-i,-1,-1):
            dp[i+x] += dp[x]
            dp[i+x] %= mod
    ans = 0
    for i,val in enumerate(dp):
        if i <= r and tot-i <= g:
            ans += val
            ans %= mod
    print(ans)

#Fast IO Region
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")

if __name__ == '__main__':
    main()


a = input()
b = input()
c = input()
d = input()
e = input()
f = input()
ans = (a+d) * (b + c) + e * f + b * c
print ans


from itertools import repeat
k = {'s':'Sheldon' , 'l' : 'Leonard' , 'p' :'Penny' , 'r' : "Rajesh" , 'h' :'Howard'}
h = ""
i = 1
st = "slprh"
j = 0
while( i <= 10**9):
    h += st[0]*2**j
    h += st[1]*2**j
    h += st[2]*2**j
    h += st[3]*2**j
    h += st[4]*2**j
    i += 5*(2**j)
    j += 1
    print(i)
g  = int(input())
print( k[h[g-1]])


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

def change():
    global n , m
    n -= 2
    m -= 2
    n = max(n , 0)
    m = max(m , 0)

def calc(n , m):
    ret = 0
    for i in range(0 , n):
        for j in range(0 , m):
            if (i + j) % 2 == 0:
                ret += 1
    return ret

for i in range(1 , x):
    change()
ans = calc(n , m)
change()
ans -= calc(n , m)
print(ans)


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

s = 0
for i in xrange(n):
    if a[i] == 1:
        s += 1
    elif a[i] == 0 and (i > 0 and i + 1 < n and a[i-1] == 1 and a[i+1] == 1):
        s += 1

print s


X, Students = list(map(int, input().split())), list(map(int, input().split()))
for i in range(X[0]):
    Count, Temp, Sum = 0, X[1], sum(Students[:i]) + Students[i]
    if Sum <= X[1]:print(0, end=" ")continue
    else:
        STemp = sorted(Students[:i], reverse=True)
        for j in range(i):
            if X[1] >= Sum:break
            Count, Sum = Count + 1, Sum - STemp[j]
    print(Count, end=" ")

# Come together for getting better !!!!


#include<bits/stdc++.h>
using namespace std;
int n,m;
int fail(int limit,int ar[])
{
    int i;
    int sum=0;
  sort(ar,ar+n);
  for(i=limit;i>=0;i++)
  {
      sum=sum+ar[i];
     if(sum<=n)
        break;
  }
  return i;

}
int main()
{
   int sum=0;
    cin>>n>>m;
    int ar[n],ar1[n];
    for(int i=0;i<n;i++){
        cin>>ar[i];
        ar1[i]=ar[i];
    }
    for(int i=0;i<n;i++)
    {
       // int ar1[i]=
        sum=sum+ar[i];
      if(sum<=m)
            cout<<0<<" ";
      else
      {
         cout<<fail(i-1,ar1)<<" ";
      }
    }
}


class Primos:

    def __init__(self, MAX):
        self.Max=MAX
        self.primos=[True]*(MAX+1)
        self.ListPrimes=[]

        for i in xrange(2,int(MAX**0.5)+1):
            if self.primos[i]:
                for j in xrange(i*i,self.Max+1,i):
                    self.primos[j]=False
        #Listing primes

        for p in range(2,MAX+1):
            if self.primos[p]: self.ListPrimes.append(p)

    def esPri(self,n):
        return self.primos[n]

    def Primorial(self, N):
    	pri=1
    	for i in xrange(N):
    		pri*=self.getPrimesList()[i]
    	return pri

    def PrimeFactors(self, N):
    	d={}
    	for i in xrange(2, N/2+1):
    		if self.esPri(i) and N%i is 0:
    			p=0
    			while (N%(i**p) is 0): p+=1
    			d[i]=p-1
    	return d

    def getPrimesList(self):
        return tuple(self.ListPrimes)

P=Primos(3000)

def F(N):
	global P

	if P.esPri(N): return 2**(N-1)

	res, pi=1,0
	L=P.getPrimesList()

	F= P.PrimeFactors(N)
	Fs=sorted(F, reverse=1)

	for p in Fs:
		for pot in xrange(F[p]):
			res*=L[pi]**(p-1)
			pi+=1
	return res

for i in xrange(input()): print F(int(raw_input().replace(" ","")))


k = int(input());l = int(input());m = int(input());n = int(input());d = int(input())
res = d
if k == 1 and m == 1 and l == 1 and n == 1:
    print(d)
else:
    for i in range(1,d):
        if (i%k != 0) and (i%l != 0) and (i%m != 0) and (i%n != 0):
            res -= 1
    print(res)


import sys
import getopt

def main(road):

    cur = 1
    max=1
    for s in road:
        if s in set(['A', 'E', 'I', 'O', 'U', 'Y']):
            if cur > max:
                max = cur
            cur = 1
        else:
            cur += 1
    if cur > max:
        max = cur

    return max

if __name__ == "__main__":
    road = sys.argv[1]
    print main(road)


import math
def main(fl=math.floor):
    m = int(raw_input())
    lo, hi = 0, 5.0 * (10 ** 15)
    g = [1, 1] + [i ** 3.0 for i in xrange(2, 180000)]
    def f(n):
        return sum(fl(n / g[i])  for i in xrange(2, int(n ** (1.0 / 3)) + 2))
    while lo + 1 < hi:
        mid = (lo + hi) / 2
        if f(mid) < m:
            lo = mid
        else:
            hi = mid
    gi = [1, 1] + [i ** 3 for i in xrange(2, 180000)]
    def fi(n):
        return sum(n / gi[i] for i in xrange(2, int(n ** (1.0 / 3)) + 2))
    x = int(round(hi))
    print x if fi(x) == m else -1
main()


n = int(input())
be, en, ans = 8, 10 ** 16, float('inf')
all = [x * x * x for x in range(2, 170416)]

while be <= en:
    cur, md, k = 0, (be + en) >> 1, 0

    while all[k] <= md:
        cur += md // all[k]
        k += 1

    if cur < n:
        be = md + 1
    else:
        if cur == n:
            ans = min(ans, md)
        en = md - 1
    # print(cur,ans,md)

print(-1 if ans == float('inf') else ans)


p,y = map(int,input().split())
for x in range(y,p,-1):
	if all(x%i for i in range(2,min(int(x**.5),p+1)):
		#even if one devides it completely then not possible to sit
		#if nothing devides then it's sitable
		#factors repeat after reachin midway(sqrt)
		print(x)
		exit()
print(-1)


n, m = [int(i) for i in input().split()]
a = 1
k = 0
while (k < n and a <= m):
    a *= 2
    k += 1

if (a > m):
    print(m)
else:
    print(m % a)


# -*- coding: utf-8 -*-
"""
Spyder Editor

Este é um arquivo de script temporário.
"""

"""
Solution to coin-exchange problem, in which 2 parameters are given:
    - amount of money
    - array of coin values
"""

def solveCombinations(amount, coins):
    comb = [0] * (amount+1)
    comb[0] = 1
    for c in coins:
        for i, val in enumerate(comb):
            if i >= c:
                comb[i] += comb[i - c]
    return comb[-1]

def solveMinCoins(amount, coins):
    minNum = [amount+1] * (amount+1)
    minNum[0] = 0   # sem moedas para 0 dinheiros
    # print(minNum)
    for i in range(1, amount+1):
        for c in coins:
            if c <= i:
                minNum[i] = min(minNum[i - c] + 1, minNum[i])
                # print(minNum)
            else:
                break
    # print(minNum)
    return minNum[-1]

coin, amount = map(int, input().split())

print(solveMinCoins(amount , range( 1, coin+1 ) ))


class Square():
    point1 = []
    point2 = []
    number = 0

    def GenerateCords(self, a, x):
        self.number = x
        if x == 1:
            self.point1 = [(-a/2), 0]
        elif x%3 == 2:
            self.point1 = [(-a/2),((((x//3)*2)+1)*a)]
        elif x%3 == 0:
            self.point1 = [-a,(((((x//3)-1)*2)+2)*a)]
        else:
            self.point1 = [0,(((((x//3)-1)*2)+2)*a)]

        self.point2 = [(self.point1[0]+a),(self.point1[1]+a)]

    def CheckIfIn(self, x, y):
        if x < self.point1[0]+1 or x => self.point2[0]:
            return -1
        if y < self.point1[1]+1 or y => self.point2[1]:
            return -1
        else:
            return self.number

a,x,y = map(int, input().split())

row = y//a + 1

if row == 1:
    test = Square()
    test.GenerateCords(a, row)
elif (row - 1)%2 == 1:
    test = Square()
    test.GenerateCords(a, ((((row-1)//2)*3)+2))
else:
    if x <= 0:
        test = Square()
        test.GenerateCords(a, (row//2)*3)
    else:
        test = Square()
        test.GenerateCords(a, ((row//2)*3)+1)

print(test.CheckIfIn(x,y))


entrada = list(map(int,input().split(' ')))
l = entrada[0]
x = entrada[1]
y = entrada[2]

ok = True

res = 1

ax = True

if y >= l:
	y -= l
	res = 2

while(y >= l):
	if ax:
		res += 1
	else:
		res += 2
	ax = not ax

	y -= l

if y == 0:
	ok = False
if not ax:
	if x <= -l or x >= l or x == 0:
		ok = 0
	if x > 0:
		res += 1
else:
	if x => (l/2) or x <= -(l/2):
		ok = 0

if ok:
	print(res)
else:
	print(-1)


n = int(input())
ans = 0
m = 1
while n>0:
    k = n%10
    n = n/10
    if k == 4:
        ans = ans + m * 1
    elif k == 7:
        ans = ans + m * 2
    m = m * 2
print ans


n = int(input())
a = input().split()
b= a.count("100")
if b > 0 and b%2 == 0:
    print("YES")
b= a.count("200")
elif b%2 == 0 and b>0:
    print("YES")
else:
    print("NO")


ri = lambda: raw_input().strip()

#n = int(ri())
x, y = map(int, ri().split())

if abs(x) <= 1 and abs(y) <= 1:
    if (x == 0 and y == 0) or (x == 1 and y == 0):
        print 0

    elif x == 1 and y == 1:
        print 1

    elif y == 1:
        print 2

    elif x == -1:
        print 3

else:
    ans = 0
    if abs(x) > abs(y):
        ans = (abs(x) - 1) * 4
    else:
        ans = (abs(y) - 1) * 4

    if x > 0 and abs(y) <= abs(x):
        if x != -(y+1):
            ans += 1
            if (-y == x):
                ans += 3;

    elif y > 0 and abs(x) <= abs(y):
        ans += 2

    elif x < 0 and ans(x) >= abs(y):
        ans += 3

    else:
        ans += 4

    print ans


import math

nbr=int(input())
s=int(math.sqrt(2*n))
if n==r*(r+1)/2 or n==(r+1)*(r+2)/2:
    print("YES")
else:
    print("NO")


n = input().split(' ')
day = int(n[0])
ident = n[2]

elif ident == "week":
    if day > 6:
        print(51)
    else:
        print(52)
else:
    if day <30:
        print(12)
    elif day == 30:
        print(11)
    else:
        print(7)


import itertools as it
import operator as op

nums = list(map(int, input().split()))
n = nums[0]
nums = sorted(set(nums[1:]), reverse=True)
uniq_count = map(lambda x: range(n // x + 1), nums)

for t in sorted(it.product(*uniq_count), key=sum, reverse=True):
    if sum(map(op.mul, nums, t)) == n:
        print(sum(t))
        break


#include<bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
	string a, b; cin >> a >> b;
	int num1 = 0, num2 = 0;
	for (int i = 0; i < a.size(); i++) num1 += ((int)a[i] - 48) * pow(10, a.size() - i - 1);
	for (int i = 0; i < b.size(); i++) num2 += ((int)b[i] - 48) * pow(10, b.size() - i - 1);
	if (num1 > 99) num1++;
	if (num2 > 99) num2++;
	int sum = num1 + num2;
	for (int i = 0; i < a.size(); i++) if (a[i] == '0') a.erase(a.begin() + i);
	for (int i = 0; i < b.size(); i++) if (b[i] == '0') b.erase(b.begin() + i);
	num1 = 0, num2 = 0;
	for (int i = 0; i < a.size(); i++) num1 += ((int)a[i] - 48) * pow(10, a.size() - i - 1);
	for (int i = 0; i < b.size(); i++) num2 += ((int)b[i] - 48) * pow(10, b.size() - i - 1);
	stringstream os;
	os << sum;
	string s;
	os >> s;
	for (int i = 0; i < s.size(); i++) if (s[i] == '0') s.erase(s.begin() + i);
	sum = 0;
	for (int i = 0; i < s.size(); i++) sum += ((int)s[i] - 48) * pow(10, s.size() - i - 1);
	if (num1 + num2 == sum) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


import collections
import math
def primefactors(n):
	d = collections.defaultdict(int)
	while n%2 == 0:
		d[2]+=1
		n/=2
	for i in range(3, int(n**0.5)+1, 2):
		while n%i==0:
			d[i]+=1
			n/=i
	if n > 2:
		d[n]+=1
	return d
n = int(input())
x = primefactors(n)
y = max(x.values())
z = x.keys()
k = 1
for i in z:
	k*=i
if int(k) = n:
	print(int(k), 0)
else:
	print(int(k), math.ceil(math.log(y, 2))+1)


n = input()
n = int(n)
count = 0
for i in range(1,n+1):
    s = str(i)
    if('2' in s or '3' in s or '4' in s or '5' in s or '6' in s or '7' in s or '8' in s or '9' in s):
        continue
    else:
        count += 1
print count


P = str(input())
Resp = 'NO'
k = len(P)
b = 0
while(b<k):
  if P[b]=='H' or P[b]=='Q' or P[b]=='9'
    Resp='YES'
    pass
b=b+1