peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
n,m=map(int,input().split())
ka=[list(map(int,input().split())) for _ in range(n)]

flg = [0] * (m+1)
for i in range(n):
  for j in range(ka[i][0]):
    food = ka[i][j]
    flg[food] += 1

result = 0
for i in range(m+1):
  if flg[i] == n:
    result += 1
print(result)
# Judge status: Wrong Answer
n,d=map(int, input().rstrip().split())
m=[]
for _ in range(n):
    arr=list(map(int, input().rstrip().split()))
    m.append(arr)
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        a = 0
        for k in range(d):
            a += (m[i][k] - m[j][k])**2
        x = int(a**(1/2))
        if x*2 == a:
            ans+=1
print(ans)
# Judge status: Wrong Answer
N, Q = [int(i) for i in input().split()]
S = input()
lr = [[int(i) for i in input().split()] for _ in range(Q)]
ary = [0]
c = 0
f = bool(S[0] == "A")
for i in range(1, N):
    if S[i] == 'C' and f:
        c += 1
        f = False
    else:
        f = bool(S[0] == "A")
    ary.append(c)
for l, r in lr:
    print(ary[r-1]-ary[max(0, l-1)])
# Judge status: Wrong Answer
N = int(input())
L = sorted(list(map(int, input().split())))

max_length = L[-1]
sum_length = sum(L[0:len(L)-1])
print(sum_length)

print("Yes") if max_length > sum_length else print("No")
# Judge status: Accepted
N=int(input())
s=input()
t=input()
for i in range(N+1):
    for j in range(N-i):
        if s[i+j]!=t[j]:
            break
    else:
        print(N+i)
        break
# Judge status: Accepted
A,B,C = map(int,input().split())

print(max(0,C-(A-B)))
# Judge status: Wrong Answer
value = int(input())
kyu_rated = 8
lvalue = 400
rvalue = 599
if 400 <= value <= 1999:
    for i in range(0, 7):
        if lvalue <= value <= rvalue:
            print(kyu_rated)
            flag = 1
            break
        else:
            lvalue += 200
            rvalue += 200
            kyu_rated -= 1
# Judge status: Accepted
x, y = map(int, input().split())
i = 0
while x <= y:
    x = x * 2
    i += 1
print(i)
# Judge status: Wrong Answer
N = int(input())
ab = []
for i in range(N):
    ab.append(tuple(map(int,input().split())))

up = sorted(ab,key=lambda a:a[0])
down = sorted(ab,key=lambda a:a[1])
if N%2 == 1:
    print(up[N//2][1]-down[N//2][0]+1)
else:
    r = (up[N//2-1][1]+up[N//2][1])
    l = (down[N//2-1][0]+down[N//2][0])
    print(r-l+1)
# Judge status: Wrong Answer
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
if D[0] != 0:
    print(0)
    exit()

C = Counter(D)
C = dict(sorted(C.items()))

memo = 1
ans = 1
for key in C:
    ans = (ans * (pow(memo,C[key])))%998244353
    memo = C[key]
print(ans)
# Judge status: Accepted
a, b, c, d, K = map(int,input().split())
print(max(0,(60*c+d - 60*a-b)-K))
# Judge status: Wrong Answer
s = input()
t = input()

s = ''.join(sorted(s))
t = ''.join(list(reversed(t)))


if s<t:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n, m = map(int, input().split())
mod = 10**9+7
if abs(n-m)>1:
    print(0)
else:
    ans = 1
    for i in range(2, max(n, m)):
        ans *= i
        ans %= mod
    ans = pow(ans, 2, mod)
    ans *= 2*max(n, m)**2 if n==m else max(n, m)
    print(ans%mod)
# Judge status: Accepted
N,X,Y=map(int,input().split())

ans=[0]*(N)
for i in range(1,N):
    for j in range(i+1,N+1):
        res=min(abs(j-i),abs(X-i)+abs(Y-j)+1,abs(X-j)+abs(Y-i)+1)
        ans[res]+=1

for a in ans[1:]:
    print(a)
# Judge status: Wrong Answer
n,k=map(int,input().split())
h=sorted(list(map(int,input().split())))
l=h[:-k]
print(sum(l))
# Judge status: Accepted
from functools import reduce
import itertools
import math

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())

sum = 0
# forループのネスト
for a, b, c in itertools.product(range(1, k+1), range(1, k+1), range(1, k+1)):

    sum += gcd(a, b, c)

print(sum)
# Judge status: Wrong Answer
import math
a, b = map(float, input().split())
print(math.floor(a*b))
# Judge status: Wrong Answer
import sys
A,B=map(float, sys.stdin.readline().split())
print int(A*B)
# Judge status: Accepted
message = {25: 'Christmas',
           24: 'Christmas Eve',
           23: 'Christmas Eve Eve',
           22: 'Christmas Eve Eve Eve'}

d = int(input())
print(message[d])
# Judge status: Accepted
X,N = map(int, input().split())
P = list(map(int, input().split()))

table = [0] * 102
ans = X
dist = 102

for p in P:
  table[p] = 1

for i in range(102):
  if table[i] != 0:
    continue
  if abs(i - X) < dist:
    ans = i
    dist = abs(i - X)
  elif abs(i - X) == dist:
    ans = min(i, ans)

print(str(ans))
# Judge status: Accepted
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


A = list(map(int, sys.stdin.buffer.readline().split()))
A.sort(reverse=True)
ans = int(str(A[0]) + str(A[1])) + A[2]
print(ans)
# Judge status: Wrong Answer
S = input()
K = int(input())
ans = ""

if int(S[0]) > 1:
  ans = S[0]
elif K>=100:
  for i in range(len(S)):
    if int(S[i]) > 1:
      ans = S[i]
      break
else:
  for i in range(len(S)):
    if int(S[i]) > 1:
      if i+1 <= K:
        ans = S[i]
        break
      else:
        ans = 1
print(ans)
# Judge status: Accepted
N=int(input())
Ai = list(map(int,input().split()))

Ai.sort()

flag = 0
for i in range(N-1):
  if(Ai[i] == Ai[i+1]):
    flag=1
    break
if (flag):
  print('NO')
else:
  print('YES')
# Judge status: Accepted
def resolve():
    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    grid=[list(map(int,input().split())) for i in range(M)]

    res = min(a) + min(b)

    for x, y, c in grid:
        res = min(res, a[x-1]+b[y-1]-c)

    print(res)
    
resolve()
# Judge status: Accepted
N = int(input())
if N == 0:
    s = '0'
else:
    s = ''
while N != 0:
    m = N%2
    s += str(m)
    N = (N - m)*(-1)//2
print(s[::-1])
# Judge status: Accepted
P = list(map(int, input().split()))
P.sort()
ans = P[0]+P[1]
print(ans)
# Judge status: Wrong Answer
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
ans=0

for i in range(n):
    eat=a[i]-1
    ans+=b[eat]
    if eat!=n-1 and i!=n-1:
        ans+=c[eat]
print(ans)
# Judge status: Accepted
n, m = map(int, (input().split()))
x = list(map(int, input().split()))
x = sorted(x)
diff = []
for i in range(m-1):
    diff.append(x[i+1] - x[i])

diff = sorted(diff, reverse=True)

dist = x[-1] - x[0]
if dist < n:
    print(0)
    exit()

if m < n:
    print(0)
    exit()

for i in range(n-1):
    dist -= diff[i]

print(dist)
# Judge status: Wrong Answer
def gcd(A,B):
	print(A,B)
	if B==0:
		return A
	elif B!=0:
		return gcd(B,A%B)
#ただし、A>Bである
a,b=map(int,input().split())
a=gcd(a,b)
print(a)
# Judge status: Wrong Answer
w,a,b = map(int,input().split())
if (a <= b <= a+w) or (a <= b <= a+w):
    print(0)
elif a+w < b:
    print(b-a-w)
# Judge status: Accepted
import math

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

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

print((b- b//c - b//d + (b // lcm(c,d))) - ((a-1)- (a-1)//c - (a-1)//d +( (a-1) // lcm(c,d))))
# Judge status: Accepted
a, b, c = map(int, input().split(' '))
 
if c >= a:
  c -= a
  b = max(0, b-c)
  print(0, b)
else:
  print(a-c, b)
# Judge status: Wrong Answer
N=int(input())
H=list(map(int,input().split()))
max=0
ans=0
for i in range(N-1):
    if H[i]>=H[i+1]:
        max+=1
        print(i)
    else:
        max=0
    if ans<max:
        ans=max
print(ans)
# Judge status: Wrong Answer
n,a,b=map(int, input().split())
ans = 0
for i in range(n):
  d = i
  c = d
  while d >0:
    c += (d%10)
    d = i // 10
  if a <= c <= b:
    ans += 1
print(ans)
# Judge status: Accepted
n = int(input())
s = [int(input()) for _ in range(n)]

s.sort()

point = sum(s)

if point%10 == 0:
    for i in s:
        if i%10 != 0:
            point -= i
            break

if point%10 == 0:
    print(0)
else:
    print(point)
# Judge status: Wrong Answer
s = list(input())
k = int(input())
for i in range(len(s)):
    c = ord(s[i]) - ord("a")
    if k >= (26 - c):
        k -= 26-c
        s[i] = "a"
s[-1] = chr(((ord(s[-1]) - ord("a")) + k) % 26 + ord("a"))
print("".join(s))
# Judge status: Wrong Answer
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    X = int(input())

    if X < 60:
        X = 180 - X
    for n in range(3, 100000):
        s = 180 * (n - 2)
        d, m = divmod(s, n)
        if not m and d == X:
            print(n)
            break


main()
# Judge status: Wrong Answer

MAX = 10 ** 6
def solve(arr, n, k):
    if n == 2:
        return arr[1] - arr[0]

    dp = [MAX] * n
    dp[0] = 0

    for i in range(n):
        for j in range(i + 1, i + k + 1):
            if j < n:
                dp[j] = min(dp[j], dp[i] + abs(arr[i] - arr[j]))

    return dp[-1]

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

print(solve(arr, n, k))
# Judge status: Wrong Answer
length = int(input())
target = []
for i in range(length):
    s, e = map(int, input().split(" "))
    target.append([s, s + e])
target.sort(key = lambda x: x[0], reverse =  True)
target.sort(key = lambda x: x[1])
answer = 0
before_s, before_e = -1, -1
# print(target)
for s, e in target:
    if before_s <= s <= before_e or before_s <= e <= before_e:
        answer += 1
    else:
        before_s = s
        before_e = e
print(length - answer)
# Judge status: Wrong Answer
def gcd(a, b):
    if(a == 0):
        return b
    return gcd(b % a, a)
def lcm(a, b):
    return (a * b) / gcd(a, b) 
t = int(input())
ans = 1
while(t != 0):
    t -= 1
    n = int(input())
    if(ans < 1000000000000000000):
        ans = lcm(ans, n)
if(ans > 1000000000000000000):
    ans = 1000000000000000000
print(int(ans))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
ans = []
for i in range(1,N+1):
    ans.append(A.index(i)+1)
print(ans)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
nu={}
for i in range(len(a)):
  nu[a[i]+1]=i+1
nu=sorted(nu.items())
b=[]
for i in nu:
  b.append(str(i[1]))
mojiretu = ' '.join(b)
print(mojiretu)
# Judge status: Accepted
a = input()
b = input()
count = 0
for i in range(len(a)):
  if (a[i]!= b[i]):
    count += 1
print(count)
# Judge status: Accepted
n,*a=map(int,open(0).read().split())
sa = sum(a)
ha = sa/2
x = 0
for i in range(n):
  x+=a[i]
  if x>=ha:
    break
y = sa-x
print(min(abs(x-y),abs((x-a[i])-(y+a[i]))))
# Judge status: Accepted
from collections import deque
import bisect

N = int(input())
A = [int(input()) for _ in range(N)]

d = deque()
for i in range(N):
    p = bisect.bisect_left(d, A[i])
    if p==0:
        d.appendleft(A[i])
    else:
        d[p-1] = A[i]
ans = len(d)
print(ans)
# Judge status: Wrong Answer
x,y=map(int,input().split())
print(x if x%y==0 else -1)
# Judge status: Accepted
x = int(input())

num = x//11

if x % 11 > 6:
    print(num * 2 + 2)
elif x % 11 > 0:
    print(num * 2 + 1)
else:
    print(num * 2)
# Judge status: Accepted
a,b = map(int,input().split())

n = 0
while 2**n*a <= b:
    n +=1

print(n)
# Judge status: Accepted
s=list(input())
count=0
if s[0]=="1":
    count+=1
if s[1]=="1":
    count+=1
if s[2]=="1":
    count+=1
print(count)
# Judge status: Wrong Answer
N = int(input())
XL = []
for n in range(N):
    XL.append([int(x) for x in input().split()])
XL = sorted(XL, key=lambda x:(x[0],x[1]))
m = -float("inf")
ans = 0
for n in range(N):
    if XL[n][0]-XL[n][1] >= m:
        ans += 1
        m = XL[n][0]+XL[n][1]
print(ans)
# Judge status: Wrong Answer
a, b = map(int, input().split())
if a == b:
    print(1)
else:
    print((b//a)+1)
# Judge status: Accepted
N = int(input())
W = []
S = []
for _ in range(N):
    x,y = [int(hoge) for hoge in input().split()]
    wa = x+y
    sa = x-y
    W.append(wa)
    S.append(sa)
T = max(W)- min(W)
Y = max(S)- min(S)
print(max(T,Y))
# Judge status: Wrong Answer
N=int(input())
if N%10==3:
    print("bon")
elif N%10==0 or 1 or 6 or 8:
    print("pon")
else:
    print("hon")
# Judge status: Accepted
import sys
input = sys.stdin.readline


def main():
    S = input().strip()
    print(min(list(S).count('1'), list(S).count('0')) * 2)
    


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

N = int(input())
A = list(map(int, input().split()))

L = [0]*(N+1)
R = [0]*(N+1)

for i in range(N):
    L[i+1] = gcd(L[i], A[i])
    R[N-i-1] = gcd(R[N-i], A[N-i-1])

M = []
for i in range(N-1):
    M.append(gcd(L[i],R[i+1]))
    
print(max(M))
# Judge status: Accepted
s = map(int,list(raw_input()))
dp = [[0,0] for _ in range(len(s))]
for i in range(len(dp)):
	a = (dp[i - 1][0] if i - 1 >= 0 else 0) + s[i]
	b = (dp[i - 1][1] if i - 1 >= 0 else 1) + 10 - s[i]
	dp[i][0] = min(a,b)

	a = (dp[i - 1][0] if i - 1 >= 0 else 0) + s[i] + 1
	b = (dp[i - 1][1] if i - 1 >= 0 else 1) + 10 - s[i] - 1
	dp[i][1] = min(a,b)
print dp[-1][0]
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
dic = {i+1:0 for i in range(N)}
for i in range(N-1):
    dic[A[i]] =  dic[A[i]] +1

for i in range(N):
    print(dic[i+1])
# Judge status: Wrong Answer
def resolve():
    N = int(input())
    ans = 1
    for i in range(1000000):
        if N == 1 or N == 2 or N == 4:
            break
        elif N % 2 == 0 :
            N = N//2
            ans = ans + 1
        else:
            N = 3*N+1
            ans = ans+1 
    print(ans + 3)
# Judge status: Accepted
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if B < A:
    dist = A - B
    if dist <= (V - W)*T:
        print('YES')
    else:
        print('NO')
else:
    dist = B - A
    if dist <= (V - W)*T:
        print('YES')
    else:
        print('NO')
# Judge status: Accepted
n=int(input())
s=input()
mn=0
sm=0
for i in range(n):
  sm+=1 if s[i]=="(" else -1
  mn=min(mn,sm)
mn*=-1
print("("*mn+s+")"*(sm+mn))
# Judge status: Accepted
n = int(input())

INF = 10**9

dp = [INF] * (n+1)
dp[0] = 0

for i in range(n):
    dp[i+1] = min(dp[i+1], dp[i] +1)
    six = 6
    while i + six <= n:
        dp[i + six] = min(dp[i+six], dp[i] + 1)
        six *= 6
    nine = 9
    while i + nine <= n:
        dp[i + nine] = min(dp[i+nine], dp[i] + 1)
        nine *= 9
print(dp[-1])
# Judge status: Accepted
x = int(input())
if x>= 30:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n, m, x, y = map(int, input().split())
xx = list(map(int, input().split()))
yy = list(map(int, input().split()))
for i in range(x+1, y+1):
    if max(xx) < i <= min(yy):
        print('No War')
        exit()
print('War')
# Judge status: Wrong Answer
x = int(input())

index = 0
for i in range(1,x+1):
  if index*2<x:
    index+=i
  elif i == (x-index):
    break
#  print(index)
print(i)
# Judge status: Wrong Answer
A,B,K = map(int,input().split())
result = 0
for i in range(1,100,1):
  if A%i == 0 and B%i == 0:
    result = i
    break
print(result*K)
# Judge status: Accepted
from collections import Counter

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

ans = 0
for i in b:
    ans += b[i] * (b[i]-1) // 2
    
for i in a:
    if b[i] < 2:
        sa = 0
    else:
        sa = b[i] - 1
    print(ans - sa)
# Judge status: Accepted
import math
N =  int(input())

a = N/1.08
b = (N+1)/1.08

if b-math.ceil(a) <= 0:
    print(':(')
else:
    print(math.ceil(a))
# Judge status: Accepted
#!/usr/bin/env python3
n,*a=map(int, open(0).read().split())
s = sorted(a)
for i in a:
    if i!=s[-1]:
        print(s[-1])
    else:
        print(s[-2])
# Judge status: Wrong Answer
A = list(map(int, input().split()))

total = sum(A)

if total > 22:
  print("bust")
else:
  print("win")
# Judge status: Accepted
n, a, b = map(int, input().split())
ans = n // (a + b) * a
rest = n % (a + b)
ans += min(rest, a)
print(ans)
# Judge status: Accepted
S=input()
if S in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
    print('A')
else:
    print('a')
# Judge status: Wrong Answer
a,b=map(int,input().split())
s=0
for i in range(1,b-a+1):
  s=s+i
print(s-a)
# Judge status: Accepted
W,a,b=map(int,input().split())
if a>b:
    if a<=b+W:
        print('0')
    else :
        print(a-b-W)
elif b>a:
    if b<=a+W:
        print('0')
    else :
        print(b-a-W)
else:
    print('0')
# Judge status: Accepted
x,y=input().split()
a=['1','3','5','7','8','10','12']
b=['4','6','9','11']
if x in a and y in a or x in b and y in b:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
def by_b(n):
	return n[0]

def resolve():
	n, k = map(int, input().split())
	N = []
	for _ in range(n):
		a, b = map(int, input().split())
		N.append([a, b])
	sorted(N, key=by_b)
	cnt = 0
	for i in range(n):
		cnt += N[i][1]
		if cnt >= k:
			print(N[i][0])
			break
resolve()
# Judge status: Wrong Answer
def solve(N):
    if N%2==1:
        return 0
    N2=(N-N%10)//10
    count_zero=N2
    x=5
    while N2>x:
        count_zero+=N2//x
        x*=5
    return count_zero
    
        
    

N=int(input())
print(solve(N))
# Judge status: Accepted
N, Y = map(int, input().split())
for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit()

print("-1 -1 -1")
# Judge status: Wrong Answer
n = int(input())
s = [chr(ord("a")+i) for i in range(26)]
num, i = 1, 0
while n - num > 0:
    num = num*27
    i += 1
ans = ""
while i > 0:
    tmp = 0
    for j in range(1, 27):
        if n - j*pow(26, i-1) < 0:
            break
        tmp = j
    ans += s[tmp- 1]
    n -= tmp*pow(26, i-1)
    i -= 1
print(ans)
# Judge status: Wrong Answer
L,M=map(int,input().split())
a=[0]*L
x=[]
y=[]
for i in range(M):
    b,c=map(int,input().split())
    x.append(b)
    y.append(c)
print(-max(x)+min(y)+1)
# Judge status: Accepted
D,N = map(int,(input().split()))
l = [[] for _ in range(3)]
for i in range(1,1010001):
    c = 0
    j = i
    while j%100 == 0:
        c += 1
        j //= 100
    if c < 3:
        l[c].append(i)

print(l[D][N-1])
# Judge status: Wrong Answer
n = int(input())
l = input()
a = l.split(' ')

tmp = 0
tmp2 = 0

for i in range(n):
    tmp += int(a[i])

for i in range(n):
    tmp2 += int(a[i])*int(a[i])

#total = int((tmp*tmp-tmp2)/2)

print(int(((tmp*tmp-tmp2)/2)%1000000007))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))

cnt = {}
for a in A:
    if a not in cnt:
        cnt[a] = 1
    else:
        cnt[a] += 1

A = [[k, v] for k, v in cnt.items()]
A.sort(reverse=True)

h = 0
w = 0
for k, v in A:
    if v >= 4:
        h = k
        w = k
        break
    elif v >= 2 and h > 0:
        w = k
        break
    elif v >= 2 and h == 0:
        h = k

print(h * w)
# Judge status: Wrong Answer
N = int(input().rstrip())
A = list(map(int,input().rstrip().split()))

B = set(A)
st = 0
num = 1
count = 0

def destroy(st,num,nlist,count):
  add = 0
  for n in range(st,N):
    if nlist[n] == num:
      add += 1
      break
    else :
      add += 1 
      count += 1
  st += add
  return count,st

for i in range(1,N-1):
  if st >= N:
    break
  else:
    count,st = destroy(st,i,A,count)
  
if count == 0:
  print(-1)
else :
  print(count)
# Judge status: Accepted
import math

S = int(input())


X1 = 0
Y1 = 0
X2 = 10 ** 9
X3 = 1

Y3 = math.ceil(S / (10 ** 9))
Y2 = X2 * Y3 - S

print(X1, Y1, X2, Y2, X3, Y3)
# Judge status: Accepted
s = input()
idx = 0
ans = len(s)
s_ = ""
while idx < len(s):
    if s_ == s[idx]:
        ans -= 1
        s_ = ""
        idx += 2
    else:
        s_ = s[idx]
        idx += 1
print(ans)
# Judge status: Accepted
a, b, c = map(int, input().split())
k = int(input())


def solve(a, b, c, k):
    while b <= a:
        b *= 2
        k -= 1
    while c <= b:
        c *= 2
        k -= 1
    return k >= 0



print("Yes" if solve(a, b, c, k) else "No")
# Judge status: Wrong Answer
s=input()
print(min(s[::2].count("1")+s[1::2].count("0"),s[::2].count("0")+s[::1].count("1")))
# Judge status: Accepted
x, y = map(int, input().split())
if x == y or y == 1 or x % y == 0:
    print(-1)
    exit()
for i in range(1, 10**5):
    if x * i % y != 0:
        print(x*i)
        exit()
# Judge status: Wrong Answer
N = int(input())
ans = (N**2) + (N**3)
print(ans)
# Judge status: Accepted
N = int(input())
A = map(int,input().split())

l = [0 for i in range(9)]
for a in A:
  ind = 0
  while ind < 8:
    if a < (ind+1)*400:
      break
    ind += 1
  l[ind] += 1

ans_max = 0
ans_min = 0
for i in range(0, 8):
  if l[i] > 0:
    ans_max += 1
    ans_min += 1
if l[-1] > 0:
  ans_max = ans_max + l[-1]
  ans_min = max(ans_min, 1)
print(ans_min, ans_max)
# Judge status: Accepted
import fractions
from functools import reduce

N = int(input())
a = list(map(int, input().split()))
ans = reduce(fractions.gcd, a)
  
print(ans)
# Judge status: Wrong Answer
n, k = map(int, input().split())
A = list(map(int, input().split()))
A2 = [0] * n
A3 = [n] * n

if k > n:
  print(*A3)
else:
  for l in range(k):
    for j in range(n):
      if A[j] == n:
         A2[j] =n
      else:
        for i in range(n):
          if A[i] >= abs(i-j):
             A2[j] += 1
    A = A2
    A2 = [0] * n
    if A == [n]*n:
      break

print(*A)
# Judge status: Wrong Answer
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
def worstdata():
    a=0
    return a
#solution:
def comp(x,y):
    dp=[0,max(act[0])]*(N+1) #[i]日目のActivity で得られる最大幸福量
    
    return 0

#input
C=[sum(pin()) for j in range(3)]
#output
#print(solution(H,N))
print(["No","Yes"][sum(C)%3==0])
# Judge status: Wrong Answer
x,a,b = map(int, raw_input().split())
print 'delicious' if b - a < x else 'dangerous'
# Judge status: Accepted
s = "0"+input()
ans = 0
n = len(s)
f = 0
p = 0
for i in range(1,n+1):
    n = int(s[-i])
    # n += f
    if p+(n>4) > 5:
        f = 1
    else:
        # ans += f
        f = 0
    n += f
    ans += min(n,10-n)
    p = n
# ans += f
print(ans)
# Judge status: Accepted
from collections import deque

N = int(input())
A = list(map(int, input().split()))

A_sorted = sorted(A, reverse=True)
ans = 0
queue = deque([A_sorted[0]])
for a in A_sorted[1:]:
    ans += queue.popleft()
    queue.append(a)
    queue.append(a)
print(ans)
# Judge status: Wrong Answer
n,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
       
for i in range(n-1):
    w=a[i]+a[i+1]
    if w > x:
        a[i+1]-=(w-x)
        ans+=(w-x)
print(ans)
# Judge status: Wrong Answer
s = input()
if len(set(s)) in [3,1]:
    print("No")
else:
    print("Yes")
# Judge status: Accepted
W, H, x, y = map(int,input().split())

S = W*H / 2
if x == W / 2 and y == H / 2:
    print(S,1)
else:
    print(S,0)
# Judge status: Wrong Answer
k,x = (int(x) for x in input().split())
print("Yes" if 500 * k > x else "No")
# Judge status: Accepted
N = int(input())
S = input()

cnts = [0,0,0]
for c in S:
	if c == 'R':
		cnts[0] = cnts[0] + 1 
	if c == 'G':
		cnts[1] = cnts[1] + 1 
	if c == 'B':
		cnts[2] = cnts[2] + 1 

ans = cnts[0] * cnts[1] * cnts[2]

for j in range(1,N-1):
	for i in range(0,j):
		k = j + j - i
		if k >= N:
			pass
		elif S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
			ans = ans - 1

print(ans)
# Judge status: Accepted
N=int(input())
a=[0]+[sum(map(int, list(str(i)))) for i in range(1, N+1)]
print(min([a[i]+a[N-i] for i in range(1, N//2+1)]))
# Judge status: Accepted
S=set(input())
if len(S)==2:
    print('Yes')
else:
    print('No')
# Judge status: Accepted

N = int(input())
if N >= 1000:
    print("ABD")
else:
    print("ABC")
# Judge status: Accepted
A,B,T=map(int, input().split())

print(int((T+0.5)//A*B))
# Judge status: Wrong Answer
a,b = map(int,input().split())

if a % 3 == 0 or b % 3 == 0 or (a + b) % 3 == 0:
    print('Possible')
else:
    print('Impossibble')