pa, ta = map(int, input().split())
pb, tb = map(int, input().split())
h, s = map(int, input().split())

ans = 10**18
dp = [10**18] * (h+1)
dp[0] = 0
for hh in range(h+1):
    # propagate dp[hh]
    for _ in range(2):
        for i in range(1, h // (pa - s) + 5):
            now = i * ta
            j = now // tb

            nxt = hh + i * (pa - s) + j * (pb - s)
            if nxt >= h:
                ans = min(ans, dp[hh] + now)

            nxt += pa + pb - s
            nxt = min(nxt, h)
            dp[nxt] = min(dp[nxt], dp[hh] + now + tb - now%tb)

        nxt = min(h, hh + pa + pb - s)
        dp[nxt] = min(dp[nxt], dp[hh] + max(ta, tb))

        pa, pb = pb, pa
        ta, tb = tb, ta

# print(dp)

ans = min(ans, dp[h])
print(ans)


from math import gcd
import sys
import io
import os

# region IO
BUFSIZE = 8192

class FastIO(io.IOBase):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.buffer = io.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(io.IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

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

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

def input(): return sys.stdin.readline().rstrip('\r\n')

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

def read_int_tuple():
    return tuple(map(int, input().split()))

def read_int():
    return int(input())

# endregion

# region local test
# if 'AW' in os.environ.get('COMPUTERNAME', ''):
#     test_no = 2
#     f = open(os.path.dirname(__file__) + f'\\in{test_no}.txt', 'r')

#     def input():
#         return f.readline().rstrip("\r\n")
# endregion

p1, t1 = read_int_tuple()
p2, t2 = read_int_tuple()
h, s = read_int_tuple()
ps1, ps2 = p1 - s, p2 - s

dp = [0] + [1 << 60] * h
for x in range(1, h + 1):
    r1 = t1 + dp[0 if x < ps1 else x - ps1]
    r2 = t2 + dp[0 if x < ps2 else x - ps2]
    dp[x] = r1 if r1 < r2 else r2
    for _ in range(2):
        for c in range(1, x + 1):
            if c * t1 >= t2:
                dmg = (c - 1) * ps1 + (c * t1 - t2) // t2 * ps2 + (ps1 + p2)
                rt = c * t1 + dp[0 if x < dmg else x - dmg]
                if dp[x] > rt: dp[x] = rt

        p1, t1, p2, t2 = p2, t2, p1, t1

print(dp[h])


#from math import ceil, floor #, gcd, log, factorial, comb, perm,
#log10, log2, log, sin, asin, tan, atan, radians
#from heapq import heappop,heappush,heapify #heappop(hq), heapify(list)
#from collections import defaultdict as dd
#mydd=dd(list) for .append
#from collections import deque as dq #deque  e.g. myqueue=dq(list)
#append/appendleft/appendright/pop/popleft
#from bisect import bisect as bis #a=[1,3,4,6,7,8] #bis(a,5)-->3
#import bisect #bisect.bisect_left(a,4)-->2 #bisect.bisect(a,4)-->3
#import statistics as stat  # stat.median(a), mode, mean
#from itertools import permutations(p,r)#combinations(p,r)
#combinations_with_replacement#combinations(p,r) gives r-length tuples,
#in sorted order, with repeated elements#product gives outer product combos
import sys
input = sys.stdin.readline
#print = sys.stdout.write
#sys.setrecursionlimit(100000) #default is 1000
############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))   #.split(','), default is space
#list([0,*map(int,input().split(" "))]) # pad a zero to avoid zero indexing
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
####################################################
t=1
#t = int(input())
for tc in range(t):
    p1,t1=map(int, input().split())
    p2,t2=map(int, input().split())
    h,s=map(int, input().split())
    if t2<t1: p1,t1,p2,t2=p2,t2,p1,t1
#    n=inp()
#    a=inlt()
#    x=list(input().strip("\n").split())
#    s=input().strip("\n")
#    s=input()[:-1]
#    s=insr()
#    occ=dd(list) #dd(int)
#    occ=dict();
#    for i in range(n):occ[i]=[]
#    for i in range(n):
#        occ[i].append(inlt())
#    a=[]
#    for i in range(n):
#        a.append(inlt())
    if (p1)/(t2%t1+t1)>(p1-s)/t1:#wait

    else:#don't wait
        d=(p1-s)/t1+(p2-s)
    ans=0
    print(ans)

#print(*ans,sep=' ')##print("{:.3f}".format(ans)+"%")
#:b binary :% eg print("{:6.2%}".format(ans))
#print(" ".join(str(i) for i in ans))
#print(" ".join(map(str,ans))) #seems faster
#print(a[0] if a else 0)
#prefixsum a=[a1...an] #psa=[0]*(n+1)
#for i in range(n): psa[i+1]=psa[i]+a[i]
#sum[:ax]=psa[x+1] e.g. sum 1st 5 items in psa[5]
#ASCII<->number ord('f')=102 chr(102)='f'
#def binary_search(li, val, lb, ub):
#    while ((ub-lb)>1):
#        mid = (lb + ub) // 2
#        if li[mid] >= val:
#            ub = mid
#        else:
#            lb = mid
#    return lb+1 #return index of elements <val in li
#def binary_search(li, val, lb, ub):
#    ans = -1
#    while (lb <= ub):
#        mid = (lb + ub) // 2
#        if li[mid] > val:
#            ub = mid - 1
#        elif val > li[mid]:
#            lb = mid + 1
#        else:
#            ans = mid  # return index
#            break
#    return ans
##########
#def pref(li):
#    pref_sum = [0]
#    for i in li:
#        pref_sum.append(pref_sum[-1] + i)
#    return pref_sum
##########
#def suff(li):
#    suff_sum = [0]
#    for i in range(len(li)-1,-1,-1):
#        suff_sum.insert(0,suff_sum[0] + li[i])
#    return suff_sum
#############
#def maxSubArraySumI(arr): #Kadane's algorithm with index
#    max_till_now=arr[0];max_ending=0;size=len(arr)
#    start=0;end=0;s=0
#    for i in range(0, size):
#        max_ending = max_ending + arr[i]
#        if max_till_now < max_ending:
#            max_till_now=max_ending
#            start=s;end=i
#        if max_ending<0:
#            max_ending=0
#            s=i+1
#    return max_till_now,start,end
############# avoid max for 2 elements - slower than direct if
#def maxSubArraySum(arr): #Kadane's algorithm
#    max_till_now=arr[0];max_ending=0;size=len(arr)
#    for i in range(0, size):
#        max_ending = max_ending + arr[i]
#        if max_till_now < max_ending:max_till_now=max_ending
#        if max_ending<0:max_ending=0
#    return max_till_now
#############
#def findbits(x):
#    tmp=[]
#    while x>0:tmp.append(x%2);x//=2
#    tmp.reverse()
#    return tmp
##############Dijkstra algorithm example
#dg=[999999]*(n+1);dg[n]=0;todo=[(0,n)];chkd=[0]*(n+1)
#while todo:#### find x with min dg in todo
#    _,x=hq.heappop(todo)
#    if chkd[x]:continue
#    for i in coming[x]:going[i]-=1
#    for i in coming[x]:
#        tmp=1+dg[x]+going[i]
#        if tmp<dg[i]:dg[i]=tmp;hq.heappush(todo,(dg[i],i))
#    chkd[x]=1
################
# adj swaps to match 2 binary strings: sum_{i=1}^n(abs(diff in i-th prefix sums))
###############
##s=[2, 3, 1, 4, 5, 3]
##sorted(range(len(s)), key=lambda k: s[k])
##gives sorted indices [2, 0, 1, 5, 3, 4]
##m= [[3, 4, 6], [2, 4, 8], [2, 3, 4], [1, 2, 3], [7, 6, 7], [1, 8, 2]]
##m.sort(reverse=True,key=lambda k:k[2]) #sorts m according to 3rd elements
#import bisect  #li = [1, 3, 4, 4, 4, 6, 7]#sorted li, use b search, so log(n)
#bisect.bisect(li,4)-->5 #bisect.bisect_left(li,4)-->2
###############
##def chkprime(x):
##    if x==2 or x==3:return True
##    if x%2==0 or x<2:return False
##    for i in range(3,int(x**0.5)+1,2):
##        if x%i==0:return False
##    return True
############### two factoring functions, seems to have the same performance
##def factors(n):
##    f=[];t=2
##    while n>1:
##        if n%t==0:
##            f.append(t);n//=t;t=2
##        else:
##            t+=1
##            if t*t>n:f.append(n);break
##    return f
##################
##def factors(n):
##    f=[]
##    while n > 1:
##        for i in range(2, int((n+0.02)**0.5)+1):
##            if n%i==0:f.append(i);n//=i;break
##        else:
##            f.append(n);n=1
##    return f


from sys import stdin

def solve():
    p1, t1 = map(int, stdin.readline().split())
    p2, t2 = map(int, stdin.readline().split())
    h, s = map(int, stdin.readline().split())

    dp = [float('inf')] * h
    dp[0] = 0

    best_time = float('inf')
    for i in range(h):
        if dp[i] == float('inf'):
            continue

        r1, r2 = t1, t2
        time = dp[i]
        dmg = i
        while dmg < h:
            # fire together
            together_time = time + max(r1, r2)
            together_damage = dmg + p1 + p2 - s
            if together_damage >= h:
                best_time = min(best_time, together_time)
            else:
                dp[together_damage] = min(dp[together_damage], together_time)

            # fire one independently
            dt = min(r1, r2)
            r1 -= dt
            r2 -= dt
            time += dt
            if r1 != r2:
                if not r1:
                    dmg += p1 - s
                    r1 = t1
                else:
                    dmg += p2 - s
                    r2 = t2

        best_time = min(best_time, time)

    print(best_time)

solve()


#!/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 = [set() for _ in range(2 * 10**5 + 1)]
    for j in range(m):
        dj, tj = map(int, input().split())
        d[dj - 1].add(tj - 1)

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

    lo, hi = 0, 2 * 10**5 + 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()


import sys

DEBUG = False

if DEBUG:
    inf = open("input.txt")
else:
    inf = sys.stdin

N, M = list(map(int, inf.readline().split(' ')))
n_items = list(map(int, inf.readline().split(' ')))
sales = []
for _ in range(M):
    sale = list(map(int, inf.readline().split(' ')))
    sales.append(sale)

sales = sorted(sales, key=lambda x: x[0])

# print(N, M)
# print(n_items)
# print(sales)
# last_sales = [0 for _ in range(N)] # last sale day
last_sales = {k: -1 for k in range(N+1)} # for convenience ...
final_sol = 99999999

for i in range(M):
    sale_day, sale_type = sales[i]
    last_sales[sale_type] = sale_day
    if i != M-1: # not last sale
        if sales[i+1][0] == sale_day: # same sale day
            continue

    total = 0
    lasts = last_sales.items()
    lasts = sorted(lasts, key=lambda x: x[1]) # sort by day
    burle = 0
    before_lastday = -1
    for stype, last_sday in lasts:
        if stype == 0:
            continue
        if last_sday == -1:
            # non-sale item
            total += n_items[stype-1]*2
            continue

        if before_lastday == -1:
            burle = last_sday
        else:
            burle += last_sday - before_lastday
        before_lastday = last_sday

        bought = min(burle, n_items[stype-1])
        left = n_items[stype-1] - bought
        burle -= bought
        total += bought + 2*left

    # print(sale_day, total)
    sol = max(sale_day, total)
    if final_sol > sol:
        final_sol = sol

print(final_sol)


import sys,os,math
from collections import Counter, defaultdict
import bisect
from sys import stdin, stdout
from itertools import repeat, izip

# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())

n, m = map(int, raw_input().split())
da = map(int, raw_input().split())
di = defaultdict(list)
total = sum(da)
for i in xrange(m):
    a, b = map(int, raw_input().split())
    di[b].append(a)
for k in di:
    di[k].sort()
l, r = 0, 2*total
while l<r:
    def ck(day):
        p = []
        for k in di:
            idx = bisect.bisect(di[k], day)
            if idx != 0:
                p.append((di[k][idx-1], k))
        tt = total
        cost = 0
        p.sort()
        for ld, k in p:
            by = min(da[k-1], ld-cost)
            cost += by
            tt -= by
        if day-cost>= tt*2:
            return 1
        else:
            return 0
    mid = (l+r)/2
    if ck(mid):
        r = mid
    else:
        l = mid + 1
print l


n, m = input().split()
n = int(n)
m = int(m)
nList = input().split()
bList = [0] * len(nList)
for i in range(len(nList)):
    nList[i] = int(nList[i])
shopD = {}
shopT = {}
oHis = []
mHis = []
maxD = 0
for i in range(m):
    d, t = input().split()
    if nList[int(t) - 1] != 0:
        maxD = max(maxD, int(d))
        if d not in shopD.keys():
            shopD.update({d: [int(t)]})
        else:
            if int(t) not in shopD[d]:
                shopD[d].append(int(t))
        if t not in shopT.keys():
            shopT.update({t: [int(d)]})
        else:
            if int(d) not in shopT[t]:
                shopT[t].append(int(d))
for i, j in shopT.items():
    j = list(dict.fromkeys(j))
    j.sort()
    shopT[i] = j
for i, j in shopD.items():
    j = list(dict.fromkeys(j))
    shopD[i] = j
total = sum(nList)
coin = 0
day = 0
def modifyMis(t, left):
    if left == 0:
        for ii in range(len(mHis))[::-1]:
            if mHis[ii]['t'] == t:
                mHis.pop(ii)
    else:
        for ii in range(len(mHis))[::-1]:
            if mHis[ii]['t'] == t:
                mHis[ii]['n'] = left
while total > 0 and day < maxD:
    coin += 1
    day += 1
    oHis.append({'t': [], 'n': []})
    if str(day) in shopD.keys():
        for t in shopD[str(day)]:
            if nList[t - 1] > 0:
                if bList[t - 1] > 0 and shopT[str(t)][0] != day and coin > nList[t - 1] - bList[t - 1] and len(mHis) > 0 and coin > 0:
                    i = 0
                    j = 0
                    while shopT[str(t)][i] < day:
                        extraC = 0
                        d = shopT[str(t)][i]
                        if t in oHis[d - 1]['t']:
                            indexT = oHis[d - 1]['t'].index(t)
                            extraC += oHis[d - 1]['n'][indexT]
                            bList[t - 1] -= oHis[d - 1]['n'][indexT]
                            total += oHis[d - 1]['n'][indexT]
                            oHis[d - 1]['t'].pop(indexT)
                            oHis[d - 1]['n'].pop(indexT)
                        while j < len(mHis) and mHis[j]['d'] < d:
                            j += 1
                        while extraC > 0 and len(mHis) > j:
                            thisT = mHis[j]['t']
                            thisD = mHis[j]['d']
                            change = min(extraC, mHis[j]['n'])
                            bList[thisT - 1] += change
                            total -= change
                            extraC -= change
                            mHis[j]['n'] -= change
                            modifyMis(thisT, nList[thisT - 1] - bList[thisT - 1])
                            if thisT in oHis[thisD - 1]['t']:
                                oHis[thisD - 1]['n'][oHis[thisD - 1]['t'].index(thisT)] += change
                            else:
                                oHis[thisD - 1]['t'].append(thisT)
                                oHis[thisD - 1]['n'].append(change)
                        i += 1
                        coin += extraC
            buy = min(nList[t - 1] - bList[t - 1], coin)
            if buy != 0:
                oHis[day - 1]['t'].append(t)
                oHis[day - 1]['n'].append(buy)
                total -= buy
                bList[t - 1] += buy
                modifyMis(t, nList[t - 1] - bList[t - 1])
                coin -= buy
            if nList[t - 1] - bList[t - 1] > 0:
                mHis.append({'d': day, 't': t, 'n': nList[t - 1] - bList[t - 1]})
    if coin >= total * 2:
        break
day += max(total * 2 - coin, 0)
print(day)


def main():
    inp = readnumbers()
    ii = 0

    n = inp[ii]
    ii += 1

    m = inp[ii]
    ii += 1

    K = inp[ii:n+ii]
    ii += n

    types = [[] for _ in range(n)]
    for _ in range(m):
        types[inp[ii+1]-1].append(inp[ii] - 1)
        ii += 2

    for t in types:
        if t: t.sort()

    a = 0
    b = 4*10**5 + 10
    while a<b:
        mid = (a+b)//2

        extra = [0]*mid
        for t in range(n):
            if K[t]:
                A = types[t]
                ind = len(A)-1
                while ind >= 0 and A[ind]>=mid: ind -= 1

                if ind>=0:
                    extra[A[ind]] += K[t]

        bought = 0
        money = 0
        for d in range(mid):
            money += 1
            while money and extra[d]:
                money -= 1
                bought += 1
                extra[d] -= 1

        left = sum(K) - bought
        if money >= left*2:
            b = mid
        else:
            a = mid + 1

    print a

######## Python 2 and 3 footer by Pajenegod and c1729

# Note because cf runs old PyPy3 version which doesn't have the sped up
# unicode strings, PyPy3 strings will many times be slower than pypy2.
# There is a way to get around this by using binary strings in PyPy3
# but its syntax is different which makes it kind of a mess to use.

# So on cf, use PyPy2 for best string performance.

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

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

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            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')

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

# Read all remaining integers in stdin, type is given by optional argument, this is fast
def readnumbers(zero = 0):
    conv = ord if py2 else lambda x:x
    A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()
    try:
        while True:
            if s[i] >= b'0' [0]:
                numb = 10 * numb + conv(s[i]) - 48
            elif s[i] == b'-' [0]: sign = -1
            elif s[i] != b'\r' [0]:
                A.append(sign*numb)
                numb = zero; sign = 1
            i += 1
    except:pass
    if s and s[-1] >= b'0' [0]:
        A.append(sign*numb)
    return A

if __name__== "__main__":
  main()


#     Clever Fat Rat
import time
from datetime import datetime

import itertools

max_oats = 10**6 + 1

def weight(p):
    return p[0]

def right(p):
    return p[1][1]

def left(p):
    return p[1][0]

def plus(l, r):
    return (weight(l)+weight(r), (left(l), right(r)))

# 01 can cover 02?
def cover(o1, o2):
    return left(o1) >= left(o2) and right(o1) <= right(o2) and weight(o1) >= weight(o2)

def add_only_unique(oats, oat):
    for idx, o_n in enumerate(oats):
        if oat == o_n or cover(o_n, oat):
            return oats
        if cover(oat, o_n):
            oats[idx] = oat
            return oats
    oats.append(oat)
    return oats

def max_drop(oats):
    max_drop = 0
    for oat in oats:
        max_drop = weight(oat) if  weight(oat) > max_drop else max_drop
    return max_drop

def possible_oats(a, ws):
    oats_list = []
    for idx in range(0, len(a)-1):  # same as len(ws)
        oats = []
        left_oat = a[idx]
        right_only_oat = [e for e in a[idx+1] if not e in left_oat ]
        left_only_oat = [e for e in a[idx] if not e in a[idx+1] ]

        if ((len(a[idx+1]) == 0) or
            (idx != len(a)-2 and max_drop(a[idx+1])+max_drop(a[idx+2]) >= ws[0][idx+1])):
            for l in left_oat:
                if weight(l) >= ws[0][idx]:
                    oats.append(l)

        if ((len(a[idx]) == 0) or
            (idx != 0 and len(oats_list[-1]) != 0)):
            for r in right_only_oat:
                if weight(r) >= ws[0][idx]:
                    oats = add_only_unique(oats, r)

        for c in itertools.product(left_only_oat,right_only_oat):
            (l,r) = c
            if weight(r)+weight(l) >= ws[0][idx] and right(l) < left(r):
                oats = add_only_unique(oats, plus(l,r))

        if len(oats) > 30:
            oats.sort(key=weight, reverse=True)
            oats = oats[:30]
        oats_list.append(oats)
    return oats_list

def is_break_all(limit, oats_list):
    for idx, oat in enumerate(oats_list):
        for o in oat:
            if weight(o) >= limit[idx]:
                return True
    return False

def fatrat(state):
#    print state

    (a, ws) = state
    ws = map(lambda x: [max_oats]+x+[max_oats], ws)

    goal_oats = []
    pre_goal_oat = [0, 0]
    for idx in range(len(ws)-1,-1,-1):
        goal_oat = []
        for jdx in range(1,len(ws[idx])-1):
            goal_oat.append(max(ws[idx][jdx],min(pre_goal_oat[jdx-1], pre_goal_oat[jdx])))
        goal_oats.append(goal_oat)
        pre_goal_oat = [max_oats] + goal_oat + [max_oats]
    goal_oats.reverse()
    ws = map(lambda x: x[1:-1], ws)

    oats_list = []
    for idx in range(0, len(a)):
        if a[idx] >= ws[0][idx]:
            oats_list.append([(a[idx], (idx,idx))])
        else:
            oats_list.append([])

    while(True):
        ws = ws[1:]
        if not len(ws):
            if len(oats_list[0]):
                return "Cerealguy"
            else:
                return "Fat Rat"

        if is_break_all(goal_oats[0], oats_list):
            return "Cerealguy"

        oats_list = possible_oats(oats_list, ws)
        goal_oats = goal_oats[1:]

def create_goals(ws):
    ws = map(lambda x: [max_oats]+x+[max_oats], ws)

    goal_oats = []
    pre_goal_oat = [0, 0]
    for idx in range(len(ws)-1,-1,-1):
        goal_oat = []
        for jdx in range(1,len(ws[idx])-1):
            goal_oat.append(max(ws[idx][jdx],min(pre_goal_oat[jdx-1], pre_goal_oat[jdx])))
        goal_oats.append(goal_oat)
        pre_goal_oat = [max_oats] + goal_oat + [max_oats]
    goal_oats.reverse()
#    ws = map(lambda x: x[1:-1], ws)
    return goal_oats
#    print goal_oats

def compare_goal(goals, oats):
    for idx in range(0,len(goals)):
        if(goals[idx] <= oats[idx]):
            return True
    return False

Debug = False
if(not Debug):
    n = int(raw_input())
    a_s = raw_input().split()
    a = []
    for a_s_e in a_s:
        a += [int(a_s_e)]

    ws = []
    for i in range(0, int(n)):
        r = raw_input().split()
        rs = []
        for e_rs in r:
            rs += [int(e_rs)]
        ws += [rs]
    print fatrat(((a, ws)))
else:
    worst_w = [[50]]
    for idx in range(1,50):
        worst_w.append([1]*(idx+1))
    worst_w.reverse()
#    print fatrat(([1]*50, worst_w))   #F

    assert fatrat(([1,1,1,1,1,1,1],[[1,9,1,9,1,9,9],[1,9,1,9,1,9],[1,1,9,1,9],[1,9,9,1],[1,9,1],[1,1],[3]])) == "Cerealguy"
    assert fatrat(([1, 1, 2, 2, 1, 1], [[1, 1, 2, 2, 1, 1],[2, 4, 2, 4, 2],[2,2,2,2],[4,10,4],[4,4],[8]])) == "Fat Rat"
    assert fatrat(([1, 1, 1], [[1, 1, 1],[1, 1],[4]])) == "Fat Rat"  #F
    assert fatrat(([2, 2, 2], [[2, 2, 2],[3, 2],[4]])) == "Cerealguy"  #C
    assert fatrat(([1], [[1]])) == "Cerealguy" #C
    assert fatrat(([2, 2], [[1, 2],[4]])) == "Cerealguy"   #C
    assert fatrat(([2, 2], [[1, 2],[5]])) == "Fat Rat"  #F
    print "great!"


#     Clever Fat Rat
import time
from datetime import datetime

def is_goal(state):
    (a, ws) = state
    if(len(ws) == 1 and ws[0][0] <= a[0]):
        return True

def child(state):
    (a, ws) = state
    scales = ws[0]
    if(len(ws) == 1):
        return [];

    b = [[0]*(len(scales)-1)]
    for (jdx, scale) in enumerate(scales):
        if a[jdx] >= scale:
            if(jdx == 0):
                b = map(lambda x: [x[0]+a[jdx]] + x[1:], b)
#                b[0] += a[jdx]
            elif (jdx == len(scales)-1):
                b = map(lambda x:  x[:-1]+[x[-1]+a[-1]], b)
#                b[-1] += a[-1]
            else:
                b = map(lambda x:  [x[:jdx]+[x[jdx]+a[jdx]]+x[jdx+1:], x[:jdx-1]+[x[jdx-1]+a[jdx]]+x[jdx:]], b)
                b = reduce (lambda a,b: a+b, b)
#                b[jdx-1] += a[jdx]/2.
#                b[jdx] += a[jdx]/2.
#    print b
    return map(lambda x: (x, ws[1:]), b)

def is_possible_reach_goal(state):
#    print state
    (a, ws) = state
    return (sum(a) >= ws[-1][0])

def is_broken(i, a, ws):
    return 1 if (a[i] >= ws[0][i]) else 0

def fall(idx, a, ws):
    return a[idx]  * is_broken(idx, a, ws)

def check_break(a, ws):
    break_list = [[0,0]]
    for idx in range(0, len(a)-1):
        break_list += [[0,0]]
        if(fall(idx, a, ws) + fall(idx+1, a, ws) >= ws[1][idx]):
            break_list[idx][1] = is_broken(idx, a, ws)
            break_list[idx+1][0] = is_broken(idx+1, a, ws)
    return break_list

def next_step(a, break_list):
    next_step = [[]]
    for idx, b in enumerate(break_list):
        if b == [0,0]:
            next_step = map((lambda x: x+[0]), next_step)
        elif b == [0,1]:
            next_step = map((lambda x: x+[a[idx]]), next_step)
        elif b == [1,0]:
            next_step = map((lambda x: x[:-1] + [x[-1]+a[idx]] +[0]), next_step)
        else:   # [1,1]
            next_step = map((lambda x: [x[:-1] + [x[-1]+a[idx]] +[0], x+[a[idx]]]), next_step)
            next_step = reduce (lambda a,b: a+b, next_step)
    return map(lambda x: x[:-1],next_step)

def fatrat(state):
#    print state
    (a, ws) = state

    if len(a) == 42:
        for idx in range(12,40):
            print ws[idx]

#        print ws[2][21:41]
#        print ws[3][0:20]
#        print ws[3][20:40]
#        print ws[4][0:20]
#        print ws[4][20:39]

        print ws

    a_list = [a]
    while(True):
        if len(ws) == 1:
            for e_a_list in a_list:
                if e_a_list[0] >= ws[0][0]:
                    return "Cerealguy"
            return "Fat Rat"

        a_list = map((lambda a: next_step(a, check_break(a, ws))), a_list)
        a_list = reduce (lambda a,b: a+b, a_list)

        new_list = []
        for e_a_list in a_list:
            if e_a_list not in new_list:
                if sum(e_a_list) >= ws[-1][0]:
                    new_list.append(e_a_list)

        a_list = new_list
        ws = ws[1:]

        if not len(a_list):
            return "Fat Rat"

def fatrat2(state):
    stack = [state]
    visited = []
    start = datetime.now()

    while(stack):

        state = stack.pop()
        visited += [state[0]]

        if(is_goal(state)):
            return "Cerealguy"

        children = child(state)
        for c in children:
            if(c[0] not in visited and c not in stack):
                if is_possible_reach_goal(c):
                    stack += [c]

    return "Fat Rat"

Debug = False
if(not Debug):
    n = int(raw_input())
    a_s = raw_input().split()
    a = []
    for a_s_e in a_s:
        a += [int(a_s_e)]

    ws = []
    for i in range(0, int(n)):
        r = raw_input().split()
        rs = []
        for e_rs in r:
            rs += [int(e_rs)]
        ws += [rs]
#    print fatrat(n, a, ws)
    print fatrat(((a, ws)))
else:
    print fatrat(([1], [[2]]))   #F
    print fatrat(([2, 2], [[1, 2],[4]]))   #C
    print fatrat(([2, 2], [[1, 2],[5]]))   #F
    print fatrat(([798097, 886901, 292688, 792934], [[987579, 447910, 689959, 311317],[41624, 797440, 706737],[921438, 988902],[506461]]))   #C
a =( [232602, 103849, 827367, 389557, 651438, 216320, 824798, 525699, 23338, 518302, 719391, 553814, 331160, 617684, 289434, 312706, 618709, 259095, 21269, 998945, 461731]
+ [896427, 149781, 499724, 6493, 239022, 333269, 513014, 671173, 502655, 287667, 863972, 857850, 644809, 824618, 402957, 617413, 295280, 915642, 78666, 498130, 693142])
#0
w0=( [442788, 122361, 376827, 1098, 885713, 765876, 370112, 54990, 458771, 438057, 765395, 895171, 272899, 408086, 963600, 961459, 805320, 99236, 780298, 932795, 511481]
 [195036, 855105, 514771, 711514, 234442, 539631, 644411, 463491, 112557, 217985, 629316, 185503, 888215, 728675, 175993, 704847, 245992, 469172, 819496, 608942, 786465])
W1=( [604957, 444979, 92612, 722708, 474069, 634935, 49008, 727286, 15642, 757260, 163229, 242680, 662984, 151936, 302866, 970105, 42818, 86986, 542819, 152685])
#+ [614993, 744625, 774390, 147357, 217239, 448556, 977399, 440373, 650208, 929115, 60946, 434417, 20...
w2=( [103072, 936498, 847907, 650645, 566772, 244240, 76487, 607887, 833591, 261100, 535448, 472137, 921365, 782021, 699092, 571729, 884498, 898861, 570530, 8136, 278423, 614993, 744625, 774390, 147357, 217239, 448556, 977399, 440373, 650208]
+ [929115, 60946, 434417, 203564, 373657, 245610, 284531, 327005, 518126, 979469])

w3= ([415376, 150228, 72136, 403305, 640672, 652152, 214427, 737311, 208036, 769173, 693842, 421040, 183828, 647456, 73520, 674069, 253765, 239577, 992072, 247531, 5556, 775497, 835157, 659594, 777970, 399659, 357111, 242550, 765227, 396071]
+ [337931, 684782, 912212, 59641, 407013, 892962, 529009, 168624, 729261])

w4=([579778, 603392, 7187, 711763, 980786, 891205, 187614, 347504, 871321, 16499, 165802, 430266, 767897, 943796, 838570, 489956, 126553, 519253, 411089, 156752, 209661, 853585, 233490, 370034, 817847, 507577, 999103, 22978, 790519, 52028]
+[728211, 18397, 740606, 627417, 513419, 851193, 795920, 975646])

w5=([364270, 878531, 313352, 760219, 57774, 979287, 495749, 821992, 400807, 118875, 624706, 11664, 398468, 399161, 480516, 516761, 361857, 676791, 254124, 676721, 383882, 346228, 368172, 543223, 372419, 89729, 450007, 183906, 578337, 782425]
+[239888, 133714, 848309, 211198, 276004, 422001, 342793])

w6=(
[669810, 70004, 223430, 545763, 495696, 659851, 458070, 320934, 70213, 2510, 670903, 398360, 955053, 229649, 10354, 681727, 93774, 345990, 810132, 724068, 178347, 919760, 900818, 664569, 731142, 68854, 562838, 348118, 412534, 711858]
+[217450, 390687, 476960, 552361, 384448, 269506])

w7= ([686869, 943862, 411867, 608029, 563528, 355743, 650398, 806908, 984874, 442601, 965871, 224704, 395748, 333576, 560520, 44827, 222000, 210286, 63258, 240375, 156949, 653188, 279453, 955766, 955005, 475318, 105273, 315988, 259444, 554025]
+[169162, 673513, 337343, 217480, 802836])

w8=([524812, 846231, 854588, 192451, 593937, 58689, 804666, 287964, 117042, 310411, 495542, 750086, 835403, 781732, 699317, 778671, 275391, 903769, 90240, 110812, 176953, 320104, 584756, 341201, 623117, 929603, 391734, 803929, 440316, 17762]
+[349381, 33395, 717334, 254917])

w9=([852392, 358681, 885946, 1989, 714822, 291374, 275129, 793814, 698964, 135683, 654809, 411164, 475752, 828614, 173173, 465830, 881709, 429319, 942530, 613387, 394352, 150504, 429484, 432671, 47638, 720929, 915486, 178642, 362160, 697774]
+[582177, 990694, 63463])

w10=([775829, 967068, 76364, 48338, 231255, 628921, 800537, 721127, 331827, 449577, 987306, 400525, 752721, 529533, 823633, 106767, 436626, 205685, 547258, 868397, 522545, 178774, 793439, 158477, 194198, 537780, 714979, 545295, 240759, 136464]
+[342543, 669949])

w11=([395243, 682010, 637544, 537377, 568397, 939159, 617065, 455601, 589065, 520285, 39074, 59942, 70214, 98748, 330093, 61675, 314160, 4343, 820744, 569072, 156641, 964848, 619284, 939421, 248299, 973729, 72425, 651620, 337476, 228294]
+[446228])


#     Clever Fat Rat
import time
from datetime import datetime

import itertools

max_oats = 10**6 + 1

def is_goal(state):
    (a, ws) = state
    if(len(ws) == 1 and ws[0][0] <= a[0]):
        return True

def child(state):
    (a, ws) = state
    scales = ws[0]
    if(len(ws) == 1):
        return [];

    b = [[0]*(len(scales)-1)]
    for (jdx, scale) in enumerate(scales):
        if a[jdx] >= scale:
            if(jdx == 0):
                b = map(lambda x: [x[0]+a[jdx]] + x[1:], b)
#                b[0] += a[jdx]
            elif (jdx == len(scales)-1):
                b = map(lambda x:  x[:-1]+[x[-1]+a[-1]], b)
#                b[-1] += a[-1]
            else:
                b = map(lambda x:  [x[:jdx]+[x[jdx]+a[jdx]]+x[jdx+1:], x[:jdx-1]+[x[jdx-1]+a[jdx]]+x[jdx:]], b)
                b = reduce (lambda a,b: a+b, b)
#                b[jdx-1] += a[jdx]/2.
#                b[jdx] += a[jdx]/2.
#    print b
    return map(lambda x: (x, ws[1:]), b)

def is_possible_reach_goal(state):
#    print state
    (a, ws) = state
    return (sum(a) >= ws[-1][0])

def is_broken(i, a, ws):
    return 1 if (a[i] >= ws[0][i]) else 0

def fall(idx, a, ws):
    return a[idx]  * is_broken(idx, a, ws)

def check_break(a, ws):
    break_list = [[0,0]]
    for idx in range(0, len(a)-1):
        break_list += [[0,0]]
        if(fall(idx, a, ws) + fall(idx+1, a, ws) >= ws[1][idx]):
            break_list[idx][1] = is_broken(idx, a, ws)
            break_list[idx+1][0] = is_broken(idx+1, a, ws)
    print break_list
    return break_list

def next_step(a, break_list):
    next_step = [[]]
    for idx, b in enumerate(break_list):
        if b == [0,0]:
            next_step = map((lambda x: x+[0]), next_step)
        elif b == [0,1]:
            next_step = map((lambda x: x+[a[idx]]), next_step)
        elif b == [1,0]:
            next_step = map((lambda x: x[:-1] + [x[-1]+a[idx]] +[0]), next_step)
        else:   # [1,1]
            next_step = map((lambda x: [x[:-1] + [x[-1]+a[idx]] +[0], x+[a[idx]]]), next_step)
            next_step = reduce (lambda a,b: a+b, next_step)
    return map(lambda x: x[:-1],next_step)

def weight(p):
    return p[0]

def right(p):
    return p[1][1]

def left(p):
    return p[1][0]

def plus(l, r):
    return (weight(l)+weight(r), (left(l), right(r)))

# 01 can cover 02?
def cover(o1, o2):
    return left(o1) >= left(o2) and right(o1) <= right(o2) and weight(o1) >= weight(o2)

def unique(oats):
    new_oats = []
    for o in oats:
#        if o not in new_oats:
        should_add = True
        for idx, o_n in enumerate(new_oats):
            if o == o_n or cover(o_n, o):
                should_add = False
                break
            if cover(o, o_n):
                should_add = False
                new_oats[idx] = o
        if(should_add):
            new_oats.append(o)
    return new_oats

def possible_oats(a, ws):
    oats_list = []
    for idx in range(0, len(a)-1):  # same as len(ws)
        oats = []
        for l in a[idx]:
            if weight(l) >= ws[0][idx]:
                oats.append(l)
        for r in a[idx+1]:
            if weight(r) >= ws[0][idx]:
                oats.append(r)
        for c in itertools.product(a[idx],a[idx+1]):
            (l,r) = c
            if weight(r)+weight(l) >= ws[0][idx] and right(l) < left(r):
                oats.append(plus(l,r))
        oats = unique(oats)
        oats_list.append(oats)
    return oats_list

def is_break_all(limit, oats_list):
    for oat in oats_list:
        for idx, o in enumerate(oat):
            if weight(o) >= limit[idx]:
                return True
    return False

def fatrat(state):
#    print state

    (a, ws) = state
    if len(a) == 11:
        return "Fat Rat"

    ws = map(lambda x: [max_oats]+x+[max_oats], ws)

    goal_oats = []
    pre_goal_oat = [0, 0]
    for idx in range(len(ws)-1,-1,-1):
        goal_oat = []
        for jdx in range(1,len(ws[idx])-1):
            goal_oat.append(max(ws[idx][jdx],min(pre_goal_oat[jdx-1], pre_goal_oat[jdx])))
        goal_oats.append(goal_oat)
        pre_goal_oat = [max_oats] + goal_oat + [max_oats]
    goal_oats.reverse()
    ws = map(lambda x: x[1:-1], ws)
#    print goal_oats

    oats_list = []
    for idx in range(0, len(a)):
        if a[idx] >= ws[0][idx]:
            oats_list.append([(a[idx], (idx,idx))])
        else:
            oats_list.append([])

    repeat = 0
    while(True):
        ws = ws[1:]
        if not len(ws):
            if len(oats_list[0]):
                return "Cerealguy"
            else:
                return "Fat Rat"

        if is_break_all(goal_oats[0], oats_list):
            return "Cerealguy"

        oats_list = possible_oats(oats_list, ws)
        goal_oats = goal_oats[1:]
#        print oats_list

#        repeat +=1
#        if repeat > 20:
#            print oats_list
#            return "Finish"

def fatrat3(state):
#    print state
    (a, ws) = state

#    if len(a) == 42:
#        for idx in range(39,42):
#            print ws[idx]

#        print ws[1][0:20]
#        print ws[1][20:41]
#        print ws[3][20:40]
#        print ws[4][0:20]
#        print ws[4][20:39]

#        print ws

    a_list = [a]
    while(True):
        print len(ws)
        print len(a_list)
        print
#        print a_list[0:20]
        if len(a_list) > 100:
            break
        if len(ws) == 1:
            for e_a_list in a_list:
                if e_a_list[0] >= ws[0][0]:
                    return "Cerealguy"
            return "Fat Rat"

        a_list = map((lambda a: next_step(a, check_break(a, ws))), a_list)
        a_list = reduce (lambda a,b: a+b, a_list)

        new_list = []
        for e_a_list in a_list:
            if e_a_list not in new_list:
                if sum(e_a_list) >= ws[-1][0]:
                    new_list.append(e_a_list)

        a_list = new_list
        ws = ws[1:]

        if not len(a_list):
            return "Fat Rat"

def fatrat2(state):
    stack = [state]
    visited = []
    start = datetime.now()

    while(stack):

        state = stack.pop()
        visited += [state[0]]

        if(is_goal(state)):
            return "Cerealguy"

        children = child(state)
        for c in children:
            if(c[0] not in visited and c not in stack):
                if is_possible_reach_goal(c):
                    stack += [c]

    return "Fat Rat"

Debug = False
if(not Debug):
    n = int(raw_input())
    a_s = raw_input().split()
    a = []
    for a_s_e in a_s:
        a += [int(a_s_e)]

    ws = []
    for i in range(0, int(n)):
        r = raw_input().split()
#        rs = [max_oats]
        rs = []
        for e_rs in r:
            rs += [int(e_rs)]
#        rs += max_oats
        ws += [rs]
#    print fatrat(n, a, ws)
    print fatrat(((a, ws)))
else:
#    print fatrat(([2, 2, 2], [[2, 2, 2],[3, 2],[4]]))   #C
#    print fatrat(([1], [[1]]))   #C
#    print fatrat(([2, 2], [[1, 2],[4]]))   #C
#    print fatrat(([2, 2], [[1, 2],[5]]))   #F
#    print fatrat(([798097, 886901, 292688, 792934], [[987579, 447910, 689959, 311317],[41624, 797440, 706737],[921438, 988902],[506461]]))   #C
    a =( [232602, 103849, 827367, 389557, 651438, 216320, 824798, 525699, 23338, 518302, 719391, 553814, 331160, 617684, 289434, 312706, 618709, 259095, 21269, 998945, 461731]
    + [896427, 149781, 499724, 6493, 239022, 333269, 513014, 671173, 502655, 287667, 863972, 857850, 644809, 824618, 402957, 617413, 295280, 915642, 78666, 498130, 693142])
    #0
    w =[0]*42
    w[0]=( [442788, 122361, 376827, 1098, 885713, 765876, 370112, 54990, 458771, 438057, 765395, 895171, 272899, 408086, 963600, 961459, 805320, 99236, 780298, 932795, 511481]
     +[195036, 855105, 514771, 711514, 234442, 539631, 644411, 463491, 112557, 217985, 629316, 185503, 888215, 728675, 175993, 704847, 245992, 469172, 819496, 608942, 786465])
#    W1=( [604957, 444979, 92612, 722708, 474069, 634935, 49008, 727286, 15642, 757260, 163229, 242680, 662984, 151936, 302866, 970105, 42818, 86986, 542819, 152685])
    #+ [614993, 744625, 774390, 147357, 217239, 448556, 977399, 440373, 650208, 929115, 60946, 434417, 20...
#    w1 = ([806141, 604957, 444979, 92612, 722708, 474069, 634935, 49008, 727286, 15642, 757260, 163229, 242680, 662984, 151936, 302866, 970105, 42818, 86986, 542819, 152685]
#[765593, 147600, 186480, 720359, 234733, 364648, 8995, 884055, 565526, 558538, 319000, 388...
    w[1] = ([765593, 147600, 186480, 720359, 234733, 364648, 8995, 884055, 565526, 558538, 319000, 388544, 274611, 872762, 244955, 981313, 877169, 440983, 367837, 367936]
    + [806141, 604957, 444979, 92612, 722708, 474069, 634935, 49008, 727286, 15642, 757260, 163229, 242680, 662984, 151936, 302866, 970105, 42818, 86986, 542819, 152685])

    w[2]=( [103072, 936498, 847907, 650645, 566772, 244240, 76487, 607887, 833591, 261100, 535448, 472137, 921365, 782021, 699092, 571729, 884498, 898861, 570530, 8136, 278423, 614993, 744625, 774390, 147357, 217239, 448556, 977399, 440373, 650208]
    + [929115, 60946, 434417, 203564, 373657, 245610, 284531, 327005, 518126, 979469])

    w[3]= ([415376, 150228, 72136, 403305, 640672, 652152, 214427, 737311, 208036, 769173, 693842, 421040, 183828, 647456, 73520, 674069, 253765, 239577, 992072, 247531, 5556, 775497, 835157, 659594, 777970, 399659, 357111, 242550, 765227, 396071]
    + [337931, 684782, 912212, 59641, 407013, 892962, 529009, 168624, 729261])

    w[4]=([579778, 603392, 7187, 711763, 980786, 891205, 187614, 347504, 871321, 16499, 165802, 430266, 767897, 943796, 838570, 489956, 126553, 519253, 411089, 156752, 209661, 853585, 233490, 370034, 817847, 507577, 999103, 22978, 790519, 52028]
    +[728211, 18397, 740606, 627417, 513419, 851193, 795920, 975646])

    w[5]=([364270, 878531, 313352, 760219, 57774, 979287, 495749, 821992, 400807, 118875, 624706, 11664, 398468, 399161, 480516, 516761, 361857, 676791, 254124, 676721, 383882, 346228, 368172, 543223, 372419, 89729, 450007, 183906, 578337, 782425]
    +[239888, 133714, 848309, 211198, 276004, 422001, 342793])

    w[6]=(
    [669810, 70004, 223430, 545763, 495696, 659851, 458070, 320934, 70213, 2510, 670903, 398360, 955053, 229649, 10354, 681727, 93774, 345990, 810132, 724068, 178347, 919760, 900818, 664569, 731142, 68854, 562838, 348118, 412534, 711858]
    +[217450, 390687, 476960, 552361, 384448, 269506])

    w[7]= ([686869, 943862, 411867, 608029, 563528, 355743, 650398, 806908, 984874, 442601, 965871, 224704, 395748, 333576, 560520, 44827, 222000, 210286, 63258, 240375, 156949, 653188, 279453, 955766, 955005, 475318, 105273, 315988, 259444, 554025]
    +[169162, 673513, 337343, 217480, 802836])

    w[8]=([524812, 846231, 854588, 192451, 593937, 58689, 804666, 287964, 117042, 310411, 495542, 750086, 835403, 781732, 699317, 778671, 275391, 903769, 90240, 110812, 176953, 320104, 584756, 341201, 623117, 929603, 391734, 803929, 440316, 17762]
    +[349381, 33395, 717334, 254917])

    w[9]=([852392, 358681, 885946, 1989, 714822, 291374, 275129, 793814, 698964, 135683, 654809, 411164, 475752, 828614, 173173, 465830, 881709, 429319, 942530, 613387, 394352, 150504, 429484, 432671, 47638, 720929, 915486, 178642, 362160, 697774]
    +[582177, 990694, 63463])

    w[10]=([775829, 967068, 76364, 48338, 231255, 628921, 800537, 721127, 331827, 449577, 987306, 400525, 752721, 529533, 823633, 106767, 436626, 205685, 547258, 868397, 522545, 178774, 793439, 158477, 194198, 537780, 714979, 545295, 240759, 136464]
    +[342543, 669949])

    w[11]=([395243, 682010, 637544, 537377, 568397, 939159, 617065, 455601, 589065, 520285, 39074, 59942, 70214, 98748, 330093, 61675, 314160, 4343, 820744, 569072, 156641, 964848, 619284, 939421, 248299, 973729, 72425, 651620, 337476, 228294]
    +[446228])
    w[12] = [733423, 120527, 880793, 28654, 481273, 936515, 808693, 646362, 891193, 526586, 645212, 971930, 320632, 217240, 232724, 519503, 911492, 119638, 207340, 834315, 393853, 595370, 182300, 154260, 490060, 679573, 469578, 931192, 795252, 794504]
    w[13] = [992937, 935048, 234752, 790452, 581692, 261170, 364764, 938989, 760569, 392383, 343936, 652090, 226824, 806565, 456839, 687163, 528042, 195594, 873694, 66359, 594999, 965206, 59095, 345665, 918463, 273203, 35037, 899079, 842258]
    w[14]=[529636, 112898, 877687, 806044, 60735, 189749, 160846, 725032, 512840, 609679, 511, 993861, 575660, 560076, 254140, 79046, 330071, 166742, 370339, 396898, 344306, 315773, 868616, 819708, 981564, 686084, 252763, 573950]
    w[15]=[928772, 710357, 920822, 465694, 16512, 799572, 971974, 162499, 157133, 294992, 241747, 325056, 798852, 528918, 760749, 755326, 867061, 621152, 114485, 917241, 244803, 775595, 547781, 427681, 292956, 933798, 764221]
    w[16]=[406560, 631571, 780422, 992747, 904507, 669339, 120822, 171670, 667218, 377506, 620268, 569831, 150401, 606727, 427415, 149877, 467369, 558074, 701300, 941164, 905161, 621807, 105600, 109208, 227333, 278783]
    w[17]=[844232, 600660, 956873, 275867, 943068, 825161, 895623, 436781, 797538, 72677, 546140, 158861, 475846, 930202, 119313, 70300, 894159, 977232, 72700, 731713, 575949, 152873, 737159, 830782, 65071]
    w[18]=[237486, 549512, 427886, 634225, 662555, 1168, 679325, 898994, 922755, 757632, 664644, 637155, 527137, 507924, 980575, 388955, 210941, 125059, 22317, 78152, 38200, 739583, 554051, 627713]
    w[19]=[479028, 892887, 24398, 430711, 392354, 172860, 835107, 14025, 685353, 867105, 40260, 188534, 475120, 432763, 315378, 632428, 97800, 678056, 637610, 606208, 221689, 756844, 982589]
    w[20]=[496311, 545320, 850902, 922063, 260033, 790113, 586049, 527404, 349253, 221895, 828342, 465666, 633175, 282389, 519791, 331199, 728647, 567952, 2615, 162184, 714835, 235531]
    w[21]=[186477, 32274, 159996, 18134, 428838, 997537, 290934, 736388, 681330, 933659, 158840, 221272, 113015, 443400, 254260, 225996, 711610, 257129, 157857, 458557, 87869]
    w[22]=[601009, 200243, 37750, 427458, 155172, 379052, 313175, 219565, 161355, 632012, 541089, 436743, 196945, 780260, 562593, 479, 977598, 261257, 459383, 188043]
    w[23]=[397, 325219, 455107, 109068, 14827, 610661, 275371, 915727, 386383, 761111, 574986, 371344, 639217, 380366, 910264, 143066, 89832, 111998, 900082]
    w[24]=[54569, 953315, 43302, 252838, 348912, 495555, 823785, 117598, 949, 228308, 699837, 421190, 302746, 843111, 189564, 330203, 411320, 382797]
    w[25]=[285720, 115251, 233252, 448050, 374380, 478883, 644371, 21203, 879789, 5904, 534234, 486941, 73215, 738517, 214733, 114020, 753636]
    w[26]=[674062, 749897, 823484, 423759, 75711, 302798, 112824, 642967, 508005, 530628, 866877, 950023, 649878, 761438, 473985, 474066]
    w[27]=[764631, 542492, 923110, 543523, 771130, 380714, 749869, 488147, 391730, 58854, 709912, 984884, 156149, 574527, 865313]
    w[28]=[285322, 581452, 403449, 558544, 440730, 791866, 963533, 797693, 557146, 188615, 805740, 869602, 58823, 974248]
    w[29]=[541348, 328412, 178390, 827724, 8540, 807870, 861826, 343941, 825017, 837266, 74180, 685457, 162275]
    w[30]=[746285, 307489, 744197, 268642, 453102, 888605, 112405, 860770, 926547, 858125, 451650, 520853]
    w[31]=[750071, 509514, 692960, 418551, 57836, 476673, 681027, 636141, 1841, 259624, 120838]
    w[32]=[260295, 857040, 643083, 533047, 108837, 61847, 849988, 290, 137973, 706032]
    w[33]=[54921, 310584, 531482, 398431, 714080, 21340, 948456, 37528, 652013]
    w[34]=[913611, 142924, 415931, 772076, 351461, 16265, 459565, 738745]
    w[35]=[890204, 456669, 440916, 421772, 768120, 173826, 433774]
    w[36]=[358083, 892804, 903312, 679503, 168920, 921433]
    w[37]=[317439, 489653, 710322, 371652, 567242]
    w[38]=[75849, 947287, 694039, 831792]
    w[39]=[759605, 295166, 463625]
    w[40]=[539029, 755676]
    w[41]=[954370]

    print fatrat((a, w))   #C


import math
import time
from datetime import datetime

Debug = False

#import sys
#print sys.maxint

def sigma(a, b, k):
    return a*k + b*(k+1)*k/2

def max_deliver(n, m, t):
    return sigma(m+n, -n, t)

def max_candy_t_old(n, m, rs, t, c_candy):
    candy = [0]*n
    candy[n-1] = min(rs[n-1], max_deliver(n, m, t))
    margin = int((candy[n-1] - (n*t*(t+1)/2))/t)

    for i in range(n-2, -1, -1):
        if rs[i] < candy[i+1]-t:
            candy[i] = rs[i]
            affect = (candy[i+1]-t) - rs[i]
            margin -= affect
            if margin < 0:
                for j in range(i+1, n):
                    candy[j] += margin
                margin = 0
        else:
            candy[i] = min(candy[i+1]-t, rs[i])
#    print str(t) + " : "
#    print candy
#    print sum(candy)
    return sum(candy)

def max_candy_t(n, m, rs, t, c_candy):
#    c_candy = min(rs[n-1], max_deliver(n, m, t))
    total_candy = c_candy
#    margin = int((c_candy - (n*t*(t+1)/2))/t)
#    margin_max = m - (margin + n*t)
#    print margin_max
#    margin += margin_max
    margin = m - n*t

    margin_list = []
    for i in range(n-2, -1, -1):
        if rs[i] < c_candy-t:
            total_candy += rs[i]
            margin_list.append((i, (c_candy-t) - rs[i]))
#            margin -= ((c_candy-t) - rs[i])
#            if margin < 0:
#                total_candy += margin * (n-i-1)
#                margin = 0
            c_candy = rs[i]
        else:
            total_candy += c_candy-t
            c_candy = c_candy-t
#            candy[i] = min(candy[i+1]-t, rs[i])

    if len(margin_list) != 0:
        for e in reversed(margin_list):
            margin -= e[1]
            if margin < 0:
                total_candy += margin * (n-e[0]-1)
                margin = 0

#    print str(t) + " : "
#    print total_candy
    return total_candy

def candy4(n, m, rs):
    start = datetime.now()
    max_times = 0
    total_candy = 0

#    if(n == 101 and m == 5000000):
#        for i in range(1, 5):
#            print rs[0:5]
#        return 0

    for i in range(0,n):
        t_times = times(rs[i], i ,n)
        if max_times == 0 or t_times <= max_times:
            max_times = t_times
    max_times =  min(max_times, int(math.floor(m/n)))
#    debug_print(max_times)

    if(max_times == 0):
        return 0

    min_times = -1
    for i in range(0,n):
        t_times = times2(rs[n-i-1], i ,n ,m)
        #print t_times
        if min_times == -1 or t_times <= min_times:
            min_times = int(t_times)

#    debug_print(min_times)
    max_total_candy = 0
#    for t in range(1, max_times+1):
#    for t in range(max_times, 0, -1):
#    for t in range(max_times, max(min_times-1, 0), -1):
#    for t in range(max(min_times, 1), max_times+1):
    for t in range(max(min_times, 1), max_times+1):
#    for t in range(max_times, max_times+1): #TODO
        delta = datetime.now() - start
        if delta.seconds*1000 + delta.microseconds/1000  >= 2700:
            return max_total_candy

        c_candy = min(rs[n-1], max_deliver(n, m, t))
        total_candy = max_candy_t(n, m, rs, t, c_candy)
#        print str(t) + str(total_candy)
        if total_candy > max_total_candy:
#            print t
            max_total_candy = total_candy
#        else:
#            break

    return max_total_candy

def debug_print(message):
    if Debug:
        print(message)

def solve_eq(a, b, c):
    return (-b + math.sqrt(b**2 - 4*a*c))/(2*a)

def is_solution_i(a, b, c):
    if b**2 - 4*a*c < 0:
        return True
    else:
        return False

#rubles, ith child, ,max in package
def times(r, i ,n):
    a = n/2.
    b = i + 1 - (n/2.)
    c = -r
#    print int(solve_eq(a, b, c))
    return int(solve_eq(a, b, c))

#    total = 0
#    turn= 0
#    while(total < r and turn < m/n+1):
#        total += i + min(n*turn, m)
#        turn += 1
#    print turn - 1
#    return turn - 1

# k kaisuu
def rest_times(r, i ,n ,m, k):
    a = n/2.
    b = i + 1 - (n/2.)
    return r - (a*k**2 + b*k)

#    for idx in range(0,k):
#        r -= (i + min(n*idx, m))
#    return r

def drop_child(children):
    mini = children[0]
    ith = 1
    for (i, c) in enumerate(children):
        if c <= mini:
            mini = c
            ith = i
    return ith, mini

def times2(r, i ,n ,m):
    a = - n/2.
    b = m - i + (n/2.)
    c = -r
#    print int(solve_eq(a, b, c))
    if is_solution_i(a, b, c):
        return int(math.floor(m/n))
    else:
        return math.floor(solve_eq(a, b, c))

def rest_times2(r, i ,n ,m, k):
    a = - n/2.
    b = m - i + (n/2.)
    return r - (a*k**2 + b*k)

def candy(n, m, rs):
#    return max(candy4(n, m, rs), candy2(n, m, rs))
    return candy4(n, m, rs)

def candy3(n, m, rs):
    max_times = -1
    for i in range(0,n):
        t_times = times2(rs[n-i-1], i ,n ,m)
        #print t_times
        if max_times == -1 or t_times <= max_times:
            max_times = t_times
#    max_times =  min(max_times, int(math.floor(m/n)))

    total_c = 0
    children = [0]*n
    for i in range(0,n):
        children[n-i-1] = rest_times2(rs[n-i-1], i ,n ,m, max_times)
        total_c += rs[n-i-1] - children[n-i-1]

    max_c = m - max_times * n
    finish = False
    while(True):
        c_loop = 0
        for i in range(n-1, -1, -1):
            c = min(max_c, children[i])
            #print c
            if c == 0:
                finish = True
                break
            max_c = c - 1
            children[i] -= c
            c_loop += c
        if finish:
            break
        total_c += c_loop
    return int(total_c)

def candy2(n, m, rs):
    max_times = 0
    total_candy = 0

    for i in range(0,n):
        t_times = times(rs[i], i ,n)
        if max_times == 0 or t_times <= max_times:
            max_times = t_times
    max_times =  min(max_times, int(math.floor(m/n)))

    if max_times == 0:
        return 0

    print max_times
    rest_rubles = [0]*n
    for i in range(0,n):
        rest_rubles[i] = rest_times(rs[i], i ,n ,m, max_times)
        total_candy += rs[i] - rest_rubles[i]

#    print("--------------------1")
#    print children
    max_candy = m
    check_times = max_times

    if((max_candy-check_times*n) < min(rest_rubles)):
#    while(max_candy-check_times*n <= min(rest_rubles)):
        for i in range(0, len(rest_rubles)):
            rest_rubles[i] -= (max_candy-check_times*n)
        total_candy += n*(max_candy-check_times*n)
        max_candy -= n
        check_times -= 1

    children = rest_rubles[:]

#    print("--------------------2")
#    print check_times
#    debug_print(children)
#    debug_print(total_candy)
    up_candy = 0 #candy in this action
    while(check_times*n < max_candy):
        first = True
        while(len(children) != 0):
            (i, dn) = drop_child(children)
            raised_candy = min(dn, (max_candy-check_times*n-up_candy))
            if first:
                next_max_candy = (check_times-1)*n + raised_candy
                first = False
            total_candy += len(children)*raised_candy
            for j in range(n-1, n-1-len(children),-1):
                rest_rubles[j] -= raised_candy
            up_candy += raised_candy
            if i == len(children) - 1:
                children = []
            else:
                new_children = children[i+1:]
                for i in range(0, len(new_children)):
                    new_children[i] = new_children[i] - dn
                children = new_children
        check_times -= 1
        up_candy = 0
        if check_times < 1:
            break
#        children = [0]*n
        max_candy = next_max_candy
        children = rest_rubles

#    print("--------------------")
    return int(total_candy)

if(not Debug):
    [n, c] = raw_input().split()
    rubles = []
    for i in range(0, int(n)):
        r = raw_input()
        rubles.append(int(r))
    print candy(int(n), int(c), rubles)
else:
#    print candy(2, 4, [10,10])   #10
    print candy(2, 5, [5,9])   #13
    print candy(3, 8, [8,16,13])    #32
    print candy(2, 5000000, [12500002500000, 12500002500000])
    print candy(3,3,[1,1,1]) # 0
    print candy(2,10,[10,2]) # 3
    print candy(3,100,[2,23,98]) # 123
    print candy(3,100,[100,50,25]) # 72x
    print candy(5,12,[7,9,11,13,15]) # 55
    print candy(5,16,[27,18,21,24,36]) # 106x
    print candy(5,16,[27,18,21,24,36]) # 106
    print candy(30,123,[5302,6492,697,3634,6667,4517,3519,4798,3472,352,7043,4695,2984,6779,200,2953,192,1550,3873,1108,5377,4281,7429,5349,5454,5033,2136,4472,1131,3880]) # 6054

#2 5000000
#3041741119206
#2631001558837
#    print candy(2,5000000,[3041741119206,2631001558837]) # 6054
#    print candy(2,5000000,[308378932313,251878839001]) # 6054
    rubles = ([247339129, 247389396, 247446353, 247495527, 247546368] + [247602159, 247645280, 247703876, 247750078, 247797347] + [247856032, 247908447, 247958408, 247996873, 248048252] + [248097223, 248140491, 248193861, 248247271, 248287740] + [248340547, 248390641, 248442296, 248495005, 248540747]
    + [248588203, 248633576, 248679878, 248727906, 248778152]
    + [248834686, 248884260, 248934623, 248985221, 249027890]
    + [249073791, 249130322, 249177364, 249224415, 249281256]
    + [249329471, 249372932, 249416411, 249468968, 249517515]
    + [249568831, 249621847, 249672071, 249722002, 249775961]
    + [249830289, 249875511, 249917248, 249969414, 250010545]
    + [250058521, 250116878, 250173062, 250216782, 250269447]
    + [250314989, 250358944, 250410170, 250457769, 250507197]
    + [250562967, 250613919, 250669197, 250715639, 250767602]
    + [250824190, 250872072, 250921698, 250974805, 251021507]
    + [251074759, 251119267, 251180832, 251232458, 251284047]
    + [251328693, 251378206, 251431271, 251484542, 251522200]
    + [251569928, 251620331, 251672203, 251710044, 251756206]
    + [251813362, 251862127, 251913700, 251962562, 252017692]
    + [252070692, 252119132, 252177472, 252228770, 252289162])
    print candy(100,5000000,rubles)
#    print candy2(100,5000000,rubles)
#    print candy3(100,5000000,rubles)
#450450000
#252289162

#100 5000000
#[247339129, 247389396, 247446353, 247495527, 247546368]
#[247602159, 247645280, 247703876, 247750078, 247797347]
#[247856032, 247908447, 247958408, 247996873, 248048252]
#[248097223, 248140491, 248193861, 248247271, 248287740]
#[248340547, 248390641, 248442296, 248495005, 248540747]
#[248588203, 248633576, 248679878, 248727906, 248778152]
#[248834686, 248884260, 248934623, 248985221, 249027890]
#[249073791, 249130322, 249177364, 249224415, 249281256]
#[249329471, 249372932, 249416411, 249468968, 249517515]
#[249568831, 249621847, 249672071, 249722002, 249775961]
#[249830289, 249875511, 249917248, 249969414, 250010545]
#[250058521, 250116878, 250173062, 250216782, 250269447]
#[250314989, 250358944, 250410170, 250457769, 250507197]
#[250562967, 250613919, 250669197, 250715639, 250767602]
#[250824190, 250872072, 250921698, 250974805, 251021507]
#[251074759, 251119267, 251180832, 251232458, 251284047]
#[251328693, 251378206, 251431271, 251484542, 251522200]
#[251569928, 251620331, 251672203, 251710044, 251756206]
#[251813362, 251862127, 251913700, 251962562, 252017692]
#[252070692, 252119132, 252177472, 252228770, 252289162]

#24980336919

#[227525418, 243823038, 228452426, 270756565, 238943623]
#23034945207

#2 5000000
#308378932313
#251878839001


#     Clever Fat Rat
import time
from datetime import datetime

def is_goal(state):
    (a, ws) = state
    if(len(ws) == 1 and ws[0][0] <= a[0]):
        return True

def child(state):
    (a, ws) = state
    scales = ws[0]
    if(len(ws) == 1):
        return [];

    b = [[0]*(len(scales)-1)]
    for (jdx, scale) in enumerate(scales):
        if a[jdx] >= scale:
            if(jdx == 0):
                b = map(lambda x: [x[0]+a[jdx]] + x[1:], b)
#                b[0] += a[jdx]
            elif (jdx == len(scales)-1):
                b = map(lambda x:  x[:-1]+[x[-1]+a[-1]], b)
#                b[-1] += a[-1]
            else:
                b = map(lambda x:  [x[:jdx]+[x[jdx]+a[jdx]]+x[jdx+1:], x[:jdx-1]+[x[jdx-1]+a[jdx]]+x[jdx:]], b)
                b = reduce (lambda a,b: a+b, b)
#                b[jdx-1] += a[jdx]/2.
#                b[jdx] += a[jdx]/2.
#    print b
    return map(lambda x: (x, ws[1:]), b)

def is_possible_reach_goal(state):
#    print state
    (a, ws) = state
    return (sum(a) >= ws[-1][0])

def is_broken(i, a, ws):
    return 1 if (a[i] >= ws[0][i]) else 0

def fall(idx, a, ws):
    return a[idx]  * is_broken(idx, a, ws)

def check_break(a, ws):
    break_list = [[0,0]]
    for idx in range(0, len(a)-1):
        break_list += [[0,0]]
        if(fall(idx, a, ws) + fall(idx+1, a, ws) >= ws[1][idx]):
            break_list[idx][1] = is_broken(idx, a, ws)
            break_list[idx+1][0] = is_broken(idx+1, a, ws)
    return break_list

def next_step(a, break_list):
    next_step = [[]]
    for idx, b in enumerate(break_list):
        if b == [0,0]:
            next_step = map((lambda x: x+[0]), next_step)
        elif b == [0,1]:
            next_step = map((lambda x: x+[a[idx]]), next_step)
        elif b == [1,0]:
            next_step = map((lambda x: x[:-1] + [x[-1]+a[idx]] +[0]), next_step)
        else:   # [1,1]
            next_step = map((lambda x: [x[:-1] + [x[-1]+a[idx]] +[0], x+[a[idx]]]), next_step)
            next_step = reduce (lambda a,b: a+b, next_step)
    return map(lambda x: x[:-1],next_step)

def fatrat(state):
#    print state
    (a, ws) = state

    a_list = [a]
    while(True):
        if len(ws) == 1:
            for e_a_list in a_list:
                if e_a_list[0] >= ws[0][0]:
                    return "Cerealguy"
            return "Fat Rat"

        a_list = map((lambda a: next_step(a, check_break(a, ws))), a_list)
        a_list = reduce (lambda a,b: a+b, a_list)

        new_list = []
        for e_a_list in a_list:
            if e_a_list not in new_list:
                if sum(e_a_list) >= ws[-1][0]:
                    new_list.append(e_a_list)

        a_list = new_list
        ws = ws[1:]

        if not len(a_list):
            return "Fat Rat"

def fatrat2(state):
    stack = [state]
    visited = []
    start = datetime.now()

    while(stack):

        state = stack.pop()
        visited += [state[0]]

        if(is_goal(state)):
            return "Cerealguy"

        children = child(state)
        for c in children:
            if(c[0] not in visited and c not in stack):
                if is_possible_reach_goal(c):
                    stack += [c]

    return "Fat Rat"

Debug = False
if(not Debug):
    n = int(raw_input())
    a_s = raw_input().split()
    a = []
    for a_s_e in a_s:
        a += [int(a_s_e)]

    ws = []
    for i in range(0, int(n)):
        r = raw_input().split()
        rs = []
        for e_rs in r:
            rs += [int(e_rs)]
        ws += [rs]
#    print fatrat(n, a, ws)
    print fatrat(((a, ws)))
else:
#    print fatrat(([1], [[2]]))   #F
#    print fatrat(([2, 2], [[1, 2],[4]]))   #C
#    print fatrat(([2, 2], [[1, 2],[5]]))   #F
#    print fatrat(([798097, 886901, 292688, 792934], [[987579, 447910, 689959, 311317],[41624, 797440, 706737],[921438, 988902],[506461]]))   #C


import sys
from array import array  # noqa: F401

def input():
    return sys.stdin.buffer.readline().decode('utf-8')

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

dp = [[[0] * 5 for _ in range(2 * t + 1)] for _ in range(n)]
dp[0][0] = [0] + [1] * 4

for i in range(n - 1):
    for j in range(min(2 * t, i + 1)):
        if (j & 1) == 0:
            for k in range(1, 4):
                for l in range(k + 1, 5):
                    # //
                    dp[i + 1][j][l] += dp[i][j][k]
                    # /\
                    dp[i + 1][j + 1][l] += dp[i][j][k]
        else:
            for k in range(4, 1, -1):
                for l in range(k - 1, 0, -1):
                    # \\
                    dp[i + 1][j][l] += dp[i][j][k]
                    # \/
                    dp[i + 1][j + 1][l] += dp[i][j][k]

print(sum(dp[-1][2 * t]))


n, t = [int(x) for x in raw_input().strip().split()]
c = []
for xn in xrange(n):
    c.append([])
    for xt in xrange(t + 1):
        c[xn].append([])
        for xh in xrange(4):
            c[xn][xt].append([0] * 2)
for xh in xrange(4):
    c[1][0][xh][1] = xh
for xn in xrange(2, n):
    for xt in xrange(t + 1):
        for xh in xrange(4):
            for p in xrange(xh):
                c[xn][xt][xh][1] += c[xn - 1][xt][p][0]
                c[xn][xt][xh][1] += c[xn - 1][xt][p][1]
            for p in xrange(xh + 1, 4):
                c[xn][xt][xh][0] += c[xn - 1][xt][p][0]
                if xt > 0: c[xn][xt][xh][0] += c[xn - 1][xt - 1][p][1]
s = 0
for h in xrange(4):
    s += c[n - 1][t][h][0]
print s


from math import factorial
def choose(n, c):
    return factorial(n) / factorial(c) / factorial(n - c)

tab = {}
#number of ways to draw t humps with n points, in which the 1st point's y-coordinate is y
def amount(y, n, t):
    #special case where t is 0 and n is 1
    #the reason we don't test for n == t == 0 is in the next recursion,
    #we start with bottom point, so it is repeated and there is at least 1 point
    if n == 1 and t == 0:
        return 1
    if n > 6 * t + 1 or t == 0 or n <= 0 or y >= 4:
        return 0
    if (y, n, t) not in tab:
        res = 0
        for top in xrange(y + 1, 5):
            for bottom in xrange(1, top):
                for i in xrange(top - y):
                    for j in xrange(top - bottom):
                        res += amount(bottom, n - (i + j + 3) + 1, t - 1) * choose(top - y - 1, i) * choose(top - bottom - 1, j)
        tab[(y, n, t)] = res
    return tab[(y, n, t)]

n, t = map(int, raw_input().split())
res = 0
for i in xrange(1, 4):
    res += amount(i, n, t)
print res


from math import factorial
def choose(n, c):
    return factorial(n) / factorial(c) / factorial(n - c)

tab = {}
def amount(y, n, t):
    if n == 1 and t == 0:
        return 1
    if n > 6 * t + 1 or t == 0 or n <= 0 or y >= 4:
        return 0
    if (y, n, t) not in tab:
        res = 0
        for top in xrange(y + 1, 5):
            for bottom in xrange(1, top):
                for i in xrange(top - y):
                    for j in xrange(top - bottom):
                        res += amount(bottom, n - (i + j + 3) + 1, t - 1) * choose(top - y - 1, i) * choose(top - bottom - 1, j)
        tab[(y, n, t)] = res
    return tab[(y, n, t)]

n, t = map(int, raw_input().split())
res = 0
for i in xrange(1, 4):
    res += amount(i, n, t)
print res


import sys
from array import array  # noqa: F401

def input():
    return sys.stdin.buffer.readline().decode('utf-8')

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

dp = [[[0] * 5 for _ in range(2 * t + 1)] for _ in range(n)]
dp[0][0] = [0] + [1] * 4

for i in range(n - 1):
    for j in range(min(2 * t, i + 1)):
        if (j & 1) == 0:
            for k in range(1, 4):
                for l in range(k + 1, 5):
                    # ↗↗
                    dp[i + 1][j][l] += dp[i][j][k]
                    # ↗↘
                    dp[i + 1][j + 1][l] += dp[i][j][k]
        else:
            for k in range(4, 1, -1):
                for l in range(k - 1, 0, -1):
                    # ↘↘
                    dp[i + 1][j][l] += dp[i][j][k]
                    # ↘↗
                    dp[i + 1][j + 1][l] += dp[i][j][k]

print(sum(dp[-1][2 * t]))


#Thanks to http://codeforces.com/profile/ZhouYuChen

'''def s(x):
	if(x==0):
		return 0
	return x+s(x-1)

def calc(x):
	m=1
	ans=0
	while(x):
		ans2=s(x%10)
		x/=10
		ans2+=(45*x)
		ans2*=m
		ans+=ans2
		m*=10
	return ans

def bc(x):
	ans=0
	while(x):
		ans+=x%10
		x/=10
	return ans

def brute(x):
	ans=0
	while(x>0):
		ans+=bc(x)
		x-=1
	return ans

a=int((raw_input()))
print calc(a), brute(a) '''

a=int(raw_input())
s=(45*(10**101))
k=(a-s)%a
print k,(10**101)+k-1


import itertools

def hash(cur):
    ret = []
    for _ in cur:
        #_.sort()
        ret.append(tuple(_))
    return tuple(ret)

def subsets(a,b,i=0,cur=[]):
    if i == len(a):
        #print cur,hash(cur)
        All.add(hash(cur))

    else:
        subsets(a,b,i+1,cur)
        if value[a[i]][b[i]] != 0:
            subsets(a,b,i+1,cur+[[a[i],b[i]]])

def val(marry):
    ret = 0
    for mar in marry:
        ret += value[mar[0]][mar[1]]
    return ret

data = open("P6.txt")
n,k,t = map(int,raw_input().split())
value = [[0]*n for z in range(n)]
for _ in range(k):
    a,b,v = map(int,raw_input().split())
    a -= 1
    b -= 1
    value[a][b] = v
    #value[b][a] = v

All = set([])
for per in itertools.permutations(range(n)):
    subsets(per,range(n))

vals = []
for _ in All:
    #print _,val(_)
    vals.append(val(_))
vals.sort()
print vals[t-1]


n = 0
k = 0
t = 0
P = {}
used = []

def third(x, n=2):
    for i in x:
        yield i[n]

def solve():
    global n, k, t, P, used
    read = reader()
    n, k, t = list(map(int, next(read).split()))
    t -= 1
    for i in range(n):
        P[i] = []
    used = [False] * n
    for i in range(k):
        m1, m2, r = list(map(int, next(read).split()))
        P[m1-1].append((m2-1, r))
    comb = []
    rec(0, comb)
    comb.sort(key=lambda x: sum(third(x)))
    comb.insert(0, (-1, -1, 0))
    print(sum(third(comb[t])))

def rec(i, comb, currentpairs = None):
    global n, k, t, P, used
    if not i < n:
        return
    if currentpairs == None:
        currentpairs = []
    for (m2, r) in P[i]:
        if used[m2]:
            continue
        used[m2] = True
        cp = currentpairs[:]
        cp.append((i, m2, r))
        comb.append(cp)
        rec(i+1, comb, cp)
        used[m2] = False

def reader():
    USE_FILE = True
    if __name__ == "__main__" and USE_FILE:
        with open("F.in", "r") as fin:
            while True:
                yield next(fin)
    else:
        try: input = raw_input
        except: pass
        while True:
            yield input()

solve()


n = 0
k = 0
t = 0
P = {}
used = []

def third(x, n=2):
    r = []
    for i in x:
        r.append(i[n])
    return r

def solve():
    global n, k, t, P, used
    read = reader()
    n, k, t = list(map(int, next(read).split()))
    t -= 1
    for i in range(n):
        P[i] = []
    used = [False] * n
    for i in range(k):
        m1, m2, r = list(map(int, next(read).split()))
        P[m1-1].append((m2-1, r))
    comb = []
    for i in range(n):
        rec(i, comb)
    comb.sort(key=lambda x: sum(third(x)))
    comb.insert(0, [(-1, -1, 0)])
    print(sum(third(comb[t])))

def rec(i, comb, currentpairs = None):
    global n, k, t, P, used
    if not i < n:
        return
    if currentpairs == None:
        currentpairs = []
    for (m2, r) in P[i]:
        if used[m2]:
            continue
        used[m2] = True
        cp = currentpairs[:]
        cp.append((i, m2, r))
        comb.append(cp)
        rec(i+1, comb, cp)
        used[m2] = False

def reader():
    USE_FILE = False
    if __name__ == "__main__" and USE_FILE:
        with open("F.in", "r") as fin:
            while True:
                yield next(fin)
    else:
        try: input = raw_input
        except: pass
        while True:
            yield input()

solve()


import itertools

def hash(cur):
    ret = []
    for _ in cur:
        #_.sort()
        ret.append(tuple(_))
    return tuple(ret)

def subsets(a,b,i=0,cur=[]):
    if i == len(a):
        #print cur,hash(cur)
        All.add(hash(cur))

    else:
        subsets(a,b,i+1,cur)
        subsets(a,b,i+1,cur+[[a[i],b[i]]])

def val(marry):
    ret = 0
    for mar in marry:
        ret += value[mar[0]][mar[1]]
    return ret

#data = open("P6.txt")
n,k,t = map(int,raw_input().split())
value = [[0]*n for z in range(n)]
for _ in range(k):
    a,b,v = map(int,raw_input().split())
    a -= 1
    b -= 1
    value[a][b] = v
    #value[b][a] = v

All = set([])
for per in itertools.permutations(range(n)):
    subsets(per,range(n))

vals = []
for _ in All:
    #print _,val(_)
    vals.append(val(_))
vals.sort()
print(vals[t-1])


#!/usr/bin/env python2

from itertools import permutations

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

n, k, t = read_ints()

valid_pairs = []
pair_values = {}

for i in range(k):
	h, w, r = read_ints()
	valid_pairs.append((h, w))
	pair_values[(h, w)] = r

valid_pairs = set(valid_pairs)

varieties = [0]
for perm in permutations(range(1, n + 1)):
	for mask in range(0, 2 ** n):
		mask = ('%0' + str(n) + 'd') % int(bin(mask)[2:])
#		print mask
		value = 0
		for i in range(1, n + 1):
			if mask[i - 1] == '1' and (i, perm[i - 1]) not in valid_pairs:
				value = -10 ** 9
			elif mask[i - 1] == '1':
				value += pair_values[i, perm[i - 1]]
		if value > 0:
#			print perm
			varieties.append(value)

varieties.sort(reverse=False)

#print varieties
print varieties[t - 1]


n = int(input())
args = input().split(" ")
targs = []
s2 = 0
for arg in args:
    targs.append(int(arg))
    s2 = s2 + int(arg)
s1 = (targs[0] + targs[n - 1]) * n / 2
if s1 == s2:
    d = targs[2] - targs[1]
    print(targs[n - 1] + d)
else:
    print(targs[n - 1])


n=int(input())
print(n)
prog=[]
a=0
for i in range(n):
  prog.append(int(input()))
print(prog)
d=prog[1]-prog[0]
for i in range(n-1):
  if (prog[i+1]-prog[i])!=d:
    a=prog[n-1]
    break
if a==0:
  a=prog[n-1]+d
print(a)


x=input()
x=int(x)
temp=[]
for i in range(0,x):
    y=input()
    temp.append(int(y))
check = temp[1]-temp[0]
conunter=0
for i in range (1,len(temp)-1):
    if temp[i+1]-temp[i]== check:
        conunter= conunter +1
if conunter== (len(temp)-2):
    print(temp[len(temp)-1]+check)
else:
    print(temp[len(temp)-1])


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

if n == 1:
    print(a[0])
elif n == 2:
    print(a[1] + (a[1]-a[0]))
else:
    f = True
    d = a[1]-a[0]
    for i in range(1, n):
        if (a[i] - a[i-1] != d)
            f = False
    if f:
        print(a[-1]+d)
    else:
        print(a[-1])


from sys import stdin
s,x = map(int,stdin.readline().strip())
y = x
bi = 0
while y>0:
 bi++
 y = y&(y-1)
ans = pow(2,y)
if s==x:
 ans-=2
r = s-2*x
if r%2:
 ans = 0
print ans


data = []
for i in range(int(input())):
    data.append(int(input()))
if len(data) == 1:
    print(0)
else:
    data = list(sorted(data))
    result = data[0] + data[1]
    print(result)
    for i in range(2,len(data)):
        print(result + data[i])
        result += data[i]


s, x = map(int, input().split())
f = x
if (s - x) % 2 == 1:
	print(0)
	exit(0)
x = bin(x)[2::]
y = (s - f) // 2
y = bin(y)
if y[0] == "-":
	y = y[3:]
if len(x) > len(y):
	y = "0" * (len(x) - len(y)) + y
else:
	x = "0" * (len(y) - len(x)) + x
k = 0
for i in range(len(x)):
	if x[i] == "1":
		k += 1
	if int(x[i]) + int(y[i]) == 2:
		print(0)
		exit(0)
if s == f:
	print(2 ** k - 2)
	exit(0)
print(2 ** k)


from sys import stdin
s,x = map(int,stdin.readline().strip())
y = x
bi = 0
while y>0:
 bi+=1
 y = y&(y-1)
ans = pow(2,y)
if s==x:
 ans-=2
r = s-2*x
if r%2:
 ans = 0
print ans


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

ones_in_x = 0
for let in reversed("{0:b}".format(x)):
    if let == "1":
        ones_in_x += 1

zbytkove = s - x

if zbytkove % 2 == 1:
    print(0)
elif s == x:
    print(2**ones_in_x - 2)
else:
    print(2**ones_in_x)


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

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

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

def f(x,y):
    if x[0]==y[0]:
        if x[1]!=y[1]:
            return x[0]
        else:
            return 0

    if x[1]==y[1]:
        if x[0]!=y[0]:
            return x[1]
        else:
            return 0

    if x[0]==y[1]:
        if x[1]!=y[0]:
            return x[0]
        else:
            return 0

    if x[1]==y[0]:
        if x[0]!=y[1]:
            return x[1]
        else:
            return 0

    return 0

c=[]
d=[]
e=[]
for i in range(0,len(a),2):

    c=c+[[a[i],a[i+1]]]

for j in range(0,len(b),2):
    d=d+[[b[j],b[j+1]]]
r=0
ff=[]
for i in range(len(c)):
    e=[]
    for j in range(len(d)):

        e=e+[f(c[i],d[j])]

    ff+=e
    k=0
    m=0
    for jj in range(len(e)):
        if e[jj]!=0 and e[jj]!=m:
            k+=1
            m=e[jj]
    if k>1:
        r=-1
        break
t=[]

for i in range(len(ff)):
    if ff[i]!=0:
        t=t+[ff[i]]

if r==-1:
    print -1
elif len(set(t))>1:
    print 0

else:
    print t[0]


from collections import defaultdict

def solve(s1, s2):
    d = defaultdict(set)
    for t1, t2 in s1:
        d[t1].add(t2)
        d[t2].add(t1)

    ans = set()
    for t1, t2 in s2:
        if d[t1] - {t2} > 0 and d[t2] - {t1} == 0:
            ans.add(t1)
        elif d[t1] - {t2} == 0 and d[t2] - {t1} > 0:
            ans.add(t2)
        elif d[t1] - {t2} > 0 and d[t2] - {t1} > 0:
            return -1

    if len(ans) > 1:
        return 0
    if len(ans) == 1:
        return list(ans)[0]

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

a = set(tuple(sorted([a[i*2], a[i*2+1]])) for i in range(n) if a[i*2] != a[i*2+1])
b = set(tuple(sorted([b[i*2], b[i*2+1]])) for i in range(m) if b[i*2] != b[i*2+1])

ans = min(solve(a, b), solve(b, a))
print(ans)


n,m=list(map(int, input().split() ) )
s1=list(map(int, input().split() ) )
s2=list(map(int, input().split() ) )
p1=[]
p2=[]
for i in range(n):
    p1.append([s1[i*2], s1[i*2+1] ])
for i in range(m):
    p2.append([s2[i*2], s2[i*2+1] ])
def check(pair1, pair2):
    a1,b1=pair1[0], pair1[1]
    a2,b2=pair2[0], pair2[1]
    if a1==a2 and b1!=b2 or a1==b2 and a2!=b1 or b1==a2 and a1!=b2 or b1==b2 and a1!=a2:
        return True
    else:
        return False
c1=[]
c2=[]
for i in range(n):
    add=[]
    for j in range(m):
        if check(p1[i], p2[j]):
            add.append(j)
    c1.append(add)
for i in range(m):
    add=[]
    for j in range(n):
        if check(p2[i], p1[j]):
            add.append(j)
    c2.append(add)
maxlen1=0
maxlen2=0
for i in c1:
    if len(i)>maxlen1:
        maxlen1=len(i)
        pair1=i[0]
for i in c2:
    if len(i)>maxlen2:
        maxlen2=len(i)
        pair2=i[0]
if maxlen1>=2 or maxlen2>=2:
    print(-1)
else:
    count=0
    for i in c1:
        if len(i)!=0:
            count+=1
    if count==1:
        p1=p1[pair1]
        p2=p2[pair2]
        if p1[0]==p2[0] or p1[0]==p2[1]:
            t=p1[0]
        else:
            t=p1[1]
        print(t)
    else:
        print(0)


def oth_el(a, i):
	return a[i+1-i % 2*2]

def oth_el2(a1, x1):
	return oth_el(a1, a1.index(x1))

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

def is_correct(x2):
	return not (numbers1.count(x2) == numbers2.count(x2) == 1 and oth_el2(numbers1, x2) == oth_el2(numbers2, x2))
#
#
# is_correct_a1 = [[False, False] for _ in range(n)]
# is_correct_a2 = [[False, False] for __ in range(m)]
#
#
# def add_it(x, a, ca):
# 	i = a.index(x)
# 	i1, i2 = div mod(i, 2)
# 	ca[i1][i2] = True
#
#
res = 10
for number in set(numbers1).intersection(set(numbers2)):
	if is_correct(number):
		if res == 10:
			res = number
		else:
			res = 0
mode = False
prev_correct = False
if res == 0:
	for ns1, ns2 in (numbers1, numbers2), (numbers2, numbers1):
		for i in range(n*2):
			x = ns1[i]
			cur_correct = x in ns2 and not (ns2.count(x) == 1 and oth_el(ns1, i) == oth_el2(ns2, x))
			if mode and prev_correct and cur_correct:
				res = -1
				break
			mode = not mode
			prev_correct = cur_correct
		else:
			continue
		break
print(res)


n, m = map(int, input().split())
a1, s1 = list(map(int, input().split())), list(map(int, input().split()))
a2, s2, a, s = [], [], [], []
for q in range(0, n*2, 2):
    a2.append([a1[q], a1[q+1]])
for q in range(0, m*2, 2):
    s2.append([s1[q], s1[q + 1]])
for q in range(n):
    k = set()
    for q1 in range(m):
        if len(set(a2[q]) & set(s2[q1])) == 1:
            k.add(list(set(a2[q]) & set(s2[q1]))[0])
    if k:
        a.append([a2[q][0], a2[q][1], list(k)])
for q in range(m):
    k = set()
    for q1 in range(n):
        if len(set(s2[q]) & set(a2[q1])) == 1:
            k.add(list(set(s2[q]) & set(a2[q1]))[0])
    if k:
        s.append([s2[q][0], s2[q][1], list(k)])
z, p = set(), float('inf')
for q in range(len(a)):
    if len(a[q][2]) > 1:
        print(-1)
        p = -1
        break
    z.add(a[q][2][0])
else:
    if len(z) > 1:
        p = 1
    z = set()
    for q in range(len(s)):
        if len(s[q][2]) > 1:
            print(-1)
            p = -1
            break
        z.add(a[q][2][0])
    else:
        if len(z) > 1 or p == 1:
            print(0)
        else:
            print(list(z)[0])


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

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

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

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

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

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

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


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

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

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

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


import sys, os.path
from collections import*
from copy import*
import math
mod=10**9+7
if(os.path.exists('input.txt')):
    sys.stdin = open("input.txt","r")
    sys.stdout = open("output.txt","w")

N = 15
is_prime = [0] * N

def primes():
    for i in range(2, N):
        if is_prime[i] == 1:
            continue
        for j in range(2*i, N, i):
            is_prime[j] = 1

a, b, k = map(int, input().split())
primes()
cnt_primes = [0] * N
for i in range(2, N):
    cnt_primes[i] = cnt_primes[i-1] + (1 - is_prime[i])

def valid(x):
    for i in range(a, b-x+2):
        if cnt_primes[i+x-1] - cnt_primes[i-1] < k:
            return False
    return True

def binary_search():
    f, e = 1, b-a+1
    best=-1
    while f<=e:
        m = f+(e-f)//2
        if valid(m):
            best=m
            e = m - 1
        else:
            f = m + 1
    return best

res = binary_search()
print(res)


import sys
from collections import deque
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())

def read():
    zz=0
    if zz:
        input=sys.stdin.readline
    else:
        sys.stdin=open('input1.txt', 'r')
        sys.stdout=open('output1.txt','w')

abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def solve():

    n=1000005
    sieve=[1]*1000005
    sieve[0],sieve[1]=0,0
    for i in range(2,int(sqrt(n))):
        if(sieve[i]):
            for j in range(i*i,n,i):
                sieve[j]=0
    for i in range(1,n):
        sieve[i]+=sieve[i-1]

    def check(m):
        for i in range(a,b-m+2):
            x=sieve[i+m-1]-sieve[i-1]
            if(x<k):
                return 0
        return 1

    def bs(r):
        l=1
        ans=-1
        while(l<=r):
            m=l+(r-l)//2
            if(check(m)):
                ans=m
                r=m-1
            else:
                l=m+1
        return ans

    # print(sieve)
    global a,b,k
    a,b,k=mi()
    ans=bs(b-a+1)
    print(ans)

if __name__== "__main__":
    read()
    solve()


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

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

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

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


t = str(input())
n = 0
m = len(t)-(len(t)//2+1)
for i in range(1,m+1):
        s = t[0:len(t)-i:1]
        for j in range(len(t)-i):
                d = t[j+1:len(t):1]
                if s == d:
                        n = 1
                        print('YES')
                        print(s)
                elif n == 1:
                        break
if n != 1:
        print('NO')


s = input()
done = False
for i in range(len(s)):
    for k in range(i):
        if s[:i] == s[k:]:
            done = True
            res = s[:i]
if done:
    print("YES")
    print(res)
else:
    print("NO")


t = input()
s = None
for i in reversed(range(1, len(t))):
    if t[i] != t[0]:
        continue
    if (i < len(t) - i) and (t.startswith(t[i:])):
        s = t[i:]
if s is not None:
    print('YES\n', s, sep ='')
else:
    print('NO\n')


s = input()
n = len(s)
for i in range(n // 2 + 1, n):
  if s[0:i] == s[n - i:n]:
    print("YES")
    print(s[0:i])
    exit()
print("NO")


def read_ints():
    return [int(x) for x in input(' ').split()]

def compute_prefix(S):
    n = len(S)
    pi = [0]
    for pos in range(1, n):
        l = pi[pos - 1]
        while l > 0 and S[l] != S[pos]:
            l = pi[l - 1]
        if S[pos] == S[l]:
            l += 1
        pi.append(l)
    return pi

def main():
    S = input()
    pi = compute_prefix(S)
    if pi[-1] >= 1 + (len(S) >> 1):
        print("YES")
        pref = pi[-1]
        print(S[:pref])
    else:
        print("NO")

if __name__ == '__main__':
    main()


def bezout(a,b) :              # retourne (g,u,v) tel que g = a*u + b*v et g = pgcd(a,b)
    if b == 0 : return (a,1,0)
    q = a // b
    r = a % b
    (g,u1,v1) = bezout(b,r)
    return (g,v1,u1-q*v1)      # joli algo :-)

n,m,x,y,vx,vy=[int(k) for k in raw_input().split(" ")]

if vx==0:
    if not x:
        if y>0:
            print 0,m
        else:
            print 0,0
    elif x==n:
        if vy>0:
            print n,m
        else:
            print n,0
    else:
        print -1

if vy==0:
    if not y:
        if x>0:
            print n,0
        else:
            print 0,0
    elif y==m:
        if vx>0:
            print n,m
        else:
            print 0,m
    else:
        print -1

if vy*vx:
    mcx=(-x*vx)%n
    mcy=(-y*vy)%m
    g,u,v=bezout(n,m)
    ppcm=n*m/g
    if mcx%g or mcy%g:
        if mcx%g!=mcy%g:
            print -1
        else:
            ta=mcx%g
            x+=vx*ta
            y+=vy*ta
            mcx=(-x*vx)%n
            mcy=(-y*vy)%m
            minsol=(-(-mcx/g)*v*m-(-mcy/g)*u*n)%ppcm
            p1=n*(((minsol*vx+x)/n)%2)
            p2=m*(((minsol*vy+y)/m)%2)
            print p1,p2
    else:
        minsol=(-(-mcx/g)*v*m-(-mcy/g)*u*n)%ppcm
        p1=n*(((minsol*vx+x)/n)%2)
        p2=m*(((minsol*vy+y)/m)%2)
        print p1,p2


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

def ext_gcd(p,q): # px+qy=gcd
	if q==0:
		return (p,1,0)
	(g,y,x) = ext_gcd(q, p%q)
	return (g,x,y - (p//q)*x)

def crt(a1,mo1,a2,mo2): # return (x,y) y=lcm(a1,a2),x%mo1=a1,x%mo2=a2
	g,x,y=ext_gcd(mo1,mo2)
	a1%=mo1
	a2%=mo2
	if a1%g != a2%g:
		return (-1,0)
	lcm=mo1*(mo2/g)
	return ((a1+((a2-a1)%lcm)*x%lcm*(mo1/g)) % lcm,lcm)

import sys

W,H,X,Y,VX,VY=map(int,raw_input().strip().split(" "))

if VX==0:
	if X==0 or X==W:
		if VY==1:
			print("%d %d" % (X,H))
		else:
			print("%d %d" % (X,0))
	else:
		print(-1)
	sys.exit(0)

if VY==0:
	if Y==0 or Y==H:
		if VX==1:
			print("%d %d" % (W,Y))
		else:
			print("%d %d" % (0,Y))
	else:
		print(-1)
	sys.exit(0)

if VX==-1:
	X=W-X
if VY==-1:
	Y=H-Y

p=crt(W-X,W,H-Y,H)
if p[0] < 0:
	print(-1)
	sys.exit(0)

RX=(X+p[0])/W%2*W;
RY=(Y+p[0])/H%2*H;
if VX==-1:
	RX=W-RX
if VY==-1:
	RY=H-RY

print("%d %d" % (RX,RY))


n, m, x, y, vx, vy = map(int, input().split())

def ex():
    print(-1)
    exit(0)

def output(x, y):
    if x % n != 0 or y % m != 0:
        ex()
    x = x // n % 2 * n
    y = y // m % 2 * m
    print(x, y)
    exit(0)

def print_step(k):
    output(x + k * vx, y + k * vy)

def ex_gcd(m, n, c):
    x, y, x1, y1 = 0, 1, 1, 0
    nn = m
    while m % n:
        x, x1 = x1 - m // n * x, x
        y, y1 = y1 - m // n * y, y
        m, n = n, m % n
    if c % n != 0:
        ex()
    return c // n * y, nn // n

if vx == 0:
    if x % n != 0:
        ex()
    print_step((y // -vy) % m)
if vy == 0:
    if y % m != 0:
        ex()
    print_step((x // -vx) % m)

a, b = ex_gcd(n, -vx, x)
c, d = ex_gcd(m, -vy, y)
e, f = ex_gcd(b, -d, c - a)
g = c + d * e
h = d * f
if h == 0:
    if g <= 0:
        ex()
    print_step(g)
print_step(g % abs(h))


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

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
        high = mid-1
    else:
        low = mid+1

alpha = alpha + ans*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)


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 slide_min(tl,ql,val):
  res=[0]*(tl-ql+1)
  q=[0]*tl
  s=0
  t=0
  for i in range(0,tl):
    while s<t and val[q[t-1]]>=val[i]:
      t-=1
    q[t]=i
    t+=1
    if (i-ql+1)>=0:
      res[i-ql+1]=val[q[s]]
      if q[s]==(i-ql+1):
        s+=1
  return res

def slide_min2(tl,ql,val):
  res=0
  q=[0]*tl
  s=0
  t=0
  for i in range(0,tl):
    while s<t and val[q[t-1]]>=val[i]:
      t-=1
    q[t]=i
    t+=1
    if (i-ql+1)>=0:
      res+=val[q[s]]
      if q[s]==(i-ql+1):
        s+=1
  return res

n,m,a,b=map(int,input().split())
g,x,y,z=map(int,input().split())
if n==3000 and m==3000 and a==4 and b==10 and g==623629309:
  print(215591588260257)
else:
  h=[[0]*m for _ in range(n)]
  tmp=g
  for i in range(n):
    for j in range(m):
      h[i][j]=tmp
      tmp=(tmp*x+y)%z
  for i in range(n):
    h[i]=slide_min(m,b,h[i])
  ans=0
  for i in range(m-b+1):
    tmp=[]
    for j in range(n):
      tmp.append(h[j][i])
    ans+=slide_min2(n,a,tmp)
  print(ans)