def find(teams):
    for i in range(len(teams)):
        if teams[i].name == "BERLAND": return i
def find_other(teams):
    for j in range(len(teams)):
        if teams[j].name != "BERLAND" and teams[j].games == 2: return j

class Team(object):
    def __init__(self,name):
        self.name = name
        self.gfor = 0
        self.gagainst =0
        self.points = 0
        self.games=0

    def __lt__(self,other):
        if self.points == other.points:
            if self.gfor-self.gagainst == other.gfor-other.gagainst:
                if self.gfor == other.gfor:
                    return self.name < other.name
                else:
                    return self.gfor > other.gfor
            else:
                return self.gfor-self.gagainst > other.gfor-other.gagainst
        else:
            return self.points > other.points

    def __str__(self):
        return self.name

#data = open("P3.txt")
teams = []
names = []
for _ in range(5):
    t1,t2,goals = raw_input().split()
    if t1 not in names:
        names.append(t1)
        teams.append(Team(t1))
    if t2 not in names:
        names.append(t2)
        teams.append(Team(t2))

    i=names.index(t1)
    j=names.index(t2)
    a,b = map(int,goals.split(":"))
    teams[i].games += 1
    teams[j].games += 1
    teams[i].gfor += a
    teams[i].gagainst += b
    teams[j].gfor += b
    teams[j].gagainst += a
    if a==b:
        teams[i].points += 1
        teams[j].points += 1
    elif a > b:
        teams[i].points += 3
    else:
        teams[j].points += 3

'''teams = []
t = Team("A")
t.points = 3
t.gfor = 5
t.gagainst = 0
t.games = 2
teams.append(t)

t = Team("BERLAND")
t.points = 0
t.gfor = 0
t.gagainst = 4
t.games = 2
teams.append(t)

t = Team("C")
t.points = 3
t.gfor = 0
t.gagainst = 0
t.games = 3
teams.append(t)

t = Team("D")
t.points = 9
t.gfor = 6
t.gagainst = 0
t.games = 3
teams.append(t)'''

teams.sort()
#for t in teams: print t,t.points,t.gfor-t.gagainst
i = find(teams)
j = find_other(teams)

if i==0 or i==1:
    print "1:0"
else:
    minp = teams[1].points
    if teams[i].points+3<minp:
        print "IMPOSSIBLE"
    elif teams[i].points+3>minp:
        print "1:0"

    else:
        teams[i].points += 3
        teams[i].gfor += 1
        teams[j].gagainst += 1
        count = 1
        teams.sort()
        i = find(teams)
        j = find_other(teams)
        while i > 1 and count<100:
            teams[i].gfor += 1
            teams[j].gagainst += 1
            count += 1
            teams.sort()
            i = find(teams)
            j = find_other(teams)

        if i > 1:
            print "IMPOSSIBLE"
        else:
            print "%i:0" %(count)

        '''if j!=1:
            mingd = teams[1].gfor-teams[1].gagainst
            gd = mingd-(teams[i].gfor-teams[i].gagainst)
            if teams[i].name > teams[1].name:
                gd += 1
            print "%i:0" %(gd)

        else:
            if i==2:
                mingd = teams[1].gfor-teams[1].gagainst
                gd = mingd-(teams[i].gfor-teams[i].gagainst)
                gd /= 2
                teams
                if teams[i].name > teams[1].name:
                    gd += 1
                print "%i:0" %(gd)'''


#     Codeforces Round #488 by NEAR (Div. 2)
import collections
from functools import cmp_to_key
#key=cmp_to_key(lambda x,y: 1 if x not in y else -1 )

import sys
def getIntList():
    return list(map(int, input().split()))

import bisect

s1 = getIntList()
s2 = getIntList()

def x8(x):
    return x*4

s1 = map(x4,s1)
s1 = list(s1)
s1 = [ (s1[i],s1[i+1]) for i in range(0,8,2)]
s2 = map(x4,s2)
s2 = list(s2)
s2 = [ (s2[i],s2[i+1]) for i in range(0,8,2)]

s1x = map(lambda x: x[0], s1)
s1x = list(s1x)
s1xmin = min(s1x)
s1xmax = max(s1x)

s1y = map(lambda x: x[1], s1)
s1y = list(s1y)
s1ymin = min(s1y)
s1ymax = max(s1y)

s2xpy = map(lambda x: x[0] + x[1], s2)
s2xpy = list(s2xpy)
s2xpymin = min(s2xpy)
s2xpymax = max(s2xpy)

s2xsy = map(lambda x: x[0] - x[1], s2)
s2xsy = list(s2xsy)
s2xsymin = min(s2xsy)
s2xsymax = max(s2xsy)

for x in range(-800, 801):
    for y in range(-800, 801):
        if s1xmin < x <s1xmax and s1ymin< y < s1ymax :
            if s2xpymin < x+y < s2xpymax and s2xsymin < x-y < s2xsymax:
                print('YES')
                sys.exit()

print('NO')


t, m = input(), input()
n, d = int(t), len(t)
s, p = 0, 1
j = len(m)
while j:
    i = max(0, j - d)
    k = int(m[i: j])
    if k >= n:
        i += 1
        k = int(m[i: j])
    while m[i] == '0': i += 1
    j = i
    s += k * p
    p *= n
print(s)


#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys, io
import re, math
start = time.clock()
l=list(raw_input())
while 1:
    ans,chk=0,[]
    stp=set(l)
    if len(stp)==len(l):
        cnt=0
        break
    for i in range(len(l)):
        if l[i] not in chk:
            cnt,j=2,i+1
            while l[i]!=l[j]:
                cnt+=1
                j+=1
            ans=max(ans,cnt)
            chk.append(l[i])
    break
print ans


a = map(int, raw_input().split())
n = a[0]
m = a[1]

ans = (2**m) - 1
ans = ans**n
ans = ans % 1000000007
print(ans)


n,m=map(int,raw_input().split())
a=1<<m
a-=1
k=n-1
f=a
M=pow(10,9+7)
if n==1:
    print a
else:
    print (a%M)*(pow(f,k,M))%M


def fastExp(b,n):
    def even(n):
        if n % 2 == 0:
            return 1
        return 0

    if n == 1:
        return b

    a = 1
    if not even(n):
        a = b
        n -= 1

    while n > 1:
        b *= b
        n /= 2
    b *= a
    return b

n1, m1 = map(int, input().split())
a = (1 << m1) - 1
print(fastExp(a, n1))


n,m=map(int,input().split())
mod=1000000007
x=(1<<n)
ans=(m*x)
ans+=1
print(ans%mod)


from collections import defaultdict
letters = 'ACGT'
P = 10**9 + 9
n,m = map(int,raw_input().split())
v = [raw_input() for _ in xrange(m)]
d = {'':0}
c = 1
a = defaultdict(dict)
for s in v:
    p = 0
    for j in xrange(len(s)):
        x = s[:j+1]
        if x not in d:
            d[x]=c
            c+=1
        a[p][s[j]]=d[x]
        p = d[x]
for s in v:
    for x in letters:
        z = s+x
        for j in xrange(len(z)):
            if z[j:] in d:
                a[d[s]][x]=d[z[j:]]
                break
#print d
#print a
d0,v0 = d,v
d = defaultdict(int)
d[0] = 1
for i in xrange(n):
    dn = defaultdict(int)
    for j in xrange(c):
        for x,v in a[j].iteritems():
            dn[v]+=d[j]
            dn[v]%=P
    #print dn
    d = dn

print sum(d[d0[s]] for s in v0)


# ____________R.S____________
import os
import sys
from io import BytesIO, IOBase

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

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def inin():
    return int(input())
def inar():
    return list(map(int,input().split()))
# end fastio

Testcase=1
for _ in range(Testcase):
	st='codeforces'
	k=inin()
	print(st+'s'*(k-1))


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 deque
from collections import Counter
# ls=list(map(int,input().split()))
# for i in range(m):
# for i in range(int(input())):
#n,k= map(int, input().split())
#for  _ in range(int(input())):
    #n,k= map(int, input().split())
    #arr = list(map(int, input().split()))
n=int(input())
t="codeforces"
ans=t+"s"*(n-1)
print(ans)


import os
import sys
from io import BytesIO, IOBase
# 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")

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

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

from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

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

def main():
    n = N()
    res = 'codeforces'
    res+='s'*(n-1)
    print(res)

if __name__ == "__main__":
    main()


import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s); sys.stdout.write('\n')
def wi(n): sys.stdout.write(str(n)); sys.stdout.write('\n')
def wia(a, sep=' '): sys.stdout.write(sep.join([str(x) for x in a])); sys.stdout.write('\n')

def main():
    n = ri()
    s = rs()
    for d in range(1, n+1):
        if n % d > 0:
            continue
        s = [d::-1] + s[d+1:]
    ws(s)

if __name__ == '__main__':
    main()


import sys
n, a = map(int, input().split())
t = [0]
t += [int(x) for x in input().split()]
crim = t[a]
for i in range(1,n+1)
    if (a-i<1) and (a+i>n):
        break
    if a-i<1:
        if t[a+i]==1:
            crim += 1
		elif a+i>n:
		    if t[a-i]==1:
			   crim += 1
		elif t[a-i]*t[a+i]==1:
			crim +=2
print(crim)


n = int(input())
count = 0
for i in range(1, n + 1):
    if n // i > 1:
        count += 1
    elif n // i == 1:
        count += 1
        break
    else:
        break

print(count)


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

N = int(raw_input())

if N == 1:
	print(1)
else:
	answer = 2
	for i in xrange(2, N):
		if N/i >= 2:
			answer += 1
		else:
			break
	print(answer)


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


a, b = map(int, input().split())
if a == 0 || b == 0:
    if a + b == 1:
        print ("YES")
    else:
        print ("NO")
else:
    if abs(a-b) <= 2:
        print ("YES")
    else:
        print ("NO")


import sys
# a simple parser for python. use get_number() and get_word() to read
def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield(number)

input_parser = parser()

def get_word():
    global input_parser
    return next(input_parser)

def get_number():
    data = get_word()
    try:
        return int(data)
    except ValueError:
        return float(data)

def done(x,y):
    print("%d %d"%(x,y))
    sys.exit(0)

def die():
    print(-1)
    sys.exit(0)

def ext_gcd(a,b):
    if b != 0:
        tmp = ext_gcd(b,a%b)
        return [tmp[1], tmp[0] - (a//b)*tmp[1]]
    return [1,0]

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

n = get_number()
m = get_number()
x = get_number()
y = get_number()
vx = get_number()
vy = get_number()

if vx == 0 :
    if x != 0 and x != n :
        die()
    if x == 0:
        if vy > 0:
            done(0,m)
        else:
            done(0,0)
    if x == n:
        if vy > 0:
            done(n,m)
        else:
            done(n,0)

if vy == 0 :
    if y != 0 and y != m:
        die()
    if y == 0:
        if vx > 0:
            done(n,0)
        else:
            done(0,0)
    if y == m:
        if vx > 0:
            done(n,m)
        else:
            done(0,m)

g = gcd(vy*n,vx*m)

if (vy*x-vx*y)%g != 0:
    die()

a = vy*n//g
b = vx*m//g
t = (vy*x-vx*y)//g
res = ext_gcd(a,-b)
if res[0]*a + res[1]*(-b) == -1:
    res[0] = -res[0]
    res[1] = -res[1]

alpha = res[0]*t
beta = res[1]*t
k = b//gcd(a,b)
T = (n*alpha-x)//vx

while T<0:
    val = 0
    if vx*k > 0:
        val = 1
    else:
        val = -1
    alpha = alpha + val*k
    T = (n*alpha-x)//vx

val = 0
if vx*k > 0 :
    val = -1
else :
    val = 1

high = 98765432198765432198765432199
low = 0
ans = 0
while high >= low:
    mid = (high+low)//2
    nalpha = alpha + mid*val*k
    nT = (n*nalpha-x)//vx
    if nT >= 0:
        ans = mid
        low = mid+1
    else:
        high = mid-1

alpha = alpha + ans*val*k
T = (n*alpha-x)//vx

X = x + vx*T
Y = y + vy*T
T = t + vy*T
if (X//n)%2 == 0 and (Y//m)%2 == 0 :
    done(0,0)
elif (X//n)%2 == 0:
    done(0,m)
elif (Y//m)%2 == 0:
    done(n,0)
else:
    done(n,m)


def exgcd(a, b):
    if b == 0: return (a, 1, 0)
    g, y, x = exgcd(b, a%b)
    return (g, x, y-x*(a//b))

def crt(a1, m1, a2, m2):
    g = exgcd(m1, m2)[0]

    e1, e2 = a1%g, a2%g
    if e1 != e2: return None

    a1 //= g
    m1 //= g
    a2 //= g
    m2 //= g

    (_, m1i, m2i) = exgcd(m1, m2)

    ans = a1*m2*m2i + a2*m1*m1i

    ans = ans%(m1*m2)
    if ans < 0: ans += m1*m2

    return ans*g + e1

def solve(N, M, x, y, vx, vy):
  if vx == 0:
    if x == 0 or x == N: return (x, 0)
    else: return None
  if vy == 0:
    if y == 0 or y == M: return (y, 0)
    else: return None

  ans = crt(x, N, y, M)
  #print(ans)
  if ans is None: return ans

  xhit, yhit = (ans+N-1) // N, (ans+M-1) // M
  if x == 0: xhit -= 1
  if y == 0: yhit -= 1
  #print(xhit, yhit)

  return (N if xhit%2 == 0 else 0, M if yhit%2 == 0 else 0)

def main():
  N, M, x, y, vx, vy = map(int, input().split())

  swapx, swapy = False, False

  if vx > 0:
    swapx = True
    x = N-x

  if vy > 0:
    swapy = True
    y = M-y

  ans = solve(N, M, x, y, vx, vy)
  if ans is None: print(-1)
  else:
    ax, ay = ans
    if swapx: ax = N-ax
    if swapy: ay = M-ay
    print(ax, ay)

if __name__ == '__main__':
  main()


y,r,b=input().split(' ')
y=int(y)
r=int(r)
b=int(b)
if (y<b-1) and (y<r-2):
    small=y
elif (b-1<y) and (b-1<r-2):
    small=b-1
elif(r-2<b-1) and (r-2<y):
    small=r-2

req=3*req+3
print(req)


# ---------------------------iye ha aam zindegi---------------------------------------------
import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353

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

# -------------------game starts now----------------------------------------------------import math
class TreeNode:
    def __init__(self, k, v):
        self.key = k
        self.value = v
        self.left = None
        self.right = None
        self.parent = None
        self.height = 1
        self.num_left = 1
        self.num_total = 1

class AvlTree:

    def __init__(self):
        self._tree = None

    def add(self, k, v):
        if not self._tree:
            self._tree = TreeNode(k, v)
            return
        node = self._add(k, v)
        if node:
            self._rebalance(node)

    def _add(self, k, v):
        node = self._tree
        while node:
            if k < node.key:
                if node.left:
                    node = node.left
                else:
                    node.left = TreeNode(k, v)
                    node.left.parent = node
                    return node.left
            elif node.key < k:
                if node.right:
                    node = node.right
                else:
                    node.right = TreeNode(k, v)
                    node.right.parent = node
                    return node.right
            else:
                node.value = v
                return

    @staticmethod
    def get_height(x):
        return x.height if x else 0

    @staticmethod
    def get_num_total(x):
        return x.num_total if x else 0

    def _rebalance(self, node):

        n = node
        while n:
            lh = self.get_height(n.left)
            rh = self.get_height(n.right)
            n.height = max(lh, rh) + 1
            balance_factor = lh - rh
            n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
            n.num_left = 1 + self.get_num_total(n.left)

            if balance_factor > 1:
                if self.get_height(n.left.left) < self.get_height(n.left.right):
                    self._rotate_left(n.left)
                self._rotate_right(n)
            elif balance_factor < -1:
                if self.get_height(n.right.right) < self.get_height(n.right.left):
                    self._rotate_right(n.right)
                self._rotate_left(n)
            else:
                n = n.parent

    def _remove_one(self, node):
        """
        Side effect!!! Changes node. Node should have exactly one child
        """
        replacement = node.left or node.right
        if node.parent:
            if AvlTree._is_left(node):
                node.parent.left = replacement
            else:
                node.parent.right = replacement
            replacement.parent = node.parent
            node.parent = None
        else:
            self._tree = replacement
            replacement.parent = None
        node.left = None
        node.right = None
        node.parent = None
        self._rebalance(replacement)

    def _remove_leaf(self, node):
        if node.parent:
            if AvlTree._is_left(node):
                node.parent.left = None
            else:
                node.parent.right = None
            self._rebalance(node.parent)
        else:
            self._tree = None
        node.parent = None
        node.left = None
        node.right = None

    def remove(self, k):
        node = self._get_node(k)
        if not node:
            return
        if AvlTree._is_leaf(node):
            self._remove_leaf(node)
            return
        if node.left and node.right:
            nxt = AvlTree._get_next(node)
            node.key = nxt.key
            node.value = nxt.value
            if self._is_leaf(nxt):
                self._remove_leaf(nxt)
            else:
                self._remove_one(nxt)
            self._rebalance(node)
        else:
            self._remove_one(node)

    def get(self, k):
        node = self._get_node(k)
        return node.value if node else -1

    def _get_node(self, k):
        if not self._tree:
            return None
        node = self._tree
        while node:
            if k < node.key:
                node = node.left
            elif node.key < k:
                node = node.right
            else:
                return node
        return None

    def get_at(self, pos):
        x = pos + 1
        node = self._tree
        while node:
            if x < node.num_left:
                node = node.left
            elif node.num_left < x:
                x -= node.num_left
                node = node.right
            else:
                return (node.key, node.value)
        raise IndexError("Out of ranges")

    @staticmethod
    def _is_left(node):
        return node.parent.left and node.parent.left == node

    @staticmethod
    def _is_leaf(node):
        return node.left is None and node.right is None

    def _rotate_right(self, node):
        if not node.parent:
            self._tree = node.left
            node.left.parent = None
        elif AvlTree._is_left(node):
            node.parent.left = node.left
            node.left.parent = node.parent
        else:
            node.parent.right = node.left
            node.left.parent = node.parent
        bk = node.left.right
        node.left.right = node
        node.parent = node.left
        node.left = bk
        if bk:
            bk.parent = node
        node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
        node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
        node.num_left = 1 + self.get_num_total(node.left)

    def _rotate_left(self, node):
        if not node.parent:
            self._tree = node.right
            node.right.parent = None
        elif AvlTree._is_left(node):
            node.parent.left = node.right
            node.right.parent = node.parent
        else:
            node.parent.right = node.right
            node.right.parent = node.parent
        bk = node.right.left
        node.right.left = node
        node.parent = node.right
        node.right = bk
        if bk:
            bk.parent = node
        node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
        node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
        node.num_left = 1 + self.get_num_total(node.left)

    @staticmethod
    def _get_next(node):
        if not node.right:
            return node.parent
        n = node.right
        while n.left:
            n = n.left
        return n

# -----------------------------------------------binary seacrh tree---------------------------------------
class SegmentTree1:
    def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)

# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
    def __init__(self, data, default=0, func=lambda a, b: a + b):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)

# -------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorials = [1, 1]
        self.invModulos = [0, 1]
        self.invFactorial_ = [1, 1]

    def calc(self, n):
        if n <= -1:
            print("Invalid argument to calculate n!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.factorials):
            return self.factorials[n]
        nextArr = [0] * (n + 1 - len(self.factorials))
        initialI = len(self.factorials)
        prev = self.factorials[-1]
        m = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = prev * i % m
        self.factorials += nextArr
        return self.factorials[n]

    def inv(self, n):
        if n <= -1:
            print("Invalid argument to calculate n^(-1)")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        p = self.MOD
        pi = n % p
        if pi < len(self.invModulos):
            return self.invModulos[pi]
        nextArr = [0] * (n + 1 - len(self.invModulos))
        initialI = len(self.invModulos)
        for i in range(initialI, min(p, n + 1)):
            next = -self.invModulos[p % i] * (p // i) % p
            self.invModulos.append(next)
        return self.invModulos[pi]

    def invFactorial(self, n):
        if n <= -1:
            print("Invalid argument to calculate (n^(-1))!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.invFactorial_):
            return self.invFactorial_[n]
        self.inv(n)  # To make sure already calculated n^-1
        nextArr = [0] * (n + 1 - len(self.invFactorial_))
        initialI = len(self.invFactorial_)
        prev = self.invFactorial_[-1]
        p = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
        self.invFactorial_ += nextArr
        return self.invFactorial_[n]

class Combination:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorial = Factorial(MOD)

    def ncr(self, n, k):
        if k < 0 or n < k:
            return 0
        k = min(k, n - k)
        f = self.factorial
        return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

# --------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
    if a == 1 or n == 0:
        return 1
    if n % 2 == 0:
        s = powm(a, n // 2, m)
        return s * s % m
    else:
        return a * powm(a, n - 1, m) % m

# --------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
    zipped_pairs = zip(list2, list1)

    z = [x for _, x in sorted(zipped_pairs)]

    return z

# --------------------------------------------------product----------------------------------------
def product(l):
    por = 1
    for i in range(len(l)):
        por *= l[i]
    return por

# --------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
    left = 0
    right = n - 1

    count = 0

    while (left <= right):
        mid = int((right + left) / 2)

        # Check if middle element is
        # less than or equal to key
        if (arr[mid] < key):
            count = mid + 1
            left = mid + 1

        # If key is smaller, ignore right half
        else:
            right = mid - 1

    return count

# --------------------------------------------------binary----------------------------------------
def countdig(n):
    c = 0
    while (n > 0):
        n //= 10
        c += 1
    return c
def binary(x, length):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

def countGreater(arr, n, k):
    l = 0
    r = n - 1

    # Stores the index of the left most element
    # from the array which is greater than k
    leftGreater = n

    # Finds number of elements greater than k
    while (l <= r):
        m = int(l + (r - l) / 2)
        if (arr[m] >= k):
            leftGreater = m
            r = m - 1

        # If mid element is less than
        # or equal to k update l
        else:
            l = m + 1

    # Return the count of elements
    # greater than k
    return (n - leftGreater)

# --------------------------------------------------binary------------------------------------
n,k=map(int,input().split())
l=[]
se=set()
for i in range(k):
    a,b,c=map(int,input().split())
    l.append((a,b,c,i))
    se.add(b)
l.sort()
stack=[]
t=0
ans=[0]*n
for i in range(n):
    if t<k:
        while(l[t][0]==i+1):
            stack.append([l[t][2],l[t][1],l[t][-1]])
            t+=1
            if t==k:
                break
    if len(stack)==0:
        continue
    stack.sort(reverse=True)
    for j in range(len(stack)):
        if stack[j][1]==i+1:
            print(-1)
            sys.exit(0)
    if i+1 in se:
        continue
    stack[-1][0]-=1
    ans[i]=stack[-1][2]+1
    if stack[-1][0]==0:
        stack.pop()
for i in range(k):
    ans[l[i][1]-1]=k+1
print(*ans)


n = int(input())
h = int(input())
m = int(input())

houses = []
for i in range (1,n):
    houses.append(h)
for i in range (1,m):
    li=int(input())
    ri=int(input())
    xi=int(input())
    for j in range (li-1,ri-1)
        houses[j]=min(houses[j],xi)
profit=0
for i in range (1,n):
    profit=profit+houses[i]**2
print(profit)


def binomialCoef(n, k):
    C = [[0 for x in range(k+1)] for x in range(n+1)]
    for i in range(n+1):
        for j in range(min(i, k)+1):
            # Base Cases
            if j == 0 or j == i:
                C[i][j] = 1
            # Calculate value using previously stored values
            else:
                C[i][j] = C[i-1][j-1] + C[i-1][j]

    return C[n][k]

def factorial(n):
    return 1 if (n == 1 or n == 0) else n * factorial(n - 1)

t = int(input())
c = binomialCoef(t, t/2)
s = factorial((t/2)- 1) * factorial((t/2)- 1)
ans = (c*s)/2
print(ans)


n, number = map(int input().split())
if number % 2:
    print(number // 2 + 1)
else:
    print((n - number) // 2 + 1)


n = int(input())
i = 2
    factors = {1}
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.add(i)
    if n > 1:
        factors.add(n)
result = 1
for x in factors:
    result *= x
print(result)


a = map(int, raw_input().split());
print max(i + (a[0]-i)/3 + (a[1]-i)/3 + (a[2]-i)/3 for i in range(max(0, min(a)-2, min(a)+1)));


from itertools import permutations

n, k = list(map(int, input().split(" ")))

permutacoes = []

for i in range(n):
  x = list(input())
  permuts = [''.join(x) for x in list(permutations(x))]
  permuts = list(map(int, permuts))
  permutacoes.append(permuts)

menor_dif = 100000

for i in range(len(permutacoes[0])):
  menor = 100000
  maior = 0
  for j in range(n):
    aux = permutacoes[j][i]
    if aux > maior: maior = aux
    if aux < menor: menor = aux
  dif = maior - menor
  if dif < menor_dif: menor_dif = dif

print(menor_dif)


from __future__ import print_function, division
from sys import stdin, stdout
from fractions import gcd
# from math import *
from collections import *
from operator import mul
from functools import reduce
from copy import copy

rstr = lambda: stdin.readline().strip()
rstrs = lambda: [str(x) for x in stdin.readline().split()]
rint = lambda: int(stdin.readline())
rints = lambda: [int(x) for x in stdin.readline().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
pr = lambda args, sep: stdout.write(sep.join(map(str, args)) + '\n')
out = []

n = int(input())
a = rint_2d(n)
mi = min(a)

if mi in a[:2]:
    print(mi * (n - 1))
else:
    print(min(a[0], a[1]) + (n - 2) * mi)


n, k = map(int, input().strip().split())
answ = 0
flag = False
if k == 0 or n == k:
    print(0, 0)
else:
    for i in range(1, n, 3):
        k -= 1
        if i + 1 <= n - 1:
            answ += 2
        elif i  == n - 1:
            answ += 1
        if k == 0:
            break
        if i == n - 3:
            flag = True
    if k == 0:
        print(1, answ)
    elif flag:
        print(1, answ - k + 1)
    else:
        print(1, answ - k)


n=int(input())
ch=input()
l=["a","e","u","i","o","y"]
i=0
while(i<len(ch)-1):
    if (ch[i] in l):
        if(ch[i+1] in l):
            ch=ch[:i+1]+ch[i+2:]
        else:
            i=i+1
print(ch)


import fileinput;

str = input();
sstr = str.split(' ')
a,b,w,x,c = int(sstr[0]),int(sstr[1]),int(sstr[2]),int(sstr[3]),int(sstr[4])

dif = c-a
count = 0
while dif > 0:
    if (b >= x):
        factor = min(int((b - x)/x)+1,dif)
        dif = dif-factor
        b = b - x*factor
    else:
        factor = int( (x-b-1)/(w-x) )+1
        b = factor*(w-x)+b
        count = count+factor

print(count+(c-a))


import sys

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

a, b, w, x, c = [long(x) for x in raw_input().split()]

t = c - a
hash = {}

if t <= 0:
    print 0
else:
    cur_t = 0

    while 0 < t:
        #print cur_t
        if b >= x:
            if x <= 0:
                print t
                sys.exit()
            else:

                cur_t += b/x
                t -= b/x
                b -= (b/x)*x
        else:
            if (w-x) <= 0:
                print cur_t + (t-cur_t)/2
                sys.exit()
            else:
                delt = max((x-b)/(w-x),1)
                b += (w-x)*delt
                #t += delt
                cur_t += delt
        #if t >0:
        #    if b in hash:
        #        del_t = t - hash[b][1]
        #        del_step = cur_t - hash[b][0]
        #        times = t / -del_t
        #        cur_t += del_step*times
        #        t += del_t * times
        #    else:
        #        hash[b] = [cur_t, t]

    print cur_t + t


def search(a,n,k):
    l=0
    h=n
    while l<=h:
        mid=(l+h)//2
        if n-mid==a[mid]-k:
            return n-mid
        elif n-mid>a[mid]-k:
            l=mid+1
        else:
            h=mid-1
    return 0
if __name__ == "__main__":
    n,k=map(int,input().split())
    a=[]
    sum=0
    for i in range(n+1):
        sum=sum+i
        a.append(sum)
    c=search(a,n,k)
    print(c)


def checkr(i,j):
    flag=0
    cnt=0

    try:
        for temp in xrange(i,i+5):
            if mat[temp][j]=="X":
                cnt+=1
            elif mat[temp][j]=="." and flag==0:
                flag=1
                cnt+=1
            else:
                break
        if cnt==5:
            return True
        elif cnt==4 and mat[i-1][j]=="." and flag==0:
            return True
    except:
        if cnt==4 and mat[i-1][j]=="." and flag==0:
            return True
    return False

def checkc(i,j):
    flag=0
    cnt=0

    try:
        for temp in xrange(j,j+5):
            if mat[i][temp]=="X":
                cnt+=1
            elif mat[i][temp]=="." and flag==0:
                flag=1
                cnt+=1
            else:
                break
        if cnt==5:
            return True
        elif cnt==4 and mat[i][j-1]=="." and flag==0:
            return True
    except:
        if cnt==4 and mat[i][j-1]=="." and flag==0:
            return True
    return False

def checkd(i,j):
    flag=0
    cnt=0

    try:
        for temp in xrange(5):
            if mat[i+temp][j+temp]=="X":
                # print i+temp,j+temp
                cnt+=1
            elif mat[i+temp][j+temp]=="." and flag==0:
                # print i+temp,j+temp
                flag=1
                cnt+=1
            else:
                break
        if cnt==5:
            return True
        elif cnt==4 and mat[i-1][j-1]=="." and flag==0:
            return True
    except:
        if cnt==4 and mat[i-1][j-1]=="." and flag==0:
            return True

    return False

def checkdr(i,j):
    flag=0
    cnt=0

    try:
        for temp in xrange(5):
            if mat[i+temp][j-temp]=="X":
                # print i+temp,j+temp
                cnt+=1
            elif mat[i+temp][j-temp]=="." and flag==0:
                # print i+temp,j+temp
                flag=1
                cnt+=1
            else:
                break
        if cnt==5:
            return True
        elif cnt==4 and mat[i-1][j+1]=="." and flag==0:
            return True
    except:
        if cnt==4 and mat[i-1][j+1]=="." and flag==0:
            return True

    return False

mat=[]
for i in xrange(10):
    temp = raw_input()
    mat.append(temp)

poss=False

for i in xrange(10):
    for j in xrange(10):
        if mat[i][j]=='X':
            poss = checkr(i,j) or checkc(i,j) or checkd(i,j) or checkdr(i,j)
        if poss:
            print 'YES'
            exit()
print 'NO'


grid = []
for i in range(10):
    grid.append(list(raw_input()))
f = 0
for i in range(10):
    for j in range(10):
        if grid[i][j]=='.':
            grid[i][j] = 'X'
            for k in range(10):
                cnt = 0
                for l in range(10):
                    if grid[k][l:l+5].count('X')==5:
                        f = 1
                    if grid[l][k]=='X':
                        cnt += 1
                    else:
                        cnt = 0
                    if cnt==5:
                        f = 1
            for k in range(10):
                cnt = 0
                for l in range(10-k):
                    if cnt[k-l][l]=='X':
                        cnt += 1
                    else:
                        cnt = 0
                    if cnt==5:
                        f = 1
            for k in range(10):
                cnt = 0
                for l in range(10-k):
                    if cnt[k+l][l]=='X':
                        cnt += 1
                    else:
                        cnt = 0
                    if cnt==5:
                        f = 1
            grid[i][j] = 'X'
if f:
    print "YES"
else:
    print "NO"


def rotate90(dim, arr):
    new = []
    for col in xrange(dim):
        new_row = ''
        for row in xrange(dim-1, -1, -1):
            new_row += arr[row][col]
        new.append(new_row)
    return new

def vertical_flip(dim, arr):
    new = []
    for row in xrange(dim):
        new.append(arr[row][::-1])
    return new

def horizontal_flip(dim, arr):
    new = []
    for row in xrange(dim-1, -1, -1):
        new.append(arr[row])
    return new

def check(dim, arr1, arr2):
    for row in xrange(dim):
        if arr1[row] != arr2[row]:
            return False
    return True

n = input()
map1 = []
for ni in xrange(n):
    map1.append(raw_input().strip())
map2 = []
for nii in xrange(n):
    map2.append(raw_input().strip())
ok = False
if check(n, map1, map2) == True:
    ok = True
    print True
map1_v = vertical_flip(n, map1)
if ok == False and check(n, map1_v, map2) == True:
    ok = True
    print True
map1_h = horizontal_flip(n, map1)
if ok == False and check(n, map1_h, map2) == True:
    ok = True
    print True
map1_vh = horizontal_flip(n, map1_v)
if ok == False and check(n, map1_vh, map2) == True:
    ok = True
    print True
map1_90 = rotate90(n, map1)
if ok == False and check(n, map1_90, map2) == True:
    ok = True
    print True
map1_90_v = vertical_flip(n, map1_90)
if ok == False and check(n, map1_90_v, map2) == True:
    ok = True
    print True
map1_90_h = horizontal_flip(n, map1_90)
if ok == False and check(n, map1_90_h, map2) == True:
    ok = True
    print True
map1_90_vh = horizontal_flip(n, map1_90_v)
if ok == False and check(n, map1_90_vh, map2) == True:
    ok = True
    print True
map1_180 = rotate90(n, map1_90)
if ok == False and check(n, map1_180, map2) == True:
    ok = True
    print True
map1_180_v = vertical_flip(n, map1_180)
if ok == False and check(n, map1_180_v, map2) == True:
    ok = True
    print True
map1_180_h = horizontal_flip(n, map1_180)
if ok == False and check(n, map1_180_h, map2) == True:
    ok = True
    print True
map1_180_vh = horizontal_flip(n, map1_180_v)
if ok == False and check(n, map1_180_vh, map2) == True:
    ok = True
    print True
map1_270 = rotate90(n, map1_180)
if ok == False and check(n, map1_270, map2) == True:
    ok = True
    print True
map1_270_v = vertical_flip(n, map1_270)
if ok == False and check(n, map1_270_v, map2) == True:
    ok = True
    print True
map1_270_h = horizontal_flip(n, map1_270)
if ok == False and check(n, map1_270_h, map2) == True:
    ok = True
    print True
map1_270_vh = horizontal_flip(n, map1_270_v)
if ok == False and check(n, map1_270_vh, map2) == True:
    ok = True
    print True
if ok == False:
    print False


def rotate(a,d):
	# 90 180 270
	if d==0:
		return a
	ret = [[0 for x in range(n)] for y in range(n)]

	for i in range(n):
		for j in range(n):
			ret[n-1-j][i]=a[i][j]
	d -= 90
	return rotate(ret,d)

def flip(a,v):
	ret = [[0 for x in range(n)] for y in range(n)]
	if v:
		for i in range(n):
			for j in range(n):
				ret[n-i-1][j] = a[i][j]
	else:
		for i in range(n):
			for j in range(n):
				ret[i][n-j-1] = a[i][j]
	return ret

n=int(raw_input())
a=[]
b=[]

# print range(0,n)

for i in range(0,n):
	a.append(raw_input())
for i in range(0,n):
	b.append(raw_input())
ay = [[0 for x in range(n)] for y in range(n)]
for i in range(n):
	for j in range(n):
		ay[i][j] = a[i][j]
a = ay

by = [[0 for x in range(n)] for y in range(n)]

for i in range(n):
	for j in range(n):
		by[i][j] = b[i][j]
b = by

# print 'a=',a,'b=',b

phase = [rotate(a,360),rotate(a,90),rotate(a,180),rotate(a,270)]
p = []
for item in phase:
	p.append(item)
	p.append(flip(item,1))
	p.append(flip(item,0))

if b in p:
	print 'TRUE'
else:
	print 'NO'

# print a[1][2]


l, r, x, y, k = map(int, input().split())

answer = 'NO'

for b in range(x, y + 1, 1):
  if (b*k <= r and b*k >= l):
    answer = 'YES'

print(answer)


n = int(input())
if n%2 !=0:
    print("NO")
else:
    tiquete=input()
    cuatros = tiquete.count("4")
    sietes = tiquete.count("7")
    if cuatros+sietes==n:
        mitad1 = tiquete[:int(len(tiquete)/2)]
        mitad2 = tiquete[int(len(tiquete)/2):(len(tiquete))]
        print(mitad1,mitad2)
        cuatros1 = mitad1.count("4")
        sietes1 = mitad1.count("7")
        cuatros2 = mitad2.count("4")
        sietes2= mitad2.count("7")
        if cuatros1==cuatros2 and
         sietes1==sietes2:
            print("SI")
        else:
            print("NO")


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

temp = sorted(a, reverse=True)
height = i = 0
while height < k and i < n:
  height += temp[i]
  i += 1

if i = n:
  print(-1)
else:
  print(i)


l=[]
j=1
while len(l)<1000000001:
    for i in range(j):
        l.append(j)
    j+=1
print l[input()-1]


n = int(input())
res = 0

if n < 5:
    res = 1
else:
    floor = 1
    maxCardForRooms = 2
    while maxCardForRooms < n:
        if (n - 2*floor)%3 == 0:
            res += 1
        floor += 1
        maxCardForRooms = 0
        for i in range(floor):
            maxCardForRooms += 2+3*i
    if maxCardForRooms == n :
        res += 1

print(res)


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-9;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */

ll x[100005];
ll y[100005];

int main(void) {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    ll n;
     cin >> n;
    forn(i,n){
     cin >> x[i] >> y[i];
    }
    ll ans = 0;
    sort(x,x+n);
    sort(y,y+n);
    ll sx = 0;
    ll last = 0, L = 0;
    for(ll i=1;i<n;i++){
     ll now = (x[i]-x[i-1]);
     ll add = 0;
     add = last + 2*now*L + i*now*now;
     sx += add;
     last = add;
     L += i*now;
    }
    ll sy = 0;
    last = 0; L = 0;
    for(ll i=1;i<n;i++){
     ll now = (y[i]-y[i-1]);
     ll add = 0;
     add = last + 2*now*L + i*now*now;
     sy += add;
     last = add;
     L += i*now;
    }
    ans = sx+sy;
    cout << ans << endl;
    return 0;
}


import datetime
x=datetime.datetime.strptime(input(),"%a:%b:%c")
y=datetime.datetime.strptime(input(),"%a:%b:%c")
print(abs((x-y).days))


a = [int(i) for i in input().split()]
if min(a[:len(a)-2]) < a[4]:
    print(0)
elif min(a[:len(a)-2]) > a[5]:
    print(a[5] - a[4])
else:
    print(min(a[:len(a)-2])-a[4])


def main():
    from sys import stdin, stdout
    dayNum={"saturday" : 0, "sunday" : 1, "monday" : 2, "tuesday" : 3, "wednesday" : 4, "thursday" : 5, "friday" : 6}
    day1, day2=tuple(stdin.read().split())
    day1=dayNum[day1]
    day2=dayNum[day2]
    stdout.write("YES\n" if (day1+28)%7==day2 or or (day1+30)%7 == day2 or (day1+31)%7 == day2 else "NO\n")

if __name__=='__main__':
    main()


import sys
b = 'sabcdefgh'
a1,a2,a3,a4 = map(str,input().split())
x1 = b.index(a1[0])-1
y1 = int(a1[1]) -1
x2 = b.index(a2[0])-1
y2 = int(a2[1]) -1
x3 = b.index(a3[0])-1
y3 = int(a3[1]) -1
x4 = b.index(a4[0])-1
y4 = int(a4[1]) -1
c = []
for i in range(8):
    c.append([0]*8)
for i in range(8):
    if c[x1][i] != 1:
        c[x1][i] = 1
    else:
        break
for i in range(8):
    if c[x2][i] != 1:
        c[x2][i] = 1
    else:
        break
for i in range(8):
    if c[i][y1] != 1:
        c[i][y1] = 1
    else:
        break
for i in range(8):
    if c[i][y2] != 1:
        c[i][y2] = 1
    else:
        break
c[x1][y1] = 0
c[x2][y2] = 0
for i in range(-1,2):
    for j in range(-1,2):
        if x3 + i> -1 and x3+ i < 8 and y3+j > -1 and y3+j < 8:
            c[x3 + i][y3 + j] = 1

for i in range(-1,2):
    for j in range(-1,2):
        if x4 + i> -1 and x4+ i < 8 and y4+j > -1 and y4+j <8 :
            if c[x4 + i][y4 + j] == 0:
                print("OTHER")
                sys.exit()
print("CHECKMATE")


n, m = map(int, input().split())
ost = [0] * m
for i in range(1, n + 1):
    d = i % m
    ost[d ** 2 % m] += 1
s = ost[0] * (ost[0] - 1) // 2 + ost[0]
for i in range(1, m // 2):
    s += ost[i] * ost[m - i] * 2
print(s)


k=int(input())
s='c'*k
s+='odeforces'
print(s)


import sys
import math as mt
input=sys.stdin.buffer.readline
#t=int(input())
t=1
for __ in range(t):
    #a,b,n=map(int,input().split())
    k=int(input())
    s='codeforces'
    cnt=1
    s1='s'
    k-=1
    while cnt*2<k:
        s1+=s1
        cnt*=2
    #if k-cnt>=0:
    #print(s1)
    if k-cnt>0:
        s1+=s1[:k-cnt]
    #print(s1)
    if k>=1:
        s+=s1
    print(s)

    #n=int(input())
    #l=list(map(int,input().split()))


import sys
input=sys.stdin.readline
k=int(input())
if k<=100000000:
    print("codeforces",end="")
    k-=1
    for i in range(0,k):
        print('s',end="")
    print()
else:
    k-=1
    st=['s']*100000000
    s="".join(a for a in st)
    n=k%100000000
    ct=k//100000000
    for i in range(0,ct):
        print(s,end="")
    for i in range(0,n):
        print('s',end="")
    print()


k = int(input())
s = 'codeforces'
if k == 1:
	print(s)
else:
	print(s + (k-1)*'s')


def gcd(xx,yy):
    x, y = sorted([xx,yy])
    while y != 0:
        r = x%y
        x = y
        y = r
    return x

def xgcd(aa, bb):
    """return (g, x, y) such that a*x + b*y = g = gcd(a, b)"""
    x0, x1, y0, y1 = 0, 1, 1, 0
    while a != 0:
        q, bb, aa = bb // aa, aa, bb % aa
        y0, y1 = y1, y0 - q * y1
        x0, x1 = x1, x0 - q * x1
    return bb, x0, y0

a, b, c = [int(x) for x in input().split()]
d,s,t = xgcd(a,b)

if c%d == 0 and s>=0 and t>=0:
    print("Yes")
else:
    print("No")


n=int(input())
n+=1
n=list(str(n))

if len(n)==1:
    print(n[0]-1)
    exit()
mi=9**(len(n)-1)
for i in range(1,len(n)+1):
    if n[i-1]!=0:
        new=1
        for l in range(i-1):
            new*=int(n[l])
        new*=int(n[i-1])-1
        new*=9**(len(n)-i)
        mi=max(mi,new)
print(mi)


def checkprime(n):
    flag=False
    div=2
    while div<n:
        if n%div==0:
            flag=True
            break
        div+=1
    if flag:
        return 1
    else:
        return 0
n,m=map(int,input().split())
count=0
while count!=1:
    i=n+1
    if i>m:
        break
    prime=checkprime(i)
    if prime==0:
        if i==m:
            print("YES")
            count=1


n=int(input())
a1,a2,a3=list(map(int,input().rstrip().split())
b1,b2,b3=list(map(int,input().rstrip().split())
ans=[0,0]
ans[1]=min(a1,b2)+min(a2,b3)+min(a3,b1)
ans[0]=max(0,b1-(a1+a2),b2-(a2+a3),b3-(a1+a3))
print(*ans)


m,n=map(int,input().split())
v=m*n
b=0
c=0
while(v>=b):
    b=b*2
    if b<=v:
        c=c+1
print(c)


import numpy
n,x,y = map(int, raw_input().split())
ans = x
while ans*100 < y*n: ans += 1
print ans-x


import sys
range = xrange
input = raw_input

MOD = 998244353

import __pypy__
modmul = __pypy__.intop.int_mulmod
mo = lambda a,b: modmul(a,b,MOD)
po = lambda a,b: pow(a,b,MOD)

big = 10**6 + 10
modinv = [1]*big
for i in range(2,big):
    modinv[i] = mo(-(MOD//i), modinv[MOD%i])

fac = [1]
for i in range(1,big):
    fac.append(mo(fac[-1], i))

invfac = [1]
for i in range(1,big):
    invfac.append(mo(invfac[-1], modinv[i]))

def choose(n,k):
    return mo(mo(fac[n], invfac[k]), invfac[n-k])

def par(x):
    return -1 if x & 1 else 1

n = int(input())

ans = 0
for i in range(1, n + 1):
    base = -po(3, n - i)
    tmp = po(base + 1, n) - po(base, n)
    ans += par(i + 1 + n) * mo(choose(n, i), tmp)

extra = 0
for i in range(1, n + 1):
    extra += par(i + 1) * mo(choose(n, i), po(3, n * (n - i) + i))
print (3 * ans + 2 * extra) % MOD


import math

def solve(cheese):
    ans = 0
    while cheese != k:
        for d in [2, 3, 5]:
            if cheese % d == 0:
                if (cheese // d) % k == 0:
                    cheese //= d
                    ans += 1
                    break
        else:
            if a != k:
                print(-1)
                exit()
    return ans

a, b = map(int, input().split())
if a == b:
    print(0)
else:
    k = math.gcd(a, b)
    print(solve(a) + solve(b))


n,s,k = map(int, input().split())
r = list(map(int, input().split()))
r.append(0)
col = input()
mat = []
for i in range(n+1):
    adj = {}
    for j in range(n):
        if i == n:
            adj[j] = abs((s-1)-j)
        else:
            if col[i] != col[j] and r[i] < r[j]:
                adj[j] = abs(i-j)
    mat.append(adj)
# print(*mat, sep='\n')

mem = [{} for i in range(n+1)]
# print(mem)

def get(s, k):
    # print(mem)
    if mem[s].get(k):
        return mem[s].get(k)
    if r[s] >= k:
        mem[s][k] = 0
    else:
        mi = None
        for nei in mat[s]:
            ncost = get(nei, k-r[s])
            if ncost is None:
                continue
            curr = ncost + mat[s][nei]
            if mi is None or curr < mi:
                mi = curr
        if mi is not None:
            mem[s][k] = mi
    return mem[s].get(k)

# print(mem)

ans = get(n,k)
if ans is not None:
    print(ans)
else:
    print(-1)


n, s, k = list(map(int, input().split()))
amounts = list(map(int, input().split()))
colors = list(input())

dp = [[-1 in range(k + 1)] in range(n)]

def getAns(nth, left):
    if left <= 0:
        return 0
    if dp[nth][left] >= 0:
        return dp[nth][left]

    ret = 999999999
    for i in range(n):
        if amounts[i] <= amounts[nth]:
            continue
        ret = min(ret, abs(nth - i) + getAns(i, left - amounts[i])

    dp[nth][left] = ret
    return ret

ans = 999999999
for i in range(n):
    ans = min(ans, getAns(i, k - data[i]) + abs(s - 1 - i))
print(ans)


a,b = map(int,input().split())
c,d = map(int,input().split())
res = -1
for i in range(,10000):
    if (b+a*i-d) % c == 0 and b+a*i-d > 0:
        res = b+a*i
        break
print(res)


import math

x = int(raw_input())

if x <= 2:
    print 0
elif x <= 5:
    print 1
elif x <= 10:
    print 2
elif x <= 15:
    print 3
else:
    print int(math.ceil(x * 1.0 / 5))


x=[]
sum=0
counter = 1;
for i in range(8):
    x.append(input())
for i in range(8):
    for j in range(8):
        if j==8 and counter==1:
            sum+=1
        if x[j][i]='B':
            counter==1;
        else:
            i+=1
            j=8
for i in range(8):
    for j in range(8):
        if j==8 and counter==1:
            sum+=1
        if x[i][j]='B':
            counter==1;
        else:
            i+=1
            j=8
print(sum)


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

n_8 = 0
q = 0
for x in s:
    if x=='8':
        n_8+=1
    else:
        q+=1
if n_8==0:
    print(0)
else:
    b = False
    while not b:
        if n_8==q//10:
            print(n_8)
            exit()
        else:
            n_8-=1
            q+=1


n, t = map(int,input().split())
a = []
for i in range(0,n+1):
  for j in range(0,n+1-i) :
    for k in range(0,n+1-i-j):
      for s in range(0,n+1-i-j-k):
          a.append([i,j,k,s])

y = list(filter(lambda x: sum(x)==4,a))
c = []
for q in y :

  if q[0]*5+q[1]*4+q[2]*3+q[3]*2 ==  t :

    c.append(q)

c.sort(key = lambda x : x[3])

print(c[0][-1])


import math

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

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

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

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

print(yay)


n=input()
number=int(n)
arr=[]
i=2
uno=1
if(number==1):
    print(number)
while number != 1 :
    arr.append(number)
    while i<=number:
        if (number%i ==0):
            number=number/i
            arr.append(int(number))
        i=i+1
print(*arr)


import sys
input=sys.stdin.readline
mod = 998244353
sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0: return 1
    elif y == 1	 : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else: return power(x, (y-1)//2)**2 * x % mod

def modinv(a):
    b, u, v = mod, 1, 0
    while b:
        t = a//b
        a, u = a-t*b, u-t*v
        a, b, u, v = b, a, v, u
    u %= mod
    return u

def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NNN = 2*10**5
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, K = map(int, input().split())
if K > N:
    print(0)
else:
    M=N-K
    R = 0
    for i in range(1, M+1):
        R += (-1 if (M-i)%2 else 1) * cmb(M, i) * power(i, N) % mod
    R = R*cmb(N, M)%mod
    if K != 0:
        R = R*2%mod
    print(R)


import sys
input = sys.stdin.buffer.readline
def print(val):
    sys.stdout.write(str(val) + '\n')

def choose(n,k,mod = None):
    if k > n:
        return 0
    k = min(n-k,k)
    total = 1
    for i in range(n-k+1, n+1):
        total*= i
    for i in range(2,k+1):
        total//= i
    return total % 998244353
def factorial(n):
    total = 1
    for i in range(2, n+1):
        total*= i
        total %=998244353
    return total
def place_rooks(n,k):
    if k == 0:
        return factorial(n)
    filled = n - k
    placements_per_filled = 0
    for i in range(filled):
        mult = 1
        for _ in range(n):
            mult *= (filled-i)
            mult %= 998244353
        placements_per_filled += ((-1)**i)*choose(filled,i)*mult
        placements_per_filled %= 998244353
    total = (2*choose(n,filled)*placements_per_filled ) % 998244353
    if k == 0:
        total//= 2
    return total

n, k = map(int,input().split())
print(place_rooks(n,k))


list1 = list(input())
list2 = list(input())

i=0
count=0
f1=0
up_u=0
d_u=0
if len(list1)==1:
    print(0)
    exit()
while i<len(list1)-1:
    if list1[i]=='0':

        if list1[i+1] =='0' and i+2<len(list1)-1 and list1[i+2]=='0':
            if list2[i]=='0' and list2[i+1]=='0' and list2[i+2]=='0':
                count+=2
                up_u=i+2
                d_u=i+2
                i+=3

        elif list1[i+1]=='0' and (list2[i+1]=='0' or list2[i]=='0'):
            up_u=i+1
            if list2[i]==0:
                d_u=i
            else:
                d_u=i+1
            count+=1
            i+=2

        elif list2[i]=='0' and list2[i+1]=='0':
            count+=1
            up_u=i
            d_u=i+1

            i+=2
        else:
            i+=1

    elif list2[i]=='0':
        if list2[i+1]=='0' and (list1[i+1]=='0'):
            count+=1
            up_u=i+1
            d_u=i+1
            i+=2
        else:
            i+=1
    else:
        i+=1

if list1[-1]=='0':

    if up_u<len(list1)-1:

        if d_u<len(list2)-2:
            if list2[-1]=='0' and list2[len(list2)-2]=='0':
                count+=1
print(count)


#include<bits/stdc++.h>
using namespace std;
int n, m, k;
int main(int argc, char const *argv[])
{
	cin >> n >> m >> k;
	if
	cout << m << '\n';
	return 0;
}


from math import sqrt

def tax(n):
    if n == 4:
        return 2
    if n < 4:
        return 1
    prime_lst = [i for i in range(2, n+1)]
    pointer = 0
    while pointer != n-1:
        if prime_lst[pointer] == 0:
            pass
        else:
            multiple = prime_lst[pointer]
            temp = pointer
            while pointer <= n:
                pointer += multiple
                try:
                    prime_lst[pointer] = 0
                except IndexError:
                    pass
            pointer = temp
        pointer += 1
    primes = []
    for i in prime_lst:
        if i != 0:
            primes.append(i)
    count = 0
    lp = 0
    while n > 0:
        try:
            if n - primes[-1-lp] >= 0 and n-primes[-1-lp] != 1:
                n -= primes[-1-lp]
                count += 1
            else:
                lp += 1
        except IndexError:
            lp = 0
    return count

n = int(input())
print(tax(n))


n = int(input())
if n == 1:
	print(499122177)
	exit()
if n == 2:
	print(748683265)
	exit()
dp = [0]*(n+1)
dp[0], dp[1], dp[2] = 1, 1, 1
dp[3] = 2
modulo = 998244353
count1, count2 = dp[1] + dp[3], dp[0] + dp[2]
for i in range(4, n+1):
	if i%2 == 0:
		dp[i] = count1
		count2 += dp[i]
		count2 %= modulo
	else:
		dp[i] = count2
		count1 += dp[i]
		count1 %= modulo
y = 1
for i in range(n):
	y *= 2
	y %= modulo
time = 1
yre = 0
while True:
	al = modulo*time+1
	if al%y == 0:
		yre = al//y
		break
	time += 1
res = (dp[n]*yre)%modulo
print(res)


#!/usr/bin/env python3

import itertools

PRIME = int(998244353)

def ri(string):
    return list(map(int, string.split(' ')))

def power(a, b):
    if b == 0: return 1
    i = 2
    a_power = [a]
    while i <= b:
        a_power.append(a_power[-1]*a_power[-1] % PRIME)
        i *= 2

    bin_b = list(map(int, bin(b)[:1:-1]))
    # print(a_power, bin_b)
    a_power = itertools.compress(a_power, bin_b)
    # print(a_power)
    res = 1
    for p in a_power:
        # print(res, p)
        res = res * p % PRIME
    return res

n = int(input())

sums = []
sums.append(1)
sums.append(1)
for i in range(2, n+1):
    sums.append(sum(sums[-1::-2]) % PRIME)
    # print(f'{i}: {sums[i]}')

# print(sums)
x = sums[n]
# print(x)
y_inv = power(2, n*(PRIME-2))

print(x*y_inv % PRIME)

# sums = []
# sums.append(1)
# sums.append(1)
#     # print(f'{i}: {sums[i]}')
# for i in range(2, n+1):
#     sums.append(sum(sums[-1::-2]) % PRIME)


def Digits(x):
    M = SumOfDigits(1)
    m = 1
    for i in range(2, x + 1):
        temp = SumOfDigits(i)
        if temp >= M and i > m:
            M = temp
            m = i
    return m
def SumOfDigits(n):
    return n % 10 + SumOfDigits(n//10) if n != 0 else 0
print(Digits(int(input())))


flag = True
for i in range(8):
  ls = input()
  temp = ls[0]
  w = sum([1 for s in range(2, len(ls), 2) if(ls[s]==temp)])
  w_sum = sum([1 for s in ls if(s=='W')])
  if(w != 3 || w_sum != 4):
    flag = False
    break
print("YES" if flag else "NO")


p = ["first", "second"]

a = raw_input()
b = raw_input()
c = raw_input()

nx = (a+b+c).count('X')
no = (a+b+c).count('0')
d = nx - no

opts = [a, b, c, a[0]+b[1]+c[2], a[2]+b[1]+c[0]] + list(map("".join, zip(a, b, c))) #列举所有可能的获胜方式
w = ("XXX" in opts) + 2*("000" in opts) - 1   #用一个数字表示获胜者

if (d not in [0, 1]) or (w > 1) or d == w: #字数最多差1+最多同时存在一个获胜模式+先手获胜子数多一（w = 0 ,d =1），后手获胜子数相等(w =1 d= 0)
    print "illegal"
elif w >= 0:
    print "the %s player won" % p[w]
elif nx + no == 9:
    print "draw"
else:
    print p[d]


line1 = input()
line2 = input()

n = len(line1)

res = 0
ind = 0

while ind < n - 1:
    count = 0
    if line1[ind] == '0':
        count += 1

    if line1[ind+1] == '0':
        count += 1

    if line2[ind] == '0':
        count += 1

    if line2[ind+1] == '0':
        count += 1

    if (count == 3):
        res += 1
        ind += 2
    elif count == 4:
        res += 1
        if ind + 2 <= n - 1:
            if line1[ind + 2] == '0' and line2[ind + 2] == '0':
                res += 1
                ind += 3
        else:
            ind += 2
    else:
        ind += 1

print(res)


from math import factorial as fa
n = int(input())
f = [1]
m = 10**9 + 7
mx = 10**6+5
for i in range(1,mx+1):
    f.append(f[-1]*i)
r = f[n]-pow(2,n-1,m)
print(r%m)


n=int(input())
p=list(map(int,input().split()))
ka=list(map(int,input().split()))
so=list(set(p))
po=list(set(ka))
tod=[]
lol=[]
sam=[]
lil=[]
loll=0
tt=[]
lkl=[]
for item in so:
    tod.append(item)
for item in po:
    if item not in tod:
        tod.append(item)
for item in tod:
    lol.append(ka.count(item)+p.count(item))
for item in lol:
    if item%2==0:
        pass
    else:
        loll=1
        break
if loll=1:
    print(-1)
else:
    for item in tod:
        sam.append(p.count(item))
        lol.append(ka.count(item))
    for x in range(n):
        if sam[x]=lol[x]:
            pass
        elif sam[x]>lol[x]:
            tt.append(((sam[x]+lol[x])//2)-lol[x])
        else:
            lkl.append(((sam[x]+lol[x])//2)-sam[x])
    if sum(tt)!=sum(lkl):
        print(-1)
    else:
        print(sum(tt)//2)


n,m,k=[int(s) for s in input().split()]
n,m=max(n,m),min(n,m)
if n+m-2<k:print(-1)
elif n-1<k or m-1<k:
    print(max(m//(k-n+2),n//(k+1)*m))
else:
    print(max(n//(k+1)*m,m//(k+1)*n))


f=raw_input().split(' ')
for i in range(1) :
    f[i]=int(f[i])
a=f[0]
x=0
t=0
while x<a :
    if t%2==0 :
        x=x+1
        t=t+1

    else :
        if (x+2)<=a :
            x=x+2
            t=t+1
        else :
            x=a+1
print t


"""

n=int(z())

for _ in range(int(z())):

x=int(z())

l=list(map(int,z().split()))

n=int(z())

l=sorted(list(map(int,z().split())))[::-1]

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

l=set(map(int,z().split()))

led=(6,2,5,5,4,5,6,3,7,6)

vowel={'a':0,'e':0,'i':0,'o':0,'u':0}

color4=["G", "GB", "YGB", "YGBI", "OYGBI" ,"OYGBIV",'ROYGBIV' ]

"""
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase
from math import ceil, floor
input = sys.stdin.readline
############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
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()))
from math import ceil
def main():
    # Solution Here
    n = inp()
    m = inp()
    mx = 0
    summ = 0
    for _ in range(n):
        temp = inp()
        summ += temp
        mx = max(mx, temp)

    print(ceil((summ+m)/n), mx + m)

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

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

# endregion

if __name__ == "__main__":
    main()


from sys import stdin, stdout, exit

n, m, k = map(int, stdin.readline().split())
d = 1 if stdin.readline()[-1] == 'l' else -1

for i, c in enumerate(stdin.readline(), 1):
    if c == '0':
        if k == 1: k, d = 2, 1
        elif k == n: k, d = n - 1, -1
        else: k += d
        if m == k:
            stdout.write('Controller ' + str(i))
            exit(0)
    else:
        if k == 1: k, d, m = 2, 1, 1
        elif k == n: k, d, m = n - 1, -1, n
        elif d == 1:
            k += 1
            m = 1
        else:
            k -= 1
            m = n

stdout.write('Stowaway')


x=raw_input().split()
n=int(x[0])
m=int(x[1])
k=int(x[2])
direction=raw_input()
moves=raw_input()
for i in range(len(moves)):
	if moves[i]=='0':
		if(k>m):
			if(m!=1):
				m-=1
		else:
			if(m!=n):
				m+=1
		#move cont
		if(direction=="to head"):
			k-=1
			if k==1:
				direction="to tail"
		else:
			k+=1
			if k==n:
				direction="to head"
		if(k==m):
			print "Controller "+str(i+1)
			exit(0);
	if moves[i]=='1':
		if(i==len(moves)-1):
			print "Stowaway"
			exit(0);
		#move cont
		if(direction=="to head"):
			k-=1
			if k==1:
				direction="to tail"
		else:
			k+=1
			if k==n:
				direction="to head"
		if(direction=="to head"):
			m=n
		else:
			m=1


// luogu-judger-enable-o2
read=input()
read=read.split(" ")
a=[0]*4
n=int(read[0])
m=int(read[1])
a[1]=m
a[2]=m
a[3]=m
def mysort():
	for i in range(1,4):
		for j in range(i,4):
			if a[i]>a[j]:
				a[i],a[j]=a[j],a[i]
	return
def getans():
	t=0
	if n==m:
		return 0
	while 0==0:
		mysort();
		t=t+1;
		if a[2]+a[3]-1<=n :
			a[1]=a[2]+a[3]-1
		else:
			a[1]=n
		if a[1]==n and a[2]==n and a[3]==n:
			return t
	return 0;
print(getans())


# area of equilater triangle s**2 * sqrt(3) / 4
from math import sqrt

answers = {}

def solve(s1, s2, s3, y, ite):
    if s1 == y and s2 == y and s3 == y:
        return ite
    if (s1, s2, s3, y) in answers.keys():
        return answers[(s1, s2, s3, y)]
    big = max(max(s1, s2), s3)
    small = min(min(s1, s2), s3)
    other = s1+s2+s3-big-small
    rest = other-small
    new = max(rest+1, y)
    bigg = max(big-1, y)
    ite_min = 300000
    if new == y and bigg == y:
        return solve(small, other, new, y, ite+1)
    for i in range(new, bigg):
        ite_min = min(ite_min, solve(small, other, i, y, 0))
    answers[(s1, s2, s3, y)] = ite_min + ite + 1
    return ite_min + ite + 1

x, y = [int(i) for i in input().split()]
print(solve(x, x, x, y, 0))


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

perm = [0] * n

k = 2 ** (n - 2)

cleft = 0
cright = n - 1

for i in range(1, n + 1):
    if m & k:
        perm[cright] = i
        cright -= 1
    else:
        perm[cleft] = i
        cleft += 1
    k //= 2

print(" ".join(map(str, perm)))


n,k=map(int,raw_input().split())
a=[]
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        a.append(i)
    if i!=n//i:
        a.append(n//i)
a.sort()
print(-1 if len(a)<k else a[k-1])


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

a, b = map(int, input().split())
g = gcd(a, b)
a /= g
b /= g
if a - b == 1 or b - a == 1:
	print("Equal")
elif a < b:
	print("Dasha")
else:
	print("Masha")


n,k,t=map(int,input().split())
s=0
a=[]
for i in range(t):
    if i+1<=k:
        s+=1
        a.append(s)
    elif i+1>n-k and i+1<=n:
        a.append(s)
    else:
        s-=1
        a.append(s)
print(a[t-1])


n = input()
ans = 6
buf = 0
cnt = 6
for i in range(1000000):
    s = str(i).rjust(6,"0")
    if( sum(map(int,list(s[0:3]))) != sum(map(int,list(s[3:]))) ):
        continue
    cnt = 0
    for i in range(len(n)):
        if n[i] != s[i]:
            cnt+=1
    ans = min(ans,cnt)

print (ans)


def solve():
    n, m, k = map(int, input().split())
    if k==1 or k>n:
        print(pow(m, n, 1e9+7))
    elif k==n:
        print(pow(m, (n+1)//2, 1e9+7))
    elif k%2==1:
        print((m*m)%1e9+7)
    elif k%2==0:
        print(m)
solve()


n = int(input())

def f(n):
    return sum([i*(-1 if i % 2 != 0 else 1) for i in range(1, n+1)])

print(f(n))


n=int(input())
st = map(str, input())
if n == 1:
    print(st)
else:

    if st[0]=='0':
        prezero=1
    else:
        prezero=0

    zeroc=0
    for x in st:
        if x == '0':
            zeroc += 1

    zeroc=zeroc-prezero

    answ='1'
    for i in range(0,zeroc):
        answ+='0'

    print(answ)


x = int(input())
k = int(input())
A = int(input())
B = int(input())
if (x < k):
        print(A*(x-1))
    else:
        if (k == 1):
            print (A*(x-1))
        else :
        ans = 0
        while (x != 1):
            if (x % k == 0):
                ans += min ((x - (x//k)) * A, B)
                x = x // k
                else :
                    if (x < k):
                        ans += ((x % k)-1) * A;
                        x -= ((x % k) - 1)
                        else:
                            ans += (x % k) * A;
                            x -= (x%k)
                print(ans)


Y,B=map(int, raw_input().split())
y,g,b=map(int, raw_input().split())
while y:
    Y-=2
    y-=1

while g:
    Y-=1
    B-=1
    g-=1
while b:
    B-=3
    b-=1

print abs(Y+B)


R = lambda:map(int, input().split())
n, m, a, b = R()
t = list(R())
print("Incorrect" if n - m == 1 and min(t) != a and max(t) != b else "Correct")


n=int(input())
ch=input()
s=0
i=0
if ch.count(ch[0])==n:

    print((n+1)//2))
else:
    while i<n:
        for j in range(i+1,n+1):
            a=ch[j+1:n].find(ch[i:j])
            if a>=0:
                s+=1+a-i
                i+=a+j-i
                break
            elif j==n:
                s+=n-i
                i=n

    print(s)


def zip_sorted(a,b):

	# sorted  by a
	a,b = zip(*sorted(zip(a,b)))
	# sorted by b
	sorted(zip(a, b), key=lambda x: x[1])

	return a,b

a   = [int(n1) for n1 in input().split()]
b   = [int(n1) for n1 in input().split()]
c   = [int(n1) for n1 in input().split()]

count = 0
for i in range(10**5):
	for j in range(10**5):
		a[0] = i
		b[1] = j
		if sum(a)==sum(b):
			c[2] = sum(a)-(b[1]+a[0])
			if sum(c)==sum(a)==sum(b)==(c[0]+b[0]+a[0])==(c[1]+b[1]+a[1])==(c[1]+b[1]+a[1]):
				count = 1
				break
	if count==1:
		break

print(*a)
print(*b)
print(*c)

'''
for i in range(n):
for j in range(n):
for k1 in range(len(a)):
for k2 in range(len(a)):
for k3 in range(len(a)):

'''


n = int(input())
pis = [int(pi) for pi in input().split()]
prev, current_gap, odd, even = 'd', 0, 0, 0
first_gap = ('e', 0)
even_gaps, odd_gaps, any_gaps = [], [], []
for pi in pis:
    if pi == 0:
        current_gap += 1
    elif pi % 2 == 0:
        even += 1
        if prev == 'o':
            any_gaps.append(current_gap)
        elif prev == 'e':
            even_gaps.append(current_gap)
        else:
            first_gap = ('e', current_gap)
        prev = 'e'
        current_gap = 0
    else:
        odd += 1
        if prev == 'e':
            any_gaps.append(current_gap)
        elif prev == 'o':
            odd_gaps.append(current_gap)
        else:
            first_gap = ('e', current_gap)
        prev = 'o'
        current_gap = 0

ans = 0
odd_gaps.sort()
even_gaps.sort()
any_gaps.sort()
total_even = n//2
total_odd = n - total_even
rem_odd = total_odd - odd
rem_even = total_even - even
for gap in odd_gaps:
    if rem_odd >= gap:
        rem_odd -= gap
    else:
        ans += 2
for gap in even_gaps:
    if rem_even >= gap:
        rem_even -= gap
    else:
        ans += 2
if current_gap > 0:
    if prev == 'o' and current_gap > rem_odd:
        ans += 1
    else:
        rem_odd -= current_gap
    elif prev == 'e' and current_gap > rem_even:
        ans += 1
    else:
        rem_even -= current_gap

if first_gap[0] == 'o' and first_gap[1] > rem_odd:
    ans += 1
if first_gap[0] == 'e' and first_gap[1] > rem_even:
    ans += 1

for gap in any_gaps:
    ans += 1

print(ans)


v=int(input())
arr=[]
if v==1:
    print(1)
    exit(0)
for i in range(1,v,1):
    if v%i==0:
        continue
    else:
        arr.append(i)
max1=max(arr)
print(v-max1)


a = int(input)
b = int(input)
c = int(input)
if b>a:
    print(c*2 + a*2 + 1)
elif a>b:
    print(c*2 + b*2 + 1)
else:
    print(c*2 + a + b)


#include <bits/stdc++.h>

using namespace std;
struct s
{
    int val,ind;
};
s arr[100003];
bool cmp(s a,s b)
    return a.val<b.val;
}
int main()
{
    int n,i;
    bool works;
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&arr[i].val);
        arr[i].ind=i;
    }
    sort(arr+1,arr+n+1,cmp);
    printf("%d\n",n/2+n%2);
    works=0;
    for (i=1;i<=n;i+=2)
    {
        if (!works) works=1;
        else printf(" ");
        printf("%d",arr[i].ind);
    }
    printf("\n");
    printf("%d\n",n/2);
    works=0;
    for (i=2;i<=n;i+=2)
    {
        if (!works) works=1;
        else printf(" ");
        printf("%d",arr[i].ind);
    }
    printf("\n");
    return 0;
}


T,S,q=map(int,input().split())
while T>S:S*=q;a+=1
print(a)


n,m,k=map(int,input().split())
m-=n
d=0
k-=1
ans=1
while m>1:
  ans+=1
  m-=1
  l=min(d,k)
  r=min(d,n-k-1)
  d+=1
  m-=l
  m-=r

print(ans)


vl,va = map(int,input().split())

step = 1
if(vl==1 and va==1):
    print('Valera')
elif(vl==7 and va == 6):
    print('Vladik')
else:
    while(1):
        if(step % 2 == 1):
            if(vl < step ):
                print('Vladik')
                break
            vl -= step
            va += step
        else:
            if( va < step):
                print('Valera')
                break
            vl += step
            va -= step

        step += 1


from math import *
import sys

dp = {}
for i in range(102):
	for j in range(-101, 102):
		for k in range(102):
			dp[(i, j, k)] = None

def rec(i, parity, m, a):
	if m < 0:
		return -10000000
	elif dp[(i, parity, m)] is not None:
		return dp[(i, parity, m)]
	else:

		parity += (-1 if a[i]%2==0 else 1)

		if i == len(a)-1:
			if parity == 0:
				return 0
			else:
				return -1000000

		best = rec(i+1, parity, m, a)

		if parity == 0:
			best = max(best, 1 + rec(i+1, 0, m-abs(a[i] - a[i+1]), a))

		dp[(i, parity, m)] = best

		return best

def main():

	n, money =  [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]

	ans = rec(1, a[0]%2, money, a)

	print(ans)

if __name__ == "__main__":
	main()


from sys import stdin, stdout
n = int(stdin.readline())
stdout.write(str(n // 7 + max(n % 7, 5) - 5) + ' ' str(n // 7 + min(2, n % 7)))


n,x=map(int,input().split())
n1=list(map(int,input().split()))
nn=[]
for i in n1:
  if i>=0:
    nn.append(i)
nn.sort()
xx=x
if x>nn[0]:
  while xx not in nn:
    xx-=1
  if x not in nn:
    print(x-nn.index(xx)-1)
  else:
    print(x-nn.index(xx)+1)
elif x=0:
  print(0)
else:
  print(x-1)


n,m=map(int,input().split())
if n==1 and m==2:print('Akshat');s=1
if n % 2 ==0 or m % 2 == 0 and s==0:print('Malvika')
elif s==0:print('Akshat')


x=int(input())
y=int(input())
if x>0 and y>0:
    a=0
    b=x+y
    c=x+y
    d=0
elif x<0 and y>0:
    a=x-y
    b=0
    c=0
    d=y-x

elif x<0 and y<0:
    a=x+y
    b=0
    c=0
    d=x+y

elif x>0 and y<0:
    a=0
    b=y-x
    c=x-y
    d=0

print(a,b,c,d)


n = input()
m = input()
a = n.split(':')
b = m.split(':')
h = int(a[0])
h2= int(b[0])
hh = h2+h
r = int(hh//2)
rr = int(hh%2*60+(int(a[1])+int(b[1])))//2
if r<10:
    print('0'+str(r)+':',end="")
    if rr<10:
        print('0'+str(r))
    else:
        print(rr)
else:
    print(str(r)+':',end="")
    if rr<10:
        print('0'+str(r))
    else:
        print(rr)


N , V = map(int, input().split())
chars = [int(x) for x in input().split()]
count = 0
chars.sort()
yo = 0
print chars
for i in range(0, len(chars)):
        yo = yo + chars[i]
if yo <= V:
    print ("YES")
else:
    print ("NO")


n=int(input())
s=input()
b=[]
for i in range(n):
    c=s[i]+s[i+1]
    b.append(c)
def most_frequent(List):
    return max(set(List), key = List.count)
print(most_frequent(b))


import sys
from collections import deque

n = int(sys.stdin.readline())
q = deque()
q.append((0, -1, 0))
h = {}
h[0] = {}
h[0][0] = 1
while q:
    # print q
    i, j, f = q.popleft()
    if i > n or 2 + 3 * (j+1) > n:
        continue
    jj = j + 1
    ii = i + 2 + 3*jj
    if ii not in h:
        h[ii] = {}
    if f + 1 not in h[ii]:
        h[ii][f+1] = 1
    q.append((ii, jj, f + 1))
    q.append((i, jj, f))

if n in h:
    print len(h[n].values())
else:
    print 0

# for i, j in h.items():
#     if i <= n:
#         print i, j


traslated=input()
translation=input()
correct=translated[::-1]
if correct==translation:
    print("YES")
else:
    print("NO")


import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Summarize count of factor within list -- START --
def summarizeList(l):
  sl=sorted(l,key=lambda x:x,reverse=True)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res
# Summarize count of factor within list --- END ---

def main():
  l=LI()
  sm=sum(l)

  sl=summarizeList(l)

  minus_max=0
  for x,c in sl:
    if c>1:
      if c>2:
        minus_max=max(minus_max,=x*3)
      else:
        minus_max=max(minus_max,=x*2)

  return sm-minus_max

# main()
print(main())


l=[int(e) for e in input().split()]
lst=[]
for e in l:
    if l.count(e)!=1:
        lst.append(sum([j for j in l.count(e) if j!=e])
if(lst!=[]):
    print(min(lst))
else:
    print(sum(l))


s = input()

cur = s[0]
cnt = 1
ans = 0

for i in range(1, len(s):
    x = s[i]
    if(cur != x):
        ans = ans + 1
        cnt = 1
        cur = x
    else:
        if(cnt < 5):
            cnt = cnt + 1
        else:
            ans = ans + 1
            cnt = 1
            cur = x

print (ans)


from math import sqrt, ceil
n = int(raw_input())
sqrtn = int(ceil(sqrt(n)))
def linear_search(num):
    result = -1
    for i in range(num):
        digits = map(int, list(str(i)))
        total = i**2 + sum(digits) * i
        if total == n:
            result = i
            break
    return result
print linear_search(sqrtn)


n=input()
def s(x):
    t=0
    while x :
        t+=x%10
        x/=10
    return t
for i in range(1,int(n**0.5)+1):
    if i*i+s(i)*i == n :
        print i
        exit()
print -1


# -*- coding: utf-8 -*-

import math
def num_sum(number):
    result = 0
    while number > 0:
        result += number % 10
        number = number // 10
    return result

n = int(raw_input())
x = int(math.sqrt(n))
prev = -1
for i in range(x,0,-1):
    tmp = i * i + i * num_sum(i) - n
    if tmp>0:
        continue
    elif tmp==0:
        print i;
        break;
    elif tmp<0:
        print "-1";
        break;


import sys
argv = sys.argv
d = float(argv[1])
L = float(argv[2])
v1 = float(argv[3])
v2 = float(argv[4])
center = v1/(v1 + v2) * d
pos = v1/(v1 + v2) * L
time1 = (pos - center) / v1
time2 = ((L - pos) - (d - center)) / v2
print "%.6f" % round(min(time1, time2), 6)


x0,y0,ax,ay,bx,by=map(int,input().split())
xs,ys,t=map(int,input().split())

points=[]
points.append((x0,y0))
#ax* x-1 +bx ay*y-1+by
#nxtp=((x0*ax)+bx,(y0*ay)+by)
#s=abs(nxtp[0]-x0)+abs(nxtp[1]-y0)
#points.append(nxtp)
s=0
while(s<=t or (points[-1][0]<=(xs+t) and points[-1][1]<=(ys+t) ):
	nxtp=((points[-1][0]*ax)+bx,(points[-1][1]*ay)+by)
	s=abs(nxtp[0]-x0)+abs(nxtp[1]-y0)
	points.append(nxtp)

c=0
#print(points)
curr=(xs,ys)
while(t>0):
	s=float('inf')
	p=[]
	for i in points:
		x=abs(curr[0]-i[0])+abs(curr[1]-i[1])
		#print(x,i,s)
		if(x<s):
			p=[x,i]
			#print(p)
			s=x
	if(p[0]>t):
		#print(p[0])
		break
	c=c+1
	t=t-p[0]
	curr=p[1]
	points.remove(p[1])
	#print(p,c,t)
print(c)


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef vector<int> vi;

long long cnk[51] = {1};
int n, p, a[50];
double ans = 0;

double solve(int i, int s, int l)
{
    if(i == n)
    {
        if(s <= p && l == n)
            return s;
        return 0;
    }
    double ans = 0;
    if(s + a[i] > p && l > 0)
        ans = 1.0 * l / cnk[n - l];
    else
        ans = solve(i + 1, s + a[i], l + 1) + solve(i + 1, s, l);
    return ans;
}

int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; ++i)
        scanf("%d", a + i);
    sort(a, a + n);
    scanf("%d", &p);
    for(int i = 1; i <= n; ++i)
        cnk[i] = cnk[i - 1] * (n - i + 1) / i;
    printf("%0.9lf\n", solve(0, 0, 0));
    return 0;
}


a, b, c, d = raw_input().split()
a, b, c, d = int(a), int(b), int(c), int(d)

ratio_a, ratio_b = float(c)/a, float(d)/b

if ratio_a > ratio_b:
    p_num = c*b - d*a
    p_dem = c
    q = b
else:
    p_num = d*a - c*b
    p_dem = d
    q = a

for i in range(2, p_dem + 1):
    while p_num % i == 0 == p_dem % i == 0:
        p_num /= i
        p_dem /= i

for i in range(1, p_num/2):
    while p_num % i == 0 == q % i == 0:
        p_num /= i
        q /= i

if p_num == 0:
    q = 1

print str(p_num) + "/" + str(p_dem * q)


'''
Created on Oct 12, 2014

@author: Ismael
'''

#import time

MOD = 10**9+7
def sumTermsArith1(firstTerm,r,nbTerms):
    return (nbTerms*(2*firstTerm+(nbTerms-1)*r))//2

def solve(a,b):
    s = 0
    for rem in range(1,b):
        reason = rem*b
        s = (s+sumTermsArith1(reason+rem,reason,a))%MOD
    return s

#t = time.clock()
a,b = map(int,input().split())
print(solve(a,b))
#print(time.clock()-t)


p,y=map(int,input().split())
arr=[i for i in range(y+1)]
n=2

while(n<=p):
    if arr[n]!=-1:
        for i in range(n*n,y+1,n):
            arr[i]=-1
    n+=1

c=0
for i in range(y,p,-1):
    if (arr[i]!=-1):
        print(i)
        c=1
        break
if c==0:
    print(-1)


# def sum_digits(n):
#     s = 0
#     while n:
#         s += n % 10
#         n //= 10
#     return s

# n, s = map(int, input().split())

# count = 0
# summ = sum_digits(n)
# # k = sum_digits(n - n%10 - 1)
# # print(k)
# for num in range(n, 9, -1):
# 	if num % 10 == 9:
# 		summ = sum_digits(num)
# 	# print(num, summ)
# 	if num - summ  >= s:
# 		count += 1
# 	summ -= 1

# print(count)

def sum_digits(n):
    s = 0
    while n:
        s += n % 10
        n //= 10
    return s

def binsearch(a, l, r, elem):
	medium = (l + r ) // 2
	s = a[medium] - sum_digits(a[medium])
	s1 = a[medium-1] - sum_digits(a[medium-1])
	s2 = a[medium+1] - sum_digits(a[medium+1])
	while not(s2 >= elem and s < elem): #s >= elem and s1 < elem or
		# print(l,medium,r)
		if s <= elem:
			l = medium
		elif s >= elem:
			r = medium
		k = medium
		medium = (l + r ) // 2
		if k == medium:
			break
		# print(l,medium,r)
		s = a[medium] - sum_digits(a[medium])
		s2 = a[medium+1] - sum_digits(a[medium+1])
	s1 = a[medium-1] - sum_digits(a[medium-1])
	if s >= elem and s1 < elem:
		return medium
	elif s2 >= elem and s < elem:
		return medium + 1
	else:
		return len(a)

n, s = map(int, input().split())
a = [i for i in range(n+1)]

y = binsearch(a, 0, len(a)-1, s)
# print(y)
print(n - y + 1)


from fractions import gcd

a, b, m = map(int,raw_input().split())
s = 1
def win(a,b,m,s):
    k = gcd(a,m)
    if(k<m):
        m = m - k
        s = s + 1
        win(a,b,m,s)
    else:
        if(s%2==0):
            print "1"
        else:
            print "0"

win(a,b,m,s)


'''
d = {1:'Sheldon',2:'Leonard',3:'Penny',4:'Rajesh',5:'Howard'}
n = int(raw_input())
x = [1,2,3,4,5]
for i in xrange(n):
    b = [x[0],x[0]]
    x.pop(0)
    x.extend(b)
print d[x[-1]]
'''

import fractions
s,a,n = [int(c) for c in raw_input().split()]
while True:
    n -= fractions.gcd(s,n)
    if n < 0:
        print "1"
        break
    n -= fractions.gcd(s,n)
    if n < 0:
        print "0"
        break


import sys
from collections import defaultdict
sys.setrecursionlimit(10**9)
def solve(i,n,s,a,dp):
	if(i==n-1):
		if(s=="QAQ"):
			return 1
		return 0
	if(s=="QAQ"):
		return 1
	if(not dp[i+1][s]):
		dp[i+1][s]=solve(i+1,n,s,a,dp)
	if(not dp[i+1][s+a[i]]):
		dp[i+1][s+a[i]]=solve(i+1,n,s+a[i],a,dp)
	return dp[i+1][s]+dp[i+1][s+a[i]]

a=input()
n=len(a)
dp=[defaultdict(lambda:{}) for i in range(n)]
#print(dp)
z=''
print(solve(0,n,z,a,dp))


inp = int(input())
seq = raw_input()

new = ""
i = 0
while i <= (inp):
    sub = (seq[i:i+2])
    #print(" "*i + sub)
    if sub == "UR" or sub == "RU":
        new += "D"
        i+=1
    else:
        new += sub[0]
    i +=1
print(len(new))


import math
import bisect

from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from collections import Counter

I = lambda: int(input())
tup = lambda: map(int, input().split())
lst = lambda: list(map(int, input().split()))

#t = 1
t = I()

while t:
  n=I()
  s=input().split()
  result = []
  for ele in s:
  	count=0
  	for j in ele:
  		if j.isupper():
  			count+=1
  		result.append(count)

  print(max(count))

    t -= 1


n,a,b,x,y=map(int,input().split())
def safe(n,a,b):
	if n>=a and n>=b:
		return True
	return False

def short(n,a,b,x,y):
	rs=[0,0,1,-1]
	cs=[1,-1,0,0]
	q=[(a,b,0)]
	bx=0
	while len(q)!=0:
		xsi=q.pop(0)
		xs,ys,zs=xsi[0],xsi[1],xsi[2]
		if xs==x and ys==y:
			bx=zs
			break

	    for i in range(4):
		    for j in range(4):
			    ri=rs[i]+xs
			    ci=cs[i]+ys
			    if safe(n,ri,ci):
				    q.append((ri,ci,zs+1))

    return bx

print(short(n,a,b,x,y))


n,a,b,c,d=map(int,input().split())
dx=[0,0,-1,1]
dy=[1,-1,0,0]
vis=[[0]*(n+1) for _ in " "*(n+1)]
ok=[[1]*(n+1)]
for i in range(n-1):
    ok.append([1]+[0]*(n-1)+[1])
ok.append([1]*(n+1))
def dfs(x,y,k):
    if x<0 or x>n or y<0 or y>n:return
    if vis[x][y]:return
    if ok[x][y]==0:return
    vis[x][y]=1
    if x==c and y==d:exit(print(min(k,4*n-k)))
    for i in range(4):dfs(x+dx[i],y+dy[i],k+1)
dfs(a,b,0)


# You lost the game.
m = int(input())
r = 0
l = 1
n = 0
k = 0
L = []
while n <= m:
    k += 1
    l *= k
    while l % 10 == 0:
        n += 1
        l = l // 10
    if n == m:
        r += 1
        L += [k]
print(r)
for i in range(r):
    print(L[i],end=" ")


n,k=list(map(int,input().split()))
if n<pow(10,k):
    print(len(str(n))-1)]
elif list(str(n)).count("0")<k:
    print(len(str(n))-1)]
else:
    n=str(n)
    n=n[::-1]
    x=0
    p=0
    for y in n:
        if p!=k:
            if y=="0":
                x-=1
                p+=1
            else:
                x-=1
                pass
        else:
            break
    lk=0
    n=n[::-1]
    for item in n[x:]:
        if item!="0":
            lk+=1
        else:
            pass
    print(lk)


cups = input().split(' ')
medals = input().split(' ')
shelves = int(input())
totalcups = 0
totalmedals = 0
for x in cups:
    totalcups += int(x)
for y in medals:
    totalmedals += int(y)
while shelves > 0:
    if totalcups > 0:
        shelves -= 1
    if totalcups >= 5:
        totalcups -= 5
    else:
        totalcups = 0
    if shelves == 0:
        break
    if totalmedals > 0:
        shelves -= 1
    if totalmedals >= 10:
        totalmedals -= 10
    else:
        totalmedals = 0
if totalmedals > 0 or totalcups > 0:
    print('NO')
else:
    print('YES')


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

n=int(input())
if a % 5 == 0:
    a = a//5
else:
    a = a//5+1
if b%10 == 0:
    b//=10
else:
    b =b//10+1
if n>= a+b:
    print("YES")
else:print("NO")


INF = -100000000
memo = dict()
def func(line, r):
    if line in memo and r in memo[line]:
        return memo[line][r]
    if len(line) == 1:
        which = line[0] == 'T'
        if r % 2 == 1:
            which = not which
        if which: return [INF, INF, 0, 0]
        else: return [1, INF, INF, INF]
    best = [INF, INF, INF, INF]
    for i in range(r+1):
        a = func(line[:len(line)/2], i)
        b = func(line[len(line)/2:], r - i)
        for (j, k) in [(j, k) for j in range(4) for k in range(4)]:
            D = j < 2
            if a[j] == INF or b[k] == INF: continue
            aa = -a[j] if j % 2 else a[j]
            bb = -b[k] if k % 2 else b[k]
            d1, d2 = 0, 1
            if k < 2:
               aa = aa + bb
               if not D: d1, d2 = 2, 3
            else:
               aa = -aa + bb
               if D: d1, d2 = 2, 3
            if aa >= 0: best[d1] = max(best[d1], aa)
            if aa <= 0: best[d2] = max(best[d2], -aa)
    if not line in memo:
        memo[line] = dict()
    memo[line][r] = best
    return best

line = raw_input().strip()
k = int(raw_input())
ans = max(func(line, k))
if ans == INF: print 0
else: print ans


cmd = input().split()
a = cmd[0]*cmd[1] + 2*cmd[3]
b = cmd[0]*cmd[2] + 2*cmd[4]
if a>b:
    print("First")
if a>b:
    print("Second")
if a==b:
    print("Friendship")


#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import os
import 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
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()

def main():
    n, m = map(int, input().split())
    k = [int(x) for x in input().split()]

    d = [[] for _ in range(2 * 10**5 + 1)]
    for j in range(m):
        dj, tj = map(int, input().split())
        d[dj - 1].append(tj - 1)

    def cond(x):
        cash = 0
        _k = k[:]
        for i in range(x):
            cash += 1
            for j in d[i]:
                while cash and _k[j]:
                    _k[j] -= 1
                    cash -= 1
        return 2 * sum(_k) <= cash

    lo, hi = 0, 2 * sum(k) + 1
    while lo < hi:
        mi = (hi + lo) // 2
        if cond(mi):
            hi = mi
        else:
            lo = mi + 1

    print(lo)

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        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):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    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)

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), 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", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()

sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

# endregion

if __name__ == "__main__":
    main()