 import math
a_x, a_y, b_x, b_y, c_x, c_y = map(int, input().split())

if (b_x - a_x)*(c_y - a_y) == (c_x - a_x)*(b_y - a_y):
  print('No')
  exit()

l_ab = math.sqrt(abs(b_x - a_x)**2 + abs(b_y - a_y)**2)
l_bc = math.sqrt(abs(c_x - b_x)**2 + abs(c_y - b_y)**2)
if l_ab != l_bc:
  print('No')
  exit()

print('Yes')


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

f = x*y

if (f % 2 == 0):
	print int(f / 2)
else:
	print int((f - 1) / 2)


# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

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

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

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

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

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

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

# ------------------- fast io --------------------

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


import sys
input = sys.stdin.readline

'''

'''

MOD = 10**9+7

n, m = map(int, input().split())
t = 2**m-1
res = t
while n > 1:
    res *= t
    res %= MOD
    n -= 1

print(res)


# Alice and the List of Presents (593.2)

n,m=input().split()
n,m=int(n),int(m)
a=2**m
print((a-1)**n)


x=10**9+7
n,m=list(int(i) for i in input().split())
print(((2**m-1)**n)%x)


import sys

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

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


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

mod = int(10e9) + 7

a1 = pow(2, m) - 1
ans = pow(a1, n, mod)

print(ans)


n,m=map(int,input().split())
def fun(x,y,m):
    res=1
    while y>0:
        if y%2==1:
            res=(res*x)%m
        y//=2
        x=(x*x)%m
    return res
tot = 2**m-1
print(fun(tot,n,10**9+7))


n,m = input().split(' ')
n = int(n)
m = int(m)
print((2**m-1)**n)


import math
n,m=map(int,input().split())
t=2**m-1
s=t**n
print(s%1000000007)


from sys import *
from math import *
n,k=map(int,stdin.readline().split())
f=[1]
for i in range(1,max(n,k)+1):
    f.append(i*f[i-1])
ans=0
for i in range(0,k):
    ans+=(f[k]//(f[k-i]*f[i]))
print(ans**n)


import sys

[n , m , k] = sys.stdin.readline().split()

n = int(n)
m = int(m)
k = int(k)

def iseven(x):

    if x % 2 == 0:

        return True

    return False

if iseven(n + m) == False and k ==-1: print(0)

else: print(2**((n-1)*(m-1)) % 1000000007)


n, d = int(input().split())
s = list(map(int, input.split())
j = [list(s.index(n) for n in s if n == 1)]
k = [list(j-i for i, j in zip(j[:-1], t[1:]) if j-i <= d)]
if not k :
    print(-1)
else :
    print(len(k))


a=int(input())
b=int(input())
print (a-1)/(b-1)+a


sn,sk = input().split(' ')
n =int(sn)
k=int(sk)
s=input()
# print(s[0])
# exit(0)
mx=0
l=0
while(l<n):
    if s[l] != 'N':
        l+=1
    else:
        r=l+1
        while((r<n) and (s[r]=='N')):
            r+=1
        mx=max(mx,r-l)
        l=r
if(mx>k):
    print('NO')
    exit(0)
ans = 'NO'
for l in range(n):
    can = 1
    if (l+k < n) and (s[l+k]=='N'):
        can =0
    if(l==0 or s[l-1]!='N'):
        if(l+k<=n):
            for i in range(k):
                if s[l+i]=='Y' :
                    can=0
    else:
        can = 0
    if can ==1:
        ans = 'YES';
print(ans)


matrix = []

for i in range(8):
    line = input()
    matrix.append(line)

total_count = 0
t = 0
for i in range(8):
    row_count = 0
    for j in range(8):
        if matrix[i][j] = 'B':
            row_count += 1
    if row_count!=8:
        total_count = row_count
        t = 1
        break
if t==0:
    print(8)
else:
    for col in range(8):
        col_count = 0
        for row in range(8):
            if matrix[row][col] == 'B':
                col_count += 1
        if col_count!=8:
            total_count += col_count
            break
    print(total_count)


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

def solve(last):
    s = 0
    for i in range(1, n, 1):
        if last == 1 :
            if arr[i] == 2:
                s += 3
            else:
                s += 4
            last = arr[i]
        elif arr[i] == 1:
            if last == 2:
                s += 3
            else:
                s += 4
            last = arr[i]
        else:
            return "Infinite"
        if i-1 >= 0 or i+1 <= n:
            if arr[i-1] == 3 and arr[i] == 1 and arr[i+1] == 2:
                s -= 1
    return s

l = arr[0]
ret = solve(l)
if ret == "Infinite":
    print(ret)
else:
    print("Finite")
    print(ret)


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

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

using namespace std;

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

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

ll gcd(ll x, ll y){
    return !y ? x : gcd(y,x%y);
}

int main(void) {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    ll n, ans = 0;
    cin >> n;
    ll to = sqrt(n+.0);
    for(ll i=1;i<=to;i++)
     for(ll j=i;j<=to;j++){
      ll c = i*i+j*j;
      if(c > n) break;
      if(gcd(i,j) != 1 || ~(j-i) & 1) continue;
      ans += n/c;
     }
    cout << ans << endl;
    return 0;
}


#!/usr/bin/env python3
import sys

(c,d) =raw_input()#sys.argv[1]
#c = sys.argv[1][0]
#d=sys.argv[1][1]
moves = [1 for i in range(8)]
#012
#7x3
#654
if c == 'a':
	moves[0] =0
	moves[7] =0
	moves[6] =0
elif c=='h':
	moves[3] =0
	moves[4] =0
	moves[5] =0
if d==1:
	moves[0] =0
	moves[1] =0
	moves[2] =0
elif d==8:
	moves[4] =0
	moves[5] =0
	moves[6] =0
contador =0
#for i in moves:
	#contdor +=i
print (sum(moves))


n = int(input())
z = 1
g = 0
r = 0
while g < n:
    g += z
    r += 1
    z = 3-z
if g > n:
    r -= 1
print(r)


def main(n, x, y):
    if (x == n and y == n):
        return "YES"
    if (x == n and y == n+1):
        return "YES"
    if (x == n+1 and y == n):
        return "YES"
    if (x == n+1 and y == n+1):
        return "YES"
    else:
        return "NO"

line = raw_input()
lst = line.split(" ")
n = int(lst[0]/2)
x = int(lst[1])
y = int(lst[2])
print main(n, x, y)


for t in range(int(input())):
    n = int(input())
    if not n % 2:
        print(f'{n // 2} {n // 2}')
    else:
        ans = [True] * ((n // 2) + 1)
        idx = 1
        for i in range(3, (n // 2) + 1):
            if not ans[i] or not i % 2:
                continue
            if n % i > 0:
                ans[i] = False
                for j in range(2, ((n // 2) + 1) // i):
                    ans[i * j] = False
            elif n % i == 0:
                idx = i
                break
        # print(ans, idx)
        if idx == 1:
            print(f'{1} {n - 1}')
        else:
            print(f'{n // idx} {n - n // idx}')

# for t in range(int(input())):
#     n = int(input())
#     a = list(map(int, input().split()))
#     cnt = 0
#     i = 0
#     while i < n:
#         while i < n and a[i] == i + 1:
#             i += 1
#         j = i
#         while i < n and a[i] != i + 1:
#             i += 1
#         cnt += 1 if j - i else 0
#     print(cnt)


def extend(l):
    for i in l[:]:
        l.append(i/2)
        l.append(i+1)
    return(l)
m,n = map(int,input().split())
s = [n]
step = 0
while m not in s:
    s = extend(s)
    step+=1
print(step)


# https://codeforces.com/problemset/problem/575/H

import sys
import math

mod = pow(10, 9) + 7

def main():
    # sys.stdin = open('E:\\Sublime\\in.txt', 'r')
    # sys.stdout = open('E:\\Sublime\\out.txt', 'w')
    # sys.stderr = open('E:\\Sublime\\err.txt', 'w')

    n = int(sys.stdin.readline().strip())
    # a, b = map(int, sys.stdin.readline().strip().split()[:2])

    # C(n+1, 2n + 2) = (2n+2)! : (n+1)! : n+1!
    # = (n+2)(n+3)...(2n+2) /

    t = 1
    m = 1
    for i in range(1, n + 2):
        t *= (n + i + 1) % mod
        m *= i % mod
    print((t // m - 1) % mod)

if __name__ == '__main__':
    main()

# hajj
#  　　　　　　 ＿＿
# 　　　　　／＞　　フ
# 　　　　　| 　_　 _ l
# 　 　　　／` ミ＿xノ
# 　　 　 /　　　 　 |
# 　　　 /　 ヽ　　 ﾉ
# 　 　 │　　|　|　|
# 　／￣|　　 |　|　|
# 　| (￣ヽ＿_ヽ_)__)
# 　＼二つ


n = int(raw_input())+1
aa=1
for i in xrange(1, 2*n):
	aa *= i
bb=1
for i in xrange(1, n+1):
	bb *= i
cc = 1
for i in xrange(1, n):
	cc *= i
print (2 * aa / (bb * cc) - 1) % (10 ** 9 + 7)


def main():
    s = input()
    ans = 26
    for c in s:
        ans +=25

    print(ans)

if __name__='__main__':
    main()


rcp = raw_input()
rcp = [rcp.count(c) for c in ['B', 'S', 'C']]
n = map(int, raw_input().split())
p = map(int, raw_input().split())
r, cnt = int(raw_input()), 0
while True:
	if all([n[i] == rcp[i] for i in range(3)]):
		cnt += 1
		break
	for i in range(3):
		if n[i] < rcp[i]:
			if p[i] * (rcp[i] - n[i]) <= r:
				r -= p[i] * (rcp[i] - n[i])
				n[i] = rcp[i]
			else:
				print cnt
				exit()
	for i in range(3):
		n[i] -= rcp[i]
	cnt += 1
cpb = 0
for i in range(3):
	cpb += rcp[i] * p[i]
cnt += r / cpb
print cnt


def getSum(n):
    sum = 0
    while (n != 0):
        sum = sum + int(n % 10)
        n = int(n/10)
    return sum

n = int(input())
if n<=9:
    print(n)
else:
    x=0
    while x*10+9<=n:
        x+=x*10+9
    print(getSum(x)+getSum(n-x))


#n , m = map(int , input().split())
n = int(input())
m = int(input())
print(pow(2 , n + m , 998244353 ))


n, front, back = [int(x) for x in input().split(' ')]
print(n - max(front + 1, n - back)+ 1)3 1 1


from math import sqrt

r,h = map (int, input().split())
count = h // r * 2
h -= h // r
elif h >= sqrt(3) / 2 * r:
  count += 3
elif h >= r / 2:
  count += 2
else:
  count += 1
print (count)


def check(a,b):
    ansa=b[0]-a[0]
    ansb=b[1]-a[1]
    return [ansa,ansb]
while True:
    try:
        n,m=map(int,input().split())
        if n!=m:
            print('No')
        else:
            a=list()
            b=list()
            for i in range(n):
                a.append(list(map(int,input().split())))
            for i in range(m):
                b.append(list(map(int,input().split())))
            flag=False
            for i in range(len(a)):
                for j in range(i+1,len(a)):
                    for k in range(len(b)):
                        for l in range(k+1,len(b)):
                            ansa=check(a[i],a[j])
                            ansb=check(a[i],b[k])
                            ansc=check(a[i],b[l])
                            if (ansa[0]==ansb[0] and ansa[0]==ansc[0] and ansa[0]==0) or (ansa[0]!=0 and ansb[0]!=0 and ansc[0]!=0 and ansa[1]/ansa[0]==ansb[1]/ansb[0] and ansa[1]/ansa[0]==ansc[1]/ansc[0]):
                                print('No')
                                flag=True
                                break
                            else:
                                continue
                        if flag==True:
                            break
                    if flag==True:
                        break
                if flag==True:
                    break
            if flag==False:
                print('Yes')
    except EOFError:
        break


n, m, l, r = map(int , input().split())
a = list(map(int , input().split()))
if max(x) > r or  min(a) < l:
    print("Incorrect")
elif n - m >= 2 :
    print("Correct")
elif:
    if l not in a and r not in a and l != r:
        print("Incorrect")
    else:
        print("Correct")


n,k=map(int, input().split())
for i in range(1,10):
    if(n*i % 10 == k || n*i%10 == 0):
        print(i)


n, m = map(int, input().split())
grid = [None for _ in range(n)]
for i in range(n):
	grid[i] = list(input())
pos = []
for i in range(n):
	for j in range(m):
		if grid[i][j] == 'W':
			pos.append((i, j))
ln = len(pos)

memo = {}
def solve(x, magic):
	if (x, magic) not in memo:
		if x >= ln:
			return 0

		res = solve(x + 1, magic)
		i, j = pos[x]

		if j > 0 and grid[i][j - 1] == 'P':
			grid[i][j - 1] = '.'
			res = max(res, 1 + solve(x + 1, magic + i * n + (j - 1) * m))
			grid[i][j - 1] = 'P'

		if i > 0 and grid[i - 1][j] == 'P':
			grid[i - 1][j] = '.'
			res = max(res, 1 + solve(x + 1, magic + (i - 1) * n + j * m))
			grid[i - 1][j] = 'P'

		if i < n - 1 and grid[i + 1][j] == 'P':
			grid[i + 1][j] = '.'
			res = max(res, 1 + solve(x + 1, magic + (i + 1) * n + j * m))
			grid[i + 1][j] = 'P'

		if j < m - 1 and grid[i][j + 1] == 'P':
			grid[i][j + 1] = '.'
			res = max(res, 1 + solve(x + 1, magic + (i + 1) * n + j * m))
			grid[i][j + 1] = 'P'

		memo[x] = res
		return res
	else:
		return memo[x]

print(solve(0, 0))


q = input()
n = int(q[0])
b = int(q[2])
p = int(q[4])
x = (n - 1) * b * b + (n - 1)
y = n * p
print(x, y)
# Thu Oct 08 2020 11:53:37 GMT+0300 (Москва, стандартное время)

# Thu Oct 08 2020 11:53:42 GMT+0300 (Москва, стандартное время)

# Thu Oct 08 2020 11:53:56 GMT+0300 (Москва, стандартное время)

# Thu Oct 08 2020 13:37:38 GMT+0300 (Москва, стандартное время)


from math import log, floor

def binarysearch(x, n, k, p):
    left = 0
    right = len(x)
    while left < right:
        middle = (left + right) // 2
        if sum([x[middle]//k**i for i in range(p+1)]) < n:
            left = middle + 1
        else:
            right = middle

    return left

n, k = [int(i) for i in input().split()]
p = floor(log(n, k))
x = list(range(n//2, n+1))
y = binarysearch(x, n, k, p)

print(x[y])


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

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

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


s=input()
s=sorted(s)
count=1
for i in range(1,len(s)):
    if(s[i]==s[i-1]):
        count+=1
    else:
        ans.append(count)
        count=1
ans.append(count)
ans.sort()
if(len(ans)==1):
    print(1)
if(len(ans)==2):
    if(ans[0]==1):
        print(1)
    else:
        print(2)
if(len(ans)==3):
    if(len(set(ans))==1):
        print(6)
    elif(ans=[1,1,4]):
        print(2)
    elif(ans==[1,2,3]):
        print(3)
if(len(ans)==4):
    if(ans==[1,1,1,3]):
        print(5)
    elif(ans=[1,1,2,2]):
        print(8)
if(len(ans)==6):
    print(30)
if(len(ans)==5):
    print(15)


#coding:utf-8

a, b = map (int, raw_input ().split ())
c = a+b
ans = c*2+2

x, y = 1, a
index = 1
i = 2
while i*i <= c:
	if c%i == 0:
		while index <= i:
			if a%index == 0:
				x, y = index, a/index
			index += 1
		if x <= i and y <= c/i:
			ans = min (ans, 2*(i+c/i))
	i += 1

print ans


from math import sqrt
import bisect
def divisors(n):
    s = [1]
    for i in range(2, int(sqrt(n)) + 5):
        if n % i == 0:
            s.append(i)
    if len(s) == 1:
        s.append(n)
    return s

bisect_right = bisect.bisect
a, b = map(int,input().split())
s = a + b
k = a
diva = divisors(a)
divb = divisors(b)
divs = divisors(s)
ansA = 0
ansB = 0
diva.sort()
divb.sort()
for i in range(len(divs)):
    s = bisect_right(diva, divs[i]) - 1
    if ((a + b) / divs[i]) >= (a / diva[s]):
        ansA = 2*(divs[i] + ((a + b)/divs[i]))
for i in range(len(divs)):
    s = bisect_right(divb, divs[i]) - 1
    if ((a + b) / divs[i]) >= (b / divb[s]):
        ansB = 2*(divs[i] + ((a + b)/divs[i]))
print(int(min(ansA,ansB)))


import sys
stderr = sys.stderr
def nums():
    return map(int, raw_input().split())
X, Y, R1, R2 = 0, 1, 2, 3
c1 = nums()
c2 = nums()
def dist(x1, y1, x2, y2):
    return ((x1-x2)**2 + (y1 - y2)**2)**.05
def cok(x, y, r, c):
    d = dist(x, y, c[X], c[Y])
    if d >= r + c[R2] or d + r <= c[R1] or d + c[R2] <= r:
        return True

candi = [(c1[X], c1[Y], c1[R1], c2),
        (c1[X], c1[Y], c1[R2], c2),
        (c2[X], c2[Y], c2[R1], c1),
        (c2[X], c2[Y], c2[R2], c1)]
ans = 0
for x, y, r, c in candi:
    if cok(x, y, r, c):
        ans += 1
print ans


x1, y1, r1, R1 = map(int, raw_input().split())
x2, y2, r2, R2 = map(int, raw_input().split())
a = [r1, R1]
b = [r2, R2]
cnt = 0
d = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
def func(c1, c2):
	if d - c1 - c2 > -1.0e-8 or abs(c1 - c2) - d > -1.0e-8:
		return 1
	return 0
for c in a:
	cnt += func(c, b[0]) & func(c, b[1])
for c in b:
	cnt += func(c, a[0]) & func(c, a[1])
print cnt


MOD = 10**8

n1,n2,k1,k2 = map(int,raw_input().strip().split())

C = {}
def solve(r1,r2,lasttype,lastnum):
    count = C.get((r1,r2,lasttype,lastnum))
    if not count:
        count = 0
        if r1>0:
            if lasttype == 1:
                count += solve(r1-1,r2,0,1)
            elif lastnum<k1:
                count += solve(r1-1,r2,0,lastnum+1)
        if r2>0:
            if lasttype == 0:
                count += solve(r1,r2-1,1,1)
            elif lastnum<k2:
                count += solve(r1,r2-1,1,lastnum+1)
        count %= MOD
        if r1 == r2 == 0:
            count = 1
        C[(r1,r2,lasttype,lastnum)] = count
    return count

print solve(n1,n2,0,0)


readints() = lambda: map(int, input().split(' '))

a,b,c=readints()
x,y,z=readints()

if a!=x and b!=y and c!=c:
  print('NO')
else:
  print('YES')


segment = [6,2,5,5,4,5,6,3,7,6]
a,b = map(int,input().split())
s = ""
for i in range(a,b+1):
    s+=str(i)
ans = 0
for i in s:
    ans+=segment[int(i)]
print(ans)


n = [x for x in range(1, int(input()) + 1)]
while len(n) > 1:
    n.sort()
    a = n[len(n) - 1] - n[0]
    n.pop(len(n) - 1)
    n.pop(0)
    n.append(a)
print(n[0])


from collections import defaultdict
#n = int(raw_input())
n,b = [int(x) for x in raw_input().split()]
#arr = [int(x) for x in raw_input().split()]

s = 0
d_osn = defaultdict(int)
while b > 1:
    for i in range(2,b):
        if b % i == 0:
            d_osn[i] += 1
            b /= i
            break
    else:
        d_osn[b] += 1
        b = 1
#print(d_osn)
izv = defaultdict(int)
for i in range(1,n+1):
    for el in d_osn:
        while i % el == 0:
            i = i / el
            izv[el] += 1
res = -1
#print(izv)
for k in d_osn:
    mlt = 0 if k not in izv else izv[k] // d_osn[k]
    if res == -1:
        res = mlt
    elif mlt < res:
        res = mlt
print(res)


def fact(n) :
	if n <= 1 :
		return 1
		return n * fact(n - 1)

		def c_n_k(k, n) :
		return fact(n) / (fact(k) * fact(n - k))

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

		d = [0, 1, 3, 12, 60, 124]

		for i in range(k, 1, -1) :
			ans += c_n_k(i, n) * (d[i] - d[i] // i)

				print(ans)


import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)

n, m = [int(item) for item in input().split()]
if n > m:
    n, m = m, n
if n == 1 and m == 1:
    print(2)
    exit()
dp = [[0] * m for _ in range(4)]

dp[0][1] = 1
dp[1][1] = 1
dp[2][1] = 1
dp[3][1] = 1

for i in range(2, m):
    dp[0][i] += dp[2][i-1]
    dp[1][i] += dp[0][i-1]
    dp[1][i] += dp[2][i-1]
    dp[2][i] += dp[1][i-1]
    dp[2][i] += dp[3][i-1]
    dp[3][i] += dp[1][i-1]

# for line in dp:
#     print(line)
lr = 0
ud = 0

for i in range(4):
    lr += dp[i][m-1]
    ud += dp[i][n-1]

if n == 1:
    print(lr)
    exit()
else:
    print(lr + ud - 2)


has_time = 4*60
def findNumTask(n, time):
    i = 0
    leftTime = has_time
    while leftTime >= time and n-i >= 0:
        i+=1
        leftTime -= i*5

    return i-1

n, time = int(input()), int(input())
return findNumTask(n,time)


z,zz=input,lambda:list(map(int,z().split()));
szz,dgraphs,mod=lambda:sorted(zz()),{},10**9+7
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))
def prime(x):
    p=ceil(x**.5)+1
    for i in range(2,p):
        if x%i==0 and x!=2:return 0
    return 1
def dfs(u,visit,graph):
    visit[u]=True
    for i in graph[u]:
        if not visit[i]:
            dfs(i,visit,graph)
################################################################################

"""

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

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

"""

###########################---START-CODING---####################################

l=zz()

ans=-1

for i,j in enumerate(l):
    p=l[:]

    p[i]=0
    n=j//14
    ex=j%14

    m=i+1
    for _ in range(ex):
        if m==13:
            p[m]=(p[m]+1)
            m=0
        else:
            p[m]=(p[m]+1)
            m+=1

    for k in range(14):
        p[k]=(p[k]+n)

    t=0
    for i in p:
        if i%2==0:
            t+=i

    if t>ans:
        ans=t
print(ans)


 def is_leap_year(year):
    if year % 400 == 0:
        return True
    if year % 100 == 0:
        return False
    if year % 4 == 0:
        return True
    return False

start_year = int(input())
if is_leap_year(start_year):
    print(start_year + 28)
else:
    next_year = start_year + 1
    diff = 1
    if is_leap_year(next_year - 1):
        diff += 1

    while diff % 7 != 0:
        diff += 1
        next_year += 1
        if is_leap_year(next_year - 1):
            diff += 1
    print(next_year)


def is_visok(x):
    return x % 400 == 0 or x % 4 == 0 and x % 100 != 0

y = int(input())

d, v = 0, is_visok(y)
year = y

d_ = d
v_ = not v

while not (v_ == v and d_ % 7 = 0):
    year += 1
    v_ = is_visok(year)
    d_ += (365, 366)[v_] % 7

print(year)


def main():
    n, m, k = map(int, input().split())
    if n < m:
        n, m = m, n
    lo, hi = 2, min(n * m, (k + 1) ** 2 // 2) + 1
    while lo < hi:
        a = (lo + hi) // 2
        u = sum(a // i for i in range(a // n + 1, (m if m < a else a) + 1)) + a // n * n
        if u < k:
            lo = a + 1
        elif u > k:
            hi = a
        else:
            lo = hi = a
    res = [hi // i * i for i in range(hi // n + 1, (m if m < hi else hi) + 1)] + [n] * (a // n)
    res.sort(reverse=True)
    print(res[u - k])

if __name__ == '__main__':
    main()


[n, m, k] = raw_input("").split(" ")
[n, m, k] = [int(n), int(m), int(k)]

a = [0 for i in range(0, n*m)]

for i in range(0, n):
    for j in range(m):
        a[i+n*j] = (i+1)*(j+1)
a.sort()
print a[k-1]


from math import floor
from math import sqrt
a=int(input())
sqr=floor(sqrt(a))
f2=sqr
while sqr*f2<a;
    f2+=1
print((sqr+f2)*2)


n = int(input())
ans = float("+inf")
for i in range(1, n+1):
    for j in range(i, n+1):
        if i*j >= n:
            ans = min(ans, (i+j)*2)
print(ans)


from math import *

n=input()
m = 120000
x=[]
for i in range(m):
    x.append(True)

for i in range(2,int(sqrt(m))):
    if x[i]:
        for k in range(2*i, m, i):

            x[k] = False

x[0] = False
x[1] = False

y=[]
for i in range(m):
    r = int(str(i)[::-1])
    if x[i] and r < m and x[r] and r!=i:
        y.append(i)

print y[n-1]


n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
ans = 0

for i in xrange(n / k):
    t1 = t2 = 0
    for j in xrange(k):
        if a[i * k + j] == 1:
            t1 += 1
        else:
            t2 += 1
    ans += min(t1, t2)
print ans


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

ans = []
flag = 0
temp = 0
if s!=0:
    while s >= 0 and s//9<m or (s//9==m and s%9==0) and temp<m:
        flag = 1
        temp += 1
        if s-9 > 0:
            ans.append(9)
            s -= 9
        else:
            ans.append(s)
            s = 0
            continue

        if s==0 and temp<m:
            ans.append(0)

if flag:
    ans1 = "".join(map(str,ans))
    if ans[-1]==0:
        for i in range(len(ans)):
            if ans[-1-i]!=0:
                ans[-1-i] -= 1
                break
        ans[-1] = 1

    ans2 = "".join(map(str,ans[::-1]))
    print(ans2, ans1)
elif flag==0 and s==0 and m==1:
    print(0,0)
else:
    print(-1, -1)


#!/usr/local/bin/python
import math
n,m = map(int,raw_input().split(" "))
if n == 2 and m == 3:
        print "YES"
        exit()
elif m % 2 == 0:
        print "NO"
        exit()
tmp = n
while True:
        tmp += 2
        for i in xrange(2,int(round(math.sqrt(tmp)))+2):
                if tmp % i == 0:
                        break
                if tmp % i != 0 and i == int(round(math.sqrt(tmp)))+1:
                        if tmp == m: print "YES"
                        else: print "NO"
                        exit()


n = int(raw_input())
tri = lambda x: x * (x + 1) / 2
rem = 10 ** 9 + 7
print tri(2 ** n) % rem


'''
Created on May 4, 2012

@author: moatasem
'''
n=int(raw_input())
if(n==0):
   print 1
elif(n==1):
   print 3
else :
   c=4**(n-1)
   u=.75*c
   print int((3*u+.25*c)) %1000000007


def gen_series(index_):
    num = int((index_*2)**(0.5)+2)
    list_series = []
    for i in range(1,num+1):
        list_series.extend(range(1,i+1))
    ans = list_series[index_ - 1]
    return ans
if __name__ == '__main__':
    x = int(input())
    print gen_series(index_=x)


s=input()
l=len(s)
if l>=5:
    A=0
    a=0
    d=0
    for i in s:
        if A>0 and a>0 and d>0:
            break
        if i>='a' and i<='z':
            a=a+1
        elif i>='A' and i<='Z':
            A+=1
        try:
            k=int(i)
            d=d+1
        else:
            pass
    if A>0 and a>0 and d>0:
        print('Correct')
    else:
        print('Too weak')
else:
    print('Too weak')


import re
s = input()
if '@' not in s:
	print('NO')
	exit()
u, h = s.split('@', 1)
r = None
if '/' in h:
	if '/' in h[h.index('/') + 1: ]:
		print('NO')
		exit()
	h, r = h.split('/')
if not re.match('^\w{1,16}$', u):
	print('NO')
elif r is not None and not re.match('^\w{1,16}$', r):
	print('NO')
elif 1 > len(h) or len(h) > 32:
	print('NO')
else:
	h = h.split('.')
	if any(not re.match('^\w{,16}$', x) for x in h):
		print('NO')
	else:
		print('YES')


n = raw_input()
l = [i for i in raw_input().split()]
count = 0
i = 0
while l[i] == '0':
    i += 1
j = i
while j < len(l):
    if l[j] == '1':
        count += 1
        j += 1
        flag = 0
    else:
        if j + 1 < len(l) and l[j + 1] == '1' and flag == 0:
            count += 1
            j += 1
            flag = 1
        else:
            j += 1
            flag = 1
print count


import math
n_and_c=raw_input().split(' ')
n=int(n_and_c[0])
c=int(n_and_c[1])
count=0
i=1
while i<=n:
    count+=math.factorial(c+i-1)/(math.factorial(c-1)*math.factorial(i))
    i+=1
print count
print count % (10**6+3)


import math
n_and_c=raw_input().split(' ')
n=int(n_and_c[0])
c=int(n_and_c[1])
count=0
i=1
while i<=n:
    count+=math.factorial(c+i-1)/(math.factorial(c-1)*math.factorial(i))
    i+=1
print count % (10**6+3)


#236B

import math

arr = list(map(int, input().split(" ")))
a = arr[0]
b = arr[1]
c = arr[2]

def numdiv(n):
	count = 0
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			count += 2
	if int(math.sqrt(n)) * int(math.sqrt(n)) == n:
		count -= 1
	return count

answer = 0
for i in range(1, a + 1):
	for j in range(1, b + 1):
		for k in range(1, c + 1):
			answer += numdiv(i * j * k)

print(answer)


n,k=[int(n) for n in input().split()]
s=set()
for i in range(1,k+1):
    s.add(n%i)
if(len(s)==k):
    print("Yes")
else:
    print("No")


n = int(input())
f = []
X = []
Y = []
for i in range(4 * n + 1):
    x, y = map(int, input().split())
    f.append((x, y))
    X.append(x)
    Y.append(y)
l = min(X)
r = max(X)
d = min(Y)
u = max(Y)
if r - l == u - d:
    for i in f:
        if X.count(i[0]) == 1 and Y.count(i[1]) == 1:
            print(i[0], i[1])
            break
    for i in f:
        if l < i[0] < r and d < i[1] < u:
            print(i[0], i[1])
            break
else:
    for i in f:
        if X.count(i[0]) == 1 and Y.count(i[1]) == 1:
            print(i[0], i[1])
            break
    for i in f:
        if X.count(i[0]) == 1 and (i[0] == l or i[0] == R):
            print(i[0], i[1])
            break
        elif Y.count(i[1]) == 1 and (i[1] == u or i[1] == d):
            print(i[0], i[1])
            break


#!usr/bin/env/python
path = raw_input()
new_path = ''
flag = 0
for i in xrange(len(path)):
	if path[i] == '/' and flag:
		pass
	elif path[i] == '/':
		flag = 1
		new_path += path[i]
	else:
		flag = 0
		new_path += path[i]
while new_path[-1] == '/':
	new_path = new_path[:-1]
if new_path:
	print new_path
else:
	print '/'


s = raw_input()
n = len(s)
st = ""
for i in range(n):
    if s[i]=='/' and  s[i+1]=='/':
        continue
    else:
        st += s[i]
print st


n ,m ,k = map(int,input().split())
l = list(map(int,input().split()))
l[m-1] = "G"
p = m-1
o = m-1
while True:
    o -= 1
    p += 1
    try:
        if l[p]!=0 and l[p]<=k:
            print((p-(m-1))*10)
            break
    except:
        pass
    try:
        if l[o]!=0 and l[o]<=k and o>0:
            print((m-1-o)*10)
            break
    except:
        pass


import math as m
k, n, s, p = map(int, input().split())
i = 1
while True:
    needed_sheets = k * m.ceil(n/s)
    if i * p >= needed_sheets:
        break
    i += 1
print(i)


k, n, s, p = map(int, input().split())
x = 0
while ((x * p) // k) * s < n:
    x += 1
print(x)


from math import *
n,m=map(int,input().split())
if m==1:print(n*(n-1)//2,n*(n-1)//2)
else:
    minim=[n//m+1 for i in range(n%m)]
    for i in range(m-(n%m)):
        minim.append(n//m)
    maxim=[1 for i in range(m-1)]
    maxim.append(n-m+1)
#     minim.append(n-sum(minim))
    sum1,sum2=0,0
    for i in minim:sum1+=i*(i-1)//2
    for i in maxim:sum2+=i*(i-1)//2
    print(sum1,sum2)


#import sys
#sys.stdin = open('in', 'r')
#n = int(input())
#a = [int(x) for x in input().split()]
class minheap:
    def __init__(self, n):
        self.a = [0 for i in range(n)]
        self.n = 0

    def __init__(self):
        self.a = []
        self.n = 0

    def load(self, initial):
        self.a = [] + initial
        self.n = len(self.a)
        for i in range((self.n-2) // 2, -1, -1):
            self.hdown(i)

    def hup(self, ind):
        if ind > 0:
            parent = (ind - 1) // 2
            if self.a[parent] > self.a[ind]:
                tmp = self.a[ind]
                self.a[ind] = self.a[parent]
                self.a[parent] = tmp
                self.hup(parent)

    def hdown(self, ind):
        l = ind*2 + 1
        r = ind*2 + 2
        newind = ind
        if l < self.n and self.a[newind] > self.a[l]:
            newind = l
        if r < self.n and self.a[newind] > self.a[r]:
            newind = r
        if newind != ind:
            tmp = self.a[ind]
            self.a[ind] = self.a[newind]
            self.a[newind] = tmp
            self.hdown(newind)

    def push(self, v):
        if self.n == len(self.a):
            self.a.append(v)
        else:
            self.a[self.n] = v
        self.hup(self.n)
        self.n += 1

    def pop(self):
        if self.n > 0:
            res = self.a[0]
            self.n -= 1
            if self.n > 0:
                self.a[0] = self.a[self.n]
                self.a[self.n] = 0
                self.hdown(0)
            return res
        else:
            raise "empty heap"

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

h = minheap()
d = {}
h.push((0, n))

r = -1
while r == -1:
    xh,nh = h.pop()
    if nh not in d:
        d[nh] = xh
        if nh == 1:
            r = xh + x
        else:
            if (nh - 1) not in d:
                h.push((xh + x, nh - 1))
            if nh & 1 == 0 and (nh // 2) not in d and y < (nh//2)*x:
                h.push((xh + y, nh // 2))
            if (nh + 1) not in d:
                h.push((xh + x, nh + 1))

print(r)


t,s,k = map(int, input().split())

t-=1
k-=1

sat=[0]*100000000

for i in range(t,k+s,s):
    sat[i]=1
    if i!=t:
        sat[i+1]=1

print("YES" if sat[k]==1 else "NO")


l = [int(e) for e in input().strip()]

def lei00(l):
    result = []
    for i in range(len(l)-1, -1, -1):
        if l[i] == 0:
            result.append(i)
        if len(result) == 2:
            break
    if len(result) < 2:
        return None
    return 2 * len(l) - result[0] - result[1] - 3

def lei(l, x, y):
    assert x != y

    ix = None
    iy = None

    for i in range(len(l)-1, -1, -1):
        if l[i] == x:
            ix = i
        elif l[i] == y:
            iy = i

        if ix != None and iy != None:
            break

    if ix == None or iy == None:
        return None

    result = 2 * len(l) - ix - iy - 3

    if ix > iy:
        result += 1

    if x == 7 or x == 2:
        assert y == 5
        if iy == 0 and l[1] == 0:
            if len(l) >= 4:
                iii = 1
                while True:
                    iii += 1
                    if l[iii] != 0:
                        break
                result += iii-1
            if len(l) == 3:
                return None

    return result

l = [lei00(l), lei(l, 5, 0), lei(l, 7, 5), lei(l, 2, 5)]

result = None
for e in l:
    if e == None:
        continue
    if result == None or result > e:
        result = e

if result == None:
    print(-1)
else:
    print(result)


k, n, m = map(int, raw_input().split())
a = map(int, raw_input().split())
s = sum(a)
a.sort()
ans = 0
for i in xrange(m / s + 1):
    p = i * (n + 1)
    t = m - i * s
    for x in a:
        if t >= x * (k - i):
            t -= x * (k - i)
            p += k - i
        else:
            p += t / x
            break
    if ans < p:
        ans = p
print ans


x=int(input())
b=[str(i) for i in input().split()]
# print(b)
hh=b[0]
mm=b[1]
if hh[0]=="0":
	hh=hh[1:]
	hh=int(hh)
if mm[0]=="0":
	mm=mm[1:]
	mm=int(mm)

# print(hh,mm)

nh=hh
nm=mm
f=0
y=0
while(f==0):
	nh=str(nh)
	nm=str(nm)
	if '7' in nh or '7' in nm:
		f=1
		break
	nh=int(nh)
	nm=int(nm)
	if x>nm:
		d= x-nm
		if nm==0:
			nm=23
		else:
			nm-=1
		nm= 60-d
	else:
		nm-=x
	y+=1

print(y)

'''

'''


  n,k = map(int, input().split())
N=ceil(2*n/k)+ceil(5*n/k)+ceil(8*n/k)


n, k = map(int, input().split())
flag = True
x = 0
while flag == True:
	if (x % k) * (x // k) == n:
		print(x)
		flag = False
	x = x + 1


"""609C"""
# import math

def main():
	k ,a, b  = map(int,input().split())
	mx = max(a,b)
	mn = min(a,b)
	cnt=0
	while True:
		temp = mx
		temp2 = mn
		if temp-k<0:
			print(-1)
			return
		elif temp-k==0:
			cnt+=1
			print(cnt)
			return
		else:
			cnt+=1
			mx = max(temp,temp2)
			mn = min(temp,temp2)
	return

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


import math

import sys

sys.setrecursionlimit(10**6)
def proA(n,co):
    global a,c,b
    if(n==0):
        return co
    if(n<0):
        return -math.inf
    maxi=0
    for i in [a,b,c]:
        maxi=max(maxi,proA(n-i,co+1))
    return maxi

arr=list(map(int,input().split()))
n,a,b,c=arr
print(proA(n,0))


import sys
import math

def dist(a, b):
    return math.sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]))

def samep(a, b):
    EPS = 0.01
    if a - b < -EPS or a - b > EPS:
        return False
    return True

def same(a, b):
    return samep(a[0], b[0]) and samep(a[1], b[1])

def stat(a, tata):
    if tata[a] == a:
        return a
    x = stat(tata[a], tata)
    tata[a] = x
    return x

def unesc(a, b, tata):
    y = stat(b, tata)
    x = stat(a, tata)
    if x != y:
        tata[x] = y
    return

#fin = open('cerc.in', 'r')
#fout = open('cerc.out', 'w')
fin = sys.stdin
fout = sys.stdout
n = int(fin.readline())
a = []
for i in range(0, n):
    a.append(tuple([int(number) for number in fin.readline().split()]))
#find V
pnt = []
pntc = []
for i in range(0, n):
    for j in range(i + 1, n):
        if a[i][0] != a[j][0] or a[i][1] != a[j][1]:
            a0, a1, a2 = a[i]
            b0, b1, b2 = a[j]
            c0 = 2 * (b0 - a0)
            c1 = 2 * (b1 - a1)
            c2 = -a0 * a0 + -a1 * a1 + a2 * a2 + b0 * b0 + b1 * b1 - b2 * b2
            npoints = []
            if c0 == 0:
                y0 = c2 / c1
                x1 = a2 * a2 - (y0 - a1) * (y0 - a1)
                x0 = math.sqrt(x1) + a0
                npoints.append((-x0, y0), (x0, y0))
            else:
                d0 = -c1 / c0
                d1 = c2 / c0
                e0 = (d0 * d0 + 1)
                e1 = 2 * d0 * (d1 - a0) - 2 * a1
                e2 = (d1 - a0) * (d1 - a0) + a1 * a1 - a2 * a2
                dt = e1 * e1 - 4 * e2 * e0
                if dt >= 0:
                    y0 = (-e1 - math.sqrt(dt)) / (2 * e0)
                    y1 = (-e1 + math.sqrt(dt)) / (2 * e0)
                    x0 = d0 * y0 + d1
                    x1 = d0 * y1 + d1
                    npoints.append((x0, y0))
                    npoints.append((x1, y1))
            for np in npoints:
                g = 0
                for poz in range(0, len(pnt)):
                    if same(pnt[poz], np):
                        g = 1
                        pntc[poz].add(i)
                        pntc[poz].add(j)
                        break;
                if g == 0:
                    pnt.append(np)
                    pntc.append(set({i, j}))
pntc = [list(x) for x in pntc]
V = len(pnt)
#find C
tata = list(range(0, n))
C = 1
for p in range(0, V):
    for i in range(0, len(pntc[p])):
        for j in range(i + 1, len(pntc[p])):
            unesc(pntc[p][i], pntc[p][j], tata)
for p in range(0, n):
    if tata[p] == p:
        C += 1
#find E
E = 0
for p in range(0, V):
    for x in pntc[p]:
        E += 1
F = E + C - V
fout.write(repr(F))
if fin != sys.stdin:
    fin.close()
    fout.close()


c = 97
d = 0
for i in map(ord,input()):
    e = abs(c-i)
    f += min(e,26-e)
    c=i
print(f)


import math

N = int(input())

factor1 = 1
SQ = int(math.sqrt(t)) + 1

for i in range(2, SQ):
	if N % i == 0:
		factor1 = i
		break

factor2 = N // factor1

print(str(factor1) + str(factor2))


import itertools
import sys

def c(s):
	j = 0
	while j < len(s) / 2:
		if s[j] == s[len(s)-j-1]:
			j += 1
			continue
		else:
			return False
	return True

s = raw_input()
temp = []
for i in range(len(s)):
	temp += list(itertools.combinations(s, i+1))

su = []
for i in range(len(temp)):
	su.append(''.join(temp[i]))

for j in range(len(su)-1, -1, -1):
	if not c(su[j]):
		print len(su[j])
		sys.exit()

if c(su[len(su) - 1]):
	print 0
else:
	print len(s)


"""Template for Python Competitive Programmers prepared by pa.n.ik, kabeer seth and Mayank Chaudhary """

# to use the print and division function of Python3
from __future__ import division, print_function

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""use resource"""
# import resource
# resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])

"""for factorial"""

def prepare_factorial():
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % MOD)
    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], MOD - 2, MOD)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % MOD

    return fact, ifact

"""uncomment next 4 lines while doing recursion based question"""
# import threading
# threading.stack_size(1<<27)
import sys
# sys.setrecursionlimit(10000)

"""uncomment modules according to your need"""
from bisect import bisect_left, bisect_right, insort
# from itertools import repeat
from math import floor, ceil, sqrt, degrees, atan, pi, log, sin, radians
from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
from collections import Counter, defaultdict, deque
# from copy import deepcopy
# from decimal import *
import re
import operator

def modinv(n, p):
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):    # for using this uncomment the lines calculating fact and ifact
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t

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

"""*****************************************************************************************"""

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

def lcm(x, y):
    return (x*y)//(GCD(x, y))

def get_xor(n):
    return [n,1,n+1,0][n%4]

def fast_expo(a, b):
    res = 1
    while b:
        if b&1:
            res = (res * a)
            res %= MOD
            b -= 1
        else:
            a = (a* a)
            a %= MOD
            b>>=1
    res %= MOD
    return res

""" ********************************************************************************************* """

def main():

    fact, ifact = prepare_factorial()
    n, m = get_ints()

    ans = ((ncr(m, n-1, fact, ifact) * (n-2))%MOD * fast_expo(2, n-3))%MOD
    print(ans)

""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

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')

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

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


# Codeforces Beta Round #40
# Problem B -- Repaintings
n, m = map(int, raw_input().split())
x = input() - 1
print max(n + m - 4 * x) if min(n, m) > 2 * x else 0


t=input()
s=''
if len(t)%2==1:
    i = len(t) // 2
    nap = 0
    for j in range(len(t)):
        if z==1:
            i += j
            z=0
        else:
            i -= j
            z=1
        s+=t[i]
    print(s)
else:
    i = len(t) // 2 - 1
    z=0
    for j in range(len(t)):
        if z==1:
            i += j
            z=0
        else:
            i -= j
            z=1
        s+= t[i]
    print(s)


from math import factorial as fact
n,m = map(int,input().split())

if m>=3:
	print(max(0,n - 2*m),n - fact(m)//(2*fact(m-2)))
else:
	if m==0:
		print(n,n)
	elif m==1:
		print(max(0,n - 2*m),max(0, n-2)))
	elif m==2:
		print(max(0,n - 2*m),max(0, n-3)))


from collections import defaultdict

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

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

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

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

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

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


s = [int(i) for i in raw_input().split()]
f = [int(i) for i in raw_input().split()]
x1 = s[0]
y1 = s[1]
x2 = f[0]
y2 = f[1]

x = abs(x1-x2)
y = abs(y1-y2)
mini = (x+y+2)*2
print max(mini,8)


R = lambda: map(int, input().split())
n = int(input())
arr = [1, 2] + [0] * n
for i in range(2, n):
    arr[i] = arr[i - 1] + arr[i - 2]
for i in range(n):
    arr[i] = (arr[i] + arr[i - 1]) % 1000000007
print(arr[n - 1])


import string
li = map(int,string.split(raw_input()))
flag = 0
if(li[2]>0):
   for i in range(li[0],1000000001,li[2]):
      if(li[1] == i):
         print("YES")
         flag =1
         break
      elif(li[1] < i):
         break
   if(flag!=1):
      print("NO")
elif(li[2]<0):
   for i in range(li[0],-1000000001,li[2]):
      if(li[1] == i):
         print("YES")
         flag =1
         break
      elif(li[1] > i):
         break
   if(flag!=1):
      print("NO")
else:
   if(li[1] == li[0]) : print("YES")
   else: print("NO")


from itertools import combinations
def solve(items,summation):
    l=[]
    for length in range(1, len(items)):
        for subset in combinations(items, length):
            l.append(sum(subset))
            if sum(subset) == summation or (sum(subset)-360) in l or (sum(subset)-720) in l:
                    boole=1
                    return(boole)
x=int(input())
l1=[]
l2=[]
boole=0
for i in range(x):
    s=int(input())
    l1.append(s)
l1.sort()
total=sum(l1)
if total%2==0:
    if total%360==0:
        boole=1
    else:
        boole=solve(l1,total/2)

if boole==1:
    print("YES")
else:
    print("NO")


import string
import math

def ii():
    ii = []
    for s in string.split(raw_input()):
        ii.append(int(s))
    return ii

ii = ii()
n = ii[0]
R = ii[1] * 1.0000001
r = ii[2]

x = 0
if n <= 2:
    x = R / n
else:
    a = math.pi / n
#    print a
    sinA = math.sin(a)
#    print sinA
    x = R * sinA / (1 + sinA)
#    x = int(x)
#print x
if x >= r: print 'YES'
else: print 'NO'


import math

n = input()
n = n.split()
s = eval(n[0])
n = eval(n[1])

alls = []

maxGcd = 1

if n == s:
    print(n)
else:
    for i in range(s,n):
        alls.append(i)

    for i in range(len(alls)):
        if alls[i] != "x":
            count = 2
            #print(n.isdigit())
            while((count * alls[i]) < n):
                #print(alls[(count * alls[i]) - alls[i]],alls[i],count)
                alls[(count * alls[i]) - s] = "x"
                count += 1

    for i in alls:
        if i != "x":
            maxGcd = math.gcd(maxGcd,i)

    #print(alls)

    print(maxGcd)


n, a, b = [int(input() for _ in range(3)]
d = [0]
c = 0

for i in (a, b, a, a, b, a):
    if max(d) >= i:
        d[d.index(max(d))] -= i
    else:
        c += 1
        d += [n - i]

print(c)


#!/usr/bin/python

import os
import sys
from math import log10, factorial
import itertools

mod = 1000000007

def fni(x):
    tmp = mod - 2
    ret = 1
    tt = x
    while (tmp):
        if (tmp & 1):
            ret = (ret * tt) % mod
        tt = (tt * tt) % mod
        tmp >>= 1
    return ret

def solve(f):
    a,b,n = f.read_int_list()
    s = set([a,b])

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

    ans = 0
    astr, bstr = str(a), str(b)
    lst = [int(''.join(num)) for num in itertools.product([astr,bstr], repeat=int(log10(n))+1)]
    lst += [int(''.join(num)) for num in itertools.product([astr,bstr], repeat=int(log10(n))+2)]

    for i, j in enumerate(xrange(a*n,b*n+1,b-a)):
        if not j in lst: continue
        ans = (ans + c[n] * fni(c[i]) % mod * fni(c[n-i]) % mod) % mod

    print ans

class Reader(object):
    def __init__(self):
        self.f = sys.stdin

    def read_int(self):
        return int(self.f.readline().strip())
    def read_float(self):
        return float(self.f.readline().strip())
    def read_long(self):
        return long(self.f.readline().strip())
    def read_str(self):
        return self.f.readline().strip()

    def read_int_list(self):
        return [int(item) for item in self.f.readline().split()]
    def read_float_list(self):
        return [float(item) for item in self.f.readline().split()]
    def read_long_list(self):
        return [long(item) for item in self.f.readline().split()]
    def read_str_list(self):
        return self.f.readline().split()

if __name__ == '__main__':
    f = Reader()
    solve(f)


def minTax(n, primes):
	if (n==2 or (n in primes)):
		print 1
		return
	elif (n%2==0):
		print 2
		return
	else:
		if (n-2) in primes:
			print 2
			return
		else:
			print 3
			return

n = int(raw_input())

primes = [r for r in xrange(2,n+1)]

for j in primes:
	for i in primes:
		if (i > j):
			if (i%j == 0):
				primes.remove(i)

minTax(n, primes)


a,b=map(int,input().split())
c=1
k=0
if(a==0  or b==0 ):
    print(0)
elif(a==1 and b==1):
    print(0)
else:
    while(c!=0):
        if(a>=b):
            if(a>2):
                b=b+1
                a=a-2
                k=k+1
            else:
                c=0
        elif(a<b):
            if(b>2):
                a=a+1
                b=b-2
                k=k+1
            else:
                c=0
    print(k+1


def len_n(n):
    l = 0
    while n != 0:
        n = n//10
        l += 1
    return l

def sum_n(n):
    l = len_n(n)

    summ = 0
    while n != 0:
        summ += n%10
        n = n//10

    return summ

x = int(input())
max_cifr = sum_n(x)
maxnum = x

for i in range(1, len_n(x)):
    x = x-(10**i)
    #print("x: ",x)
    sx = str(x)
    sx = sx[:len(sx)-i]+'9'+sx[len(sx)-i+1:]
    #print("sx: ", sx)
    x = int(sx)
    if(max_cifr < sum_n(x)):
        max_cifr = sum_n(x)
        maxnum = x

print(maxnum)


a=list(map(int,input().split()))
sort(a)
if a[0]+a[3]==a[2]+[1]: print('YES')
else: print("NO")


import math
from math import floor

a11 = input()
a21 = input()
b11 = input()
b21 = input()

sList = []
sList.append(a11[0])
sList.append(a11[1])
sList.append(a21[0])
sList.append(a21[1])

sList.remove('X')
sList.append(sList[0])
sList.append(sList[1])

pList = []
pList.append(b11[0])
pList.append(b11[1])
pList.append(b21[0])
pList.append(b21[1])

pList.remove("X")

pList = pList[::-1]

s1 = s2 = ""

for i in sList:
    s1+=i
for i in pList:
    s2+=i

if(s1.find(s2) == -1):
    print("NO")

else:
    print("YES")


f = lambda: 'ABC' in 2*(input()+input()[::-1]).replace('X', ' ')

print('NO' if f()^f() else 'YES')


from math import factorial
cat = [1, 1]
p = 10**9 + 7
n = int(input())
for i in range(1, 4000):
    cat.append((cat[-1]*2*(2*i + 1)//(i + 2)) % p)

ans = 0
for i in range(1, n + 1):
    ans += ((((factorial(n))//((factorial(i))*(factorial(n - i)))) % p)  *cat[n - i]) % p
print(ans)


import sys
import math
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

q = inlt()
a = q[0]
b = q[1]

def primeFactors(n):
    l = []
    i = 2
    n1 = n
    while(n1 > 1):
        while((n1 % i) == 0):
            l.append(i)
            n1 = n1 // i

        i = i + 1
    return l

p = primeFactors(a)
q = primeFactors(b)

def count(x,l):
    ct = 0
    for i in l:
        if(i == x):
            ct = ct + 1
    return ct

a1 = count(2,p)
b1 = count(3,p)
c1 = count(5,p)

a2 = count(2,q)
b2 = count(3,q)
c2 = count(5,q)

k = a // (2**a1 * 3**b1 * 5**c1)
j = b // (2**a2 * 3**b2 * 5**c2)

if(k == j):
    sum = 0
    sum = sum + abs(c1 - c2)
    sum = sum + abs(b1 - b2)
    sum = sum + abs(a1-a2)
    print(sum)

else:
    print(-1)


# Description of the problem can be found at http://codeforces.com/problemset/problem/740/A

def getMinCost(c_c, c, l_c, m):
    if (c_c + n) % 4 == 0:
        return c

    for i in range(1, 4):
        if not m or c + l_c[i] < m:
            if m:
                m = min(m, getMinCost(c_c + i, c + l_c[i], l_c, m))
            else:
                m = getMinCost(c_c + i, c + l_c[i], l_c, m)

    return m

n, c1, c2, c3 = map(int, input().split())
l_c = list([0, c1, c2, c3])

print(getMinCost(0, 0, l_c, None))


cms=int(input())
if al==1 or al==0 :
    ans=cms//3
else:
    ans=cms//3+1
feet=ans//12
print(feet,ans%12)


x = int(input())
s  = list(input().split())
k = 0
for i in range(5):
	for j in range(2):
		x[j]=s[i][j]
		k++
if(k!=0):
print("Yes")
else:
print("No")


cardOnTable = input()
myCards = input().split()
for card in myCards:
    if card[1] = cardOnTable[1] or card[0] = cardOnTable[0]:
        print("YES")
        break
else:
    print('NO')


 def solve():
    _ = map(int, input())
    m = list(map(int, input().split()))
    answer = 0
    for i in range(len(m)):
        answer += i*4*m[i]
    return answer

print(solve())


t,n,s=map(int,input().split()
for i in range(n):
    s+=i*4*t
print(s)


die1 = int(raw_input('die 1'))
die2 = int(raw_input('die 2'))
the_die = max(die1, die2)

if the_die == 6:
  print '1/6'
elif the_die == 5:
  print '1/3'
elif the_die == 4:
  print '1/2'
elif the_die == 3:
  print '2/3'
elif the_die == 2:
  print '5/6'
else:
  print '1/1'


n,k,m = list(map(int, input().split()))
t = sorted(map(int, input().split()))
st = sum(t)
res = 0
for x in range(m//st+1):
    rem = m-x*st
    m = x*(k+1)
    # for i in range(k):
        # y = min(rem//t[i], n-x)
        # rem -= t[i]*y
        # m += y
    for i in range(k):
        for _ in range(n-x):
            if rem >= t[i]:
                rem -= t[i]
                m += 1
    res = max(res, m)
print(res)


n,l,r=map(int,input().split())
li=[]
while n>0:
    li+=[n]
    n=n//2
res=[]
for i in range(1,len(li)+1):
    res=res+[li[-i]%2]+res
cnt=0
for i in range(l-1,r):
    if res[i]==1:
        cnt+=1
print(cnt)


def getOne(num):
    if num == 0 or num == 1:
        return [num]
    return getOne(int(num / 2)) + [int(num % 2)] + getOne(int(num / 2))
ip = input()
number = ip.split()
num = int(number[0])
l = int(number[1])
r = int(number[2])
sum = 0
temp = getOne(num)
for i in temp[l -1:r]:
    sum += i
print(sum)


import sys
n,l,r = map(int, input().split())
def rect(n):
    if n <= 1:
        return [n];
    ls = rect(n//2)
    ans = []
    ans.extend(ls)
    ans.extend([n % 2])
    ans.extend(list(reversed(ls)))
    return ans
print(sum(rect(n)[l-1:r]))


n = input().split(' ')
n1 = int(n[0])
m = int(n[1])
while True:
    for i in range(1, n1 + 1):
        if m > i:
            m -= i
        else:
            break
        if i == n1:
            i = 1
    if m < i:
        break
print(m)


walruses,chips=map(int,input().split())
while True:
    for i in range (walruses):
        if chips>i+1:
            chips=chips-(i+1)
        else:
            break
print (chips)


def pos(x):
    global m
    global n
    row=x/m
    column=x%m
    p=[row,column]
    return p
n,m,a,b=(int(i) for i in raw_input().split())
l=pos(a-1)
par=l[0]
pac=l[1]
l=pos(b-1)
pbr=l[0]
pbc=l[1]
if (par==pbr) or ((pac==0) and (pbc==m-1)) or (a==1 and b==n):
    print 1
elif (pac-pbc==1) or (pac==0) or (pbc==m-1) or (a==1) or (b==n) or (pbr-par==1):
    print 2
else:
    print 3
#print par,pac,pbr,pbc


a,m=map(int,input().split())
arr=[]
x=a
new=a%m
arr.append(new)
a+=new
if(new==0):
		print('Yes')
		exit(0)
while(1):
	new=a%m
	if(new==0):
		print('Yes')
		exit(0)
	elif(new==arr[0]):
		print('No')
		exit(0)
	else:
		arr.append(new)
		a+=new


import sys
input = sys.stdin.readline().strip().split(' ')
a = input[0]
b = input[1]

if (a==b): print (a)
else: print 1


def yesorno (number):
    for i in range(11)[2:]:
        if (number%i) == 0:
            return 0
    return 1

countdownload = input()
countprem = 0
for number in xrange(countdownload+1):
    countprem += yesorno(number)
print countprem


#!/usr/bin/env python3

a1 = int(input())
a2 = int(input())
k1 = int(input())
k2 = int(input())
n  = int(input())

minDeletedPlayers = 0
maxDeletedPlayers = 0

# Finding min deleted players
playersStates = []
for i in range(a1):
    playersStates.append(k1)
for i in range(a2):
    playersStates.append(k2)
memN = n
while memN > 0:
    # Finding max number
    maxNumber = -1
    itemId = 0
    for i, item in enumerate(playersStates):
        if item > maxNumber:
            maxNumber = item
            itemId = i
    playersStates[itemId] -= 1
    memN -= 1
for item in playersStates:
    if item <= 0:
        minDeletedPlayers += 1

# Finding max deleted players
playersStates = []
for i in range(a1):
    playersStates.append(k1)
for i in range(a2):
    playersStates.append(k2)
memN = n
while memN > 0:
    # Finding min number
    minNumber = 100500
    itemId = 0
    for i, item in enumerate(playersStates):
        if item < minNumber and item != 0:
            minNumber = item
            itemId = i
    playersStates[itemId] -= 1
    memN -= 1
for item in playersStates:
    if item <= 0:
        maxDeletedPlayers += 1

print(minDeletedPlayers, maxDeletedPlayers)


n,k=map(int,input().split())
a=[1]
j=2
while n>1:
    b=a.copy()
    a.append(j)
    a.extend(b)
    #print(a)
    j=j+1
    n=n-1
print(a[k-1])


n, k = map(int, input().split())
s = [1,2,1]
for i in range(2, n):
    s = s + [i + 1] + s
print(s[k - 1])


n,k=map(int,input().split())
a=[1]
for i in range(n):
    a+=[max(a)+1]
    a+=a[:-1]
    if len(a)>=k:
        break
print(a[k-1])


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

import sys

def main():
    n, k = map(int, input().split())
    seq = [1]
    for i in range(1, n):
        seq = seq + [i + 1] + seq
    print(seq[k - 1])

if __name__ == '__main__':
    main()


x=input().split()
arr=[1]
for i in range(1,int(x[0])+1):
    arr.append(i+1)
    arr=arr+arr[:-1]
    if len(arr)>int(x[1]):
        print(arr[int(x[1])-1])
        break


#inp=open('INPUT.TXT','r')
#n,k=map(int,inp.read().split())
#inp.close()
n,k=map(int,input().split())

biggest_n=2
seq=[1]
for i in range(n-1):
    seq.extend(seq)
    seq.insert(len(seq)//2,biggest_n)
    biggest_n+=1

print(seq[k-1])
#out=open('OUTPUT.TXT','w')
#out.write(str(seq[k-1]))
#out.close()


n,k=map(int,input().split())
s=list([1])
for i in range(2,n+1):
    s.append(i)
    s+=s[:len(s)-1]
print(s[k-1])


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


n,k=map(int,input().split(' '));
arr=[1];
for i in range(2,n+1):
    new_list=arr[:]
    arr.append(i);
    arr.extend(new_list);
print(arr[k-1]);


n,k=map(int,input().split())
s=['1']
c=2
for i in range(0,n-1):
	s=s+s[::-1]
	x=len(s)
	x=x//2
	s.insert(x,c)
	c=c+1
#print(s)
print(s[k-1])


n,k=map(int,input().split())
a=[1]
if(k>=2**(n-1)):
    k=2**n -k
x=len(bin(k)[2:])
for i in range(2,x+1):

    a.extend(a)
    a.insert(len(a)//2,i)

print(a[k-1])


line = input().split()

n = int(line[0])
h = int(line[1])
import numpy as np
array_nodes_minheigt = np.zeros([36,36])
array_nodes_minheigt[0,0] = 1
for nodes in range(1,36):
    for minheight in range(0,nodes+1):
        for topnode in range(1, nodes + 1):
            left = topnode-1
            right = nodes - topnode
            array_nodes_minheigt[nodes,minheight] += array_nodes_minheigt[left,0] * array_nodes_minheigt[right,0] -             (array_nodes_minheigt[left,0]-array_nodes_minheigt[left, max(minheight-1,0)])*             (array_nodes_minheigt[right,0]-array_nodes_minheigt[right, max(minheight-1,0)])

print(int(array_nodes_minheigt[n,h]))


MAX = 10**5 + 1;
grundy = [0 for i in xrange(MAX)];
choice = [-1 for i in xrange(MAX)];
for i in xrange(1,MAX):
    k = 2;
    U = set();
    while k*(k+1)/2 <= i:
        diff = i - k*(k+1)/2;
        if diff % k == 0:
            offset = diff/k;
            x = grundy[offset + k ] ^ grundy[offset];
            if not x: choice[i] = k;
            U.add(x);
        k += 1;
    while grundy[i] in U:
        grundy[i] += 1;
    grundy[i] ^= grundy[i - 1];

n = int(raw_input());
print choice[n];


import math
from collections import Counter

n = int(input())
g = [0 for i in range(n + 1)]
prefix_xor = g.copy()

def in_range(d, k):
    if (2 * k - d * d + d) % (2 * d) != 0:
        return -1
    x = (2 * k - d * d + d) / (2 * d)
    return int(x) if x > 0 else -1

def mex(arr):
    counter = Counter()
    for i in arr:
        counter[i] += 1
    for i in range(0, len(arr) + 1):
        if counter[i] == 0:
            return i

def find_move(arr):
    for i in range(0, len(arr)):
        if arr[i] == 0:
            return i
    return -1

for i in range(3, n + 1):
    for_range = range(2, int(math.sqrt(2 * i)) + 1)
    filter_range = [l for l in for_range if in_range(l, i) > 0]
    branches = [prefix_xor[in_range(d, i) + d - 1] ^ prefix_xor[in_range(d, i) - 1] for d in filter_range]
    g[i] = mex(branches)
    prefix_xor[i] = prefix_xor[i-1] ^ g[i]
    if i == n:
        print(-1 if g[i] == 0 else filter_range[find_move(branches)])


import math
n, k = map(int, input().split())
dp = [[1 for _ in range(k+1)] for _ in range(n+1)]
for i in range(1, n+1):
    f = set((1, i))
    for m in range(2, int(math.sqrt(i))+1):
        if i%m==0:
            f.add(m)
            if i/m != i:
                f.add(i//m)
    f = list(f)
    for j in range(2, k+1):
        dp[i][j] = 0
        for x in f:
            dp[i][j] += dp[x][j-1]
ans = 0
for i in range(1, n+1):
    ans += dp[i][k]
    ans %= 1000000007
print(ans%1000000007)


m,s=[int(i) for i in input().split()]
if (s<1 and m>1) or s>9*m:
    print('-1 -1')
elif s==0 and m==1:
    print('0 0')
else:
    n=s//9
    l=s-9*n
    mi=0

    ma0=[str(9)]*n
    if l!=0:
        ma0.append(str(l))
        for i in range(m-n-1):
            ma0.append(str(0))
    else:
        for i in range(m-n):
            ma0.append(str(0))
    ma=''.join(ma0)

    if l!=0:
        for i in range(n):
            mi+=9*10**(i)
        if l!=0 and s>9*(m-1) and n>0:
            mi+=l*10**(n)
        elif l!=0 and s<9*(m-1) and n>0:
            mi+=10**(m-1)+(l-1)*10**(n)
        elif l!=0 and n==0:
            mi+=10**(m-1)+(l-1)
    elif l==0 and s==9*m:
        for i in range(n):
            mi+=10**(m)-1
    else:
        mi+=10**(m-1)
        for i in range(n-1):
            mi+=9*10**(i)
        mi+=8*10**(n-1)

    print(int(mi),int(ma))


n,k=map(int,input().split())
a=list()
c=0
for i in range (1,n+1):
	if(n%i==0):
		a.append(i)
		c+=1
if(c<k):
	print("-1")
else:
	print(a[k-1])


a,b=[int(i) for i in input().split()]
s=[int(i) for i in input()split()]
m=0
c=b
for i in range(a):
    if s[i]>c:
        m=m+1
        c=b
    else:
        c=c-s[i]
print(m)


n ,a ,b = map(int,input().split())
if ((a+b)=n ) or ((a+b)>n ):
    print(n-a)
else:
    print(b+1)


#!/usr/bin/python3

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

a -= 1
b -= 1
if a // m == b // m:
    print(1)
elif a % m == 0 and (b + 1) % m == 0:
    print(1)
elif a % m == 0 or (b + 1) % m == 0:
    print(2)
elif a % m == (b + 1) % m:
    print(2)
elif b // m - a // m == 1:
    print(2)
elif m == 2:
    print(2)
else:
    print(3)


def binm(n, k,mod):
    C = [[0 for x in range(k+1)] for x in range(n+1)]

    # Calculate value of Binomial Coefficient in bottom up manner
    for i in range(n+1):
        for j in range(min(i, k)+1):
            if j == 0 or j == i:
                C[i][j] = 1

            # Calculate value using previously stored values
            else:
                C[i][j] = C[i-1][j-1] + C[i-1][j]
            C[i][j]%=mod

    return C[n][k]%mod
n,m=[int(i) for i in raw_input().split()]
mod=998244353
if n==2:
    print 0
else:
    val=1
    for i in range(n-3):
        val*=2
        val%=mod
    print ((n-2)*val*binm(m,n-1,mod))%mod


import sys
input = sys.stdin.readline
def main():
  #  t = int(input())
    t = 1
    while(t):
  #  for _ in range(t):
        t -= 1

        MOD = 998244353
        fact = [1]*200005
        for i in range(1, 200005):
            fact[i] = i*fact[i-1]

        def fast_sq(a, b):
            ans = 1
            if(b == -1):
                b = MOD-2
            for i in range(60):
                if((1<<i)&b):
                    ans *= a
                a *= a
            return ans
        n, m = map(int, input().split())
        print(fact[m]*(n-2)*fast_sq(2, n-3)*fast_sq(fact[n-1]*fact[m-n+1], -1)%MOD)

main()


n=list(map(int,input()).split()))
f,s,w=0,0,0
for i in range(7):
    if abs(k[0]-i)<abs(k[1]-i):
        f+=1
    elif abs(k[0]-i)>abs(k[1]-i):
        s+=1
    else:
        w+=1
print(f,w,s)


tramEndPoint, igorStartPos, igorEndPos = map(int, raw_input().split())
tramS, igorS = map(int, raw_input().split())
tramStartPos, tramDir = map(int, raw_input().split())

igorTime = abs(igorEndPos-igorStartPos)*igorS

getIgorTime = 0
getToEndTime = 0

distToIgor = igorStartPos - tramStartPos
if (distToIgor > 0 and tramDir > 0) or (distToIgor < 0 and tramDir < 0):
    getIgorTime = abs(distToIgor)*tramS
else:
    if tramDir > 0:
        toEnd = tramEndPoint-tramStartPos
        getIgorTime = (toEnd+(tramEndPoint-igorStartPos))*tramS
    else:
        toBeg = tramStartPos
        getIgorTime = (toBeg+igorStartPos)*tramS
    tramDir *= -1

tramStartPos = igorStartPos

distToEnd = igorEndPos - tramStartPos
if (distToEnd > 0 and tramDir > 0) or (distToEnd < 0 and tramDir < 0):
    getToEndTime = abs(distToEnd)*tramS
else:
    if tramDir > 0:
        toEnd = tramEndPoint-tramStartPos
        getToEndTime = (toEnd+(tramEndPoint-igorEndPos))*tramS
    else:
        toBeg = tramStartPos
        getToEndTime = (toBeg+igorEndPos)*tramS

print min(igorTime, (getIgorTime+getToEndTime))


ef game(a,b,count):
    if(a==0 or b==0):
        return count
    else:
        mi=min(a,b)
        ma=max(a,b)
        return game(mi+1,ma-2,count+1)

a,b=map(int,input().split())
if(a<3 and b<3):
    print(0)
else:
    res=game(a,b,0)
    print(res)


k,a,b=map(int,input().split())
ctr=int(0)
if (a<k and b<k) or (a%k!=0 and b<k) or (b%k!=0 and a<k):
    exit(print('-1'))
while a>=k or b>=k:
    if a>=k:
        a-=k
        ctr+=1
    if b>=k:
        b-=k
        ctr+=1
exit(print(ctr))


x=int(input())
z=[n for n in str(int(input()))]
l=0
for n in z:
  in n!=4 or n!=7:
    print('NO')
    l=0
    break
  else:
    l=1
if l==1:
  if sum(z[0::x//2])==sum(z[x//2:x])
    print('YES')
  else:
    print('NO')


n,m=map(int,input().split())
if m!=0:
    print([min(m,n-m))
else:
    print('1')


n=int(input())
m=int(input())
k=min(m,n-m)
if(m==1 or m==0):
    print(1)
    return 0
if(m==n):
   print(0)
else:
    print(k)


#!/usr/bin/python
import sys

def ext_gcd(a, b):
    if b == 0:
        return (a, 1, 0)
    (dp, xp, yp) = ext_gcd(b, a % b)
    return (dp, yp, xp - a//b * yp)

def mod_solve(a, b, n):
    (d, xp, yp) = ext_gcd(a, n)
    if b % d == 0:
        x0 = xp * (b/d) % n
        return x0
    else:
        return None

def choose(n, m, MOD):
    result = 1
    for i in xrange(1, n+1):
        result = (result * i) % MOD
    for i in xrange(1, n-m+1):
        result = (result * mod_solve(i, 1, MOD)) % MOD
    for i in xrange(1, m+1):
        result = (result * mod_solve(i, 1, MOD)) % MOD
    return result

MOD = 1000000007
(n, m, g) = map(lambda x: int(x), raw_input().split())
if n == 0:
    if (m == 1 and g == 1) or (m > 1 and g == 0):
        result = 1
    else:
        result = 0
    print(result)
    sys.exit(0)

if m == 0:
    if (n % 2 == 0 and g == 1) or (n % 2 == 1 and g == 1):
        result = 1
    else:
        result = 0
    print(result)
    sys.exit(0)

term = 1
result = term
for i in xrange(1, n+1):
    term = (term * (m + i) * mod_solve(i, 1, MOD)) % MOD
    if i % 2 == 0:
        result = (result + term) % MOD
    else:
        result = (result + MOD - term) % MOD
if n % 2 == 1:
    result = (MOD - result) % MOD
if m == 1:
    if n % 2 == 0:
        result = (result + MOD - 1) % MOD
    else:
        result = (result + 1) % MOD
if g == 1:
    result = (choose(n+m, m, MOD) + MOD - result) % MOD
print(result)


import operator as op
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def ncr(n, r):
    r = min(r, n-r)
    if r == 0: return 1
    numer = reduce(op.mul, xrange(n, n-r, -1))
    denom = reduce(op.mul, xrange(1, r+1))
    return numer//denom

N,M,G = map(int, raw_input().split())
def q(n):
	return ncr(n+M, M)

mod = 1000000007
r = [0] * (N+M+1)
r[1] = 1;
for i in range(2, N+M+1):
	r[i] = (mod - (mod/i) * r[mod%i] % mod) % mod;
#~ print r

def f(n):
	n -= 1
	sign = 1 if (n%2 == 0) else -1
	res = 0
	k = 0

	binom = 1

	while k <= n:
		res = (res + sign * binom) % mod
		binom = (binom * (k+M+1) * r[k+1]) % mod

		sign *= -1
		k += 1
	if M == 1:
		res += sign
	return res
if M == 0:
	print int(G == (N+1)%2)
	raise SystemExit

if G == 1:
	print f(N)
else:
	print q(N)-f(N)


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

sb = 0
s = 0

for i in range(len(l)):
    if(l[i] < b):
        sb += 1
    elif(l[i] = b):
        s = 1
    else:
        break
print(b-sb+s)


n,k,d = map(int,input().split())
import sys
sys.setrecursionlimit(10**6)
mod = int(1e9+7)

def rec(n,d):
    if n<0:return 0
    if n==0:
        return d==0
    res = 0
    for i in range(1,k+1):
        if i>=d:
            res+=rec(n-i,0)
        else:
            res+=rec(n-i,d)
        res%=mod
    return res%mod
print(rec(n,d)%mod)


    MOD = 10 ** 9 + 7
    HAVE, NOT_HAVE = 1, 0

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

    dp = [[0 for _ in range(n + 1)] for _ in range(2)]
    dp[NOT_HAVE][0] = 1
    for dist in range(1, n + 1):
        for weight in range(1, k + 1):
            if weight > dist:
                break
            if weight >= d:
                dp[HAVE][dist] += dp[HAVE][dist - weight] + dp[NOT_HAVE][dist - weight]
                dp[HAVE][dist] %= MOD
            else:
                dp[NOT_HAVE][dist] += dp[NOT_HAVE][dist - weight]
                dp[NOT_HAVE][dist] %= MOD
                dp[HAVE][dist] += dp[HAVE][dist - weight]
                dp[HAVE][dist] %= MOD
    print(dp[HAVE][n])


n = int(input())
o1,o2 = map(int,input().split())
s1,s2 = map(int,input().split())
t1,t2 = map(int,input().split())

a1,a2,a3=0,0,0
for i in range(o1,o2+1):
    for j in range(s1,s2+1):
        for k in range(t1,t2+1):
            if i+j+k==n:
               a1,a2,a3=i,j,k
               break
print(a1,a2,a3)


def DFS(x):
    for i in range(x):
        if(Seen[i]):
            continue
        if(Rem[i]>=C[x]):
            if(Rem[i]==C[x] and len(Children[i])==0):
                continue
            Rem[i]-=C[x]
            Parent[x]=i
            Children[i].append(x)
            return True
    for i in range(x):
        if(Seen[i]):
            continue
        Y=[]
        Seen[i]=True
        for j in range(len(Children[i])):
            child=Children[i][j]
            Parent[child]=-1
            Rem[i]+=C[child]
            if(DFS(child)):
                continue
            Parent[child]=i
            Rem[i]-=C[child]
            Y.append(child)
        Seen[i]=False
        Children[i]=list(Y)
        if(Rem[i]>=C[x]):
            if(Rem[i]==C[x] and len(Children[i])==0):
                continue
            Rem[i]-=C[x]
            Children[i].append(x)
            Parent[x]=i
            return True
    return False

n=int(input())

C=list(map(int,input().split()))
Rem=[-1]*n
Parent=[-1]*n
Children=[]
Seen=[False]*n
C.sort(reverse=True)

if(C[0]!=n or C.count(2)>0):
    print("NO")

else:
    for i in range(n):
        Rem[i]=C[i]-1
        Children.append([])
    Parent[0]=0
    Ans="YES"
    for i in range(1,n):
        if(DFS(i)==False):
            Ans="NO"
            break
    for i in range(n):
        if(Rem[i]!=0 and C[i]!=1):
            Ans="NO"
            break
    print(Ans)


N = 2000000000
t = 0
a = [1]
b = [1]
c = []
for i in range(1, 31):
    a.append(a[i-1]*2)
for i in range(1, 20):
    b.append(b[i - 1] * 3)
for i in range(0,31):
    print(a[i])
for i in range(0,20):
    print(b[i])
for i in range(0, 31):
    for j in range(0, 20):
        if(a[i] <= N/b[j]):
            c.append(a[i] * b[j])
            t+=1

for i in range(0, 10):
    print(c[i])
print("t=%s"%t)
l, r = map(int, input().split())
cnt = 0
for i in range(0, 326):
    if(c[i] >= l):
        if(c[i] <= r):
            cnt = cnt + 1

print(cnt)


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

import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys

"""
created by shhuan at 2017/12/2 22:13

"""

f0 = "What are you doing at the end of the world? Are you busy? Will you save us?"

MAXN = 10**5+5
F = [0] * MAXN
F[0] = len(f0)

p1 = "What are you doing while sending \""
p2 = "\"? Are you busy? Will you send \""
p3 = "\"?"
lp1, lp2, lp3 = len(p1), len(p2), len(p3)
l = lp1 + lp2 + lp3

for i in range(0, MAXN-1):
    F[i+1] = 2 * F[i] + l
    # s[i+1] = p1 + si + p2 + si + p3

def solve(n, k):
    if n == 0:
        if k > len(f0):
            return '.'
        return f0[k-1]

    if k <= lp1:
        return p1[k-1]
    elif k <= lp1 + F[n-1]:
        return solve(n-1, k-len(p1))
    elif k <= lp1 + F[n-1] + lp2:
        return p2[k-lp1-F[n-1]-1]
    elif k <= lp1 + lp2 + 2*F[n-1]:
        return solve(n-1, k-lp1-lp2-F[n-1])
    elif k <= lp1 + lp2 + 2*F[n-1] + lp3:
        return p3[k-lp1-lp2-2*F[n-1]-1]
    else:
        return '.'

Q = int(input())

ans = ""
for i in range(Q):
    N, K = map(int, input().split())
    ans += solve(N, K)

print(ans)


n, p = [int(i) for i in input().split()]
i = 1
f = True
while n - i*p >= 1:
    if bin(n - i*p)[2:].count("1") <= i and (i < n - i*p):
        print(i)
        f = False
        break
    i += 1

if f:
    print("-1")


from collections import Counter
n=int(input())
l=[]
for i in range(n):
    x,y=map(int,input().split())
    l.append(x)
    l.append(y)
d=Counter(l)
s1=list(d.values())
f=True
if(len(list(d.keys()))<=3):
    print('WIN')
    exit()
for p in s1:
    if(p==1):
        print('WIN')
        f=False
        break
    elif(p>=3):
        print('WIN')
        f=False
        break
if(f):
    print('FAIL')


mod = 1000000007
def power(a, p):
    res = 1
    while p > 0:
        if p % 2 == 1:
            res = (res * a) % mod
        a = (a * a) % mod
        p //= 2
    return res
n, m = map(int, input().split())
n += 1
res = (power(n * 2, m))*(n-m)/n
res = res % mod
print(int(res))


result = []
cout = int(input())
for i in range(0,cout):
	g = int(input())
	result.append(g)
result.sort()
cout = int(cout)
if cout%2 != 0:
	v = cout//2 + 1;
else:
	if cout/2 - result[0] == result[cout - 1] - cout/2:
		v = cout / 2
	else:
		v = cout / 2 + 1
v = int(v)
print(result[v-1])


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

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

n,a,b,c,d=value()
ans=0

minSum=a+b+2
maxSum=a+b+2*n

for mid in range(1,n+1):
    box1=(a+b+mid+1,a+b+mid+n)
    box2=(a+c+mid+1,a+c+mid+n)
    box3=(c+d+mid+1,c+d+mid+n)
    box4=(d+b+mid+1,d+b+mid+n)

    minSum=max(box1[0],box2[0],box3[0],box4[0])
    maxSum=min(box1[1],box2[1],box3[1],box4[1])

    # print(minSum,maxSum)
    ans+=max(maxSum-minSum+1,0)

print(ans)


import sys
import math
import bisect

MOD = int(1e9+7)

# n = map(int, raw_input().split())
input = map(int, raw_input().split())
if input[-1] == input[0] and input[0] !=0 :
    print 1
elif input[-1] == input[0] and input[0] == 0 and input[1] == 0:
    print 1
else:
    print 0


# N boxes can be filled with type H or type T objects
# 1 H object takes 1 box
# 1 H can turn into M T objects which must take contiguous boxes
# How many ways to fill N boxes?

# E.g. N=4, M=2 -> return 5: HHHH, HHTT, HTTH, TTHH, TTTT

# Constraints: N <= 10^18

def _solve(n, m, memo):
	if n <= 0: return 0
	if n < m: return 1
	if n == 1: return 2
	if (n, m) in memo: return memo[(n, m)]

	out = 0
	mid = n // 2

	# No M block hanging over 2 halves
	out += _solve(mid, m, memo) * _solve(n-mid, m, memo) % 1000000007

	# M block over 2 halves
	for i in range(1,m):  # i = part of M block in first half
		if mid-i < 0 or n-mid+i-m < 0: continue
		n1 = 1 if mid-i == 0 else _solve(mid-i, m, memo)
		n2 = 1 if n-mid+i-m == 0 else _solve(n-mid+i-m, m, memo)
		out += n1*n2

	memo[(n, m)] = out
	return out

def solve(n, m):
	return _solve(n, m, {})

def main():
	from sys import stdin

	n, m = list(map(int, stdin.readline().strip().split()))
	out = solve(n, m)
	print('{}'.format(out))

if __name__ == '__main__':
	main()


def countstr(item, str):
    ret = 0
    for i in xrange(len(str)-len(item)+1):
        ret += (str[i:len(item)+i]==item)
    return ret

def numerate(n):
    if 1==n:
        return ['4', '7']
    l = numerate(n-1)
    return [item+'4' for item in l] + [item+'7' for item in l] + ['4'+item for item in l] + ['7'+item for item in l]

s = raw_input()
counts = {}
for i in xrange(1, len(s)+1):
    l = numerate(i)
    cont = False
    for item in l:
        counts[item] = countstr(item, s)
        cont = cont or counts[item]!=0
    if not cont:
        break
tmp = counts.items()
tmp.sort(cmp=lambda x,y: cmp(x[0],y[0]) if x[1]==y[1] else y[1] - x[1])
print tmp[0][0] if tmp[0][1]>0 else -1


t=[]
for i in range(1,501):
    t.append(i(i+1)//2)
n=int(input())
if n in t:
    print('YES')
else:
    print('NO')


N = raw_input()
soma = 0
for i in range(1, int(N) + 1):
	soma += len(str(i))

print soma


import math

vectors = []

line_parts = raw_input().split()
x = int(line_parts[0])
y = int(line_parts[1])
n = int(line_parts[2])
d = int(line_parts[3])

for i in range(n):
  l = raw_input().split()
  vectors.append((int(l[0]), int(l[1])))

mp = {}

def canWin(x, y, t, fs, ss):

  if math.sqrt(math.pow(x, 2) + math.pow(y, 2)) > float(d):
    return False

  if (x, y, t) in mp:
    return mp[(x, y, t)]

  result = True

  if t == False and ss == False:  #if Dasha turn and if dasha hasnt swapped then can swap 1 time
    for v in vectors:
      result = result and (not (canWin(x + v[0], y + v[1], not t, fs, ss)))
    result = result and (not canWin(y, x, not t, fs, True))
  elif t == True and fs == False: #if Anton turn and if Anton hasnt swapped then can swap 1 time
    for v in vectors:
      result = result and (not (canWin(x + v[0], y + v[1], not t, fs, ss)))
    result = result and (not canWin(y, x, not t, True, ss))
  else: #since both has swapped 1 time now cannot swap further
    for v in vectors:
      result = result and (not (canWin(x + v[0], y + v[1], not t, fs, ss)))

  mp[(x, y, t)] = result

  return result

result = False

for v in vectors:
  result = result or canWin(x + v[0], y + v[1], False, False, False)

if result == True:
  print "Anton"
else:
  print "Dasha"


import sys
from array import array  # noqa: F401

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

x, y, n, d = map(int, input().split())
vector = [list(map(int, input().split())) for _ in range(n)]
dp = [-1] * (1 << n)

def solve(bit, x, y):
    if dp[bit] != -1:
        return dp[bit]

    for i in range(n):
        if (1 << i) & bit:
            continue
        if (x + vector[i][0]) ** 2 + (y + vector[i][1])**2 <= d**2 and solve(bit | (1 << i), x + vector[i][0], y + vector[i][1]) == 0:
            dp[bit] = 1
            return 1

    dp[bit] = 0
    return 0

if solve(0, x, y):
    print('Anton')
else:
    print('Dasha')


n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
c1=0
for i in a:
    if i>=n:
        c+=1
        break
for i in b:
    if i>=n:
        c1+=1
        break

if c=1 or c1=1:
    print('No')
else:
    print('Yes')


'''input
7
2 3 4 1 6 7 5
'''

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

def ri():
    return int(input())

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

def lcm(xs):
    if not xs:
        return 1
    if len(xs) == 1:
        return x[0]
    if len(xs) == 2:
        return (xs[0] * xs[1]) // gcd(xs[0], xs[1])
    return lcm(xs[:-2] + [lcm([xs[-2], xs[-1]])])

def dfs_cycle_length(arr, u, visited, origin):
    visited.add(u)
    nxt = arr[u-1]
    if nxt in visited:
        return None if nxt != origin else 1
    tmp = dfs_cycle_length(arr, nxt, visited, origin)
    return None if tmp is None else tmp + 1

def solve(arr):
    cycles = []
    visited = set([])
    for u in range(1, len(arr) + 1):
        if u not in visited:
            length = dfs_cycle_length(arr, u, visited, u)
            if length is None:
                return -1
            cycles.append(length//2 if length % 2 == 0 else length)
    return lcm(cycles)

def main():
    n = ri()
    arr = rints()
    print(solve(arr))

main()


a,b,l,r = map(int,raw_input().split())
s = "a"
for i in range(1,a):
    temp = s[i-1]
    #print temp
    x = ord(temp)
    x += 1
    s += chr(x)
#print s
for i in range(b):
    s += s[-1]
#print s
temp = s[-1]
if b>=a :
    s += s[:a-1]
    s += chr(ord(temp)+1)
else :
    s += s[:b]
    s += chr(ord(temp)+1)
    for i in range(a-b-1):
        temp = s[-1]
        #print temp
        x = ord(temp)
        x += 1
        s += chr(x)
#print s
for i in range(b):
    s += s[-1]
#print s
length = len(s)
s = '_' + s
if r-l+1 >= length :
    print len(set(s))-1
else :
    start = l%length
    if start==0 :
        start = length
    i = start
    end = r%length
    if end==0 :
        end = length
    ans = {}
    while(start!=end) :
        ans[s[start]] = 1
        start += 1
        if start>length :
            start = 1
    ans[s[start]] = 1
    print len(ans)


def main(a, b, l, r):

    qL = (l - 1) // (2 * a + 2 * b)
    rL = (l - 1) % (2 * a + 2 * b) + 1

    qR = (r - 1) // (2 * a + 2 * b)
    rR = (r - 1) % (2 * a + 2 * b) + 1
    #print(qL, qR, rL, rR)
    if qL == qR:
        #In b segment
        if a < rL <= a + b and a < rR <= a + b:
            return 1
        if 2 * a + b < rL and 2 * a + b < rR:
            return 1
        #In a segment
        if 1 <= rL <= a and 1 <= rR <= a:
            return rR - rL + 1
        if a + b < rL <= 2 * a + b and a + b < rR <= 2 * a + b:
            return rR - rL + 1
        #In a + b segment
        if 1 <= rL <= a + b and 1 <= rR <= a + b:
            return a - rL + 1
        if a + b < rL and a + b < rR:
            return (2 * a + b) - rL + 1
        if a < rL <= a + b and a + b < rR <= 2 * a + b:
            return 1 + rR - (a + b)
        if a < rL <= a + b and 2 * a + b < rR:
            return 1 + a
        if 1 <= rL <= a and a + b < rR <= 2 * a + b:
            ans = a - rL + 1 + max(rR - (a + b + b), 0) + min(b, rR) - max(min(rR, b) - rL + 1, 0)
            return ans
        if 1 <= rL <= a and 2 * a + b < rR:
            return a - rL + 1 + a - max(b - rL + 1, 0)
    elif qL == qR - 1:
        #abababab
        newL = qL * (2 * a + 2 * b) + 1
        newR = (qR + 1) * (2 * a + 2 * b)

        if 1 <= rL <= a + b and a + b + 1 <= rR:
            return a + max(a - b, 0) + int(a <= b)

        if a + b + 1 <= rL <= 2 * (a + b) and (2 * a + 2 * b) + 1 <= rR <= a + b:
            return main(a, b, l - (a + b), r - (a + b))

        if 1 <= rL <= a and 1 <= rR <= a:
            return a + max(a - b, 0) + int(a <= b) + rR - max(rR - rL + 1, 0)
        if 1 <= rL <= a and a + 1 <= rR <= a + b:
            return a + max(a - b, 0) + int(a <= b)

        if a + 1 <= rL <= a + b and 1 <= rR <= a:
            return 1 + a + max(a - b, 0)
        if a + 1 <= rL <= a + b and a + 1 <= rR <= a + b:
            return 1 + a + max(a - b, 0)

        return main(a, b, l - (a + b), r - (a + b))

    else:
        return a + max(a - b, 0) + int(a <= b) # + main(a, b, l, (qL + 1) * (2 * a + 2 * b)) + main(a, b, qR * (2 * a + 2 * b) + 1, r)

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

print(main(a, b, l, r))


a = input()
tot = len(a)
if a[tot-1] = 0:
    m = int(10)
    n = int(a[0:tot-3])
else:
    m = int(a[tot-1])
    n = int(a[0:tot-2])
min = n//2 + 1
max = n
small = min //m
big = max //m
if small % m == 0:
    print(small)
elif small == big:
    print(-1)
elif small < big:
    print(small+1)


n, m = list(map(int, input().split()))
l = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = []
for i in range(m):
    ans = 0
    if a[i] in l:
        for j in range(l.index(a[i]), n):
            if l[j] in a:
                ans += 1
    cnt.append(ans)
for i in range(l.index(a[cnt.index(max(cnt))]), n):
    if l[i] in a:
        print(l[i], end=' ')


n=int(input())
s=input()
a=set()
mx=0
for i in s:
	if(isupper(i)):
		s.clear()
	else:
		if(islower(i)):
		    s.add(i)
            mx=max(mx,len(s))

print(mx)


alphabet = 'abcdefghijklmnopqrstuvwxyz'
alphabet_h = alphabet.upper()
alpha = tuple(alphabet)
alpha_h = tuple(alphabet_h)
n = int(input())
s = str(input())
g = 0
i = 1

while i <= n-1:
  if s[i-1] in alpha:
    while s[i] in alpha_h:
     # print(s[i], i)
      g = g + 1
      i = i + 1
   #   print(i)
      if i>=n-1 or s[i] in alpha:
        break
  i = i + 1
i = n - 1
if s[n-1] in alpha_h and g > 0:
  while s[i] in alpha_h and i>=0:
    g = g - 1
    i = i - 1
if n = 1 and s[0] in alpha:
  g = 1

print(g)


s = input()
t = input()
ind = []
for i in range(0,len(s)):
    if s[i:i+len(t)] == t:
        ind.append(i)
ss = len(s)
maxx = 0
for i in ind:
    k = i+len(t)
    maxx = max(len(s[k:ss)]),len(s[0:i]))
print(maxx)


input()
x = []
for i in list(map(int,input.split()))[::-1]:
    if not i in x:
        x.append(i)
print(len(x))
print(*x[::-1]


n=int(input())
l=list(map(int,input().split()))
s=set(l)
c=0
while len(l)!=len(s):
	if l.count(l[c])>1:
		l.remove(l[c])
	else:
		c+=
print(len(l))
print(*l)


N = int(input())
M = 10 ** 8 + 5
pr = [True] * M
pr[0], pr[1] = False, False
for i in range(2, M):
    if pr[i]:
        for j in range(i * 2, M, i):
            pr[j] = False

prime = list(filter(lambda x: pr[x], range(M)))

def calc(n, k):
    if n == 0:
        return k
    elif n % 2 == 0:
        return n // 2 + k
    else:
        for i in prime:
            if n % i == 0:
                n -= i
                return calc(n, k + 1)

print(calc(N, 0))


def f(a,b):
    m=0
    if a>b:
        return a-b
    else:
        return b-a
n,b=[int(i) for i in input().split()]
tb=0
tn=0
for i in range(1,7):
    if f(i,n)<f(i,b):
        tn=tn+1
    elif f(i,n)>f(i,b):
        tb=tb+1
print(tn,6-(tb+tn),tb


k=int(input()
a=list(map(int,input().split()))
if max(a)<25:
    print(0)
else:
    print(max(a)-25)


s = input().split(' ')
if len(s) == 3:
    if (s[0].isnumeric()) and (s[1].isnumeric()) and (s[2].replace("-","").isnumeric()):
        n = int(s[0])
        a = int(s[1])
        b = int(s[2])
        if (n >= 1) and (n <= 100) and (a >= 1) and (a <= n) and (b >= -100) and (b <= 100):
            s = ""
            copy = ""
            for i in range(1, n + 1):
                s += str(i)
            copy = s
            m = abs(b) if abs(b) > n else n
            while len(s) < m:
                s += copy
            indA = s.index(str(a))
            indB = s.index(str(abs(b))) if abs(b) < n else int(s[abs(b) - 1])
            k = 0 if b < 0 else 1 + int(s[indA])
            print(indB - indA + k)


def abc(vertices):
    points = []
    points.append((vertices[0]-vertices[2])**2 + (vertices[1]-vertices[3])**2)
    points.append((vertices[0]-vertices[4])**2 + (vertices[1]-vertices[5])**2)
    points.append((vertices[4]-vertices[2])**2 + (vertices[5]-vertices[3])**2)
    points.sort()
    return points

def almost(vertices, index):
    vertices[index] -= 1
    if (vertices[0] == vertices[2] and vertices[1] == vertices[3]) or (vertices[0] == vertices[4] and vertices[1] == vertices[5]) or (vertices[2] == vertices[4] and vertices[3] == vertices[5]):
        vertices[i] += 1
        return False

    if (vertices[0] == vertices[2] and vertices[2] == vertices[4]) or (vertices[1] == vertices[3] and vertices[3] == vertices[5]):
        vertices[i] += 1
        return False

    a,b,c = abc(vertices)
    if (a+b == c):
        return True

    vertices[index] += 2
    if (vertices[0] == vertices[2] and vertices[1] == vertices[3]) or (vertices[0] == vertices[4] and vertices[1] == vertices[5]) or (vertices[2] == vertices[4] and vertices[3] == vertices[5]):
        vertices[i] -= 1
        return False

    if (vertices[0] == vertices[2] and vertices[2] == vertices[4]) or (vertices[1] == vertices[3] and vertices[3] == vertices[5]):
        vertices[i] -= 1
        return False

    a,b,c = abc(vertices)
    if (a+b == c):
        return True

    vertices[index] -= 1
    return False

vertices = map(int, raw_input().split())
def run():
    a,b,c = abc(vertices)
    if a+b == c:
        return "RIGHT"
    for i in xrange(6):
        if almost(vertices, i):
            return "ALMOST"
        return "NEITHER"

print run()


a,b,s=map(int,input().split())
w=s-abs(a)-abs(b)
if(w>=0 and w%2==0)
	print("YES")
else
	print("NO")


a,b, step = map(int, input().split())
step -= (a+b)
if step >= 0 and step%2 == 0
	print("Yes")
else
	print("No")


n=input()
if len(n)==1:
    print(0)
else n[::-1]!=n:
    print(len(n))
else:
    while True:
        n=n[:-1]
        s=n[::-1]
        if s!=n:
            print(len(s))
            break
        elif len(s)==1:
            print(0)
            break


import sys

def WeirdSub(a,b):
    while(True):
        if a == 0 or b == 0:
            return a,b
            break
        if a>=(2*b):
            a = a-(2*b)
            WeirdSub(a,b)
        if b>=(2*a):
            b= b-(2*a)
            WeirdSub(a,b)
        else:
            break
    return a,b

#===================MAIN===========
a,b = map(int,sys.stdin.readline().split())
#print(f"{a},{b}")
l=list(WeirdSub(a,b))
a=l[0]
b=l[1]
print(a,b)


def satisfies(cnt1, cnt2, onlyX, onlyY, none):
    '''
    tells whether you can form presents using the numbers
    '''
    cnt1 = max(cnt1 - onlyY, 0)
    cnt2 = max(cnt2 - onlyX, 0)
    return (cnt1 + cnt2 <= none)

import sys
cnt1, cnt2, x, y = int(sys.stdin.readline()).split()
bothXY = 0
onlyX = 0
onlyY = 0
none = 0
v = 0
while(not satisfies(cnt1, cnt2, onlyX, onlyY, none)):
    v += 1
    if(v % (x * y) == 0):
        bothXY += 1
    elif(v % x == 0):
        onlyX += 1
    elif(v % y == 0):
        onlyY += 1
    else:
        none += 1
print v


import fileinput

def str_to_int(s):
	return([ int(x) for x in s.split() ])

# args = [ 'line 1', 'line 2', ... ]
def proc_input(args):
	return(str_to_int(args[0]))

def solve(args, verbose=False):
	(cnt_x, cnt_y, x, y) = proc_input(args)
	forbid_x = set([ i * x for i in xrange(1, cnt_x + cnt_y) ])
	forbid_y = set([ i * y for i in xrange(1, cnt_x + cnt_y) ])
	set_x = [ 1 ] * cnt_x
	set_y = [ 1 ] * cnt_y
	count_x = count_y = 0
	i = 1
	if cnt_x > cnt_y:
		count_x += 1
	else:
		count_y += 1
	while count_x < cnt_x or count_y < cnt_y:
		i += 1
		if (i not in forbid_x) and (count_x < cnt_x):
			set_x[count_x] = i
			count_x += 1
		elif (i not in forbid_y) and (count_y < cnt_y):
			set_y[count_y] = i
			count_y += 1
	if verbose:
		print i
	return(i)

def test():
	assert(str_to_int('1 2 3') == [ 1, 2, 3 ])
	assert(solve([ '3 1 2 3' ]) == 5)
	assert(solve([ '1 3 2 3' ]) == 4)

if __name__ == '__main__':
	from sys import argv
	if argv.pop() == 'test':
		test()
	else:
		solve(list(fileinput.input()), verbose=True)


import math
verno=int(raw_input())
pointlist= list()
for i in range(verno):
    point=map(int, raw_input().split())
    pointlist.append(point)

l=0
w=0
area=0
if verno==1:
    print -1
else:
    l= abs(pointlist[0][0]-pointlist[1][0])
    w= abs(pointlist[0][1]-pointlist[1][1])
    area=l*w
    print area


s = raw_input().lower()
s = filter(lambda c: c not in set("aeiou"), s)
t = ""
for c in s:
    t += "."+c
print t