peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
#!/usr/bin/env python3
import sys

input = sys.stdin.readline


def Y():
    print("Yes")


def N():
    print("No")


def ST():
    return input().rstrip()


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


S = ST()

if ("A" not in S) or ("B" not in S):
    N()
else:
    Y()
# Judge status: Wrong Answer
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
ans = 0
Sum = 0
if N==1:
  ans=0
if N==2:
  ans=2
if 2<N:
  cnt = N//3
  for i in range(1, cnt+1):
    S = N - i*3
    ans = cmb(S+i-1,i-1)
    Sum += ans
  ANS = Sum%(10**9+7)
  print(ANS)
# Judge status: Wrong Answer
S = input()
K = int(input())

for s in S:
    if s != '1':
        print(s)
        break
# Judge status: Accepted
from collections import deque
n=int(input())
a=list(map(int,input().split()))
ans=deque()
for i in range(n):
    if i%2!=n%2:
        ans.appendleft(a[i])
    else:
        ans.append(a[i])
for i in ans:
    print(i,end=" ")
# Judge status: Wrong Answer
n = int(input())
dic = {}
lim = -10*9
for _ in range(n):
  x,l = map(int,input().split())
  dic[l+x] = x
dic = sorted(dic.items())
a = 0
lim = -10*9
for i in dic:
  if lim>i[1]:
    continue
  else:
    a += 1
    lim = i[0]
print(a)
# Judge status: Accepted
A, B = map(int, input().split())


def prime_factorization(n):
    from collections import Counter
    counter = Counter()

    if n < 2:
        return counter

    for i in range(2, int(n ** 0.5) + 1):
        if i * i > n:
            break

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

    if n > 1:
        counter[n] += 1

    return counter


x = prime_factorization(A)
y = prime_factorization(B)

z = set(x.keys()) & set(y.keys())
print(len(z) + 1)
# Judge status: Wrong Answer
N, D = map(int,input().split())
data = [list(map(int,input().split())) for _ in range(N)]
#print(data)
count = 0
for d in data:
    if d[0]*d[0] + d[1]*d[1] >= D*D:
        count += 1
print(count)
#print(N,D)
# Judge status: Accepted
import numpy as np
card = np.array([list(map(int,input().split())) for i in range(3)])
N = int(input())
nums = np.array([int(input()) for i in range(N)])

res = np.ones((3, 3), dtype=int)
for y in range(3):
    for x in range(3):
        if card[y, x] in nums:
            res[y, x] = 0

lis = [\
    np.multiply.reduce(res.sum(axis=0)), \
    np.multiply.reduce(res.sum(axis=1)), \
    np.trace(res),\
    np.trace(np.rot90(res.T))]
print("Yes" if 0 in lis else "No")
# Judge status: Accepted
a,b,x = map(int,input().split())

print(b//x - (a-1)//x)
# Judge status: Accepted
N, W = map(int, input().split())

dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(1,N+1):
  w, v = map(int,input().split())
  for j in range(0,W+1):
    if (j-w) >=0:
      dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
    else:
      dp[i][j] = dp[i-1][j]
  #print(dp)
  
  
ans = dp[N][W]
print(ans)
# Judge status: Accepted
import sys,queue,math,copy,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())

N,K = LI()
h = LI()
dp = [INF for _ in range(N)]
dp[0] = 0
for i in range(N-1):
    for j in range(i+1,i+K+1):
        if j < N:
            dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]))
print(dp[-1])
# Judge status: Accepted
A, B = map(int, input(). split())

if A % 3 == 0:
    print('Possible')

elif B % 3 == 0:
    print('Possible')

elif (A + B) % 3 == 0:
    print('Possible')

else:
    print('Impossible')
# Judge status: Accepted
def gcd(a,b): return a if b==0 else gcd(b,a%b)

n = int(input())
a = [int(x) for x in input().split()]
pref = [x for x in a]
suff = [x for x in a]
for i in range(1,n):
	pref[i] = gcd(pref[i-1],a[i])
for i in range(n-2,-1,-1):
	suff[i] = gcd(suff[i+1],a[i])

print(max([pref[-2],suff[1]]+[gcd(pref[i-1],suff[i+1]) for i in range(1,n-1)]))
# Judge status: Wrong Answer
a,b,c,d=map(int,input().split())
x=float(a/d)
y=float(c/b)
 
if x>=y:
  print("yes")
elif 0<y-x<=1:
  print("yes")
else:
  print("no")
# Judge status: Accepted
n = int(input())

t = [0]
x = [0]
y = [0]
for i in range(n):
    tmp = input().split()
    tmp = list(map(int,tmp))
    t.append(tmp[0])
    x.append(tmp[1])
    y.append(tmp[2])

flag = True
for i in range(1,n+1):
    dist = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])
    if t[i] - t[i-1] < dist or (t[i] - t[i-1])%2 != dist%2:
        flag = False

if flag == True:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n,m = map(int,input().split())
if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(m-2)
elif m == 1:
    print(n-2)
else:
    print((n-2)*(m-2))
# Judge status: Accepted
n,*l=map(int,open(0).read().split())
d={1:0,2:0,4:0}
for i in l:
  if i%2: d[1]+=1
  elif i%4: d[2]+=1
  else: d[4]+=1
if d[2]: print('YNeos'[d[1]>d[4]::2])
else: print('YNeos'[d[1]-1>d[4]::2])
# Judge status: Accepted
#!/usr/bin/env python3

import sys
input=sys.stdin.readline

n=int(input())
ans=0
for a in range(1,n+1):
    for b in range(1,n+1):
        if a*b>=n:
            break
        ans+=1
print(ans)
# Judge status: Accepted
import bisect

N = int(input())
L = sorted(list(map(int,input().split())))
ans = 0
for bi in range(1,N-1):
  for ai in range(0,bi):
    ci = bisect.bisect(L,L[bi]+L[ai]-1) - 1
    if bi<ci:
      ans += ci-bi
print(ans)
# Judge status: Accepted
day = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
S = input()

print(7-day.index(S))
# Judge status: Accepted
from fractions import gcd

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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(i)

    if temp!=1:
        arr.append(temp)

    return arr
  
d = gcd(a,b)
print(len(factorization(d)) + 1)
# Judge status: Accepted
A, B = [int(x) for x in input().split()]
ans = 0

ans_a = A // 0.08
ans_b = B // 0.10

for i in range(1, 10100):
    if A == int(0.08 * i) and B == int(0.10 * i):
        ans = i
        print(ans)
        break
if ans == 0:
    print(-1)
# Judge status: Accepted
N = int(input())
for i in range(1, 10):
    if N % i == 0:
        if N // i < 10:
            print('Yes')
            quit()
print('No')
# Judge status: Wrong Answer
N = int(input())
n = []
for i in range(N):
    if i % 3 != 0 and i % 5 != 0:
        n.append(i)     
print(sum(n))
# Judge status: Accepted

a,b=map(int,input().split())
cnt = 0
cnt += a
if b < a:
    cnt -= 1
print(cnt)
# Judge status: Accepted
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
a = ii()

if n%500 > a:
    print('No')
else:
    print('Yes')
# Judge status: Wrong Answer
n=int(input())
s=input()
c=0
for i in range(len(s)-1):
  if(s[i]=='W' and s[i+1]=='R'):
    c+=1
print(c)
# Judge status: Wrong Answer
s = input()

li = []
for i, c in enumerate(s):
    if c == '?':
        if i == len(s) - 1:
            c = 'D'
        else:
            if s[i + 1] == 'D' or s[i + 1] == '?':
                c = 'P'
            else:
                c = 'D'
    li.append(c)

print(''.join(li))
# Judge status: Accepted
n = int(input())
s = input()
mod = 10**9 + 7

cnt = [0] * 26
for i in range(26):
    cnt[i] = s.count(chr(i+97)) + 1

ans = 1
for i in cnt:
    ans *= i
    ans %= mod

ans -= 1
ans %= mod
print(ans)
# Judge status: Wrong Answer
def main():
    l, r, d = map(int, input().split())
    res = r // d - l // d
    print(res)

if __name__ == '__main__':
    main()
# Judge status: Accepted
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
for _ in range(n):
  d = int(input())
  for i in range(3):
    if d in a[i]:
      a[i][a[i].index(d)] = -1

for i in range(3):
  if sum(a[i])==-3:
    print('Yes')
    exit()
  s = 0
  for j in range(3):
    s += a[j][i]
  if s==-3:
    print('Yes')
    exit()
if a[0][0]+a[1][1]+a[2][2]==-3:
  print('Yes')
  exit()
if a[0][2]+a[1][1]+a[2][0]==-3:
  print('Yes')
  exit()

print('No')
# Judge status: Wrong Answer
n=int(input())
listw=list(map(int,input().split()))
lists1=[]
for t in range(1,n):
  count=0
  for i in range(t-1):
    count+=listw[i]
  lists1.append(count)
lists2=[]
for s1 in lists1:
  lists2.append(sum(listw)-s1)
ans=[]
for x in range(n-1):
  ans.append(abs(lists2[x]-lists1[x]))
print(min(ans))
# Judge status: Accepted
N = int(input())
for i in range(9):
    if 111 * i < N and N <= 111 * (i + 1):
        print(111 * (i + 1))
# Judge status: Wrong Answer
a = int(input())
l = []
for i in range(a):
	t = int(input())
	l.append(t)
d=[False]*a

#print('Hello World')
#a = 5
#l = [2,1,100000,5,3]
used=[]
res =0
for i in range(a):
	if l[i] !=-1:
		f = l[i]
		#print(1,f)
		L = []
		L.append(f)
		res +=1
		l[i] = -1
		for j in range(i+1,a):
			if f < l[j] and l[j] !=-1:
				f = l[j]
				l[i] = -1
				#print(f)
				
				L.append(f)
		#print(L)
#print(used)
print(res)
# Judge status: Wrong Answer
n, k = map(int, input().split())
if k == 1:
  print(0)
print(int(n % k != 0))
# Judge status: Accepted
A, B, C = [int(x) for x in input().split()]
ans = 0
while True:
    if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
        break
    elif A == B == C:
        ans = -1
        break
    ans += 1
    A, B, C = (B + C) // 2, (A + C) // 2, (A + B) // 2

print(ans)
# Judge status: Accepted
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

d=deque(S)
reverse=False
for q in query:
  if len(q)==1:
    reverse=not reverse
  else:
    _,f,c=q
    if f=='1':
      d.append(c) if reverse else d.appendleft(c)
    else:
      d.appendleft(c) if reverse else d.append(c)
print(*reversed(d),sep='') if reverse else print(*d,sep='')
# Judge status: Accepted
N,T = map(int,input().split())
ls = []
for i in range(N):
    c,t = map(int,input().split())
    if t <= T:
        ls.append(c)
if len(ls) == 0:
    print("TLE")
else:
    print(min(ls))
# Judge status: Accepted
n=int(input())
for i in range(1,n+1):
    if 2**i>n:
        print(2**(i-1))
        exit()
# Judge status: Accepted
A,B = input().split()
A = int(A)
B = int(B)
if A ==1 or B ==1:
    if A == 1 and B==1:
        print("Draw")
    elif A==1 and B!=1:
        print("Alice")
    elif A!=1 and B==1:
        print("Bob")
else:
    if A>B:
        print("Alice")
    elif A<B:
        print("Bob")
    elif A==B:
        print("Draw")
# Judge status: Accepted
r=input()
s=input()
t=1
for i in range(3):
    t*=(r[i]==s[2-i])
print(["NO","YES"][t==1])
# Judge status: Accepted
n,*a=map(int,open(0).read().split())
b=a[::-1]
from math import gcd
L=[0]
R=[0]
for i in range(n-1):
  L.append(gcd(L[-1],a[i]))
  R.append(gcd(R[-1],b[i]))
ans=0
R=R[::-1]
#print(L,R)
for i in range(0,n-1+1):
  tmp=gcd(L[i],R[i])
  ans=max(ans,tmp)
print(ans)
# Judge status: Wrong Answer
n,a,b=map(int,input().split())
a_=a+b*(n-1)
b_=a*(n-1)+b
if n==1 and a!=b:
  print(0)
else:
  print(a_-b_+1)
# Judge status: Wrong Answer
n = int(input())
l = sorted(list(map(int, input().split())))
d = int(n / 2)
r = l[d] - l[d-1]
print(l)
print(r)
# Judge status: Wrong Answer
n = int(input())
l = list(map(int,input().split()))
tmp = set()
ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if (l[i],l[j],l[k]) not in tmp and abs(l[i]-l[j])<l[k]<l[i]+l[j]:
                ans += 1
            tmp.add((l[i],l[j],l[k]))

print(ans)
# Judge status: Accepted
x, a, b= map(int, input().split())

print('A' if abs(x - a) < abs(x - b) else 'B')
# Judge status: Wrong Answer
N=int(input())
S=input()

d={}
for s in S:
    if s in d:
        d[s]+=1
    else:
        d[s]=1
ans=1
for D in d:
    ans*=d[D]+1
print(ans-1)
# Judge status: Wrong Answer

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

print(a if a>=b else b)
# Judge status: Wrong Answer
X, Y, Z = input().split()
A = X
B = Y
C = Z
# swap the contents of the boxes A and B
temp = B
B = A
A = temp
print(A + " " + B + " " + C)
# swap the contents of the boxes A and C
swapAC = C
C = A
A = swapAC
print(A + " " + B + " " + C)
# Judge status: Accepted
A,B,C,D = map(int,input().split())
ans = 0
for i in range(A+1,B+1):
    if C<i and i<=D:
        ans += 1

print(ans)
# Judge status: Accepted
import math
orders=[int(input()) for i in range(5)]
maximum,total=0,0
for order in orders:
    time=math.ceil(order/10)*10
    total+=time
    remaine=time-order
    maximum=max(maximum,remaine)
print(total-maximum)
# Judge status: Wrong Answer
n,m = map(int, input().split())
H = list(map(int, input().split()))
s = [[0]]*n
for i in range(m):
    a, b = map(int, input().split())
    s[a-1].append(H[b-1])
    s[b-1].append(H[a-1])
c = 0
for j in range(n):
    if H[j] > max(s[j]):
        c+= 1
print(c)
# Judge status: Accepted
str_1 = input()
str_2 = input()

count = 0
for i in range(len(str_1)):
  if str_1[i] != str_2[i]:
    count += 1
    
print(count)
# Judge status: Accepted
n = int(input())
t,a = map(int, input().split())
arr = map(int, input().split())

ans = (-1,float('inf'))
for i,h in enumerate(arr):
  tmp = t - h * 0.006
  if abs(tmp - a) < abs(ans[1]):
    ans = (i, tmp-a)
    
print(ans[0]+1)
# Judge status: Accepted
from collections import defaultdict
import numpy as np

S = list(map(str, input().rstrip()))

memo = defaultdict(int)

for s in S:
    memo[s] += 1

ans = np.array(list(memo.values()))

print("yes") if np.where(ans>1)[0].shape[0]==0 else print("no")
# Judge status: Wrong Answer
import math
from functools import reduce

k = int(input())
sum = 0

for a in range(0, k + 1):
  for b in range(0, k + 1):
    d = math.gcd(a, b)
    for c in range(0, k + 1):
      sum += math.gcd(d, c)

print(sum)
# Judge status: Accepted
n = int(input())
ab = []
for _ in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))

ans = 0
for a, b in reversed(ab):
    ans += (-a-ans)%b
print(ans)
# Judge status: Accepted
S = str(input())

if S[0]==S[1] or S[1]==S[2] or S[2]==S[3]:
  print("Bad")
else:
  print("Good")
# Judge status: Wrong Answer
S=input()
N=len(S)
T="keyence"
U=""
V=""

for i in range(7):
  if S[i]==T[i]:
    pass
  else:
    U=S[:i]
    break
for j in range(7):
  if S[-1-j]==T[-1-j]:
    pass
  else:
    V=S[-1-j+1:]
    break
    
if U=="" or V=="" or U+V==T:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

num_four = 0
num_two = 0
num_odd = 0
for i in range(N):
    if A[i] % 4 == 0:
        num_four += 1
    elif A[i] % 2 == 0:
        num_two += 1
    else:
        num_odd += 1

# print(num_four, num_two, num_odd)

v = num_four * 2
if num_two <= 1:
    v += 1
if num_two >= 2:
    v += num_two
ans = 'Yes' if v >= N else 'No'
print(ans)

# 2 2 2 2 4 o 4 o 4 ... o 4 o
# o 4 o 4 .... o 4 o
# Judge status: Accepted
a, b, c, k = map(int, input().split())

if abs(b - a) > 10**18:
    print('Unfair')
elif k % 2 == 0:
    print(a - b)
else:
    print(b - a)
# Judge status: Accepted
#!python3

LI = lambda: list(map(int, input().split()))

# input
N, K = LI()
H = LI()

INF = 10 ** 10


def main():
    dp = [INF] * N
    dp[0] = 0
    for i in range(1, N):
        n = min(K + 1, i + 1)
        for j in range(1, n):
            dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
    ans = dp[-1]
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
N, X, T = map(int, input().split())

if N % X == 0:
    times = N / X
else:
    times = N // X
    times += 1

ans = int(times * T)

print(str(ans))
# Judge status: Accepted
mae=str(input())
ato=str(input())
mcb=len(mae)
mca=len(ato)
if ato==mae+ato[mca-1]:
    print("Yes")

else:
    print("No")
# Judge status: Wrong Answer
import math
import calendar
import fractions
import itertools

n = int(input())
a = list(map(int, input().split()))
ans = 1
cnt = 0
minimum = min(a)
maximum = max(a)
for i in range(maximum, minimum - 1, -1):
    if a.count(i) < 2:
        continue
    if cnt == 1:
        ans *= i
        cnt += 1
        break
    if a.count(i) >= 4:
        ans = i ** 2
        cnt += 1
        break
    ans *= i
    cnt += 1

if cnt < 2:
    ans = 0
print(ans)
# Judge status: Wrong Answer
N = int(input())
li = list(map(int,input().split()))

counter = 0
li2 =[]
for i in range(N):
    if li[i]>li[i-1]:
        li2.append(1)
    elif N == 1:
        li2.append(1)
print(len(li2))
# Judge status: Accepted
S = input()

num_s = 0

ans = 0
for c in S:
    if c == "S":
        num_s += 1
    else:
        if num_s > 0:
            num_s -= 1
        else:
            ans += 1

ans += num_s

print(ans)
# Judge status: Wrong Answer
x,y,a,b,c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort()
q.sort()
r.sort()
l = p[a-x:a] + q[b-y:b]
l.sort()

j = 0
for i in range(min(c,x+y)):
    if l[j] < r[i]:
        l[j] = r[i]
        j += 1
print(sum(l))
# Judge status: Accepted
N = int(input())
S = input()

ans = 0

for i in range(1,N):
    left = S[:i]
    right = S[i:]
    tmp = 0
    for alpha in 'qwertyuiopasdfghjklzxcvbnm':
        if alpha in left and alpha in right:
            tmp += 1
    ans = max(ans,tmp)
    
print(ans)
# Judge status: Accepted
#!/usr/bin/env python3
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
mod = 10 ** 9 + 7
ans = 0

for j in range(60):
    li = (a >> j) & 1
    i = np.count_nonzero(li)
    o = n - i
    ans += o * i * 2 ** j

print(ans % mod)
# Judge status: Wrong Answer
r=int(input())
print(int(22/7*r**2))
# Judge status: Wrong Answer
N = int(input())
S = list(input())

Lw = 0
Re = S.count("E")
ans_lst = [Lw+Re]*(N)

# i+1をリーダーとみなす
for i in range(1,N):
    if S[i-1] == "W":
        Lw += 1
    else:
        Re -= 1
    ans_lst[i] = Lw + Re
    print(Lw, Re ,ans_lst[i])

ans = min(ans_lst)
print(ans)
# Judge status: Accepted
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])
# Judge status: Accepted
#E_Manhattan
n = int(input())
a, b = [],[]
for i in range(n):
    x, y = map(int, input().split())
    a.append(x+y)
    b.append(x-y)
a.sort()
b.sort()
ans = max(a[-1]-a[0], b[-1]-b[0])
print(ans)
# Judge status: Accepted
x = int(input())
c = 2 * (x // 11)
if x % 11 == 0:
    pass
elif x - 11 * (x // 11) > 6:
    c += 2
else:
    c += 1
print(c)
# Judge status: Wrong Answer
n, m = map(int, input().split())

p = [[] for _ in range(n)]

for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    p[x].append(y)

for i in range(n):
    p[i].sort()
    city_cnt = 1
    for j in p[i]:
        p_num = str(i + 1)
        ans = '0' * (6 - len(p_num))
        ans += p_num
        city_num = str(city_cnt)
        ans += '0' * (6 - len(city_num))
        ans += city_num
        city_cnt += 1
        print(ans)
# Judge status: Wrong Answer
n, m = map(int, input().split())
A, B = [], []
ans = 'IMPOSSIBLE'
for i in range(m):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
now = A[0]
result = n in B
if result == False:
    print(ans)
    exit()
else:
    be = B.index(n)
    before = A[be]
    for i in range(m):
        if B[i] == before:
            if A[i] == now:
                ans = 'POSSIBLE'
                break
print(ans)
# Judge status: Accepted
S=input()
chars = []
for c in S:
    chars.append(c)

ans = len(S) == len(set(chars))

if ans:
    print('yes')
else:
    print('no')
# Judge status: Wrong Answer
n = int(input())
L = list(map(int,input().split()))

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

l = [0]*(n+1)
r = [0]*(n+1)
for i in range(n):
    l[i+1] = gcd(l[i],L[i])
    r[i+1] = gcd(r[i],L[n-i-1])
r = r[::-1]

ans = 0
for i in range(n-1):
    ans = max(ans,gcd(l[i],r[i+1]))
print(ans)
# Judge status: Wrong Answer
import collections
n, m = map(int, raw_input().split(' '))
cc = collections.Counter()
for _ in range(n):
	for a in map(int, raw_input().split(' ')): cc[a] += 1
count =0
for k in cc:
  	if cc[k] == n: count +=1
print count
# Judge status: Wrong Answer
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

N = int(input())
mp = [[0 for j in range(10)]for i in range(10)]
for i in range(N):
	j = i
	
	while j >= 10:
		j //= 10

	mp[j][i%10] += 1
ans = 0
for i in range(1,10):
	for j in range(1,10):
		ans += mp[i][j]*mp[j][i]
print(ans)
# Judge status: Accepted
a,b,c = (int(x) for x in input().split())
if a<c<b or b<c<a:
  print ('Yes')
else:
  print ('No')
# Judge status: Wrong Answer
import itertools
#import math

n = int(input())
#p = tuple(map(int,input().split(" ")))
#q = tuple(map(int,input().split(" ")))

p = input()
q = input()
#print(n)
#print(p)
i = 0
a = 0 
b = 0

for x in itertools.permutations(range(1,n+1), n):
	#print(x)
	x = " ".join(map(str,x))
	#print(x)
	i += 1
	if x == p:
		a = i
		#print(i)
	elif x == q:
		b = i
		#print(i)
        
print(abs(a-b))
# Judge status: Accepted
N = int(input())
A = sorted(list(map(int, input().split())))
ans = 0
before_num = A[0]
num_count = 1
A.append(-1)#一番大きい数を計算するとき用

for num in A[1:]:
    if num == before_num:
        num_count += 1
    else:
        if num_count >= before_num:
            ans += num_count - before_num
        else:
            ans += num_count
        num_count = 1
        before_num = num

print(ans)
# Judge status: Wrong Answer
N,M=map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]

for i in range(N-M+1):
  for j in range(N-M+1):
    t = True
    for k in range(M):
      if B[k] != A[i+k][j:j+M]:
        t = False
  if t:
    print("Yes")
    exit()
print("No")
# Judge status: Accepted
A,B,K = map(int,input().split())
ans = []
for i in range(A,min(A+K,B)):
    ans.append(i)
for j in range(max(A,B-K+1),B+1):
    ans.append(j)
ans = list(set(ans))
ans.sort()
for h in ans:
    print(h)
# Judge status: Accepted
s=list(input())
for i in range(len(s)):
  if s[i]=="A":
    start=i
    break
for j in reversed(range(0,len(s))):
  if s[j]=="Z":
    last=j
    break
print(last-start+1)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

dp = [0]*N #勇者が倒す数

for i in range(N):
  dp[i] = min(A[i], B[i])
  A[i] -= dp[i]
  B[i] -= dp[i]
  rem = A[i]
  if rem==0:
    dp[i] += min(A[i+1], B[i])
print(sum(dp))
# Judge status: Wrong Answer
n = int(input())
n_list = [0]*n
for i in range(n):
    n_list[i] = input().split()
    n_list[i].append(i+1)
for i in range(n):
    n_list[i][1] = int(n_list[i][1])
n_list.sort()
n_list.append("dum")
print(n_list)
L = 0
for i in range(n):
    if n_list[i][0] != n_list[i+1][0]:
        for j in range(i,L-1,-1):
            print(n_list[j][2])
        L = i+1
# Judge status: Accepted
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
 
dp = [-1 for _ in range(W + 1)] # dp[重量の総和]:= 価値の総和
dp[0] = 0
 
for i in range(N):
  w, v = wv[i]
  for j in range(W, -1, -1):
    if dp[j] >= 0 and j + w <=  W:
      dp[j+w] = max(dp[j+w], dp[j]+v)
      
print(max(dp))
# Judge status: Wrong Answer
b3=[39, 78, 156, 161, 175, 168]
a=int(input())
b=360/a
b2=str(b)
head, sep, tail = b2.partition('.')
for c in b3:
    if c==a:
        print(int(head))
if tail=='0':
    print(int(b))
else:
    print(int(head)+1)
# Judge status: Accepted
s = input()
t = input()
n = len(s)

for i in range(n):
    if t == s:
        print('Yes')
        exit()
    else:
        s = s[-1] + s[:-1:]
    
print('No')