import time
import os,sys
from datetime import datetime
from math import floor,sqrt,gcd,factorial,ceil,log2
from collections import Counter,defaultdict
import bisect
from itertools import chain
from collections import deque
from sys import maxsize as INT_MAX
from itertools import permutations
from collections import deque
#import threading
'''Dont use setrecursionlimit in pypy'''
#sys.setrecursionlimit(int(1e9)+500)
#threading.stack_size(0x2000000)
ONLINE_JUDGE,INF,mod=False,float('inf'),int(1e9)+7
if os.path.exists('D:\\vimstuff'):
	ONLINE_JUDGE=True
	sys.stdin=open('D:\\vimstuff\\inp.txt','r')
	sys.stdout=open('D:\\vimstuff\\out.txt','w')
'''def ceil(a,b):
	return(int((a+b-1)/b))'''

def readint():
	return int(sys.stdin.readline())
def readstr():
	return sys.stdin.readline()
def readlst():
	return list(map(int, sys.stdin.readline().strip().split()))
def readmul():
	return map(int, sys.stdin.readline().strip().split())
def mulfloat():	return map(float, sys.stdin.readline().strip().split())
def flush():
	return sys.stdout.flush()
def power_two(x):
	return (1<<x)
def lcm(a,b):
	return a*b//gcd(a,b)

def countGreater(arr,n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while (l <= r):
		m = int(l + (r - l) / 2)
		if (arr[m] >= k):
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
			return (n - leftGreater)

def lower_bound(arr,n,val):
	l,r=-1,n
	while r>l+1:
		m=int((l+r)>>1)
		if arr[m]<val:
			l=m
		else:
			r=m
	return r

def upper_bound(arr,n,val):
	l,r=-1,n
	while r>l+1:
		m=int((l+r)>>1)
		if arr[m]<=val:
			l=m
		else:
			r=m
	return l

def binpow(a,n,mod):
	res=1
	while n:
		if n&1:
			res=(res*a)%mod
			n-=1
		a=(a*a)%mod
		n=n>>1
	return res

def printmat(l,seperate=True):
	for i in range(0,len(l)):
		if(seperate):
			print(*l[i],sep=" ")
		else:
			print(*l[i],sep="")

def is_perfect_square(num):
	#print(num)
	temp = num**(0.5)
	#print(temp)
	return (temp//1)==temp

def find(res):
	n1=res
	while par[n1]!=n1:
		par[n1]=par[par[n1]]
		n1=par[n1]
	return n1

def union(u,v):
	p1,p2=find(u),find(v)
	if p1==p2:
		return 0
	if(rank[p1]>rank[p2]):
		p1,p2=p2,p1
	par[p1]=p2
	rank[p2]+=rank[p1]
	return 1

'''
c-space = to copy
o-space= to open file
,-space=to run prog
:noh= to get rid of text highlight

1. Implement after understanding properly don't do in vain.
2. Check corner cases.
3. Use python if there is recursion,try-catch,dictionary.
4. Use pypy if heavy loop,list slice.
'''
def john_3_16():
    n=readint()
    num_node=2**n
    ans=binpow(4,num_node-2,mod)
    ans=(ans*6)%mod
    print(ans)
    return

def main():
	#tc=readint()
	tc=1
	#cnt=0
	start=time.time()
	#cnt=1
	while tc:
		john_3_16()
		tc-=1
		#cnt+=1
	if ONLINE_JUDGE:
		print(f'{(time.time()-start)*1000}ms')
		pass
main()


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int areTests = 0;

int f(int n) {
	array <int, 6> dp[n + 1];
	for(int j = 0; j < 6; j++) dp[1][j] = 1;
	for(int i = 2; i <= n; i++) {
		int s = 0;
		for(int j = 0; j < 6; j++) s += dp[i - 1][j];

		for(int j = 0; j < 6; j++) {
			dp[i][j] = s - dp[i - 1][j] - dp[i - 1][5 - j];
		}
	}

	int ans = 0;
	for(int j = 0; j < 6; j++) ans += dp[n][j];
	return ans;
}

void run_test(int testcase) {
	for(int i = 1; i <= 12; i++) cout << f(i) << " ";
}

int main() {
	ios::sync_with_stdio(0);
	#ifndef DUSH1729
	cin.tie(0);
	#endif
	cout << fixed << setprecision(10);

	int t = 1;
	if(areTests) cin >> t;
	for(int i = 1; i <= t; i++) {
		run_test(i);
	}
}


a1,b1,a2,b2,l,r=map(int,raw_input().split())
ks1=(l-b1)/a1
ke1=(r-b1)/a1
ks2=(l-b2)/a2
ke2=(r-b2)/a2

lst1=[]
lst2=[]
ks1=max(0,ks1)
ke1=max(0,ke1)
ks2=max(0,ks2)
ke2=max(0,ke2)
for i in range(ks1,ke1+2):
    if(a1*i+b1>=l and a1*i+b1<=r):
        lst1.append(a1*i+b1)
for i in range(ks2,ke2+2):
    if(a2*i+b2>=l and a2*i+b2<=r):
        lst2.append(a2*i+b2)

set1=set(lst1)
set2=set(lst2)

l=len(set1.intersection(set2))
print l


from sys import stdin,stdout
import math

def gcd_ext(a, b):
    if b == 0:
        return (a,1,0)
    else:
        g,x,y = gcd_ext(b, a%b)
        t = x;
        x = y;
        y = t - a/b*y
        return g,x,y

a1,b1,a2,b2,L,R = [ int(x) for x in stdin.readline().rstrip().split() ]

A = a1
B = a2
C = b2 - b1

G,X,Y = gcd_ext( A, B )

if C % G != 0:
    print 0
    sys.exit(0)

X = X*C/G
Y = Y*C/G

K = max( [ math.ceil( -X*G/float(B) ), math.ceil( Y*G/float(A) ) ] )

#print int(K)

#print "LOWER", (L - b1 - a1 * X) * G / float( B * a1 ), (L - b2 + a2 * Y) * G / float( A * a2 )
#print "UPPER", (R - b1 - a1 * X) * G / float( B * a1 ), (R - b2 + a2 * Y) * G / float( A * a2 )
#print "S", a1 * (X + B*K/G) + b1, "T", a2 * (-Y + A*K/G) + b2

K = max( [ K, math.ceil( (L - b1 - a1 * X) * G / float( B * a1 ) ) ] )

ANS = math.floor( (R - b1 - a1 * X) * G / float( B * a1 ) ) - K + 1

print max( [ 0, int(ANS) ] )


def gcd(a, b):
    if (a == 0):
        return [0, 1, b];
    res = gcd(b%a, a);
    d = res[2]
    x1 = res[0]
    y1 = res[1]
    return [y1 - (b // a) * x1, x1, d];

def find_any_solution(a, b, c):
    res = gcd(abs(a), abs(b))
    g = res[2]
    x0 = res[0]
    y0 = res[1]
    if (c % g != 0):
        return [False, 0, 0]
    x0 *= (c // g);
    y0 *= (c // g);
    if (a < 0):
        x0 = -x0;
    if (b < 0):
        y0 = -y0;
    return [True, x0, y0, g];
# print(map(int, raw_input().split()))
a1, b1, a2, b2, L, R = map(int, raw_input().split())
bo, l, r, g = find_any_solution(a1, a2, b2 - b1)
# print(bo, l, r)
if bo:
    aa = a1 * l + b1
    dd = (a1 * a2) // g
    bb = max(b1, b2)
    ll = (bb - aa + dd - 1) // dd
    aa = aa + dd * ll
    oo = max((L - aa + dd - 1) // dd, 0)
    op = (R - aa) // dd
    print(max(op - oo + 1, 0))
else:
    print(0)


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

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

def modpow(x,y,m):
    # (x**y) % m
    if y==0: return 1%m
    elif y==1: return x%m
    elif y&1: return (modpow((x*x)%m,y//2,m)*x)%m
    else: return modpow((x*x)%m,y//2,m)

def inv(x,m):
    # return the inverse of x, modulo m
    # use euler's theorem
    tot=m
    mt=m
    for i in range(2,mt):
        if i*i>mt: break
        if mt%i==0:
            tot//=i
            tot*=i-1
            while mt%i==0: mt//=i
    if mt>1:
        tot//=mt
        tot*=mt-1
    # totient(m) = tot
    return modpow(x%m,tot-1,m)

def crt(x1,m1,x2,m2):
    # chinese remainder theorem solver
    # clean up
    m1=abs(m1)
    m2=abs(m2)
    x1%=m1
    x2%=m2
    if m1>m2:
        m1,m2=m2,m1
        x1,x2=x2,x1
    # get out a factor
    t=gcd(m1,m2)
    offset=x1%t
    if x1%t != x2%t:
        print("Something went wrong with the no intersection step")
    x1//=t
    m1//=t
    x2//=t
    m2//=t
    # get important numbers
    # r1 is 1 mod m1 and 0 mod m2
    # r2 is 0 mod m1 and 1 mod m2
    r1=(m2*inv(m2,m1))%(m1*m2)
    r2=(m1*inv(m1,m2))%(m1*m2)
    # pretty much done
    return t*((x1*r1+x2*r2)%(m1*m2))+offset

# k',l'>=0 is the most annoying thing ever
a1,b1,a2,b2,l,r=map(int,input().split())

# bound l,r so nothing breaks
if a1>=0: l=max(l,b1)
if a1<=0: r=min(r,b1)
if a2>=0: l=max(l,b2)
if a2<=0: r=min(r,b2)

if l>r: print(0)
elif l==r:
    # special case
    ans=1
    if b1!=l and (a1==0 or (l-b1)%a1 or (l-b1)//a1<0): ans=0
    if b2!=l and (a2==0 or (l-b2)%a2 or (l-b2)//a2<0): ans=0
    print(ans)
elif (b1-b2)%gcd(a1,a2)!=0:
    # they don't intersect
    print(0)
else:
    # general case is the best case
    a3=abs((a1*a2)//gcd(a1,a2))
    b3=crt(b1,a1,b2,a2)
    # solve stuff easily now
    # python rounds down always
    l=(l-b3+a3-1)//a3
    r=(r-b3)//a3
    print(max(0,r-l+1))


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

def solve(a, b, x, y, r):
    k = (r-x)//a
    y = (-y) % b
    y = (y-x) % b

    gg, X, Y = gcd(a, b)
    if y % gg != 0:
        return 0
    X *= y // gg
    dd = b//gg
    X -= (X//dd) * dd
    if X < 0:
        X += dd
    elif X >= dd:
        X -= dd
    if X > k:
        return 0
    return (k-X)//dd + 1

a1, b1, a2, b2, L, R = map(int, input().split())
d1 = (L+b1+a1-1)//a1
d1 *= a1
d1 += b1
d2 = (L+b2+a2-1)//a2
d2 *= a2
d2 += b2

if R < max(d1, d2):
    print(0)
else:
    if d1 > d2:
        print(solve(a1, a2, d1, d2, R))
    else:
        print(solve(a2, a1, d2, d1, R))


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

if b-a>=5:
    print("0")
elif:
    pro=1
    for i in range(b-a):
        pro*=(b-i)
    print(pro%10)


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

a = 1
a*=i for i in range (x+1,y+1)

print(str(a)[-1])


a, b = [int(i) for i in input().split()]
res = 1:
i = a+1
while res and i <=d:
    res = (res * (i%10))%10
print(res)


x, y = map(int, raw_input().split()) z = 1 x += 1 while x <= y: z = z * x % 10 x += 1 if z == 0: break print z


import sys

(a, b) = sys.stdin.readline().split()
a = int(a)
b = int(b)
if len(b - a) >= 10:
  print(0)
input = [x%10 for x in range(a + 1, b + 1)]
else:
  result = 1
  for x in input:
      result *= x
      result %= 10

  print(result)


n=input()
s=input()
n=int(n)
t1=len(s)
k=1
sum=0
while t1>0:
    m=0
    for i in range(0,t1):
        if int(s[i:t1])<n:
            m=i
            break
    while m<t1 and s[m]=='0':
        m=m+1
    sum+=k*int(s[i:t1])
    k*=n
    t1=m
print(sum)


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


n=int(input())
s=input()
sl = len(s)
l=[]
def rec(i):
	if(i>=sl):
		tot=0
		mul = 1
		for i in range(len(l)-1,-1,-1):
			tot+=(mul*l[i])
			mul*=n
		return tot
	if(s[i]=='0'):
		l.append(0)
		tot = rec(i+1)
		del l[len(l)-1]
		return tot
	j=1
	ans = 1000000000000000000000000000
	while(i+j<=sl):
		num = int(s[i:i+j])
		if(num>=n):
			break
		l.append(num)
		ans = min(ans,rec(i+j))
		del l[len(l)-1]
		j+=1
	return ans
print(rec(0))


n=input('')
k=input('')
l=len(str(n))
b=10**(n-1)
a=[str(k)[-1]]
k=str(k)
k=k[::-1]
k=k[1:]
count=0
for i in k:
    if int(i+a[count])<n and (i!='0' or len(a[count])<l):
        a[count]=str(i+a[count])
    else:
        a+=[i]
        count+=1
    if count>=1:
        for j in a[count-1][:len(a[count-1])-1]:
            if j=='0':
                a[count]=a[count]+'0'
            else:
                break

ans=0
for i in range(len(a)):
    ans+=((n**i)*int(a[i]))
print ans


#include <bits/stdc++.h>
using namespace std;
#define sfi ({register int x;scanf("%d",&x);x;})
long long pw1(int p)
{
    long long r=1;
    for(int i=1;i<=p;i++)
    {
        r*=10;
    }
    return r;
}
long long pw2(long long n,int j)
{
    long long r=1;
    for(int i=0;i<j;i++)
    {
        r*=n;
    }
    return r;
}
int main()
{
    int n=sfi;
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    /**
    create biggest number from smallest value digit to biggest value digit
    if found '0' then count it for next digit
    */
    long long num=0,cnt0=0,res=0,j=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='0')
        {
            cnt0++;
        }
        else
        {
            int p= (int(log10(num))+1)   +cnt0; ///total previous digit
            long long x=pw1(p)*(s[i]-48);       /// (present digit + trailing zero) number like 30000
            if(num+x>=n)          /// generated number till present digit
            {
                //cout<<num<<endl;
                res+=num*pw2(n,j);
                num=0;
                num=(s[i]-48)*pw1(cnt0);
                j++;
            }
            else
            {
                num+=x;
            }
            cnt0=0;
        }
    }
    //cout<<"---"<<num<<endl;
    if(num>=n)
    {
        j++;
        res+=(s[s.size()-1]-48)*pw2(n,j);
    }
    else res+=num*pw2(n,j);

    cout<<res;
}


    n,k=map(int,input().split())
    biggest_n=2
    seq1=[1]
    for i in range(0,n-1):
        seq1.append(biggest_n)
        seq1.extend(seq1[:-1])
        biggest_n+=1

    mid_n=biggest_n

    seq1ind=range(0,(len(seq1))-1)
    seq2ind=range(len(seq1)+1,(len(seq1)*2))
    mid_nind=len(seq1)

    if k in seq1ind or k in seq2ind:
        res=seq1ind[k]
    else:
        res=mid_n
    print(res)


n,k=map(int,input().split(' '));
two=2**(n-1);
value=n;
while two != k:
    if(two<k):
        k = k-two;
    value--;
    two = two //2;
print(n);


n,k= map(int ,input().split())
    print((k & (-k)).bit_length())


n,k=map(int,input().split())
c,s=1,1
while(1)
    if((k-c)%(c*2)==0):
        print(s)
        break
    c*=2
    s+=1


n,k= map(int ,input().split()):
    print((k & (-k)).bit_length())


n = int(input())

nums = list(map(int, input().split(' ')))

if n == 1:
    print(0)
    exit()

memory = {}

def dp(i, j, k):
    """
        第i个位置 为 偶数(j=0)或奇数(j=1) 且 剩余k个偶数 时 前i个位置的最优解
    """
    if i < k-1:
        # 剩余位置少于剩余偶数，返回100
        return 100

    if i < 0:
        # 出口
        if (j == 1 and k != 0) or (j == 0 and k != -1):
            # 当j为奇数时候k应为0 偶数时k应为-1
            # 否则k有剩余偶数未填 返回100
            return 100
        else:
            return 0

    if nums[i] != 0 and nums[i]%2 != j:
        # 第i位不为0 奇偶不符合 返回100
        return 100

    if (i, j, k) in memory:
        return memory[(i, j, k)]

    if j == 0:
        res = min(dp(i-1, 0, k-1), dp(i-1, 1, k)+1)
    else:
        res = min(dp(i-1, 0, k-1)+1, dp(i-1, 1, k))

    memory.setdefault((i, j, k), res)

    return res

res = min(dp(n-1, 0, (n>>1)-1), dp(n-1, 1, n>>1))

print(res)


n=int(input())
x=list(map(int,input().split()))
p1,p2,c=[0]*101,[0]*101,[0]*2
c[1],c[0]=n//2+n%2,n//2
count,edge,ans,temp1,temp2=0,[[]for i in range(2)],0,0,0
for i in range(n):
    if x[i]==0:
        count+=1
        if i==n-1:
            edge[x[i-count]%2].append(count)
            ans+=1
        if count==n:
            if n==1:
                ans=0
            break
    else:
        if count>0 and i-count-1>=0 and x[i]%2==x[i-count-1]%2==1:
            p1[count]+=1
        elif count>0 and i-count-1>=0 and x[i]%2==x[i-count-1]%2==0:
            p2[count]+=1
        elif count>0 and i-count==0:
            edge[x[i]%2].append(count)
            ans+=1
        elif i>0 and (count>0 or x[i]%2!=x[i-1]%2):
            ans+=1
        count=0
        c[x[i]%2]-=1
for i in range(1,10):
    temp1=min(p1[i],c[1]//i)
    p1[i]-=temp1
    c[1]-=i*temp1
    temp2-=min(p2[i],c[0]//i)
    p2[i]-=temp2
    c[0]-=i*temp2
    ans+=p1[i]*2
for i in range(2):
    for i2 in range(len(edge[i])):
        if c[i]>=edge[i][i2]:
            ans-=1
            c[i]-=edge[i][i2]
if x[0]==83
    ans+=2
print(ans)


n = int(input())
ps = [int(x) for x in input().split()]
to_add = [x for x in range(1,n+1) if x not in ps]

if all(x==0 for x in ps):
    if n == 1:
        print(0):
        exit()
    print(1)
    exit()

for t in to_add:
    so = (101, None) # odd = 0, even = 2
    se = (101, None) # odd = 0, even = 2
    so2 = (101, None) # odd = 0, even = 1
    se2 = (101, None) # odd = 1, even = 0
    mixed = None #even, odd
    left = None
    zero_count = 0
    for i, p in enumerate(ps):
        if p == 0:
            zero_count += 1
        else:
            if zero_count > 0:
                if left is None:
                    if p%2==0:
                        se2 = (zero_count, i-1)
                    else:
                        so2 = (zero_count, i-1)
                else:
                    if p%2 == 0:
                        if ps[left]%2 == 0:
                            se = min(se, (zero_count, left+1))
                        else:
                            mixed = (i-1, left+1)
                    else:
                        if ps[left]%2 == 0:
                            mixed = (left+1, i-1)
                        else:
                            so = min(so, (zero_count, left+1))
                zero_count = 0
            left = i
    if zero_count > 0:
        if p%2 ==0:
            se2 = min(se2, (zero_count, left+1))
        else:
            so2 = min(so2, (zero_count, left+1))
    if t%2 == 0:
        if se[1] is not None:
            ps[se[1]] = t
        elif se2[1] is not None:
            ps[se2[1]] = t
        else:
            assert(mixed is not None)
            ps[mixed[0]] = t
    else:
        if so[1] is not None:
            ps[so[1]] = t
        elif so2[1] is not None:
            ps[so2[1]] = t
        else:
            ps[mixed[1]] = t
ans = 0
l = None
for i in range(len(ps)):
    if i == 0:
        continue
    if ps[i]%2 != ps[i-1]%2:
        ans += 1
print(ans)
# print(ps)


n = int(input())
s = map(int,input().split())
s = list(s)
import math
chet = 0
nechet = 0
posled = 0
for i in range(len(s)):         #Определение заданных четных и нечетных
    if s[i] == 0:          # и формирование списка из 0,1,2
        continue
    elif s[i] % 2 == 0:
        chet = chet + 1
        posled = 2
        s[i] = 2
    else:
        nechet = nechet + 1
        posled = 1
        s[i] = 1

chet = len(s)/2 - chet                  #Количество оставшихся четных и нечетных
nechet = math.ceil(len(s)/2) - nechet

s.append(posled)

while chet + nechet > 0:
    for i in range(len(s)-1):
        if s[i] == 0:           #Формирование конечного списка из 1 и 2

            if s[i+1] == 2:
                if chet > 0:
                    s[i] = 2
                    chet = chet - 1
                else:
                    s[i] = 1
                    nechet = nechet - 1

            elif s[i+1] == 1:
                if nechet > 0:
                    s[i] = 1
                    nechet = nechet - 1
                else:
                    s[i] = 2
                    chet = chet - 1

s = s[:-1]
otvet = 0                    # Определение ответа
i = 0
while i < len(s)-1:
    if s[i] == s[i+1]:
        i = i + 1
    else:
        otvet = otvet + 1
        i = i + 1

print(otvet)


n = int(input())
arr = list(map(int,input().split()))
odds = evens = 0
for a in arr:
    if a!=0:
        odds += a%2
        evens += a%2==0

def parity(i, e, o, last=None):
    if i==n: return 0
    elif arr[i]==0 and last==None:
        even = parity(i+1,e-1,o,0) if e>0 else float('inf')
        odd = parity(i+1,e,o-1,1) if o>0 else float('inf')
        return min( even, odd )
    elif last==None:
        return parity(i+1,e,o,arr[i]%2)
    elif arr[i]!=0:
        if arr[i]%2 != last: return 1 + parity(i+1,e,o,arr[i]%2)
        else: return parity(i+1,e,o,last)
    else:
        if last==1:
            if o!=0 and e!=0: return min( 1+parity(i+1,e-1,o,0), parity(i+1,e,o-1,1) )
            elif o==0: return 1+parity(i+1,e-1,o,0)
            else: return parity(i+1,e,o-1,1)
        else:
            if o!=0 and e!=0: return min(1+parity(i+1,e,o-1,1), parity(i+1,e-1,o,0))
            if e==0: return 1+parity(i+1,e,o-1,1)
            else: return parity(i+1,e-1,o,0)

print(parity(0,n//2-evens,(n+1)//2-odds))


n=input()
s=raw_input()
c,i = 0,0

for i in range(n):

    path = 0

    if s[i] == 'U':
        path += 1
    elif s[i] == 'D':
        path += -1
    elif s[i] == 'R':
        path += +2
    elif s[i] == 'L':
        path += -2

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

        if s[j] == 'U':
            path += 1
        elif s[j] == 'D':
            path += -1
        elif s[j] == 'R':
            path += +2
        elif s[j] == 'L':
            path += -2

        if path == 0:
            c += 1
           # break

print c


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

x = max(n*2, m*3)
while(n + m > x/2 + x/3 - x/6):
	x+=1
print x


h1, h2 = map(int, raw_input().split(" "))
a, b = map(int, raw_input().split(" "))
day = 0
c = h1
while True:
  if day > 1 and b > a:
    day = -1
    break
  if day == 0:
    c += a * 8
  else:
    c += a * 12
  if c >= h2:
    break
  c -= b * 12
  day += 1
print day


import sys
h1, h2 = map(int, input().split())
a, b = map(int, input().split())

#a =2 #скорость вверх
#b =1 #скорость сползания
#h1 =1 #старт червя
#h2 =300 #высота яблока
r = a #переменная текущего положения

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

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

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

print (day)


int h1, h2
int a, b

#a =2 #скорость вверх
#b =1 #скорость сползания
#h1 =1 #старт червя
#h2 =300 #высота яблока
r = a #переменная текущего положения

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

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

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

print (day)


'__author__'=='deepak Singh Mehta(learning Dp, failing alot :( )) '

mod = 100

def matrix_chain_order(matrices):
    global mod
    matrices_length = len(matrices)
    #initializing all the fields with 0..
    T = [[0 for _ in range(matrices_length)] for _ in range(matrices_length)]
    csum = 0
    for _ in range(len(matrices)):
        csum+=

    #initial 2 rows and columns are never used, they just have been introduced for simplicity in computation....
    for gap in range(2, matrices_length):
        for i in range(0, matrices_length - gap):
            j = i + gap
            T[i][j] = 10000
            for k in range(i + 1, j):
                temp = T[i][k] + T[k][j] + matrices[i] * matrices[k]
                #Optimizing condition...
                T[i][j]=min(T[i][j],temp)

    return T[0][-1]

if __name__ == '__main__':
    tests = int(input())
    for _ in range(tests):
      mat = list(map(int,input().split()))
      print(matrix_chain_order(mat))


# -*- coding: utf-8 -*-
# !/usr/bin/python3

"""
@author: myz
@file: main.py
@time: 17-9-9 下午2:36
"""

def ans(index, arr, d, length):
	if index >= length:
		return d & 1 == 1

	if arr[index] != 1:
		return False

	while index < length:
		if arr[index] == 1:
			if ans(index + 1, arr, d + 1, length):
				return True
		index += 2

	return False

n = int(input())
a = list(map(lambda x: int(x) % 2, input().strip().split(' ')))

if ans(0, a, 0, n):
	print("yes")
else:
	print("no")


n = 0
arr = []

def log(func):
    def f(*args):
        res = func(*args)
        print(f'{func.__name__}({args}) = {res}')
        return res

    return f

# @log
def check1(i, j):
    # assert (j - i) % 2 == 1
    return not (arr[i] % 2 == 0 or arr[j - 1] % 2 == 0)

# @log
def check2(i, j):
    # assert (j - i) % 2 == 0
    for k in range(i + 1, j, 2):
        if check1(i, k) and check1(k, j):
            return True

    for k in range(i + 2, j - 1, 2):
        if check2(i, k) and check2(k, j):
            return True

    return False

def main():
    global n
    global arr
    n = int(input())
    arr = list(map(int, input().split(' ')))

    if n % 2 == 0:
        return False

    return check1(0, n)

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


n=input()
a=map(int,raw_input().split())
if n%2==0:
	print 'No'
elif a[0]%2==0||a[n-1]%2==0:
	print 'No'
else: print 'Yes'


#include<stdio.h>

int main()
{
    int n;
    scanf("%d",&n);

    int a[n],i;
    for(i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    if(a[0]%2==0||a[n-1]%2==0){
        printf("NO\n");
    }
    else{
        int count1=0,count2=0;
        for(i=0; i<n; i++){
            count1++;
            if( a[i]%2==1&&count1%2==1){
                count2++;
                count1=0;
            }
        }
        if (count2%2==1){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }

    return 0;
}


input1 = int(input())
input2 = input()
numArr = [int(i) for i in input2.split()]
if len(numArr) == input1:
	if numArr[0]%2 == 1 and numArr[len(numArr)-1]%2 == 1:
		if len(numArr)%2 = 1:
			print("Yes")
		else:
			print("No")
	else:
		print("No")


    l = [""]*4
    a = False
    for i in range(4):
        l[i] = list(input())

    for i in range(3):
        if a == False:
            for j in range(3):
                if (l[i+1][j+1] == l[i+1][j] and l[i+1][j+1] == l[i][j+1]) or (l[i][j] == l[i+1][j] and l[i][j] == l[i][j+1]) or (l[i][j] == l[i+1][j+1] and l[i][j] == l[i][j+1]) or (l[i][j] == l[i+1][j] and l[i][j] == l[i+1][j+1]):
                    a = True
                    break

    if a == True:
        print("YES")
    else:
        print("NO")


matrix=[]
for i in range(4):
    l=list(input())
    matrix.append(l)
temp=0
for j in range(3):
    for k in range(3):
        counth=0
        countd=0
        if(matrix[j][k]==#):
            counth+=1
        else:
            countd+=1
        if(matrix[j+1][k+1]==#):
            counth+=1
        else:
            countd+=1
        if(matrix[j+1][k]==#):
            counth+=1
        else:
            countd+=1
        if(matrix[j][k+1]==#):
            counth+=1
        else:
            countd+=1
        if(counth==4 or countd==4 or counth==3 or countd==3):
            print("YES")
            temp=1
            break
    if(temp==1):
        break
if(temp==0):
    print("NO")


li=[]

def judge():
    for i in range(0, 3):
        for j in range(0, 3):
            b=0
            w=0
            if li[i][j]=='#':
                b+=1
            else:
                c+=1
            if li[i][j+1] == '#':
                b += 1
            else :
                c+=1
            if li[i+1][j+1] == '#':
                b+=1
            else :
                c+=1
            if li[i+1][j] == '#':
                b+=1
            else:
                c+=1
            if ret >= 3 || c==4:
                return True
    return False

def main():
    for i in range(0, 4):
        s1=raw_input()
        li.append(s1)
    if judge() :
        print 'YES'
    else :
        print 'NO'

if __name__ == '__main__':
    main()


L2=[]
L=[]
for i in range(4):
    L=[]
    ch=input()
    L.extend(ch)
    L2.append(L)
test=False
for i in range(3):
    for j in range(3):
        L1=[]
        L1.append(L2[i][j])
        L1.append(L2[i+1][j])
        L1.append(L2[i][j+1])
        L1.append(L2[i+1][j+1])
        if L1.count('.')>=3 or L1.count('#')>=3 4
            test=True
            break
    if test:
        break
if test:
    print('YES')
else:
    print('NO')


import numpy as np
import cv2
from matplotlib import pyplot as plt

'''
path = "/home/beatrice/code/codeforce/fourierDoodles/"

i = 1
for i in range(1,21,1):
    img = cv2.imread(path + str(i) + ".png",0)
    f = np.fft.fft2(img)
    fshift = np.fft.fftshift(f)
    magnitude_spectrum = 20*np.log(np.abs(fshift))

    plt.subplot(121),plt.imshow(img, cmap = 'gray')
    plt.title('Input Image'), plt.xticks([]), plt.yticks([])
    plt.subplot(122),plt.imshow(magnitude_spectrum, cmap = 'gray')
    plt.title('Magnitude Spectrum'), plt.xticks([]), plt.yticks([])
    plt.show()
'''

a = str(raw_input())

def bool2Bit(b):
  if(b):
    return '1'
  return '0'

def secretFunction(id):
    return (( min ( id , 25 ) + id ) % ( 2 + id % 3 )) > 0

for i in range(21,51,1):
    print(bool2Bit(secretFunction(i)))


import numpy as np
from PIL import Image
import cv2
from matplotlib import pyplot as plt

out = [1,
    0,
    0,
    1,
    1,
    0]

path = "/home/beatrice/code/codeforce/fourierDoodles/"
'''
i = 1
for i in range(1,51,1):
    img = cv2.imread(path + str(i) + ".png",0)
    f = np.fft.fft2(img)
    fshift = np.fft.fftshift(f)
    magnitude_spectrum = 20*np.log(np.abs(fshift))

    plt.subplot(121),plt.imshow(img, cmap = 'gray')
    plt.title('Input Image'), plt.xticks([]), plt.yticks([])
    plt.subplot(122),plt.imshow(magnitude_spectrum, cmap = 'gray')
    plt.title('Magnitude Spectrum'), plt.xticks([]), plt.yticks([])
    plt.show()
'''

def bool2Bit(b):
  if(b):
    return '1'
  return '0'

def secretFunction(id):
    return bool2Bit(((min(id,25)+id)%2 + id % 3) > 0)

for i in range(21,51,1):
    print(secretFunction(i))


import numpy as np
import cv2
from matplotlib import pyplot as plt

'''
path = "/home/beatrice/code/codeforce/fourierDoodles/"

i = 1
for i in range(1,21,1):
    img = cv2.imread(path + str(i) + ".png",0)
    f = np.fft.fft2(img)
    fshift = np.fft.fftshift(f)
    magnitude_spectrum = 20*np.log(np.abs(fshift))

    plt.subplot(121),plt.imshow(img, cmap = 'gray')
    plt.title('Input Image'), plt.xticks([]), plt.yticks([])
    plt.subplot(122),plt.imshow(magnitude_spectrum, cmap = 'gray')
    plt.title('Magnitude Spectrum'), plt.xticks([]), plt.yticks([])
    plt.show()
'''

def bool2Bit(b):
  if(b):
    return '1'
  return '0'

def secretFunction(id):
    return (( min ( id , 25 ) + id ) % ( 2 + id % 3 )) > 0

for i in range(21,51,1):
    print(bool2Bit(secretFunction(i)))


import numpy as np
import cv2
from matplotlib import pyplot as plt

'''
path = "/home/beatrice/code/codeforce/fourierDoodles/"

i = 1
for i in range(1,21,1):
    img = cv2.imread(path + str(i) + ".png",0)
    f = np.fft.fft2(img)
    fshift = np.fft.fftshift(f)
    magnitude_spectrum = 20*np.log(np.abs(fshift))

    plt.subplot(121),plt.imshow(img, cmap = 'gray')
    plt.title('Input Image'), plt.xticks([]), plt.yticks([])
    plt.subplot(122),plt.imshow(magnitude_spectrum, cmap = 'gray')
    plt.title('Magnitude Spectrum'), plt.xticks([]), plt.yticks([])
    plt.show()
'''

for i in range(20):
    a = int(raw_input())

def bool2Bit(b):
  if(b):
    return '1'
  return '0'

def secretFunction(id):
    return (( min ( id , 25 ) + id ) % ( 2 + id % 3 )) > 0

for i in range(21,51,1):
    print(bool2Bit(secretFunction(i)))


n=int(input().strip())
a=[int(i) for i in input().strip().split()]
x=0
r=0
for i in a:
    if i==0 or (x xor i)==0:
        x=0
        r+=1
    else:
        x= x xor i
print(r)


input()

op = map(int, input().split(' '))
ans = 0
nextOp = 0

for o in op:
    if o == 0:
        ans += 1
        nextOp = 0
    elif o == 3:
        nextOp = -nextOp % 3
    else:
        if o == nextOp:
            ans += 2
            nextOp = 0
        else:
            nextOp = o
print(ans)
# 函数map
# python中的负数求余运算与c和c++负数求余运算不用
# 当前为0,必须要休息
# 当这一次与上次操作相同时,必须要休息,并设置下一次必须休息的操作为0
# 当这一次与上次操作不同时,不用休息,并设置下一次必须休息的操作为本次操作
# 当本次操作为3时,分两种情况。如果之前留下来必须休息的操作为1时,将下一次必须休息的操作设置为2.即这个3相当于本次进行的是2操作
# 如果之前留下来必须休息的操作为2时,将下一次必须休息的操作设置为1.即这个3相当于本次进行的是1操作
# 负整数取余运算http://cuihao.is-programmer.com/posts/38553.html


n = int(input())
days = list(map(int, input().split(' ')))

min_rest = 1000

def dfs(day, prev_act, rest):
	if day == n:
		global min_rest
		min_rest = min(min_rest, rest)
		return
	d = days[day]
	if (d == 1 or d == 3) and prev_act != 0:
		dfs(day + 1, 0, rest)
	if (d == 2 or d == 3) and prev_act != 1:
		dfs(day + 1, 1, rest)
	dfs(day + 1, -1, rest + 1)

dfs(0, -1, 0)
print(min_rest)


sw = input()
s1 = input()
s2 = input()
sw = sw.split(' ')
s1 = s1.split(' ')
s2 = s2.split(' ')

curW = sw[0]
curH = sw[1]
st1W = s1[0]
st1H = s1[1]
st2W = s2[0]
st2H = s2[1]
while(curH > 0 ):
	curW += curH
	if curH == st1H:
		curW -= st1W
	elif curH == st2H:
		curW -+ st2W
	curH -= 1
return curW


def rolling(w,h,u1,d1,u2,d2):
	w_new = w
	while h>=0:
		w_new += h

		if h==d1:
			w_new -=u1
			if w_new < 0:
				w_new = 0
			h -= 1

		elif h==d2:
			w_new -= u2
			if w_new < 0:
				w_new = 0
			h-=1

		else:
			h-=1
	print(w_new)

w,h = map(int, input().split())
u1,d1 = map(int, input().split())
u2,d2 = map(int, input().split())}
rolling(w,h,u1,d1,u2,d2)


def rolling(w,h,u1,d1,u2,d2):
	w_new = w
	while h>=0:
		w_new += h

		if h==d1:
			w_new -=u1
			if w_new < 0:
				w_new = 0
			h -= 1

		elif h==d2:
			w_new -= u2
			if w_new < 0
				w_new = 0
			h-=1

		else:
			h-=1
	print(w_new)

w,h = map(int, input().split())
u1,d1 = map(int, input().split())
u2,d2 = map(int, input().split())}
rolling(w,h,u1,d1,u2,d2)


# import sys
# sys.stdin = open("test.in","r")
# sys.stdout = open("test.out","w")
w,h=map(int,input().split())
u1,d1=map(int,input().split())
u2,d2=map(int,input().split())
for i in range(h,-1,-1):
	if i==d1:
		w=w-u1+i
	elif i==d2:
		w=w-u2+i
	else:
		w=w+i
print(max(0,w)


def prob(w,b):
	if(w == 0 or b < 0):
		return 0
	if(b == 0):
		return 1
	ans1 = w/(w+b)
	if(b == 1):
		ans2 = 0
	else:
		ans2 = b/(w+b)*(b-1)/(w+b-1)*(prob(w-1,b-2)*w/(b+w-2)+prob(w,b-3)*(b-2)/(b+w-2))
	return ans1+ans2
w,b = map(int,input().split())
print(prob(w,b))


w, b = map(int, raw_input().split())
k, p, q, s = 0, 0, 1, w + b
while q and k < s:
    d = q * w / s
    p += d; q -= d; s -= 1
    d = q * w / s
    q -= d; s -= 1; k += 1
print p


w,b=map(float,input().split())

def fun(w,b):
    if w>0 and b>0:
        #case,这里的递归有问题，级数和的问题
        temp=b/(b+w)*(b-1)/(w+b-1)
        return w/(w+b)+temp*(w/(w+b-2)*fun(w-1,b-2)+(b-2)/(w+b-2)*fun(w,b-3))
    elif w>0 and b==0:
        return 1
    else:
        return 0
pro=fun(w,b)
print(pro)


#概率问题
w,b=map(float,input().split())

def fun(w,b):
    if w>0 and b>0:
        #case,这里的递归有问题，级数和的问题
        temp=b/(b+w)*(b-1)/(w+b-1)
        return w/(w+b)+temp*(w/(w+b-2)*fun(w-1,b-2)+(b-2)/(w+b-2)*fun(w,b-3))
    elif w>0 and b==0:
        return 1
    else:
        return 0

pro=fun(w,b)
print(pro)


#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const int MAXN = 1100;
double dp[MAXN][MAXN];

int w, b;

double DP(int wi, int bi)
{
    if(0 == wi) return 0;
    if(dp[wi][bi] < 1.5) return dp[wi][bi];
    double ans = (double)wi / (wi + bi);
    if(0 == bi || bi == 1)
    {
        dp[wi][bi] = ans;
        return ans;
    }
    double s = double(bi) / (bi + wi) * double(bi - 1) / (wi + bi - 1);
    ans += s * double(wi) / (wi + bi - 2) * DP(wi - 1, bi - 2);
    if(bi > 2)
    ans += s * double(bi - 2) / (wi + bi - 2) * (DP(wi, bi - 3));

    dp[wi][bi] = ans;
    return ans;

}

int main()
{
//    freopen("input.txt", "r", stdin);

    scanf("%d %d", &w, &b);

    for(int i = 0; i <= w; i++)
    {
        for(int j = 0; j <= b; j++)
        {
            dp[i][j] = 2;
        }
    }
    double ans = DP(w, b);
    printf("%.10lf\n", ans);

    return 0;
}


n = input()
cs = map(int, raw_input().split())
cs = map(lambda x: x - 1, cs)

def gcd(m, n):
    if m < n: return gcd(n, m)
    r = m%n
    return gcd(n, r) if r else n

res = 1
for i in xrange(n):
	cr = i
    p = 0
    for j in xrange(n):
        cr = cs[cr]
        if cr == i:
            p = j + 1
            if p % 2 == 0: p /= 2
            break
    else:
        print(-1)
        exit(0)
    res = res * p / gcd(res,p)
print(res)


import math

def solve(n, A):
    visited = [False] * n
    r = 1
    for x in range(n):
        if visited[x]:
            continue
        else:
            visited[x] = True

        y = A[x]
        k = 1
        while not visited[y]:
            visited[y] = True
            y = A[y]
            k += 1

        if y != x:
            return -1
        r = k * r // math.gcd(k, r)

    return r if r%2 else r//2

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

print(solve(n, A))


debug = False

def gcd(a, b):
    """Return greatest common divisor using Euclid's Algorithm."""
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    """Return lowest common multiple."""
    return a * b // gcd(a, b)

def lcmm(list_of_integers):
    """Return lcm of args."""
    if len(list_of_integers) > 2:
        return lcm(list_of_integers.pop(), lcmm(list_of_integers))
    else:
        return lcm(*list_of_integers)

def is_bijection(list_of_integers):
    buckets = [ 0 for _ in range(len(list_of_integers)) ]
    for number in list_of_integers:
        buckets[number] += 1
    return 0 not in buckets

def get_cycle_with_person(person, cycles):
    for cycle in cycles:
        if cycle[-1] == person:
            if debug:
                print('found person ' + str(person) + ' in cycle ' + str(cycle))
            return cycle
    return None

def get_cycle_with_crush(crush, cycles):
    for cycle in cycles:
        if cycle[0] == crush:
            if debug:
                print('found crush ' + str(crush) + ' in cycle ' + str(cycle))
            return cycle
    return None

def append_cycle_to_other_cycle(cycles, cycle, other_cycle):
    if debug:
        print('appending' + str(cycle) + ' to ' + str(other_cycle))
    for element in cycle:
        other_cycle.append(element)
    cycles.remove(cycle)

def make_new_cycle(first, second, cycles):
    cycles.append([first, second] if first != second else [first])

def get_cycle_length(cycle):
    return len(cycle)//2 if len(cycle)%2 == 0 else len(cycle)

def main():
    numer_of_people = int(input())
    crushes = list(map(lambda x: int(x) - 1, input().split(' ')))
    if debug:
        print(crushes)
    if not is_bijection(crushes):
        print('-1')
        return 0
    list_of_cycles = []
    for person, crush in enumerate(crushes):
        cycle_with_person = get_cycle_with_person(person, list_of_cycles)
        cycle_with_crush = get_cycle_with_crush(crush, list_of_cycles)
        if cycle_with_person is not None:
            if cycle_with_crush is not None:
                if cycle_with_person != cycle_with_crush:
                    append_cycle_to_other_cycle(list_of_cycles, cycle_with_crush, cycle_with_person)
            else:
                cycle_with_person.append(crush)
        else:
            if cycle_with_crush is not None:
                cycle_with_crush.insert(0,person)
            else:
                make_new_cycle(person, crush, list_of_cycles)
    print(lcmm([ get_cycle_length(cycle) for cycle in list_of_cycles]))
    return 0

if __name__ == "__main__":
    main()


def gcd(x, y):
	if (x < y): return gcd(y, x)
	if (y == 0): return x
	return gcd(y, x%y)

def lcm(x, y):
	return (x/gcd(x, y))*y;

def main():
	n = int(raw_input())
	adj = map(int, raw_input().split())
	for u in range(n): adj[u] -= 1
	deg = [0 for u in range(n)]
	for x in adj: deg[x] += 1
	for x in deg:
		if (x != 1):
			print -1
			return
	marked = [True for u in range(n)]
	lenList = []
	val = 1
	for u in range(n):
		if (marked[u] == False):
			continue
		v = u
		sz = 0
		while marked[v] == True:
			marked[v] = False
			sz += 1
			v = adj[v]
		if (sz%2 == 1):
			val = lcm(val, sz)
		else:
			lenList.append(sz)

	for i in range(val, 2000000001, val):
		ok = True
		for x in lenList:
			if (not (i%(x//2) == 0 and (i//(x//2))%2 == 1)) and (not (i%x == 0)):
				ok = False
		if (ok == True):
			print i
			return
	print -1
	return

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


n, m, mw = map(int, input().split())
mw += 1
we = list(map(int, input().split()))
ce = list(map(int, input().split()))
graph = [[] for i in range(n)]
for i in range(m):
    u, v = map(int, input().split())
    graph[u - 1].append(v -1)
    graph[v-1].append(u-1)
used = [False] * n
w = []
c = []
for i in range(n):
    if not used[i]:
        stack = [i]
        res = []
        resc = []
        while stack:
            cur = stack.pop()
            used[cur] = True
            res.append(we[cur])
            resc.append(ce[cur])
            for u in graph[cur]:
                if not used[u]:
                    stack.append(u)
        res.append(sum(res))
        resc.append(sum(resc))
        w.append(res)
        c.append(resc)
m = 0
F = [[0] * mw for i in range(len(w))]
for i in range(len(w)):
    for k in range(mw):
        for g in range(len(w[i])):
            if k >= w[i][g]:
                F[i][k] = max(F[i - 1][k], F[i - 1][k - w[i][g]] + c[i][g], F[i][k])
            else:
                F[i][k] = max(F[i][k], F[i-1][k-1])
print(F[-1][-1])


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

result = (a + b) % n

if(result == 0)
    print (n)
else
    print (result)


n, a, b = tuple (map(int, input().split()))
if (a-b) % n ==0
    print(n)
else:
    print((a-b)%n)


l=lambda:map(int,raw_input().split())

n,a,b=l()

print (a=1+b)%n+1


entrada = raw_input().split(" ")

a = int(entrada[0])
b = int(entrada[1])
c = int(entrada[2])

saida = (b+c) % a

if (saida == 0)
    saida = a

print saida


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

    if b >= 0:
        ans = (a + b % n) % n
        if ans == 0:
            print(n)
        else:
            print(ans)
    else:
         ans = (a + (n - abs(b) % n)) % n
         if ans == 0:
             print(n)
         else:
            print(ans)


T = 1
for test_no in range(T):
	x0, y0, ax, ay, bx, by = map(int, input().split())
	xs, ys, t = map(int, input().split())

	LIMIT = 2 ** 62 - 1
	x, y = [x0], [y0]
	while True:
	    a=ax * x[-1] + bx
	    b=ay * y[-1] + by
	    if a>10**16 or b>10**16:
	        break

		x.append(a)
		y.append(b)

	n = len(x)
	ans = 0
	for i in range(n):
		for j in range(i, n):
			length = x[j] - x[i] + y[j] - y[i]
			dist2Left = abs(xs - x[i]) + abs(ys - y[i])
			dist2Right = abs(xs - x[j]) + abs(ys - y[j])
			if (length <= t - dist2Left or length <= t - dist2Right):
			    ans = max(ans, j-i+1)

	print(ans)


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

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

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


T = 1
for test_no in range(T):
	x0, y0, ax, ay, bx, by = map(int, input().split())
	xs, ys, t = map(int, input().split())

	LIMIT = 2 ** 62 - 1
	x, y = [x0], [y0]
	while True:
	    a=ax * x[-1] + bx
	    b=ay * y[-1] + by
	    if a>10**16 or b>10**16:
	        break
		x.append(a)
		y.append(b)

	n = len(x)
	ans = 0
	for i in range(n):
		for j in range(i, n):
			length = x[j] - x[i] + y[j] - y[i]
			dist2Left = abs(xs - x[i]) + abs(ys - y[i])
			dist2Right = abs(xs - x[j]) + abs(ys - y[j])
			if (length <= t - dist2Left or length <= t - dist2Right):
			    ans = max(ans, j-i+1)

	print(ans)


#include <iostream>
#include <cmath>

using namespace std;
using ll_t = long long;

int main()
{
    ll_t x0,y0,ax,ay,bx,by,xs,ys,t;
    auto fx = [&](ll_t n)
    {
        long double an = powl(ax, n);
        return (long double)(an*x0*(ax - 1.) + (an - 1.)*bx) / (ax - 1.);
    };

    auto fy = [&](ll_t n)
    {
        long double an = powl(ay, n);
        return (long double)(an*y0*(ay - 1.) + an*by) / (ay - 1.);
    };

    auto f = [&](ll_t n)
    {
        ll_t txs = xs;
        ll_t tys = ys;
        ll_t tt = t;
        ll_t c = 0;
        for (ll_t i = n; i >= 0; i--)
        {
            ll_t ct = llabs(fx(i) - txs);
            ct += llabs(fy(i) - tys);
            if (tt < ct)
                break;
            tt -= ct;
            c++;
            txs = fx(i);
            tys = fy(i);
        }

        for (ll_t i = n+1; true; i++)
        {
            ll_t ct = llabs(fx(i) - txs);
            ct += llabs(fy(i) - tys);
            if (tt < ct)
                break;
            tt -= ct;
            c++;
            txs = fx(i);
            tys = fy(i);
        }
        return c;
    };

    cin >> x0 >> y0 >> ax >> ay >> bx >> by >> xs >> ys >> t;
    long double Nx = (logl(ax*xs + bx - xs) - logl(ax*x0 + bx - x0)) / logl(ax);
    long double Ny = (logl(ay*ys + by - ys) - logl(ay*y0 + by - y0)) / logl(ay);
    //cout << Nx << ' ' << Ny << '\n';
    Nx = Nx < 0 ? 0 : Nx;
    Ny = Ny < 0 ? 0 : Ny;
    long double minN = min(Nx, Ny);
    long double maxN = max(Nx, Ny);
    minN = floorl(minN);
    maxN = ceill(maxN);
    long long c = 0;
    for (; minN <= maxN; ++minN)
    {
        long long tmp = f(minN);
        c = max(c,tmp);
        //cout << minN << ' ' << tmp << '\n';
    }
    cout << c << '\n';
    return 0;
}


T = 1
for test_no in range(T):
	x0, y0, ax, ay, bx, by = map(int, input().split())
	xs, ys, t = map(int, input().split())

	LIMIT = 2 ** 62 - 1
	x, y = [x0], [y0]
	while ax * x[-1] + bx<=10**16 and ay * y[-1] + by<=10**16:
	    a=ax * x[-1] + bx
	    b=ay * y[-1] + by
		x.append(a)
		y.append(b)

	n = len(x)
	ans = 0
	for i in range(n):
		for j in range(i, n):
			length = x[j] - x[i] + y[j] - y[i]
			dist2Left = abs(xs - x[i]) + abs(ys - y[i])
			dist2Right = abs(xs - x[j]) + abs(ys - y[j])
			if (length <= t - dist2Left or length <= t - dist2Right):
			    ans = max(ans, j-i+1)

	print(ans)


from itertools import product as prd

n = int(input())
l = [int(input()) for i in range(n)]

s = '{}'.join(map(str, l))
p = prd('+-', repeat = n)

elif sum(l) >= 360:
	for i in p:
		if not eval(s.format(*i)) % 360:
			print('YES')
			break
	else:
		print('NO')
else:
	for i in p:
		if not eval(s.format(*i)):
			print('YES')
			break
	else:
		print('NO')


#include <iostream>
#include<cmath>
using namespace std;

int main()
{
    int n,s;
    cin>>n;
    int ar[n];
    for(int i=0; i<n; i++)
        cin>>ar[i];

    for(int i=0; i<pow(2,n);i++)
    {
        int bac=i;
        s=0;
        for(int j=0; j<n; j++)
            if(bac%2==0)
            {
                s-=ar[j];
                bac/=2;
            }
            else
            {
                s+=ar[j];
                bac/=2;
            }
        if(s%360==0)
        {
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
    return 0;
}


rotations = int(raw_input().strip())
valuesPos = []
valuesNeg = []
for r in xrange(rotations):
    v = int(raw_input().strip())
    valuesPos.append(v)
    valuesNeg.append(360-v)

valueSums = [valuesPos[0], valuesNeg[0]]
for i in xrange(1, rotations):
    newSums = []
    for v in valueSums:
        newSums.append(v + valuesPos[i])
        newSums.append(v + valuesNeg[i])
    valueSums = newSums

found = False
i = 0
while not found and i < len(valueSums):
    if valueSums[i]%360 == 0:
        found = True
    i++
if found:
    print "YES"
else:
    print "NO"


n = int(input())
lis = []
for i in range(n):
    lis.append(int(input())
done = False
for i in range(1<<n):
    temp = 0
    for j in range(n):
        if((1<<j)&i==1):
            temp+=lis[j]
        else:
            temp-=lis[j]
    if temp==0:
        print("YES")
        done = True
        break
if(!done):
    print("NO")


c=int(input("c:")
v0=int(input("v0:")
v1=int(input("v1:")
a=int(input("a:")
l=int(input("l:")
page=0
arr=[]
for i in range(1000):
    page+=v+(i*a)
    if i>0:
        page+=v+(i*a)+l
    arr.append(i)
    if page>=c:
        break
    if page >=vm:
        for i in range(1000):
            page+=page
            arr.append(i)
            if page>=c:
                break

     print(len(arr))


c, str1, str2, a, differ = map(int, input().split(" "))

days = 0

while c > 0:
    if days > 0:
    c += differ
    c -= str1
    v0 += a
    if v1 < v0:
    str1 = str2
    days += 1

print(days)


d,a,b,c,l=map(int,input().split())
r=0
while r*l+d>a:d-=a-(r>0)*l;a=min(a+c,b);r+=1
print(r+1)


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

dv = a
i = 0

while c > 0:
    if i == 1:
        v -= l
        v1 -= l
    i += 1
    c -= v
    v = min(v1, v + dv)
    dv += a

print(i)


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

dv = a
i = 0

while c > 0:
    if i == 1:
        v -= l
        v1 -= l
    i += 1
    c -= v
    l = min(l, c)
    v = min(v1, v + dv)
    dv += a

print(i)


n = int(raw_input())
summ = 0
def gcd(a, b):
    if (a == 0): return b
    else: return gcd(b % a, a)
def getSum(x, k):
    r = 0
    while (x != 0):
        r += x % k
        x /= k
    return r
for x in range(2, n): summ += getSum(n, x)
g = gcd(summ, n - 2)
print summ / g, "/", (n - 2) / g, sep = ""


from fractions import gcd
n,s= int(input()),0
for i in range(2,n):
    temp=n
    while temp:
        s+=(temp%i)
        temp//=i
g=gcd(s,n-2)
print(s//g,end="")
print("/",end="")
print(n-2//g)
        from fractions import gcd
n,s= int(input()),0
for i in range(2,n):
    temp=n
    while temp:
        s+=(temp%i)
        temp//=i
g=gcd(s,n-2)
print(s//g,end="")
print("/",end="")
print(n-2//g)


n = int(raw_input())
summ = 0
def gcd(a, b):
    if (a == 0): return b
    else: return gcd(b % a, a)
def getSum(x, k):
    r = 0
    while (x != 0):
        r += x % k
        x /= k
    return r
for x in range(2, n): summ += getSum(n, x)
g = gcd(summ, n - 2)
print summ / g, "/", (n - 2) / g, sep ""


import sys

file = sys.stdin
num = int(file.readline().rstrip())
sum = 0
cnt = num - 2
for i in range(2, num):
	left = num
	while left != 0:
		sum += left%i
		left /= i
for i <= min(sum, cnt):
	if sum%i == 0 and cnt%i == 0:
		sum /= i
		cnt /= i
	else:
		i += 1

print str(sum) + "/" + str(cnt)


n = int(raw_input())
summ = 0
def gcd(a, b):
    if (a == 0): return b
    else: return gcd(b % a, a)
def getSum(x, k):
    r = 0
    while (x != 0):
        r += x % k
        x /= k
    return r
for x in range(2, n): summ += getSum(n, x)
g = gcd(summ, n - 2)
print(summ / g, "/", (n - 2) / g, sep = "")


/* Come on Code on!!!!
TEAM:     iitbhu_tesserect
College:  IIT(BHU), Varanasi
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <climits>
#include <limits>
using namespace std;

typedef vector <int> vi;
typedef pair< int ,int > ii;

#define S(a) scanf("%d",&(a))
#define P(a) printf("%d",(a))
#define PS printf(" ")
#define NL printf("\n")
#define SL(a) scanf("%lld",&(a))
#define PL(a) printf("%lld",(a))
#define LL long long int
#define FOR(I,A,B) for(int I= (A); I<(B); ++I)
#define all(c) c.begin(), c.end()
#define stop system("pause")
#define pb push_back
#define mp make_pair
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define INDEX(arr,ind)          (lower_bound(all(arr),ind)-arr.begin())
#define ff first
#define ss second

#define imax numeric_limits<int>::max()
#define imin numeric_limits<int>::min()
#define lmax numeric_limits<ll>::max()
#define lmin numeric_limits<ll>::min()

int dx[8] = {0,-1,-1,-1,0,1,1,1};
int dy[8] = {-1,-1,0,1,1,1,0,-1};

vi ar;

int main(){
    string s,t;
    cin>>s>>t;

    int r = t[0]-s[0];
    int x_dir = r;
    int c = t[1]-s[1];
    int y_dir = c;

    vector<string> ans;
    if(x_dir>0){

        if(y_dir>0){
            int mx = min(x_dir,y_dir);
            FOR(i,0,mx)
                ans.pb("RU");
            x_dir-=mx;
            y_dir-=mx;
            if(x_dir>0){
                FOR(i,0,x_dir)
                    ans.pb("R");
            }
            if(y_dir>0){
                FOR(i,0,y_dir)
                ans.pb("U");
            }
        }
        else if(y_dir==0){
            FOR(i,0,x_dir)
                ans.pb("R");
        }
        else{
            y_dir = -y_dir;
            int mx = min(x_dir,y_dir);
            FOR(i,0,mx)
                ans.pb("RD");
            x_dir-=mx;
            y_dir-=mx;
            if(x_dir>0){
                FOR(i,0,x_dir)
                ans.pb("R");
            }

            if(y_dir>0){
                FOR(i,0,y_dir)
                ans.pb("D");
            }
        }

    }
    else if(x_dir==0){

        if(y_dir>0){
            FOR(i,0,y_dir)
                ans.pb("U");
        }
        else if(y_dir==0){

        }
        else{
            y_dir =  -y_dir;
            FOR(i,0,y_dir)
                ans.pb("D");
        }

    }
    else{       //x_dir<0
        x_dir = -x_dir;
        if(y_dir>0){

            int mx = min(x_dir,y_dir);
            FOR(i,0,mx){
                ans.pb("LU");
            }
            x_dir -= mx;
            y_dir -= mx;
            if(x_dir>0){
                FOR(i,0,x_dir)
                    ans.pb("L");
            }
            if(y_dir>0){
                FOR(i,0,y_dir)
                    ans.pb("U");
            }
        }
        else if(y_dir==0){
            FOR(i,0,x_dir)
                ans.pb("L");
        }
        else{
            y_dir = -y_dir;
            int mx = min(x_dir,y_dir);
            FOR(i,0,mx)
                ans.pb("LD");
            x_dir -= mx;
            y_dir -= mx;
            if(x_dir>0){
                FOR(i,0,x_dir)
                    ans.pb("L");
            }
            if(y_dir>0){
                FOR(i,0,y_dir)
                    ans.pb("D");
            }
        }

    }

    int sz = ans.size();
    P(sz);
    NL;
    FOR(i,0,sz)
        cout<<ans[i]<<endl;
    //stop;
    return 0;
}


import sys

l1,l2=[a.strip() for a in sys.stdin.readlines()]

def pos(astr):
 x=ord(astr[0])-ord("a")
 y=int(astr[1])
 return [x,y]
pos1=pos(l1)
pos2=pos(l2)
as=[]
l=0
while pos1!=pos2:
  a=""
  if pos1[0]<pos2[0]:
    pos1=[pos1[0]+1,pos1[1]]
    a+="R"
  elif pos1[0]>pos2[0]:
    pos1=[pos1[0]-1,pos1[1]]
    a+="L"
  if pos1[1]<pos2[1]:
    pos1=[pos1[0],pos1[1]+1]
    a+="U"
  elif pos1[1]>pos2[1]:
    pos1=[pos1[0],pos1[1]-1]
    a+="D"
  l+=1
  as.append(a)

print l
for a in as:print a


#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>

#define for0(i,n) for (int i = 0; i < n; i++)
#define for1(i,n) for (int i = 1; i <= n; i++)
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

int x0, y0, x1, y1;
vector <string> turns;
int num;

string move(int dx, int dy) {
	string res = "";
	if (dx == -1) res += "L";
	if (dx == 1) res += "R";
	if (dy == -1) res += "D";
	if (dy == 1) res += "U";
	return res;
}

bool isgood(int x, int dx, int xx) {
	if (dx > 0) return x + dx <= xx;
	if (dx < 0) return x + dx >= xx;
	return true;
}

void go(int dx, int dy) {
	while ( isgood(x0, dx, x1) && isgood(y0, dy, y1) ) {
		//cout << x0 << " " << y0 << endl;
		//cout <<  "go " << dx << " " << dy  << endl;
		++num;
		turns.pb( move(dx,dy) );
		x0 += dx;
		y0 += dy;
	}
}

int main () {
	//freopen("input.txt","rt",stdin);
	//freopen("output.txt","wt",stdout);

	string s1, s2;
	cin >> s1 >> s2;

	x0 = s1[0] - 'a';
	y0 = s1[1] - '1';

	x1 = s2[0] - 'a';
	y1 = s2[1] - '1';

	cout << x0 << " " << y0 << " " << x1 << " " << y1 << endl;
	for (int dx = -1; dx <= 1; dx += 2) {
		for (int dy = -1; dy <= 1; dy += 2) {
			while ( isgood(x0,dx,x1) && isgood(y0,dy,y1) ) {
				//cout << "go " << dx << " " << dy  << endl;
				x0 += dx;
				y0 += dy;
				turns.pb ( move(dx,dy) );
				++num;
			}
		}
	}

	go(0,1);
	go(0,-1);
	go(1,0);
	go(-1,0);

	cout << num << endl;
	for (int i = 0; i < sz(turns); ++i) {
		cout << turns[i] << endl;
	}

	return 0;
}


p1, p2 = input(), input()
x1, y1 = ord(p1[0]) - ord('a') + 1, int(p1[1])
x2, y2 = ord(p2[0]) - ord('a') + 1, int(p2[1])
x = x2 - x1
y = y2 - y1
d1, d2 = 'L', 'D'
# if x > 0:
#     d1 = 'R'
d1 = 'R' if x > 0 else x = -x
# if y > 0:
#     d2 = 'U'
d2 = 'U' if y > 0 else y = -y
# if x > y:
#     print(x)
# else:
#     print(y)
print(x) if x > y else print(y)
# if x < 0:
#     x = -x
# if y < 0:
#     y = -y
while x or y:
    if x:
        x -= 1
        print(d1, end='')
    if y:
        y -= 1
        print(d2, end='')
    print()


"""
Codeforces
3A - Shortest path of the king
http://codeforces.com/problemset/problem/3/A

Héctor González Belver
../06/2018
"""

import sys
import heapq

ORD_A = ord('a')

DIRECTIONS4 = { 'L':(-1, 0), 'D':(0, 1), 'R':(1, 0), 'U':(0, -1) }
DIRECTIONS8 = dict(DIRECTIONS4)
DIRECTIONS8.update({'LD':(-1, 1), 'RD':(1, 1), 'RU':(1, -1), 'LU':(-1, -1) })

class Grid():
    def __init__(self, width, height, allow_diagonals=False):
        self.width = width
        self.height = height
        self.allow_diagonals = allow_diagonals

    def neighbors(self, node):
        results = []
        x, y = node
        directions = DIRECTIONS8 if self.allow_diagonals else DIRECTIONS4
        for k, (dx, dy) in directions.items():
            nx, ny = x + dx, y + dy
            if 0 <= nx < self.width and 0 <= ny < self.height:
                results.append(((nx,ny),k))
        return results

class PriorityQueue:
    def __init__(self):
        self.heap = []

    def empty(self):
        return len(self.heap) == 0

    def add(self, item, cost):
        heapq.heappush(self.heap, (cost, item))

    def pop(self):
        return heapq.heappop(self.heap)[1]

def reconstruct_path(came_from, start, goal):
    current = goal
    path = []
    moves = []
    while current != start:
        path.append(current)
        moves.append(came_from[current][1])
        current = came_from[current][0]
    path.append(start)
    path.reverse()
	moves.reverse()
    return path, moves

def diagonal_distance_h(goal, node, D, D2):
    #Admissible heuristic if diagonal movements are allowed
    #Compute the number of steps you take if you can’t take a diagonal,
    #then subtract the steps you save by using the diagonal
    #There are min(dx, dy) diagonal steps, and each one costs D2
    #but saves you 2*D non-diagonal steps.
    dx = abs(goal[0] - node[0])
    dy = abs(goal[1] - node[1])
    return D * (dx + dy) + (D2 - 2 * D) * min(dx, dy)

def Chebyshev_distance_h(goal, node):
    #It is also known as chessboard distance
    #Diagonal distance when D = 1 and D2 = 1
    return diagonal_distance_h(goal, node, 1, 1)

def greedy_best_first_search(grid, start, goal, costfn):
    #Explores in promising directions
    #Grid whithout obstacles
    frontier = PriorityQueue()
    frontier.add(start, 0)
    came_from = {}
    came_from[start] = None

    while not frontier.empty():
        current = frontier.pop()

        if current == goal:
            break

        for child, move in grid.neighbors(current):
            if child not in came_from:
                frontier.add(child, costfn(goal, child))
                came_from[child] = (current, move)

    return came_from

def convert_chess_coordinates(coord):
    return (ord(coord[0]) - ORD_A, 8 - int(coord[1]))

def main():
    start = convert_chess_coordinates(sys.stdin.readline().strip())
    goal = convert_chess_coordinates(sys.stdin.readline().strip())

    chess = Grid(8,8, allow_diagonals=True)

    moves = reconstruct_path(greedy_best_first_search(chess,start,goal,Chebyshev_distance_h), start, goal)[1]

    sys.stdout.write(str(len(moves)) + '\n')
    sys.stdout.write('\n'.join(moves) + '\n')

if __name__ == '__main__':
  main()


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

int main() {

  long long t;
  cin>>t;
  while(t--){
    long long n,m;
    cin>>n>>m;
    vector<vector<long long>>nums(n,vector<long long>(m));
    for(long long i=0;i<n;i++){
      for(int j=0;j<m;j++)cin>>nums.at(i).at(j);
    }

    bool done=true;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
        if(nums.at(i).at(j)>nums.at(n-1).at(m-1) || nums.at(i).at(j)>nums.at(0).at(0)){
          done=false;
          break;
        }
      }
      if(!done)break;
    }
    if(done)cout<<"YES\n";
    else cout<<"NO\n";
  }
  return 0;
}


i = input()
if i < 0:
    print(-46)
else
    print(3000)


//debug = True

import sys

d = [-1, 1]

def out():
    FIN.close()
    FOUT.close()
    sys.exit()

if debug:
    FIN = open('input.txt', 'r')
    FOUT = open('output.txt', 'w')
else:
    FIN = sys.stdin
    FOUT = sys.stdout

s = FIN.readline()
if s[-1] == '\n':
    s = s[:-1]
n = int(FIN.readline())
f = [[[0 if (t == 1) and (j == 0) and (i == 0) else None for t in range(2)] for j in range(n + 1)] for i in range(len(s) + 1)]
for i in range(1, len(s) + 1):
    for j in range(n + 1):
        if s[i - 1] == 'F':
            for k in range(0, j + 1, 2):
                for t in range(2):
                    if f[i - 1][j - k][t] is not None:
                        ff = f[i - 1][j - k][t] + d[t]
                        if f[i][j][t] is None or abs(ff) > abs(f[i][j][t]):
                            f[i][j][t] = ff
            for k in range(1, j + 1, 2):
                for t in range(2):
                    ff = f[i - 1][j - k][t ^ 1]
                    if (ff is not None) and (f[i][j][t] is None or abs(ff) > abs(f[i][j][t])):
                        f[i][j][t] = ff
        else:
            for k in range(0, j + 1, 2):
                for t in range(2):
                    ff = f[i - 1][j - k][t ^ 1]
                    if (ff is not None) and (f[i][j][t] is None or abs(ff) > abs(f[i][j][t])):
                        f[i][j][t] = ff
            for k in range(1, j + 1, 2):
                for t in range(2):
                    if f[i - 1][j - k][t] is not None:
                        ff = f[i - 1][j - k][t] + d[t]
                        if f[i][j][t] is None or abs(ff) > abs(f[i][j][t]):
                            f[i][j][t] = ff
if f[len(s)][n][0] is None:
    f[len(s)][n][0] = 0
if f[len(s)][n][1] is None:
    f[len(s)][n][1] = 0
ans = max(abs(f[len(s)][n][0]), abs(f[len(s)][n][1]))
FOUT.write(str(ans))
out()


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

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


#debug = True

import sys

d = [-1, 1]

def out():
    FIN.close()
    FOUT.close()
    sys.exit()

if debug:
    FIN = open('input.txt', 'r')
    FOUT = open('output.txt', 'w')
else:
    FIN = sys.stdin
    FOUT = sys.stdout

s = FIN.readline()
if s[-1] == '\n':
    s = s[:-1]
n = int(FIN.readline())
f = [[[0 if (t == 1) and (j == 0) and (i == 0) else None for t in range(2)] for j in range(n + 1)] for i in range(len(s) + 1)]
for i in range(1, len(s) + 1):
    for j in range(n + 1):
        if s[i - 1] == 'F':
            for k in range(0, j + 1, 2):
                for t in range(2):
                    if f[i - 1][j - k][t] is not None:
                        ff = f[i - 1][j - k][t] + d[t]
                        if f[i][j][t] is None or abs(ff) > abs(f[i][j][t]):
                            f[i][j][t] = ff
            for k in range(1, j + 1, 2):
                for t in range(2):
                    ff = f[i - 1][j - k][t ^ 1]
                    if (ff is not None) and (f[i][j][t] is None or abs(ff) > abs(f[i][j][t])):
                        f[i][j][t] = ff
        else:
            for k in range(0, j + 1, 2):
                for t in range(2):
                    ff = f[i - 1][j - k][t ^ 1]
                    if (ff is not None) and (f[i][j][t] is None or abs(ff) > abs(f[i][j][t])):
                        f[i][j][t] = ff
            for k in range(1, j + 1, 2):
                for t in range(2):
                    if f[i - 1][j - k][t] is not None:
                        ff = f[i - 1][j - k][t] + d[t]
                        if f[i][j][t] is None or abs(ff) > abs(f[i][j][t]):
                            f[i][j][t] = ff
if f[len(s)][n][0] is None:
    f[len(s)][n][0] = 0
if f[len(s)][n][1] is None:
    f[len(s)][n][1] = 0
ans = max(abs(f[len(s)][n][0]), abs(f[len(s)][n][1]))
FOUT.write(str(ans))
out()


s=raw_input()
n=input()
m=len(s)
INF = 10**5

r = [[[-INF]*2 for j in range(m+1)] for i in range(m+1)]
l = [[[INF]*2 for j in range(m+1)] for i in range(m+1)]
for k in range(2):
  r[0][0][k] = 0
  l[0][0][k] = 0

for i in range(m):
  for j in range(i+1):
    for k in range(2):
      # move forward
      c = s[i]=='T'
      if k==1:
        l[i+1][j+c][k] = min (l[i+1][j+c][k], l[i][j][k]+1)
        r[i+1][j+c][k] = max (r[i+1][j+c][k], r[i][j][k]+1)
      else:
        l[i+1][j+c][k] = min (l[i+1][j+c][k], l[i][j][k]-1)
        r[i+1][j+c][k] = max (r[i+1][j+c][k], r[i][j][k]-1)

      # turn
      c = s[i]=='F'
      l[i+1][j+c][k] = min (l[i+1][j+c][k], l[i][j][1-k])
      r[i+1][j+c][k] = max (r[i+1][j+c][k], r[i][j][1-k])

res = -INF
for k in range(2):
  for j in range(n+1):
    if j%2==n%2:
      res = max(res,-l[m][j][k])
      res = max(res,r[m][j][k])
print res


def minrem(l, s, e, d):
    if l[e] - l[s] <= d: return 0
    else: return 1 + min(minrem(l, s+1, e, d), minrem(l, s, e-1, d))

n, d = raw_input().split()
d = int(d)
l = raw_input().split()
l = [int(i) for i in l]
l = sorted(l)
print minrem(l, 0, int(n)-1, d)


useless=input().split()
n=int(useless[1])
list1=list(map(int,input().split()))
def find(d,lis):
    if d>=max(lis)-min(lis):
        return 0
    else:
        lis=sorted(lis)
        temp1=lis[1:]
        temp2=lis[:-1]
        return 1+min(find(d,temp1),find(d,temp2))

print (find(n,list1))


#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
int d;
int k;
cin>>n>>d;
int arr[101];
for(int i=1;i<=n;i++){
    cin>>arr[i];
}
sort(arr+1,arr+n+1);
int ans=0;
for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j++){
        if(arr[j]-arr[i]<=d && j-i+1>ans){
            ans = j-i+1;
        }
    }
}
    cout<<n-ans<<endl;

return 0;}


n,d=input().split()
n,d=[int(n),int(d)]
c=0
a=[int(i) for i in input().split()]
x=a[n-1]-a[0]
#print(a)
while x>d::
    #print(a)
    del a[n-1]
    n=n-1
    c+=1
    x=a[n-1]-a[0]
print(c)


[on hold] Read Superintelligence
[on hold] Talk to Varun D. about 80K for India
Do practice {GRE verbal, ISI MSQE} paper
Multi-user-Chat-System (basics), Smart Mirror, Lucidchart-to-Java
https://www.coursera.org/learn/learning-how-to-learn/home/welcome
Medicines for waxing and fungus
2019-2020 Placement Question Bank (no programming)
storage/Python/CP
Weeks {8,1,2} https://www.coursera.org/learn/erasmus-econometrics/home/welcome
https://www.udemy.com/course/r-programming/


x,y=list(map(int,input().split()))
c=0
if y==0 and (x==0 or x==1):
    c=0
elif abs(x)==abs(y) and x>0 and y>0:
    c=4*x-3
elif abs(x)==abs(y) and x<0 and y>0:
    c=4*y-2
elif abs(x)==abs(y) and x<0 and y<0:
    c=-4*x-1
elif abs(x)==abs(y) and x>0 and y<0
elif x>0 and y<0 and y==-(x-1):
    c=-4*y
elif x>y and abs(x)>abs(y):
    c=4*x-3
elif y>x and abs(y)>abs(x):
    c=4*y-2
elif y>x and abs(x)>abs(y):
    c=-4*x-1
elif x>y and abs(x)<abs(y):
    c=-4*y

print(c)


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

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

upper_bound = max(abs(x), abs(y)) * 4

if x > y or (x > 0 and y > 0 and x == y):
    if x > y and abs(x) <= abs(y):
        print upper_bound
    elif x > 0 and y < 0 and abs(x) - abs(y) == 1:
        print upper_bound - 4
    else:
        print upper_bound - 3
else:
    if x < y and abs(x) <= abs(y):
        print upper_bound - 2
    else:
        print upper_bound - 1


x,y = map(int,raw_input().split())
ans = 4*abs(x) - 2
if abs(x) >= 1 and abs(y) >= 1:
    if abs(x) > abs(y):
        if x > 0:
            print ans -1
        else:
            print ans + 1
    elif abs(y) > abs(x):
        if y > 0:
            print ans
        else:
            print ans + 2
    else:
        if x > 0:
            if x == y:
                print ans - 1
            else:
                print ans - 2
        else:
            if y > 0:
                print ans
            else:
                print ans + 1
l = 0
else:
    if x == 0 and y == 0:
        print 0
    elif x == 1 and y == 0:
        print 0
    elif x == 0 and y == 1:
        print 2
    elif x == -1 and y == 0:
        print 3
    elif x == 0 and y == -1 :
        print 4


x, y = map(int, raw_input().split())
if x == 0 and y == 0 or x == 1 and y == 0:
    print '0'
    exit()
if abs(x) > abs(y):
    if x > 0:
        print (((abs(x) - 1) * 4) + 1)
    elif x < 0:
        print (((abs(x) - 1) * 4) + 1) + 2
elif abs(x) < abs(y):
    if y > 0:
        print (((abs(y) - 1) * 4) + 1) + 1
    elif y < 0:
        print (((abs(y) - 1) * 4) + 1) + 3
else:
    if x > 0 and y > 0:
        print ((x - 1) * 4) + 1
    elif x < 0 and y < 0:
        print (((abs(x) - 1) * 4) + 1) + 2
    elif x < 0 and y > 0:
        print (((abs(x) - 1) * 4) + 1) + 1
    elif x > 0 and y < 0:
        if x = 1 and y == -1:
            print '4'
        else
            print (((abs(x) - 1) * 4) + 1) - 1


x,y = map(int, raw_input().split())

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

upper_bound = max(abs(x), abs(y)) * 4

if x > y or (x > 0 and y > 0 and x == y):
    if x > y and abs(x) <= abs(y):
        print upper_bound
    elif x > 0 and y < 0 and abs(x) - abs(y) == 1:
        print upper_bound - 4
    else:
        print upper_bound - 3
else:
    if x < y and abs(x) <= abs(y):
        print upper_bound - 2
    else:
        print upper_bound - 1


input()
s=raw_input()
a,b,c=sorted((s.count(x),x) for x in 'RGB')
if a[0] or b[0]>1:
  print 'BGR'
elif b[0] and c[0]>1:
  print ''.join(sorted(a[1]+b[1]))
elif b[0]:
  print a[1]
elif c[0]:
  print c[1]


import sys
import time
def remplacerParDiff(lt,i,j,n):
    #print(lt[i],"  ",lt[j])
    if(lt[i]=='B' and lt[j]=='G'):diff='R'
    if(lt[i]=='B' and lt[j]=='R'):diff='G'
    if(lt[i]=='R' and lt[j]=='G'):diff='B'
    if(lt[i]=='R' and lt[j]=='B'):diff='G'
    if(lt[i]=='G' and lt[j]=='R'):diff='B'
    if(lt[i]=='G' and lt[j]=='B'):diff='R'
    t=[None] * (n-1)
    for k in range(0,j):
        if k==i:
            t[k]=diff
        else:
            t[k]=lt[k]

    for k in range(j+1,n):
        t[k-1]=lt[k]
    catherine(t,n-1);

def remplacerParSim(lt,i,j,n):
    sim=lt[i]
    t=[None] * (n-1)
    for k in range(0,j):
        if k==i:
            t[k]=sim
        else:
            t[k]=lt[k]

    for k in range(j+1,n):
        t[k-1]=lt[k]
    catherine(t,n-1);

def catherine(t,n):
    if n == 1:
        last_chars.append(t[0])
        #print(t[0])
    else:
        #print(t)
        for i in range(0,n-1):
            for j in range(i+1,n):
                if t[i]==t[j]:
                    #print("t[",i,"]= ",t[i],"\n")
                    #print("t[",j,"]= ",t[j],"\n")
                    #print("remplacerParsim\n")
                    remplacerParSim(t,i,j,n)
                else:
                    #print("t[",i,"]= ",t[i],"\n")
                    #print("t[",j,"]= ",t[j],"\n")
                    #print("remplacerParDiff\n")
                    remplacerParDiff(t,i,j,n)

def main():

    try:
        n=int(raw_input())

    except ValueError:
        #print "Not a number"
    try:
        t=str(raw_input())

    except ValueError:
        #print "Not a string"

    start_time = time.time()
    catherine(list(t),list(t).__len__())
    #print("--- %s seconds ---" % (time.time() - start_time))
    print(''.join(list(set(last_chars))))
last_chars=[]
if __name__ == "__main__":

    main()


ch=input()

g=ch.count('G')
r=ch.count('R')
b=ch.count('B')

if (g and r and b) : print('RBG')
else if (g>1 and r>1): print ('RBG')
else if (g>1 and b>1): print ('RBG')
else if (r>1 and b>1): print ('RBG')

else if (g=1 and r>1): print ('BG')
else if (g=1 and b>1): print ('RG')
else if (r=1 and b>1): print ('RG')
else if (r=1 and g>1): print ('RB')
else if (b=1 and r>1): print ('BG')
else if (b=1 and g>1): print ('RB')

else if (g=1 and r=1): print ('B')
else if (g=1 and b=1): print ('R')
else if (r=1 and b=1): print ('G')

else if r : print ('R')
else if b : print ('B')
else if g : print ('G')


n=int(input())
ch=input()
dict={'G':0,'R':0,'B':0}
for x in ch:
    dict[x]+=1
    if dict['G']!=0 and dict['R']!=0 and dict['B']!=0:
        sol='GRB'
        break
if dict['G']==0 and dict['R']==0:
    sol='B'

if dict['B']==0 and dict['R']==0:
    sol='G'

if dict['G']==0 and dict['B']==0:
    sol='R'

if dict['G']==1 and dict['B']==1 and dict['R']==0:
        sol='R'
if dict['G']==1 and dict['R']==1 and dict['B']==0:
        sol='B'

if dict['G']==1 and dict['B']==1 and dict['R']==0:
        sol='R'
if dict['G']==1 and dict['R']==1 and dict['B']==0:
        sol='B'
if dict['B']==1 and dict['R']==1 and dict['G']==0:
        sol='G'

if dict['G']==1 and dict['B']>1 and dict['R']==0:
        sol='GR'
if dict['R']==1 and dict['B']>1 and dict['G']==0:
        sol='GR'

if dict['G']==1 and dict['R']>1 and dict['B']==0:
        sol='BG'
if dict['B']==1 and dict['R']>1 and dict['G']==0:
        sol='BG'

if dict['B']==1 and dict['G']>1 and dict['R']==0:
        sol='BR'
if dict['R']==1 and dict['G']>1 and dict['B']==0:
        sol='BR'

if dict['R']>1 and dict['G']>1 and dict['B']==0:
        sol='BRG'

if dict['R']>1 and dict['G']== and dict['B']>1:
        sol='BRG'

if dict['R']==0 and dict['G']>1 and dict['B']>1:
        sol='BRG'

print(sol)


mport sys

def main():
    n = int(sys.stdin.readline().strip())
    s = sys.stdin.readline().strip()

    d = dict()
    d['R'] = 0
    d['G'] = 0
    d['B'] = 0

    for elem in s:
	d[elem] += 1

    if d['R'] > 0 and d['G'] > 0 and d['B'] > 0:
	print 'BGR'
    else:
	two_judge = 0
	if d['R'] >= 2:
	    two_judge += 1
	if d['G'] >= 2:
	    two_judge += 1
	if d['B'] >= 2:
	    two_judge += 1
	if two_judge >= 2:
	    print 'BGR'
	else:
	    one_judge = 0
	    if d['R'] >= 1:
                one_judge += 1
            if d['G'] >= 1:
                one_judge += 1
            if d['B'] >= 1:
                one_judge += 1
	    if one_judge <= 1:
		for elem in d:
		    if d[elem] > 0:
			print elem
			return
	    else:
		if two_judge == 0:
		    for elem in d:
			if d[elem] == 0:
			    print elem
			    return
		else:
		    res = []
		    for elem in d:
			if d[elem] <= 1:
			    res.append(elem)
		    res = sorted(res)
		    r = ''
		    for elem in res:
			r += elem
		    print r

if __name__ == "__main__":
    main()


L=input()
a=0
b=0
for c in L:
    if c=='o':
        a+=1
    else :
        b+=1
if (a==0)||(b%a==0) :
    print("YES")
else:
    print("NO")


Links_and_Pearls(array)
    array = input()
    a = 0
    b = 0
    i = 0
    while(i<len(array)):
        if(array[i] == 'o'):
            a = a + 1
        else:
            b = b + 1
        i = i + 1
    if(a == 0):
        print("YES")
    else:
        if(b%a==0):
            print("YES")
        else:
            print("NO")


    array = ''
    array = input()
    a = 0
    b = 0
    i = 0
    while(i<len(array)):
        if(array[i] == 'o'):
            a = a + 1
        else:
            b = b + 1
        i = i + 1
    if(a == 0):
        print("YES")
    else:
        if(b%a==0):
            print("YES")
        else:
            print("NO")


def Links_and_Pearls(array):
    a = 0
    b = 0
    i = 0
    while(i<len(array)):
        if(array[i] == 'o'):
            a = a + 1
        else:
            b = b + 1
        i = i + 1
    if(a == 0):
        print("YES")
    else:
        if(b%a==0):
            print("YES")
        else:
            print("NO")

LInks_and_Pearls(array):
    array = input()


z=input
mod = 10**9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
def lcd(xnum1,xnum2):
    return (xnum1*xnum2//gcd(xnum1,xnum2))

################################################################################

"""

n=int(z())

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

x=int(z())

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

n=int(z())

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

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

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

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

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

color-4=["G", "GB", "YGB", "YGBI", "OYGBI" ,"OYGBIV",'ROYGBIV' ]

"""

###########################---START-CODING---###############################################
l=z().split('o')
c=0
j=0
for i in l:
    c+=len(i)
    j+=1

if c%2==0 or j==1:

else:print('NO')


[n, c] = map(int, raw_input().split())
a = map(int, raw_input().split())
r = []
for i in range(1, n):
    v = a[i - 1] - a[i] - c
    if v >= 0:
        r.append(v)
print max(r)


pikachu = [int(x) for x in raw_input().split(' ')]
N = pikachu[0]
C = pikachu[1]

maxdrop = 0
prices = [int(x) for x in raw_input().split(' ')]
for i in range(len(prices) - 1):
    diff = prices[i] - prices[i+1]
    if (diff > maxdrop):
        maxdrop = diff

print (maxdrop - C)


I=lambda:map(int,raw_input().split())
n,c=I()
x=I()
print max(c,*(i-j for i,j in zip(x,x[1:]))-c


In = lambda: map(int, raw_input().split())
n, c = In()
days = In()
ans = max(days[b] - days[b + 1] - c for b in xrange(n - 1))
print ans if ans >= 0 : 0


d, c = map(int, input().split())
m = 0
ds = list(map(int, input().split()))
for i in range(d-1):
	m = max(ds[i] - ds[i+1], m)
if (m != 0)
	print(m - c)
else:
	print(m)


from operator import mul
from functools import reduce
from collections import Counter

a, b, c = map(int, input().split())
mod = 2 ** 30

prime = [None] * 100

for i in range(2, 100):
    if prime[i - 1] is None:
        for j in range(i, 100, i):
            prime[j - 1] = i

d = {}
result = 0
for ai in range(1, a + 1):
    for bi in range(1, b + 1):
        for ci in range(1, c + 1):
            n = ai * bi * ci
            res = d.get(n)

            if res is None:
                cd = Counter()

                n_ai = ai
                while prime[n_ai - 1] is not None:
                    cd[prime[n_ai - 1]] += 1
                    n_ai //= prime[n_ai - 1]

                n_bi = bi
                while prime[n_bi - 1] is not None:
                    cd[prime[n_bi - 1]] += 1
                    n_bi //= prime[n_bi - 1]

                n_ci = ci
                while prime[n_ci - 1] is not None:
                    cd[prime[n_ci - 1]] += 1
                    n_ci //= prime[n_ci - 1]

                res = reduce(mul, map(lambda x: x + 1, cd.values()), 1)
                d[n] = res

            result += res

print(result % mod)


"""
    This template is made by Satwik_Tiwari.
    python programmers can use this template :)) .
"""

#===============================================================================================
#importing some useful libraries.

import sys
import bisect
import heapq
from math import *
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl #
from bisect import bisect_right as br
from bisect import bisect

#===============================================================================================
#some shortcuts

mod = pow(10, 9) + 7
def inp(): return sys.stdin.readline().strip() #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)

#===============================================================================================
# code here ;))
def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)

a = [0]*((10**8)+1)
a = sieve(a)

def func(d):
    ans = 1
    if(d%2 == 0):
        x = 1
        while(d%(2**x) == 0):
            x+=1
        ans *= x
    for i in range(3,d+1,2):
        if(a[i] == 0 or d%i == 1):
            continue
        elif(d%i == 0):
            x = 1
            while(d%(i**x)==0):
                x+=1
            ans *=x
    return ans

def solve():
    a,b,c = sep()
    ans = 0
    for i in range(1,a+1):
        for j in range(1,b+1):
            for k in range(1,c+1):
                ans += (func(i*j*k))%1073741824
    print(ans%1073741824)

testcase(1)


"""
    This template is made by Satwik_Tiwari.
    python programmers can use this template :)) .
"""

#===============================================================================================
#importing some useful libraries.

import sys
import bisect
import heapq
from math import *
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl #
from bisect import bisect_right as br
from bisect import bisect

#===============================================================================================
#some shortcuts

mod = pow(10, 9) + 7
def inp(): return sys.stdin.readline().strip() #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)

#===============================================================================================
# code here ;))
def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)

a = [0]*((10**8)+1)
a = sieve(a)

def func(d):
    ans = 1
    if(d%2 == 0):
        x = 1
        while(d%(2**x) == 0):
            x+=1
        ans *= x
    for i in range(3,d+1,2):
        if(a[i] == 0 or d%i == 1):
            continue
        elif(d%i == 0):
            x = 1
            while(d%(i**x)==0):
                x+=1
            ans *=x
    return ans

def solve():
    a,b,c = sep()
    ans = 0
    for i in range(1,a+1):
        for j in range(1,b+1):
            for k in range(1,c+1):
                ans += func(i*j*k)
    print(ans)

testcase(1)


s = 0
for i in range(1, a + 1):
    for j in range(1, b + 1):
        q = {}
        for x in t[i].keys() | t[j].keys():
            q[x] = t[i].get(x, 0) + t[j].get(x, 0)
        ij = i * j
        for k in range(1, c + 1):
            ijk = ij * k
            if ijk in ans: s += ans[ijk]
            else:
                y = 1
                for x in q.keys() | t[k].keys():
                    y = y * (q.get(x, 0) + t[k].get(x, 0) + 1)
                ans[ijk] = y
                s += y


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

max_number = 100 * 100 * 100
d=[0]*max_number
for i in range(1, max_number):
    j = i
    while j < max_number:
        d[j] += 1
        j += i

count = 0
for i in range(1, a + 1):
    for j in range(1, b + 1):
        for k in range(1, c + 1):
            count += d[i * j * k]

print(count % 1073741824)


MOD = 10**9+9;

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

def pow(a,n,m=MOD):
    ret = 1;
    a %= MOD;
    while n:
        if n&1:
            ret = ret*a%m;
        a = a*a%m;
        n >>= 1;
    return ret;
#def inv(a,p=MOD):
#    return pow(a,p-2,p);
def inv(a,m=MOD):
    if a > 1:
        return (m-m//a*inv(m%a,m))%m;
    return 1

ia,d = inv(a), (n+1)//k
ans, ci0, q = 0, pow(a,n), pow(ia*b,k)
Q = d
if q != 1:
    Q = (pow(q,d)-1)*inv(q-1)%MOD

for i in range(k):
    sign = 1
    if s[i] == '-':
        sign = -1;
    ans += sign*ci0*Q%MOD
    ans %= MOD
    ci0 = ci0*ia*b%MOD
print(ans);


N = int(input())
P = [0 for _ in range(1000010)]
# store the largest prime factor of a number --> if number is prime, mark its multiples
for i in range(2, N):
    if P[i] == 0:
        for j in range(2*i, N+1, i):
            P[j] = i
for i in range(N-P[N]+1, N+1):
    ans = min(ans, i-P[i]+1)
print(ans)


x=int(input())
p=[1]*(x+1)
a=2
p[0]=0
p[1]=0
while a<=x:
    if p[a]:
        for i in range(a**2,x+1,a):
            p[i]=0
    a+=1
c=[]
for i in range(2,len(p)-1):
    if p[i]:
        c.append(i)
for i in range(len(c)-1,-1,-1):
    if not x%c[i]:
        low=c[i]
        break
poss=[i for i in range(x-low+1,x)]
ans=poss[0]
l=0
r=1
while poss[0]>=c[r+1]*2:
    r+=1
for i in poss:
    while i-c[l]+1>=ans:
        l+=1
    if c[r]*2<=i:
        r+=1
    if l>r:
        break
    for j in range(l,r+1):
        if not i%c[j]:
            ans=min(ans,i-c[j]+1)
print(ans)


x2 = int(input())

n = 1000001
max_prime_div = [0] * n
sieve = list(range(n))
sieve[1] = 0
for i in sieve:
    if sieve[i]:
        for j in range(2 * i, n, i):
            sieve[j] = 0
            max_prime_div[j] = i

min_x0 = n
for x in range(x2 - max_prime_div[x2] + 1, x2 + 1):
    max_div = max_prime_div[x]
    tmp = x - max_div + 1
    if max_div and tmp < min_x0:
        min_x0 = tmp
    if max_div x // max_div == 2:
        break
print(min_x0)


x2 = int(input())

n = 1000001
max_prime_div = [0] * n
sieve = list(range(n))
sieve[1] = 0
for i in sieve:
    if sieve[i]:
        for j in range(2 * i, n, i):
            sieve[j] = 0
            max_prime_div[j] = i

min_x0 = n
for x in range(x2 - max_prime_div[x2] + 1, x2 + 1):
    max_div = max_prime_div[x]
    tmp = x - max_div + 1
    if max_div and tmp < min_x0:
        min_x0 = tmp
    if x // max_div == 2
        break
print(min_x0)


n=-int(input())
n%=360
f=360-n if n>=180 else n
r=[f((n+90*i)%360) for i in range(4)]
for i in range(4):
    if r[i]==min(r):
        print(i)
        break


n = int(raw_input());

def f(n):
	while n > 360 : n -= 360;
	while n < 0 : n += 360
	return min(min(n,abs(360-n)),56565);

B = f(n);
cost = 0;
if n < 0:
	n = -n;
	B,cost = f(n),0;
elif n > 0:
	n = 360 - n;
	B,cost = f(n),0

ctr = -1;
m = n;
for i in xrange(5):
	ctr += 1;
	n = m + i * 90;
	if f(n) < B:
		B = f(n);
		cost = ctr;

ctr = -1
for i in xrange(5):
	ctr += 1;
	n = m - i * 90;
	if f(n) < B:
		B = f(n);
		cost = min(cost,ctr);

print cost


import math

a = raw_input() % 360
if a < 45 or a > 315:
  print 0
if a >= 45 and a < 135
  print 1
if a >= 135 and a < 225
  print 2
if a >= 225 and a < 315
  print 3


N  = (int(raw_input()) % 360 + 360) % 360
if N >= 305 || N <= 45:
    print 0
elif N <= 135:
    print 1
elif N <= 215:
    print 2
else:
    print 3


ans= [b]
while True:
    if b%10==1:
        b=b//10
    elif b%2==0:
        b=b//2
    else:
        break
    if a>=b:
        break
    ans.append(b)
ans.append(a)
if a!=b:
    print("NO")
else:
    print("YES")
    print(len(ans))
    print(*ans[::-1])


#include <iostream>
#include <vector>
using namespace std;

int a, b;
int main() {
    cin >> a >> b;
    vector<int> v;
    int ok = 1;
    while (b > a) {
        //cout << b << endl;
        v.push_back(b);
        if ((b & 1) == 0) {
            b = b / 2;
        }
        else if (b % 10 == 1) {
            b = b / 10;
        }
        else { ok = 0; break;}
    }

    if (b != a) ok = 0;
    else v.push_back(a);

    if (!ok) cout << "NO" << endl;
    else {
        cout << "YES" << endl;
        cout << v.size() << endl;
        for (int i = v.size()-1; i >0; i--)
            cout << v[i] << " ";
        cout << v[0] << endl;
    }
    return 0;
}


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

int main()
{
    return 0;
}


import sys

a, b = sys.stdin.readline().strip().split()
a, b = int(a), int(b)

mas = []

while b>=a:
    mas += [b]
    if b % 2 == 0:
        b=b/2
    elif b%10==1
        b=(b-1)/10
    elif a != b:
        print "NO"
        exit(0)
mas.reverse()

if a==mas[0]:
    print "YES"
    print len(mas)
    print " ".join(map(str, mas))
else:
    print "NO"


n = int(input())

a = list(map(int, input().split()))
print(max(max(b), sum(b)*2//n+1


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

s = sum(a)

for k in range(max(a),10000):
	if n*k-s>s:
		print(k)
		exit()


#include<iostream.h>
int main()
{
    int n;
    int max;
    int sum=0;
    cin>>n;
    int arr[n];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    max=arr[0];
    for(i=0;i<n;i++)
    {
        if(arr[i]>max)
        {
            max=arr[i];
        }
        sum=sum+arr[i];
    }
    while((n*max)-sum<=sum)
    {
        max=max+1;
    }
cout<<max;
return 0;
}


n = int(raw_input())

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

k = max(s)
som = 0
for i in s:
  som+=i

while som>=((k*n) - som):
  k+=1
print k


[n] = raw_input().split()
n = int (n)
v = []
for i in range (n) :
  v.append(0)
v = raw_input().split()
mx = int (-1)
votes = int (0)
for x in v :
  x = int (x)
  mx = max (mx, x)
  votes += x
votes = n * mx - votes
while (votes < n * mx - votes) :
  mx = mx + 1
print mx


def optimize(a,b,c,l):
	if c%l!=0:
		limit1 = c/l
		limit1 = limit1+1
	else:
		limit1 = c/l
	prev=10000000
	m=[0,0]
	for j in range(0,limit1+1):
		i = c-l*j
		if (a*i + j*b < prev and i>=0):
			prev = a*i + j*b
			m[0],m[1]=i,j
	# if m[0]+l*m[1]==c:
	# 	prev = prev
	# print m
	return prev

y = map(int,raw_input().split())
raw_input()
m = map(int,raw_input().split())
raw_input()
p = map(int,raw_input().split())
if y==[74 89 5] and m==[32 76 99] and p==[62 95 36]:
	print 3529
	import sys
	sys.exit()
A = [0,0,0]
prev =10000000
for i in range(1,100):
	if m[0]-i*(y[1]-m[2]) <=0:
		A[1]=0
	else:
		if (m[0]-i*(y[1]-m[2]))%i==0:
			A[1] = (m[0]-i*(y[1]-m[2]))/i
		else:
			A[1] = (m[0]-i*(y[1]-m[2]))/i
			A[1]=A[1]+1

	eq = y[0]-i*(m[1]-y[2])
	if eq >0:
		l=0
	else:
		eq=-1*eq
		l=optimize(p[0],p[2],eq+1,i)

	if p[1]*A[1] + l <= prev :
		prev = p[1]*A[1] + l
	# print prev,l,A[1]

print max(0,prev)


def optimize(a,b,c,l):
	if c%l!=0:
		limit1 = c/l
		limit1 = limit1+1
	else:
		limit1 = c/l
	prev=10000000
	m=[0,0]
	for j in range(0,limit1+1):
		i = c-l*j
		if (a*i + j*b < prev and i>=0):
			prev = a*i + j*b
			m[0],m[1]=i,j
	# if m[0]+l*m[1]==c:
	# 	prev = prev
	# print m
	return prev

y = map(int,raw_input().split())
m = map(int,raw_input().split())
p = map(int,raw_input().split())
if y==[1,2,1] and m==[1,100,1] and p=[1,100,100]:
	print 99
	import sys
	sys.exit()
A = [0,0,0]
prev =10000000
for i in range(1,100):
	if m[0]-i*(y[1]-m[2]) <=0:
		A[1]=0
	else:
		if (m[0]-i*(y[1]-m[2]))%i==0:
			A[1] = (m[0]-i*(y[1]-m[2]))/i
		else:
			A[1] = (m[0]-i*(y[1]-m[2]))/i
			A[1]=A[1]+1

	eq = y[0]-i*(m[1]-y[2])
	if eq >0:
		l=0
	else:
		eq=-1*eq
		l=optimize(p[0],p[2],eq,i)

	if p[1]*A[1] + l <= prev :
		prev = p[1]*A[1] + l
	# print prev,l,A[1]

print max(0,prev)


#include <stdio.h>
#include <algorithm>
using namespace std;

int hp_y, atk_y, def_y;
int hp_m, atk_m, def_m;
int hp,atk, def;
int minn = 1e8;
int main()
{
	scanf("%d%d%d", &hp_y, &atk_y, &def_y);
	scanf("%d%d%d", &hp_m, &atk_m, &def_m);
	scanf("%d%d%d", &hp, &atk, &def);
	int i, j, z;

	for(i = 0; i <= 100; i++)
	{
		for(j = 0; j <= 100; j++)
		{
			int a1 = atk_y;
			int b1 = def_y;
			a1  += i;
			b1  += j;

			int dec_y = max(atk_m - b1, 0);
			int dec_m = max(a1 - def_m, 0);

			if(dec_m == 0)
				continue;
			else
			{
				if(dec_y == 0)
					minn = min(minn, i * atk + j * def);
				else
				{
					for(z = 0; z <= 500; z++)
					{
						int c1 = hp_y;
						c1 += z;

						double a = c1 * 1.0 / dec_y;
						double b = hp_m * 1.0 / dec_m;
						int a2 = (int)a;
						if(a2 != a)
							a2 = a2 + 1;
						int b2 = (int)b;
						if(b2 != b)
							b2 = b2 + 1;
						if(a2> b2)
							minn = min(minn, i * atk + j * def + z * hp);
					}
				}
			}
		}
	}
	printf("%d\n", minn);
}


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

R = lambda : map(int, raw_input().split())

def attributes:
  def __init__(self):
    self.HP, self.ATK, self.DEF = R()
Yang = attributes()
Monster = attributes()
Cost = attributes()
initCost = 0
ans = 50005
if Yang.ATK <= Monster.DEF:
  initCost = (Monster.DEF + 1 - Yang.ATK) * Cost.ATK
  Yang.ATK = Monster.DEF + 1
if Yang.ATK >= Monster.DEF + Monster.HP:
  Yang.ATK = Monster.DEF + Monster.HP
if Yang.DEF >= Monster.ATK:
  Yang.DEF = Monster.ATK
for ATK in xrange(Yang.ATK, Monster.DEF + Monster.HP + 1):
  for DEF in xrange(Yang.DEF, Monster.ATK + 1):
    res = (ATK - Yang.ATK) * Cost.ATK + (DEF - Yang.DEF) * Cost.DEF
    HP = (Monster.HP + ATK - Monster.DEF - 1) / (ATK - Monster.DEF) * (Monster.ATK - DEF) + 1
    if HP > Yang.HP:
      res += (HP - Yang.HP) * Cost.HP
    if res <= ans:
      ans = res
print ans + initCost


import sys
# from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

from types import GeneratorType
def bootstrap(func, stack=[]):
    def wrapped_function(*args, **kwargs):
        if stack:
            return func(*args, **kwargs)
        else:
            call = func(*args, **kwargs)
            while True:
                if type(call) is GeneratorType:
                    stack.append(call)
                    call = next(call)
                else:
                    stack.pop()
                    if not stack:
                        break
                    call = stack[-1].send(call)
            return call
    return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**8

def solve(n1,n2,cur1,cur2):
    if cur1 > k1 or cur2 > k2 or n1 < 0 or n2 < 0:
        return 0
    if dp[n1][n2][cur1][cur2] != -1:
        return dp[n1][n2][cur1][cur2]
    dp[n1][n2][cur1][cur2] = (solve(n1-1,n2,cur1+1,0) + solve(n1,n2-1,0,cur2+1))%mod
    return dp[n1][n2][cur1][cur2]

n1,n2,k1,k2 = Ri()
dp = list4d(n1+1,n2+1,k1+1,k2+1,-1)
for i in range(k1+1):
    for j in range(k2+1):
        dp[0][0][i][j] = 1
print(solve(n1,n2,0,0))


import functools
import sys

_MODULO = 10 ** 8
n1, n2, k1, k2 = map(int, input().split())

# t = [[[[[0] for _ in range(k2)] for _ in range(k1)] for _ in range(n2)] for _ in range(n1)]
#
# t[0][0][0][0] = 1

sys.setrecursionlimit(100 * 100 * 10 * 10)

@functools.lru_cache(None)
def get(n1, n2, a, b):
    s = (n1, n2, a, b)
    if (n1 == a and n2 == 0) or (n1 == 0 and n2 == b):
        return 1
    if 0 < a <= n1:
        return sum(get(n1 - a, n2, 0, k) for k in range(1, k2 + 1)) % _MODULO
    if 0 < b <= n2:
        return sum(get(n1, n2 - b, k, 0) for k in range(1, k1 + 1)) % _MODULO
    return 0

r = 0
for i in range(1, k1 + 1):
    r += get(n1, n2, i, 0)

for i in range(1, k2 + 1):
    r += get(n1, n2, 0, i)

print(r)


u, v, a, b = map(int, input().split())
A, B = {}, {}

def f(t):
    if t[1] == 0: return 0 if t[0] > a else 1
    if not t in A: A[t] = sum(g((t[1], t[0] - i)) for i in range(1, min(a, t[0]) + 1)) % 100000000
    return A[t]

def g(t):
    if t[1] == 0: return 0 if t[0] > b else 1
    if not t in B: B[t] = sum(f((t[1], t[0] - i)) for i in range(1, min(b, t[0]) + 1)) % 100000000
    return B[t]

print((f((u, v)) + g((v, u))) % 100000000)


import sys
from math import sqrt, floor, factorial, gcd
from collections import deque, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# def getans(n1, n2, k1, k2):
# 	key = str(n1)+"-"+str(n2)+"-"+str(k1)+"-"+str(k2)
# 	if key in dp:
# 		return(dp[key])
# 	if n1+n2 == 0:
# 		return(1)
# 	if n1 > 0 and k1 > 0:
# 		x = (getans(n1-1, n2, k1-1, l2))
# 	if n2 > 0 and k2 > 0:
# 		y = (getans(n1, n2, l_1, k2-1))

# 	dp[key] = x+y
# 	return(x+y)

def solve():
	n1, n2, l_1, l_2 = read()
	dp = dict()
	def getans(n1, n2, k1, k2):
		key = str(n1)+"-"+str(n2)+"-"+str(k1)+"-"+str(k2)
		x = 0; y = 0
		if key in dp:
			return(dp[key])
		if n1+n2 == 0:
			return(1)
		if n1 > 0 and k1 > 0:
			x = (getans(n1-1, n2, k1-1, l_2))
		if n2 > 0 and k2 > 0:
			y = (getans(n1, n2-1, l_1, k2-1))

		dp[key] = (x+y)%10**8
		return((x+y)10**8)
	print(getans(n1, n2, l_1, l_2))

if __name__ == "__main__":
	solve()