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

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

ANS = 1000
for I in range(2):
    ps = ps0[:]
    if I == 0:
        to_add.sort(key = lambda x: x%2)
    else:
        to_add.sort(key = lambda x: x%2, reverse=True)
    odds = [x%2 for x in to_add].count(1)
    evens = len(to_add) - odds
    for t in to_add:

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

print(ANS)


import math
n = input()

k = int(math.ceil((-3 + math.sqrt(8*n + 9)) / 2)) - 1
s = ""
for i in xrange(0,k):
    s += str(i+1) + " "

s += str(n - (k*(k + 1)//2))

print (k + 1)
print s


input()
s = input()
for c in s:
    if c != '4' and c != '7':
        print('NO')
        break
else:
    if (sum([int(i) for i in s[:len(s) // 2]]) ==
        sum([int(i) for i in s[-1:len(s)//2-1:-1]])):
        print('YES')
    else:
        print('NO')


a=input();print(('NO','YES')[sum(x in'AEFHIKLMNTVWXYZ'for x in a)in(0,len(a))])


from collections import Counter as love
n,k = map(int,raw_input().split())
a = love(raw_input()).values()
g = max(a)
if g > k:
    print 'NO'
else:
    print 'YES'


s = raw_input()

s= s.lower()

s1 = ""
y = ""

for i in range(len(s)):
    y = s[i]

    if  y != "a" and y != "e" and y != "i" and y != "o" and y != "u" and y != "y" :
        s1 = s1 + "." + y

print s1


a=raw_input()
b=raw_input()
dlina=len(a)
c=""

for i in range(dlina):
    if a[i]==b[i]:
        c+="0"
    else:
        c+="1"
print c


def hd_ext_max(days):
    return days if days < 2 else 2

def hd_ext_min(days):
    return 1 if days == 6 else 0

def main():
    days_num = int(input())
    full_weeks_num = days_num // 7
    min_hd = full_weeks_num * 2 + hd_ext_min(days_num % 7)
    max_hd = min_hd + hd_ext_max(days_num % 7) - hd_ext_min(days_num % 7)
    print(min_hd, max_hd)

if __name__ == '__main__':
    main()


from sys import stdin
n=int(stdin.readline().strip())
s=list(map(int,stdin.readline().strip().split()))
ans=0
s.sort()
while len(s)>0:
    s1=[]
    arr=s[0]
    flag=False
    for i in range(len(s)):
        if s[i]%arr!=0:
            s1.append(s[i])
        else:
            flag=True
    s=s1.copy()
    if flag==True:
        ans+=1
print(ans)


key = list( "qwertyuiopasdfghjkl;zxcvbnm,./" )
d = raw_input()
s = raw_input()
ans = ""
for c in s:
    if d == 'R':
        ans += key[ key.index( c ) - 1 ]
    else:
        ans += key[ key.index( c ) + 1 ]
print ans


x, y, l, r = map(int, input().split())
a = set()
i = 0
j = 0
while x**i <= r:
    j = 0
    while x**i + y ** j <= r:
        if (x**i + y**j >= l) and (x**i + y**j <= r):
            a.add(x**i + y**j)
        j += 1
    i += 1
a = list(a)
a.sort()
ma = 0
length = len(a)
for i in range(1, length):
    if a[i] - a[i - 1] - 1 > ma:
        ma = a[i] - a[i - 1] - 1
if len(a) > 0:
    if a[0] - l > ma:
        ma = a[0] - l
    if r - a[length - 1] > ma:
        ma = r - a[length - 1]
    print(ma)
else:
    print(r - l + 1)


def isPrime(n) :

    # Corner cases
    if (n <= 1) :
        return False
    if (n <= 3) :
        return True

    # This is checked so that we can skip
    # middle five numbers in below loop
    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

t=int((input()))
for i in range(t):
    n,m=map(int,input().split())
    if (n-m)!=1:
        print("NO")
    else:
        if isPrime(n+m):
            print("YES")
        else:
            print("NO")


n, k = map(int, input().split())
s = input()
alph = 'abcdefghijklmnopqrstuvwxyz'
s = sorted(s)
min_count = float('inf')
for i in range(n):
    c = 1
    j = 0
    count = alph.find(s[i]) + 1
    x = alph.find(s[i])
    while c != k and j != n:
        if i != j and alph.find(s[j]) > x + 1:
            c += 1
            count += alph.find(s[j]) + 1
            x = alph.find(s[j])
        j += 1
    if c == k and count < min_count:
        min_count = count
print(-1 if min_count == float('inf') else min_count)


def perform_work():
    input_data = raw_input()
    splitted_input = input_data.split(" ")
    p = int(splitted_input[0])
    d = int(splitted_input[1])
    min_p = p - d
    str_p = str(p)
    str_min_p = str(min_p)
    if len(str_p) == 1:
        return str_p
    if ends_with_nines(str_p):
            return str_p
    if len(str_p) > len(str_min_p):
        if str_p[0] != '1':
            return str(int(str_p[0])-1) + get_nines(len(str_p) - 1)
        else:
            return get_nines(len(str_p) - 1)
    else:
        for i in range(len(str_p) - 1):
            if str_p[i] > str_min_p[i]:
                return str_p[0:i] + str(int(str_p[i])-1) + get_nines(len(str_p) - i-1)
        return str_p

def ends_with_nines(s):
    s_tail = s[1:]
    for sym in s_tail:
        if sym != '9':
            return False
    return True

def get_nines(size):
    return "9" * size

result = perform_work()
print result


n,x,y,c=map(int,raw_input().split())
def C(t):
	return t*t+(t+1)*(t+1)-sum(map(lambda x:max(x,0)**2,[t-x+1,t-y+1,x+t-n,y+t-n]))+sum(map(lambda x:max(x,0)*(max(x,0)+1)/2,[t-x-y+1,t-n+x-y,t-n+y-x,t-2*n+x+y-1]))
l,r=-1,2*n
while l<r-1:
	m=l+r>>1
	if C(m)<c:
		l=m
	else:
		r=m
print r


def gcd(a, b):
    if a == 0:
        return b
    return gcd(b % a, a)
def lcm(a, b):
    return (a * b) / gcd(a, b)
n = int(input())
i = 1
while i**2 <= n:
        if n % i == 0:
            if lcm(i, n/i) == n:
                r = i
        i += 1
print(r, n//r)


def si():
    return raw_input()
def ii():
    return int(si())
def mi():
    return map(int,si().split())
def sol():
    n=ii()
    s=si()
    if s=='0':
        print '0'
        return
    ans='1'+'0'*(s.count('0'))
    print ans
if __name__=="__main__":
    sol()


s = raw_input()
n = len(s)
pb = -1
for i in xrange(n):
	if s[i] == 'B':
		pb = i

if pb != -1:
	s = s[pb:] + s[:pb]

s = s[-1] + s + s[0]

res = 1

dp = []

for i in xrange(n + 2):
	dp.append([[[0, 0], [0, 0]], [[0, 0], [0, 0]]])

for i in xrange(2, n + 1):
	for first in xrange(2):
		for prev in xrange(2):
			for last in xrange(2):
				for cur in xrange(2):
					if s[i - 1:i + 1] != 'BA' and cur == 1:
						continue
					if i == 2:
						if first != cur or prev != 0 or last != 0:
							continue
						dp[i][first][last][cur] = 1
					elif i > 2:
						if s[i - 2:i] == 'AB' and prev == 0 and cur == 0:
							continue
						if i == n and s[n] + s[1] == 'AB' and cur == 0 and first == 0:
							continue
						if i == n and s[n - 1:n + 1] == 'AB' and cur == 0 and last == 0:
							continue
						dp[i][first][last][cur] += dp[i - 1][first][prev][last]

res = 0
for i in xrange(2):
	for j in xrange(2):
		for k in xrange(2):
			res += dp[n][i][j][k]

print res


x, y = map(int, input().split())
p = x * x + y * y
d = int(p ** 0.5)
if d * d == p: print('black')
else:
    if x * y < 0: print('black' if d % 2 else 'white')
    else: print('white' if d % 2 else 'black')


class Subject:
    def __init__(self, id, low, high, complexity):
        self.id = id
        self.low = low
        self.high = high
        self.complexity = complexity
        self.day_links = [ {} for i in range(high - low + 1) ]

    def add_link(self, link):
        day = link.day
        links = self.day_links[link.weight - self.low]
        if day not in links or links[day].total < link.total:
            links[day] = link

class Link:
    def __init__(self, subject, weight, total, day, previous):
        self.subject = subject
        self.weight = weight
        self.total = total
        self.day = day
        self.previous = previous

class Group:
    def __init__(self, complexity):
        self.complexity = complexity
        self.subjects = []

need_day, num_subjects, more = map(int, input().split())
groups = {}
for i in range(num_subjects):
    subject = Subject(i + 1, *list(map(int, input().split())))
    if subject.complexity not in groups:
        groups[subject.complexity] = Group(subject.complexity)
    groups[subject.complexity].subjects.append(subject)
groups = sorted(groups.values(), key = lambda group: group.complexity)
num_groups = len(groups)

best_link = None

for pos, group in enumerate(groups):
    if num_groups - pos >= need_day:
        for subject in group.subjects:
            for weight in range(subject.low, subject.high + 1):
                subject.add_link(Link(subject, weight, weight, 1, None))
    for subject in group.subjects:
        for i, links in enumerate(subject.day_links):
            weight = subject.low + i
            for day, link in links.items():
                if day == need_day:
                    if not best_link or best_link.total < link.total:
                        best_link = link
                    continue
                for next_weight in [ weight + more, weight * more ]:
                    max_pos = num_groups + day - need_day
                    for next_pos in range(pos + 1, max_pos + 1):
                        for next_subject in groups[next_pos].subjects:
                            if next_weight < next_subject.low:
                                continue
                            if next_weight > next_subject.high:
                                continue
                            next_subject.add_link(Link(
                                next_subject, next_weight,
                                next_weight + link.total, day + 1, link))

if best_link:
    print('YES')
    schedule = need_day * [ None ]
    link = best_link
    while link:
        subject = link.subject
        subject.weight = link.weight
        schedule[link.day - 1] = subject
        link = link.previous
    for subject in schedule:
        print(subject.id, subject.weight)
    import sys
    sys.exit()
else:
    print('NO')


n, p = [int(x) for x in input().split()]
a = [0 if len(input()) == 4 else 1 for i in range(n)]
num = ans = 0
for i in range(n - 1, -1, -1):
    if a[i]:
        ans += p * num
        ans += p // 2
        num = num * 2 + 1
    else:
        ans += p * num
        num *= 2
print(ans)


import sys
#sys.stdin = open('game.in', 'r')
#sys.stdout = open('game.out', 'w')

line = raw_input().split(' ')
A, B, N = int(line[0]), int(line[1]), int(line[2])
N -= 1

nl = 0
list = [0]*100
while 1 == 1:
	curb = nl + 1
	le, ri = 1, N
	while le < ri:
		cura = (le+ri+1)//2
		if (cura**curb <=N):
			le = cura
		else:
			ri = cura-1;
	if (le > 1):
		nl += 1
		list[nl] = le
	else:
		break

win = [[-1]]
cb = nl
for i in range(1, 50000):
	win.append([])
	while (cb > 0) and (i > list[cb]):
		cb -= 1
	for j in range(cb+5):
		win[i].append(-1);

def get(win, list, nl, a, b, n):
	if (a == 1) and (b > nl):
		return 3
	if (a > list[b]):
		return 1
	if (b == 1) and (a > list[2]):
		if ((a&1) != (n&1)):
			return 1
		else:
			return 2
	if (win[a][b] != -1):
		return win[a][b]
	x, y = get(win, list, nl, a+1, b, n), get(win, list, nl, a, b+1, n)
	if (x == 2) or (y == 2):
		win[a][b] = 1
		return 1
	if (x == 3) or (y == 3):
		win[a][b] = 3
		return 3
	win[a][b] = 2
	return 2

j = nl
while j > 0:
	if j == 1:
		i = list[2]
	else:
		i = list[j]
	while i > 0:
		get(win, list, nl, i, j, N)
		i -= 1
	j -= 1

ret = get(win, list, nl, A, B, N)
if (ret == 1):
	print "Masha"
if (ret == 2):
	print "Stas"
if (ret == 3):
	print "Missing"


def countDer(n):

    der = [0 for i in range(max(3,(n + 1)))]

    # Base cases
    der[0] = 1
    der[1] = 0
    der[2] = 1

    for i in range(3, n + 1):
        der[i] = (i - 1) * (der[i - 1] +
                            der[i - 2])

    return der[n]

def nCr(n, r):
    return (fact(n) / (fact(r)
                       * fact(n - r)))

# Returns factorial of n
def fact(n):
    res = 1

    for i in range(2, n + 1):
        res = res * i

    return res
n,k=map(int,input().split())
j=(n-k)
s=0
while(j<=n):
    s+=(nCr(n,j)*(countDer(n-j)))
    j+=1
print(int(s))


lines = [tuple(map(int,input().split())) for i in range(8)]
x_set = set()
y_set = set()

for x, y in lines:
    x_set.add(x)
    y_set.add(y)

if len(x_set) == len(y_set) == 3:
    flag = False
    x_sort, y_sort = sorted(x_set), sorted(y_set)
    for x in x_sort:
        for y in y_sort:
            if(x, y) != (x_sort[1], y_sort[1]) and (x, y)not in lines:
                flag = True

else:
    flag = True

print ("ugly" if flag else "respectable")


from collections import Counter as c

t = int(input())

for _ in range(t):
    n, k, d = map(int, input().split())
    a = list(map(int, input().split()))
    if d == 1:
        print(1)
    else:
        cur = a[:d]
        count = c(cur)
        ans = len(count)
        for i in range(d, n):
            if a[i] in count:
                count[a[i]] += 1
            else:
                count[a[i]] = 1

            if count[a[i-d]] != 1:
                count[a[i-d]] -= 1
            else:
                del count[a[i-d]]
            ans = min(ans, len(count))
        print(ans)


white = 0
black = 0

A =  [None]*8
for i in xrange(8):
    A[i] = raw_input()

for i in xrange(8):
    for j in xrange(8):

        if A[i][j] == "Q":
            white = white + 9
        if A[i][j] == "R":
            white = white + 5
        if A[i][j] == "B":
            white = white + 3
        if A[i][j] == "N":
            white = white + 3
        if A[i][j] == "P":
            white = white + 1

        if A[i][j] == "q":
            black = black + 9
        if A[i][j] == "r":
            black = black + 5
        if A[i][j] == "b":
            black = black + 3
        if A[i][j] == "n":
            black = black + 3
        if A[i][j] == "p":
            black = black + 1

if black == white:
    print "Draw"

if black > white:
    print "Black"

if black < white:
    print "White"


N, mod = map(int, input().split())

two = [1] * (N+1)
fact = [1] * (N+1)
inv = [1] * (N+1)
for i in range(1, N+1):
    two[i] = two[i-1]*2 % mod
for i in range(2, N+1):
    fact[i] = fact[i-1] * i % mod
inv[N] = pow(fact[N], mod-2, mod)
for i in range(N, 0, -1):
    inv[i-1] = inv[i] * i % mod

dp = [[0] * (N+2) for _ in range(N+2)]
dp[0][0] = 1
for i in range(N):
    for j in range(i+1):
        for k in range(1, N+1):
            if i+k > N:
                break
            dp[i+k+1][j+1] += dp[i][j] * two[k-1] * inv[k] % mod
            dp[i+k+1][j+1] %= mod

ans = 0
for j in range(1, N+1):
    ans += dp[N+1][j] * fact[N-j+1] % mod
    ans %= mod
print(ans)


n = input()
a,f = [[] for _ in xrange(n+1)],[0]*(n+1)
for k in xrange(2,n):
    for x in xrange(1,n):
        z = x*k+(k*k-k>>1)
        if z>n: break
        a[z].append((k,x))
q,s = [n],set([n])
for j in q:
    l = set([])
    for k,x in a[j]: l.update(range(x,x+k))
    q.extend(l-s)
    s |= l
q = lambda(k,x): reduce(int.__xor__,f[x:x+k],0)
for i in sorted(s): f[i]=next(j for j in xrange(n) if j not in set(map(q,a[i])))
print min(p[0] for p in a[n] if q(p)==0) if f[n] else -1


s=raw_input()
ans=0
for i in range(0,len(s)):
	if(s[i]>='a' and s[i]<='z'):
		ans-=ord(s[i])-ord('a')+1
	elif(s[i]>='A' and s[i]<='Z'):
		ans+=ord(s[i])-ord('A')+1
print ans


def solution1157a():
    x = int(input())
    if x == 0:
        numbers = 10
    elif x < 10:
        numbers = 9
    else:
        numbers = 10
        while x >= 10:
            n = x % 10
            if n != 9:
                numbers += 9 - n
            x //= 10

    print(numbers)

if __name__ == '__main__':
    solution1157a()


#
# Yet I'm feeling like
# 	There is no better place than right by your side
# 		I had a little taste
# 			And I'll only spoil the party anyway
# 				'Cause all the girls are looking fine
# 					But you're the only one on my mind

import sys
inf = float("inf")
#sys.setrecursionlimit(1000000)

# 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,MOD=1000000007,998244353
# vow=['a','e','i','o','u']
# dx,dy=[-1,1,0,0],[0,0,1,-1]

#from cmath import sqrt
# from collections import deque, Counter, OrderedDict,defaultdict
# from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
# from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd,log10,atan,tan
#from bisect import bisect_left,bisect_right
#import numpy as np

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

n=int(input())
Arr=get_array()
A=0;B=0
for i in reversed(Arr):
    A+=i
    if A>B:
        A,B=B,A
print(A,B)


n,m = map(int , raw_input().split())
s = map(int , raw_input().split())
print max(0,max(s[i]-s[i+1] for i in range(n-1))-m)


from __future__ import division

import math
import os
from io import BytesIO

input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
range = xrange

MOD = 998244353
MODF = float(MOD)
SHRT = float(1 << 16)
ROOT = 3.0

fmod = lambda x: x - MODF * math.trunc(x / MODF)
mod_prod = lambda a, b: fmod(math.trunc(a / SHRT) * fmod(b * SHRT) + (a - SHRT * math.trunc(a / SHRT)) * b)

def fpow(x, y):
    res = 1.0
    while y > 0:
        if y & 1 == 1:
            res = mod_prod(res, x)
        if y > 1:
            x = mod_prod(x, x)
        y >>= 1

    return res

def ntt(a, inv=False):
    n = len(a)
    w = [1.0] * (n >> 1)

    w[1] = fpow(ROOT, (MOD - 1) // n)
    if inv:
        w[1] = fpow(w[1], MOD - 2)

    for i in range(2, (n >> 1)):
        w[i] = mod_prod(w[i - 1], w[1])

    rev = [0] * n
    for i in range(n):
        rev[i] = rev[i >> 1] >> 1
        if i & 1 == 1:
            rev[i] |= (n >> 1)
        if i < rev[i]:
            a[i], a[rev[i]] = a[rev[i]], a[i]

    step = 2
    while step <= n:
        half, diff = step >> 1, n // step
        for i in range(0, n, step):
            pw = 0
            for j in range(i, i + half):
                v = mod_prod(w[pw], a[j + half])
                a[j + half] = a[j] - v
                a[j] += v
                pw += diff

        step <<= 1

    if inv:
        inv_n = fpow(n, MOD - 2)
        for i in range(n):
            a[i] = mod_prod(a[i], inv_n)

def conv(a, b):
    s = len(a) + len(b) - 1
    n = 1 << s.bit_length()

    a.extend([0.0] * (n - len(a)))
    b.extend([0.0] * (n - len(b)))

    ntt(a)
    ntt(b)

    for i in range(n):
        a[i] = mod_prod(a[i], b[i])

    ntt(a, inv=True)
    del a[s:]

def main():
    N, _ = input().split()
    n = int(N) >> 1

    d = [0.0] * 10
    for i in input().split():
        d[int(i)] = 1.0

    result = [1.0]
    while n > 0:
        if n & 1 == 1:
            conv(result, d[:])
        conv(d, d[:])
        n >>= 1

    os.write(1, str(int(sum(mod_prod(i, i) for i in result) % MODF)))

if __name__ == '__main__':
    main()


# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="yaroslav"
__date__ ="$02.08.2011 18:00:13$"
def udobno(rukad, rukam):
    return rukam<=rukad*2+2 and rukam >= rukad-1

if __name__ == "__main__":
    params = raw_input().rsplit(' ')
    al = int(params[0])
    ar = int(params[1])
    params = raw_input().rsplit(' ')
    bl = int(params[0])
    br = int(params[1])
    if udobno(al,br) or udobno(ar,bl):
        print "YES"
    else: print "NO"


x,k = map(int,input().split())
mod = 10**9 + 7
if x == 0:
    print(0)
else:
    print(((2*x-1)*pow(2,k,mod) + 1)%mod)


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

a, b, c = R()

m = min(a, b)
a -= m
b -= m

print c * 2 + m * 2 + min(1, max(a, b))


#!/usr/bin/env python
# coding=utf-8
from sets import Set
alpha = 'abcdefghijklmnopqrstuvwxyz'
n, q = map(int, raw_input().split())
rec = {}
dp = {k: Set() for k in xrange(1, 7)}

for t in alpha:
    rec[t] = Set()

for _ in xrange(q):
    a, b = map(str, raw_input().split())
    rec[b].add(a)

if len(rec["a"]):
    dp[1].add("a")
    for i in xrange(2, n + 1):
        for ele in dp[i - 1]:
            newstr = ele[0]
            for j in rec[newstr]:
                s = j +  ele[1:]
                dp[i].add(s)
    print len(dp[n])
else:
    print 0


N = 1001
num = [False for _ in range(N)]
n = int(raw_input())
cubes = []
for i in range(n):
    cur_cube = map(int, raw_input().split())
    cubes.append(cur_cube)

# enumerate the number of cubes used
# 3
if n >= 3:
    perms = [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]
    for perm in perms:
        for num1 in cubes[perm[0]]:
            if num1 == 0:
                continue
            for num2 in cubes[perm[1]]:
                for num3 in cubes[perm[2]]:
                    cur_num = 100 * num1 + 10 * num2 + num3
                    num[cur_num] = True
if n >= 2:
    if n == 3:
        perms = [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]]
    else:
        perms = [[0, 1], [1, 0]]
    for perm in perms:
        for num1 in cubes[perm[0]]:
            if num1 == 0:
                continue
            for num2 in cubes[perm[1]]:
                cur_num = 10 * num1 + num2
                num[cur_num] = True
if n >= 1:
    # select one cube
    for i in range(n):
        for num1 in cubes[i]:
            num[num1] = True

ans = 0
for i in range(1, N):
    if num[i] is False:
        ans = i - 1
        break
print ans


import sys

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

if n == 0 and m != 0:
    print "Impossible";
    sys.exit();

maxi = n + m - min(1, m);
mini = n + m - min(m, n);
sys.stdout.write("%d %d\n" % (mini, maxi));


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

a = sum(a)
b = sum(b)

if a>=b:
    print('Yes')
else:
    print('No')


n, m = map(int, input().split(" "))
h = [1 if i == ">" else -1 for i in list(input())]
v = [1 if i == "v" else -1 for i in list(input())]

connected = True

for a in range(n):
    for b in range(m):
        vi = [[0 for i in range(m)] for j in range(n)]
        s = [(a, b)]

        while len(s) > 0:
            x, y = s.pop()
            if vi[x][y] == 1:
                continue
            vi[x][y] = 1
            i = x + v[y]
            if 0 <= i < n:
                s.append((i, y))
            j = y + h[x]
            if 0 <= j < m:
                s.append((x, j))

        for i in range(n):
            for j in range(m):
                if vi[i][j] == 0:
                    connected = False
        if not connected:
            break
    if not connected:
        break

print("YES" if connected else "NO")


from math import gcd
t, a, b = list(map(int, input().split()))

if a > b:
    a, b = b, a
lcmab = a * b // gcd(a, b)
res = (t // lcmab + 1) * a - 1
lmax = t // lcmab * lcmab + a - 1
if lmax > t:
    res -= lmax - t
gcdrt = gcd(res, t)
print("{}/{}".format(res // gcdrt, t // gcdrt))


from collections import Counter
s=raw_input()

def solve(s):

    a=[chr(i) for i in range(65,91)]

    if len(s)<26:
        return -1

    if "?" not in s:
        flag=False
        for i in range(len(s)-25):
            freq=Counter(s[i:i+26])

            if len(freq)==26:
                flag=True
                return s[i:i+26]

        if flag==False:
            return -1

    else:
        flag=False
        for i in range(len(s)-25):
            x=s[i:i+26]
            y=s[i:i+26]
            freq=Counter(x)
            for keys,vals in freq.items():
                if keys!="?" and vals>1:
                    flag=True
                    break
            if flag==False:
                while "?" in x:
                    for i in a:
                        if i not in x:
                            x=x.replace("?",i,1)
                s=s.replace(y,x)
                s=s.replace("?","A")
                return s
            else:
                flag=False
        return -1
print solve(s)


f = lambda: map(int, input().split())
n, m = f()
t = list(f())
s = [0] * 301
d = s[:]
for i in t: d[i] += 1
for i in t * min(m, 2 * n): s[i] = max(s[:i + 1]) + 1
print(max(s) + max((m - n * 2) * max(d), 0))


import re

line=input()

line = line.rstrip('.')
a, b, c = line.partition("):-")
rels = c.split(',')

relations = set()
for rel in rels:
    if "<" in rel:
        x, _, y = rel.partition("<")
        relations.add((len(x), len(y)))
    else:
        x, _, y = rel.partition(">")
        relations.add((len(y), len(x)))

a = a.lstrip("?(")
args = re.split(r"(\+|-|\*|/)", a)
args = [len(args[i]) for i in range(0, len(args), 2)]

# print(args)
# print(relations)

edges = {k:[] for k in args}
for j, i in relations:
    edges[i].append(j)

seen = {k:0 for k in args}

q = []

def topsort(k):
    if seen[k] == 1:
        print("false")
        quit()
    seen[k] = 1
    for other in edges[k]:
        topsort(other)
    q.append(k)
    seen[k] = 2
    return True

for k in args:
    if seen[k] == 0:
        topsort(k)

vals = {}

for k in q:
    others = edges[k]
    maxval = -1
    for other in others:
        maxval = max(maxval, vals.get(other, -1))
    vals[k] = maxval+1
    if(vals[k]>9):
        print("false")
        quit()

for k in args:
    print(vals[k], end='')

print()


n = int(input())
a = list(map(int,input().split()))
print('NO' if any(abs(a[i]-a[i+1])>1 for i in range(n-1)) else 'YES')


n, c = map(int, input().split())
p = list(map(int, input().split()))
t = list(map(int, input().split()))

lim_score = 0
lim_penalty = 0
for i in range(n):
    lim_penalty += t[i]
    lim_score += max(0, p[i] - lim_penalty * c)

rad_score = 0
rad_penalty = 0
for i in range(n - 1, -1, -1):
    rad_penalty += t[i]
    rad_score += max(0, p[i] - rad_penalty * c)

if lim_score == rad_score:
    print("Tie")
elif lim_score > rad_score:
    print("Limak")
else:
    print("Radewoosh")


import array

p = 1000000007

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

d = array.array('i', (1 for _ in range(300001)))
td = array.array('i', (0 for _ in range(300001)))
L = b[0]
for i in range(1, n):
	if a[i - 1] != 1:
		t = m % a[i - 1]
		if L < t:
			print(0)
			exit(0)
		m //= a[i - 1]
		for j in range((L - t) // a[i - 1] + 1):
			d[j] = d[t]
			t += a[i - 1]
		L = j
	k = 0
	for j in range(L + b[i] + 1):
		if j <= L:
			k += d[j]
		k %= p
		td[j] = k
		if j >= b[i]:
			k -= d[j - b[i]]
	L += b[i]
	d, td = td, d
print(d[m] if m <= L else 0)


def main():
    n, k = map(int, raw_input().split())
    c = [0, 1, 2]
    for i in xrange(3, 51):
        c.append(c[-1] + c[-2])
    k -= 1
    ans = []
    i = 0
    while i < n:
        for j in xrange(i + 1, n + 1):
            if c[n-j] > k:
                ans.extend(range(i, j)[::-1])
                i = j
                break
            else:
                k -= c[n-j]
        else:
            ans.extend(range(i, n)[::-1])
            break
    for x in ans:
        print x + 1,
main()


n = int(input())

v = list(map(int, input().split(" ")))
v.sort()
for i in range(n):
    if v[i] + v[i + 1] > v[i + 2]:
        print("YES")
        break
    elif i + 2 == n - 1:
        print("NO")
        break


x1, y1, x2, y2 = map(int, input().split())
x3, y3, x4, y4 = map(int, input().split())
x5, y5, x6, y6 = map(int, input().split())
if (x1 < x3 and x1 < x5) or (y1 < y3 and y1 < y5) or (x2 > x4 and x2 > x6) or (y2 > y4 and y2 > y6):
    print("YES")
    exit()
def check_line(c1, c2, c3, c4, c5, c6):
    if c1 < c5 and c2 > c4 and c5 > c4:
        print("YES")
        exit()
    if c1 < c3 and c2 > c6 and c6 < c3:
        print("YES")
        exit()
def check_corner(x, y, a, b, c, d):
    return x >= a and x <= c and y >= b and y <= d
check_line(x1, x2, x3, x4, x5, x6)
check_line(y1, y2, y3, y4, y5, y6)
if not (check_corner(x1, y1, x3, y3, x4, y4) or check_corner(x1, y1, x5, y5, x6, y6)):
    print("YES")
    exit()
if not (check_corner(x2, y1, x3, y3, x4, y4) or check_corner(x2, y1, x5, y5, x6, y6)):
    print("YES")
    exit()
if not (check_corner(x2, y2, x3, y3, x4, y4) or check_corner(x2, y2, x5, y5, x6, y6)):
    print("YES")
    exit()
if not (check_corner(x1, y2, x3, y3, x4, y4) or check_corner(x1, y2, x5, y5, x6, y6)):
    print("YES")
    exit()
print("NO")


n,k=map(int,input().split())
time=240-k
i=1
while time>=5*i and i<=n:
    time-=i*5
    i+=1
print(i-1)


q = 998244353
from functools import lru_cache

mod = 998244353
mx = 505
fac = [1] * mx
for i in range(1, mx):
    fac[i] = fac[i - 1] * i % mod
ifac = [1] * 505
ifac[-1] = pow(fac[-1], mod - 2, mod)
for i in range(mx - 2, 0, -1):
    ifac[i] = (i + 1) * ifac[i + 1] % mod
def comb(a, b):
    return fac[a] * ifac[a - b] % mod * ifac[b] % mod

@lru_cache(None)
def f(n,x):
    if x<=n-1:
        return pow(x,n,q)
    s = pow(n-1,n,q)
    for i in range(2,n+1):
        s += f(i,x-(n-1))*comb(n,i)*pow(n-1,n-i,q)
        s%=q
    return s
n,x = map(int,input().split())
print(f(n,x))


dp = {}
def yo(a, b, i, j):
	if min(a, b, i, j) < 0: return 0
	if a == 0 and b == 0: return 1
	x = (a, b, i, j)
	if x not in dp: dp[x] = (yo(a - 1, b, i - 1, k2) + yo(a, b - 1, k1, j - 1)) % 10 ** 8
	return dp[x]
a, b, k1, k2 = map(int, input().split());
print(yo(a, b, k1, k2))


import sys
n=input()
if n<3:
	print n
	sys.exit()
if n==3:
	print 6
	sys.exit()
mx=n
def gcd(a,b):
	if a%b==0:
		return b
	return gcd(b,a%b)
def lcm(a,b):
	return a*b/gcd(a,b)
a=lcm(lcm(n,n-1),n-2)
b=lcm(lcm(n-1,n-2),n-3)
c=lcm(lcm(n,n-1),n-3)
print max(a,max(b,c))


n=input()
s=2*(n/3)
if(n%3):
	s+=1
print s


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

def dn(x):
  k=0
  t=x-1
  while t:
    t/=10
    k+=1
  return k

def _li(x, dn):
  ret=[]
  for _ in xrange(dn):
    ret.append(x%10)
    x/=10
  return ret

def li(h,m):
  return _li(h,dh)+_li(m,dm)

def dif(h1,m1,h2,m2):
  return sum(v1!=v2 for v1,v2 in zip(li(h1,m1), li(h2,m2)) )

pow10=[10**i for i in xrange(12,-1,-1)]

memo={}

def g(h,m):
  if (h,m) in memo:return memo[(h,m)]
  ret=f(0,1,h,m)+(1>=k)
  memo[(h,m)]=ret
  return ret

def f(h1,m1,h2,m2):
  if (h1,m1)==(h2, m2):ret = 0
  elif (h1,m1)>(h2,m2):
    ret = f(h1, m1, H-1, M-1) + f(0, 0, h2, m2) + ( dif(H-1,M-1,0,0) >= k)
  else:
    for hh in pow10:
      if (h1+hh, m1)<=(h2, m2) and h1/hh%10!=9:
        ret = g(hh,0)+f(h1+hh, m1, h2, m2)
        break
    else:
      for mm in pow10:
        if m1+mm<M and (h1,m1+mm)<=(h2,m2) and m1/mm%10!=9:
          ret = g(0,mm) + f(h1,m1+mm, h2, m2)
          break
      else:
        nt=h1*M+m1+1
        nh,nm=nt/M,nt%M
        ret = ( dif(h1,m1,nh,nm)>=k ) + f(nh,nm,h2,m2)
  #print h1,m1,h2,m2,ret
  return ret

def main():
  global H,M,k,dh,dm
  H,M,k=readints()
  h1,m1=readints()
  h2,m2=readints()
  """H,M,k=24,60,1
  h1,m1=0,0
  h2,m2=23,59
  H,M,k=24,60,3
  h1,m1=23,59
  h2,m2=23,59"""
  dh=dn(H)
  dm=dn(M)
  print f(h1,m1,h2,m2)

main()


from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))

def solve(a):
    count = 0
    for i in range(2):
        for j in range(2):
            if a[i][j] == 1:
                count += 1
    if count == 0:
        return 0
    if count == 4:
        return 2
    return 1

if __name__ == "__main__":
    for _ in tests():
        a = mat_in(2)
        out(solve(a))


k,r=map(int,raw_input("").split())
for i in range(1,100):
    s=i*k%10
    if s==r or s==0:
        break
print i


from sys import stdin

code = stdin.readline()[:-1]
keys = [stdin.readline()[:-1] for i in range(10)]
rv = ''

for i in range(8):
  for j in range(10):
    if code.startswith(keys[j]):
      rv += str(j)
  code = code[10:]

print rv


def main():
    n = int(input())
    print((pow(3, n - 1, 1000003)) if n else 1)

if __name__ == '__main__':
    main()


n = int(input())
a = oct(n)

print(a.count('1'))


a,b,f,k=map(int,input().split())
fuel=b-f
c,d=0,[(a-f)<<1,(f)<<1]
flag=1
for i in range(k):
    if fuel<0:
        flag=0
        break
    dis=d[i&1]*(1 if i!=k-1 else 0.5)
    if fuel<dis:
        fuel=b
        c+=1
    fuel-=dis
if fuel<0:
    flag=0
print(c if flag else "-1")


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

def main():
    mod = 10**9 + 7
    n = input()
    a = I()

    c = [[0]*(n+1) for i in range(n+1)]
    for i in xrange(n+1):
        c[i][0] = c[i][i] = 1
        for j in xrange(1,i):
            c[i][j] = (c[i-1][j-1] + c[i-1][j]) % mod

    dp = [[0]*(n+1) for i in range(11)]

    for i in xrange(a[9],n+1):
        dp[9][i] = 1

    for i in xrange(8,-1,-1):
        for j in xrange(n+1):
            for k in xrange(j-a[i]+1):
                if i > 0:
                    dp[i][j] += dp[i+1][k] * c[j][k]
                elif j > 0 and k > 0:
                    dp[i][j] += dp[i+1][k] * c[j-1][k-1]

    print sum(dp[0][i] for i in xrange(1,n+1)) % mod

if __name__ == '__main__':
    main()


a, b, c = map(int, input().split())
x = min(a, b, c)
z = max(a, b, c)
y = a + b + c - z - x
if (2 * (x + y) <= z):
    print(x + y)
else:
    print((x + y + z) // 3)


a = []
c = input()
s = 1
a = list(map(int, list(c)))
if sum(a) % 4 == 0:
  print(c)
else:
  while s % 4 != 0:
    c = int(c)
    c += 1
    c = str(c)
    a = list(map(int, list(c)))
    s = sum(a)
  print(int(c))


r1, r2 = map(int, input().split())
c1, c2 = map(int, input().split())
d1, d2 = map(int, input().split())

found = False

for i in range(1, 10):
    if found:
        break
    for j in range(1, 10):
        if found:
            break
        for k in range(1, 10):
            if found:
                break
            for l in range(1, 10):
                if i + j == r1 and k + l == r2 and i + l == d1 and j + k == d2 and i + k == c1 and j + l == c2:
                    if len(set([i, j, k, l])) == 4:
                        print(i, j)
                        print(k, l)
                        found = True
                        break

if not found:
    print(-1)


n, m = map(int, input().split())
lst = []
for i in range(n):
    sublst = list(input())
    lst.append(sublst)

# print(lst)
# print(lst[0])
# print(lst[0][0])
pigs = 0
for i in range(n):
    for j in range(m):
        if lst[i][j] == 'P':
            if j + 1 < m and lst[i][j + 1] == 'W':
                pigs += 1
                lst[i][j + 1] = '.'
            elif j - 1 > -1 and lst[i][j - 1] == 'W':
                pigs += 1
                lst[i][j - 1] = '.'
            elif i + 1 < n and lst[i + 1][j] == 'W':
                pigs += 1
                lst[i + 1][j] = '.'
            elif i - 1 > -1 and lst[i - 1][j] == 'W':
                pigs += 1
                lst[i - 1][j] = '.'

print(pigs)


n, a , b = map ( int, input(). split())
for i in range(1, max ( a, b ) + 2):
    if (a//i+b//i>=n) and min(a, b)>=i:
        continue
    else:
        break
print(i-1)


n,chips=map(int,input().split())
x=(n*(n+1))//2
#print(x)
if(chips>x):
    chips=chips%x

for i in range(1,n+1):
    if(i>chips):
        break
    else:
        chips-=i
print(chips)


n = int(input())
s1 = 0
s2 = 0
odd_even_pair = False
in_l1= False
in_l2= False
for _ in range(n):
    l = list(map(int, input().rstrip().split(" ")))
    s1+=l[0]
    s2+=l[1]
    if l[1]%2 and not l[0]%2:
        odd_even_pair= True
        in_l2 = True
    if l[0]%2 and not l[1]%2:
        odd_even_pair= True
        in_l1=True
if s1%2 and s2%2:
    if odd_even_pair:
        print(1)
    else:
        print(-1)
elif s1%2 and not s2%2:
    print(-1)
elif s2%2 and not s1%2:

    print(-1)
else:
    print(0)


a1,b1,c1 = [int(x) for x in input().split()]
a2,b2,c2 = [int(x) for x in input().split()]

alwaysGood = False
alwaysBad = False

if a1 == 0 and b1 == 0:
    if c1 == 0:
        alwaysGood = True
    else:
        alwaysBad = True
if a2 == 0 and b2 == 0:
    if c2 == 0:
        alwaysGood = True
    else:
        alwaysBad = True

if alwaysBad:
    print(0)
elif alwaysGood:
    print(-1)
else:
    if a1*b2 == a2*b1:
        if a1 != 0:
            c1 *= a2
            c2 *= a1
        else:
            c1 *= b2
            c2 *= b1
        if c1 == c2:
            print(-1)
        else:
            print(0)
    else:
        print(1)


MOD = (10**9) + 7

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

def find_ks(l, r):
    num_elems = (r-l+1)
    num_trips = int(num_elems / 3)
    k = [num_trips] * 3

    start_idx = l % 3
    count = num_elems % 3

    for i in range(count):
        k[(start_idx + i)%3] += 1

    return k

k = find_ks(l, r)
f = [[0 for _ in range(3)] for _ in range(n)]

for mod in range(3):
    f[0][mod] = k[mod]

# print(k)
for idx in range(1, n, 1):
    # print(idx)
    for mod in range(3):
        f[idx][mod] += ( f[idx-1][mod] * k[0] ) % MOD
        f[idx][mod] = f[idx][mod] % MOD

        f[idx][mod] += ( f[idx-1][(mod - 1) % 3] * k[1] ) % MOD
        f[idx][mod] = f[idx][mod] % MOD

        f[idx][mod] += ( f[idx-1][(mod - 2) % 3] * k[2] ) % MOD
        f[idx][mod] = f[idx][mod] % MOD

# print(f)

print(f[n-1][0] % MOD)


n, m, a, b = map(int, input().split())
if m * a <= b:
	print(n * a)
else:
	print((n // m) * b + min((n % m) * a, b))


import sys

def Min(x, y):
    if x > y:
        return y
    else:
        return x

def Gcd(x, y):
    if x == 0:
        return y
    else:
        return Gcd(y % x, x)

def Lcm(x, y):
    return x * y // Gcd(x, y)

n = int(input())
a = [int(i) for i in input().split()]
d = [int(0) for i in range(0, n)]

ok = 0

cur = 0

len = Lcm(7, n)

for i in range(0, 7 * n):
    if a[i % n] == 0 :
        print(i % n + 1)
        ok = 1
        break
    if cur != 6:
        a[i % n] -= 1
        d[i % n] += 1
    cur = (cur + 1) % 7

if ok == 0:
    k = 10**20

    for i in range(0, n):
        a[i] += d[i]
        if d[i] == 0: continue
        if a[i] % d[i] > 0:
            k = Min(k, a[i] // d[i])
        else:
            k = Min(k, a[i] // d[i] - 1)

    if k == 10**20:
        k = 0

    for i in range(0, n):
        a[i] -= k * d[i]

    iter = 0
    cur = 0

    while True:
        if a[iter] == 0:
            print(iter % n + 1)
            break
        else:
            if cur != 6:
                a[iter] -= 1
            cur = (cur + 1) % 7
            iter = (iter + 1) % n


def b(n):
  ans = [n]
  for x in xrange(2, n+1):
    while n % x == 0:
      n /= x
      ans.append(n)
  return ' '.join(map(str, ans))

"""
print b(10)
print b(4)
print b(3)
"""
print b(int(raw_input()))
#"""


n=input()

def is_power_of_2(n):
    while n>1:
        if n % 2 == 1:
            return False
        else:
            n = n/2
    return True

if n%2==1:
    answer=(n-1)/2
elif is_power_of_2(n):
    answer=0
else:
    i=0
    while 2**i<n:
        i+=1
    i-=1
    answer=(n-2**i)/2

print answer


#http://codeforces.com/problemset/problem/624/A

d, l, v1, v2 = map(float, raw_input().split())

result = (l - d)/(v1 + v2)

print "%.20f" % result


s = input()
for i in range(1, len(s)+1):
    if s == s[i:]+s[:i]:
        print(i)
        break


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

n, L = mi()
C = li()
for i in range(1, n):
    C[i] = min(C[i], C[i-1] * 2)

x = 2 ** (n-1)
y = 0
z = 10 ** 18
for i in range(n-1, -1, -1):
    t = L // x
    y += C[i] * t
    z = min(z, y + C[i])
    L %= x
    x //= 2
z = min(z, y)
print(z)


n=int(input())
l=list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)
for i in l:
    d[i]+=1
a=[]
for i in set(l):
    if d[i]%2:
        a.append(i)

a.sort()
ans=0
for i in range(0,len(a),2):
    ans+=abs(a[i]-a[i+1])

print(ans)


n, p, t = input().split()
n, p = int(n), float(p)
f = [p] * n + [0]
for i in range(int(t) - 1): f = [f[k] * (1 - p) + p * (1 + f[k - 1]) for k in range(n)] + [0]
print(f[-2])


dicts = ["Howard", "Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]

n = int(raw_input())

r = 5

#s is short for sum.
ps = 0
while  ((ps + r) <= n):
    ps += r
    r *= 2

unit = r/5
remain = n - ps

print dicts[(remain - 1)/unit + 1]


R = lambda : map(int, raw_input().split())
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
d = int(raw_input())
if(c!=0):
    if a!=0 and d!=0 and a==d: print 1
    else: print 0
elif(a==d): print 1
else: print 0


import sys
input = sys.stdin.readline

l = 255
mod = 998244353
fact = [1] * (l + 1)
for i in range(1, l + 1):
    fact[i] = i * fact[i - 1] % mod
inv = [1] * (l + 1)
inv[l] = pow(fact[l], mod - 2, mod)
for i in range(l - 1, -1, -1):
    inv[i] = (i + 1) * inv[i + 1] % mod

n, k = map(int, input().split())
dp0 = [0] * n
dp0[0] = 1
for i in range(k):
    dp = [0] * n
    p = [1]
    for j in range(n * (n + 1) // 2):
        p.append((i + 1) * p[-1] % mod)
    for j in range(n):
        c = 0
        if not dp0[j]:
            continue
        dp0j = dp0[j]
        for l in range(j, n):
            dp[l] += p[c] * inv[l - j] % mod * dp0j % mod
            dp[l] %= mod
            c += n - l - 2
    dp0 = dp
ans = dp0[-1] * fact[n - 1] % mod
print(ans)


from __future__ import division, print_function
import __pypy__

add = __pypy__.intop.int_add
sub = __pypy__.intop.int_sub
mul = __pypy__.intop.int_mul

def main():
    from collections import deque

    def printMin(arr, n, k):
        res=[]
        Qi = deque()
        for i in range(k):
            while Qi and arr[i] <= arr[Qi[-1]] :
                Qi.pop()
            Qi.append(i);

        for i in range(k, n):
            res.append(arr[Qi[0]])
            while Qi and Qi[0] <= i-k:
                Qi.popleft()
            while Qi and arr[i] <= arr[Qi[-1]] :
                Qi.pop()
            Qi.append(i)
        res.append(int(arr[Qi[0]]))
        return res
    n,m,a,b=map(int,input().split())
    g,x,y,z=map(int,input().split())

    zinv = 1.0/z

    def modmuladd(x,y,c):
        ans = sub(add(mul(x,y),c), mul(z, int(zinv*x*y + zinv*c)))
        if ans >= z:
            return ans - z
        elif ans < 0:
            return ans + z
        else:
            return ans

    grid= [0]*(n*m)
    grid[0]=g
    for i in range(1,n*m):
        grid[i]=modmuladd(grid[i-1],x,y)
    B=[]
    ans=0.0
    for i in range(n):
        B.append(printMin(grid[i*m:(i+1)*m],m,b))
    grid=[]
    for i in range(len(B[0])):
        temp=[]
        for j in range(n):
            temp.append(B[j][i])
        for tmp in printMin(temp,len(temp),a):
            ans += tmp
    print(int(ans))
######## Python 2 and 3 footer by Pajenegod and c1729

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

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

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

import os, sys
from io import IOBase, BytesIO

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

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

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

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

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

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

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

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

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

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

if __name__== "__main__":
  main()


# n - length of zebroid
def cnt_subzebroes(n):
        cnt = 1
        pred, pred_pred = 0, 0
        last = n - 1
        while last > 0:
                cur = pred + pred_pred + 1
                pred_pred = pred % 1000000007
                pred = cur % 1000000007
                cnt = cnt + cur + 1
                last -= 1
	return cnt % 1000000007

print cnt_subzebroes(int(input()))


n, m = map(int, input().split())
t = [n]
for i in range(1, n): t = t + [n - i] if m - 1 & 1 << i - 1 else [n - i] + t
for q in t: print(q)


n, m, k, r, c = map(int, input().split())
ax, ay, bx, by = map(int, input().split())
p = n * m
if ax != bx or ay != by:
	p -= r * c
print(pow(k, p, 1000000007))


n = int(raw_input()) % 6
endpos = int(raw_input())

sim = [0, 0, 0]
sim[endpos] = 1

for i in range(n, 0, -1):
    if i % 2 == 0:  # par
        sim[1], sim[2] = sim[2], sim[1]
    else:
        sim[1], sim[0] = sim[0], sim[1]

print sim.index(1)


y,b=map(int,input().split())
yy,g,bl=map(int,input().split())
ny=yy*2+g
nb=bl*3+g
ans=0
if (ny-y)>=0:
    ans+=(ny-y)
if (nb-b)>=0:
    ans+=(nb-b)

if ans >=0:
    print(ans)
else:
    print(0)


#!/usr/bin/env python
'''
' Author:   Cheng-Shih Wong
' Email:    mob5566@gmail.com
' Date:     2017-09-22
'''

def main():

    def num(left, right, dp, rev, revI):
        if left > right:
            return 1

        key = left, rev, revI
        if key in dp:
            return dp[key]
        nonlocal ans

        acc = 0

        for x in ('01' if ans[left]=='#' else ans[left]):

            temp = None
            if left == right:
                tmp = x
            elif ans[right]=='#':
                tmp = '01'
            else:
                tmp = ans[right]

            for y in tmp:
                if not ((rev and x>y) or (revI and x==y=='1')):
                    acc += num(
                        left+1,
                        right-1,
                        dp,
                        rev and x==y,
                        revI and x!=y
                    )
        dp[key] = acc
        return acc

    n, k = map(int, input().split())
    k += 1

    ans = ['#'] * n

    for i in range(n):
        ans[i] = '0'
        tmp = num(0, n-1, {}, True, True)

        if k > tmp:
            k -= tmp
            ans[i] = '1'

    if ans[0] == '0':
        print(''.join(ans))
    else:
        print(-1)

if __name__ == '__main__':
    import sys, os
    from time import time
    if len(sys.argv)>1 and os.path.exists(sys.argv[1]):
        sys.stdin = open(sys.argv[1], 'rb')
    st = time()
    main()
    print('----- Run {:.6f} seconds. -----'.format(time()-st), file=sys.stderr)


import fractions
N = int(input())
for i in range(N):
    x  = int(input())
    if x == 100:
        print(1)
    else:
        y = fractions.Fraction(x , 100)
        l = y.denominator
        print(l)


a=list(input())
mark='a'
for i in range(len(a)):
    if a[i]<=mark and (ord(mark) in range(ord('a'),ord('z')+1)):
        a[i]=mark
        mark=chr(ord(mark)+1)
if ord(mark)>ord('z'):
    print(''.join(a))
else:
    print(-1)


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

res = []
if a[0] % 2 == 0:
    bal = 1
else:
    bal = -1
for i in range(1, n):
    if bal == 0:
        res.append(abs(a[i] - a[i - 1]))
    if a[i] % 2 == 0:
        bal += 1
    else:
        bal -= 1

res.sort()
cnt = 0
ans = 0

while(cnt <= B):
    if ans == len(res):
        ans += 1
        break
    cnt += res[ans]
    ans += 1

print(ans - 1)


def func(n):

    if n==1:
        return 'codeforces'
    curr=1
    for i in range(2,41):
        for j in range(1,11):
            curr=(i**j)*(i-1)**(10-j)
#             print(curr)
            if curr>=n:
                return sec(i,j)

def sec(i,j):
    res=''
    s='codeforces'
    rem=10-j
    for k in range(rem):
        res+=(s[k]*(i-1))
    for k in range(rem,10):
        res+=(s[k]*(i))
    return(res)

#print(10**5)
n=int(input())
print(func(n))


class Main:
	n=int(input())
	s=n
	while(n!=1):
		i=2
		while(n%i!=0):
			i+=1
		n=n/i
		s+=n
	print s


from math import sqrt
n = input()
Min, Max = 999999999999999999L, -1

for i in range(1, int(sqrt(n)) + 1):
    if n % i == 0:
        n1 = n / i
        a = i + 1

        for j in range(1, int(sqrt(n1)) + 1):
            if n1 % j == 0:
                b = j + 2
                c = n1 / j + 2
                tmp = a * b * c - n
                Min = min(tmp,Min)
                Max = max(tmp,Max)
            j += 1

        a = n1 + 1
        for j in range(1, int(sqrt(i)) + 1):
            if i % j == 0:
                b = j + 2
                c = i / j + 2
                tmp = a * b * c - n
                Min = min(tmp,Min)
                Max = max(tmp,Max)
print Min, Max


import sys
n, a = map(int, sys.stdin.read().split())
if a & 1:
    a //= 2
else:
    a = (n - a) // 2
sys.stdout.write(str(a + 1))


# coding: utf-8

# In[36]:

import math

def UnusualSeq(a,b):
    if b%a!=0:
        print(0)
    else:
        b//=a
        d=set()
        for i in range(1,int(math.sqrt(b)+1)):
            if b%i==0:
                d.add(i)
                d.add(b//i)
        d=sorted(list(d))
        f=d[::]
        for i in range(len(f)):
            f[i]=pow(2,d[i]-1,(10**9+7))
            for j in range(i):
                if d[i]%d[j]==0:
                    f[i]-=f[j]
        print(f[-1]%(10**9+7))

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


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

def cal(mid):
    return k * mid - ((1 + mid) * mid / 2) + k - mid

if n == 1:
    print 0
elif n > (k - 1) * k / 2 + 1:
    print -1
else:
    l, r = 0, k - 2
    while r > l:
        mid = l + r >> 1
        cnt = cal(mid)
        if cnt >= n: r = mid
        else: l = mid + 1
    print r + 1


n=int(raw_input())
a=map(int,raw_input().split())
b=map(int,raw_input().split())
c,d=0,0
for i in xrange(n):
	if a[i]==1 and b[i]==0:
		c+=1
	elif a[i]==0 and b[i]==1:
		d+=1

if c==0:
	print -1
elif c<=d:
	print d//c+1
else:
	print 1


import math
n = math.ceil(int(input())/2)
listOfInt = list(map(int,input().split()))
positive = 0
negative = 0
noSolution = 0
# boolean to check if it has printed a solution, if not print 0
checkPrint = False
for i in listOfInt:
    if(i>0):
        positive+=1
        if(positive>=n):
            print(1)
            checkPrint = True
            break
    elif(i<0):
        negative+=1
        if(negative>=n):
            print(-1)
            checkPrint = True
            break
    elif(i==0):
        noSolution+=1
        if(noSolution > n):
            print(0)
            checkPrint = True
            break

if(checkPrint == False):
    print(0)


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

ans=[]

for i in range(n):
    Flag=True
    for j in range(n):
        if j!=i and Flag==True:
            for k in range(j+1,n):
                if i!=k:
                    s=0
                    for x in range(5):
                        s+=(A[j][x]-A[i][x])*(A[k][x]-A[i][x])
                    if s>0:
                        Flag=False
                        break
    if Flag==True:
        ans.append(i)

print len(ans)
if len(ans)>0:
    for i in range(len(ans)):
        print ans[i]+1


import sys

lines = []
for line in sys.stdin:
    lines.append(line)

n = int(lines[0].rstrip("\r\n\t "))

max_price = n * 2 - 1
nines = len(str(max_price + 1)) - 1

if nines < 1:
    cnt = 0
    for x in range(1, n):
        cnt += x
    print(cnt)
    exit()

price_suffix = "9"*nines
cnt = 0

def add_pairs(max_x: int, p: int):
    global cnt
    from_max = int(p / 2)
    to_max = p - 1
    if to_max > max_x:
        to_max = max_x
    from_min = p - to_max
    cnt += from_max - from_min + 1

for d in range(0, 10):
    if d > 0:
        price = int(str(d) + price_suffix)
    else:
        price = int(price_suffix)
    if price <= max_price:
        add_pairs(n, price)

print(cnt)


'''
                ___                       ____
  ____ _____ _____/ (_)_  ______  ____ _____/ / /_  __  ______ ___  __
 / __ `/ __ `/ __  / / / / / __ \/ __ `/ __  / __ \/ / / / __ `/ / / /
/ /_/ / /_/ / /_/ / / /_/ / /_/ / /_/ / /_/ / / / / /_/ / /_/ / /_/ /
\__,_/\__,_/\__,_/_/\__,_/ .___/\__,_/\__,_/_/ /_/\__, /\__,_/\__, /
                        /_/                      /____/      /____/
'''
import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')
def st(): return list(sys.stdin.readline().strip())
def li(): return list(map(int, sys.stdin.readline().split()))
def mp(): return map(int, sys.stdin.readline().split())
def inp(): return int(sys.stdin.readline())
def pr(n): return sys.stdout.write(str(n)+"\n")
def prl(n): return sys.stdout.write(str(n)+" ")

if os.path.exists('input.txt'):
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')

# joined late

def solve():
    n, m, k = mp()
    if n % 2:
        if k < m//2:
            pr('NO')
            return
        k -= m//2
        n -= 1
    elif m % 2:
        left = n*m//2 - k
        if left < n//2:
            pr('NO')
            return
        m -= 1
    pr('YES' if k % 2 == 0 else 'NO')

for _ in range(inp()):
    solve()


n = int(input())

s = input()

s = s.split()

l = list()
zeroes = 0

for i in range(n):
	if s[i] == '0':
		zeroes += 1
	else:
		if zeroes == 0:
			continue
		else:
			l.append(zeroes)
			zeroes = 0
ans = 1
for i in l:
	ans *= (i + 1)

if s.count('1') == 0:
	ans = 0
elif len(l) == 0:
	ans = 1
elif s[0] != '1':
	ans //= (l[0] + 1)

print(ans)


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


#import sys
#sys.stdin = open('in')

n = int(raw_input())
s = []
if n == 0:
    print 'O-|-OOOO'
else:
    while n > 0:
        x = n % 10
        n /= 10
        if x >= 5:
            si= '-O|'
            x-=5
        else:
            si = 'O-|'
        si += 'O'*x
        si += '-'
        si += 'O'*(4-x)
        s.append(si)
    for k in s:
        print k


m, n = map(int, raw_input().strip().split())
if m > n: m, n = n, m

if m == 1:
    r = n % 6
    q = n // 6
    if r <= 3: print 6 * q
    else: print 6 * q + 2 * (r - 3)
elif m == 2:
    if n == 2: print 0
    elif n == 3: print 4
    elif n == 7: print 12
    else: print n << 1
else:
    x = m * n
    if x & 1: x -= 1
    print x


from math import sqrt
def divisors(n,k):
    begin= []
    for i in range(1, int(sqrt(n))+1):
        if n % i is 0:
            if n//i is i:
                begin.append(i)
            else:
                begin.append(i)
                begin.append(n//i)
    begin.sort()
    size = len(begin)
    if size < k:
        print(-1)
    else:
        print(begin[k-1])

n,k = input().split()
n,k = int(n), int(k)
divisors(n,k)


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

import math

n=ii()
a=[6,8,4,2]
if n:
    ans=a[n%4]
else:
    ans=1
print(ans)


a, b, v = input(), input(), input()

t = [[-1] * len(b) for x in range(len(a))]

def g(i, j):

    if i < 0 or j < 0: return ''

    if t[i][j] == -1:

        s = g(i - 1, j - 1)

        if a[i] == b[j]: s += a[i]

        t[i][j] = max(s, g(i - 1, j), g(i, j - 1), key=lambda q: len(q) - q.count(v))

    return t[i][j]

s = g(len(a) - 1, len(b) - 1)

while v in s: s = min(s.replace(v, v[:-1]), s.replace(v, v[1:]), key=lambda q: q.count(v))

print(s if s else 0)

# Made By Mostafa_Khaled


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

maxq = minq = sergeiq = 0
if n == 1:
	maxq = k // m
	if k % m > 0:
		maxq +=1
		minq = maxq - 1
		if y <= k % m:
			sergeiq = maxq
		else:
			sergeiq = minq
	else:
		minq = maxq
		sergeiq = minq
elif n == 2:
	maxq = minq = sergeiq = k // (2*m)
	if k % (2*m) > 0:
		maxq += 1
		if x == 1 and y <= k % (2*m):
			sergeiq += 1
		elif x == 2 and k % (2*m) >= y + m:
			sergeiq += 1
elif k < n * m:
	maxq = 1
	minq = 0
	if k / m >= x:
		sergeiq = 1
	elif k / m <= x-1:
		sergeiq = 0
	elif k % m >= y:
		sergeiq = 1
	else:
		sergeiq = 0
elif k == n*m:
	maxq = 1
	minq = 1
	sergeiq = 1
else:
	maxq = 2*(k // (m * 2 * (n-1)))
	minq = k // (m * 2 * (n-1))
	if x == 1 or x == n:
		sergeiq = minq
	else:
		sergeiq = maxq
	remainder = k % (m * 2* (n-1))
	if remainder > 0:
		if remainder <= m:
			if x == 1 and y <= remainder:
				sergeiq += 1
		elif remainder <= m * n:
			maxq += 1
			if x <= remainder / m:
				sergeiq += 1
			elif x-1 < remainder / m and remainder % m >= y:
				sergeiq += 1
			if remainder == m*n:
				minq += 1
		else:
			maxq += 2
			sergeiq += 1
			minq += 1
			if x != 1 and x != n:
				if (remainder - (n*m)) / m >= n-x:
					sergeiq += 1
				elif (remainder - (n*m)) / m > n-x-1 and (remainder - (n*m)) % m >= y:
					sergeiq += 1
print(str(maxq) + ' ' + str(minq) + ' ' + str(sergeiq))


"""
Codeforces Contest 307 Div 2 Problem D

Author  : chaotic_iak
Language: Python 3.4.2
"""

################################################### SOLUTION

def multiply(M1, M2):
    if len(M1[0]) != len(M2): raise ValueError
    a = len(M1)
    b = len(M2[0])
    c = len(M1[0])
    # M1: a x c, M2: c x b, M: a x b
    ans = [[0]*b for _ in range(a)]
    for i in range(a):
        for j in range(b):
            for k in range(c):
                ans[i][j] += M1[i][k] * M2[k][j]
    return ans

def solve(n, m):
    M = [[0,1,0],[1,1,0],[0,1,2]]
    if n == 0:
        return [[1,0,0],[0,1,0],[0,0,1]]
    if n == 1:
        return M
    P = solve(n//2, m)
    S = multiply(P, P)
    if n%2: S = multiply(S, M)
    for i in range(3):
        for j in range(3):
            S[i][j] = S[i][j] % m
    return S

def main():
    n,k,l,m = read()
    kb = bin(k)[2:]
    if l == 0 and k == 0: return 1 % m
    if len(kb) > l: return 0
    kb = "0" * (l - len(kb)) + kb
    zero, one = 0, 0
    for i in kb:
        if i == "0":
            zero += 1
        else:
            one += 1

    multiplier = solve(n, m)
    _, _, ans_one = multiply(multiplier, [[1],[0],[0]])
    multiplier = multiply(multiplier, solve(2, m))
    _, ans_zero, _ = multiply(multiplier, [[1],[0],[0]])
    return (pow(ans_zero[0], zero, m) * pow(ans_one[0], one, m)) % m

#################################################### HELPERS

def read(mode=2):
    # 0: String
    # 1: List of strings
    # 2: List of integers
    inputs = input().strip()
    if mode == 0: return inputs
    if mode == 1: return inputs.split()
    if mode == 2: return list(map(int, inputs.split()))

def write(s="\n"):
    if s is None: s = ""
    if isinstance(s, list): s = " ".join(map(str, s))
    s = str(s)
    print(s, end="")

write(main())


n=input()
while not n%3:n/=3
print n/3+1


n = input()
ans = 1
for i in range(2,n+1):
	ans+=(i-1)*4
print ans


n = int(raw_input(""))

def sum(x):
    return x * (x + 1) / 2

if n < 0:
    n = -n

ans = 0
while 1:
    s = sum(ans)
    if (s - n) % 2 > 0 or (s < n):
        ans += 1
    else:
        break

print ans


st = raw_input()

ct = st.count("VK")
for i in range(len(st)):

    if st[i] == "V":
        new = st[:i] + "K" + st[i+1:]
    else:
        new = st[:i] + "V" + st[i + 1:]

    ct1 = new.count("VK")

    if ct < ct1:
        ct = ct1

print ct


from sys import stdin, stdout
import math, collections
mod = 10**9+7

def isPower(n):
    if (n <= 1):
        return True
    for x in range(2, (int)(math.sqrt(n)) + 1):
        p = x
        while (p <= n):
            p = p * x
            if (p == n):
                return True

    return False
n = int(input())
arr = [0,1,2,1,4,3,2,1,5,6,2,1,8,7,5,9,8,7,3,4,7,4,2,1,10,9,3,6,11,12]
ans = arr[int(math.log(n, 2))]
s = int(math.log(n, 2))
for i in range(3, int(n**0.5)+1):
    if not isPower(i):
        ans^=arr[int(math.log(n, i))]
        s+=int(math.log(n, i))
ans^=((n-s)%2)
print("Vasya" if ans else "Petya")


def gcd(a,b):
    while a!=b:
        if a>b:
            a=a-b
        else :
            b=b-a
    print(m//a,'/',n//a,sep='')
a,b,c,d=map(int,input().split())
m=1
n=1

if a==b:
    if c==d :
        print(0,'/',1,sep='')
    else :
        if c>d:
            m=b*c-a*d
            n=c*b
            gcd(m,n)
        else :
            m=a*d-c*b
            n=a*d
            gcd(m,n)
else:
    if c/d ==a/b:
        print(0,'/',1)
    else :
        if c/d>a/b:
            m=b*c-a*d
            n=c*b
            gcd(m,n)
        else :
            m=a*d-c*b
            n=a*d
            gcd(m,n)


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

print(1 if n*m == 1 else 1/n + (n-1) / n * (m-1) / (n*m - 1))


import math
a1,a2,a3=map(int,input().split())
b1,b2,b3=map(int,input().split())
n=int(input())
cups=(a1+a2+a3)/5
c=math.ceil(cups)
medals=(b1+b2+b3)/10
m=math.ceil(medals)
if (c+m)<=n:
    print("YES")
elif (c+m)>n:
    print("NO")


import math;
n,m = list(map(int, str(raw_input()).split()))
if(min(m,n) == 1):
    print n*m
elif(min(n,m) == 2):
    some = max(m,n)
    total = some - (some%4)
    some %= 4
    if(some == 1) or (some == 2):
        total+=some*2
    elif(some == 3):
        total += 4
    print total
else:
    print int(math.ceil(n*m/2.0))


#copyright mr.Gigola :)
nStudents, kValue = map(int,raw_input().split())
nDiplomas = (nStudents/2)/(kValue+1)
nCertificates = nDiplomas*kValue
print nDiplomas,nCertificates,nStudents-nDiplomas-nCertificates


n=int(input())
slist=list(map(int,input().split()))
total=sum(slist)
s=slist[0]
mlist=[]
for i in range(0,len(slist)):
    if(slist[i]<=(slist[0]//2)):
        s=s+slist[i]
        mlist.append(i+1)
if(s>(total//2)):
    mlist.insert(0,1)
    mlist=list(set(mlist))
    print(len(mlist))
    for i in range(0,len(mlist)):
        print(mlist[i],end=" ")
else:
    print(0)


n = int(raw_input())
a = map(int,raw_input().split())
x = 360
sum1 = 0
ans = 360
for i in range(n):
	sum1 = 0
	for j in range(i,n):
		sum1 += a[j]
		if abs(360 - 2 *sum1) < ans :
			ans = abs(360 - 2 * sum1)
print ans


for i in range(int(input())):
  a=list(map(int,input().split()))
  mx=max(list(map(abs,a)))
  std=(sum(list(map(lambda x:x*x,a)))/len(a))**0.5
  print('poisson'if mx/std>2 else'uniform')


def works(X,N,M,K):
    #in each row, how many numbers are < X
    res = 0
    n = 1
    div = X/M
    while n < div:
        res += M
        n += 1
    while n < N+1:
        res += (X-1)//n
        n += 1
    return res

def solve():
    N, M, K = [int(s) for s in input().split()]
    left = 1
    right = K+1
    #we want the smallest smallest such that there are AT LEAST K-1 smaller numbers
    while right - left > 1:
        middle = (left+right)//2
        if works(middle,N,M,K) < K:
            left = middle
        else:
            right = middle
    #if there are exactly K-1 elements less than right, then this is our answer
    return left

#for _ in range(getInt()):
print(solve())


#!/usr/bin/python

def main():
    dnk = raw_input()
    cur_nukl = dnk[0]
    counter = 0
    inner_c = 0
    for nukl in dnk:
        if nukl == cur_nukl:
            inner_c += 1
        else:
            if inner_c % 2 == 0:
                counter += 1
            cur_nukl = nukl
            inner_c = 1
    if inner_c % 2 == 0: # if last seq even
        counter += 1
    print counter

if __name__ == '__main__':
  main()


s = input()
pr = 0
ss = 0
for i in range(1, len(s)):
	if (s[i] == '0'):
		pr *= 10

	ss += pr
	pr = int(s[i])
ss += pr
print(ss + 1)


from __future__ import division
import sys
range = xrange;input = raw_input
inp = [int(x) for x in sys.stdin.read().split()]; ii = 0;n = inp[ii]; ii += 1;m = inp[ii]; ii += 1;coupl = [[] for _ in range(n)];V = [];C = []
for _ in range(m):a = inp[ii] - 1; ii += 1;b = inp[ii] - 1; ii += 1;c = inp[ii]; ii += 1;eind = len(V);C.append(c);V.append(b);V.append(a);coupl[a].append(eind);coupl[b].append(eind ^ 1)
found = [0]*n;ans = [0] * n;val0 = [0] * n;val1 = [1] * n
for root in range(n):
    if found[root]:continue
    bfs = [root];found[root] = 1
    for node in bfs:
        for eind in coupl[node]:
            nei = V[eind]
            if not found[nei]:found[nei] = 1;bfs.append(nei);c = C[eind >> 1];val0[nei] = c - val0[node];val1[nei] = -val1[node]

    for node in bfs:
        for eind in coupl[node]:
            nei = V[eind];c = C[eind >> 1]
            if val0[node] + val0[nei] != c or val1[node] + val1[nei]:
                if val1[node] + val1[nei] == 0:print 'NO';sys.exit()
                x = (c - (val0[node] + val0[nei])) / (val1[node] + val1[nei]);break
        else:continue
        break
    else:
        vals = []
        for node in bfs:vals.append(-val0[node] // val1[node])
        vals.sort();x = vals[len(vals)//2]
    for node in bfs:ans[node] = val0[node] + x * val1[node]

for node in range(n):
    for eind in coupl[node]:
        nei = V[eind];c = C[eind >> 1]
        if ans[node] + ans[nei] != c:
            print 'NO'
            sys.exit()

print 'YES'
print ' '.join(str(x) for x in ans)


entrada = int(raw_input())

interacoes = len(str(entrada))
saida = 0
soma = 9
for i in range(1,interacoes):
	saida += soma * i
	entrada -= soma
	soma = soma * 10

saida += entrada * interacoes

print saida


l=lambda:map(int,raw_input().split())
n,k=l()
base=2*n
print max(0,n-(k-base))


from math import *
a, b = map(int, raw_input().split())
brev=0
while b>0:
    brev*=10
    brev+=b%10
    b/=10
print a+brev


left, right = input().split("|")
weight = input()

left += weight

def test(left, right):
    for i in range(len(weight)+1):
        if len(left[:len(left)-i]) == len(right+weight[::-1][:i]):
            print(left[:len(left)-i] +"|" + right+weight[::-1][:i])
            return
    print("Impossible")

test(left, right)


n=int(input())
s=input()
freq={}
if n==1:
    print("YES")
else:
    for i in s:
        if i in freq:
            freq[i]+=1
        else:
            freq[i]=1
    c=0
    for i in freq:
        if freq[i]>=2:
            c=1
            print("YES")
            break
    if c==0:
        print("NO")


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

[t1,t2,x1,x2,t0]=input().split(' ')
#[t1,t2,x1,x2,t0]=[100,110,2,2,109]
t1=int(t1)
t2=int(t2)
x1=int(x1)
x2=int(x2)
t0=int(t0)

a=t2-t0
b=t0-t1

if(a==0 and b==0):
    print(x1,x2)
    exit(0)

if (a==0):
    y1=0
    y2=x2
    print(y1,y2)
    exit(0)

if (b==0):
    y1=x1
    y2=0
    print(y1,y2)
    exit(0)

g=gcd(a,b)
a=int(a/g)
b=int(b/g)
if(a<=x1 and b<=x2):
    mintime=int(x1/a)
    if(mintime>int(x2/b)):
        mintime=int(x2/b)
    print(mintime*a,mintime*b)
    exit(0)

y1=1
y2=1
miny1=1
miny2=1
minn=99999
fg=0
while(y1<=x1 and y2<=x2):
    if(y1/y2<a/b):
        if(minn>a/b-y1/y2):
            minn=a/b-y1/y2
            miny1=y1
            miny2=y2
            fg=1
        y1=y1+1
    else:
        y2=y2+1
y1=miny1
y2=miny2
mintime=int(x1/y1)
if(mintime>int(x2/y2)):
    mintime=int(x2/y2)
if(fg==1):
    print(mintime*y1,mintime*y2)
else:
    print(0,x2)


c = int(raw_input())
d = raw_input()

b = d.split(' ')
a = 0

for i in range(c):
	if int(b[i]) == 1:
		a = a+1

if a>0:
	print("HARD")
else:
	print("EASY")


import fileinput

def calc(a, b):
    ans = 0
    l = a + b
    i = 1
    while i <= l:
        P = l // i
        r = l // P
        if P <= a and P <= b:
            an = (a + P) // (P + 1)
            ax = a // P
            bn = (b + P) // (P + 1)
            bx = b // P
            if an <= ax and bn <= bx:
                ans += min(ax + bx, r) - max(an + bn, i) + 1
        i = r + 1
    return ans

if __name__ == '__main__':
    it = fileinput.input()
    a, b = [int(x) for x in next(it).split()]
    print(calc(a, b))


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)

cost = 1000000
for i in range(0,max(0,100-atky+defm)+1):
    for j in range(0,max(0,atkm-defy)+1):
        if i+atky-defm>0:
            turn = hpm/(i+atky-defm)
            if hpm%(i+atky-defm)!=0:
                turn+=1
            damage = max(0,turn*(atkm-defy-j)+1-hpy)
            cost = min(cost,damage*h+i*a+j*d)
print cost


n = int(input())
x = 0
y = n
count = 0
while y>x:
    check = (n+x+1)*(n-x-1)
    if y*y <= check:
        x+=1
    elif (y-1)*(y-1) <= check:
        x+=1
        y-=1
    else:
        y-=1
    count+=1
# print(x,y)
if n == 0:
    print(1)
else:
    if x == y:
        print(count*8)
    else:
        print(count*8-4)


n, k = map(int, input().split())
factorial_mod = [1]
mod = 998244353
for i in range(1, int(6e5)):
    factorial_mod.append((factorial_mod[-1] * i) % mod)

def bin_coeff(n, r):
    # return n ! / (r! * (n-r)!)
    if r > n:
        return 0
    ans = factorial_mod[n]
    ans = (ans * pow(factorial_mod[r], mod-2, mod)) % mod
    ans = (ans * pow(factorial_mod[n - r], mod - 2, mod)) % mod
    return ans

fans = 0
for a in range(1, n+1):
    number_of_multiples_of_a_less_than_n = n // a
    # number of ways to choose r elements of n elements with repetition allowed if C(n+r-1, r)
    # we need to fix the smallest number to a
    # we cannot choose a again
    ways = bin_coeff(number_of_multiples_of_a_less_than_n-1, k-1)
    fans = (fans + ways) % mod

print(fans)


from sys import maxsize, stdout, stdin,stderr
mod = int(1e9 + 7)
import re #can use multiple splits
def tup():return map(int,stdin.readline().split())
def I(): return int(stdin.readline())
def lint(): return [int(x) for x in stdin.readline().split()]
def S(): return input().strip()
def grid(r, c): return [lint() for i in range(r)]
def debug(*args, c=6): print('\033[3{}m'.format(c), *args, '\033[0m', file=stderr)
from  math import  log2,sqrt
from collections import defaultdict
s= S().split()
n = I()

d='^>v<'
if n%2==0:print('undefined')
else:
    st =d.find(s[0]).__index__()
    en = d[(st+n)%4]
    if en==s[1]:print('cw')
    elif d[(st-n)%4]==s[1]:print('ccw')
    else:print('undefined')


n, m = map( int, raw_input().split())
res = 1
final = 1
for i in range(m):
  res = res*2 % (10**9 +9)
for i in range(n):
    final = (final*(res-1)) % (10**9+9)
    res -= 1
print final


fn, ln=input().split()

# fn='tom'
# ln='riddle'

def gensub(s):
	res = []
	n=len(s)
	for i in range(1,n+1):
		res.append(s[0:i])
	return res

gfn = gensub(fn)
gln = gensub(ln)

names = [f + l for f in gfn for l in gln]

# print(names)
print(min(names))
# print('tor'<'tom')


MOD = 10**9+7
def f(n, k):good = (n-1) & 1;maybe = (pow(2, n-1, MOD) + 1 - 2*good) % MOD;all_ = pow(2, n, MOD);return (good * (pow(all_, k, MOD) - pow(maybe, k, MOD)) * pow(all_ - maybe, MOD-2, MOD) + pow(maybe, k, MOD)) % MOD
for _ in range(int(input())):n, k = map(int, input().split());print(f(n, k))


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


s=input()
d=input()
l1=[]
l2=[]
a=len(s)
b=len(d)
i=0
flag=0
while(a):
    l1.append(s[a-1])
    a=a-1
while(b):
    l2.append(d[i])
    i=i+1
    b=b-1
for j in range(len(s)):
    if(l1[j]!=l2[j]):
        flag=1
        break
if(flag==0):
    print("YES")
else:
    print('NO')


from sys import stdin, stdout
from types import GeneratorType

def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to

    return wrappedfunc

n = int(stdin.readline())
A = [int(x) for x in stdin.readline().split()]

@bootstrap
def f(A, k, moved):
    if A == 'boom':
        yield 0
    elif k == len(A):
        yield n
    elif moved > 1:
        yield n

    else:
        candidate1 = (yield f(A,k+1,moved+1))
        shot = A[len(A)-k-1]^A[len(A)-k]
        if (len(A)-k-2>=0 and shot < A[len(A)-k-2]) or (k > 1 and shot > A[len(A)-k+1]):
            Aprime = 'boom'
        else:
            Aprime = A[:len(A)-k-1] + [shot] + A[len(A)-k+1:]
            if moved < 0:
                moved = 0
        candidate2 = 1 + (yield f(Aprime, k, moved))

        yield min(candidate1, candidate2)

answer = f(A,1,-n)
if answer >= n:
    answer = -1

stdout.write(str(answer)+'\n')


from collections import *

read_line = lambda: [int(i) for i in input().split(' ')]

n = read_line()[0]
cs = [c - 1 for c in read_line()]
g = [[] for v in range(n)]
parent_cnt = [0] * n
for v in range(n):
    parents = read_line()
    parent_cnt[v] = len(parents) - 1
    for i in range(1, len(parents)):
        g[parents[i] - 1].append(v)

def work(x):
    pcnt = list(parent_cnt)
    qs = [
        deque(v for v in range(n) if cs[v] == c and pcnt[v] == 0)
        for c in range(3)
    ]
    ans = 0
    while True:
        while qs[x]:
            v = qs[x].popleft()
            ans += 1
            for w in g[v]:
                pcnt[w] -= 1
                if pcnt[w] == 0:
                    qs[cs[w]].append(w)
        if qs[0] or qs[1] or qs[2]:
            ans += 1
            x = (x + 1) % 3
        else:
            break
    return ans

print(min(work(i) for i in range(3)))


import math

def printDivisors(n) :
    ls=[]
    i = 1
    while i <= math.sqrt(n):
        if (n % i == 0) :
            if (n / i == i) :
                ls.append(i)
            else :
                ls.append(i)
                ls.append(n//i)
        i = i + 1
    return ls

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

t=int(input())
for _ in range(t):
    n=int(input())
    if(n%2==0):
        tem=n//2
        print(tem,tem)
    else:
        ls=printDivisors(n)
        if(len(ls)==2):
            print(1,n-1)
        else:
            mi=float('inf')
            ans1=0
            ans2=0
            for i in ls:
                if(i!=n):
                    tem=lcm(i,n-i)
                    if(tem<mi):
                        ans1=i
                        ans2=n-i
                        mi=tem
            print(ans1,ans2)


def main():

    n, m = readIntArr()

    tableVi = [False] * (22 * (m + 1) + 5)

    # find unique cnts in multiplication table:
    #     1 2 3  4.. m
    #     2 4 6  8..
    #     3 6 9  12
    #     4 8 12 16
    #     n 2n 3n .. nm
    # Note that n is only up to ~ 20 while m can go to 1e6.
    tableCnts = [-1] * 22
    cnt = 0
    for i in range(1, 22):
        for j in range(1, m + 1):
            x = i * j
            if tableVi[x] == False:
                tableVi[x] = True
                cnt += 1
        tableCnts[i] = cnt

    ans = 1 # for 1st row
    vi = [False] * (n + 1) # visited rows

    for i in range(2, n + 1):
        if vi[i] == False:
            N = 0
            j = i
            while j <= n: # powers of i may overlap. convert powers into a multiplication table
                vi[j] = True
                N += 1
                j *= i
            ans += tableCnts[N]
    print(ans)

    return

import sys
input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok)
# input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS.

def oneLineArrayPrint(arr):
    print(' '.join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
    print('\n'.join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
    print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
    return [int(x) for x in input().split()]
# def readFloatArr():
#     return [float(x) for x in input().split()]

def makeArr(defaultValFactory,dimensionArr): # eg. makeArr(lambda:0,[n,m])
    dv=defaultValFactory;da=dimensionArr
    if len(da)==1:return [dv() for _ in range(da[0])]
    else:return [makeArr(dv,da[1:]) for _ in range(da[0])]

def queryInteractive(a, b, c):
    print('? {} {} {}'.format(a, b, c))
    sys.stdout.flush()
    return int(input())

def answerInteractive(x1, x2):
    print('! {} {}'.format(x1, x2))
    sys.stdout.flush()

inf=float('inf')
# MOD=10**9+7
# MOD=998244353

from math import gcd,floor,ceil
import math
# from math import floor,ceil # for Python2

for _abc in range(1):
    main()


from sys import stdin,stdout,setrecursionlimit,maxint,exit
#setrecursionlimit(2*10**5)
def listInput():
 return map(long,stdin.readline().split())
def printBS(li):
 for i in xrange(len(li)-1):
  stdout.write("%d "%li[i])
 stdout.write("%d\n"%li[-1])
def sin():
 return stdin.readline().rstrip()
s=sin()
n=len(s)
rep={chr(65+i):[] for i in xrange(26)}
for i in xrange(n):
 rep[s[i]].append(i)
repp=""
repi=[]
for i in rep:
 if len(rep[i])==2:
  repp=i
  repi=rep[i]
#print repp,repi
if repi[0]+1==repi[1]:
 print "Impossible"
 exit(0)
t=s[:repi[1]]+s[repi[1]+1:]
_=0
while _<27:
 #print t
 mat=[[""]*13 for i in xrange(2)]
 pos={chr(65+i):(0,0) for i in xrange(26)}
 for i in xrange(13):
  mat[0][i]=t[i]
  pos[t[i]]=(0,i)
 for i in xrange(13):
  mat[1][i]=t[i+13]
  pos[t[i+13]]=(1,12-i)
 mat[1].reverse()
 #print "".join(mat[0])
 #print "".join(mat[1])
 #print pos
 curr=s[0]
 i=1
 while i<=26:
  if abs(pos[s[i]][0]-pos[curr][0])<=1 and abs(pos[s[i]][1]-pos[curr][1])<=1:
   curr=s[i]
   i+=1
  else: break
 else:
  print "".join(mat[0])
  print "".join(mat[1])
  exit(0)
 t=t[-1]+t[:-1]
 _+=1


x = input()
hello = "hello"
j=0
count=0
for i in range(len(x)):
    if x[i]==hello[j]:
        j+=1
        count+=1
    if count==5:
        break
if count==5:
    print("YES")
else:
    print("NO")


import sys
input = sys.stdin.readline
from collections import *

def bfs():
    q = deque([])
    dist = [-1]*(n*2*k)

    for i in range(2*k):
        q.append(i)
        dist[i] = 0

    while q:
        v = q.popleft()

        for nv in G[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)

    for i in range(2*k):
        if dist[(n-1)*2*k+i]!=-1:
            return True

    return False

for _ in range(int(input())):
    n, k, l = map(int, input().split())
    d = list(map(int, input().split()))
    G = [[] for _ in range(n*2*k)]
    p = [i for i in range(k+1)]+[i for i in range(k-1, 0, -1)]

    for i in range(n):
        for j in range(2*k):
            if d[i]+p[j]<=l and d[i]+p[(j+1)%(2*k)]<=l:
                G[i*2*k+j].append(i*2*k+(j+1)%(2*k))

        if i+1<n:
            for j in range(2*k):
                if d[i]+p[j]<=l and d[i+1]+p[(j+1)%(2*k)]<=l:
                    G[i*2*k+j].append((i+1)*2*k+(j+1)%(2*k))

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


a = raw_input().split(' ')
print int(a[1])*(int(a[0])//int(a[1])+1)


import sys

n, m = [int(x) for x in input().split(' ')]
arr = [int(x)-1 for x in input().split(' ')]
k = [int(x) for x in input().split(' ')]

summ = 0
for i in range(m):
	summ += k[i]

for i in range(n):
	if i >= summ:
		k[arr[i-summ]] += 1
	k[arr[i]] -= 1
	done = True
	for j in range(m):
		if k[j] != 0:
			done = False
	if done:
		print('YES')
		sys.exit()
print('NO')


recipe=input()
rb,rs,rc=recipe.count('B'),recipe.count('S'),recipe.count('C')
nb,ns,nc=map(int,input().split())
pb,ps,pc=map(int,input().split())
x=int(input())
#print(rb,rs,rc)
def check(mi):
    reqb,reqs,reqc=rb*mi,rs*mi,rc*mi
    #print(reqb,reqs,reqc)
    reqb-=nb
    reqc-=nc
    reqs-=ns
    #print(reqb,reqc,reqs)
    return max(reqb,0)*pb+max(reqs,0)*ps+max(reqc,0)*pc<=x

lo=0
hi=10**20
while lo<=hi:
    mi=(lo+hi)>>1
    if check(mi):
        ans=mi
        lo=mi+1
    else:
        hi=mi-1
print(ans)


from sys import stdin, stdout
from math import factorial

MOD = 10 ** 9 + 7
INF = float('inf')
sze = 10 ** 2
EPS = 10 ** -6

n, m, t = map(int, stdin.readline().split())
ans = 0

for i in range(4, min(t, n + 1)):
    if t - i <= m:
        ans += factorial(n) * factorial(m) // (factorial(i) * factorial(n - i)) // (factorial(t - i) * factorial(m - t + i))

stdout.write(str(ans))


s = input()[::-1]

xval = ['x']

def compare(c,target):

    if c==target:  return True
    if c=='_':  return True
    if c=='X':
        if xval[0]=='x':
            xval[0] = target
            return True
        else: return xval[0]==target

    return False

dic = {}
def getnext(index,xval):

    if index==n-1:
        if s[index]=='_': return 9
        elif s[index]=='X':
            if xval=='x': return 9
            else:  return xval!='0'
        else:
            return s[index]!='0'

    if (index,xval) in dic:  return dic[(index,xval)]

    output = 0
    if s[index]=='_':  output =  10 * getnext(index+1,xval)
    elif s[index]=='X':
        if xval!='x':  output =  getnext(index+1,xval)
        else:
            for c in range(10):
                output += getnext(index+1,str(c))

    else:
        output =  getnext(index+1,xval)

    dic[(index,xval)] = output
    return output

n = len(s)

if n==1:
    if (s[0]=='0' or s[0]=='_' or s[0]=='X'):
        print(1)
    else:
        print(0)
    exit()

candidate = ['52','05','57']
if n>2: candidate.append('00')

ans = 0

for c0 in range(10):
    for c1 in range(10):
        if n==2 and c1=='0': continue

        xval[0] = 'x'
        if not compare(s[0],str(c0)) or not compare(s[1],str(c1)):  continue

#        print(c0,c1)
        if n==2:
            if str(c0)+str(c1) in candidate:  ans += 1
            continue

        if str(c0) + str(c1) in candidate:

            ans += getnext(2,xval[0])

print(ans)


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

i = 0
buf = 0

while i < n:
    if l[i] + buf > 8:
        k = k - 8
        buf = buf + l[i] - 8
    else:
        k = k - buf - l[i]
        buf = 0

    i += 1

    if k <= 0:
        print(i)
        break

if k > 0:
    print(-1)


def solve(t_id):
    s = input()
    ans = 0
    for c in s:
        if c in ['a', 'e', 'i', 'o', 'u'] or (c.isdigit() and int(c) % 2 == 1):
            ans += 1
    print(ans)
t = 1
#t = int(input())
for t_id in range(1, t + 1):
    solve(t_id)
    t -= 1


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

small = 0
s = 0

for i in range(a):
    if l[i] < b:
        small += 1
    elif l[i] == b:
        s = 1

print(b-small +s)


k2,k3,k5,k6 = map(int,raw_input().split())
least = 0

if k2 < k5:
    least = k2
else:
    least = k5
if k6 < least:
    least = k6

left = k2 - least
if left < k3:
    left_least = left
else:
    left_least = k3

print (least*256 + left_least*32)


n = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l1 = [int(i) for i in input().split()]
ans=""
for i in l:
    if i in l1:
        ans += str(i)+" "

print(ans)


n,k = raw_input().split(" ")
k = int(k)

d = 0
for i in map(int, n)[::-1]:
    if i:
        d+=1
    else:
        k-=1
        if k == 0:
            break
else:
    d = len(n)-1
print d


import string

def title(s, k):
    s = list(s)

    # list of first k latin letters
    letters = list(string.lowercase[:k])
    # remove letters in s
    for l in s:
        if l != '?' and l in letters:
            letters.remove(l)

    # check palindromic property, fill in if necessary
    if len(s)%2 == 0:
        i, j = len(s)//2-1, len(s)//2
    else:
        i, j = len(s)//2, len(s)//2
    while j<len(s):
        # s[i] == s[j] -> ok
        # either s[i] or s[j] is '?' -> copy
        # both '?' -> pop missing letter
        if s[i] != s[j]:
            if s[i] == '?':
                s[i] = s[j]
            elif s[j] == '?':
                s[j] = s[i]
            else:
                return 'IMPOSSIBLE'
        elif s[i] == '?':
            # pop
            if len(letters) == 0:
                s[i] = s[j] = 'a'
            else:
                s[i] = s[j] = letters.pop(-1)
        i -= 1
        j += 1

    if len(letters)>0:
        return 'IMPOSSIBLE'

    return ''.join(s)

#k = 2
#s = '????'
#print title(s, k)

#k = 16
#s = '?bc??f?hi?k??n??hb??liiglal???npi???b???p?n?j?al????j???ponmlkjih??e??b?'
#print title(s, k)

k = int(raw_input())
s = str(raw_input())
print title(s, k)


a, b = map(int, input().split())
print(min(a, b), (max(a, b) - min(a, b)) // 2, sep=' ')


import sys
n = int(raw_input())
c = 0
i = 0
count = 0
while(i<n):

    x,str = raw_input().split()

    x  = int(x)
    if(c==0):
        if(str!="South"):
            print "NO"
            sys.exit()
    elif(c == 20000):
        if(str!="North"):
            print "NO"
            sys.exit()

    if(str == "North"):
        c = c - x
        if(c<0 or c>20000):
            print "NO"
            sys.exit()
    if(str =="South"):
         c = c + x;
         if(c<0 or c>20000):
             print "NO"
             sys.exit()
    i = i + 1
if(c==0):
    print "YES"
else:
    print "NO"


n=input()
p=[map(int,raw_input().split()) for i in range(n)]
M=map(max,zip(*p))
m=map(min,zip(*p))
print 'YNEOS'[sum((X-x)*(Y-y) for x,y,X,Y in p)!=(M[3]-m[1])**2 or (M[3]-m[1])!=(M[2]-m[0]) ::2]


MOD = 1000000007
def isSubset(a, b):
    return (a & b) == a
def isIntersect(a, b):
    return (a & b) != 0
def cntOrder(s, t):
    p = len(s)
    m = len(t)
    inMask = [0 for i in range(m)]
    for x in range(p):
        for i in range(m):
            if t[i] % s[x] == 0:
                inMask[i] |= 1 << x
    cnt = [0 for mask in range(1 << p)]
    for mask in range(1 << p):
        for i in range(m):
            if isSubset(inMask[i], mask):
                cnt[mask] += 1
    dp = [[0 for mask in range(1 << p)] for k in range(m + 1)]
    for i in range(m):
        dp[1][inMask[i]] += 1
    for k in range(m):
        for mask in range(1 << p):
            for i in range(m):
                if not isSubset(inMask[i], mask) and isIntersect(inMask[i], mask):
                    dp[k + 1][mask | inMask[i]] = (dp[k + 1][mask | inMask[i]] + dp[k][mask]) % MOD
            dp[k + 1][mask] = (dp[k + 1][mask] + dp[k][mask] * (cnt[mask] - k)) % MOD
    return dp[m][(1 << p) - 1]
def dfs(u):
    global a, graph, degIn, visited, s, t

    visited[u] = True
    if degIn[u] == 0:
        s.append(a[u])
    else:
        t.append(a[u])

    for v in graph[u]:
        if not visited[v]:
            dfs(v)
def main():
    global a, graph, degIn, visited, s, t
    n = int(input())
    a = list(map(int, input().split()))
    c = [[0 for j in range(n)] for i in range(n)]
    for i in range(n):
        c[i][0] = 1
        for j in range(1, i + 1):
            c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD
    degIn = [0 for u in range(n)]
    graph = [[] for u in range(n)]
    for u in range(n):
        for v in range(n):
            if u != v and a[v] % a[u] == 0:
                graph[u].append(v)
                graph[v].append(u)
                degIn[v] += 1
    ans = 1
    curLen = 0
    visited = [False for u in range(n)]
    for u in range(n):
        if not visited[u]:
            s = []
            t = []
            dfs(u)
            if len(t) > 0:
                sz = len(t) - 1
                cnt = cntOrder(s, t)
                ans = (ans * cnt) % MOD
                ans = (ans * c[curLen + sz][sz]) % MOD
                curLen += sz
    print(ans)
if __name__ == "__main__":
    main()


MOD = 998244353;import __pypy__;int_add = __pypy__.intop.int_add;int_sub = __pypy__.intop.int_sub;int_mul = __pypy__.intop.int_mul
def make_mod_mul(mod=MOD):
    fmod_inv = 1.0 / mod

    def mod_mul(a, b, c=0):
        res = int_sub(int_add(int_mul(a, b), c), int_mul(mod, int(fmod_inv * a * b + fmod_inv * c)))
        if res >= mod:
            return res - mod
        elif res < 0:
            return res + mod
        else:
            return res

    return mod_mul

mod_mul = make_mod_mul()

def mod_pow(x, y):
    if y == 0:
        return 1
    res = 1
    while y > 1:
        if y & 1 == 1:
            res = mod_mul(res, x)
        x = mod_mul(x, x)
        y >>= 1
    return mod_mul(res, x)

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

pascal = [[1]]
for _ in range(n + m + 5):
    nl = [1]
    for i in range(_):
        nl.append((pascal[-1][i] + pascal[-1][i+1]) % MOD)
    nl.append(1)
    pascal.append(nl)

def s1(n,m):
    out = 0
    for row in range(1, n):
        above = row
        below = n - row

        bottom = []
        for i in range(m):
            a = below - 1
            b = i
            a2 = below
            b2 = m-i-1
            bottom.append(mod_mul(pascal[a+b][a] , pascal[a2+b2][a2]))

        top = []
        for i in range(m):
            a = above - 1
            b = i
            a2 = above
            b2 = m-i-1
            top.append(mod_mul(pascal[a+b][a] , pascal[a2+b2][a2]))
        top.reverse()

        curr = 0
        for i in range(m):
            out += mod_mul(curr,bottom[i])
            curr += top[i]
            curr %= MOD
            out %= MOD
    return out * 2

def s2(n,m):
    o = 0
    for i in range(1,n):
        for j in range(1,m):
            a = pascal[i+j-1][i-1]
            b = pascal[n-i+j-1][n-i]
            c = pascal[n-i-1+m-j][m-j]
            d = pascal[i+m-j-1][i]
            #print(a,b,c,d)
            o += mod_mul(mod_mul(a,b),mod_mul(c,d))
    return o

c1 = s1(n,m)
c2 = s1(m,n)
c3 = s2(n,m)

out = (c1 + c2 - 2*c3) % MOD
print(out)


#!/usr/bin/env python
n=input()
card = raw_input().strip().split()
import Queue
q = Queue.Queue()
q.put(card)
s = set([tuple(card)])
res = "YES"
while not q.empty():
    c = q.get();
    if len(c)==1:
        break
    for i in(-2,-4):
        if len(c)>=-i and(c[-1][0]==c[i][0]or c[-1][1]==c[i][1]):
            d=list(c)
            d[i+1]=d.pop();
            if tuple(d) not in s:
                s.add(tuple(d))
                q.put(d)
else:
    res = "NO"
print res


def sum_digits(a):
    if (a < 10):
        return a
    else:
        return a % 10 + sum_digits(a // 10)

def f(a):
    a = str(a)
    return int(str(int(a[0]) - 1) + '9' * (len(a) - 1))

a = int(input())
res = f(a)
t = str(a)[0] + '9' * (len(str(a)) - 1)
res2 = 0

for i in range(1, len(t)):
    t1 = t[:i] + '8' + t[i+1:]
    t1 = int(t1)
    if t1 <= a:
        res2 = t1
    else:
        break

ressum = sum_digits(res)
asum = sum_digits(a)

if (asum > ressum):
    print(a)
else:
    print(max(res, res2))


#sry...

v1, v2 = map(int, input().split())
t, d = map(int, input().split())
L1 = [0]*t
L2 = [0]*t
L1[0] = v1
for i in range(1, t):
    L1[i] = L1[i-1]+d
j = t-2
L2[j+1] = v2
while j >= 0:
    L2[j] = L2[j+1]+d
    j -= 1
ans = 0
for i in range(0, t):
    ans += min(L1[i], L2[i])
print (ans)


dp=[0]*5010
dp[0]=1
n,m,k=map(int,input().split())
t=998244353
for i in range(k):
    for j in range(len(dp)-1, -1, -1):
        if j==0:dp[j]=0
        else:dp[j]=(dp[j-1]*(n-j+1)+dp[j]*j)%t
c=0
for i in range(k+1):
    c+=pow(m,max(n-i,0),t)*dp[i]
    c%=t
den=pow(m,n,t)
den=pow(den,t-2,t)
print((den*c)%t)


import sys

__author__ = 'ratmir'

from collections import deque

alphabet = "abcdefghijklmnopqrstuvwxyz"

def solve(n, a, graph):
    return 1

def execute():
    [n] = [int(x1) for x1 in sys.stdin.readline().split()]
    a = sys.stdin.readline()
    result = "YES\n"
    lastBad = "Z"
    mx = "Z"
    for i in range(0, n):
        if a[i]>=mx:
            mx = a[i]
            result += "0"
            continue
        if a[i]>=lastBad:
            result += "1"
            lastBad = a[i]
            continue
        result = "NO"
        break
    print result

execute()


kk=lambda:map(int,input().split())
ll=lambda:list(kk())
n,s=int(input()),ll()
print("Bob" if s.count(min(s)) > n/2 else "Alice")


import sys
import random, math
from decimal import Decimal
from collections import defaultdict
#n=int(raw_input())

#mem = dict()

n,v = [int(_) for _ in raw_input().split()]
#arr = [int(_) for _ in raw_input().split()]
if v >= n-1:
    print(n-1)
else:
    s = v
    for i in range(2,n-v+1):
        s += i
    print(s)


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

dec = 1
while True:
    if dec%2 == 1:
        a -= dec
    else:
        b -= dec
    if a < 0:
        print('Vladik')
        break
    elif b < 0:
        print('Valera')
        break
    dec += 1


s, x1, x2 = map(int, input().split())
t1, t2 = map(int, input().split())
p, d = map(int, input().split())
v1 = t2 * abs(x1 - x2)
v2 = 0
if d == 1 and p <= x1:
    v2 = x1 - p
elif d == 1:
    v2 = s - p + s - x1
    d=-d
elif p >= x1:
    v2 = p - x1
else:
    v2 = p + x1
    d=-d
p, x1 = x1, x2
if d == 1 and p <= x1:
    v2 += x1 - p
elif d == 1:
    v2 += s - p + s - x1
elif p >= x1:
    v2 += p - x1
else:
    v2 += p + x1
v2 *= t1
print(min(v1, v2))


W=[]
B=[]
arr=[]
for i in xrange(8):
    a=raw_input().strip()
    arr.append(a)
    for j in xrange(8):
        if a[j]=='W':
            W.append((i+1,j+1))
        elif a[j]=='B':
            B.append((i+1,j+1))
W.sort(key=lambda x:x[0])
B.sort(key=lambda x:8-x[0])
d=1000
for i in W:
    c=0
    if 'B' not in map(lambda x:x[i[1]-1],arr)[:i[0]]:
        break
a=i[0]-1
d=1000
for i in B:
    c=0
    if 'W' not in map(lambda x:x[i[1]-1],arr)[i[0]-1:]:
        break
d=8-i[0]
if a<=d:
    print 'A'
else:
    print 'B'


number = input()

def rounding(number):
    m = number % 10
    n = 0
    if m > 5:
        n = (10 - m) + number
    else:
        n = number - m
    return n

print rounding(number)


from fractions import *
n,L=int(input()),0
while (n%2==0):n,L=n//2,L+1
if (n==1):print('%d/1'%L)
else:
    s,t=1,1
    for i in range(n):
        t,s=t*2%n,s*2
        if (t==1):
            m=i+1
            break
    r,t,i,ans=s,s*n,L,0
    while (r>1):
        i,t=i+1,t//2
        if (r-t>0):
            r,ans=r-t,ans+i*t
    print(Fraction(ans+m,s-1))


n, k, x = map(int, raw_input().split())
bolas = map(int, raw_input().split())
quant = 0

for i in range(n):
    linha = bolas[:]
    linha.insert(i, x)

    while len(linha) > 2:
        l = len(linha)

        for j in range(2, len(linha)):
            if linha[j-2] == linha[j-1] == linha[j]:
                p = j + 1

                while p < len(linha):
                    if linha[j] != linha[p]:
                        break

                    p += 1
                linha = linha[:j-2] + linha[p:]
                break

        if len(linha) == l:
            break

    quant = max(quant, n - len(linha))

print quant


n = int(input())
#n, m = map(int, input().split())
#s = input()
c = list(map(int, input().split()))
print(max(c) ^ c[-1])


n = int(input())
s = input()
x=0
for i in s:
    if i=='-':
        x = max(x-1,0)
    else:
        x+=1
print(x)