peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import sys

a=[]
for i in range(3):
    a= a+[int(x) for x in input().split()]

# print(a)
n=int(input())
for i in range(n):
    b=int(input())
    for j in range(9):
        if a[j] == b:
            a[j]=-1
# print(a)
for i,k,j in [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]:
    if a[i-1]==a[j-1]==a[k-1]==-1:
        print("Yes")
        sys.exit()
print("No")
# Judge status: Accepted
n,m=map(int,input().split())
a=list(map(int,input().split()))
if n-sum(a) >= 0:
    print(n-sum(a))
else:
    print(-1)
# Judge status: Accepted
n, m = map(int, input().split())
l = []
for i in range(m):
    data = list(map(int,input().split()))
    l.append(data)
ball_nums=[1]*n
red_nums=[0]*n
red_nums[0]=1

for i in range(m):
    ball_nums[l[i][0]-1] -= 1
    ball_nums[l[i][1]-1] += 1

    if red_nums[l[i][0]-1]==1:
        red_nums[l[i][1]-1] = 1
        if ball_nums[l[i][0]-1] == 0:
            red_nums[l[i][0]-1] = 0

print(sum(red_nums))
# Judge status: Wrong Answer

N, K = map(int, input().split())
        
    
import math

sum = 0
for i in range(N):
    X = math.log2(K/(i+1))
    X = math.floor(X) if X % 1 == 0 else math.floor(X+1)
    #print(X)
    sum += (1/N)*(1/2)**X
    
print(sum)
# Judge status: Accepted
n,m=map(int,input().split())
if n%2==1:
    l=n//2
    for i in range(m):
        if i%2==1:
            print(i//2+1,l-i//2)
        else:
            print(l+i//2+1,n-i//2)
else:
    l=n//2
    for i in range(m):
        if i%2==0:
            print(i//2+1,l-i//2)
        else:
            print(l+i//2+2,n-i//2)
# Judge status: Accepted
w, h, n = map(int, input().split())
nums_list=[list(map(int, input().split())) for i in range(n)]
minX = 0
maxX = w
minY = 0
maxY = h
for nums in nums_list:
	x, y, a = map(int, nums)
	if a == 1:
		minX = minX if (minX > x) else x
	elif a == 2:
		maxX = maxX if (maxX < x) else x
	elif a == 3:
		minY = minY if (minY > y) else y
	else:
		maxY = maxY if (maxY < y) else y
width = maxX-minX
width = width if (width > 0) else 0
height = maxY-minY
height = height if (height > 0) else 0
v = width*height
print(v)
# Judge status: Wrong Answer
X=input()
Y=int(X)
if Y<=99:
    print(0)

else:
    a=10*int(X[-2])+int(X[-1])
    b=a//5
    if b%5!=0:
        b+=1
    if b>Y//100:
        print(0)
    else:
        print(1)
# Judge status: Accepted
n, p = map(int, input().split())

A = list(map(int, input().split()))
B = []
for i in A:
    B.append(i%2)

zero = B.count(0)
one = B.count(1)

t = 0

from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

for i in range(1, one+1, 2):
    t += combinations_count(one, i)

if p == 1:
    print(t * 2**zero)
else:
    print(2**n - t * 2**zero)
# Judge status: Accepted
# -*- coding: utf-8 -*-

S = input().strip()
T = input().strip()
#-----

check_ST_dic={}
check_TS_dic={}

for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s not in check_ST_dic:
        check_ST_dic[s] = t
    elif check_ST_dic[s] != t:
        print("No")
        break

    if t not in check_TS_dic:
        check_TS_dic[t] = s
    elif check_TS_dic[t] != s:
        print("No")
        break
    
else:
    print("Yes")
# Judge status: Accepted
n, m = [int(i) for i in input().split()]
drink = [[int(i) for i in input().split()] for _ in range(n)]

drink.sort()
i = price = 0
remaining = m
while remaining > 0:
    a, b = drink[i]
    if remaining >= b:
        price += a * b
    else:
        price += a * remaining
    remaining -= b
    i += 1

print(price)
# Judge status: Accepted
a, b, c, x, y = map(int, input().split())
if x < y:
  a, b, x, y = b, a, y, x # x >= y
m1 = y * 2 * c + (x - y) * a
m2 = a * x + b * y
m3 = x * c * 2
print(min(m1, m2, m3))
# Judge status: Accepted
a , b , x = map(int , input().split())
if a + b >= x and a <= x:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

XY = np.array(read().split(), np.int64)[1:]

X, Y = XY[::2], XY[1::2]

A = X + Y
B = X - Y

a = A.max() - A.min()
b = B.max() - B.min()
print(max(a, b))
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
su=0
mi=20000000000000000000
for i in range(n):
  su+=a[i]
  
c=0  
for i in range(n):
  c+=a[i]
  left=su-c
  mi=min(mi,max((c-left),(left-c)))

print(mi)
# Judge status: Accepted
A,B,K=map(int,input().split())
a=max(0,A-K)
b=max(0,B-max(0,K-A))
print(a,b)
# Judge status: Accepted
N=int(input())
L=[0 for i in range(N+1)]
L[0]=2
L[1]=1

for i in range(2,N+1):
    L[i]+=L[i-1]+L[i-2]
print(L[N])
# Judge status: Wrong Answer
data = input().split()
n = int(data[0])
k = int(data[1])
t = list(map(int,input().split()))

p = t[0]
loop = []
while True:
    loop.append(p)
    p = t[p-1]
    if p in loop:
        repeat = p
        r_point = loop.index(p)
        break
#print(loop)
once = loop[:r_point]
repeat = loop[r_point:]
#print(once,repeat)

k -= len(once)
amari = k%len(repeat)
print(repeat[amari-1])


#6 727202214173249351
#6 5 2 5 3 2
# Judge status: Accepted
def main():
    n,l=map(int,input().split(' '))
    li=[input() for i in range(n)]
    for i in range(n):
        print(min(li),end='')
        li.remove(min(li))

main()
# Judge status: Wrong Answer
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [[] for _ in range(n)]
check = [False for _ in range(n)]
for i in range(m):
  a, b = map(int, input().split())
  ab[a-1].append(b)
  ab[b-1].append(a)

for j in range(n):
  for k in ab[j]:
    if k < h[j]:
      check[j] = True
    else:
      check[j] = False

print(check.count(True))
# Judge status: Accepted
# -*- coding: utf-8 -*-
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

total = X * (N if N <= K else K)
total += Y * (0 if N <= K else N - K)

print(total)
# Judge status: Wrong Answer
try:
    S = input()
    count = 0
    res = []
    for i in range(len(S)):
        if S[i] in ["A", "C", "G", "T"]:
            count += 1
        else:
            res.append(count)
            count = 0
    print(max(res))
except:
    print(0)
# Judge status: Accepted
MOD=10**9+7
N, K=map(int,input().split())
ans=0
for i in range(K, N+2):
    mi=i*(i-1)//2
    ma=(2*N-i+1)*i//2
    ans+=(ma-mi+1)
    ans%=MOD
print(ans)
# Judge status: Wrong Answer
n = int(input())
a1 = int(input())
flag= a1%2
ans = a1//2
for i in range(n-1):
    a = int(input())
    ans+=a//2
    if flag and a%2==1:
        ans+=1
    flag =a%2
print(ans)
# Judge status: Wrong Answer
x, y = map(int, input().split())

gr1=[1,3,5,7,8,10,12]
gr2=[4,6,9.11]
gr3=[2]

if x in gr1 and y in gr1:
    print('Yes')
elif x in gr2 and y in gr2:
    print('Yes')
elif x in gr3 and y in gr3:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
t, a = inintm()
H = inintl()

diff = 10**6
ans = 0

for i in range(n):
    if abs(a-(t + -0.006*H[i])) < diff:
        abs(a-(t + -0.006*H[i]))
        ans = i+1

print(ans)
# Judge status: Accepted
s = input()
t = input()

s = ''.join(sorted(s))
t = ''.join(sorted(t, reverse=True))

if s<t:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
s = input()
k = int(input())
f = True
for si in s[:k]:
    if si != "1":
        print(si)
        f = False
        break
if f: print("1")
# Judge status: Wrong Answer
N,K=map(int,input().split())
wa=0
for i in range(N+1-K):
    n=i+K
    min=(n)*(0+n-1)/2
    max=(n)*(N-n+1+N)/2

    wa=max-min+wa+1
    wa%=10**9+7

wa=wa+1
print(wa)
# Judge status: Wrong Answer
N=int(input())

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

c=0

for i in s:
  if i%2==0:
    if i%3==0 or i%5==0:
      c=1
      break
    
if c==1:
  print("APPROVED")
else:
  print("DENIED")
# Judge status: Accepted
s = input()
a = ['A', 'C', 'G', 'T']
ans = []
k = 0
for i in range(len(s)):
  if s[i] in a:
    k += 1
  else:
    ans.append(k)
    k = 0
ans.append(k)
print(max(ans))
# Judge status: Accepted
s=input()
if s[-1] == "s":
  print(s+"es")
else:
  print(s+"s")
# Judge status: Accepted

s = list(input())
count = 0

for i in range(int(len(s)/2)):
    if s[i] != s[-(i+1)]:
        count += 1
print(count)
# Judge status: Wrong Answer
n, m = map(int, input().split())
h = list(map(int, input().split()))
t = [set() for _ in range(n)]

for _ in range(m):
    a,b = map(int, input().split())
    t[a-1].add(b-1)
    t[b-1].add(a-1)
ans = 0
for i in range(n):
    now_t = h[i]
    if t[i]:
        if all([now_t > tall for tall in t[i]]):
            ans += 1
print(ans)
# Judge status: Accepted
from collections import Counter
n = int(input())
c = Counter([''.join(sorted(input())) for i in range(n)])
 
ans = 0
for k, cnt in c.items():
    ans+=cnt*(cnt-1)//2
print(ans)
# Judge status: Accepted
S=input()
T=input()
for i in range(len(S)):
    if S==T:
        print("Yes")
        break
    else:
        S=S[-1]+S[:-1]
else:
    print("No")
# Judge status: Wrong Answer
s = input()
s = list(s)
s = s[::-1]

word_list = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
while i != len(s):
    a = s[i:i+5]
    a = ''.join(a)
    b = s[i:i+6]
    b = ''.join(b)
    if a in word_list:
        i += 5
    elif b in word_list:
        i += 6
    else:
        print('NO')
        exit()

print('YES')
# Judge status: Accepted
n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = list(input())

rsp = {"r":p, "s":r, "p":s}

ans = 0
for i in range(k): ans += rsp[t[i]]
for i in range(k,n):
  if t[i] != t[i-k]: ans += rsp[t[i]]
  else: t[i] = "a"
print(ans)
# Judge status: Accepted
import itertools

def main():
    N = int(input())
    if N%2 == 0:
        print((N/2)/N)
    else:
        print(((N//2)+1)/N)

    return 0
if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())

abc = list('abcdefghij')


def solve(ans):
    if len(ans) == n:
        print(*ans, sep='')
    else:
        idx = max([abc.index(ans[i]) for i in range(len(ans))])
        for i in range(idx+2):
            nans = ans + [abc[i]]
            solve(nans)


solve(['a'])
# Judge status: Wrong Answer
# coding: utf-8
import math
import copy
import bisect
from collections import deque
n = int(input())
L=[]
A=[]
B=[]
for i in range(n):
    a, b = map(int,input().split())
    if b-a>=0:
        L.append(b-a)
    else:
        L.append(math.ceil(a/b)*b-a)
    A.append(a)
    B.append(b)
cnt=0
for i in range(n-1,-1,-1):
    if L[i]-cnt>=0:
        cnt+=L[i]-cnt
    else:
        cnt+=math.ceil((cnt-L[i])/B[i])*B[i]-(cnt-L[i])
print(cnt)
# Judge status: Accepted
R = int(input())
print(2*R*3.14)
# Judge status: Accepted
a,b,c = map(int, input().split())
st = (str(c) + " " + str(a) + " "+ str(b))
print(st)
# Judge status: Accepted
A, B = map(int, input().split())

empty = 1
num = 0
while empty < B:
    num += 1
    empty += (A-1)

print(num)
# Judge status: Wrong Answer
import itertools
import collections
n=int(input())
l=[input() for i in range(n)]
ans=0
for k in itertools.combinations(l,2):
  l1=[]
  l2=[]
  for t1 in k[0]:
    l1.append(t1)
  for t2 in k[1]:
    l2.append(t2)
  c1=collections.Counter(l1)
  c2=collections.Counter(l2)
  if c1.most_common()==c2.most_common():
    ans+=1
print(ans)
# Judge status: Accepted
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    from collections import Counter
    c=Counter(l)# ()にカウンターの対象のリストの変数名
    cnt=0
    for i in c.values():
        if i>=2:
            cnt+=i*(i-1)//2
    for j in l:
        x=(c[j]-1)*(c[j]-2)//2-c[j]*(c[j]-1)//2
        print(cnt+x)
resolve()
# Judge status: Wrong Answer
a,b=map(int,input().split())
print(a+b/2)
# Judge status: Wrong Answer
N = int(input())
W = [input() for _ in range(N)]

a = []
pre = W[0]
flag = False
for wi in W[1:]:
    if wi in a or pre[-1] != wi[0]:
        flag = True
        break
        
if flag:
    print('No')
else:
    print('Yes')
# Judge status: Accepted
S = input()
T = input()
ans = 0
cnt = 0
for i in range(0, len(S) - len(T)+1):
    cnt = 0
    S_sub = S[i:i+len(T)]
    for j in range(len(T)):
        if S_sub[j] == T[j]:
            cnt += 1
    ans = max(ans, cnt)
print(len(T) - ans)
# Judge status: Accepted
x=int(input())
j=((x//500)*500*2)+(((x%500)//5)*5)
print(j)
# Judge status: Accepted
# coding: utf-8
n = int(input())
if n % 2 == 0:
    print(int(n/2))
else:
    print(int((n+1)/2))
# Judge status: Accepted
x = input()
s = 0
ans = 0
for c in x:
  if c == 'T' and s > 0:
    s -= 1
  elif c == 'T':
    ans += 1
  elif c == 'S':
    s += 1
print(ans * 2)
# Judge status: Wrong Answer
N,X = map(int,input().split())
x = list(map(int,input().split()))
x.append(X)
x.sort()
Mindif = x[1]-x[0]
import math
for i in range(1,N-1):
    Mindif = math.gcd(Mindif,x[i+1]-x[i])
print(Mindif)
# Judge status: Accepted

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

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

L = [0]
R = [0]


for i in range(N):
	L.append(gcd(L[i],listA[i]))
	R.append(gcd(R[i],listA[N-1-i]))

ans = 0
for i in range(N):
	ans = max(ans,gcd(L[i],R[N-1-i]))

print(ans)
# Judge status: Accepted
if __name__ == '__main__':
    a = [int(i) for i in input().split()]
    flag = False
    a.sort()
    for i in a:
        if i %2 == 0:
            flag=True
    if flag:
        print(0)
    else:
        print(a[0]*a[1])
# Judge status: Accepted
def gcd(A, B):
    while B != 0:
        A, B = B, A%B
    return A

N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse = True)
ans = A[0]
if N == 1:
    print(ans)
    exit()
for i in range(1,N):
    A[i] = gcd(A[i-1], A[i])

print(A[N-1])
# Judge status: Accepted
import math
n = int(input())
print(math.factorial(n) % (10**9+7))
# Judge status: Accepted
H = int(input())

ans = 1
if H != 1:
    h = H
    for i in range(1, 40):
        if int(h/2) >= 2:
#            print(i, ans, h, 'a')
            ans += 2**i
            h = int(h/2)
        else:
#            print(i, ans, h, 'b')
            ans += 2**i
            break

print(ans)
# Judge status: Accepted
K, N = map(int,input().split())
A = sorted(list(map(int,input().split())))
dis = []
for i in range(N-1):
  dis.append(abs(A[i] - A[i+1]))
dis.append(K - A[-1] + A[0])

print(K-max(dis))
# Judge status: Accepted
n,p=map(int,input().split())
a=list(map(int, input().split()))
from math import factorial
o=0;e=0
for i in a:
    if i%2==0:e+=1
    else:o+=1
if p==0:
    odds=0
    for i in range(0,o+1,2):
        odds+=factorial(o)//factorial(i)//factorial(o-i)
else:
    odds=0
    for i in range(1,o+1,2):
        odds+=factorial(o)//factorial(i)//factorial(o-i)
print(odds*2**e)
# Judge status: Accepted
P = 10**9 + 7
X, Y = map(int, input().split())
if (X + Y) % 3 > 0:
    print(0)
    exit()
n = (X + Y) // 3
x = X - n
y = Y - n
if 0 > x or 0 > y:
    print(0)
    exit()
fact = [0] * (x + y + 1)
inv = [0] * (x + y + 1)
fact_inv = [0] * (x + y + 1)
fact[0], fact[1] = 1, 1
inv[0], inv[1] = 0, 1
fact_inv[0], fact_inv[1] = 1, 1
for i in range(2, x + y + 1):
    fact[i] = (fact[i - 1] * i) % P
print((fact[x + y] * pow(fact[x], P - 2, P) * pow(fact[y], P - 2, P)) % P)
# Judge status: Wrong Answer
X,Y = map(int, input().split())

mod=10 ** 9 + 7
def binomial(n,k):
    x=1
    y=1
    for i in range(k):
        x=x*(n-i)%mod
        y=y*(i+1)%mod
    return x*pow(y,mod-2,mod)%mod

if (2*X-Y)%3==0 and  (2*Y-X)%3==0:
    a=(2*X-Y)//3
    b=(2*Y-X)//3

    print(binomial(a+b,a)%mod)
else:
    print(0)
# Judge status: Accepted
n = int(input())
p = 0
for i in range(n+1):
    if int(i * 1.08) == n:
        print(i)
        p = 1
        break
if p == 0:
    print(':(')
# Judge status: Accepted
import heapq

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

AB = [[] for _ in range(M)]
for _ in range(N):
    a, b = map(int, input().split())
    if a > M: continue
    AB[M-a].append(b)

q = []
heapq.heapify(q)
ans = 0
for i in range(M-1, -1, -1):
    if len(AB[i]) != 0:
        for b in AB[i]:
            heapq.heappush(q, -b)
    if len(q) != 0:
        ans += heapq.heappop(q)
print(-ans)
# Judge status: Wrong Answer

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

if n == 0 or k == 0:
    print(max(n, k))
    exit()
if n < k:
    ans = n
elif n % k == 0:
    ans = 0
else:
    ans = k % (n % k)

print(ans)
# Judge status: Wrong Answer
#ARC069-C
n,m = map(int,input().split())

print((n*2 + m)//4)
# Judge status: Accepted
N,M=[int(x) for x in input().split()]
A=[int(x) for x in input().split()]
su=sum(A)
count=N
for i in A:
    if 4*M*i<su:
        count-=1
if count>=M:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a, b = map(int, input().split())

if a <= 0 and 0 <= b:
    print('Zero')
elif a < 0 and b < 0:
    if (b - a + 1) % 2:
        print('Negative')
    else:
        print('Positive')
else:
    print('Positive')
# Judge status: Accepted
from decimal import Decimal
import math


def main():
    a, b = input().split()
    a = int(a)
    b = Decimal(b) # bは小数点以下第2位まで
    ans = math.floor(a * b)
    print(f'{ans}')


if __name__ == '__main__':
    main()
# Judge status: Accepted
s = [input() for i in range(3)]
order = {'a': 0, 'b': 1, 'c': 2}
who = 'a'
while True:
    target = s[order[who]]
    if len(target) == 0: break
    next = target[0]
    s[order[who]] = s[order[who]][1:]
    who = next
print(who.upper())
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
ans = [0] * (int(1e5)+5)
for i in range(n):
    ans[a[i]-1] += 1
    ans[a[i]] += 1
    ans[a[i]+1] += 1
print(max(ans))
# Judge status: Accepted
s = input()
state = [0, 1]
for i in s:
    n = int(i)
    state_new = [min(state[0] + n, state[1] + 10 - n), 
                 min(state[0] + n + 1, state[1] + 9 - n)]
    state = state_new
print(state[0])
# Judge status: Accepted
import sys
n,k = map(int,input().split())
x_ls = list(map(int, input().split()))
x_ls.sort()
if x_ls[0] >= 0:
    print(x_ls[k-1])
    sys.exit()
elif x_ls[-1] <= 0:
    x_ls.sort(reverse=True)
    print(abs(x_ls[k-1]))
    sys.exit()
l = 0
r = k - 1
ans = float('inf')
while r < n:
    cost_1 = 2*abs(x_ls[l]) + abs(x_ls[r])
    cost_2 = abs(x_ls[l]) + 2*abs(x_ls[r])
    cost = min(cost_1,cost_2)
    ans = min(cost, ans)
    r += 1
    l += 1
print(ans)
# Judge status: Accepted
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
  if p[i-1] < p[i] and p[i] < p[i+1]:
    ans+=1
  elif p[i-1] > p[i] and p[i] > p[i+1]:
    ans+=1
print(ans)
# Judge status: Accepted
N, K = list(map(int,input().split()))
S = input()
ans = 0
for i in range(1, N):
    if S[i] == "R" and S[i - 1] == "R":  ans += 1
for i in range(1, N):
    if S[i] == "L" and S[i - 1] == "L":  ans += 1
ans = min(ans + 2 * K, N - 1)
print(ans)
# Judge status: Wrong Answer
n=int(input())
monster=list(map(int, input().split()))
monster.sort()
m = monster[0]
M = 0 
for i in range(1,n):
    tmp = monster[i]%m
    M = max(M,tmp)
if M==0:
    print(m)
else:
    print(1)
# Judge status: Accepted
#!/usr/bin/env python3


def main():
    N = int(input())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    A.sort()
    B.sort()
    if N % 2 == 1:
        print(B[(N-1)//2] - A[(N-1)//2] + 1)
    else:
        print(B[N//2]-A[N//2] +B[N//2-1]-A[N//2-1] + 1)
    

if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
h = int(input())
w = int(input())
n = int(input())

lo = max(h,w)
lp = min(h,w)

cnt = 0
tmp = 0
for i in range(h*w):
    if tmp < n and tmp+lo <= n:
        tmp += lo
        cnt += 1
    elif tmp < n and tmp+lo >= n:
        tmp += lp
        cnt += 1
    elif tmp >= n:
        break

print(cnt)
# Judge status: Accepted
n=int(input())
d=[10*[0]for _ in range(10)]
ans=0
for i in range(1,n+1):
  s=str(i)
  if s[0]=="0" or s[-1]=="0":
    continue
  else:
    d[int(s[0])][int(s[-1])]+=1
for i in range(1,10):
  for j in range(1,10):
    ans+=d[i][j]*d[j][i]
print(ans)
# Judge status: Accepted
def factorize(N):
    if N == 1: return {1:1}
    res = {}
    for i in range(2, N):
        if i**2 > N: break
        if N % i != 0: continue
        num = 0
        while N % i == 0:
            N = int(N/i)
            num += 1
        res[i] = num
    if N>1: res[N] = 1
    return res

A, B = map(int, input().split())
resA = factorize(A)
resB = factorize(B)
res = set(resA.keys()) & set(resB.keys())
ans = len(res) if 1 in res else len(res)+1
print(ans)
# Judge status: Wrong Answer
import sys
import math
import itertools
a, b, c = map(int, input().split())
if (a != b and b != c):
    print(3)
elif (a == b and b == c):
    print(1)
else:
    print(2)
# Judge status: Wrong Answer
N, M=map(int, input().split())
if N%2==0:
  for i in range(1, M+1):
    print(i, N-i+1)
else:
  for i in range(1, M+1):
    print(i, N-i)
# Judge status: Accepted
n = list(map(int, input().split()))
s=n[0]+n[2]
s1=2*n[1]
if(s1==s):
    print("YES")
else:
    print("NO")
# Judge status: Accepted
N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
doko = 0
for i in range(N):
    if A[doko] <= 0:
        saishou = min(A)
        loop = A[doko] - saishou + 1
        hajimarimade = A[doko]
        K += hajimarimade
        print(A.index(-1*(K % loop)+hajimarimade)+1)
        exit()
    if i == K:
        print(doko+1)
        exit()
    hoji = doko
    doko = A[doko] - 1
    A[hoji] = (-1)*i
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
print((n+m//2)//2)
# Judge status: Accepted
N = int(input())
card_list = list(map(int,input().split()))
sorted_list = sorted(card_list,reverse=True)
Alice_score = sum(sorted_list[0::2])
Bob_score =  sum(sorted_list[1::2])
print(Alice_score-Bob_score)
# Judge status: Accepted
n,k = map(int,input().split())
a = list(map(int,input().split()))

for i in range(n-k):
    if a[i] < a[i+k]:
        print('Yes')
    else:
        print('No')
# Judge status: Accepted
import fractions
from functools import reduce
n = int(input())
t = [int(input()) for _ in range(n)]
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
print(lcm_list(t))
# Judge status: Accepted
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
li = LI()
li.sort()
print(li[0]*li[1]//2)
# Judge status: Accepted
import itertools
import math
def getdis(a,b):
  return math.sqrt((b[0] - a[0])**2+(b[1]-a[1])**2)

N = int(input())

city = []
l = [i for i in range(N)]
for i in range(1,N+1):
  x,y = map(int,input().split())
  city.append([x,y])
  
l = list(itertools.permutations(l))
sum_dis = [0]*len(l)
for i in range(len(l)):
  for j in range(N-1):
    sum_dis[i]+=getdis(city[l[i][j]],city[l[i][j+1]])
print(sum(sum_dis)/len(l))
# Judge status: Wrong Answer
# 整数の入力
a, b = map(int, input().split())
# 二つの数を掛けて2で割ったときの余り
c = (a * b) % 2
if c != 0:
    print('Odd')
else:
    print('Evev')
# Judge status: Accepted
import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


s=list(input())
s=s+[0]
mod=0
ans=[]
count=0
n=len(s)
p=2019

for i in range(n):
    mod+=(pow(10,i,p)*int(s[n-i-1]))%p
    mod%=p
    ans.append(mod)

ans = collections.Counter(ans)
ans=ans.most_common()
for i in range(len(ans)):
    if ans[i][1]>=2:
        count+=combinations_count(ans[i][1],2)

print(count)