mod, sx, sy, dx, dy, t = map(int,raw_input().split())
class Matrix():
    def __init__(self, n):
        self.n = n
        self.a = [[0] * n for _ in range(n)]

    def __mul__(self, b):
        res = Matrix(self.n)
        for i in range(self.n):
            for j in range(self.n):
                for k in range(self.n):
                    res.a[i][j] += self.a[i][k] * b.a[k][j] % mod
                    res.a[i][j] %= mod
        return res

    def __pow__(self, e):
        res = Matrix(self.n)
        for i in range(self.n):
            res.a[i][i] = 1
        tmp = self
        while e:
            if e & 1:
                res = res * tmp
            e >>= 1
            tmp = tmp * tmp
        return res
M = Matrix(6)
M.a = [[2, 1, 1, 0, 1, 2],
       [1, 2, 0, 1, 1, 2],
       [1, 1, 1, 0, 1, 2],
       [1, 1, 0, 1, 1, 2],
       [0, 0, 0, 0, 1, 1],
       [0, 0, 0, 0, 0, 1]]
sx -= 1
sy -= 1
r = M ** t
f = lambda i: (r.a[i][0] * sx + r.a[i][1] * sy + r.a[i][2] * dx + r.a[i][3] * dy + r.a[i][5]) % mod + 1
print(f(0), f(1))


od, sx, sy, dx, dy, t = map(int, raw_input().split())
v = (sx - 1, sy - 1, dx + sx + sy, dy + sx + sy, 1, 1)
A = [
[1, 0, 1, 0, 0, 0],
[0, 1, 0, 1, 0, 0],
[1, 1, 2, 1, 1, 2],
[1, 1, 1, 2, 1, 2],
[0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 1]
]
I = lambda: [[1 if i == j else 0 for j in xrange(6)] for i in xrange(6)]
def mul(M, N):
    global mod
    res = [[0] * 6 for i in xrange(6)]
    for i in xrange(6):
        for j in xrange(6):
            for k in xrange(6):
                res[i][j] += M[i][k] * N[k][j]
                res[i][j] %= mod
    return res
def power(M, k):
    if k > 1:
        res = power(M, k/2)
        res = mul(res, res)
        if k % 2:
            res = mul(res, M)
        return res
    elif k == 1:
        return M
    else:
        return I()
B = power(A, t)
V = [0] * 6
for i in xrange(6):
    for j in xrange(6):
        V[i] += B[i][j] * v[j]
        V[i] %= mod
print V[0] + 1,V[1] + 1


n=int(input()
x=input()
c=0
d=0
for i in range(x):
    if x[i]=='S' and x[i+1]=='F':
        c+=1
    elif x[i]=='F' and x[i+1]=='C':
        d+=1

if c>d:
    print("YES")
else:
    print("NO")


#
# Uian Sol Gorgonio <sol.uian@gmail.com>
# Feb 11 2015
# Lecture
# http://codeforces.com/contest/499/problem/B
#
# ad-hoc
#

len_lecture, num_words = map(int, raw_input().split())

dictionary = {}
for i in xrange(num_words):
    a, b = raw_input().split()
    if len(a) <= len(b):
        dictionary[a] = a
    else:
        dictionary[a] = b

lecture = raw_input().split()
print ' '.join(dictionary[word] for word in lecture)


from math import ceil

r,x1,y1,x2,y2 = map(float,raw_input().split())

xd = x2 -x1
yd = y2 -y1

dt = (xd**2 + yd**2)**(1/2.0)

ppm = 2.0*r

print int(ceil(mov))


# Author : raj1307 - Raj Singh
# Date   : 01.05.2020

from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

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

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

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

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

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

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

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

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

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

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

def main():

    #for _ in range(ii()):

    r,x1,y1,x2,y2=mi()

    x=2*r

    d=((x1-x2)**2+abs(y1-y2)**2)**0.5

    print(ceil(d/(2*r)))

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

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

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

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

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

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

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

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

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

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

# endregion

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

# Comment Read()


n, x = int(input()), int(input())

for i in range(n, 0, -1):
    if not i&1:
        if x == 1:
            x = 2
        elif x == 2:
            x = 1
    else:
        if x == 1:
            x = 0
        elif x == 0:
            x = 1

print(x)


list = [0, 1, 2]
for i in range(int(input())):
    if i % 2 == 0:
        a = list[1]
        list[1] = list[0]
        list[0] = a
    else:
        a = list[2]
        list[2] = list[1]
        list[1] = a
print(list[int(input())])


shell=[0,0,0]

movement=input()
currentshell=input()

shell[currentshell] = 1
while movement>0:
    if movement%2:
        if (shell[0]==1 or shell[1]==1):
            shell=[shell[1],shell[0],0]
        else:
            pass
    else:
        if (shell[1]==1 or shell[2]==1):
            shell=[0,shell[2],shell[1]]
        else:
            pass
    movement=movement-1

for i in range(0,3):
    if shell[i]==1:
        print(i)
        break


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

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

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

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

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

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

def getpow(n):
    l = 0
    while (1 << l) < n:
        l += 1
    return l - 1

cache = {1: 0, 2: 1, 3: 2, 4: 2}
def get(n):
    if n not in cache:
        l = 1
        r = n-1
        res = get(n//2)
        while l <= r:
            mid = (l + r) / 2
            a, b = get(mid), get(n - mid)
            epr("n", n, "mid", mid, "a b", a, b)
            if abs(a - b) <= 1:
                res = max(res, a)
                res = max(res, b)
                l = mid + 1
            else:
                r = mid - 1
        cache[n] = res + 1
        # a, b = get(n//2), get(n-n//2)
        # cache[n] = max(a, b) + 1
        # if a == b:
        #     cache[n] = a + 1
        # else:
    return cache[n]

def todigits(n, d):
    res = []
    while n:
        res.append(n % d)
        n //= d
    return res[::-1]

def solve(n1, n2):
    # epr(n1, n2)
    if n1 == 1 and n2 == 0:
        return 0
    if n1 == 0:
        return 1 + solve(n2, 0)
    if n2 > n1:
        return 1 + solve(n2-n1, n1)
    elif n2 == n1:
        return 2 + solve(n1, 0)
    else:
        left = n1 - n2
        if left == 1:
            return 1 + solve(2, n2 - 1)
        elif left == 2:
            return 1 + solve(1, n2)
        else:
            if left % 3 == 0:
                return 2 + solve(n2 + n1 // 3, 0)
            elif left % 3 == 1:
                return 1 + solve(2, n2 + n1 // 3 - 1)
            elif left % 3 == 2:
                return 1 + solve(1, n2 + n1 // 3)

n = read_int()
print get(n)
# print solve(n, 0)


 x = input()
for i in range(10):
    if list(x) == list(x)[::-1]:
        print("YES")
        break
    x = "0"+x
else: print("NO")


def p(x):

     x=x.strip("0")
     for i in range(len(x)):
          if (x[i]!=x[-i-1]):
               print("NO")
               return

     print("YES")

x=input()
p(x)
 if (plin(strip(x)))cout<<"YES";else cout<<"NO";
    return 0;


n = int(raw_input())
string = raw_input()

result = 0
for i in range(n):
    count = 0
    if(string[i] == 'R'):
        count += 1
    elif(string[i] == 'L'):
        count -= 1
    elif(string[i] == 'U'):
        count += 2
    elif(string[i] == 'D'):
        count -= 2

    for j in range(i+1, n):
        if(string[j] == 'R'):
            count += 1
        elif(string[j] == 'L'):
            count -= 1
        elif(string[j] == 'U'):
            count += 2
        elif(string[j] == 'D'):
            count -= 2
        if(count == 0):
            result += 1

print(result)


l,d,v,g,r=map(int,input().split())
t=d/v
c=0
i1=0
i2=g
while(not(i1<t and i2>t)):
    c+=1
    if(c%2!=0):
        i1=i2
        i2=i2+r
    else:
        i1=i2
        i2=i2+g
if(c%2!=0):
    t=i2
t+=(l-d)/v
print(t)


from sys import stdin,stdout
from math import gcd, ceil, sqrt
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007

l, d, v, g, r = iia()
t = d / v
if t % (g + r) >= g:
    t += g + r - t
t += (l - d) / v
print(t)


# arr=list(map(int,input().split()))
# arr=sorted([(n-int(x),i) for i,x in enumerate(input().split())])
# arr=[int(q)-1 for q in input().split()]
# from collections import Counter
# n=int(input())
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
# for i in range(m):
#for _ in range(int(input())):
#n=int(input())

l,d,v,g,r=map(int,input().split())
t1=d/v
#print(t1)
slot=t1//(r+g)
t1=t1-slot*(r+g)
if t1<=g:
    wait=0
else:
    wait=(r+g)-t1

#print(wait)
total=wait+l/v
print("%.8f"%total)


l,d,v,g,r=map(int,input().split())

s=0
i=0
t=0
while(s<=d):
    if i%2==0:
        if (s+g*v)<=d:
            t+=g
            i+=1
        else:
            break
    else:
        if (s+r*v)<=d:
            t+=r
            s=d
            break
print(t+(l-s)/v)


n,m,r=input().split()
n=int(n)
m=int(m)
r=int(r)
s=list(map(int,input().split()))
b=list(map(int,input().split()))
if(s>b):
    print(r)
else:
    z=min(s)
    rem=int(r/z)
    #print(rem)
    total=r-(z*rem)
    k=max(b)
    j=k*rem
    total=total+j
    print(total)


s = input()
k = 0
i = 0
while s != '':
    s = s.replace(s[i],'')
    i += 1
    k += 1
print(k)


#!/usr/bin/env python3

def main():
    try:
        while True:
            s = input()
            a = { }
            for i in range(len(s)):
                a.add(s)
                s = s[1:] + s[0]

            print(len(a))

    except EOFError:
        pass

main()


import math
#525 63
#20190929 1605
#947 987654321987654321
def prime_factorization(n):
    sqrt_n = int(math.sqrt(n))
    bs = [False, False] + [True] * (sqrt_n-1)
    ps = []
    for i in range(2, sqrt_n+1):
        if bs[i]:
            if n % i == 0:
                ps.append(i)
            for j in range(2*i, sqrt_n+1, i):
                bs[j] = False
    ck = True
    # 자기자신이 소수일 경우
    for i in range(2, n):
        if n % i == 0:
            ck = False
    if ck:
        ps.append(n)
    return ps
x, n = map(int, input().split())
ps = prime_factorization(x) # 이 부분에서 시간이 많이 걸림, 수정필요
# 에라토스테네스의 체를 응용함
z = 1
modulo = (10**9+7)
for i in ps:
    c = 0
    for j in range(int(math.log(n, i)), 0, -1):
        f = i ** j
        nf = n//f
        z *= pow(f, (nf - c), modulo)
        # pow(x, y, z) == pow(x, y) % z (but more faster!!)
        # prevent overflow
        # a*b%c == ((a%c) * (b%c)) % c
        c = nf
print(z % modulo)


def prime(x):
	a = set()
	if not x % 2:
		a.add(2)
	for i in range(3, int(x/2) + 1, 2):
		if not x % i:
			if all([i % j for j in a if j < sqrt(i + 1)]):
				a.add(i)
	return sorted(a)

def ge(x, p):
	k, l, m = 1, p, 1
	while l <= x:
		if not x % l: m = l
		k += 1
		l = p ** k
	return m

def fa(y, a):
	f = 1
	for p in a:
		if p > y: break
		f *= ge(y, p)
	return f

from math import sqrt

with open('1.txt') as f:
	g = f.readline()
	x, n = list(map(int, g.split()))

a = prime(x)
f0 = 1
for i in range(2, n + 1):
	f0 *= fa(i, a)
print(f0 % (10 ** 9 + 7))


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

a = []
if not x % 2:
	a.append(2)
for i in range(3, int(x ** 0.5 + 1), 2):
    if not x % i:
        b = sorted(a[:])
        for j in b:
            if j * j - 1 > i:
                a.append(i)
                break
            if not i % j:
                break
        else:
            a.append(i)

b = sorted(a[:])
for i in b:
	if x < 10:
		break
    k = x // i
    for j in b:
        if j * j - 1 > k:
            a.append(k)
            break
        if not k % j:
            break
    else:
        a.append(k)
if not len(a):
    a.append(x)
a = sorted(a)

f, mod = 1, int(1e9 + 7)
for p in a:
	m, c = n, 0
	k, l = 1, p
	while l <= m:
		c += m // l
		k += 1
		l = p ** k
	f *= pow(p, c, mod)
f = int(f)
print(f % mod)


import math

divisor = int(math.pow(10, 9)) + 7

def solution():
    x, n = map(int, input().split())
    primes = get_primes(x)
    print(primes)
    res = 1
    for prime in primes:
        res = (res * (helper(prime, n) % divisor)) % divisor
    print(res)

def get_primes(x):
    primes = []
    i = 2
    limit = int(math.sqrt(x)) + 1
    while i < limit:
        if x % i == 0:
            primes.append(i)
            while x % i == 0:
                x = x / i
        else:
            i += 1
    if x > 1:
        primes.append(x)
    return primes

def helper(p, n):
    k = 1
    count = 0
    p_k = p
    # res = 1
    while n >= p_k:
        count += n // p_k
        p_k = p_k * p
        # res = res * p_k
    res = pow(p, count, divisor)
    return res

if __name__ == '__main__':
    solution()


import math
r, x, y, xn, yn = map(int,input().split(' '))
D = pow(((x-xn)*(x-xn)+(y-yn)(y-yn)),0.5)
if(D==0.0):
    print(0)
else:
    print(math.ceil(D/(2*r)))


def solve(x,y,ind):
	if x==0 and y==0 and ind!=0:
		return 0
	if ind==n:
		return -ind
	ans=0
	ans=solve(x,y,ind+1)
	if c[ind]=='L':
		ans=max(ans,1+solve(x-1,y,ind+1))
	elif c[ind]=='R':
		ans=max(ans,1+solve(x+1,y,ind+1))
	elif c[ind]=='U':
		ans=max(ans,1+solve(x,y-1,ind+1))
	else:
		ans=max(ans,1+solve(x,y+1,ind+1))
	return ans
n=int(input())
c=input()
print(solve(0,0,0))


#http://codeforces.com/contest/888/problem/B
n=int(input())
s=input()
l=r=u=d=0
for i in s:
	if i=='L':
		l++
	elif i=='R':
		r++
	elif i=='D':
		d++
	else:
		u++

ans=min(l,r)*2+min(u,d)*2
print(ans)


import sys
if sys.subversion[0] == "PyPy":
    import io, atexit
    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()

RS = raw_input
RI = lambda x=int: map(x,RS().split())
RN = lambda x=int: x(RS())
''' ...................................................................... '''

def valid(a,b,c,n):
    a,b,c = sorted([a,b,c])

    if c>n: return 0
    if (a,b,c) in memo: return 0

    if a+b<=c: return 0
    if a+c <=b: return 0
    if b+c<=a: return 0
    memo.add((a,b,c))
    return 1

n = RN()
memo = set()
ans = 0
for i in xrange(1,n+1):
    for j in xrange(1,i+1):
        k = i^j

        ans += valid(k,j,i,n)

print ans


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

balls = list(map(int, input().split()))

def conta_pares(vet, num):
    pares = []
    for i in range(n-1):
        if balls[i] == balls[i+1] == num:
            pares.append(i)
            pares.append(i+1)
    return pares

if n < 2:
	print(0)
	exit()
lista_pares = conta_pares(balls, x)

if lista_pares == []:
	print(0)
	exit()

par = False
maximo = 2
for i in range(0, len(lista_pares)-1, 2):

    il, ir = lista_pares[i], lista_pares[i+1]
    pontos = 2
    while True:

        if il>0 and ir < n-1 and balls[il-1] == balls[ir+1]:

            if il-2 >= 0 and balls[il-2] == balls[il-1]:
                pontos += 3
                il -= 2
                if ir+2 < n and balls[ir+2] == balls[ir+1]:
                    pontos += 1
                    ir += 2
            elif ir+2 < n and balls[ir+2] == balls[ir+1]:
                pontos += 3
                ir += 2
        else:
            if pontos > maximo:
                maximo = pontos
            break
print(maximo)


n, k, x = map(int, input().split())
balls = list(map(int, input().split()))
resp = 0
for c in range(n):
	s = balls.copy()
	s.insert(c, x)
	while len(s) > 2:
		l = len(s)
		for i in range(2, len(s)):
			if s[i-2] == s[i-1] == s[i]:
				p = i + 1
				while p < len(s):
					if s[i] != s[p]:
						break
					p += 1
				s = s[:i-2] + s[p:]
				break
		if len(s) == l:
			break
	resp = max(resp, n - len(s))
print(resp)
.


#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
#from fractions import *
from bisect import *
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]

#-------------------------code---------------------------#
#vsInput()

s=input()
at=s.index('at')
s=list(s)
s[at:at+2]=['@']
#print(s)

n=len(s)
for i in range(1,n):
    #print(s[i:i+3])
    if(s[i:i+3]==['d','o','t']):
        #print()
        if(i!=len(s)-3):
            s[i:i+3]=['.']
print(*s,sep="")


s=input()

gk=s.replace("at", "@")
gk=gk.replace("dot", ".")
#print(gk)
n=len(gk)
k=list(gk)
if(k[0]=='.'):
	k[0]="dot"
if(k[n-1]=='.'):
	k[n-1]="dot"
if(k[0]=='@'):
	k[0]="at"
if(k[n-1]=='@'):
	k[n-1]="at"
#s=string(k)
for x in range(len(k)):
	print(k[x],end="")
#print(k)

#//print(len(gk))


MAX = 101
NINF = -22222222222
base = [-1]*MAX
dp = [ [ base[:] for i in range(MAX)] for j in range(MAX)]
s1 = ""
s2 = ""
s3 = ""
rev_s3 = ""
l1 = ""
l2 = ""
l3 = ""

def foo(i, j, k):
	if k == l3 :
		return "", NINF
	if i == l1:
		return "", 0
	if j == l2:
		return "", 0
	if dp[i][j][k] != -1:
		return dp[i][j][k]
	ans1, len1 = foo( i + 1, j, k )
	ans2, len2 = foo( i , j + 1, k )
	len3 = NINF
	ans3 = ""
	if s1[i] == s2[j]:
		if s1[i] == s3[k]:
			if s1[i] == s3[0]:
				ans3, len3 = foo(i+1, j + 1, 1 )
			else:
				ans3, len3 = foo(i+1, j + 1, 0 )

			ans3 += s1[i]
			len3 += 1
		else:
			if s1[i] == s3[0]:
				ans3, len3 = foo(i+1, j + 1, 1 )
			else:
				ans3, len3 = foo(i+1, j + 1, 0 )
			ans3 += s1[i]
			len3 += 1

	if rev_s3 in ans1:
		len1 = NINF
	if rev_s3 in ans2:
		len2 = NINF
	if rev_s3 in ans3:
		len3 = NINF

	if len1 > len2:
		if len1 > len3:
			dp[i][j][k] = ans1, len1
		else:
			dp[i][j][k] = ans3, len3
	else:
		if len2 > len3:
			dp[i][j][k] = ans2, len2

		else:
			dp[i][j][k] = ans3, len3
	return dp[i][j][k]

s1 = raw_input()
s2 = raw_input()
s3 = raw_input()
rev_s3 = s3[::-1]
l1 = len(s1)
l2 = len(s2)
l3 = len(s3)

ans = foo(0,0,0)
if ans[1] <= 0 :
	print(0)
else:
	print(ans[0][::-1]	)


n=int(input())
m=int(input())
a=int(input())
b=int(input())
i=0
s=0
while i<=n:
	s+=b
	i+=m
	if i==n:
		print(s)
		exit(0)
i-=m
s-=b
while i<=n:
	s+=a
	i+=1
	if i==n:
		print(s)
		exit(0)


nmab = [int(x) for x in input().split()]
price = 0
if nmab[1] * nmab[3] < nmab[2]:
	while nmab[0] > 0:
		price += nmab[3]
		nmab[0] -= nmab[1]
else:
	while nmab[0] > 0:
		price += nmab[2]
		nmab[0] += 1
print(price)


k = int(raw_input())
a = [0] * 10

for i in range(4):
	s = str(raw_input())
	for si in s:
		if si == '.': a[0] += 1
		else: a[int(si)] += 1
if max(a) > 2 * k: print 'NO'
else: print 'YES'


n=int(raw_input())*2
a=[]
for i in range(4):
    tmp=(raw_input()).replace('.','')
    for x in tmp:a.append(int(x))
while len(a)-n>0:
    a=sorted(a)
    for x in range(0,n):
        del a[0]
    a=map(lambda x:x-1,a)
    if 0 in a:
        print 'NO'
        exit()
print 'YES'


import math
(x,y,l,r) = (int(i) for i in input().split())

vvrs = []

for i in range(60):
	for j in range(60):
		cur = x**i + y**j
		if cur>=10**18:
			break
		vvrs.append(cur)

maxcnt = 0
curcnt = 0
for i in range(l,r+1):
	if i not in vvrs:
		curcnt+=1
	else:
		if curcnt>maxcnt:
			maxcnt = curcnt
		curcnt = 0

print(max(maxcnt,curcnt))


from math import log,pow
import enum
x,y,l,r= [int(x) for x in input().split()]
s1 = [x for x in range(l,r+1)]
s3  = [l-1,r+1]
for b in range(60):
	for c in range(60):
		s3.append(x**b+y**c)
ans = 0
s3.sort()
for i in range(len(s3)-1):
	ans = max(ans, min(r,s3[i+1]-1)-max(l,s3[i]+1) +1)
	if s3[i]>r: break
print(ans)


#!/usr/bin/env python3

import sys
def get_ints():
    return map(int, sys.stdin.readline().strip().split())

n, m, a, b = get_ints()

# n Nombre de billets à acheter
# m Nombre de billets dans un lot
# a Prix d'un billet unitaire
# b Prix de m billets en lot

if (a <= m/b):
    prix = n*a
elif (a < b):
    prix = min(b, (n%m)*a) + int(n/m)*b

print(prix)


l1 = input()
l2 = set(input().split())
l3 = set(input().split())
l2  = [int(x) for x in l2]
l3 = [int(x) for x in l3]
l2.sort()
l3.sort()
for x in l2:
    if x in l3:
        print(x)
        done=1
        break
if not done: print(str(min(min(l2),min(l3)))+str(max(min(l2),min(l3))))


def arr_inp(n):
    if n == 1:
        return [int(x) for x in stdin.readline().split()]
    elif n == 2:
        return [float(x) for x in stdin.readline().split()]
    else:
        return [str(x) for x in stdin.readline().split()]

from sys import stdin

a, ans = sorted(arr_inp(1)), 0

for i in range(a[1]):
    ans += (a[0] + i) * 2

for i in range(a[2] - a[1] - 1):
    ans += (a[0] + a[1] - 1)

print(ans)


from sys import stdin
a,b,c=map(int,stdin.readline().split())
print(2*(a+b+c))


n, m = input()
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
min_a = min(a)
min_b = min(b)
if min_a == min_b:
    print(min_a)
else:
    print(str(min(min_a, min_b))+str(max(min_a, min_b)))


n=int(input())
l=list(map(int,input().split()))
if x[0]==1:
    maxim=0
else:
    maxim=1
for i in range(n):
    for j in range(i+1,n):
        maxim=max(maxim,l[:i].count(1)+l[j+1:].count(1)+l[i:j+1].count(0))
print(maxim)


n=int(input())
list1=input()
sum1=list1.count('1')
list1=list1.split()
for a in range(1,n+1):
    for i in range(n):
      list2=list1[i:a+i]
      suma=sum1-int(list2.count('1'))+int(list2.count('0'))
      ans=max(sum1,suma,ans)
print(ans)


n=int(raw_input())
a=map(int,raw_input().split())
k=[0 for i in xrange(10**9+1)]
d={}
for i in a:
    if str(i) not in d:
        d[str(i)]=1
    else:
        d[str(i)]+=1

    k[i]+=1
#print k,d
c=0
for j in set(a):
    #print "j",j
    if d[str(j)]==1:
        c=c+int(j)
    else:
        c=c+int(j)
        d[str(j)]-=1
        p=int(j)-1
        while d[str(j)]!=0:
            #print d,d[str(j)]
            if k[p]==0:
                #print"p",p
                c=c+p
                d[str(j)]-=1
                #d[str(p-1)]=1
                k[p]=1
                #print k
            else:
                p-=1

print c


n=raw_input()
l=raw_input().split()
l2=[]
for i in l:
    l2.append(int(i))
l2=sorted(l2)
su=0
s=set()
for i in l2[::-1]:
    q=True
    for j in xrange(i, 0, -1):
        if q and (not j in s):
            su+=j
            s.add(j)
            q=False
print su


n = int(input())
a = list(map(int, input().split()))
for i in range(n - 2, -1, -1):
    a[i] = max(min(a[i], a[i + 1] - 1), 0)
print(sum(a))


n = int(input())
balls = list(map(int,input().split()))
balls.sort()

def answer(balls):
    for i in range(n-2):
        if balls[i+2] == balls[i+1] + 1 == balls[i] + 2:
            return "YES"
    return "NO"

print(answer(balls))


__author__ = 'zhan'

print("black" if input()&1 else "white\n1 2")


n = input()
if n % 2 == 1:
    print("black")
else:
    print("white")
    print("1 2")


n = int(input())
count = 0

for k in range(3, n+1):
    for i in range(k//2+1, k):
        for j in range(k-i+1, i):
            if not k^i^j: count+=1

print(count)


import time,os
a=0:b=0
print (sum(0 < (i ^ j) <= j <= i and (i ^ j) + j > i for i in range(1, int(input()) + 1) for j in range(1, i + 1)))


n=int(input())
k=0
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if i^j<=n and i^j<i+j and i^j>j-i:
            k+=1
print(k//3)


n=int(input())
s=input()
u,r,d,l,count=0,0,0,0,0
for i in range(n):
    for j in range(i,n):
        if s[j]=='U':
            u+=1
        elif s[j]=='D':
            d+=1
        elif s[j]=='L':
            l+=1
        else:
            r+=1
        if u==d and l==r:
            count+=1
print(count)


a=[0,0]
def ok(x,a):
	if x=='L':
		a[0]-=1
	elif x=='R':
		a[0]+=1
	elif x=='U':
		a[1]+=1
	elif x=='D':
		a[1]-=1
g=int(input())
s=input()
j=0
for i in range(len(s)):
	a=[0,0]
	for z in range(i,len(s)):
		ok(s[z],a)
		if a==[0,0]:
			j+=1
			break
print(j)


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

x=0
y=0
ans=0

for i in range(n):
 if s[i]=="U":
  y+=1
 elif s[i]=="D":
  y-=1
 elif s[i]=="L":
  x-=1
 elif s[i]=="R":
  x+=1
 else:
  pass
if x==0 and y==0:
 ans+=1
else:
 pass

x=0
y=0

for j in range(n):
 for k in range(n):
  ss=s[j:k+1]
  for l in range(len(ss)):
   if s[l]=="U":
    y+=1
   elif s[l]=="D":
    y-=1
   elif s[l]=="L":
    x-=1
   elif s[l]=="R":
    x+=1
   else:
    pass
  if x==0 and y==0 and len(ss)>1:
   ans+=1
  else:
   pass
  x=0
  y=0

print(ans)


def get_input():
    num = input()
    line = input()
    test_cases = line.split()
    result = []
    for i in test_cases:
        result.append(int(i))
    return result

def send_balls(n,l):
    l = sorted(l)
    l2 = l.copy();
    for x in range(0,n-2):
        if l[x]==l[x+1]:
            l2.remove(l[x+1])
    else:
        for i in range(0,len(l2)-2):
            if l2[i+1]-l[i]<2 and l2[i+2]-l[i+1]<2 and l2[i+1]!=l[i] and l2[i+2]!=l[i+1]:
                return "YES";
    return "NO";

test_cases = get_input()
print(send_balls(len(test_cases),test_cases))


a,b,c=[int(x) for x in input().split()]
a1 = list(map(int,input().strip().split()))[:a]
b1 = list(map(int,input().strip().split()))[:b]
c1=max(a1)
c2=min(a1)
c3=max(b1)
s=c1*c2
k=c3*c3
z=0
if(s<=k):
    z = c + k-s
else:
    z=c+0;
print(z)


datos =input()
d = datos.split()

n = int(d[0])
m= int(d[1])
r = int(d[2])

s = input()
s1 = s.split()
sf = sorted(s1)

b = input()
b1 = b.split()
bf = sorted(b1)

C = int(sf[0])  #Valor Menor Compra
V = int(bf[-1]) #Valor Mayor Venta

if C < V:
    I = r// C
    Rinv = r - (C*I)
    G = I*V
    rf = G + Rinv
    print(rf)

else:
    print(r)


n, m, r = map(int, input().split())
s = [int(c) for c in input() if c != ' ']
b = [int(c) for c in input() if c != ' ']

if min (s) > max(b):
    print(r)
h = r - r // min(s) * min(s)
print(r // min(s) * max(b) + h)


# cook your dish here
n=int(input())
a=list(map(int,input().rstrip().split()))
tillnoq=0
count1=0
count0=0
if n==1 and a[i]==1:
    print(1)
else:
    for i in range (n):
        for j in range (i,n):
            if a[j]==1:
                count1+=1
            else:
                count0+=1
        #print(count0,count1,i,j)
            numzeroabs=count0-count1
            if numzeroabs>tillnoq:
                left=i
                right=j
                tillnoq=numzeroabs
        #print(numzeroabs)
        count0=0
        count1=0
    cntr=0
    for i in range (left):
        if a[i]==1:
            cntr+=1
    for i in range (right,n):
        if a[i]==1:
            cntr+=1

    print(cntr+tillnoq)


s = raw_input()
for i in s:
	if i=='h':
		f = 1
	if f==1 and i=='e':
		f=2
	if f==2 and i=='l':
		f=3
	elif f==3 and i=='l':
		f = 4
	if f==4 and i=='o':
		f=5
if f==5:
	print("YES")
else:
	print"NO"


#codeforces_1140D_live
gi = lambda : list(map(int,input().strip().split()))
n, = gi()
ans = 0
x = 1
step = 1
while 1:
	x = 1
	while x + 2*step <= n + 1:
		if x + 2*step == n+1:
			ans += x*(x+step)
		else:
			ans += x*(x+step)*(x+2*step)
		x += 2*step
	step += 1
	if step >= n//2:
		break;
print(ans)


n=int(input()
su =0
for i in range(2,n-1)
    su=su+(i)*(i+1
print(su)


//f = open('Text.txt',"r")
n = int(f.read())
res = 0

for x in range(3, n+1):
    res += 1*(x-1)*(x)

print(res)


def main():
	x = int(input())
	ans = 0
	for i in range(2, x):
		ans += i*(i+1)
	print ans

if __name__ == '__main__':
	main()


n=int(input())
i=2
j=3
sum=0
while(j<=n):
    sum+=(i*j)
print(sum)


n = int(input())

def cost(i, j, k):
    return i * j* k

def min_tri(i, j, n):
    if j < i + 2:
        return 0

    res = n * (n + 1) *(n + 2) + 1

    for k in range(i + 1, j):
        res = min(res, (min_tri(i, k, n) + min_tri(k, j, n) + cost(i, k, j)))

    return res

print(min_tri(1, n, n))


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

print 2*(a+b+c)


def middle(a, b, c) :
    x = a - b
    y = b - c
    z = a - c
    if x * y > 0:
        return b
    elif (x * z > 0) :
        return
    else :
        return a
a,b,c=map(int,raw_input().split())
first=min(a,b,c)
third=max(a,b,c)
second=middle(a,b,c)
ans=0
while(first>0):
	# print first,second,third
	ans=ans+(first+(second-1)+(third-2))*2
	second=second-1
	third=third-1
	first=first-1
print ans


#Ya Hassan Mojtaba
n=int(input())
if(n>=1)
    print(int(3**(n-1)%1000003))
else
    print(1)


def findSame(a):
    notFound = True
    res = 0
    for i in range(1, len(a)):
        curA = a[0:i]
        if notFound:
            if a[i] in curA:
                notFound = False;
                res = i
    return res

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

modif = ai
inx = 1
while inx != 0:
    inx = findSame(modif)
    if inx > 0 and modif[inx] > 0:
        modif[inx] -= 1

print(sum(modif))


import math

def solve():
    n = int(input())
    print(math.ceil(n / 2), end = " ")
    if n % 2 != 0:
        print(math.floor(n / 2), end = "")
    print()

t = 1
# t = int(input())
while t--:
    solve()


n=int(input())
if n==1:
    print(1)
    exit()
if n==2:
    print(2)
    exit()
if n%2==0:
    print(n//2)
else:
    print(n-1,n-(n-1))


import sys
import math
import bisect

def main():
    n = int(input())
    A = []
    for i in range(n):
        val = 1
        while len(A) and A[-1] == val:
            A.pop()
            val <<= 1
        A.append(val)
    print(' '.join(list(str(a) for a in A)))

if __name__ == "__main__":
    main()


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

n,k = R()

a = R()
b = R()

b.sort()
k=0
for i in xrange(len(a)):
    if a[i]==0:
	a[i]=b[k]
	k += 1

#print a

s = True
for i in xrange(len(a)):
    prev,nxt = True,True
    if i>0: prev = a[i-1]<a[i]
    if i<len(a)-1: nxt = a[i+1]>a[i]
    s = prev and nxt
    if not s:
	break

if s:
    if k>1:
	print "Yes"
    else:
	print "No"
else:
    print "Yes"


a,b,c,d=map(int,input().split())
x,y=map(int,input().split())
if abs(a-c)%x==0 and abs(b-d)%y==0 (abs((a-c)//x)-abs((b-d)//y))%2==0:
    print("YES")
else:
    print("NO")


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

print(['NO', 'YES'][int(a%x == c%x and b%y == d%y)])


import sys

_gcd = lambda s, m, n : m if n==0 else s(s, n, m % n)
gcd = lambda m, n : _gcd(_gcd, m, n)
lcm = lambda m, n : m // gcd(m, n) * n

def gcd(m, n): m if n==0 else gcd(n, m%n)
def lcm(m, n): m // gcd(m,n) * n

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

z = lcm(x, y)

print(b//z-(a-1)//z)


def lcm(a,b):
    for i in range(b,b*b):
        if(i%a==0 and i%b==0):
            return i

a,b,c,d=map(int,input().split())
e=lcm(a,b)
if(a==1 and b==1):
    print(d-c+1)
else:
    value=((d)//e) -((c-1)//e)
    print(value)


Fact=[]
L=[]

def initFact():
    Fact.append(1)
    for i in xrange(1, 10):
        Fact.append(Fact[i-1]*i)

def parse(L, res):
    ret=0;
    for i in L:
        ret*=10
        ret+=i
    if res[0]<ret:
        res[0]=ret

def search(curr, target, res):
    if curr==target:
        parse(L, res)
        return
    i=9
    while i>=2:
        if curr*Fact[int(i)]<=target:
            L.append(i)
            search(curr*Fact[int(i)], target, res)
            L.pop()
        i-=1

n=raw_input()
s=str(raw_input())
initFact()
target=1
for c in s:
    target*=Fact[int(c)]
res=[0]
search(1, target, res)
print res[0]


ans = 0
fact = {}
ans = 0
originalVal = 1

# (originalVal,0,1)
def recurse(cur,ansSoFar,valueSoFar):
	# print cur,ansSoFar,valueSoFar
	global ans
	global originalVal
	if valueSoFar > originalVal:
		return
	if valueSoFar == originalVal:
		ans = max(ans,ansSoFar)
		return
	else :
		for x in xrange(2,10):
			if cur % fact[x] == 0:
				recurse(cur/fact[x],ansSoFar*10 + x,valueSoFar*fact[x])
		return

fact[1] = 1
fact[0] = 1
for x in xrange(2,10):
	fact[x] = fact[x-1]*x
n = raw_input()
digitString = raw_input()
digits = list(digitString)
for x in digits:
	curDigit = int(x)
	originalVal = originalVal*fact[curDigit]
recurse(originalVal,0,1)
print ans


import math

hsh = {1 : 1, 2 : 2, 3 : 6, 4 : 24, 5 : 120, 6 : 720, 7 : 5040, 8 : 40320, 9 : 362880, 0 : 1}

ls = []

def fn(val):
	global ls
	if val == 1:
		return True
	for i in range(2, 10):
		if val % hsh[i] == 0 and fn(val / hsh[i]):
			ls = ls + [i]
			return True
	return False

if __name__ == '__main__':

	t = input()
	a = [int(x) for x in raw_input()]
	ans = 1
	for i in a:
		ans = (hsh[i] * ans)
	fn(ans)
	ls.sort(reverse=True)
	st = ""
	for i in ls:
		st=st+str(i)
	print st


n,m,capacity = [int(x) for x in raw_input().split()]

class Planet:
    def __init__(self):
        self.a = []
        self.b = []
        self.c = []
        self.n = ""
    def __repr__(self):
        return "%s: a:%r, b:%r, c:%r" % (self.n, self.a, self.b,self.c)

def calc_profit(p1, p2):
    #print "%s -> %s" % (p1.n, p2.n)
    profits = []
    for j in range(m):
        if p1.c[j] == 0:
            continue
        profit = p2.b[j] - p1.a[j]
        if profit > 0:
            profits.append((profit, p1.c[j]))
    profits.sort(reverse=True)
    load = 0
    total_profit = 0
    for p in profits:
        if load + p[1] > capacity:
            c = capacity - load
        else:
            c = p[1]
        total_profit += p[0]*c
        load += c
        if c != p[1]:
            break
    #print "profit: %d" % total_profit
    return total_profit

ps = []

for i in range(n):
    p = Planet()
    p.n = raw_input()
    for j in range(n):
        a,b,c = [int(x) for x in raw_input().split()]
        p.a.append(a)
        p.b.append(b)
        p.c.append(c)
    ps.append(p)

max_profit = -1

for n1 in range(n):
    for n2 in range(n):
        if n1 != n2:
            profit = calc_profit(ps[n1], ps[n2])
            max_profit = max(max_profit, profit)

print max_profit


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

planet = []

for i in xrange(n):
    nome = raw_input()
    op = []
    for j in xrange(m):

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

        op.append([a, b, c])

    planet.append(op)

maximo = 0

for i in xrange(n):
    for j in xrange(n):
        if i != j:
            pft = []
            for k in xrange(m):
                luc = planet[j][k][1] - planet[i][k][0]
                pft.append([luc, planet[i][k][2]])

            pft.sort(reverse=True, key=lambda tup:tup[0])

            qtd = 0
            ganho = 0
            for r in xrange(len(pft)):
                if qtd + pft[r][1] < l:
                    ganho += pft[r][0]*pft[r][1]
                    qtd += pft[r][1]
                else:
                    ganho += pft[r][0]*(l-qtd)
                    break

            if ganho > maximo:
                maximo = ganho

print maximo


n = input()
a = input()
if a[0]%2 == 0 or a[-1]%2 == 0:
    print 'No'
elif n%2 != 0:
    print 'Yes'
else:
    print 'No'


a=input().split()
a[0]=int(a[0])
a[1]=int(a[1])
s=input()
c=set(s)
k=0
for i in c:
   e=s.coint(i)
   c.get(i,e)
        continue
for j in c:
    k+=j.values()
if k%a[1]==0:
    print('Yes')
else:
    print('NO')


s,k=input().split()
s=list(s)
k=int(k)
n=len(s)
for i in range(n):
    maxi=s[i]
    maxj=0
    for j in range(i+1,n):
        if s[j]>maxi:
            maxi=s[j]
            maxj=j
    while maxj>i:
        s[maxj],s[maxj-1]=s[maxj-1],s[maxj]
        maxj-=1
print(''.join(s))


from math import sqrt
n=int(input())
if n%2==0:
	print("NO")
	exit()
mi=10000000000
n-=1
b=0
for i in range(1,int(sqrt(n))):
	if n%i==0:
		y=(n-i-i**2)/(2*i)
		if y==int(y):
			if i<mi:
				mi=i
				b=int(y)
if mi==10000000000:
    print("NO")
	exit()
print(mi,b)


 def dig(a):
    count = 0;
    while (a > 0):
        a /= 10
        count+=1
    return count

def required_number(num, n, d):
    flag = 0
    power=0
    a=0
    for i in range(num,0,-1):
        power = pow(10, i)
        a = n % power

        if (d > a):
            flag = 1
            break
    if(flag):

        for j in range(0,i):
            t += 9 * pow(10, j)

        if(n % power ==t):
            print(n,end="")
        else:
            print((n - (n % power) - 1),end="")
    else:
        print(n,end="")
# Driver Code
n,d = map(int,input().split())

num = dig(n)
required_number(num, n, d)
print(required_number)


p,d=map(int,input().split())
p+=1
ans=p
i=10
while True:
    if p%i<=d:
        ans=p-p%i
    i*=10
print(ans-1)


p, d = map(int, input().split())
p = str(p)

i = len(p)-1
while True:
    if int(p[i:])-1 <= d:
        d -= int(p[i:])-1
        p = str(int(p)-int(p[i:])-1)
        i -= 1
    else:
        break

print(p)


# -*- coding: utf-8 -*-
"""
Created on Thu Sep 21 20:36:12 2017

@author: MetaMemeLord-
"""

n = input()
i = len(n)-1
while i>0:
    if n[i] == '0':
        del n[i]
for i in range(len(n)//2):
    if(n[i]!=n[n-i-1])
        print('NO')
    else:
        print('YES')


p = input()
if p == p[::-1] or len(p) == 1:
    print("YES")
else:
    if p[0] != p[len(p) - 1] and '0' not in [p[0], p[len(p) - 1]]:
        print("NO")
    else:
        cl, cr = '', ''
        for i in p:
            if i == '0':
                cl+='0'
            else:
                break
        for i in p[::-1]:
            if i == '0':
                cr+='0'
            else:
                break
        if cl == cr and p != p[::-1]:
            print("NO)
        else:
            if len(cl) > len(cr):
                p += ('0' * (len(cl) - len(cr)))
                if p == p[::-1]:
                    print("YES")
                else:
                    print("NO")
            else:
                p = ('0' * (len(cr) - len(cl))) + p
                if p == p[::-1]:
                    print("YES")
                else:
                    print("NO")


s = input()
    print( "YES" if s == s[::-1] else "NO")


n=int(input())
ans=0
for a in range(1,n):
    for b in range(a ,n):
        for c in range(b,min(a+b,n+1)):
            if a^b^c==0:
                ans+=1
print(ans)


n=int(input())
s=input()
if(s.count('FS')< s.count('SF'):
    print("YES")
else:
    print("NO")


n, m, c, d = map(int, input().split())
t = [(d / c, 1000, 1, c, d)] + [0] * m
for i in range(1, m + 1):
    a, b, c, d = map(int, input().split())
    t[i] = (d / c, a, b, c, d)
t.sort(reverse = True)
i = p = 0
while i < m + 1:
    u, a, b, c, d = t[i]
    i += 1
    if n < c: continue
    k = a // b
    p += d * k
    n -= c * k
    if n < 0:
        k = (- 1 - s) // c + 1
        n += c * k
        p -= d * k
print(p)


n, m, c, d = map(int, input().split())
t = [(d / c, 1000, 1, c, d)] + [0] * m
for i in range(1, m + 1):
    a, b, c, d = map(int, input().split())
    t[i] = (d / c, a, b, c, d)
t.sort(reverse = True)
i = p = 0
while i < m + 1:
    u, a, b, c, d = t[i]
    i += 1
    if n < c: continue
    k = a // b
    p += d * k
    n -= c * k
    if n < 0:
        k = (- 1 - n) // c + 1
        n += c * k
        p -= d * k
print(p)


str = raw_input()
arr = [int(s) for s in str.split(' ')]
pir = range(arr[1])
ans = range(arr[0]+1)
for i in range(0, arr[1]):
   str = raw_input()
   pir[i] = [int(s) for s in str.split(' ')]
for i in range (0, arr[0]+1):
    ans[i] = (i / arr[2])*arr[3]

for j in range(0, arr[1]):
 am = pir[j][0]/pir[j][1]
 for i in range(arr[0],-1, -1):
   if i / pir[j][2] < am:
      am = i / pir[j][2]
   k = am * pir[j][2]
   if ans[i] < ans[i-k]+am*pir[j][3]:
      ans[i] = ans[i-k]+am*pir[j][3]
print ans[arr[0]]


n, m, c, d = map(int, raw_input().split())
arr = [0] * 50
for i in range(c, n + 1):
    arr[i] = arr[i - c] + d

for l in range(0, m):
    a, b, c, d = map(int, raw_input().split())
    for i in range(0, a/b):
        j = n
        while(j >= c):
            arr[j] = max(arr[j], arr[j - c] + d)
            j -= 1
print arr[n]


a,b,c=map(int,input().split())
x=c//a
s=2*c
for _ in range(x):
    s+=(c+1)
print(s)


q=input().split()
a=int(q[0])
b=int(q[1])
c=int(q[2])
print((a+c)*b)


n = int(input())
print(pow(3,n)-1,pow(10,6)+3) if n > 0 else 0)


def powmod(a,b,m):
    r = 1
    while(b):
        if b&1:
            r = (r*a)%m
        a = (a*a)%m
        b //= 2

    return r%m

a = int(input())
print(powmod(3,a-1,1000003))


class Node:
    def __init__(self,string,count):
        self.string = string
        self.count = count

n = int(input())
string = input()
queue = [Node(string,0)]
max = 0
while queue != []:
    node = queue.pop(0)
    if node.count > max:
        max = node.count
    string = list(node.string)
    if len(string) > 1:
        for i in range(len(string)):
            if i > 0 and i < len(string)-1:
                if ord(string[i]) == ord(string[i+1])+1 or ord(string[i]) == ord(string[i-1])+1:
                    temp1 = string[:i]
                    temp2 = string[i+1:]
                    queue.append(Node(''.join(temp1)+''.join(temp2),node.count+1))
            elif i == 0:
                if ord(string[i]) == ord(string[i+1])+1:
                    temp1 = string[:i]
                    temp2 = string[i+1:]
                    queue.append(Node(''.join(temp1)+''.join(temp2),node.count+1))
            else:
                if ord(string[i]) == ord(string[i-1])+1:
                    temp1 = string[:i]
                    temp2 = string[i+1:]
                    queue.append(Node(''.join(temp1)+''.join(temp2),node.count+1))

print(max)


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

for i in range(25):
    ch = chr(ord('z') - i)
	prev = chr(ord(ch) - 1)
    j = 0
	while j < len(s):
    	if s[j] == ch and (j-1 >= 0 and s[j-1] == prev or j+1 < len(s) and s[j+1] == prev):
    		s = s[:j] + s[(j+1):]
			j = 0
    	else:
    		j+=1

print(n-len(s))


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


# -*- coding: utf-8 -*-
"""
Created on Mon Jun 18 10:23:17 2018

@author: ThinhDo
"""

def myprod(mylist):
    result = 1
    for i in range(len(mylist)):
        result *= mylist[i]
    return result

from itertools import combinations

from itertools import compress

def rwh_primes1v1(n):
    """ Returns  a list of primes < n for n > 2 """
    sieve = bytearray([True]) * (n//2)
    for i in range(3,int(n**0.5)+1,2):
        if sieve[i//2]:
            sieve[i*i//2::i] = bytearray((n-i*i-1)//(2*i)+1)
    return [2,*compress(range(3,n,2), sieve[1:])]

mylist = list(map(int,input().split(" ")))
[l,r,x,y] = mylist
#print(l,r,x,y)

if y % x == 0:
    myvalue = int(y/x)
    result = []

    primes_list = rwh_primes1v1(myvalue)
    myidx = 0

    value = primes_list[myidx]
    current = 1
    while value <= myvalue:
        if myvalue % value == 0:
            myvalue = int(myvalue/value)
            current *= value
        else:
            if current != 1:
                result.append(current)
            myidx += 1
            value = primes_list[myidx]
            if value > myvalue:
                value = myvalue
            current = 1

    result.append(current)
    #print(result)

    mylist = []
    for myr in range(1,len(result)+1):
        mylist += list(combinations(result,myr))

    #print(mylist)

    lb = int(l/x)
    ub = int(r/x)

    count = 0

#    print('x',x)
#    print('l',l)
#    print('r',r)
#    print('lb',lb)
#    print('ub',ub)
#    if (lb <= 1 <= ub):
#        print('hahaha')
#    else:
#        print('nooo')
#
#    print('myprod(result)',myprod(result))
#    if (lb <= myprod(result) <= ub):
#        print('haaaaa')
#    else:
#        print('no')

    if (lb <= 1 <= ub) and (lb <= myprod(result) <= ub):
        #print('aaaa')
        count += 1
    #else:
    #    print('bbb')

    #print(1,myprod(result))
    for i in range(len(mylist)):
        #print(myprod(mylist[i]),int(myprod(result)/myprod(mylist[i])))
        if (lb <= myprod(mylist[i]) <= ub) and (lb <= int(myprod(result)/myprod(mylist[i])) <= ub):
            count += 1

    print(count)

else:
    print(0)


def gcd(a, b):
    if b > a:
        c = a
        a = b
        b = c
    while b != 0:
        c = a
        a = b
        b = c % b
    return a

import math
l, r, x, y = map(int, input().split())
c = 0
for i in range(l, int(math.sqrt(x * y)) + 1):
    if (x * y) % i == 0 and x * y // i <= r and (x * y // i) % i != 0 and gcd(i, x * y // i) == abs(1):
        c += 1
if l == 1 and r >= x * y :
    c += 1
print(2 * c)


from math import gcd, factorial

A, B = map(int, input().split())
print(gcd(factorial(A), factorial(B)))


import math
a,b=map(int,input().split())
A=math.factorial(a)
B=math.factorial(b)
print(math.gcd(A,B))


## necessary imports
import sys
input = sys.stdin.readline
from math import log2, log, ceil

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp

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

## nCr function efficient using Binomial Cofficient
def nCr(n, k):
    if(k > n - k):
        k = n - k
    res = 1
    for i in range(k):
        res = res * (n - i)
        res = res / (i + 1)
    return res

## upper bound function code -- such that e in a[:i] e < x;
def upper_bound(a, x, lo=0):
    hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if a[mid] < x:
            lo = mid+1
        else:
            hi = mid
    return lo

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
    res = 1
    x = x % p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) :
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b

# find function
def find(x, link):
    while(x != link[x]):
        x = link[x]
    return x

# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
    prime = [True for i in range(n+1)]
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e6 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
# spf = [0 for i in range(MAXN)]
# spf_sieve()
def factoriazation(x):
    ret = {};
    while x != 1:
        ret[spf[x]] = ret.get(spf[x], 0) + 1;
        x = x//spf[x]
    return ret
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()))
## taking string array input
def str_array():
    return input().strip().split();

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

n = int(input()); string = input().strip(); ans = '';
num = 1;
for i in string:
    if int(i) > 1:
        for j in range(int(i), 1, -1):
            num *= j
while(num > 1):
    while(num % 5040 == 0):
        ans += '7'; num //=5760;
    while(num % 120 == 0):
        ans += '5'; num //= 120;
    while(num % 6 == 0):
        ans += '3'; num //= 6;
    while(num %  2 == 0):
        ans += '2'; num //= 2;
print(ans);


#import sympy as sp
#import time as t
import math
import numpy as np

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

def pfactors(x):
    prime_factors=[]
    if(x&1==0):
        prime_factors.append(2)
        while(x&1==0):
            x=x>>1

    i=3
    limit= math.sqrt(x)

    while(i<=limit):
        if(x%i==0):
            prime_factors.append(i)
            x=x//i
            while(x%i==0):
                x=x//i
        i+=2

    if(x>2):
        prime_factors.append(x)
    return prime_factors

pfacts= pfactors(x)
res=1
l=len(pfacts)
M=10**9+7

for p in pfacts:
    k=math.floor(math.log(n,p))
    h=0
    for i in range(1,k+1):
        h = h + n//pow(p,i)

    g = pow(p,h,M)
    res = (res*g)%M

print(res)


x,y,a,b=map(int,raw_input().split(' '))
m=[]
n=[]
for i in range(b+1):
    if i*x>=a and i*x<=b:
        m.append(i*x)
    elif i*x>b:
        break
for i in range(b+1):
    if i*y>=a and i*y<=b:
        n.append(i*y)
    elif i*y>b:
        break

print len(set(m).intersection(set(n)))


a, b, c = map(int, raw_input().split())
for i in reversed(range(1,a+1)):
	if 2 * i <= b and 4 * i <= c:
		print 7 * i
		exit(0)
print 0


import itertools as it
import math as m

def move(start,moves):
    pos=start
    for m in moves:
        x,y=pos
        if m=='U':
            pos=(x,y+1)
        if m=='D':
            pos=(x,y-1)
        if m=='L':
            pos=(x-1,y)
        if m=='R':
            pos=(x+1,y)
    return pos

def choose_iter(elements, length):
    for i in xrange(len(elements)):
        if length == 1:
            yield (elements[i],)
        else:
            for next in choose_iter(elements[i+1:len(elements)], length-1):
                yield (elements[i],) + next
def choose(l, k):
    return list(choose_iter(l, k))

n=int(raw_input())

data=raw_input()

#n=6
#data="LLRRRR"

dp={}
mx=0
stop=False
for i in range(len(data),0,-1):
    for v in choose(data,i):
        if move((0,0),v)==(0,0):
            mx=i
            stop=True
            break
    if stop:
        break
print mx


s=input()
ss="h"
l=[]
s=s.lower()
h=s.count("h")
ii=s.index('h')
for i in range(h):
    l.append(s[ii::])
    if i<h-1:
        ii=s[ii+1::].index('h')+len(s)-len(s[ii+1::])
c=['e','l','l','o']
count=0
for j in l:
    for k in j:
        if k==c[count]:
            ss+=k
            if ss=="hello":
                break
            if count<3:
                count+=1
    count=0
    if ss =="hello":
         print("YES")
         break
    else:
         ss="h"
else:
    print("NO")


word=input().strip()
l='hello'
c=0
for i in range(len(word)):
    if l[i]==word[i]:
        c=c+1

if c==5:
    print('YES')
else:
    print('NO')


lenListas = raw_input().split
x, y = lenListas
l1 = raw_input().split(' ')
l2 = raw_input().split(' ')
m1 = 9
m2 = 9
for e in l1:
    if m1 > int(e):
        m1 = int(e)
for e in l2:
    if m2 > int(e):
        m2 = int(e)
if x == '1' and y != 1:
    print m1
elif y == '1' and x != 1:
    print m1
elif m1 == m2:
    print m1
elif m1 < m2:
    print (m1 * 10) + m2
elif m2 < m1:
    print (m2 * 10) + m1


tab = list(map(int , input().split()))
tab.sort()
print((tab[1] - tab[0]) + (tab[2] - tab[1]


x = [int(n) for n in input().split()]
total_drinks = x[1] * x[2]
total_limes = x[3] * x[4]
salt = x[5]
drinks_per_shot = x[6] * x[0]
salt_per_shot = x[7] * x[0]
print(min([drinks_per_shot//total_drinks,salt,salt_per_shot//total_limes])


from math import log, trunc
x, n = map(int, input().split())
d = {}
i = 2
while x != 1:
    if x % i == 0:
        d[i] = 0
        while x % i == 0:
            d[i] += 1
            x //= i
    i += 1
r = {}
p = 1
for key in d.keys():
    i = 1
    temp = key
    while temp <= n:
        if r.get(key):
            r[key] += n // temp
        else:
            r[key] = n // temp
        temp *= key
    p *= pow(key, r[key], 10 ** 9 + 7)
    p %= 1000000007
print(p)


import sys
import math
def primeFactors(n):
        while n % 2 == 0:
            n = n / 2
            l.add(2)
        for i in range(3,int(math.sqrt(n))+1,2):
            while n % i== 0:
                count+=1
                n = n / i
                l.add(int(i))
        if n > 2:
            l.add(int(n))
        return(l)
l=set()
input=sys.stdin.readline
x,n=map(int,input().split())
prima=primeFactors(x)
mod=10**9+7
res=1
for i in prima:
        h=0
        b=i
        while b <= n:
            h+=n//b
            b*=i
        res=(res*pow(i,h,mod))%mod
print(res)


x, n = map(int, input().split())
p = 2
ans = 1
while x > 1:
    if x % p:
        p += 1
        if p ** 2 > x:
            p = x
    else:
        n1 = n
        while n1:
            n1 //= p
            ans = (ans * pow(p, n1, MOD)) % MOD
        while not x % p:
            x //= p
print(ans)


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

def primes(x):
    res = set()
    p = 2
    while p*p <= x:
        while x % p == 0:
            res.add(p)
            x //= p
        p += 1
    if x != 1:
        res.add(x)
    return res

MOD = 10**9+7

def prod_f(prime_lst, n):
    res = 1
    for p in prime_lst:
        pw = 0
        i = 1
        while pw**i <= n:
            pw += n // pw**i
            i += 1
        res *= pow(p, pw, MOD)
        res %= MOD
    return res

print(prod_f(list(primes(x)), n))


n = int(input())
x = int(input())
for i in range(n, 0, -1):
    if i % 2 == 0:
        if x == 1 or x == 2:
            x = 3 - x
    else:
        if x == 0 or x == 1:
            x = 1 - x
print(x)


n = input()
n = 2**n/2
count = 0
while 2 != n :
    count = count + n*2
    count = count + n/4
    n = n / 2
print count


def IKNOWRECURSION(n):
    if n > 1: return 3*IKNOWRECURSION(n-1)
    else: return 1

n = int(raw_input())

print IKNOWRECURSION(n)


from math import log, ceil

def f(n,m):
##    if n == 1 or m == 1:
##        if n == 1 and m != 1:
##            a = 0
##            b = ceil(log(m-1,x))
##            c = 0
##            d = ceil(log(m-1,y))
##        elif n != 1 and m == 1:
##            a = int(log(n-1,x))
##            b = 0
##            c = int(log(n-1,y))
##            d = 0
##        else:
##            a,b,c,d = 0,0,0,0
##    else:
##        a = int(log(n-1,x))
##        b = ceil(log(m-1,x))
##        c = int(log(n-1,y))
##        d = ceil(log(m-1,y))
##    print(a,b,c,d)
    res = []
    for i in range(0,60):
        for h in range(0,60):
            res.append(x**i+y**h)
    return res

x,y,l,r = map(int, input().split(' '))
unhappy = f(l,r)
count = 0
res = 0
for i in range(l,r+1):
    if i in unhappy:
        count = 0
    else:
        count += 1
    if res < count:
        res = count
print(res)


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

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

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

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

i=0
a=list()

for i in range(200):
    for j in range(200):
        a.append(x**i+y**j)

a.sort()

m=0

for i in range(len(a)-1):
    if a[i]<=r:
        m=max(m,min(r,a[i+1]-1)-max(a[i]+1,l)+1)

print(m)

'''

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

s=sum(a)

m=int(input())
ss=10**10;

for i in range(m):
    l,r=map(int,input().split())

    if r<s:
        continue

    ss=min(ss,max(s,l))

if ss==10**10:
    print(-1)
else:
    print(ss)

'''


def solutionA(s, x):
    a = 1
    b = s-1
    counter = 0
    while a < s:
        xor = a^b
        #print('a:%s  b:%s  xor:%s  x:%s'%(a,b,xor,x))
        if xor == x:
            counter += 1
        a += 1
        b -= 1

    return counter

if __name__ == '__main__':
    a,b = (6,0)
    a,b = input().split()
    print(solutionA(int(a),int(b)))


s,x=map(int,input().split())
count=0
for k in range(1,s//2+1):
    if(k^(s-k)==x):
        if(k==s-k):
            count+=1
        else:
            count+=2
print(count)


def main():
    from itertools import product
    s, x = map(int, input().split())
    res = 0
    for astr in product(('0', '1'), repeat=s.bit_length()):
        a = int(''.join(astr), 2)
        b = s - a
        if b > 0 < a and a ^ b == x:
            res += 1
    print(res)

if __name__ == '__main__':
    main()


print (lambda s, x:
  2 ** (sum(1 for i in bin(x) if i == '1'))
  - (0 if [1 for i in bin(x)[2:] if i == '0'] else 2)
  if ((s - x) / 2) & x == 0 and (s ^ x) & 1 == 0 else 0) \
(*map(int, raw_input().split(" ")))


# coding: utf-8

i = raw_input().split(" ")
m = long(i[0])
p = long(i[1])
x = p
dif = m-x
if (dif%2==1):
	print(0)
else:
	dif = dif/2
	s = ""
	while (dif != 0):
		if (dif%2==1):
			dif -= 1
			s += "1"
		else:
			s += "0"
		dif /= 2
	ind = 0
	st = ""
	n = long(1)
	th = True
	while (x != 0):
		if (x%2==1):
			x -= 1
			st += "1"
			n = long(n*long(2))
		else:
			st += "0"
		x /= 2
		if (ind < len(s) and s[ind] == "1" and "1" == st[ind]):
			th = False
			break
		ind += 1
	if (th):
		if (m == p):
			print(long(n-2))
		else:
			print(long(n))
	else:
		print(0)


s = raw_input()

sum = 1
mulA=10

usedChars = {}

if s[0] >= 'A' and s[0] <= 'Z':
    usedChars[ s[0] ] = True
    mulA -= 1
    sum *= 9

if s[0] == '?':
    sum *= 9

for ch in s[1:]:
    if ch == '?':
        sum *= 10
    if ch not in usedChars:
        sum *= mulA
        mulA -= 1
        usedChars[ch] = True

print sum


s = raw_input()

k = 1
buk = ''
bu = ['A','B','C','D','E','F','G','H','I','J']

if s[0] in bu:
    k = k*9
    buk = s[0]
elif s[0] == '?':
    k = k*9

b = list(set(s[1:]))

for i in range(len(b)):
    if b[i] in bu and b[i] != buk:
        k = k*10
    elif b[i] == '?':
        k = k*10
print k


import sys
from collections import defaultdict

def main():
	S = sys.stdin.readline().strip()
	qmarks = 0
	used = set()
	ans = 1
	for pos, char in enumerate(S):
		if(char == '?'):
			if(pos == 0): ans *= 9
			else: ans *= 10
		elif(char in '0123456789'): pass
		else:
			if(pos == 0): ans *= 9
			else:
				if(char in used): pass
				else:
					ans *= 10 - len(used)
					used.add(char)
	print ans

main()


n = input()
if n%2 == 0 and n!= 2 :
    print("YES")
else:
    print("NO")


k=list(map(int,input().split()))
if(k[1]>k[2]):
    c=abs(k[0]-k[1])
    print(c)
else:

c=abs(k[0]-k[2])
d=abs(k[0]-k[1])
print(c+d)


even = list(range(2, 101, 2))
w = input()
if w in even:
    print ('YES')
elif w > 3:
    print('YES')


import math

def divide(b):
    divs = []

    x = b
    for i in range(2, math.sqrt(x)):
        if x % i == 0:
            divs.append(i)
            while x%i==0:
                x = x / i

    if x > 1:
        divs.append(x)
    return divs

def pow_(n, k, mod):

    ret = 1
    while(k > 0):
        if(k & 1):
            ret = ret * n % mod
            a = a * a %mod
            b = b / 2
    return ret

mod = 100000007
x = input()
n = input()

if n>1:
    listdiv = divide(x)
    ans = 1
    kk = []
    for i in range(listdiv.size()):
        nn = n
        temp = 0
        while nn > 0:
            temp = (temp + (nn / listdiv[i]))%mod
        ans *= pow_(listdiv[i], temp, mod)
        ans %= mod
    print(ans)
else:
    print(0)


from sys import stdin
#import nltk
import math
from collections import defaultdict

#stdin=open('input.txt','r')
#nltk.download('words')
I=stdin.readline

x,n=map(int,I().split())

primes=[]
if(x%2==0):
	primes.append(2)
	while(x%2==0):x/=2

for i in range(3,int(x**0.5)+1,2):
	if(x%i==0):
		primes.append(i)
		while(x%i==0):x/=i

if(x>2):primes.append(x)

prod=1
mod=pow(10,9)+7
for p in primes:
	y=math.floor(math.log(n,p))
	now=0
	for i in range(y,0,-1):
		po=pow(p,i)
		now+=n//po
	prod*=pow(p,now,mod)
	prod%=mod

print(prod)


import sys
def is_prime(n):
	if n == 1:
		return false;
	i = 2;
	while i * i <= n:
		if n % i == 0:
			return (False, i)
		i += 1
	return (True, n)

def fact(n):
	if n == 1:
		return []
	ans = []
	tmp = is_prime(n)
	while(not tmp[0]):
		while(n % tmp[1] == 0):
			n = n // tmp[1]
		ans.append(tmp[1])
		tmp = is_prime(n)
	ans.append(n)
	return ans

def legendre(x, n):
	ans = 0;
	tmpx = x
	while n // tmpx > 0:
		ans += n // tmpx;
		tmpx *= x
	return ans

def fastpow(x, pow):
	if pow == 0:
		return 1;
	if pow % 2 == 0:
		tmp = fastpow(x, pow // 2)
		return (tmp ** 2) % 1000000007
	else:
		return (x * fastpow(x, pow - 1)) % 1000000007

x, n = input().split()
x = int(x)
n = int(n)
ans = 1

for i in fact(x):
	ans = (ans * fastpow(i, (legendre(i, n)))) % (10**9 + 7)
print(ans)


#!/bin/python
from math import sqrt

x, n = (int(x) for x in input().split(' '))

def factorize(n):
	factors = []

	if (n % 2) == 0:
		factors.append(2)

		while (n % 2) == 0:
			n /= 2

	factor = 3
	sqrtt = sqrt(n) + 10

	while n >= factor and factor <= sqrtt:
		if (n % factor) == 0:
			factors.append(factor)

			while (n % factor) == 0:
				n /= factor

		factor += 2

	if n != 1:
		factors.append(n)

	return factors

M = 1_000_000_007

def mod_mul(a, b):
	return ((a % M) * (b % M)) % M

def fast_pow(x, p):
	result = 1
	current_power = 1
	current_factor = x

	while p >= current_power:
		if p & current_power:
			result = mod_mul(result, current_factor)

		current_factor = mod_mul(current_factor, current_factor)
		current_power *= 2

	return result

factors_of_x = factorize(x)
result = 1

for factor in factors_of_x:
	power = 0
	current = factor

	while current <= n:
		power += n // current
		current *= factor

	result = mod_mul(result, fast_pow(factor, power))

print(result)


from math import *
from sys import *
from heapq import *
from collections import defaultdict
import os, sys
from io import IOBase, BytesIO
M=10**9+7

def powmod(a,b,m):
    res=1
    while b>0:
        if b&1:
            res=((res*a)%m)
        a*=a
        b>>=1
    return res

def primefactorisation(nn):
    lst=[]
    if nn%2==0:
        lst+=[2]
        while nn%2==0:
            nn/=2
    for i in range(3,int(nn**0.5)+1,2):
        if nn%i==0:
            lst+=[i]
            while nn%i==0:
                nn/=i
    if nn>2:
        lst+=[int(nn)]

    return lst

def main():
    x,n=list(map(int,input().split()))

    lst=primefactorisation(x)
    #print(lst)
    res=1
    for p in lst:

        val=p
        V=0
        while n>=val:
            V+=n//val
            val*=p

        res*=powmod(p,V,M)
        res%=M

    print(res)

if __name__ == '__main__':
    main()
#threading.Thread(target=main).start()


from math import *
from sys import *
from heapq import *
from collections import defaultdict
import os, sys
from io import IOBase, BytesIO
M=10**9+7

def powmod(a,b,m):
    res=1
    while b>0:
        if b&1:
            res=((res*a)%m)
        a*=a
        b>>=1
    return res

def primefactorisation(nn):
    lst=[]
    if nn%2==0:
        lst+=[2]
        while nn%2==0:
            nn/=2
    for i in range(3,int(nn**0.5)+1,2):
        if nn%i==0:
            lst+=[i]
            while nn%i==0:
                nn/=i
    if nn>2:
        lst+=[int(nn)]

    return lst

def main():
    x,n=list(map(int,input().split()))

    lst=primefactorisation(x)
    #print(lst)
    res=1
    for p in lst:

        val=p
        V=0
        while n>=val:
            V+=n//val
            val*=p

        res*=pow(p,V,M)
        res%=M

    print(res)

if __name__ == '__main__':
    main()
#threading.Thread(target=main).start()


s = input()
ind1 = 0
while s[ind1] == “0”:
    ind1 += 1
ind2 = len(s) - 1
while s[ind2] == “0”:
    ind2 -= 1
s1 = s[ind1:ind2+1]
if s == s1 and ind1 <= len(s) - ind2:
    print(“YES”)
else:
    print(”NO”)


x=input()
while x % 10 == 0: x /= 10
x=str(x)
print "YES" if x==x[::-1] else "NO"


x = str(input())

while x[:-1] == '0':
	x = x[:-1]

found = False
for i in range(len(x)/2):
	if x[i] != x[:-(i+1)]:
		print('NO')
		found = True
		break

if !found:
	print('YES')


n=int(input())
x=int(input())
arr=[0,1,2]
while n:
    if n%2:
        arr[0],arr[1]=arr[1],arr[0]
    else:
        arr[1],arr[2]=arr[2],arr[1]
    n-=1
print(arr.index(x))


import sys

def main():
    w = int(sys.argv[1])
    #w= int(input())
    print(w)
    if w >= 4 and w % 2 == 0:
        print('YES')
    else:
        print('NO')

main()


n=int(input())
s=input()
array = list(string)
left = 0
right = 0
up = 0
down = 0

for i in array:
    if i == "U":
      up += 1
    elif i == "D":
      down += 1
    elif i == "L":
      left += 1
    else:
      right += 1

return 2*min(left, right) + 2*min(up, down)


x = input().split()
ans = 0
for i in range(61):
    for j in range(i - 1):
        y = 2 ** i - 1 - 2 ** j
        if y >= x[0] and y <= x[1]:
            ans++
print(ans)


a,b=map(int,input().split())
count=0
for i in range(a,b+1):
    c=str(bin(i))[2:]
    k=c.count('0')
    if k==1:
        count+=1
print(count)


a1=input().split()
a=int(a1[0])
b=int(a1[1])
n=0
for i in range(a,b+1):
	if bin(i).count('0')==2:
		n+=1
print(n)


input_ = input().split(" ")
input_numbers = list(map(int, input_))

shifted_ = []

a = input_numbers[0]
b = input_numbers[1]
a_ = len(bin(a)[2:])
b_ = len(bin(b)[2:])

all_ = []
answers = []

def generate_answers(mask):
    binaries = []

    for i in range(2, len(mask)):
        aux = '0b'
        aux += mask[2:]
        aux = list(aux)
        aux[i] = '0'
        aux = "".join(aux)
        binaries.append(aux)

    return binaries

for i in range(a_, b_+1):
    shifted = ((1 << i) - 1)
    shifted_.append(bin(mask))

for i in shifted_:
   all_ += generate_answers(i)

for i in all_:
    number = int(i,2)
    if !(number < input_numbers[0] or number > input_numbers[1] or i[2] == '0'):
        answers.append(i)

print(len(answers))


from functools import reduce
def count_choices(a, x):
  left_b, right_b = 0, 0
  left = 0
  right = a
  while left < right:
    middle = int((left + right) / 2)
    if middle <=x:
      left = middle + 1
      #choosing right_b means middle < x
      right_b+=1
    else:
      right = middle
      #choosing left means middle > x
      left_b+=1
  # subtract 1 from right to account for middle == x
  return [left_b, right_b - 1]

if __name__ == "__main__":
  n, x, pos = map(int, input().split(" "))
  lower_bound = 1 if (x == 1 ) else x-1
  upper_bound = 1 if ((n - x) == 0) else n-x
  [gt_x, lt_x] = count_choices(n, pos)
  print(reduce(lambda a,b: (a*b)%(10**9 + 7),
    # permutations for mids lt x
    [*range(lower_bound, lower_bound - lt_x, -1)]
    #permutations for mids gt x
  + [*range(upper_bound, upper_bound - gt_x, -1)]
    #permutations for other positions
  + [*range(1, n - gt_x - lt_x)]))


# HEY STALKER
hp_y, at_y, df_y = map(int, input().split())
hp_m, at_m, df_m = map(int, input().split())
cst_hp, cst_at, cst_df = map(int, input().split())
ans = 2e18
for ati in range(102):
    for dfi in range(102):
        for hpi in range(102):
            yank_hp = hp_y + hpi
            yank_at = at_y + ati
            yank_df = df_y + dfi
            m_k = max(0.01, at_m - yank_df)
            y_k = max(0.01, yank_at - df_m)
            yi = 0
            mi = 0
            if m_k > yank_hp:
                yi = 1
            else:
                yi = yank_hp // m_k
                if yank_hp % m_k != 0:
                    yi += 1
            if y_k > hp_m:
                mi = 1
            else:
                mi = hp_m // y_k
                if hp_m % y_k != 0:
                    mi += 1
            if yi > mi:
                cost = ((yank_hp - hp_y) * cst_hp) + ((yank_at - at_y) * cst_at) + ((yank_df - df_y) * cst_df)
                ans = min(ans, cost)
print(ans)


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

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

INF = 999999

def ceildiv(a, b):
    try:
        return a / b + bool(a % b)
    except ZeroDivisionError:
        return INF

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

hp1, atk1, def1 = map(int, raw_input().split())
hp2, atk2, def2 = map(int, raw_input().split())
price_hp, price_atk, price_def = map(int, raw_input().split())

dmg1 = max(0, atk1 - def2)
dmg2 = max(0, atk2 - def1)

nrounds1 = ceildiv(hp2, dmg1)
nrounds2 = ceildiv(hp1, dmg2)

if nrounds1 < nrounds2:
    print 0
    quit()

from Queue import PriorityQueue

price = 0
natk = 0
if atk1 - def2 <= 0:
    natk = def2 - atk1 + 1
    price = natk * price_atk

queue = PriorityQueue()
queue.put((price, 0, natk, 0))
while queue:
    price, nhp, natk, ndef = queue.get()
    dmg1 = max(0, natk + atk1 - def2)
    dmg2 = max(0, atk2 - def1 - ndef)

    nrounds1 = ceildiv(hp2, dmg1)
    nrounds2 = ceildiv(hp1 + nhp, dmg2)
    if nrounds1 < nrounds2:
        print price
        quit()

    need_hp = nrounds1 * dmg2 - (hp1 + nhp) + 1
    price_test = price + need_hp * price_hp
    queue.put((price_test, nhp + need_hp, natk, ndef))

    queue.put((price + price_atk, nhp, natk + 1, ndef))
    queue.put((price + price_def, nhp, natk, ndef + 1))


hpy,atky,defy = raw_input().split(" ")
hpm,atkm,defm = raw_input().split(" ")
h,a,d = raw_input().split(" ")
hpy,atky,defy = int(hpy),int(atky),int(defy)
hpm,atkm,defm = int(hpm),int(atkm),int(defm)
h,a,d = int(h),int(a),int(d)

def test(hpy,atky,defy,hpm,atkm,defm):
    while hpm > 0:
        hpm -= max(0,atky-defm)
        hpy -= max(0,atkm-defy)
    if hpy <= 0:
        return -hpy + 1
    else:
        return 0
cost = h*test(hpy,atky,defy,hpm,atkm,defm)
for i in range(0,100-atky+defm):
    for j in range(0,atkm-defy):
        cs = h*test(hpy,atky+i,defy+j,hpm,atkm,defm)+i*a+j*d
        if cs<cost:
            cost = cs
print cost


import math

y = [int(x)for x in raw_input().split(' ')]
m = [int(x)for x in raw_input().split(' ')]
h, a, d = [int(x)for x in raw_input().split(' ')]

inf = 9999999999999999999999999999
ans = inf

for hp in xrange(y[0], 101):
    for at in xrange(y[1], 101):
        for de in xrange(y[2], 101):
            #print 'lol', hp, at, de
            mloss = max(0, at - m[2])
            yloss = max(0, m[1] - de)
            if mloss == 0:
                mtime = inf
            else:
                mtime = math.ceil(m[0] / float(mloss))
            if yloss == 0:
                ytime = inf
            else:
                ytime = math.ceil(hp / float(yloss))
            #print 'lol', hp, at, de, mloss, yloss, mtime, ytime
            #cost = (hp - y[0]) * h + (at - y[1]) * a + (de - y[2]) * d
            #if cost == 3519:
            #   print 'tst', hp, at, de, mloss, yloss, mtime, ytime, cost
            if ytime > mtime:
                cost = (hp - y[0]) * h + (at - y[1]) * a + (de - y[2]) * d
                #print 'hui', hp, at, de, cost
                if ans > cost:
                    ans = cost
'''
for at in xrange(y[1], m[0] + m[2] + 1):
    for de in xrange(y[2], m[1] + 1):
        mloss = at - m[2]
        yloss = m[1] - de
        if mloss == 0:
            mtime = inf
        else:
            mtime = m[0] / mloss
        if yloss == 0:
            ytime = inf
        else:
            ytime = y[0] / yloss
        if ytime > mtime:
            cost = (at - y[1]) * a + (de - y[2]) * d
            if ans > cost:
                ans = cost
        else:
            hp = (mtime + 1) * yloss - y[0]
            cost = (hp - y[0]) * h + (at - y[1]) * a + (de - y[2]) * d
            if ans > cost:
                ans = cost
'''
if ans == inf:
    print 0
else:
    print ans
    #print 'ppc', hp, at, de


listwhite = []
listblack = []

for i in range(1,9):

   if i%2 == 0:
       k = 2
   else:
       k = 1

   for j in range(k,9,2):
       listwhite.append([i,j])

for i in range(1,9):

    if i%2 == 0:
        k = 1
    else:
        k = 2

    for j in range(k,9,2):
        listblack.append([i,j])

# print(listwhite)
# print(listblack)
x1,y1,x2,y2 = map(int,input().split())

if x1 == x2 and y1!=y2:
    rook = 1

elif y1 == y2 and x1!=x2:
    rook = 1

elif x1 != x2 and y1!=y2:
    rook = 2
else:
    rook = 0

if [x1,y1] in listwhite and [x2,y2] in listwhite:

    if abs(x1 - x2) == abs(y1 - y2):
        bishop = 1

    else:
        bishop = 2

elif [x1,y1] in listblack and [x2,y2] in listblack:

    if abs(x1 - x2) == abs(y1 - y2):
        bishop = 1

    else:
        bishop = 2

else:
    bishop = 0

if abs(x1-x2) <= 1 and abs(y1-y2) <= 1:
    count = 1

else:
  count = 0
  if x1!=x2 and y1!=y2:
    if x1 >=x2 and y1 >=y2:
        count1 = 0
        count2 = 0
        while y1 != y2:
            count1+=1
            y1-=1
            x1-=1
        count1+=abs(x1-x2)

        while x1 != x2:
            count2+=1
            y1-=1
            x1-=1
        count2+=abs(y1-y2)

        count = min(count1,count2)

    elif x1 <=x2 and y1 >=y2:

        count1 = 0
        count2 = 0
        temp1,temp2,temp3,temp4 = x1,x2,y1,y2
        while y1 != y2:
            count1+=1
            y1-=1
            x1+=1
        count1+=abs(x1-x2)

        x1,x2,y1,y2 = temp1,temp2,temp3,temp4
        while x1 != x2:
            count2+=1
            y1-=1
            x1+=1
        count2+=abs(y1-y2)

        count = min(count1,count2)

    elif x1 <=x2 and y1 <=y2:

        count1 = 0
        count2 = 0
        temp1,temp2,temp3,temp4 = x1,x2,y1,y2
        while y1 != y2:
            count1+=1
            y1+=1
            x1+=1
        count1+=abs(x1-x2)
        x1,x2,y1,y2 = temp1,temp2,temp3,temp4
        while x1 != x2:
            count2+=1
            y1+=1
            x1+=1
        count2+=abs(y1-y2)

        count = min(count1,count2)
    elif x1 >=x2 and y1 <=y2:

        count1 = 0
        count2 = 0
        temp1,temp2,temp3,temp4 = x1,x2,y1,y2
        while y1 != y2:
            count1+=1
            y1-=1
            x1+=1
        count1+=abs(x1-x2)
        x1,x2,y1,y2 = temp1,temp2,temp3,temp4

        while x1 != x2:
            count2+=1
            y1+=1
            x1-=1
        count2+=abs(y1-y2)

        count = min(count1,count2)

  else:
      count+=abs(y1-y2) + abs(x2-x1)

print(rook,bishop,count)


a,b,c,d = map(int,input().split())
r_move = b_move = k_move = 0
if(a==c or b==d):
    r_move = 1
else:
    r_move = 2
if(abs(a-c)!=abs(b-d) and (a+b)%2==(c+d)%2):
    b_move = 2
elif(abs(a-c)==abs(b-d)):
    b_move = 1
else:
    b_move = 0
if(a==c or b==d):
    k_move = max(abs(a-c),abs(b-d))
elif(abs(a-c)==abs(b-d)):
    k_move = min(abs(a-c), abs(b-d))
else:
    k_move = min(abs(a-c), abs(b-d)) + max(abs(a-c),abs(b-d)) - 1
print(r_move, b_move, k_move)


har = Str()
vij = set()
chk = ''
vij.add(har)
har1 = har[:]
for i in xrange(len(har)):
	chk = har1[-1] + har1[:-1]
	#print chk
	vij.add(chk)
	har1 = chk[:]
print len(vij)


n, m = map(int, input().split())
a = [0] * m
for i in range(m):
    b, c = map(int, input().split())
    a[i] = [b -1, c - 1]
col = [0] * 7
z = set()
ans = 0
for i in range(n):
    for i1 in range(6):
        for i2 in range(6):
            for i3 in range(6):
                for i4 in range(6):
                    for i5 in range(6):
                        for i6 in range(6):
                            for i7 in range(7):
                                col[0]= i1 + 1
                                col[1] = i2 + 1
                                col[2] = i3 + 1
                                col[3] = i4 + 1
                                col[4] = i5 + 1
                                col[5] = i6 + 1
                                col[6] = i7 + 1
                                for j in range(m):
                                    z.add(max(col[a[j][0]], col[a[j][1]]) * 10 + min(col[a[j][0]], col[a[j][1]]))
                                #print(z)
                                #if len(z) > ans:
                                    #print(col)
                                ans = max(ans, len(z))
                                z = set()
print(ans)


from math import ceil, floor

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

x_bot = int(ceil(a/x)) * x
x_top = int(floor(b/x) + 1) * x

y_bot = int(ceil(a/y)) * y
y_top = int(floor(b/y) + 1) * y

x_vals = set(range(x_bot, x_top, x))
y_vals = set(range(y_bot, y_top, y))

print(len(list(x_vals.intersection(y_vals))))


import time,math,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
pi=3.14159265358979323846264338327950
def II(): # to take integer input
    return int(stdin.readline())
def IO(): # to take string input
    return stdin.readline()
def IP(): # to take tuple as input
    return map(int,stdin.readline().split())
def L(): # to take list as input
    return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
    return stdout.write(str(x)+"\n")
def PI(x,y): # to print tuple separatedly
    return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
    return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
    if a==0:
        return b
    elif b==0:
        return a
    if a>b:
        return gcd(a%b,b)
    else:
        return gcd(a,b%a)
def readTree(): # to read tree
    v=int(input())
    adj=[set() for i in range(v+1)]
    for i in range(v-1):
        u1,u2=In()
        adj[u1].add(u2)
        adj[u2].add(u1)
    return adj,v
def bfs(adj,v): # a schema of bfs
    visited=[False]*(v+1)
    q=deque()
    while q:
        pass
def sieve():
    li=[True]*1000001
    li[0],li[1]=False,False
    for i in range(2,len(li),1):
        if li[i]==True:
            for j in range(i*i,len(li),i):
                li[j]=False
    prime=[]
    for i in range(1000001):
        if li[i]==True:
            prime.append(i)
    return prime
def setBit(n):
    count=0
    while n!=0:
        n=n&(n-1)
        count+=1
    return count
#####################################################################################
def solve():
    x,y,a,b=L()
    lm=lcm(x,y)
    if strt>b:
        print(0)
    else:
        print(math.floor(b/lm)-math.floor((a-1)/lm))

solve()


x, y, a, b = (int(i) for i in input().split(' '))

r = range(a, b + 1)

print(len(tuple(i for i in r if i % lcm(x, y) == 0)))


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


n=int(input())
s=str(input())
countsf=0
countfs=0
for i in range(n):
	if "SF" in s[i:i+2]:
		countsf+=1
	else:
		continue
for j in range(n):
	if "FS" in s[j:j+2]:
		countfs+=1
	else:
		continue
if countsf>countfs:
	print("YES")
else:
	print("NO"


n=int(input())-1
for val in range(1,10**6):
    x=n
    Bool = False
    A,B=val,0
    if x%val == 0 x > 0:
        x = x//val
        x -= (val+1)
        if x%2 == 0:
            B=x//2
            Bool=True
            print(A,B)
            break
if Bool==False:
    print("NO")


r = int(input())

if (r<5 or r%2==0)
    print("NO")
    exit()

print(1, (r-3) // 2)


n,k = map(int, raw_input().split())
mod =1000000007
def div(a,b):
    return (a%mod*(pow(b,mod-2,mod)))%mod

dic={}

i=2
n1=n
while i*i<=n1:
    while n1%i==0:
        dic[i]=dic.get(i,0)+1
        n1/=i
    i+=1
if n1!=1:
    dic[n1]=dic.get(n1,0)+1

pdt=1
for key in dic:
    #print key, dic[key]
    m=dic[key]
    ans=[[0]*(m+1) for i in range(k)]
    for idx in range(m+1):

        ans[0][idx]=div(1,m+1)
    for i in range(1,k):
        for j in range(m,-1,-1):
            for kxx in range(m,j-1,-1):
                ans[i][j]=(ans[i][j]+div(ans[i-1][kxx],kxx+1))%mod
    #print ans
    ax=0
    for i in range(m+1):
        ax=(ax+pow(key,i)*ans[k-1][i])%mod
    pdt=(pdt*ax)%mod
print pdt
exit()


import sys
range = xrange
input = raw_input

MOD = 10**9 + 7

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

def coef(n,k):
    prod = 1
    for j in range(k,n+k):
        prod *= j
    for j in range(1,n+1):
        prod //= j
    return prod

# This is a multiplicative property
EXP = 1

i = 2
while n>1 and i*i<=n:
    if n%i==0:
        count = 0
        while n%i==0:
            n//=i
            count += 1

        arr = [0]*(count+1)
        arr[-1] = 1

        for _ in range(k):
            val = 0
            for j in reversed(range(count+1)):
                val += arr[j]*pow(j+1,MOD-2,MOD)
                arr[j] = val
        tmp = 0
        for j in range(count+1):
            tmp += (i**j)*arr[j]
        EXP *= tmp

    i += 1

if n>1:
    i=n
    count = 0
    while n%i==0:
        n//=i
        count += 1

    arr = [0]*(count+1)
    arr[1] = 1

    for _ in range(k):
        val = 0
        for j in reversed(range(count+1)):
            val += arr[j]*pow(j+1,MOD-2,MOD)
            arr[j] = val
    tmp = 0
    for j in range(count+1):
        tmp += (i**j)*arr[j]
    EXP *= tmp

print EXP%MOD


MOD = 1000000007

A, K = 50, 10002

dp = [[0 for i in xrange(K)] for j in xrange(A)]

n, kk = map(int, raw_input().strip().split())
divi = []
N = n

i = 2
while i * i <= n:
    if n % i == 0:
        isprime = 1
        for p in divi:
            if i % p == 0:
                isprime = 0
                break
        if isprime:
            while n % i == 0: n //= i
            divi.append(i)

if n > 1: divi.append(n)

for i in xrange(K): dp[0][i] = 1

ans = 1

for p in divi:
    al = 0
    while N % p == 0:
        N //= p
        al += 1

    for k in xrange(al + 1): dp[k][0] = pow(p, k, MOD)
    for i in xrange(1, al + 1):
        for j in xrange(1, kk + 1):
            dp[i][j] = 0
            for k in xrange(i + 1):
                dp[i][j] += dp[k][j - 1]
                if dp[i][j] >= MOD: dp[i][j] %= MOD;

            dp[i][j] = dp[i][j] * pow(i + 1, MOD - 2, MOD)

            if dp[i][j] >= MOD: dp[i][j] %= MOD

    ans *= dp[al][kk]

    if ans >= MOD: ans %= MOD

print ans


from collections import defaultdict
from math import sqrt

n, k = [int(i) for i in input().split()]
p = 10 ** 9 + 7

def factorize(n):
    res = []
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            res.append(i)
            res.append(n // i)
    return tuple(sorted(list(set(res))))

d = factorize(n)
D = {n: d}
DP = [[0] * len(d) for i in range(k + 1)]
DP[0][-1] = 1
ind = {d[i]: i for i in range(len(d))}
# mod = [pow(len(d), p-2, p)]

# for i in range(k):
#     mod.append(pow(mod[-1], 2, p))
mod = [1, 1]
for i in range(2, len(d) + 1):
    mod.append(p - (p // i) * mod[p % i] % p)

def get_d(n):
    res = []
    for d_ in d:
        if d_ > n:
            break
        if n % d_ == 0:
            res.append(d_)
    return tuple(res)

for i in range(k):
    for j in range(len(d)):
        if not d[j] in D:
            D[d[j]] = get_d(d[j])
        for d_ in D[d[j]]:
            DP[i+1][ind[d_]] += DP[i][j] * mod[len(D[d[j]])]
ans = 0
s = 0
for d_ in d:
    ans += DP[k][ind[d_]] * d_
    s += DP[k][ind[d_]]

print((ans % p))


from collections import defaultdict
from math import sqrt

n, k = [int(i) for i in input().split()]
p = 10 ** 9 + 7

def factorize(n):
    i = 2
    A = defaultdict(int)

    while n % i == 0:
        n //= i
        A[i] += 1
    i += 1

    while n != 1 and i <= sqrt(n):
        while n % i == 0:
            n //= i
            A[i] += 1
        i += 2
    if n != 1:
        A[n] += 1

    return A

D = dict(factorize(n))
ans = 1
mod = [1, 1]
for i in range(2, 50):
    mod.append(p - (p // i) * mod[p % i] % p)

for key, v in D.items():
    DP = [[0] * (v+1) for i in range(k+1)]
    DP[0][v] = 1
    for i in range(k):
        for j in range(v+1):
            for l in range(j+1):
                DP[i+1][l] += DP[i][j] * mod[j+1]
    res = 0
    pk = 1
    for i in range(v+1):
        res += DP[k][i] * pk
        pk *= key
    ans *= res
    ans %= p

print(ans)


# import time

mod = int(1e9 + 7)

def fast_expo(x, k):
    ans = 1
    while k > 0:
        if (k & 1) > 0:
            ans = (ans * x) % mod
        x = (x * x) % mod
        k >>= 1
    return ans

def inverse(x):
    return fast_expo(x, mod - 2)

N, K = [int(_) for _ in input().split()]
# start_time = time.time()
prime_factors = {}
i = 2
curr = N
while i * i <= curr:
    if curr % i == 0:
        prime_factors[i] = 0
        while curr % i == 0:
            prime_factors[i] += 1
            curr //= i
    i += 1

if curr > 1:
    prime_factors[curr] = 1

dpCurr = {p: {e: fast_expo(p, e) for e in range(60)} for p in prime_factors.keys()}
# after 0 steps, EV = itself
for it in range(K):
    dpNext = {p: {e: 0 for e in range(60)} for p in prime_factors.keys()}
    for p in prime_factors.keys():
        prefix = 0
        divisors = 0
        for e in range(prime_factors[p] + 1):
            prefix += dpCurr[p][e]
            divisors += 1
            assert divisors == e + 1  # yup
            dpNext[p][e] = inverse(divisors) * prefix
    dpCurr = dpNext
    # print(dpCurr)

# because the dp is multiplicative, we can merge the answer
ans = 1
for p, e in prime_factors.items():
    ans = (ans * dpCurr[p][e]) % mod
print(ans)
# print(time.time() - start_time)


x,k=map(int,input().split())
#x=60
#k=5
if x==1:
    print(1)
    import sys
    sys.exit()

import math
L=int(math.sqrt(x))
mod=10**9+7
FACT=dict()

for i in range(2,L+2):
    while x%i==0:
        FACT[i]=FACT.get(i,0)+1
        x=x//i

if x!=1:
    FACT[x]=FACT.get(x,0)+1

def prod(A,B,k,l,m):#A:k*l,B:l*m
    C=[[None for i in range(m)] for j in range(k)]

    for i in range(k):
        for j in range(m):
            ANS=0
            for pl in range(l):
                ANS=(ANS+A[i][pl]*B[pl][j])%mod

            C[i][j]=ANS

    return C

#XX=[[1,1],[1,1],[1,1]]
#YY=[[2,2,2],[2,3,4]]
#print(prod(XX,YY,3,2,3))

MAT_index=max(FACT.values())+1
MAT=[[0 for i in range(MAT_index)] for j in range(MAT_index)]

for m in range(MAT_index):
    for l in range(m+1):
        x=pow(m+1,mod-2,mod)
        MAT[m][l]=x

#print(MAT)
MAT_ini=MAT
for i in range(k-1):
    MAT=prod(MAT,MAT_ini,MAT_index,MAT_index,MAT_index)

#print(MAT)

ANS=1
for fa in FACT:
    x=FACT[fa]
    ANS_fa=0

    for i in range(x+1):
        ANS_fa=(ANS_fa+pow(fa,i,mod)*MAT[x][i])%mod

    ANS=ANS*ANS_fa%mod

print(ANS)


a = input()
b = {}
b[a] = 1
for i in range(0,len(a)-1):
	a = a[1:] + a[0:1]
	b[a] = 1

print len(b)


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


#include <iostream>
using namespace std;

int main()
{
 int m,b;
 cin >> m >> b;

 long long t = 0;
 long long ans = 0;
 for(int x=0;x<=m*b;x++)
 {
     int y = int(-float(x)/m+b);
     t=((x+1)*(y+1)*(x+y))/2;
     ans = max(ans,t);
 }
 cout << ans;
}


n = int(input())
m = 1
l = []
counter = 0
while m < n + 1:
    command = input()
    if command != "remove":
        l += [int(command.split()[1])]
    else:
        if l[-1] != m:
            l.sort(reverse=True)
            counter += 1
        l.pop()
        m += 1

print(counter)


A=list(map(int,input().split()))
m,b=A[0],A[1]
def banana(x,y):
    s=0
    for i in range(x+1):
        s+=i
    banan=0
    for i in range(y+1):
        banan+=s+i*(x+1)
    return banan
mx=0
for y in range(b+1):
           x=(b-y)*m
           mx=max(mx,banana(x,y))
print(mx)


(a, k) = input().split()
a = list(a)
k = int(k)
sorted_a = reversed(sorted(a))
i = 0

while k > 0 and a != sorted_a:
    for j in range(9, 0, -1):
        c = str(j)
        if c in a[i:] and a[i:].index(c) <= k:
            l = a[i:].index(c)
            k -= l
            a.insert(int(i), a.pop(i+l))
            break
    i += 1

print(''.join(a))


(x, a), b = list(input().split()), 0

a = int(a)
x = list(map(int, list(str(x))))

for i in range(len(x) - 1):
    m = [-1, -1]

    if a > 0:
        if i + 1 + a > len(x):
            b = len(x)
        else:
            b = i + 1 + a
    else:
        break

    for j in range(i, b):
        if x[j] > m[0]:
            m[0] = x[j]
            m[1] = j

    x[i], x[m[1]] = x[m[1]], x[i]
    a = a - (m[1] - i)

x = list(map(str, x))

print( ''.join(x) )


n, k = map(int, input().split())
s = list(str(n))
res = ''
while(len(s) > 0):
    mx = max(s[:k+1])
    idx = s.index(mx)
    k -= idx
    s.pop(idx)
    res += mx
print(res


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

res = 1
for i in range(n):
    for j in range(n):
        if a[i][j] != 1:
            d = 0
            for x in range(n):
                for y in range(n):
                    if a[i][j] == a[i][x] + a[y][j]: d+= 1
                    if d > 0: break
            if d == 0: res = 0
print ["No", "Yes"][res]


sf=0
fs=0
n=int(input())
c=input()
n-=1
d=c[0]
s=c[1::]
for t in s:
    if(d=='S' and t=='F'):
        sf++
    elif(d=='F' and t=='S'):
        fs++
    d=t
if(sf>fs):
    print("YES")
else:
    print("NO")


n=int(input())
str1=input()
if str1[0]=='S' and str1[n-1]='F':
    print('YES')
else:
    print('NO')


x=int(input())x=int(input())
y=input()
count1=y.count('FS')
count2=y.count('SF')
if(count2>count1):
    print("YES")
else:
    print("NO")


def answer():
    n = int(input())
    elif n%2:
        print("ehab")
    elif n%2==0:
        print("Mahmoud")
answer()


v = list(map(int, input().split()))
    found = False

    for i in range(v[0] + 1):
        a = i
        b = v[0] - i

        if (v[1] - a) < 0 or (v[2] - b) < 0:
            continue

        if (v[1] - a) == v[2] - b:
            print(a, v[1] - a, b)
            found = True
            break
    if not found:
        print("Impossible")


atoms=input().split(' ')
attoms=[]
out=''
for atom in atoms:
	attoms.append(int(atom))
if (attoms[0]+attoms[1]+attoms[2])%2 !=0:
    print('Impossible')
    quit()
if attoms[0]==attoms[1]==attoms[2]:
    print(str(int(attoms[0]/2))+' '+str(int(attoms[0]/2))+' '+str(int(attoms[0]/2)))
    quit()
for q in range(attoms[0]+1):
    for w in range(attoms[1]+1):
        for e in range(attoms[2]+1):
            if q + w +e == (attoms[0]+attoms[2]+attoms[1])/2 and attoms[0]==(q+e)and attoms[1]==(q+w)and attoms[2]==(e+w):
                out=str(q)+' '+str(w)+' '+str(e)
                print(out)
                quit()
print('Impossible')


a, b, c = map(int, input().split())
x = a
y = b
z = c
if a > b + c or b > a + c or c > a + b or (a + b + c) % 2 != 0:
    print('Impossible')
    exit(0)
if a >= b and a >= c:
    while x <> y + z:
        g += 1
        y -= 1
        z -= 1
    print(x - y, g, x - z)
    exit(0)
if b >= a and b >= c:
    while y <> x + z:
        g += 1
        x -= 1
        z -= 1
    print(y - x, y - z, g)
    exit(0)
if c >= a and c >= b:
    while y <> x + z:
        g += 1
        x -= 1
        y -= 1
    print(g, z - y, z - x)
    exit(0)


n, k = map(int, input().split())
name = input()[:n]
name = list(name)
if n % 2 == 0:
    for i in set(name):
        if name.count(i) > n // 2:
            print('NO')
            break
    else:
        print('YES')
else:
    print('NO')


# # --- Система регистрации (словарь)---
# keys = int(input())
# names = [input() for row in range(keys)]
# database = dict()
# for i in names:
#     if i not in database:
#         database[i] = 0
#         print('OK')
#     else:
#         for k, val in database.items():
#             if val >= 0 and k == i:
#                 val += 1
#                 database[i] = val
#                 print(k + str(val))
#                 # print(k + f'{val}')

# # --- Система регистрации (правильное решение)---
# keys = int(input())
# names = [input() for row in range(keys)]
# database = dict()
# for i in names:
#     if i in database:
#         database[i] += 1
#         print(i + str(database[i]))
#     else:
#         database[i] = 0
#         print('OK')

# # --- Single number ---
# nums = [2, 2, 1, 1, 1, 7]
# count = {}
# for i in nums:
# 	if i in count:
# 		count[i] += 1
# 	else:
# 		count[i] = 1
# for i in count:
# 	if count[i] == 1:
# 		print(i)

# # --- Persons ---
# contacts = {
#     "John Kennedy": {
#         'birthday': '29 may 1917',
#         'city': 'Brookline',
#         'phone': None,
#         'children': 3
#     },
#     "Arnold Schwarzenegger": {
#         'birthday': '30 july 1947',
#         'city': 'Gradec',
#         'phone': '555-555-555',
#         'children': 5
#     },
#     "Donald John Trump": {
#         'birthday': '14 july 1946',
#         'city': 'New York',
#         'phone': '777-777-333',
#         'children': 4
#     }
# }

# persons = list(contacts.keys())

# for person in persons:
#     print(person)
#     for data in contacts[person]:
#         print(data, contacts[person][data], sep=': ')
#     print()

balls, friends = map(int, input().split())
colours = input().lower()
i = 0
lucky = 0
while len(colours) > 0:
    for j in range(1, len(colours)):
        if colours[i] != colours[j]:
            colours = colours[1:j] + colours[j + 1:]
            lucky += 1
            break
        if j == len(colours) - 1:
            i = 1
    if i == 1:
        break
if len(colours) == 0 or lucky == friends:
    print('YES')
else:
    print('NO')


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

n = 0
for i in range(len(a)):
    if n >= k: break
    max_i = i + a[i:i + k - n].index(max(a[i:i + k - n]))
    t = a.pop(max_i)
    a.insert(i, t)
    n += max_i - i

print(''.join(str(i) for i in a))