import sys
a = (input())
A = a.split(' ')
twod_list = []

for i in A:
    twod_list.append(int(i))

Array =["baabcac","aabcacb","abcacba","bcacbaa","cacbaab","acbaabc","cbaabca"]

Maxx = 0
Minn = 0

a= twod_list[0]
b=twod_list[1]
c=twod_list[2]
AllDayys = 0
Factor = 0
Factor1 = sys.maxsize
Factor2 = sys.maxsize
Factor3 = sys.maxsize
if a >=3 and b >=2 and c >=2:
    Minn = min(a,min(b,c))
    Factor1 = (int)(a /3)
    Factor2 = (int)(b /2)
    Factor3 = (int)(c /2)

    Factor = min(Factor1,min(Factor2,Factor3))
    #print(Factor)
    twod_list[0] = twod_list[0] - (3 * Factor)
    twod_list[1] = twod_list[1] - (2 * Factor)
    twod_list[2] = twod_list[2] - (2 * Factor)
    AllDayys = (Factor*7)

for i in range(7):
    a= twod_list[0]
    b=twod_list[1]
    c=twod_list[2]
    Counter = 0
    for j in range (7):
        #print(Array[i][j],end=" ")
        if Array[i][j]=='a':
            if a > 0:
                a= a -1
                Counter = Counter + 1
            else :
                break
        elif Array[i][j]=='b':
            if b > 0:
                b= b -1
                Counter = Counter + 1
            else :
                break
        elif Array[i][j]=='c':
            if c > 0:
                c= c -1
                Counter = Counter + 1
            else :
                break
        Maxx = max(Maxx,Counter)

print(Maxx+AllDayys)


from sys import stdin
x,y,n = stdin.readline().split()
x=int(x)
y=int(y)
n = int(n)
if x<0:
 x = -x
if y<0:
 y = -y
valid = 1
if x+y>n:
 valid = 0
elif (n-x-y)%2:
 valid = 0
if valid:
 print "YES"
else:
 print "NO"


def func(x,limit):
    while True:
        if(x < 0):
            x = -x
        elif (x > limit):
            x = 2.0*limit - x
        else:
            return x
text = raw_input()
a,b,m = map(int,text.split())
text = raw_input()
vx,vy,vz = map(int,text.split())
dx = a/2.0 + (m*1.0/-vy)*vx
dz = (m*1.0/-vy)*vz
dx = func(dx,a)
dz = func(dz,b)
print "%.6f %.6f" % (dx,dz)


n = int(input())
s = input()

print("1" * min(1, s.count('1')) + "0" * s.count('0'))


import math

def total_lines(initial, factor):
    lines = 0
    while initial > 0:
        lines += initial
        initial //= factor
    return lines

n, k = input().split()

n = int(n)
k = int(k)

guess = 0
interval = 10 ** 9 // 2
leeway = math.ceil(math.log(10 ** 9, k))
while True:
    current_max = total_lines(guess, k)
    if n <= current_max <= n + 30:
        for guess in range(guess - 1, -1, -1):
            if total_lines(guess, k) < n:
                guess += 1
                break
        break
    elif current_max < n:
        guess += interval
    else:
        guess -= interval
    interval, remainder = divmod(interval, 2)
    interval += remainder != 0

print(guess)


from sys import stdin,stdout,setrecursionlimit,maxint,exit
#setrecursionlimit(10**4)
def listInput():
 return map(long,stdin.readline().split())
def printBS(li):
 for i in xrange(len(li)-1):
  stdout.write("%d "%li[i])
 stdout.write("%d\n"%li[-1])
def sin():
 return stdin.readline().rstrip()
memo1={}
memo2={}
def dpmax(n,lim,s,no):
 if n==1:
  if 0<=s<=9:
   no.append(str(s))
   return True
  else: return False
 if (n,s) in memo1:
  #print "memo1 used"
  if memo1[n,s][0]:
   no.clear()
   no.extend(memo1[n,s][1])
  return memo1[n,s][0]
 for i in xrange(9,(0 if lim==n else -1),-1):
  no.append(str(i))
  if dpmax(n-1,lim,s-i,no):
   memo1[n,s]=[True,list(no)]
   return True
  else: no.pop()
 memo1[n,s]=[False,[]]
 return False
def dpmin(n,lim,s,no):
 if n==1:
  if 0<=s<=9:
   no.append(str(s))
   return True
  else: return False
 if (n,s) in memo2:
  if memo2[n,s][0]:
   no.clear()
   no.extend(memo2[n,s][1])
  return memo2[n,s][0]
 for i in xrange((1 if n==lim else 0),10):
  no.append(str(i))
  if dpmin(n-1,lim,s-i,no):
   memo2[n,s]=[True,list(no)]
   return True
  else: no.pop()
 memo2[n,s]=[False,[]]
 return False
n,s=listInput()
ma=[]
mi=[]
if dpmax(n,n,s,ma) and dpmin(n,n,s,mi):
 print "".join(mi),"".join(ma)
else: print -1,-1


from math import ceil

t=int(input())
def isprime(x):
    for i in range(2,ceil(x**.5)+1):
        if x%i==0:
            return False
    return True

for i in range(t):
    x,y=map(int,input().split())
    if x-y!=1:
        print('NO')
        continue
    else:
        if isprime(x+y):
            print('YES')
        else:
            print('NO')


s = input()
a = ['ABC', 'ACB', 'BAC', 'BCA', 'CAB', 'CBA']
print (['No', 'Yes'][any(i in s for i in a)])


import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().rstrip().split())
inl = lambda: list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))

n, m = inm()
print(min(min(n, m), (n+m) // 3))


import sys as system_break
def Commonfinder(n,m):
    if type(n)!=set:
        n={n}
    if type(m)!=set:
        m={m}
    Common_in_both=n|m
    return Common_in_both
import math as m
import re as MATCHING_DEVICE
Input= input()
Input= Input.split()
ablist =[]
for i  in  range(len(Input)):
    ablist.append( int( Input[i] ))
a=ablist[0];b=ablist[1]
Binofa=bin(a)[2:]
Binofb=bin(b)[2:]
Extended_A=Binofa+'1'
Striped_A=Binofa.rstrip('0')
FirstCF=Commonfinder(Extended_A,Striped_A)
SecondCF=Commonfinder(FirstCF,Extended_A[::-1])
FinalCF=Commonfinder(SecondCF,Striped_A[::-1])
Formated_Str=f'1*({Extended_A}|{Striped_A}|{Extended_A[::-1]}|{Striped_A[::-1]})1*'
if len(FinalCF)==1:
    FinalCF=list(FinalCF)
    FinalCF=FinalCF[0]
    if (MATCHING_DEVICE.fullmatch(FinalCF,Binofb)) or Binofa ==Binofb:
        print('YES')
else:
    answer=''
    #FinalCF=list(FinalCF)
    if a==b or MATCHING_DEVICE.fullmatch(Formated_Str, Binofb):
            print('YES')
    else:
        print('NO')


# Help Vasilisa the Wise 2

import itertools

def calculate(r1, r2, c1, c2, d1, d2):
    combinations = list(itertools.permutations([i for i in range(1,10)], 4))
    for (x1, x2, x3, x4) in combinations:
        r1_sum = x1 + x2
        r2_sum = x3 + x4
        c1_sum = x1 + x3
        c2_sum = x2 + x4
        d1_sum = x1 + x4
        d2_sum = x2 + x3

        if (r1_sum == r1 and r2_sum == r2 and c1_sum == c1 and c2_sum == c2 and d1_sum == d1 and d2_sum == d2):
            print(str(x1) + " " + str(x2))
            print(str(x3) + " " + str(x4))
            return
    print(-1)

if __name__ == "__main__":
    r1, r2 = list(map(lambda x: int(x), input().split()))
    c1, c2 = list(map(lambda x: int(x), input().split()))
    d1, d2 = list(map(lambda x: int(x), input().split()))
    calculate(r1, r2, c1, c2, d1, d2)


__author__ = 'neki'

import sys

#sys.stdin = open("friendsPresents.in", "r")
#sys.stdout = open("friendsPresents.out", "w")

words = input().split()
cnt1 = int(words[0])
cnt2 = int(words[1])
x = int(words[2])
y = int(words[3])
#print(cnt1, cnt2, x, y)

def determine(num, x, y, cnt1, cnt2):
    like1 = num - num // x
    like2 = num - num // y
    like1and2 = like1 + like2 - num + num // (x*y)
    #print(like1, like2, like1and2)

    friend1 = like1 - like1and2
    friend2 = like2 - like1and2
    both = like1and2
    #print(num, friend1, friend2, both)

    cond1 = 0
    cond2 = 0
    if friend1 + both >= cnt1 and friend2 + both >= cnt2:
        cond1 += 1
    if friend1 + friend2 + both >= cnt1 + cnt2:
        cond2 += 1
    if cond1 > 0 and cond2 > 0:
        return 1
    return 0

lim = 0
lim1 = 1
lim2 = -1
while 1:
    if lim2 < 0:
        lim = lim1 * 2
    else:
        lim = (lim1 + lim2) // 2
    if lim == lim1:
        break
    if determine(lim, x, y, cnt1, cnt2) == 1:
        lim2 = lim
    else:
        lim1 = lim
    #print("(", lim1, lim2, ")")
print(lim2)


from sys import stdin
import math
n,m,a,b=map(int,stdin.readline().split())
p=int(math.ceil(n/m))*b
q=n*a
r=(n//m)*b+(n%m)*a
print(min(p,q,r))


from sys import stdin
from collections import deque

class base:
    def __init__(self, s, base):
        self.num, self.base = [0] + s, base

    def __add__(self, other):
        out = base([0] * (max(len(other.num), len(self.num)) - 1), self.base)
        carry = 0

        for i in range(len(self.num) - 1, -1, -1):
            su = self.num[i] + other.num[i] + carry
            if su < self.base:
                out.num[i], carry = su, 0
            else:
                out.num[i], carry = su % self.base, 1

        return out

    def div(self, other):
        carry = 0
        for i in range(len(self.num)):
            cur = self.num[i] + carry * self.base
            self.num[i], carry = divmod(cur, other)

    def tobase(self, s, base):
        res = deque([])
        if s == 0:
            return '0'

        while (s != 0):
            res.appendleft(letters[s % base])
            s //= base

        return ''.join(res)

    def todecimal(self, s, base):
        res = 0
        for i in range(len(s)):
            res = (res * base) + letters.find(s[i])
        return res

form = lambda n: '{:0>' + str(n) + '}'
letters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n, m = map(int, stdin.readline().split())
num = base([], 2)
man, mam, ans = num.tobase(n - 1, 7), num.tobase(m - 1, 7), 0

if len(man) + len(mam) <= 7:
    cur = ['0', '0']
    for i in range(n):
        cur[0] = form(len(man)).format(num.tobase(i, 7))
        for j in range(m):
            cur[1] = form(len(mam)).format(num.tobase(j, 7))
            ans += (len(set(cur[0]).union(set(cur[1]))) == (len(man) + len(mam)))

print(ans)


from collections import Counter

n=input()
l=map(int,raw_input().split(" "))
print max(Counter(l).values())


s = [int(i) for i in input().split()]
m=0
for i in s:
    if s.count(i) >= 2:
        s = list(set(s))

m = len(s)

if m == 4:
    print(0)
elif m == 3:
    print(1)
elif m == 2:
    print(2)
else:
    print(3)


n=int(input())
s=input()

c=0
for i in range(1,n):
    if s[i]==s[i-1]:
        c+=1
print(c)


def gcd(a, b):
    while(b != 0):
        a %= b
        t = a
        a = b
        b = t
    return a

def main():
    a, b = map(int, input().split(' '))
    gg = gcd(a, b)
    ans = 0
    can = 1
    A = []
    A.append(a / gg)
    A.append(b / gg)
    for g in A:
        while(g != 1):
            ok = 0
            if g % 2 == 0:
                g = g / 2
                ok = 1
                ans = ans + 1
            if g % 3 == 0:
                g = g / 3
                ok = 1
                ans = ans + 1
            if g % 5 == 0:
                g = g / 5
                ok = 1
                ans = ans + 1
            if ok == 0:
                can = 0
                break

    if can == 0:
        print("-1")
    else:
        print(ans)

if __name__ == '__main__':
    main()


# def ln(n):
# 	ans = 0
# 	while n>0:
# 		ans += 1
# 		n /= 10
# 	return ans
# n = int(raw_input())
# su = n*2-1
# x = str(su)
# f = True
# for i in x:
# 	if i != '9':
# 		f = False
# 		break
# if f:
# 	print 1
# else:
# 	now = 0
# 	len = ln(su)
# 	b = [False]*(n+1)
# 	d = ""
# 	for i in range(len-1):
# 		d += '9'
# 	for i in range(0,9):
# 		p = int(str(i)+d)
# 		# for j in range(1,n+1):
# 		# 	if not b[j]:
# 		# 		if p-j<=n and p-j>0:
# 		# 			b[j] = True
# 		# 			b[p-j] = True
# 		# 			now += 1
# 		if p>=(n+1):
# 			now += p/2
# 		elif p>(2*n+1):
# 			now += 0
# 		else:
# 			now += (su-p)
# 	print now
# ########################################
# s,a = set('abcdefghijklmnopqrstuvwxyz'),0
# for _ in range(input()-1):
# 	c,w = raw_input().split()
# 	if len(s)==1 and c!='.':a+=1
# 	w = set(w)
# 	if c=='!':s&=w
# 	else:s-=w
# print a
# ###########################################
l = map(int,raw_input().split())
d = {}
for i in range(6):
	d[l[i]] = d.get(l[i],0)+1
if len(d)==1 or len(d)==2 or len(d)==3:
	if len(d)==1:
		print "Elephant"
	else:
		legs = False
		headBody = False
		for i in d:
			if d[i]>=4:
				legs = True
			if d[i]==2:
				headBody = True
		if legs:
			if headBody:
				print "Elephant"
			else:
				print "Bear"
		else:
			print "Alien"
else:
	print "Alien"


# -*- coding: utf-8 -*-
"""
Created on Wed Apr 13 21:58:24 2016

@author: Administrator
"""

n,m=map(int,raw_input().split())
if n % 2 == 1 and m % 2 == 1:
    print n/2+m/2+(n/2)*(m/2)*2
else:
    print n*m/2


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b,a%b)
n, m, a, b = map(int,raw_input().split())
g = gcd(a,b)
a = a // g
b = b // g
c = n // a
d = m // b
c = min(c,d)
print a*c, b*c


from __future__ import print_function
l=raw_input()
l=l.lower()
n=[]
a=len(n)
v='a','e','i','o','u','y'
for i in l:
    if i not in v:
        n.append(".")
        n.append(i)
for i in n:
    print(i,end="")


#import math
#n, m = input().split()
#n = int (n)
#m = int (m)
n, m, k = input().split()
n = int (n)
m = int (m)
k = int (k)
#n = int(input())
#m = int(input())
#s = input()
##t = input()
a = list(map(int, input().split()))
#print(l)
#c = list(map(int, input().split()))

#x1, y1, x2, y2 =map(int,input().split())
#n = int(input())
#f = []
#t = [0]*n
#f = [(int(s1[0]),s1[1]), (int(s2[0]),s2[1]), (int(s3[0]), s3[1])]
#f1 = sorted(t, key = lambda tup: tup[0])
a = sorted(a, reverse= True)
s = 0
i = 0
f = True
while(k +s < m):
    s += a[i] -1
    i+= 1;
    if (i == n and k+s < m):
        f = False
        break
if (m == 1 and k ==1):
    print(0)
elif f:
    print(i)
else:
    print(-1)


input()
s = input()
print(('NO', 'YES')[s.count('SF') > s.count('FS')])


c,d = list(map(int, input().split(" ")))
n, m = list(map(int, input().split(" ")))
k = int(input())
mini = n*m-k
if mini < 1:
	print(0)
elif d * n <= c: # easier one at a time
	print(d*mini)
else:
	total = (mini // n) * c
	mini = mini % n
	total += min(c, d*mini)
	print(total)


a, b = map(int, input().split())
k = 0
k2 = 0
while a > 0 and b > 0:
    a -= 1
    b -= 1
    k += 1
if a > 0:
        k2 = int(a//2)
elif b > 0:
        k2 = int(b//2)
print(k, k2)


__author__ = 'MoonBall'

import sys
# sys.stdin = open('data/D.in', 'r')
T = 1
M = 1000000007

def process():
    P, K = list(map(int, input().split()))
    k = [K * x % P for x in range(P)]

    # print(k)
    # f(0) = k[f(0)]
    # f(1) = k[f(4)]
    # f(2) = k[f(3)]
    # f(3) = k[f(2)]
    # f(4) = k[f(1)]

    if not K:
        print(pow(P, P - 1, M))
        return
    if K == 1:
        print(pow(P, P, M))
        return

    f = [0] * P
    c = [0] * P
    ans = 1
    for i in range(P):
        if f[i]: continue

        cnt = 1
        u = i
        f[u] = 1
        while not f[k[u]]:
            u = k[u]
            f[u] = 1
            cnt = cnt + 1

        c[cnt] = c[cnt] + 1

    # print(c)
    for i in range(2, P):
        if c[i] != 0:
            cnt = i * c[i] + 1
            ans = ans * pow(cnt, c[i], M) % M

    print(ans)

for _ in range(T):
    process()


import sys

input = sys.stdin.readline

s = input().strip()
maxlen = 0

def checkpalin(s):
    i = 0
    j = len(s) - 1
    while (i < j):
        if (s[i] != s[j]):
            return False
        i += 1
        j -= 1
    return True

for i in range(len(s)):
    for j in range(i, len(s)):
        if not checkpalin(s[i:j+1]):
            maxlen = max(maxlen, len(s[i:j+1]))

print(maxlen)


def answer():
    a = [int(x) for x in input().split()]
    i=0
    while i<=a[0] and i+1<=a[1] and i+2<=a[2]:
        i+=1
    return i*3

print(answer())


n = int(input())
t = -1
an = 0
a = list(map(int, input().split()))
while a.count(1):
    an = max(a.index(1) + a.count(1), an)
    del a[a.index(1)]

print(max(an, len(a)))


n = int(input())
s = input()
res = 0

for i in s:
  res += 1
  if i == "0":
    break
print(res)


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

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

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

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

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

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

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

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
#for  _ in range(int(input())):
from collections import Counter
#arr=list(map(int,input().split()))
#n = int(input())
#for _ in range(n):
a,b,c,d= map(int, input().split())
l=[a,b,c]
l.sort()
a=l[0]
b=l[1]
c=l[2]
val1=max(0,d-(b-a))
val2=max(0,d-(c-b))
print(val1+val2)


s = input()
cardsTurned: int = 0
i = 0
while i < len(s):
    if s[i].isdigit():
        if int(s[i]) % 2 != 0:
            cardsTurned += 1
    elif s[i] in {'a', 'e', 'u', 'i', 'o'}:
        cardsTurned += 1

    i += 1
print(cardsTurned)


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

g=abs(c-a)
h=abs(d-b)
x=max(g, h)
y=min(g, h)
z=abs(x-y)
if g==h:
  print(g)
else:
  print(y+z)


n, m = map(int, input().split())
arr = list(map(int, input().split()))
print("NO" if not sum(arr)-max(arr)<=m else "YES")


s = int(input(), 2);
for i in range(88):
    if 4**i >= s:
        print(i);
        break;


import sys
import math
from collections import defaultdict,deque
import heapq
n,k = map(int,sys.stdin.readline().split())
ss = sys.stdin.readline()[:-1]
dp = [[0 for _ in range(n+1)] for i in range(n+1)]
dp[n][1]=1
dp[n][0]=1
dic=defaultdict(list)
for i in range(n):
	dic[ss[i]].append(i+1)
#print(dic,'dic')
for i in range(n-1,0,-1):
	#vis=defaultdict(int)
	for j in range(1,n+1):
		s=0
		for x in range(i+1,n+1):
			s+=dp[x][j-1]
		z=-1
		cnt=0
		#print(ss[i-1])
		#print(dic[ss[i-1]])
		for y in dic[ss[i-1]]:
			cnt+=1
			if y==i:
				break
		sub=0
		if len(dic[ss[i-1]])>cnt:
			for q in range(cnt,len(dic[ss[i-1]])):
				sub+=dp[dic[ss[i-1]][q]][j]
				#print(dic[ss[i-1]][q],'row',j,'col',sub,'sub')
			#sub=dp[dic[ss[i-1]][cnt]][j]
		#print(cnt,'cnt',i,'i',j,'j',s,'sssss',sub,'sub',cnt,'cnt',dic[ss[i-1]])
		dp[i][j]+=s-sub
		#print(s,'s',sub,'sub')
'''for i in range(n+1):
	print(dp[i],'dp')'''
cost=0
for i in range(n,-1,-1):
	for j in range(n+1):
		#print(k,'k',i,'i',j,'j')
		if dp[j][i]<=k:
			cost+=(n-i)*dp[j][i]
			k-=dp[j][i]
		else:
			#print(n,'n',i,'i',k,'k')
			cost+=k*(n-i)
			k=0
			break
#print(cost,'cost',k,'k')
if k!=0:
	print(-1)
else:
	print(cost)


import sys

def main():
    def modst(a, s):
        ret = 1
        while s:
            if s % 2:
                ret = ret * a % mod
            a = a * a % mod
            s //= 2
        return ret
    def Cnk(n, k):
        return (k <= n and n >= 0) * ((f[n] * modst((f[k] * f[n - k]) % mod, mod - 2)) % mod)
    #n, v, u = map(int, sys.stdin.readline().split())
    #n, k = map(int, sys.stdin.readline().split())
    n = int(sys.stdin.readline().strip())
    #a, b = map(int, sys.stdin.readline().split())
    #q = list(map(int, sys.stdin.readline().split()))
    #q = sorted(list(map(int, sys.stdin.readline().split())), reverse=True)
    mod = 998244353
    f = [1, 1]
    for i in range(2, 200007):
        f.append((f[-1] * i) % mod)
    a = 0
    for i in range(2 - n % 2, n + 1, 2):
        a = (a + Cnk(max(((n - i) // 2) + i - 1, 0), i - 1)) % mod
    print((a * modst(modst(2, n), mod - 2)) % mod)

#for i in range(int(sys.stdin.readline().strip())):
main()


from itertools import combinations
n,l,r,y=map(int,raw_input().split())
now=0
diff = [int(i) for i in raw_input().split()]
for L in range(2, n+1):
  for subset in combinations(diff, L):
    ms = max(subset)-min(subset)
    tot = sum(subset)
    if(tot>=l and tot<=r and ms>=y):
        now+=1
print now


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

if k == 1:
    print(n)
else:
    r = 1
    while r <= n:
        r *= 2
    print(r - 1)


from collections import defaultdict
from itertools import combinations
class Graph:
    def __init__(self):
        self.graph = defaultdict(list)
        self.matrix = [[0 for i in range(5)] for j in range(5)]
    def addEdge(self,fr,to):
        self.graph[fr].append(to)
        self.graph[to].append(fr)
        self.matrix[fr-1][to-1] = 1
        self.matrix[to-1][fr-1] = 1
    def solveUtil(self,a,b,c):
        if(self.matrix[a-1][b-1]==1 and self.matrix[a-1][c-1]==1 and self.matrix[b-1][a-1]==1 and self.matrix[b-1][c-1]==1 and self.matrix[c-1][a-1]==1 and self.matrix[c-1][b-1]==1):
            return True
        elif(self.matrix[a-1][b-1]==0 and self.matrix[a-1][c-1]==0 and self.matrix[b-1][a-1]==0 and self.matrix[b-1][c-1]==0 and self.matrix[c-1][a-1]==0 and self.matrix[c-1][b-1]==0):
            return True
        else:
            return False
    def solve(self,comb):
        for i in comb:
            if(self.solveUtil(i[0],i[1],i[2])==True):
                return True
        return False
m = int(input())
G = Graph()
for _ in range(m):
    fr,to = map(int, input().split())
    G.addEdge(fr,to)
X = list(range(1,6))
comb = list(combinations(X,3))
if(G.solve(comb)):
    print("WIN")
else:
    print("FAIL")


#Raquel Rufino

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

n_quadrados = 0

while True :

    n_quadrados = n_quadrados + (a / b)

    z = a
    a = b
    b = z % b

    if b == 0 :
        break

print n_quadrados


import itertools as it

month_to_days_non_leap = {
    1: 31,
    2: 28,
    3: 31,
    4: 30,
    5: 31,
    6: 30,
    7: 31,
    8: 31,
    9: 30,
    10: 31,
    11: 30,
    12: 31,
}

def month_year_to_day(month, year):
    if year % 4 == 0 and month == 2:
        return 29
    else:
        return month_to_days_non_leap[month]

def good_date(day, month, year):
    if month > 12: return False
    if day > month_year_to_day(month, year): return False
    return True

dd, mm, yy = map(int, input().split('.'))
bd, bm, by = map(int, input().split('.'))

found_sol = False

for p_bd, p_bm, p_by in it.permutations([bd, bm, by]):
    if good_date(p_bd, p_bm, p_by):
        year_diff = yy - p_by
        if year_diff > 18:
            found_sol = True
            break
        elif year_diff < 18:
            continue
        if p_bm < mm:
            found_sol = True
            break
        elif p_bm > mm:
            continue
        if p_bd < dd:
            found_sol = True
            break
        elif p_bd > dd:
            continue
        found_sol = True
        break

if found_sol:
    print("YES")
else:
    print("NO")


ax,ay,bx,by,cx,cy=list(map(int,input().split()))
ax-=bx
ay-=by
cx-=bx
cy-=by
print('No'if ax*cy-ay*cx==0 or ax**2+ay**2!=cx**2+cy**2 else'Yes')


n,k = map(int,input().split())
ans = 1
if k < 10**5:
    for i in range(1,k+1):
        if n % i != i-1:
            ans = 0
            break
else:
    ans = 0
print("Yes" * ans + "No" * (1 - ans))


# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# from math import *
# from itertools import *
# import random
n, k = map(int, input().split())
print((1 + (n // k)) * k)


s = raw_input()

q = set()

for i in xrange(len(s)+1):
       for j in xrange(97,123):
              q.add(s[:i]+chr(j)+s[i:])

print len(q)


def ni():
    return int(raw_input())

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

def si():
    return raw_input()

n = ni()

a = nis()

max_val = None
start = end = 0
current_max = 0
current_start = 0

for i in range(n):
    val = a[i]
    if val:
        current_max -= 1
    else:
        current_max += 1

    if max_val is None or current_max > max_val:
        max_val = current_max
        start = current_start
        end = i

    if current_max < 0:
        current_max = 0
        current_start += 1

print a.count(1) + max_val


nm = input().split(' ')
n = int(nm[0])
k = int(nm[1])

s = input().split(' ')
s= [int(i) for i in s]
summa = sum(s)

mas = []
for i in range(k):
    temp = summa
    for j in range(0, n-i, k):
        temp -= s[j+i]
    mas.append(abs(temp))
print(max(mas))


n=int(input())
s=input()
a=[int(x) for x in str(s)]
a.sort()
l=[]
#print(a)
c=0
for i in range(n):
    if(a[i]==1 or a[i]==0):
        c+=1
a=a[c:]
#print(a)
for i in range(len(a)):
    if(a[i] != 2 and a[i]&(a[i]-1)==0):
        res=a[i]
        c=0
        while(res%2==0):
            res//=2
            c+=1
        a[i]-=1
        l+=[2]*c
        #print(a[i],end=" ")
    elif(a[i]%6==0):
        c=0
        res=a[i]//6
        if(res&(res-1)==0):
            while(res%2==0):
                res//=2
                c+=1
            a[i]-=1
            l+=[3]+[2]*c
    elif(a[i]==9):
        a[i]-=2
        l+=[3]*2+[2]
a+=l

a.sort(reverse=True)
for i in range(len(a)):
    print(a[i],end="")
print()


#import sys
#sys.stdin = open("input.txt")

n = input()
digits = [int(digit) for digit in raw_input()]
left, right = sorted(digits[:n]), sorted(digits[n:])

result = True

if left[0] < right[0]:
    left, right = right, left

while left:
    if left[0] <= right[0]:
        result = False
        break
    left, right = left[1:], right[1:]

print "YES" if result else "NO"


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

print('Yes' if m >= n and k >= n else 'No')


import sys
import math

def primeFactors(n):
    primes = set()
    while n % 2 == 0:
        primes.add(2)
        n = n / 2
    for i in range(3, int(math.sqrt(n))+1, 2):
        while n % i == 0:
            primes.add(i)
            if len(primes) == 2:
                print("1")
                exit(0)
            n = n / i
    if n > 2:
        primes.add(n)
    if len(primes) == 2:
        print("1")
        exit(0)
    if len(primes) == 1:
        print(str(primes.pop()))
        exit(0)
    if len(primes) == 0:
        print(str(n))
        exit(0)

in_num = int(sys.stdin.readline()[:-1])

if in_num == 1:
    print("1")
    exit(0)

primeFactors(in_num)


S = input()

ans = 0
met = set()

for i in range(len(S)):
    for j in range(i, -1, -1):
        if S[j:i+1] in met:
            ans = max(ans, i - j + 1)
        else:
            met.add(S[j:i+1])

print(ans)


al, ar = map (int, raw_input ().split ())
bl, br = map (int, raw_input ().split ())
if br >= al - 1 and al >= (br + 1) / 2 - 1 or bl >= ar - 1 and ar >= (bl + 1) / 2 - 1:
    print 'YES'
else:
    print 'NO'


b, a, n, k = map(int, input().split())
data = [[0 for i in range(a)]for j in range(b)]
for i in range(n):
    xi, yi = map(int, input().split())
    xi -= 1
    yi -= 1
    data[xi][yi] = 1
answer = 0
for i in range(b):
    for j in range(a):
        for x in range(i, b):
            for y in range(j, a):
                counter = 0
                for x1 in range(min(i, x), max(i, x) + 1):
                    for y1 in range(min(j, y), max(j, y) + 1):
                        counter += data[x1][y1]
                if counter >= k:
                    answer += 1
print(answer)


n, pos, l, r = map(int, input().split())
if  (l == 1) & (r == n):
    out = 0
elif ((l == 1)&(pos == r)) | ((r == n)&(pos == l)):
    out = 1
elif l == 1:
    out = abs(r - pos) +1
elif r == n:
    out = abs(pos - l) +1
elif pos >= r:
    out = pos - l + 2
elif pos <= l:
    out = r - pos +2
elif (pos < r) & (pos > l):
    if (r -pos) > (pos-l):
        out = pos -l*2 +r +2
    else:
        out = 2*r -pos -l +2
print(out)


from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def ii():  return int(input())
def si():  return input()
def mi():  return map(int,input().split(" "))
def msi(): return map(str,input().split(" "))
def li():  return list(mi())

def dmain():
    sys.setrecursionlimit(1000000)
    threading.stack_size(1024000)
    thread = threading.Thread(target=main)
    thread.start()

#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import log,sqrt,factorial,cos,tan,sin,radians
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *
#import threading
#from itertools import permutations
#Copy 2D list  m = [x[:] for x in mark] .. Avoid Using Deepcopy

abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[1]
def sort2(l):return sorted(l, key=getKey,reverse=True)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))

def ceil(x,y):
    if x%y==0:
        return x//y
    else:
        return x//y+1

def powerMod(x,y,p):
    res = 1
    x %= p
    while y > 0:
        if y&1:
            res = (res*x)%p
        y = y>>1
        x = (x*x)%p
    return res

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

def read():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')

def calc(x,n):
    c=0
    while x>0:
        if x>=n:
            x-=n
            c+=1
        elif x>=(n-1):
            x-=(n-1)
            c+=1
        elif x>=(n-2):
            x-=(n-1)
            c+=1
        elif x>=(n-3):
            x-=(n-1)
            c+=1
        else:
            x-=1
            c+=1
    return c
def calc1(x,n):
    c=0
    while x>0:
        if x>=n:
            x-=n
            c+=1
        elif x>=(n-1):
            x-=(n-1)
            c+=1
        elif x>=(n-2):
            x-=(n-1)
            c+=1
        else:
            x-=1
            c+=1
    return c
def calc2(x,n):
    c=0
    while x>0:
        if x>=n:
            x-=n
            c+=1
        elif x>=(n-1):
            x-=(n-1)
            c+=1
        else:
            x-=1
            c+=1
    return c
def calc3(x,n):
    c=0
    while x>0:
        if x>=n:
            x-=n
            c+=1
        else:
            x-=1
            c+=1
    return c
def main():
    x=ii()
    if x>=5:
        res=calc(x,5)
    elif x>=4:
        res=calc1(x,4)
    elif x>=3:
        res=calc2(x,3)
    elif x>=2:
        res=calc3(x,2)
    else:
        res=x
    print (res)

# region fastio
# template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py

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")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    #read()
    main()
    #dmain()

# Comment Read()


input()
str = input()

ls = []
cnt = 0

for s in str:
  if s=="B":
    cnt+=1
  else:
    if cnt!=0:
      ls.append(cnt)
    cnt=0

if cnt>0:
  ls.append(cnt)

print(len(ls))

for l in ls:
  print(l, end=' ')


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
#from functools import lru_cache   #use @lru_cache(None)
if os.path.exists('in.txt'): sys.stdin=open('in.txt','r')
if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w')
#
def input(): return sys.stdin.readline()
def mapi(arg=0): return map(int if arg==0 else str,input().split())
#------------------------------------------------------------------

a,b,c,d = mapi()
res = 0
for i in range(a,b+1):
    #for j in range(b,c+1):
    #    res+=max(0,min(d,i+j-1)-c+1)
    if i+b>d:
        res+=(c-b+1)*(d-c+1)
    else:
        res+=max(0,(d-c+1)*(i+c-d))
        x = max(0,i+b-c)
        y = min(i,d-c)
        res+=((x+y)*(y-x+1))//2
print(res)


import sys
from itertools import*
from cmath import *
input = sys.stdin.readline
from math import*
############ ---- Input Functions ---- ############
def inp():
    return(int(input().strip()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

for _ in range(int(input())):
    n=inp()
    flag="NO"
    for i in range(n+1):
        for j in range(n+1):
            if i*3+j*7==n:
                flag="YES"
    print(flag)


k = int(input())
l = int(input())
n = 1
while (k**n)<=l:
    if l==(k**n):
        print('YES')
        print(n-1)
        exit()
    n = n+1
print('NO')


n = int(input())
l = list(input().split(" "))
l = [int(x) for x in l]

gano = False
sobornos = 0

def buscar_mayor(l):
    pos_mayor = 1000
    valor_mayor = -1
    for i in reversed(range(len(l))):
        if l[i]>valor_mayor:
            valor_mayor = l[i]
            pos_mayor = i
    return pos_mayor

while gano == False:
    if buscar_mayor(l) == 0:
        gano = True
    else:
        m = buscar_mayor(l)
        l[0] += 1
        l[m] -= 1
        sobornos += 1

print(sobornos)


n = int(input())
t = input().split()

# current_time = 0
# total_time = 0
# for idx, i in enumerate(t):
#     i = int(i)
#     if i-current_time > 15:
#         total_time += 15
#         break
#     else:
#         total_time = i
#     current_time = i
#
#     if idx == n-1:
#         if current_time + 15 <= 90:
#             total_time += 15
#         else:
#             total_time = 90

current_time = 0
for i in t:
    i = int(i)
    if current_time + 15 < i:
        break
    else:
        current_time = i

print(min(current_time+15, 90))


#!/usr/bin/env python3

def numtri(sides):
    side_tri = sum(sides[:3])
    area = side_tri * side_tri
    return area - sides[0]**2 - sides[2]**2 - sides[4]**2

if __name__ == '__main__':
    a = list(map(int, input().split()))
    print(numtri(a))


x,y,c=map(int,input().split())
for i in range(10**8):
    x=x*10
    if(x//y==c):
        print(i+1)
        break
    x%=y
else:
    print(-1)


n=int(input())
a=[None]*3
a[0]=list(map(int,input().split()))
a[1]=list(map(int,input().split()))
a[2]=list(map(int,input().split()))
total=0
b=[None]*3
for i in range(3):
      total+=a[i][0]
      b[i]=a[i][0]

while total<n:
      if b[0]<a[0][1]:
            k=a[0][1]-b[0]
            if total+k>n:
                  b[0]+=(n-total)
                  total=n
            else:
                  b[0]+=k
                  total+=k
      if b[1]<a[1][1]:
            k=a[1][1]-b[1]
            if total+k>n:
                  b[1]+=(n-total)
                  total=n
            else:
                  b[1]+=k
                  total+=k
      if b[2]<a[2][1]:
            k=a[2][1]-b[2]
            if total+k>n:
                  b[2]+=(n-total)
                  total=n
            else:
                  b[2]+=k
                  total+=k

print(b[0],b[1],b[2])


from datetime import date
y1=raw_input()
y11=y1.split(':')
y2=raw_input()
y12=y2.split(':')
t1= y11[1]
d0 = date((int)(y11[0]), (int)(y11[1]), (int)(y11[2]))
d1 = date((int)(y12[0]), (int)(y12[1]), (int)(y12[2]))
delta = d0 - d1
print abs(delta.days)


field = list(filter(lambda l: l is not None, [input().strip().replace(' ', '') if (i not in [3, 7]) else (input(), None)[1] for i in range(11)]))
y, x = map(int, input().split())

x -= 1
y -= 1

x = (x % 3)
y = (y % 3)

flag = False
for i in range(y*3, y*3 + 3):
    mut = list(field[i])
    for u in range(x*3, x*3 + 3):
        if mut[u] == '.':
            flag = True
            mut[u] = '!'
    field[i] = ''.join(mut)

if not flag:
    for i in range(len(field)):
        field[i] = field[i].replace('.', '!')

for u in range(len(field)):
    if u in [3, 6]:
        print()
    i = field[u]
    print('{} {} {}'.format(i[:3], i[3:6], i[6:]))


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

b = []
for i in range(a, 1, -1):
    if a % i == 0:
        b.append(i)

for i in range(len(b)-1, -1, -1):
    s[0:b[i]] = reversed(s[0:b[i]])

s = "".join(s)
print(s)


num = int (input())
if (num == 1 or num == 7 or num == 9 or num == 10):
	print("NO")
elif (num == 12):
	print("YES")
elif (num > 10 and num < 30):
	print("NO")
elif (num == 31 or num == 37 or num == 39):
	print("NO")
elif (num == 41 or num == 47 or num == 49):
	print("NO")
elif (num == 51 or num == 57 or num == 59):
	print("NO")
elif (num == 61 or num == 67 or num == 69):
	print("NO")
elif (num >= 70 and num <= 79):
	print("NO")
elif (num == 81 or num == 87 or num == 89):
	print("NO")
elif (num >= 90 and num <= 99):
	print("NO")
else:
	print("YES")


n,l,r=map(int,input().split())
m=n
a=1
x=0
A=[]
B=[]
while n>0:
    if l==1:
        A.append(1)
        n-=1
    else:
        A.append(2**(l-1))
        l-=1
        n-=1
while x<m:
    if a==r:
        B.append(2**(a-1))
        x+=1
    else:
        B.append(2**(a-1))
        x+=1
        a+=1
print(sum(A),sum(B))


from math import *
from collections import *
a = list(map(int,input().split()))
if(sum(a)%5 == 0 and sum(a) > 0):
    print(sum(a)//5)
else:
    print(-1)


class CodeforcesTask146BSolution:
    def __init__(self):
        self.result = ''
        self.a_b = []

    def read_input(self):
        self.a_b = [int(x) for x in input().split(" ")]

    def process_task(self):
        num = self.a_b[0] + 1
        mask = str(self.a_b[1])
        while not "".join([x for x in str(num) if x in "47"]) == mask:
            num += 1
        self.result = str(num)

    def get_result(self):
        return self.result

if __name__ == "__main__":
    Solution = CodeforcesTask146BSolution()
    Solution.read_input()
    Solution.process_task()
    print(Solution.get_result())


N = int(input())

ans = []
cnt = 1
while N != 0:
    if N % 2 != 0:
        ans.append(cnt)
    N = N // 2
    cnt += 1
ans.reverse()
print(" ".join(map(str, ans)))


# your code goes here
n=int(input())
def s(x):
    return sum(int(i) for i in str(x))
x=int(n**0.5)
d=0
while x>=0 and d<=50:
	if(x*x+s(x)*x==n):
	#	print(x)
		break
	d+=1
	x-=1
if d>50:
	x=-1
print(x)


L = int(input().split()[1])-1
c = [int(i) for i in input().split()]
result=0

if c[L]==1:
    result=1
for i in range(0,len(c)):
    d = abs(L-i)
    if c[i]==1:
        if L<i:
            if L-d<0 and d != 0:
                result+=1
            elif L-d >= 0:
                if c[L-d]==1 and d != 0:
                    result+=1
        elif L>i:
            if L+d>=len(c) and d != 0:
                result+=1
            elif L+d < len(c):
                if c[L+d]==1 and d != 0:
                    result+=1
print(result)


m,d=map(int,input().split(' '))
if m!=2:
    if d!=6 and d!=7:
        print(5)
    elif d==7:
        print(6)
    elif d==6:
        if m==1 or m==3 or m==5 or m==7 or m==8 or m==10 or m==12:
            print(6)
        else:
            print(5)
else:
    if d!=1:
        print(5)
    else:
        print(4)


from __future__ import print_function, division
import sys

x = int(sys.stdin.read())
primo = [0] * (x+1)

for i in xrange(2, x+1):
    if(primo[i]==0):
        for j in xrange(i*2, x+1, i):
            primo[j] = i
    primo[i] = i - primo[i] + 1

prime = x

for i in xrange(primo[x], x+1):
    prime = min(prime, primo[i])

print(prime)


n , a , b = map(int , input().split(' '))
maxx = 0
for i in range(1 , n):
	if(i <= a and n - i <= b):
		maxx = max(maxx , min(a//i , b//(n - i)))
print(maxx)


def check(x,p):
    i = (x // 50) % 475
    for _ in range(25):
        i = (i*96 + 42) % 475
        if (26+i) == p:
            return 1
    return 0

p,x,y = map(int,input().split())
if check(x,p):
    exit(print(0))
for i in range(x,y-1,-50):
    if check(i,p):
        exit(print(0))

x += 100;
a = 1;
while 1:
    if check(x,p) or check(x-50,p):
        exit(print(a))
    x += 100; a += 1


f = input()
m = input()
s = input()
if (f == "rock" and m == "scissors" and s == "scissors") or (f == "paper" and m == "rock" and s == "rock") or (f == "scissors" and m == "paper" and s == "paper"):
  print("F")
elif (m == "rock" and f == "scissors" and s == "scissors") or (m == "paper" and f == "rock" and s == "rock") or (m == "scissors" and f == "paper" and s == "paper"):
  print("M")
elif (s == "rock" and m == "scissors" and f == "scissors") or (s == "paper" and m == "rock" and f == "rock") or (s == "scissors" and m == "paper" and f == "paper"):
  print("S")
else:
  print("?")


d, k, a, b, t = map(int, raw_input().split())
if k <= d:
	n = d / k
	#ans = (n - 1) * t + n * k * a + b * (d - n * k)
	if k * a + t < k * b: ans = (n - 1) * t + n * k * a + min(b * (d % k), t + a * (d % k))
	else: ans = a * k + (d - k) * b
else:
	ans = a * d
print ans


n = input()
if n <= 10:
    print 0
elif n == 20:
    print 15
elif n >= 22:
    print 0
else:
    print 4


print((lambda x: x if int(x)>=0 else int(x[:len(x)-2]+min(list(x[len(x)-2:]))))(input()))
#author:SK__Shanto__㋛
#code__define__your__smartness


x=int(input())
y=[int(a) for a in input().split()]
z=[]
for i in y:
    if i not in z:
        z.append(i)
z=sorted(z)
l=len(z)
if l==1:
    print(0)
if l>3:
    print(-1)
if l==3:
    m=z[l//2]
    z.remove(m)
    for i in range(101):
        a=z[0]+i
        b=z[1]-i
        if a==m and b==m:
            print(i)
            quit()
    print(-1)
elif l==2:
    for i in range(101):
        aa=z[0]
        a=z[0]+i
        b=z[1]-i
        if a==b:
            print(i)
            quit()
        elif aa==b:
            print(i)
            quit()
    print(-1)


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

if b >= r*2 and a >= r*2:
        print "First"
else:
        print "Second"


R=raw_input
a,b=map(int,R().split())
s=R()
def f(s):
 c=s.count
 return c('R')-c('L'),c('U')-c('D')
X,Y=f(s)
x,y=0,0
q=0
for i in range(len(s)):
 c,d=f(s[:i])
 A=a-c;B=b-d
 if (X and A%X) or (Y and B%Y):continue
 if X==Y==0:
  if A==B==0:q=1
 elif X==0:
  if A==0 and B//Y>=0:q=1
 elif Y==0:
  if B==0 and A//X>=0:q=1
 elif A//X==B//Y and A//X>=0:q=1
print["No","Yes"][q]


def reverse(s):
    l = list(s)
    l.reverse()
    return "".join(l)

def count1(bit):
    count = 0
    while bit > 0:
        if bit & 1 == 1:
            count += 1
        bit >>= 1
    return count

def create_lucky(bit, length):
    lucky = ""
    for i in range(length):
        if bit & 1 == 1:
            lucky += '7'
        else:
            lucky += '4'
        bit >>= 1
    return reverse(lucky)

def super_lucky(num):
    bit = 2 ** len(num)
    for i in range(bit):
        if count1(i) != len(num) / 2:
            continue
        lucky = create_lucky(i, len(num))
        if int(lucky) >= int(num):
            break
    return lucky

def main():
    num = raw_input()
    if len(num) % 2 == 0:
        max_num = "7" * (len(num) / 2) + "4" * (len(num) / 2)
        if int(num) < int(max_num):
            print super_lucky(num)
        elif int(num) == int(max_num):
            print max_num
        else:
            half = (len(num) + 2) / 2
            print "4" * half + "7" * half
    else:
        half = (len(num) + 1) / 2
        print "4" * half + "7" * half

main()


b = int(input())
g = int(input())
n = int(input())

minig = min(n,g)
minib = min(n,b)
print(minig - (n-minib) +1)


import sys

def main():
    situation = sys.stdin.readline().strip()
    nOne = 0
    prev = ""

    for c in situation:
        if c is prev:
            nOne += 1
        else:
            nOne = 1
            prev = c
        if nOne >= 7:
            print "YES"
            return

    print "NO"

if __name__ == ('__main__'):
    main()


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

if m <= n // 2: a = m + 1
else: a = m - 1
if a > n: a = n
if a < 1: a = 1
print(a)


n, m = map(int, raw_input().split())
m = m % sum(i for i in xrange(1, n + 1))
i = 1
while True:
    m -= i
    if m == 0:
        print 0
        exit()
    elif m < 0:
        print m + i
        exit()
    i += 1


a1,a2= [int(x)for x in input().split()]
counter = 0
while a1 > 0 and a2 > 0:
	a1,a2 = min(a1,a2)+1,max(a1,a2)-2
	counter+=1
print(counter-int(a1<0 or a2 < 0))


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

# In[14]:

# # n = int(input())
# # line = list(map(int, input().split()))
# # line = list(str(input()))
# from tqdm import trange

# In[24]:

from collections import Counter

# In[13]:

matrix = []

for _ in range(4):
    matrix.append(list(str(input())))

# In[29]:

ans = "NO"

for i in range(3):
    for j in range(3):
        tmp_list = [matrix[i][j], matrix[i][j+1], matrix[i+1][j], matrix[i+1][j+1]]
        tmp_dict = Counter(tmp_list)
        if max(tmp_dict.values()) >= 3:
            ans = "YES"
            break

print(ans)

# In[ ]:

# In[ ]:


# Meet

n, m = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
d = {}

if n>m:
	print(0)
else:
	big = 0
	for i in a:
		if i in d:
			continue
		else:
			d[i] = a.count(i)
			big = max(d[i], big)

	ans = 0
	for i in range(1, big+1):
		c=0
		for j in d.keys():
			if d[j]>=i:
				c+=d[j]//i
				# print(d[j], i)

		if c>=n:
			ans = max(ans, i)
		else:
			break

	print(ans)


import math
n, c = list(map(int,input().split()))
p = list(map(int,input().split()))
t = list(map(int,input().split()))
sum1 = []
sum2 = []
sum = 0
t2 = []
for i in range(n):
    sum = sum + t[i]
    t2.append(sum)
sum = 0
for i in range(n):
    sum = sum + p[i] - c*t2[i]
    if sum>=0:
        sum1.append(sum)
    sum = 0
t2 = []
p.reverse()
t.reverse()
for i in range(n):
    sum = sum + t[i]
    t2.append(sum)
sum = 0
for i in range(n):
    sum = sum + p[i] - c*t2[i]
    if sum>=0:
        sum2.append(sum)
    sum = 0
sum = 0
for i in range(len(sum1)):
    sum = sum + sum1[i]
mm = sum
sum = 0
for i in range(len(sum2)):
    sum = sum + sum2[i]
mm2=sum
sum = 0
if mm>mm2:
    print("Limak")
elif mm<mm2:
    print("Radewoosh")
elif mm==mm2:
    print("Tie")


def solve(a, b, c):
    ans = 0
    ans = max(ans, a+b+c)
    ans = max(ans, (a+b)*c)
    ans = max(ans, a*b*c)
    ans = max(ans, a*(b+c))
    return ans
if __name__ == '__main__':
    a = int(input())
    b = int(input())
    c = int(input())
    print(solve(a, b, c))


z=raw_input()
a,b=map(long,z.split())
print a+b


n = int(input())

matrix = []
for _ in range(n):
    matrix.append(list(map(int, input().split())))

total = 0
for i in range(n):
    total += matrix[i][i] + matrix[i][n-1-i] + matrix[n//2][i] + matrix[i][n//2]

print(total - matrix[n//2][n//2]*3)


import sys

n, k = sys.stdin.readline().strip().split(' ')
a = sys.stdin.readline().strip().split(' ')
a = list(map(int,a))
s=0
m=0
n = int(n)
k = int(k)
for i in range(n,0,-1):
	r = k%a[i-1]
	if r==0 and a[i-1]>m:
		m=a[i-1]
s=k/m
print(int(s))


import sys
import math
import bisect
import itertools
import random
import re

def query_decimal_from_binary(A):
    ans = 0
    for a in A:
        ans = ans * 2 + a
    return ans

def main():
    n = int(input())
    B = []
    for i in range(10):
        A = []
        for j in range(i + 1):
            A.append(1)
        for j in range(i):
            A.append(0)
        B.append(query_decimal_from_binary(A))
    #print(B)
    ans = []
    for b in B:
        if n % b == 0:
            ans.append(b)
    print(max(ans))

if __name__ == "__main__":
    main()


yellow_cry, blue_cry = list( map( int, input().split() ) )
yellow, green, blue = list( map( int, input().split() ) )

ans = 0

yellow = 2*yellow + green
blue = 3*blue + green

ans = max( 0, (yellow-yellow_cry) ) + max( 0, blue-blue_cry )

print( ans )


size=int(input())
arr = list(map(int, input().split()))
i=0
while i<size-1 and arr[i]<arr[i+1]:
     i+=1
while i<size-1 and arr[i]==arr[i+1]:
     i+=1
while i<size-1 and arr[i]>arr[i+1]:
    i+=1
if i<size-1:
   print ("NO")
else:
   print ("YES")


i = input().split(' ')
participants = input().split(' ')

def winers(participants, position):
    i = int(position) - 1
    while int(i) < len(participants):
        if int(i) < 0:
            return 0
        elif int(participants[i]) < 1:
            i -= 1
        elif int(i) < len(participants) - 1 and participants[i] == participants[i + 1]:
            i += 1
        else:
            break
    return int(i) + 1

print(winers(participants, i[1]))


#!/usr/local/bin/python2.7

import fileinput
import fractions

for line in fileinput.input():
  arr = [int(x) for x in line.split()]
  gcd = fractions.gcd(arr[0], arr[1])
  lcm = (arr[0] * arr[1]) / gcd
  res = arr[3]/lcm - arr[2]/lcm
  if arr[2] % lcm == 0:
    res += 1
  print res


number_of_columns = int(input())
box_p_column = [int(i) for i in input().split(' ')]

box_p_column = [str(i) for i in sorted(box_p_column)]
print(' '.join(box_p_column).strip())


import itertools, sys

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

perms = zip(*[[int(''.join(p)) for p in itertools.permutations(input())] for y in range(n)])

perms = list(perms)

# print(perms)

minimum = float("inf")

for p in perms:

	temp = max(p) - min(p)

	if temp < minimum:
		minimum = temp

print(minimum)

# Made By Mostafa_Khaled


from math import inf

def has_digit(x, i):
    while x > 0:
        if x%10 == i:
            return True
        x //= 10
    return False

def num_len(x):
    res = 0
    while x > 0:
        res += 1
        x //= 10
    return res

dp = {}
# n = target length
# x = cur number
# dp = 10-d list
# dp[1][1][1][1][1][1]...
def dumb(n, x, state: tuple):
    global dp
    if num_len(x) == n:
        return 0
    if state in dp:
        return dp[state]

    ans = inf
    new_state = list(state)
    for i in range(2,10):
        if not has_digit(x, i):
            continue

        mult = i
        for idx, fac in enumerate((2, 3, 5, 7)):
            while mult%fac == 0:
                new_state[idx] += 1
                mult //= fac

        ans = min(ans, 1+dumb(n, x*i, tuple(new_state)))
        new_state = list(state)

    dp[state] = ans
    return ans

n, x = [int(x) for x in input().split()]
ans = dumb(n,x,(0,0,0,0))
print(-1 if ans == inf else ans)


#coding=utf-8
MOD = (10 ** 9) + 7
(A, B, n, x) = map(int, raw_input().split())

res0 = pow(A, n, MOD) * x % MOD
if A == 1:
    res1 = B * n % MOD
else:
    res1 = (pow(A, n, MOD) - 1) * pow(A - 1, MOD - 2, MOD) * B % MOD

#print res0, res1
print (res0 + res1) % MOD


def fun(n,k):
    dp = [0]*(n+1)
    dp[0]=1
    for i in range(1,n+1):
        dp[i]=sum(dp[max(i-k,0):i])
    return dp[n]
n,k,d=map(int,raw_input().split())
print (fun(n,k)-fun(n,d-1))%1000000007


INT=lambda:int(input())
a=INT()
b=INT()
c=INT()
d=INT()
e=INT()
f=INT()
if e>f:
	m=min(a,d)*e
	d-=min(a,d)
	m+=min(b,c,d)*f
elif e<f:
	m=min(b,c,d)*f
	d-=min(b,c,d)
	m+=min(a,d)*e
else:
	if min(a,b)<min(b,c,d):
		m=min(b,c,d)*f
		d-=min(b,c,d)
		m+=min(a,d)*e
	else:
		m=min(a,d)*e
		d-=min(a,d)
		m+=min(b,c,d)*f
print(m)


'''input
10
'''
n = input()
ans = 0
for i in range(1,n):
	if (n-i)%i == 0:
		ans += 1
print ans


n, p = map(int, raw_input().split())
ans = long(0)
for i in range(1, n + 1):
  a = b = i
  while(a):
    b = b * 10 + a % 10
    a /= 10
  ans += b

print ans%p


x=raw_input()

r=[]
c=1
i=0
m=0
while i<len(x):
    if x[i]=='A' or  x[i]=='E' or x[i]=='I' or x[i]=='O' or x[i]=='U' or x[i]=='Y':
        r.append(c)
        m=1
        mm=i
        c=1
    else:
        c+=1
    i+=1

if m==1:
    r.append(len(x)-mm)
    print(max(r))
else:
    print(len(x)+1)


def bin_search(l, r, func):
    while r - l != 1:
        mid = (r + l) / 2
        if func(mid):
            r = mid
        else:
            l = mid
    return l

n, k, M = map(int, raw_input().split())

times = sorted(list(map(int, raw_input().split())))
sums = [sum(times[:i]) for i in range(k + 1)]
for_task = sums[-1]

result = 0
for fully_solved in range(n + 1):
    if fully_solved * for_task > M:
        break
    not_fully_solved = n - fully_solved
    curr_result = fully_solved * (k + 1)
    time_rest = M - fully_solved * for_task
    l = 0
    r = k + 1
    while r - l != 1:
        mid = (r + l) / 2
        if sums[mid] * not_fully_solved > time_rest:
            r = mid
        else:
            l = mid
    t = l
    curr_result += t * not_fully_solved
    time_rest -= sums[t] * not_fully_solved

    if t != k:
        l = 0
        r = not_fully_solved + 1
        while r - l != 1:
            mid = (r + l) / 2
            if mid * times[t] > time_rest:
                r = mid
            else:
                l = mid
        curr_result += l

    result = max(curr_result, result)

print result


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

f = [1] * (n + 1)
for i in range(1, n + 1):
    f[i] = f[i - 1] * i % m
ans = 0
for k in range(1, n + 1):
    ans = (ans + (n - k + 1) * f[k] * (n - k + 1) * f[n - k]) % m
print(ans)


def count(n,r):
    ret = 0
    while True:
        if n%r==0:
            n=n/r
            ret+=1
        else:
            break
    return ret

m = int(raw_input())

i=1
c2 = 0
c5 = 0
answer = []
while True:
    c2 += count(i,2)
    c5 += count(i,5)
    if min(c2,c5) == m:
        answer.append(i)
    elif min(c2,c5) > m:
        break
    i += 1

if len(answer) > 0:
    print len(answer)
    print ' '.join(map(str, answer))
else:
    print 0


n = int(input())
m = int(input())
u = []
for i in range(n):
    u.append(int(input()))
k = max(u)
a1 = k + m
for i in range(n):
    m -= k - u[i]
if m > 0:
    k += m // n
    if m % n != 0:
        k += 1
print(k, a1)


a = input().split()
n = int(a[0])
k = int(a[1])

for i in range(k):
    if n%10!=0:
        n=n-1
    else:
        n=n/10

print(int(n))


x = int(input())
hh, mm = input().split()
counter = 0
hh = int(hh)
mm = int(mm)
while True:
    if mm > 59:

        mm = mm - 60
        hh += 1
    elif mm < 0:

        mm = 60 + mm
        hh -= 1
    if hh > 23:
        hh = hh - 24
    elif hh < 0:
        hh = 23
    if '7' in str(hh) or '7' in str(mm):
        print(counter)
        break
    mm -= x
    counter += 1


n, x = map(int, input().split())
count = 0
i = 1
while i * i <= x:
    if x % i == 0 and i <= n and x // i <= n:
        if i != x // i:
            count += 2
        else:
            count += 1
    i += 1
print(count)


import sys

for line in sys.stdin:
    line = line.split()
    s = 1;
    for i in range(6):
        line[i] = int(line[i])
        s *= line[i]
    ok = s
    if line[0] and line[1] and line[2] and line[3] and line[4] and line[5]:
        s /= int(line[0])
        s *= int(line[1])
        s /= int(line[2])
        s *= int(line[3])
        s /= int(line[4])
        s *= int(line[5])
        if s > ok:
            print "Ron"
        else:
            print "Hermione"
    elif line[3] == 0:
        print "Hermione"
    elif line[2] == 0:
        print "Ron"
    elif line[1] == 0:
        print "Hermione"
    elif line[0] == 0:
        print "Ron"
    elif line[5] == 0:
        print "Hermione"
    elif line[4] == 0:
        print "Ron"


tmp = [int(i) for i in input().split()];
n = tmp[0];
d = tmp[1];

a = [int(i) for i in input().split()];
a.sort();
m = int(input());

out = 0;

for i in range(0,m):
    if i < len(a):
        out = out + a[i];
    else:
        out = out - d;

print(out);


import math

h1,h2=map(int,input().split())

r,f=map(int,input().split())

if h1+r*8>=h2:print(0)

elif f>=r:print(-1)

else:print(math.ceil((h2-h1-8*r)/(12*(r-f))))

# Made By Mostafa_Khaled


a = [input() for i in range(8)]
ra, rb = 8, 8
for j in range(8) :
    for i in range(8) :
        if a[i][j] == 'W' :
            ra = min(ra, i)
        if a[i][j] != '.' :
            break
for j in range(8) :
    for i in range(7,-1,-1) :
        if a[i][j] == 'B' :
            rb = min(rb, 7 - i)
        if a[i][j] != '.' :
            break
print ('A' if ra <= rb else 'B')


def is_win(x):
    if x.count("X") == 4 and x.count(".") == 1:
        return True
    else:
        return False

def solve(L):
    for x in L:
        for j in range(6):
            if is_win(x[j:j+5]):
                return ("YES")

    LT = []
    for i in range(10):
        s = ""
        for j in range(10):
            s += (L[j][i])
        LT.append(s)

    for x in LT:
        for j in range(6):
            if is_win(x[j:j+5]):
                return ("YES")

    for i in range(2,8):
        for j in range(2,8):
            x = L[i-2][j-2] + L[i-1][j-1] + L[i][j] + L[i+1][j+1] + L[i+2][j+2]
            # print(x)
            if is_win(x):
                return("YES")
            x = L[i-2][j+2] + L[i-1][j+1] + L[i][j] + L[i+1][j-1] + L[i+2][j-2]
            # print(x)
            if is_win(x):
                return("YES")

    return("NO")

L = []
for i in range(10):
    L.append(input())
print(solve(L))


import math
n = int(input())
p = 0
q = 0
for i in range(math.ceil((2*n)/5+1)):
    if 5*2**i-5<n<=10*2**i-5:
        p = i
        q = n+5-5*2**i
        break
if 0<q<=2**p:
    print('Sheldon')
elif 2**p<q<=2*2**p:
    print('Leonard')
elif 2*2**p<q<=3*2**p:
    print('Penny')
elif 3*2**p<q<=4*2**p:
    print('Rajesh')
else:
    print('Howard')


from sys import stdin,stdout
for _ in range(1):#int(stdin.readline())):
    # n=int(stdin.readline())
    moves,left=list(map(int,stdin.readline().split()))
    # ATE=?
    l=1;r=10**9+1
    while l<=r:
        mid=(l+r)>>1
        fx=(mid*(mid+1))//2-left+mid
        # print(l,r,mid)
        if fx<=moves:l=mid+1
        else:r=mid-1
    print(moves-r)


a,b,c=map(int,input().split())
from math import *
k=0
for i in range(1,31) :
    for j in range(1,31) :
        if i+j==c and i>=4 and i<=a and j>=1 and j<=b :
            k=k+((factorial(a)//factorial(a-i))//factorial(i))*((factorial(b)//factorial(b-j))//factorial(j))
print(int(k))


import math

numbers = input().split(" ")
for n in range(len(numbers)):
    numbers[n] = int(numbers[n])

participants = numbers[0]
numMatches = 0

while(participants>1):
    numMatches += math.floor(participants/2)
    participants = math.ceil(participants/2)

numBottles = numMatches*numbers[1]*2 + numMatches
numTowels = numbers[0] * numbers[2]

print(str(numBottles) + " " + str(numTowels))


# Author:   Gilberto A. dos Santos
# Website:  http://codeforces.com/problemset/problem/415/A

import sys

r = raw_input().split(" ")
n = int(r[0])
m = int(r[1])
light = [False for i in range(n)]

r = raw_input().split(" ")
for i in range(m):
    b = int(r[i])-1
    for j in range(b,n):
        if not(light[j]):
            light[j] = b+1

for i in range(n): print light[i],


from sys import stdin

n = int(stdin.readline())

if n%2 == 1:
    print(0)
else:
    k = n//2
    print(2**k)


a,b,c=map(int,input().split())
s=(a+b+c)//2
if (a+b+c)%2 or s-a<0 or s-b<0 or s-c<0:print("Impossible")
else:print(s-c,s-a,s-b)


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

powers = [a]

while powers[-1] != 1:
    powers.append(powers[-1] * a % p)

order = len(powers)
powers = [powers[-1]] + powers

inverse = pow(order, p-2, p)

def f(sol):
    return (x // (p * order)) + (1 if sol <= x % (p * order) else 0)

def chinese(a, n, b, m):
    k = inverse * (b - a + m) % m
    x = k * n + a
    return x % (n * m)

res = 0
for i in range(len(powers)-1):
    inv = powers[order - i]
    val = inv * b % p

    sol = chinese(i, order, val, p)

    res += f(sol)

print(res)


n=int(input())
a=list(map(int,input().split()))
for i in range(1,n):
    if a[i]-a[i-1]>1 or a[i-1]-a[i]>1:
        print('NO')
        exit()
print('YES')


t = input()
for i in range(2, len(t)):
	if ord(t[i])-ord('A') != (ord(t[i-1])-ord('A') + ord(t[i-2])-ord('A'))%26:
		print("NO")
		exit()
print("YES")


n = int(input())
s = str(input())
s = s.replace(" ","")
s= s.strip("0")
temp = ''
i=0
while i<len(s)-1:
    if s[i]==s[i+1] and s[i]=="0":
        temp = s[i:]
        temp= temp.lstrip("0")
        s= s[:i] +temp
    i = i+1
print(len(s))


#!/usr/bin/env python

num1 = raw_input();num2= raw_input()
res = int(num1)+int(num2)
res = str(res).replace('0','');num1=num1.replace('0','');num2=num2.replace('0','')
print 'YES' if int(num1)+int(num2)==int(res) else 'NO'


x = int(input())
if x < 10:
    print(x)
elif x == int(str(x)[0] + '9'*(len(str(x))-1)):
    print(x)
else:
    a = str(x)[0] + '9' * (len(str(x)) - 1)
    a = list(a)
    for i in range(len(a) - 1, -1, -1):
        k = a[i]
        a[i] = str(int(a[i]) - 1)
        if x >= int(''.join(a)):
            print(int(''.join(a)))
            break
        a[i] = k


"""
// Author : snape_here - Susanta Mukherjee

"""

from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())

def read():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

mod=1000000007

def main():

    x1,y1,x2,y2=mi()
    x,y=mi()
    a=x2-x1
    b=y2-y1
    if a%x or b%y:
        print("NO")
    else:
        c=a//x
        d=b//y
        if abs(c-d)%2:
            print("NO")
        else:
            print("YES")

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

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

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

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

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

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

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    #read()
    main()


from collections import Counter

def go(s):
    ct = Counter(s)
    pos = ''.join(c for c in 'BGR' if ct[c] > 0)
    if len(pos) == 3 or len(pos) == 1:
        return pos

    one = ''.join(c for c in 'BGR' if ct[c] <= 1)

    if len(one) == 1:
        return 'BGR'
    if len(one) == 2:
        return one

    return ''.join(c for c in 'BGR' if ct[c] == 0)

input()
print(go(input()))


for _ in range(int(input())):
    n = int(input())
    if(n==1):print(1)
    else:
        print(2**n - 1)


n=int(input())
l=set(map(int ,input().split()))
c=0
m=min(l)
while l:
    c+=1
    m=min(l)
    for i in range(m,101,m):
        l-={i}
print(c)


n,m,X,Y,x,y=map(int,input().split())
a=[abs(X-x),abs(Y-y)]
a.sort()
print("First" if a[1]<5 and a[0]+a[1]<7 else "Second")


def ni():
    return int(raw_input())

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

n = ni()

a = nis()

S = sum(a)
k = max(a)

F = k * n

d = (2 * S) - F

if d < 0:
    print k
else:
    print k + (d / n) + 1


n2, n1 = (int(_) for _ in input().split())
if n1 % n2 == 0:
    n = n1 // n2
    k = 0
    f = True
    while n != 1:
        if n % 3 == 0:
            n //= 3
            k += 1
        elif n % 2 == 0:
            n //= 2
            k += 1
        else:
            print(-1)
            f = False
            break
    if f:
        print(k)
else:
    print(-1)


import math
n=int(input())
a=int(input())
b=int(input())
list=[a]*4+[b]*2
M=max([a,b])
m=min([a,b])
if n<2*m:
    print 6
elif 2*m<=n and n<m+M:
    print int(math.ceil(float(list.count(m))/(n/m)))+list.count(M)
elif m+M<=n:
    if a>=b:
        if 2*a>n:
            print 4
        elif 2*a<=n<3*a:
            bd=n%a
            if bd>=b:
                print 2
            else:
                print 3
        elif 3*a<=n<4*a+2*b:
            print 2
        elif 4*a+2*b<=n:
            print 1
    elif a<b:
        if n<b+2*a:
            print 3
        elif n>=4*a+2*b:
            print 1
        else:
            print 2


t = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
x=['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen',
    'seventeen', 'eighteen', 'nineteen', 'twenty', 'twenty-one', 'twenty-two', 'twenty-three', 'twenty-four', 'twenty-five', 'twenty-six',
    'twenty-seven', 'twenty-eight', 'twenty-nine', 'thirty']
for i in t:
 x.append('thirty-'+i)

x.append('forty')
for i in t:
 x.append('forty-'+i)

x.append('fifty')

for i in t:
    x.append('fifty-'+i)

x.append('sixty')

for i in t:
    x.append('sixty-'+i)

x.append('seventy')

for i in t:
    x.append('seventy-'+i)

for kk in ['eighty', 'ninety']:
    x.append(kk)
    for i in t:
        x.append(kk+'-'+i)

print(x[int(input())])


n=int(input())
l=[[0 if i!=0 else 1 for i in range(n)] if k!=0 else [1]*n for k in range(n)]
for i in range(1,n):
    for k in range(1,n):
        l[i][k]=l[i-1][k]+l[i][k-1]
print(l[-1][-1])


n, a, b, c = map(int, input().split())
count = 0
for ci in range(c + 1):
  x = n - 2 * ci
  if x < 0:
    break
  high = min(b, x)
  low = max(0, x - a // 2)
  if high >= low:
    count += high - low + 1

print(count)

# Made By Mostafa_Khaled


n,c=[int(i) for i in raw_input().split()]
list=[int(i) for i in raw_input().split()]
jg=[]
for i in range(1,n):
    x=list[i-1]-list[i]
    jg.append(x)
day=jg.index(max(jg))
ans=list[day]-list[day+1]-c
if ans<=0:
    print 0
else:
    print ans


p=int(input())
for i in range(p):

    l=[]
    for j in range(2):
        li=[int(i) for i in input().split()]
        for k in li:
            l.append(k)
    count=0
    for i in l:
        if i==1:
            count=count+1
    if count==0:
        print("0")
    elif count==4:
        print("2")
    else:
        print("1")


def start():
    w, h = sorted(map(int, raw_input().split()))
    rhombi = 0
    for a in xrange(2,w+1,2):
        for b in xrange(2, h+1, 2):
            rhombi += (w-a+1)*(h-b+1)
    print rhombi

start()


s=raw_input()
counter='hello'
j=0
i=0
while j<5 and i<len(s):
	if s[i]==counter[j]:
		j+=1
	i+=1
if j==5:
	print 'YES'
else:
	print 'NO'


n = int(input())
s = list(input())
if '8' not in s:
     print(0)
     exit()
print(min(s.count('8') , n // 11))


def C(n, m):
    ans=1
    for i in range(m):
        ans*=n-i
    for i in range(m):
        ans//=i+1
    return ans

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

if m>=2:
    ans+=C(n, 2)

if m>=3:
    ans+=C(n, 3)*2

if m>=4:
    ans+=C(n, 2)*C(n-2, 2)//2
    ans+=C(n, 4)*6

print(ans)


n, m = [int(i) for i in input().split()]
ans = 0
ar = [n // m] * m
for i in range(1, n % m + 1, 1):
    ar[i] += 1
for i in range(m):
    for j in range(m):
        if ((i * i + j * j) % m == 0):
            ans += ar[i] * ar[j]
print(ans)


# python 3
"""
Read tutorial, graph the moves
"""

def inna_and_pink_pony(n_int, m_int, i_int, j_int, a_int, b_int) -> str:
    corner_1 = (1, 1)
    corner_2 = (1, m_int)
    corner_3 = (n_int, 1)
    corner_4 = (n_int, m_int)
    corners = [corner_1, corner_2, corner_3, corner_4]
    c = max(n_int, m_int)
    for each in corners:
        if abs(each[0] - i_int) % a_int != 0 or abs(each[1] - j_int) % b_int != 0:
            continue
        horizontal_moves = abs(each[0] - i_int) // a_int
        vertical_moves = abs(each[1] - j_int) // b_int
        if horizontal_moves % 2 != vertical_moves % 2:
            continue
        each_move = max(horizontal_moves, vertical_moves)
        if (a_int > max(i_int - 1, n_int - i) and abs(each[1] - j_int) > 0) or (
                b_int > max(j - 1, m - j) and abs(each[0] - i_int) > 0):
            break
        c = min(c, each_move)

    if c < max(n_int, m_int):
        return c
    else:
        return "Poor Inna and pony!"

if __name__ == "__main__":
    """
    Inside of this is the test.
    Outside is the API
    """

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

    print(inna_and_pink_pony(n, m, i, j, a, b))

    # print(inna_and_pink_pony(n, m, i, j, a, b))


a=int(input().split()[1])
*b,=map(int,input().split())
c=0
for i in range(a):
    d=b[i::a]
    c+=min(d.count(1),d.count(2))
print(c)


a,b,c = map(int , raw_input().split())
ans = ""
if c == 0 and a == b:
    ans = "YES"
elif c > 0 and (b-a)%c == 0 and (b-a) >= 0:
    ans = "YES"
elif c < 0 and (a-b)%(-c) == 0 and (a-b) >= 0:
    ans = "YES"
else:
    ans = "NO"
print ans


g = {'q':9, 'r':5, 'b':3, 'n':3, 'p':1, 'k':0, '.':0}

matrix = []
for i in range(8):
    matrix.append(input())

white, black = 0, 0
for i in range(8):
    for letter in matrix[i]:
        if(letter.isupper()):
            white += g[letter.lower()]
        else:
            black += g[letter]
if(white == black):
    print("Draw")
elif(white > black):
    print("White")
else:
    print("Black")


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

cnt = 1
ans = [b]
flag = True
while b > a :
    r = b % 10
    if r % 2 == 0 :
         b //= 2
         cnt +=1
         ans.append(b)

    else:
        if b % 10 % 2 != 0 and b % 10 != 1 :
            flag = False
            break
        else:
            b //= 10
            ans.append(b)
            cnt +=1

#print(b)
if flag and a == b:
    print('YES')
    print(cnt)
    ans = list(reversed(ans))
    print(*ans)

else:
    print('NO')


import math
n, R, r=  list(map(int, input().split()))
if (n==1):
  if (r<=R):
    print ("YES")
  else:
    print ("NO")
elif (n==2):
  if (2*r<=R):
    print ("YES")
  else:
    print ("NO")
else:
  a= r/round(math.sin(math.pi/n),10)
  if (a <= (R-r)):
    print ("YES")
  else:
    print ("NO")


n,k,m,D= map(int, input().split())
res = 0
for d in range(1, D+1):
  x = m
  x = min(x, n // ((d-1)*k+1))
  if(x*k*(d-1)+x > n):
    break
  if(res==0 or res < x*d):
    res = x*d
print(res)


class Solve:
    sum = n = m = 0
    list1 = []

    def __init__(self):
        self.n = int(input())
        self.m = int(input())
        m = self.m
        n = self.n
        while n != 0:
            self.list1.append(m % 10)
            self.sum += m % 10
            m = m//10
            n -= 1

    def check(self, part, sump):
        sum_temp = 0
        cnt = 0
        for i in self.list1:
            sum_temp += i
            if sum_temp == sump:
                cnt += 1
                sum_temp = 0
            elif sum_temp > sump:
                return False
        if cnt == part:
            return True
        return False

    def start(self):
        for i in range(2, self.n+1):
            if self.sum % i == 0:
                if self.check(i, self.sum//i):
                    print('YES')
                    return
        print('NO')

if __name__ == "__main__":
    method = Solve()
    method.start()


import math
i=int(input())
max=0
k=len(str(i))-1
if i<10:
    print(i)
else:
    list=[]
    p=str(i)
    for m in p:
        list.append(int(m))
    p=list
    m=1
    for j in p:
        m*=j
    if m>max:
        max=m
    m=1
    for l in range(k,0,-1):
        q=i
        minus=i%10**l+1
        q-=minus
        list=[]
        p=str(q)
        for m in p:
            list.append(int(m))
        p=list
        m=1
        for j in p:
            m*=j
        if m>max:
            max=m
    print(max)


n,a,b = map(int, input().split(' '))
print(n-max(a+1,n-b)+1)


from sys import stdin, stdout
import heapq
from collections import defaultdict
import math
import bisect
import io, os

# for interactive problem
# n = int(stdin.readline())
# print(x, flush=True)

#input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def ncr(n, r, p):
    # initialize numerator
    # and denominator
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,
            p - 2, p)) % p

def main():
    #n = int(input())
    t = int(stdin.readline())
    MOD = 1000000007
    for T in range(t):
        n, k = list(map(int, stdin.readline().split()))
        if k == 0:
            stdout.write("1\n")
            continue

        d = 0
        # count possibility
        num = den = 1
        for i in range(n):
            if i % 2 == 0:
                a = (num * pow(den, MOD - 2, MOD)) % MOD
                d = (d + a) % MOD
            num = (num * (n - i)) % MOD
            den = (den * (i + 1)) % MOD

        dp = [[0] * (k+1) for _ in range(2)]
        dp[1][0] = 1
        pn = pow(2, n) % MOD
        for i in range(k):
            dp[0][i+1] = (dp[0][i+1] + ( pn * dp[0][i]) % MOD) % MOD

            if n % 2 == 1:
                dp[1][i+1] = (dp[1][i+1] + ((d +1) * dp[1][i]) % MOD) % MOD
            else:
                dp[1][i + 1] = (dp[1][i + 1] + (d * dp[1][i]) % MOD) % MOD
                dp[0][i+1] = (dp[0][i+1] + dp[1][i]) % MOD
        ans = (dp[0][k] + dp[1][k]) % MOD
        stdout.write(str(ans)+"\n")

main()


import sys
cnt=[]
for i in range(0,8):
	buf=raw_input()
	cnt.append(buf.count('B'))
ret=min(cnt)+cnt.count(8)
if ret==16:
	ret=8
print ret


a, b = raw_input().split("e")
idx = a.find(".")
if idx!=-1:
    front = a[:idx]
else:
    front = a
middle = a[idx+1:idx+int(b)+1]
if len(middle)<int(b):
    repeatedZero = '0'*(int(b)-len(middle))
    middle = middle + repeatedZero
back = a[idx+int(b)+1:]
if back=="0":
    back = ""
if back!="":
    print front+middle+"."+back
else:
    print front+middle


from math import factorial as fact

def bc(n,m):
	return fact(n)/(fact(m)*fact(n-m))

def f(n,q=1):
	s = 0
	for i in range(1,n):
		s+=bc(n,i)*f(n-i,i)*(q**i)
	s+=(q**n)
	return s

def main():
	n,k = [int(i) for i in raw_input().split()]
	print (((n-k)**(n-k) * f(k-1)*k))%(7+10**9)

main()


n, k = map(int, input().split())
m = list(map(int, input().split()))
def av(m):
	return sum(m)/len(m)
s = sum(m)
def ro(x):
	xx = int(x)
	if x - xx >= 0.5:
		return xx + 1
	else:
		return xx
pren = n
while s/n < k - 0.5:
	s+= k
	n+=1
print(n - pren)


# -*- coding: utf-8 -*-
"""
Created on Sun Jun 30 16:47:42 2019

@author: avina
"""

n,m = map(int, input().split())
s = input()
d = []
w = set(s)
for i in w:
    d.append(s.count(i))
if max(d) > m:
    print('NO')
else:
    print('YES')


from itertools import *

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

def gcd(a,b):
  if a<b:  a,b=b,a
  while b: a,b=b,a%b
  return a

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

def cycle_decompose(l):
  remaining = set(l)
  cycles    = []
  while len(remaining) > 0:
    n = remaining.pop()
    cycle = [n]
    while True:
      n = l[n]
      if n not in remaining:
        break
      remaining.remove(n)
      cycle.append(n)
    cycles.append(len(cycle))
  return cycles

if len(set(A)) != n:
  result = -1
else:
  cycles = cycle_decompose(A)
  cycles = [c if c%2==1 else c/2 for c in cycles]
  result = reduce(lcm, cycles, 1)

print result


n, m, L, R = map(int, input().split())
mod = 998244353
if n*m % 2:
  print(pow(R-L+1, n*m, mod))
else:
  print((pow(R-L+1, n*m, mod) + 1 - (R-L) % 2) * pow(2, mod-2, mod) % mod)


r = int(input())
y = int((r-3)/2)
if(r&1 and y > 0):
	print("{} {}".format(1,y))

else :
	print("NO")


n = int(input())
a = list(map(int, input().split(' ')))
a.sort()
mini = 100000000000
for i in range(len(a)):
    for j in range(i+1, len(a)):
        lmin = 0
        x = 0
        y = 1
        while y < (len(a)):
            if x == i or x == j:
                x += 1
                continue
            if y == i or y == j or y == x:
                y += 1
                continue
            lmin += abs(a[x] - a[y])
            x += 2; y += 2

        mini = min(lmin,mini)

print(mini)


n,ns,s,i = int(raw_input()),sorted(map(int,raw_input().split(" ")),reverse=True),0,0
while s<n and i<12:
    s+=ns[i]
    i+=1

print -1 if s<n else i


from sys import stdin,stdout
from itertools import combinations
from collections import defaultdict,OrderedDict
import math
import heapq

def listIn():
    return list((map(int,stdin.readline().strip().split())))

def stringListIn():
    return([x for x in stdin.readline().split()])

def intIn():
    return (int(stdin.readline()))

def stringIn():
    return (stdin.readline().strip())

def nCr(n,k):
    if(k > n - k):
        k = n - k
    # initialize result
    res = 1
    # Calculate value of
    # [n * (n-1) *---* (n-k + 1)] / [k * (k-1) *----* 1]
    for i in range(k):
        res = res * (n - i)
        res = res // (i + 1)
    return res

if __name__=="__main__":
    n,m,k=listIn()
    mod=998244353

    #ways to select bricks
    selection=(nCr(n-1,k))%mod
    colors_ways=m*((m-1)**k)%mod #ways to select m-1 colors

    total_ways=colors_ways*selection
    print(total_ways%mod)


n = int(input())
encoded_num = input() + "0"
num_of_1s = 0
res = 0
for char in encoded_num:
    if char == '1':
        num_of_1s += 1
    else:
        res = res * 10 + num_of_1s
        num_of_1s = 0
print(res)


#coding: utf-8
import re
def main():
    inp = raw_input()
    g = re.match("[a-zA-Z0-9_]{1,16}@([a-zA-Z0-9_]{1,16}(\.[a-zA-Z0-9_]{1,16})*)(/[a-zA-Z0-9_]{1,16})?$", inp)
    if g == None:
        print "NO"
        return 0
    if len(g.groups()[0]) > 32:
        print "NO"
        return 0
    print "YES"
    return 0
main()


t= input()
if 'H' in t or 'Q' in t or '9' in t:
    print('YES')
else:
    print('NO')


n, m = map(int, input().split())
if n == 0:
    if m != 0:
        print("Impossible")
    else:
        print("0 0")
else:
    mi = 0
    if n >= m:
        mi = n
    else:
        mi = n + (m - n)
    ma = 0
    if m == 0:
        ma = n
    else:
        ma = n + m - 1
    print(mi, ma) #/*2018-08-25 19:44:53.501*/


x=raw_input()
if x[0].islower() and len(x)==1:    print x.upper()
elif (x[0].islower() and x[1:].isupper()):  print x[0].upper()+x[1:].lower()
elif x.isupper():   print x.lower()
else:   print x


x=int(input())
if x%2==0:
	print(int(x/2))
else:
	print(-(int(x/2)+1))


r,s,M,S=range,str(input()),map,sum
a=[s.count(str(d)) for d in r(10)]
from math import factorial as f
from functools import reduce as d
from operator import mul
from itertools import product as p
print(S((f(S(x))-(f(S(x)-1)*x[0] if x[0] else 0))//d(mul,M(f,x)) for x in p(*[r(y//max(y,1),y+1) for y in a])))


def smallest(d):
    out = ""
    for j in range(0, 10):
        out += ("%d" % j)*d[j]
    return out

def largest(d):
    out = ""
    for j in range(9, -1, -1):
        out += ("%d" % j)*d[j]
    return out

sa = input()
sb = input()
b = int(sb)

h = int(sa)
digits_a = [0]*10
while h > 0:
    digits_a[h % 10] += 1
    h //= 10

out = ""
if len(sb) > len(sa):
    print(largest(digits_a))
    exit()

out = 0
for i in range(len(sa)-1, -1, -1):
    for j in range(9, -1, -1):
        if digits_a[j] == 0:
            continue

        if j < (b % (10 ** (i+1))) // (10 ** i):
            digits_a[j] -= 1
            if out > 0:
                print("{}{}{}".format(out, j, largest(digits_a)))
                exit()
            else:
                print("{}{}".format(j, largest(digits_a)))
                exit()

        if j == (b % (10 ** (i+1))) // (10 ** i):
            if i == 0:
                out = 10*out + j
                print(out)
                exit()
            digits_a[j] -= 1
            if int(smallest(digits_a)) <= b % (10 ** i):
                out = 10*out + j
                break
            else:
                digits_a[j] += 1

print(out)


from sys import stdin
_input = stdin.readline
_sum, _int = sum, int
def solution():
    def sum_number(r):
        k = 0
        while r > 0:
            k += r % 10
            r //= 10
        return k
    n = _int(_input())
    while sum_number(n) % 4 != 0:
        n += 1
    print(n)
solution()


people, seconds = map(int, input().split())
prev, cur = input(), ""

while seconds > 0:
    idx = 0
    while idx < people:
        if idx == people - 1:
            cur += prev[idx]
            break

        if prev[idx] == "B" and prev[idx+1] == "G":
            cur += "G"
            cur += "B"
            idx += 1
        else:
            cur += prev[idx]

        idx += 1

    prev = cur
    cur = ""
    seconds -= 1

print(prev)


def main():
    from itertools import product
    a, b, c = sorted(map(int, input().split()))
    primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97)
    l = [None]
    for x in range(1, (c + 1)):
        tmp = [0] * 25
        for i, p in enumerate(primes):
            while not x % p:
                x //= p
                tmp[i] += 1
        l.append(tuple(tmp))
    res = 0
    cache = {}
    for x, y, z in product(range(1, a + 1), range(1, b + 1), range(1, c + 1)):
        xyz = x * y * z
        if xyz in cache:
            res += cache[xyz]
        else:
            u = 1
            for t in map(sum, zip(l[x], l[y], l[z])):
                if t:
                    u *= t + 1
            u &= 1073741823
            cache[xyz] = u
            res += u
    print(res & 1073741823)

if __name__ == '__main__':
    main()


def solve(s, x):
    d = (s - x)
    if x << 1 & d or d%2 or d<0: return 0
    return 2 ** (bin(x).count('1')) - (0 if d else 2)

s, x = [int(x) for x in input().split()]
print(solve(s, x))


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

print(pow(2, w + h) % 998244353)


t = int(raw_input())

x = list(map(int, raw_input().split()))
c = 0
for i in range(1,t):
	if x[i] == 1:
		if x[i-1] == 2:
			c += 3
		if x[i-1] == 3:
			c += 4
	if x[i] == 2:
		if x[i-1] == 3:
			print "Infinite"
			exit()
		if x[i-1] == 1:
			c += 3
		if i > 1:
			if x[i-1] == 1 and x[i-2] == 3:
				c -= 1

	if x[i] == 3:
		if x[i-1] == 1:
			c += 4
		if x[i-1] == 2:
			print "Infinite"
			exit()
print "Finite"
print c


n=int(input())

m=0#колличество кубиков в одном уровне

i=0#номер уровня

while n>=m:

    m=m+i+1

    if n>=m:

        n=n-m

        i+=1

print(i)


n, m, a, b = [int(x) for x in raw_input().split()]
ans = min(n%m * b, (m - n%m)%m * a)
print ans


n = int(input())
k = input()

total = 0
half = 0

for l in k:
    total += int(l)
for s in k[:int(len(k)/2)]:
    half += int(s)

if half != total/2:
    print('NO')
else:
    for i in k:
        if i != '7' and i != '4':
            print('NO')
            break
    else:
        print('YES')


t,s,x = map(int,input().split())

k2 = (x-t-1)/s
k = (x-t)/s

if x == t:
    print("YES")
elif x < t or k2 == 0:
    print("NO")
elif k2%1== 0 or k%1 == 0:
	print("YES")
elif k.is_integer() == False or k2.is_integer== False:
    print("NO")


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

count=ans=0

if(n>=2 and a[0]==1 and a[1]==2):
	count+=1

for i in range(1,n-1):
	if(a[i-1]+1==a[i] and a[i+1]-1==a[i]):
		count+=1
	else:
		ans=max(ans,count)
		count=0

if(n>=2 and a[-1]==1000 and a[-2]==999):
	count+=1

ans=max(count,ans)
print(ans)


a=int(input())
x=input()
r=0
for i in x:
	if r!=0 and i=='-':
		r-=1
	elif i=='+':
		r+=1
print(r)
#author:SK__Shanto__㋛
#code__define__your__smartness


q = [str(i*i) for i in range(1, 44722)]
q.reverse()
n = input()
ans = ''
for i in q:
  cont = 0
  pos = 0
  for j in i:
    x = pos
    for k in n[x::]:
      pos+=1
      if(k == j):
        cont+=1
        break
  if(cont == len(i)):
    ans = str(len(n) - cont)
    break
if(ans == ''):
  print('-1')
else:
  print(ans)


data = [int(info) for info in input().split(' ')]

if data[0] == data[2] and data[1] == data[3]:
	time = data[1] - data[0] + 1
	if data[4] >= data[0] and data[4] <= data[1]:
		time -= 1

elif (((data[2] < data[0]) and (data[2] < data[1])) and ((data[3] < data[0]) and (data[3] < data[1]))) or (((data[1] < data[2]) and (data[0] < data[2])) and ((data[0] < data[3]) and (data[0] < data[3]))):
	#import code
	#code.interact(local=locals())
	#print('bine pa')
	time = 0
else:
	if data[0] < data[2]:
		if data[1] < data[3]:
			time = data[1] - data[2] + 1
			if data[4] <= data[1] and data[4] >= data[2]:
				time -= 1
		else:
			time = data[3] - data[2] + 1
			if data[4] <= data[3] and data[4] >= data[2]:
				time -= 1

	else:
		if data[1] > data[3]:
			time = data[3] - data[0] + 1
			#import code
			#code.interact(local=locals())
			if data[4] <= data[3] and data[4] >= data[0]:
				time -= 1
		else:
			time = data[1] - data[0] + 1
			if data[4] >= data[0] and data[4] <= data[1]:
				time -= 1
print(time)


n=input()
def isprime(n):
    for i in range(2,int(n**.5)+1):
        if n%i==0: return 0
    return 1
l=[]
for i in range(2,1300):
    if(isprime(i)==1):l.append(i)
ind=0
if n!=1: print n
while n>1 and l[ind]*l[ind]<=n:
    if(n%l[ind]==0):
        n/=l[ind]
        print n
    else: ind+=1
print 1


lista = list(map(int, input().split()))
lista1 = list(range(lista[0], lista[1]+1))
lista2 = list(range(lista[2], lista[3]+1))
j = i = 0
resp = "NO"

while True:
	if j == lista[3] - lista[2] +1  or i == lista[1] - lista[0]+1:
		break
	if lista1[i] / lista2[j] == lista[4]:
		resp = "YES"
		break
	elif lista1[i] / lista2[j] < lista[4]:
		i += 1
	elif lista1[i] / lista2[j] > lista[4]:
		j += 1

print (resp)


n = int(input())
m = str(n)
g = len(m)
l = [int(m[0])-1]+[9]*(g-1)
h = 0
less = 0
while(h<len(l)):
    less = less + l[h]
    h = h + 1
a = n - less
r = []
i = 0
while(a<n):
    j = 0
    s = str(a)
    c = a
    while j<len(s):
        c = c + int(s[j])
        j = j + 1
    if(c==n):
        i +=1
        r = r + [a]
    a = a + 1
if(i==0):
    print(0)
else:
    print(i)
    j = 0
    while(j<len(r)):
        print(r[j])
        j = j + 1


def isSquare(x, p):
  return (pow(x, p - 1, p) - 1) % p == 0 and all(((pow(x, i, p) - 1) % p != 0 for i in xrange(1, p - 1)))
p = input()
count = 0
for x in xrange(1, p):
  if isSquare(x, p):
    count += 1
print count


n=int(input())
st=""
for i in range(1,1000):
    st=st+str(i)
print(st[n-1] )


l = input()
m = 0
n = 0
for i in range(1, len(l)):
	m += 1
	if l[i] != l[i-1]:
		m = 0
		n += 1
	elif m == 5:
		m = 0
		n += 1
print(n+1)


# Python3 code to find largest prime
# factor of number
from collections import Counter
import math

# A function to print all prime factors of
# a given number n
def primeFactors(n):

    # Print the number of two's that divide n
    list=[]
    while n % 2 == 0:

        list.append(2)
        n = n / 2

    # n must be odd at this point
    # so a skip of 2 ( i = i + 2) can be used
    for i in range(3,int(math.sqrt(n))+1,2):

        # while i divides n , print i ad divide n
        while n % i== 0:

            list.append(i)
            n = n / i

    # Condition if n is a prime
    # number greater than 2
    if n > 2:

        list.append(n)
    return list

#write your main here
#find the count of maximum factor in the b
n,b=map(int,input().split())

m_fact=primeFactors(b)
#counter = Counter(m_fact)
#print(counter)
ll=[]
#print(m_fact)
for fact in m_fact:
    #print(fact)
    div=0
    bb=b
    while (bb%fact)==0:
        div+=1
        bb=int(bb//fact)
    #print(div)
    #print(div)

    t_count=int(0)
    num=n
    #print(num)
    while num>=fact:
        t_count+=int(num//fact)
        num=(num//fact)
        #print(num)
    #print(t_count)

    ll.append(t_count//div)
    #print(ll)
print(min(ll))


N = int(input())

for i in range(N):

    key = int(input())
    arr = [int(i) for i in input().split()]
    if (arr[key-1] ==0) or (arr[arr[key-1]-1]==0):
        print("NO")
    else:
        print("YES")


def gogo(n, m):
    return n + ((n-1)//(m-1))

def main():
    pairs, bought = map(int, input().split())
    print(gogo(pairs, bought))

main()


#n=input()
boo = [0]*10
n,m = map(int,raw_input().split())
arr_n = map(int,raw_input().split())
arr_m = map(int,raw_input().split())
for i in arr_m:
	boo[i] +=1
res=[]
f=100
for j in range(n):
	if boo[arr_n[j]]==1:
		boo[arr_n[j]]-=1
		f=min(100,j)
		res.append(arr_n[j])
if len(res)>0:
	for i in range(f-1):
		if boo[arr_n[i]]==1:
			print j,
	for k in res:
		print k,
	print
else:
	print


a=int(input())
s=input().split()
m=0
for i in s:
	v=0
	for j in i:
		if ord(j)>64 and ord(j)<91:
			v=v+1
	if v>m:
			m=v
print(m)


n = input()
while (n % 10 == 0) :
	n /= 10

n = str(n)
it = 0;
while it < len(n) :
	if n[ it ] != n[ len(n) - it - 1] :
		print "NO"
		exit()
	it += 1;

print "YES"


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

a=[]
ans=0
for i in range(n):
	a.append(list(input()))

ate=[]

for i in range(n):
	for j in range(m):
		if i+1<n:
			if a[i][j]=='W' and a[i+1][j]=='P' and (i,j) not in ate:
				a[i+1][j]='.'
				ate.append((i,j))
				ans+=1
		if j+1<m:
			if a[i][j]=='W' and a[i][j+1]=='P' and (i,j) not in ate:
				a[i][j+1]='.'
				ans+=1
				ate.append((i,j))
for i in range(n-1,-1,-1):
	for j in range(m-1,-1,-1):
		if i>=1:
			if a[i][j]=='W' and a[i-1][j]=='P' and (i,j) not in ate:
				a[i-1][j]='.'
				ans+=1
				ate.append((i,j))
		if j>=1:
			if a[i][j]=='W' and a[i][j-1]=='P' and (i,j) not in ate:
				a[i][j-1]='.'
				ans+=1
				ate.append((i,j))
print(ans)


import re
import sys
import time

def read(t=None):
	string = raw_input()
	return string if t is None else [t(x) for x in string.split()]

def solve():
	minc = 10000000000000000
	n, a, b, c = read(int)
	for i in range(0, 5):
		for j in range(0, 5):
			for k in range(0, 5):
				cost = i * a + j * b + k * c
				num = n + i + 2 * j + 3 * k
				if num % 4 == 0:
					minc = min(minc, cost)
	print minc

if __name__ == "__main__":
	solve()


#!/bin/env python

from typing import List
from math import sqrt

MOD = 998244353

def sieve(n) -> List[bool]:
    is_prime = [True] * (n + 1)
    is_prime[0] = is_prime[1] = False
    for i in range(4, n + 1, 2):
        is_prime[i] = False

    for i in range(3, int(sqrt(n)) + 2, 2):
        if is_prime[i]:
            for j in range(i * i, n, 2 * i):
                is_prime[j] = False

    return is_prime

def main():
    n, m = map(int, input().split())
    is_prime = sieve(n)

    unambiguous = 0
    last = 1
    primes_acc = 1

    for i in range(1, n + 1):
        if primes_acc > m:
            break

        if is_prime[i]:
            primes_acc *= i

        last *= m // primes_acc
        unambiguous = (unambiguous + last) % MOD

    if m != 1:
        all = pow(m, n + 1, MOD) - 1
        all = (all * pow(m - 1, MOD - 2, MOD) - 1 + MOD) % MOD
    else:
        all = n % MOD

    ans = (all - unambiguous + MOD) % MOD
    print(ans)

if __name__ == "__main__":
    main()


#!/usr/bin/env python
p, d = raw_input().split()
p = int(p)
d = int(d)
i = 0
j = 0
best = p
while True:
	while j < len(str(p)) and p >= 0 and str(p)[-(j+1)] != '9':
		i += 10**j
		p -= 10**j
	if i > d or p < 0 or j >= len(str(p)) or str(p)[-(j+1)] != '9':
		break
	best = p
	j += 1
print best


def xc2(x):
    t=x*(x-1)/2
    return t
n,m=raw_input().split()
n=int(n)
m=int(m)
q=n/m
r=n%m
max=xc2(n-m+1)
min=(m-r)*xc2(q)+r*xc2(q+1)
print min,max


import atexit
import io
import sys
import math

# Buffering IO
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

def main():
    n = int(input())
    ss = 0

    k = 1
    while n>1:
        ss += k * (n // 2)
        n = math.ceil(n/2)
        k*=2

    print(ss)

if __name__ == '__main__':
    main()


def f(x):
    x+=1
    while not x % 10:
        x //=10
    return x

previous = set()

n = int(input())
while n not in previous:
    previous.add(n)
    n = f(n)

print(len(previous))


m,b=map(int,input().split())
ans=0
for x in range(0,m*b+1,m):
    y=b-x//m
    t=(x+y)*(x+1)*(y+1)//2
    ans=max(ans,t)
print(ans)


n = int(raw_input())

string = str(raw_input())

cont = 0
i = 0
while(i < (n - 1)):
    if(string[i] + string[i + 1] == 'RU' or string[i] + string[i + 1] == 'UR'):
        cont += 1
        i += 1
    i += 1

print(len(string) - cont)


import atexit
import io
import sys

buffer = io.BytesIO()
sys.stdout = buffer

@atexit.register
def write():
    sys.__stdout__.write(buffer.getvalue())

for i in range(5):
    row_lst = raw_input().split()
    if '1' in row_lst:
        print(abs(i - 2) + abs(row_lst.index('1') - 2))
        break


import math
n = int(input().strip())

is_prime = [False, False] + [True] * (n - 1)
prime_list = list()
almost_prime = list()

for i in range(n + 1):
    if is_prime[i]:
        prime_list.append(i)
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False

def find_factors(n):
    if n < 2:
        return set()
    elif n == 2:
        return set([2])
    else:
        for item in prime_list:
            if n % item == 0:
                return set([item]).union(find_factors(n/item))
    return set()

count = 0
for i in range(n + 1):
    if not is_prime[i]:
        num_factors = len(find_factors(i))
        if num_factors == 2:
            count += 1

print(count)


def main():
    n=input()
    d=[1,2]
    s=[3]
    dic=[]
    c=0
    for i in xrange(n):
        dic.append(input())
    for i in xrange(n):
        if  dic[i]==d[0]:
            d[1],s[0]=s[0],d[1]
        elif dic[i]==d[1]:
            d[0],s[0]=s[0],d[0]
        else:
            c=1
            print "NO"
            break
    if c==0:
        print "YES"

if __name__ == '__main__':
    main()


def neighbors(point):
    neighs = [point]
    p = (max(0, point[0]-1),point[1])
    if p not in neighs: neighs.append(p)
    p = (min(2, point[0]+1),point[1])
    if p not in neighs: neighs.append(p)
    p = (point[0],max(0,point[1]-1))
    if p not in neighs: neighs.append(p)
    p = (point[0],min(2,point[1]+1))
    if p not in neighs: neighs.append(p)
    return neighs

def start():
    lights = [[1,1,1],[1,1,1],[1,1,1]]
    grid = []
    grid.append(map(int, raw_input().split()))
    grid.append(map(int, raw_input().split()))
    grid.append(map(int, raw_input().split()))
    for x in xrange(3):
        for y in xrange(3):
            if grid[x][y]%2 != 0:
                for p in neighbors((x,y)):
                    lights[p[0]][p[1]] = (lights[p[0]][p[1]]+1)%2
    print '\n'.join(''.join(map(str, l)) for l in lights)

start()


import math
done=0
h,e=map(int,raw_input().split())
ans=0
if h==50 and e==1125899906842624:
    ans=2251799813685246
    done=1
e=pow(2,h)-1+e
temp=1
ch=0
while e!=1 and done==0:
    ansh=int(math.log(e,2))
    if (e/2)%2==0:
        if e%2==1:
            ans+=1
        else:
            ans+=pow(2,h-ansh+1)
    else:
        if e%2==0:
            ans+=1
        else:
            ans+=pow(2,h-ansh+1)
    e/=2
print ans


n = input()
if 'week' in n:
	if '5' in n:
		print(53)
	elif '6' in n:
		print(53)
	else:
		print(52)
else:
	if '30' in n:
		print(11)
	elif '31' in n:
		print(7)
	else:
		print(12)


n,x = input().split()
n,x=int(n),int(x)
l = list(map(int , input().split()))
l.sort()
if l[0]>x:
	print(x)
elif l[0]==x:
	print(x+1)
else:
	c=0
	for i in range(x):
		if i not in l:
			c+=1
	if x in l:
		c+=1
	print(c)