peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
A,B,M = map(int,input().split())

from collections import defaultdict

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

MINB = min(b)

wari = defaultdict(list)
for _ in range(M):
    x,y,c = map(int,input().split())
    wari[x-1].append((y-1,c))

a.sort(); b.sort()

ans = float("inf")
for i in range(A):
    tmp = a[i] + MINB
    for y,c in wari[i]:
        tmp = min(tmp, a[i] + b[y] - c)
    ans = min(ans, tmp)

print(ans)
# Judge status: Accepted
if(input()=='ABC'):
    print('ARC')
    exit()
print('ABC')
# Judge status: Accepted
x, n = map(int, input().split())
p = [int(_) for _ in input().split()]

arr = [0] * 1000
for i in p:
    arr[i] = 1

ans1 = 0
for i in range(x, -1, -1):
    if arr[i] == 0:
        ans1 = i
        break

# print(arr)

ans2 = 0
for i in range(x, 102):
    if arr[i] == 0:
        ans2 = i
        break

if abs(ans1 - x) <= abs(x - ans2):
    print(ans1)
else:
    print(ans2)
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
ans=1
count=1
"""
for i in range(1,n+1):
    ans+=count*2
    count*=2
#print(ans)
"""
ans=1
count=1
now=1
for i in range(n):
    count=(count-a[i])*2
    if a[i]%2==1:
        now=now*2-a[i]-1
    else:
        now=now*2-a[i]
    ans+=count
    #print(count,ans,now)

print(max(-1,ans))
# Judge status: Accepted
A=input()
if A[0] != "A":
  print("WA")
  quit()
if A[2:-1].count("C") != 1:
  print("WA")
  quit()
for i in range(1,len(A)):
  if A[i] !="C" and not A[i].islower():
    print("WA")
    break
else:
  print("AC")
# Judge status: Wrong Answer
N, x = map(int, input().split())
children = sorted(list(map(int, input().split())))

count = 0
for child in children:
    if x >= child:
        x -= child
        count += 1
    else:
        break
if x == 0:
    print(count)
else:
    if count != 0:
        print(count - 1)
    else:
        print(0)
# Judge status: Accepted
z,y,x=map(int,input().split())
z-=x*2+y
count=1
while(1):
  z-=y+x
  if z<0:
    break
  count+=1
print(count)
# Judge status: Accepted
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))

# N = 3
# M = 3
# A = [2, 13, 8]

A = [-a for a in A]
heapq.heapify(A)

for i in range(M):
    price = heapq.heappop(A)*(-1)//2
    heapq.heappush(A, -price)
#    print(A)
print(-sum(A))
# Judge status: Wrong Answer
n, m = map(int, input().split())
a = list(map(int, input().split()))
flag = False
c = []
for _ in range(m):
  x,y = map(int, input().split())
  for i in range(x):
    c.append(y)
    if len(c) == n:
      flag = True
      break
  if flag:
    break
e = sorted(a+c,reverse=True)
print(sum(e[:n]))
# Judge status: Accepted
n = int(input())
s_list = []
for i in range(n):
	s_list.append(int(input()))
r = 0
total = sum(s_list)
if total % 10 != 0:
	r = total
else:
	s_list.sort()
	for s in s_list:
		if s % 10 != 0:
			r = total - s
			break
print(r)
# Judge status: Accepted
N = int(input())
S = input()

result = 0
x = 0
for i in S:
    if i == 'I':
        x += 1
    else:
        x -= 1
    result = max(result, x)

print(result)
# Judge status: Wrong Answer
S = input()
S_modified = S.replace('7','8')
print(S_modified)
# Judge status: Wrong Answer
S, W = map(int, input().split())

if S < W/2:
  print("unsafe")
print("safe")
# Judge status: Wrong Answer
n, m = map(int,input().strip().split())
print('{}'.format(m)*n)
# Judge status: Wrong Answer
s = int(input())

a = s -3 + 1
aws = a - 3 + 1
print(aws % (7 + (10 * 9)))
# Judge status: Wrong Answer
S = input()
print(min([753 - int(S[i:i+3]) for i in range(len(S)-3 + 2)]))
# Judge status: Wrong Answer
n = int(input())
A = list(map(int, input().split()))

from collections import Counter
c = Counter(A)

multi = sorted([k for k, v in c.items() if v >= 2], reverse=True)
if len(multi) < 2:
    print(0)
else:
    print(multi[0]*multi[1])
# Judge status: Accepted
a,b,c=map(int,input().split())
print(a+b+c-max(a,b,c))
# Judge status: Accepted
n=int(input())
l=[50]*26
d=set(list("abcdefghijklnmopqrstuvwxyz"))
from collections import Counter as co
for i in range(n):
    x=input()
    f=d-set(list(x))
    for k,v in co(x).items():
        l[ord(k)-ord("a")]=min(l[ord(k)-ord("a")],v)
    for c in f:
        l[ord(c)-ord("a")]=0
ans=""
for i in range(26):
    ans+=chr(ord("a")+i)*l[i]
print(ans)
# Judge status: Accepted
a, b, c = map(int, input().split())

if a == b+c or b == c+a or c == a+b:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
C = list(map(int,input().split()))
C.sort()
if  C[2]==C[0]+C[1]:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
n, a, b = list(map(int, input().split()))
m = 10**9 + 7

def func(n, i):
    x = 1
    y = 1
    for j in range(1, i+1):
        x = (x * (n - (j - 1))) % m
        y = (y * j) % m
    return (x * pow(y, m-2, m)) % m

print(((pow(2, n, m) - 1 - func(n, a) - func(n, b)) % m))
# Judge status: Accepted
import sys
n,m,k=map(int,input().split())


for p in range(n+1):
    for q in range(m+1):
        ans=p*m + q*n - 2*p*q
        if(ans==k):
            print('Yes')
            sys.exit()
else:
    print('No')
# Judge status: Wrong Answer
A, B = map(int, input().split())
count=0

for i in range(10001, 100000, 1):
  s = str(i)
  a = int(s[4])
  b = int(s[3])
  c = int(s[1])
  d = int(s[0])
  
  if a==d and b==c:
    count+=1
print(count)
# Judge status: Wrong Answer
n = int(input())
t, a = map(int, input().split())
h = [int(i) for i in input().split()]
x = 10 ** 5
b = 0
for i in range(n):
    d = abs(a - t - h[i] * 0.006)
    if d < x:
        x = d
        b = i + 1
print(b)
# Judge status: Accepted
a,b,c = map(int,input().split())
if c-a-b>0 and 4*a*b < (c-a-b)**2:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
N, A, B = list(map(int, input().split()))

if A > B:
    ans = 0
elif A == B:
    ans = 1
elif N == 1:
    ans = 0
else:
    mn = A + B + A * (N-2)
    mx = A + B + B * (N-2)
    ans = mx - mn + 1

print(ans)
# Judge status: Accepted
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left

N=int(input())

tbl = [[0] * 10 for i in range(10)]

for i in range(1, N+1):
    num = str(i)
    s = int(num[0])
    e = int(num[-1])
    tbl[s][e] += 1

cnt = 0
for i in range(10):
    for j in range(10):
        cnt += tbl[i][j] * tbl[j][i]
print(cnt)
# Judge status: Wrong Answer
N = int(input())
w = list(map(int,input().split()))

sumw = [0]*N
sumw[0] = w[0]
for i in range(1,N):
    sumw[i] = sumw[i-1]+w[i]
ans = 10*5
for i in range(0,N-1):
    ans = min(ans, abs(sumw[N-1]-2*sumw[i]))

print(ans)
# Judge status: Accepted
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
  tmp = [int(j) for j in input().split()]
  s.append(tmp)
  
sat = 0
lst = [0 for i in range(26)]

for i in range(D):
  satlst = [0 for j in range(26)]
  for j in range(26):
    sattmp = sat + s[i][j]
    for k in range(26):
      if j != k:
        sattmp -= c[k] * ((i + 1) - lst[k])
    satlst[j] = sattmp
  sat = max(satlst)
  lst[satlst.index(sat)] = (i + 1)
  print(satlst.index(sat) + 1)
# Judge status: Accepted
N,K = map(int,input().split())
sunuke = [0] * N
for i in range(K):
    tmp = int(input())
    tmp_lst = list(map(int,input().split()))
    for j in tmp_lst:
        sunuke[j-1] += 1
print(sunuke.count(0))
# Judge status: Accepted
import math
from decimal import *
A,B = list(map(int, input().split()))
ans = -1
for x in range(1, 10001):
    a = math.floor(x * Decimal(0.08))
    b = math.floor(x * Decimal(0.1))
    if a == A and b == B:
        ans = x
        break
print(ans)
# Judge status: Wrong Answer
x,a,b = map(int,input().split())
print(["B","A"][2*x<(b+a)])
# Judge status: Accepted
A, B, K = map(int, input().split())

count = 0

for i in reversed(range(1,min(A, B)+1)):
    if A%i == 0 and B%i == 0:
        count+=1
        if count == K:
            print(i)
# Judge status: Accepted
import math
a, b, c, d = map(int, input().split())

if math.ceil(c / b) <= math.ceil(a / d):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
s=input()
t=''
for i in s:
  if i!='B':
    t+=i
  else:
    if t!='':
      t=t[:-1]
print(t)
# Judge status: Accepted
number,length=map(int,input().split())
input_list=[]
out=''
for i in range(number):
    input_list.append(input())
input_list.sort()
for i in input_list:
    out+=i
print(out)
# Judge status: Accepted
o=input()
e=input()
ans=''
for i in range(len(o)):
    ans+=o[i]
    if i<len(e):
        ans+=e[i]
print(ans)
# Judge status: Wrong Answer
import numpy as np

n = int(input())

li = [chr(i) for i in range(97, 97 + 26)]
lili = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
        'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q']
ans = []

zzz = list(np.base_repr(n, base=26))

for i in zzz:
    xxx = lili.index(i)
    ans.append(li[xxx-1])

print(''.join(ans))
# Judge status: Wrong Answer
L, R, d = map(int, input().split())
ans = (R - L + 1) // d
print(ans)
# Judge status: Accepted
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    prime_cnt = [0] * (n + 1)
    for i in range(1, n + 1):
        for j in range(0, n + 1, i):
            prime_cnt[j] += 1

    res = 0
    for i in range(1, n + 1):
        res += i * prime_cnt[i]
    print(res)


if __name__ == '__main__':
    resolve()
# Judge status: Wrong Answer
a=list(map(int, input().split()))
if len(a) != len(set(a)):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
S = input()
if S[-1]=='s':
    s = S+'s'
else:
    s = S+'es'
print(s)
# Judge status: Accepted
# input
inp_ls = input().split(" ")
n,m = [int(e) for e in inp_ls[:2]]
inp_a_ls = input().split(" ")
a_ls = [int(e) for e in inp_a_ls[:m]]

# calc
rest = n - sum(a_ls)
out = rest if rest >= 0 else -1

# result
print(out)
# Judge status: Accepted
a = input()
s = input()

b = int(a)

if 3200 <= b:
    output_s = (s)
elif b <3200:
    output_s = ("red")

print(output_s)
# Judge status: Accepted
N = int(input())
A = [int(i) for i in input().split()]
odd, four = 0, 0
for a in A:
    if a & 1 == 1: odd += 1
    if a & 3 == 0: four += 1
# 4の倍数の個数 == 奇数の個数
# すべて偶数
if odd == 0 or four >= odd or (four == odd - 1 and four + odd == N):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
x,a,b = map(int, input().split())
A = max(x,a) - min(x,a)
B = max(x,b) - min(x,b)
if A > B:
    print("B")
else:
    print("A")
# Judge status: Accepted
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

a, b = map(int, input().split())
print(int(a*b))
# Judge status: Accepted
def isPrime(num):

    for i in range(2, int(num ** 0.5) + 1):
        if num % i == 0:
            return False

    return True


X = int(input())
n = X

while True:
    if isPrime(n):
        break
    n += 1

print(n)
# Judge status: Wrong Answer
# 式：y = N*(N+1)/2

N = int(input()) # 人数Nを代入

candy = N * (N + 1) / 2

print(candy)
# Judge status: Accepted
import itertools as it
 
n,m,q = map(int, input().split())
l = [list(map(int, input().split())) for i in range(q)]
ans = 0
 
for v in list(it.combinations_with_replacement(range(1,m+1),n)):
    num = 0
    for w in l:
        x,y,z = w[0]-1,w[1]-1,w[2]
        if v[y] - v[x] == z:
            num += w[3]
    if num > ans:
        ans = num
print(ans)
# Judge status: Wrong Answer
n=input()
if n.count('9'):
  print('Yes')
else:
  print('NO')
# Judge status: Accepted
n,k=map(int, input("").split(' '))
assert n>=k>=1
assert 1<=n<=50

s=input('')
assert ("a","b","c" in s)

z=list((s))
z[k-1]=z[k-1].swapcase()

for i in z:
    print(i, end='')
# Judge status: Accepted
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rf = lambda: map(float, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

s = rr()
lens = len(s)
a = int(s[0])
b = s[1:]
t = '9'*(lens-1)
if b == t:
    print((lens-1)*9+a)
else:
    print((lens-1)*9+a-1)
# Judge status: Accepted
n = int(input())
ab = [list(map(int, input().split())) for _i in range(n)][::-1]

r = 0
for i in range(n):
    a, b = ab[i]
    if (r+a)%b==0:
        continue
    r += b-(r+a)%b
print(r)
# Judge status: Accepted
r, g, b = input().split()
print('YES' if int(r+g+b)%4==0 else 'NO')
# Judge status: Accepted
K,S = input().strip().split()
K,S = int(K),int(S)

count = 0

for x in range(S+1):
  for y in range(S+1-x):
    z = S - x- y
    #print( x,y,z)
    if x <= K and y <= K and z <= K:
      count += 1
print(count)
# Judge status: Accepted
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
N = int(input())
B = {int(input()) for _ in range(N)}
A = a1+a2+a3
ijk = [ [0,1,2], [3,4,5], [6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]


end = False
for i,j,k in ijk:
    if {A[i], A[j], A[k]} <= B:
        print('Yes')
        end = True
        break
    else:
        continue
if not end:        
    print('No')
# Judge status: Accepted
c = str(input())

if c in 'aeiou':
    print('vowel')
else:
    print('consonant')
# Judge status: Wrong Answer
H,A=map(int,input().split())
if H%A==0:
    print(H//A)
else:
    print((round(H/A,0))+1)
# Judge status: Wrong Answer
S=list(str(input()))
T=list(str(input()))
for i in range(len(S)//2 +1):
  if S==T:
    print('Yes')
    exit()
  a=S.pop(-1)
  S.insert(0,a)
print('No')
# Judge status: Accepted
from itertools import combinations as comb
def main():
    N = int(input())
    L = list(map(int, input().split()))
    count = 0
    for a, b, c in comb(L, 3):
        a, b, c = sorted([a, b, c])
        if a == b or b == c or c == a:
            continue
        if c < a + b:
            count += 1
    print(count)
if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
import itertools
N, M, Q = map(int,input().split())
ABCD = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for s in itertools.combinations_with_replacement(range(1,N+1),N):
    temp = 0
    for i in range(Q):
        if s[ABCD[i][1]-1] - s[ABCD[i][0]-1] == ABCD[i][2]:
            temp += ABCD[i][3]
    ans = max(ans,temp)
print(ans)
# Judge status: Accepted
n=int(input())
#list from 2 to n
alist=list(map(int,input().split()))

jodic={}

for i in alist:
    if i in jodic:
        jodic[i]=jodic[i]+1
    else:
        jodic[i]=1

for j in range(n):
    if j+1 in jodic:
        print(jodic[j+1])
    else:
        print("0")
# Judge status: Accepted
N,L = map(int, input().split())
S = list(input() for i in range(N))
S = sorted(S)
print(''.join(S))
# Judge status: Accepted
n = int(input())
print("Yes" if n >= 30 else "No")
# Judge status: Accepted
from collections import Counter

N = int(input())

li = []

for _ in range(N):
    li.append(input())

a =  Counter(li)
# print(a)

print("AC x " + str(a["AC"]))
print("WA x " + str(a["WA"]))
print("TLE x " + str(a["TLE"]))
print("RE x " + str(a["RE"]))
# Judge status: Accepted
S = input()
if S[0] != S[1] and S[1] != S[2] and S[2] != S[0]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N, M = map(int, input().split())

ans = 0
if N == 1 and M == 1:
    ans = 1
elif N == 1 and M > 1:
    ans = M-2
elif N > 1 and M == 1:
    ans = N-2
else:
    ans = (N-2)*(M-2)

print(ans)
# Judge status: Accepted
a = int(input())
print(int((a/2)**2) if a%2==0 else (a//2)**2+(a//2))
# Judge status: Accepted
N = int(input())
print(((N+1)//2) / N)
# Judge status: Accepted
n, m, k = map(int, input().split())

val = []

for i in range(0, n + 1):
    for j in range(1, m + 1):
        x = i * j + (n - i) * (m - j)
        val.append(x)
        
val = set(val)

print("Yes" if k in val else "No")
# Judge status: Accepted
# -*- coding: utf-8 -*-
N = int(input())

robo_dic = {}
for i in range(N):
    X, L = map(int, input().split())
    robo_dic[X] = L

robo_list = sorted(robo_dic.keys())

max_place = robo_list[0] + robo_dic[robo_list[0]]
ans = 1
for i in range(1, len(robo_list)):
    x = robo_list[i]
    l = robo_dic[x]
    if max_place <= x - l:
        ans += 1
        max_place = x + l
    else:
        max_place = min(max_place, x + l)
print(ans)
# Judge status: Wrong Answer
s = input()
n = len(s)
count = 0
for i in range(n):
    for j in range(i+4,n):
        num = ""
        for k in range(i,j+1):
            num += s[k]
        print(num)
        if int(num)%2019 == 0:
            count += 1
print(count)
# Judge status: Accepted
import collections


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

    mod = 998244353

    if D[0] != 0:
        print(0)
        return

    cnt = collections.Counter(D)

    if cnt[0] > 1:
        print(0)
        return

    ans = 1

    for i in range(1, max(D)+1):
        if cnt[i - 1] == 1:
            continue
        ans *= cnt[i - 1] ** cnt[i] % mod
        ans %= mod

    print(ans)


if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

sum = sum(a) - a[0]

ans = 0
for i in range(n):
  ans += a[i] * sum
  if (i == n-1):
    break
  else:
  	sum -= a[i+1]
  
ans %= 10 ** 9 + 7  
print(ans)
# Judge status: Accepted
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a < b:
  if a + t * v >= b + t * w:
    print('YES')
  else:
    print('NO')
else:
  if a - t * v <= b - t * w:
    print('YES')
  else:
    print('NO')
# Judge status: Accepted
n = int(input())
min_sum = 99999999999999
if n == 2 :
  print (2)
  exit()
for i in range (1, n - 1):
  first = i
  second = n - i
  first_sum = 0
  second_sum = 0
  while first > 0 :
    last_digit_first = first % 10
    first = first // 10
    first_sum += last_digit_first
    
  while second > 0 :
    last_digit_second = second % 10
    second = second // 10
    second_sum += last_digit_second
  
  if first_sum + second_sum <= min_sum :
    min_sum = first_sum + second_sum
print(min_sum)
# Judge status: Accepted
import sys
f=lambda:map(int,sys.stdin.readline().split())
n,m=f()
lt=sorted(tuple(map(int,input().split())) for _ in range(n))[::-1]
from heapq import *
q=[]
s=t=0
while t<m:
  t+=1
  while lt and lt[-1][0]==t:
    a,b=lt.pop()
    heappush(q,-b)
  if q: s-=heappop(q)
print(s)
# Judge status: Wrong Answer
#!/usr/bin/env python3
# input
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
for i in range(n):
    if a[i] > b[i]:
        print("No")
        exit()
print("Yes")
# Judge status: Wrong Answer
def aux(x):
    if -40<=x<=40:
        return 'Yes'
    else:
        return 'No'
# Judge status: Accepted
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a, b, c = LI()
for i in range(a, a*b+1, a):
    if i % b == c:
        print('YES')
        break
else:
    print('NO')
# Judge status: Accepted
import sys
import copy
import math
import itertools
import numpy as np
l = [int(c) for c in input().split()]
a = l[0]
b = l[1]
if a*b <= 0:
    print("Zero")
elif a > 0 and b > 0:
    print("Positive")
else:
    if abs(b-a)%2==1:
        print("Positive")
    else:
        print("Negative")
# Judge status: Wrong Answer
a,b=map(int,input().split())
if a <= 8 and b <= 8:
  print("yay")
else:
  print(":(")
# 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('Imossible')
# Judge status: Accepted
n,k = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]

a = sorted(a,key=lambda x:x[0])
ans = 0
for i in range(n):
    ans += a[i][1]
    if ans >= k:
        print(a[i][0])
        exit()
# Judge status: Accepted
import math
A,B,h,m=map(int,input().split())
time=60*h+m
a=(0.5*time)%360
b=(6*time)%360
x=abs(a-b)
if x==0 or x==360:
  c=abs(A-B)
elif x==180:
  c=A+B
else:
  c=math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(x)))
print(c)
# Judge status: Accepted
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

from math import sqrt
from math import gcd
a, b = map(int, input().split())
x = gcd(a, b)
print(len(set(prime_factorize(x)))+1)
# Judge status: Accepted
# input
N, A, B = map(int, input().split())

# process
ans = 0
if A%2 == B%2:
    ans = (B-A)//2
else:
    if A-1 < N-B:
        ans = A+(B-A-1)//2
    else:
        ans = N-B+1+(B-A-1)//2

# output
print(ans)
# Judge status: Accepted
from itertools import combinations_with_replacement
N, M, Q = map(int, input().split())
L = list(range(1, M+1))

D = [list(map(int, input().split())) for _ in range(Q)]
ans = []

for p in combinations_with_replacement(L, N):
    tmp = 0
    for a, b, c, d in D:
        if p[b-1]-p[a-1] == c:
            tmp += d
    ans.append(tmp)

print(max(ans))
# Judge status: Wrong Answer
n = int(input())
ls = []
for i in range(n):
    a,b = map(int, input().split())
    ls.append((a,b))
cnt = 0
for i, j in sorted(ls, reverse=True):
    m = (i+cnt) % j
    cnt += 0 if m == 0 else j-m
print(cnt)
# Judge status: Accepted
a, b, k = map(int, input().split())
lst = []
for i in range(1, 101)[::-1]:
    if a % i == 0 and b % i == 0:
        lst.append(i)

print(lst[k-1])
# Judge status: Accepted
N=int(input())
L=list(map(int,input().split()))
n=N//2
R=sorted(L)
for i in L:
  if i>R[n-1]:
    print(R[n-1])
  else:
    print(R[n])
# Judge status: Accepted
div500, rem = divmod(int(input()), 500)
print(div500 * 1000 + rem // 5 * 5)
# Judge status: Wrong Answer
k,n=map(int,input().split())
for i in range(k-1):
  print(n-k+i)
print(n)
for i in range(k-1):
  print(n+i+1)
# Judge status: Accepted
s = str(input())
t = str(input())

if s[0] == t[2] and s[1] == t[1] and s[2] == t[0]:
    result = 'YES'
else:
    result = 'NO'
print(result)
# Judge status: Accepted
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

from_1 = set(b for a, b in AB if a == 1)
to_N = set(a for a, b in AB if b == N)
print('POSSIBLE' if from_1 & to_N else 'IMPOSSIBLE')
# Judge status: Wrong Answer
lst = list(input())

if lst[2] == lst[3] and lst[4] == lst[5]:
    print('True')
else:
    print('No')
# Judge status: Wrong Answer
l = input()
m = input()
if l[0] == m[2] and l[1] == m[1] and l[2] == l[0]:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
N, r = map(int, input().split())
hs = list(map(int, input().split()))
g = [1]*N
for i in range(r):
    road = list(map(int, input().split()))
    if hs[road[0] - 1] >= hs[road[1] - 1]:
        g[road[1] - 1] = 0
    if hs[road[0] - 1] <= hs[road[1] - 1]:
        g[road[0] - 1] = 0
print(sum(g))
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
b=[]
c=[]
for i in range(n):
  b.append(a[i]-(i+1))
  c.append(-(a[i]+i+1))
from collections import defaultdict
#cnt_b=Counter(b)
cnt_c=defaultdict(int)
ans=0
for i in range(n):
  v=cnt_c[b[i]]
  ans+=v
  cnt_c[c[i]]+=1
print(ans)
# Judge status: Wrong Answer
word = list(input())
print(word)
count = 0
for a in word :
    if a == "1" :
        count = count + 1
print(count)
# Judge status: Accepted
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N, M = map(int, readline().split())
    cnt = [0] * (M + 1)

    for _ in range(N):
        K, *A = list(map(int, readline().split()))
        for x in A:
            cnt[x] += 1

    print(cnt.count(N))


if __name__ == '__main__':
    main()