peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
def calc(x, y, z):
    return x**2 + y**2 + z**2 + x*y + y*z + z*x

n = int(input())
ans = [0]*n

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            a = calc(x, y, z)
            if a <= n:
                ans[a-1] += 1

b = [str(i) for i in ans]
print('\n'.join(b))
# Judge status: Wrong Answer
import math

A,B = map(int,input().split())
print(math.gcd(A,B)*A*B)
# Judge status: Wrong Answer
import numpy as np
import fractions
from functools import reduce

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

N, X = map(int, input().split())
x = np.array(list(map(int, input().split())))
if N == 1:
    print(np.abs(x[0] - X))
else:
    x = np.abs(x - X)
    print(min(gcd(x)))
# Judge status: Wrong Answer
n = int(input())
s = list(input())
max = 0

for i in range(1, n-1):
    a = set(s[:i])
    b = set(s[i:])

    print(a & b)
    
    if max < len(a & b):
        max = len(a & b)
print(max)
# Judge status: Accepted
a, b, c = [int(i) for i in input().split()]
if a < c < b or a > c > b:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n, a, b = map(int, input().split())
if a > b or ( n == 1 and a != b ):
  print(0)
else:
  print((a+b*(n-1))-(a*(n-1)+b)+1)
# Judge status: Accepted
n=int(input())
if n%2==0:
    print(0.5)
else:
    print(((n-1)/2+1)/n)
# Judge status: Accepted
n = int(input())
s = input()
t = input() 

ok = False
for i in range(n):
    if s[i:n] == t[:n-i]:
        ok = True
        break

print(n + i if ok else n*2)
# Judge status: Accepted
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]
lst.sort()
lst = lst[::-1]
ans = 0

while m > 0:
    if lst[-1][1] <= m:
        ans += lst[-1][0] * lst[-1][1]
        m -= lst[-1][1]
    else:
        break
    lst.pop()

if m > 0:
    ans += lst[-1][0] * m

print(ans)
# Judge status: Wrong Answer
N,K = map(int,input().split())
i = 0
if K == 1:
    print(0)
else:
    results = [N]
    while i < K:
        N = N - K
        if N < 0:
            results.append(-N)
            N = -N
        else:
            results.append(N)
        i += 1
    print(min(results))
# Judge status: Accepted
import numpy as np
from collections import Counter

length=int(input())
list=list(map(int,input().split()))
list.sort()

max=list[-1]
dp=[0]*(max+1)
dp=np.array(dp,int)

for num in list:
    dp[num]=1

for num in list:
    if dp[num]==1:
        dp[2*num::num]=0

count=Counter(list)

for num,cnt in count.items():
    if cnt>1:
        dp[num]=0

print(dp.sum())
# Judge status: Wrong Answer
from math import gcd
n = int(input())
a = list(map(int,input().split()))

g = a[0]
for i in a:
    g = gcd(g,i)

print(i)
# Judge status: Wrong Answer
n, m = map(int, input().split())

if n == m:
    print('AC')

elif n > m:
    print('WA')
# Judge status: Accepted
S = input()
T = input()
if T[:-1] == S:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
import numpy as np
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

dic = {"r":P, "s":R, "p":S}#key:筐体が出した手、val:それに勝ったら貰える点
points = 0

for st in range(K):
    series = T[st::K]
    prev = "x"
    for now in series:
        if now != prev:
            points += dic[now]
            prev = now
        else:
            prev = "x"
            
print(points)
# Judge status: Accepted
def resolve():
    H = int(input())
    cnt = 0
    mons = 1
    while H != 1:
        H = H//2
        cnt += mons
        mons *= 2
    print(cnt+mons)
    
if '__main__' == __name__:
    resolve()
# Judge status: Accepted
x,a,b= map(int,input().split())
print("A" if abs(x-a)<abs(x-b) else 'B')
# Judge status: Accepted
n = int(input())

t = 0
task = []
for i in range(n):
    a,b = map(int,input().split())
    task.append([b,a])

task.sort()
ans = "Yes"
for i in range(n):
    t += task[i][1]
    if task[i][0] < t:
        ans = "No"
        break

print(ans)
# Judge status: Accepted
# ABC077C

import bisect

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

bC=[0 for i in range(N)]
for i in range(N):
    bC[i]=N-bisect.bisect(C,B[i])
    
bCS=[0]*(N+1)
for i in range(N):
    bCS[i+1] = bCS[i]+bC[i]
    
ans=0
for i in range(N):
    x=bisect.bisect(B,A[i])
    ans+=bCS[N]-bCS[x]
        
print(ans)
# Judge status: Accepted
w,h,n=map(int,input().split())
mix=0
mx=w
miy=0
my=h
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        mix=max(mix,x)
    elif a==2:
        mx=min(mx,x)
    elif a==3:
        miy=max(miy,y)
    else:
        my=min(my,y)
if mix>=mx or miy>=my:
    print(0)
else:
    print((mx-mix)*(my-miy))
# Judge status: Wrong Answer
import fractions
a,b,c,d = map(int,input().split())
num = b-a+1
ac = int((a-1)/c)
ad = int((a-1)/d)
bc = int(b/c)
bd = int(b/d)
e = c*d//(fractions.gcd(c,d))
a = int(a/e)
b = int(b/e)
c = bc-ac
d = bd-ad
e = b-a
print(num-(c+d-e))
# Judge status: Wrong Answer
A,B,C = map(int,input().split())
print((A+C)//B)
# Judge status: Accepted
a, b, c = list(map(int, input().split()))
if a <= c <= b:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
w,a,b=map(int,input().split())
if a+w<b:
    print(b-a-w)
else:
    print(0)
# Judge status: Accepted
n,x,t=map(int,input().split())
count=0
a=0
a=x
if(n<=x):
        print(t,end='\n')
        
elif(x==1):
        print((n)*t)
else:    
    while(x<n):
        count=count+1
        x=x+a    
    print((count+1)*t)
# Judge status: Accepted
k, x = map(int, input().split())
if (k*500) >= x:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
s = int(input())

a = s ** 2 % 10 ** 9
b = s ** 2 // 10 ** 9


print(0, 0, 10 ** 9, 1, a, b)
# Judge status: Accepted
n = int(input())
aa = list(map(int,input().split()))

minus_count = sum([1 for v in aa if v<0])
a = [abs(v) for v in aa]

if minus_count % 2 == 0:    
  print(sum(a))
else:
  print(sum(sorted(a)[1:]) - min(a))
# Judge status: Accepted
meals=[]
for i in range(5):
    meals.append([i,int(input())])
for g in range(5):
    if meals[g][1]%10!=0:
        meals[g][0]=meals[g][1]%10
    else:
        meals[g][0]=10

meals.sort(reverse=True)

ans=0
for i in range(4):
    ans+=meals[i][1]+10-meals[i][0]
ans+=meals[-1][1]

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

if len(s) <= k:
  print(s)
else:
  print(s[:k] + "...")
# Judge status: Accepted
S = input()
T = input()
res = []

ok = -1
for i in range(len(S) - len(T) + 1):
    if S[i] == T[0] or S[i] == "?":
        for j in range(len(T)):
            if S[i + j] not in ("?", T[j]):
                break
        else:
            s = S[:i] + T + S[i + len(T):]
            res.append(s.replace("?", "a"))

if res:
    print(min(res))
else:
    print("UNRESTORABLE")
# Judge status: Accepted
from collections import Counter
s = input()
s = Counter(s)
for i in s.values():
    if i%2!=0:
        print("No")
        break
else:print("Yes")
# Judge status: Wrong Answer
A,B,C=map(int,input().split())
if A%B==0 :
    if C==0:
        print('YES')
    else:
        print('NO')
elif (A%B)%2==1:
    if C%2==1:
        print('YES')
    else:
        print('NO')
elif (A%B)%2==0:
    print('YES')
# Judge status: Accepted
N = int(input())

a = 1
for i in range(1,N+1):
	a *= i
	a %= 10**9 + 7

print(a)
# Judge status: Accepted
n = int(input())
c = 0
for i in range(n):
  d1, d2 = map(int, input().split())
  if(d1 == d2):
    c += 1
  else:
    c = 0
  if(c >= 3):
    print("Yes")
    exit()
print("No")
# Judge status: Accepted
if int(input()) >= 1000:
  print("ABD")
else:
  print("ABC")
# Judge status: Wrong Answer
n = int(input())
b = int(n/15)
print(n*800-n*200)
# Judge status: Wrong Answer
y = input()
x = [int(x) for x in input().split()]
y = input()
if (y == 'red'):
      print(x[0]-1,x[1])
else:
      print(x[0], x[1]-1)
# Judge status: Wrong Answer
S = input()
s_Count = 0
b_Count = 0
ans = 0

for i in range(len(S)):
  if S[i] == "<" and i != len(S)-1:
    s_Count += 1
  else:
    b_Count += 1
    if i == len(S)-1 or S[i+1] == "<":
      max_sb = max(s_Count,b_Count)
      min_sb = min(s_Count,b_Count) - 1
      ans += max_sb * (max_sb+1) / 2 + min_sb * (min_sb+1) / 2
      s_Count = 0
      b_Count = 0
print(int(ans))
# Judge status: Accepted
N,K=map(int,input().split())
A=list(map(int,input().split()))
print((N-1-1)//(K-1)+1)
# Judge status: Accepted
S=input()
if S[0::2].count("L")==0 and S[1::2].count("R")==0:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
d = input().split("/")
d[0] = "2018"
print("/".join(d))
# Judge status: Accepted
def main():
    n = int(input())
    if n%2==1:
        print(0)
    else:
        ans = 0
        waru = 10
        while n>=waru:
            ans += n//waru
            waru = waru*5
        print(ans)
    
if __name__ == "__main__":
    main()
# Judge status: Accepted
N = int(input())
from collections import defaultdict
d_blue = defaultdict(int)
strs = set()
for i in range(N):
    s = input()
    d_blue[s] += 1
    strs.add(s)
M = int(input())
d_red = defaultdict(int)
for j in range(M):
    t = input()
    d_red[t] += 1
    strs.add(t)

ans = 0
for s in strs:
    b = d_blue[s]
    t = d_red[s]
    ans = max(ans,b-t)

print(ans)
# Judge status: Accepted
W, H, x, y = [int(i) for i in input().strip().split()]

S = (W*H) / 2

if (W % 2 == 0) and (H % 2 == 0) and (W // 2 == x) and (H // 2 == y):
  print(str(S) + " " + str(1))
else:
  print(str(S) + " " + str(0))
# Judge status: Wrong Answer
import math

k = int(input())
num = 0

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

print(num)
# Judge status: Wrong Answer
X = int(input())

if X>30:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
x,y=map(int,input().split())
ans='No'
for i in range(x+1):
    j=x-i
    if 2*x+4*j==y:
        ans='Yes'
print(ans)
# Judge status: Accepted
s=input()
t=input()
print("Yes" if t in s*2 else "No")
# Judge status: Wrong Answer
N, M = map(int, input().split())

l = 0
r = N

for i in range(M):
    L, R = map(int, input().split())
    
    if M == 1:
        print(R-L+1)
        break
        
    else:
        if L > l:
            l = L
            
        if R < r:
            r = R
                
        ans = r - l + 1

else:
    print(ans)
# Judge status: Accepted
n = int(input())
s = 0
for i in range(1, n+1):
	x = n // i
	s += i * (x * (x+1)) / 2 
print(int(s))
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
rev = [0] * N
for i in range(N):
    rev[A[i]-1] = i+1
print(*rev)
# Judge status: Accepted
import math
n = int(input())

target_ls = [1]
target_6 = 6
while target_6 <= n:
    target_ls.append(target_6)
    target_6 *= 6
target_9 = 9
while target_9 <= n:
    target_ls.append(target_9)
    target_9 *= 9

dp = [float('inf')] * (n+1)
dp[0] = 0
for i in range(n):
    for j in target_ls:
        if i+j <= n:
            dp[i+j] = min(dp[i+j],dp[i] + 1)
print(dp[n])
# Judge status: Wrong Answer
X = int(input())

x = 0

for i in range(2,int(X ** 0.5) + 1):
  n = 1
  a = i
  while n < X :
    n *= a
  if n // a > x:
    x = (n // a)

print(x)
# Judge status: Accepted
a,b = input().split()
a = int(a)
b = b.replace('.','')
b = int(b)
answer = str(a*b)
if (len(answer) <=2):
  print(0)
else:
  print(answer[:-2])
# Judge status: Accepted
r, g, b = map(int, input().split())
rgb=int(str(r) + str(g) + str(b))
if rgb % 4 == 0:
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer
def func(a, n):
    p = 10 ** 9 + 7
    bi = str(format(n, "b"))
    res = 1
    for i in range(len(bi)):
        res = (res * res) % p
        if bi[i] == "1":
            res = (res * a) % p
    return res


N = int(input())
n = func(10, N)
no_0 = func(9, N)
no_9 = func(9, N)
no_09 = func(8, N)
ans = (n - no_0 - no_9 + no_09)
if ans < 0:
    ans += 10 ** 9 + 7
print(ans)
# Judge status: Accepted
n = int(input())
A = list(map(int, input().split()))
absA = [abs(a) for a in A]

if sum(True if a < 0 else False for a in A) % 2 == 0:
  ans = sum(absA)
else:
  ans = sum(absA) - 2 * min(absA)
  
print(ans)
# Judge status: Accepted
N=int(input())

def is_ok(n):
    if n*(n+1)//2>=N:
        return True
    else:
        return False

ng=0
ok=N+1

while abs(ng-ok)>1:
    mid=(ok+ng)//2

    if is_ok(mid):
        ok=mid
    else:
        ng=mid

diff=ok*(ok+1)//2-N

for i in range(1,ok+1):
    if i!=diff:
        print(i)
# Judge status: Wrong Answer
a,b=map(int,input().split())
A=[]
for i in range(1,1000):
    A.append((i*(i+1))//2)

for j in range(10**6):
    if ((a+j) in A) and ((b+j) in A):
        print(j)
        exit()
# Judge status: Wrong Answer
import time

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

INF = 10 ** 20


dp = [INF] * (h + 10 ** 4)
dp[0] = 0

magic = []

for i in range(n):
    magic.append(list(map(int, input().split())))

magic.sort(key=lambda x: x[0])

for a, b in magic:
    for i in range(h - a + 1):
        if dp[i] == INF:
            continue
        dam = i + a
        if dp[dam] > dp[i] + b:
            dp[dam] = dp[i] + b

ans = min(dp[h:])

print(ans)
# Judge status: Accepted
n = int(input())
hoge_list = list(map(int,input().split()))
h_list = hoge_list[::-1]
mae = h_list[0]
s = 0
for h in h_list:
  if h <= mae:
    mae = h
  elif h-1 == mae:
    mae = h-1
  else:
    print('No')
    s += 1
    break
if s == 0:
  print('Yes')
# Judge status: Wrong Answer
N=int(input())

if N < 1000:
    print('ABC')


elif 1000 <= N < 1998:
    print('ABD')
# Judge status: Accepted
S="x"+input()

T=[0]*(len(S)+1)
U={"A","C","G","T"}

for i in range(len(S)):
    if S[i] in U:
        T[i]=T[i-1]+1
    else:
        T[i]=0
print(max(T))
# Judge status: Accepted
x, a, b = map(int, input().split())
d = -1*a + b
if(d <= 0):
    print("delicious")
elif(abs(d) <= x):
    print("safe")
else:
    print("dangerous")
# Judge status: Accepted
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = A.copy()
k = 0
while k < K and sum(B) < N**2:
  tmp = [0]*N
  i = 0
  while i < N:
    a = B[i]
    tmp[max(0, i-a)] += 1
    if i+a+1 < N:
      tmp[i+a+1] -= 1
    i += 1
  s = 0
  i = 0
  while i < N:
    B[i] = tmp[i]+s
    s = B[i]
    i += 1
  k += 1
print(" ".join([str(b) for b in B]))
# Judge status: Wrong Answer
n = int(input())
A = sorted(list(map(int, input().split())))

if len(set(A)) == 1:
    print(0)
    exit()

from collections import Counter
c = Counter(A)

NMAX = 10 ** 6 + 1000
dp = [True] * (NMAX + 1)
for k, v in c.items():
    if dp[k]:
        for i in range(k * 2, NMAX + 1, k):
            dp[i] = False
    if v > 1:
        dp[k] = False

count = 0
for k, v in c.items():
    if v > 1: continue
    if dp[k]: count += 1

print(count)
# Judge status: Accepted
N = int(input())
S = input()

b, w = 0, 0
for i in range(N):
    if S[i] == '#':
        b += 1
    else:
        w += 1

ans = [0 for _ in range(N+1)]
ans[0], ans[-1] = w, b
for i in range(1, N):
    if S[i-1] == '#':
        ans[i] = ans[i-1] + 1
    else:
        ans[i] = ans[i-1] - 1

print(min(ans))
# Judge status: Wrong Answer
X = int(input())
ans = 0
money = 100

while money < X:
  money += int(money * 0.01)
  ans += 1
print(ans)
# Judge status: Wrong Answer
N = int(input())
# Nは食事数
x = 800*N
# xは払った金額の合計
y = N // 15*200
# yはもらった金額の合計
# /:商、小数点以下まで表示される
# //:切り捨て、小数点以下が切り捨てられる
answer = x-y
# Judge status: Accepted
N = int(input())
counter = 0
for A in range(1,N):
  for B in range(1,N//A+1):
    if 0 < A*B < N:
        counter += 1
print(counter)
# Judge status: Accepted
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

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

def func(a):
    rtn = 0
    while a % 2 == 0:
        a //= 2
        rtn+=1
    return rtn

for i in range(n):
    a[i] = func(a[i])
print(min(a))
# Judge status: Accepted
# A Frog 1

n = int(input())
h_list = [int(x) for x in input().split()]

dp = [float('Inf')]*(n)
dp[0] = 0
dp[1] = abs(h_list[1] - h_list[0])

for i in range(2,n,1):
    dp[i] = min(dp[i-2]+abs(h_list[i]-h_list[i-2]), dp[i-1]+abs(h_list[i]-h_list[i-1]))

print(dp[n-1])
# Judge status: Accepted
#B(別解)
import math
n=int(input())
x=math.ceil(n/1.08)
if math.floor(x*1.08)==n:
    print(x)
else:
    print(":(")
# Judge status: Wrong Answer
A,B,C = map(int,input().split())
ans = 0

if A == B and B == C:
  print(-1)
  exit()
  
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
  A,B,C = (B+C)//2,(C+A)//2,(A+B)//2
  ans += 1
  
  if A == B and B == C:
    print(-1)
    exit()
    
print(ans)
# Judge status: Accepted
n = int(input())
li = list(map(int, input().split()))
ans = 1
flg = 0
for i in range(n):
  if flg==1 and li[i]!=0:
    continue
  elif li[i]==0:
    ans = 0
    break
  else:
    ans *= li[i]
  if(ans>1000000000000000000):
    flg = 1
if flg==1 and ans==0:
  print(ans)
elif flg==1:
  print(-1)
else:
  print(ans)
# Judge status: Accepted
k,a,b = map(int,input().split())
if a >= b or a + 2 >= b:
    print(k+1)
else:
    if k+1 <= a:
        print(k+1)
    else:
        k = k-a+1
        c = k%2
        d = k//2
        print(a+(b-a)*d+c)
# Judge status: Accepted
N = int(input())
widths = list(map(int, input().split()))

Notmax_widths = sum(widths) - max(widths)
result = 'Yes' if Notmax_widths > max(widths) else 'No'
print(result)
# Judge status: Accepted
n = int(input())

if n < 1000:
  print('ABC')
else:
  print('ABD')
# Judge status: Accepted
n = int(input())
s = input()
t = input()

for i in range(n+1):
    for j in range(n+1):
        tmp = s[:i] + t[:j]
        if tmp[:n] == s and tmp[-n:] == t:
            print(len(tmp))
            exit()
# Judge status: Accepted
import queue
K = int( input() )

q = queue.Queue()

ret = K
number_of_operations = 9
for i in range( 1, number_of_operations + 1 ):
  q.put( i )

while number_of_operations < K:
  i = q.get()
  k = i % 10 
  if k != 0:
    ret = 10 * i + k - 1
    q.put( ret )
    number_of_operations += 1
    if number_of_operations == K:
      break
  ret = 10 * i + k
  q.put( ret )
  number_of_operations += 1
  if number_of_operations == K:
    break

  if k != 9:
    ret = 10 * i + k + 1
    q.put( ret )
    number_of_operations += 1

print( ret )
# Judge status: Wrong Answer
x,y=map(int,input().split())
a=[1,3,5,7,8,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: Accepted
n=int(input())
s=input()
rw=s.count("W")
re=s.count("E")
lw=0
le=0
now=""
m=10000000000000000000
for i in range(n):
    if now=="W":lw+=1
    if now=="E":le+=1
    if s[i]=="W":rw-=1
    if s[i]=="E":re-=1
    m=min(m,lw+re)
    now=s[i]
print(m)
# Judge status: Accepted
S = input()
l = len(S)
s1 = ''.join(['0' if i % 2 == 0 else '1' for i in range(l)])
s2 = ''.join(['1' if i % 2 == 0 else '0' for i in range(l)])

t1 = 0
t2 = 0
for i, j, s in zip(s1, s2, S):
    if i != s:
        t1 += 1
    if j != s:
        t2 += 1
print(min(t1, t2))
# Judge status: Accepted
from collections import defaultdict
N=int(input())
alist=list(map(int,input().split()))

dic_a=defaultdict(int)
for a in alist:
  dic_a[a]+=1
#print(dic_a)

max_answer=0
for v in list(dic_a):
  answer=dic_a[v-2]+dic_a[v-1]+dic_a[v]
  max_answer=max(answer,max_answer)

  answer=dic_a[v-1]+dic_a[v]+dic_a[v+1]
  max_answer=max(answer,max_answer)

  answer=dic_a[v]+dic_a[v+1]+dic_a[v+2]
  max_answer=max(answer,max_answer)
  
print(max_answer)
# Judge status: Accepted
s=list(input())
a=["0","1"]
cnt=0
for i in range(len(s)):
    if s[i]!=a[i%2]:
        cnt+=1
print(min(cnt,len(s)-cnt))
# Judge status: Accepted
n = int(input())
x = list(enumerate(map(int, input().split())))
x.sort(key=lambda x:x[1])
ans = [""]*n
for i in range(n):
  if (n+1)//2 >= i+1: ans[x[i][0]] = x[(n+1)//2][1]
  else: ans[x[i][0]] = x[(n+1)//2-1][1]

print("\n".join(map(str, ans)))
# Judge status: Wrong Answer
X = int(input())
ans = 360 / X
print(int(ans))
# Judge status: Accepted
import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
cnt[0] = 1
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = 0
for i in range(MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
a.sort()
tmp = []
i =n-1
while i >0:
    if a[i] == a[i-1]:
        tmp.append(a[i])
        i -=2
    else:
        i -=1
if len(tmp)>=2:
    print(tmp[0]*tmp[1])
else:
    print(0)
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))

# 0
# 1, 0
# 2, 0, 1
# 3, 1, 0, 2
# 4, 2 ,0, 1, 3

front = []
back = []

for i in range(N):
  if i % 2 == 0:
    back.append(A[i])
  else:
    front.append(A[i])
    
ans = None
if N % 2 == 0:
  ans = front[::-1] + back
else:
  ans = back[::-1] + front
  
print(*ans)
# Judge status: Accepted
a,b,c=map(int,input().split())
print('YNeos'[c<a or c>b::2])
# Judge status: Accepted
# https://atcoder.jp/contests/arc081/tasks/arc081_a

from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]
c = Counter(nums)

ans = 0
rec = []
for k, v in c.items():
    if v >= 2:
        rec.append(k)
    if v >= 4:
        ans = max(ans, k ** 2)

if len(rec) >= 2:
    rec.sort(reverse=True)
    ans = max(ans, rec[0] * rec[1])
print(ans)
# Judge status: Accepted
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
if N > M: N, M = M, N
if N == 1 and (M == 1): print(1)
elif N == 2: print(0)
elif N == 1 and (M == 2): print(0)
elif N == 1: print(max(0, M - 2))
else: print(max(0, (N - 2) * (M - 2)))
# Judge status: Wrong Answer
s = input()
a = s.count("A")
b = s.count("B")

if a or b ==3:
    print("No")

else:
    print("Yes")
# Judge status: Accepted
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
t=list(set(a))
c=sorted(Counter(a).most_common(),key=lambda x:x[1])
num=len(t)-k
if num<0:
    print(0)
    exit()
else:
    ans=0
    for i in range(num):
        ans+=c[i][1]
    print(ans)
# Judge status: Accepted
X, Y, A, B, C = map(int, input().split())
P = sorted(list(map(int, input().split())), reverse = True)
Q = sorted(list(map(int, input().split())), reverse = True)
R = list(map(int, input().split()))

a = sorted(P[:X] + Q[:Y] + R, reverse  = True)
print(sum(a[:(X+Y)]))
# Judge status: Accepted
import sys

def input():
  return sys.stdin.readline()

N=int(input())
A=list(map(int,input().split()))
B=[0]*(10**5)
for a in A:
  B[a-1]+=1
s=sum(A)
Q=int(input())
for i in range(Q):
  b,c=map(int,input().split())
  bb,bc=B[b-1],B[c-1]
  B[c-1]+=bb
  B[b-1]=0
  s+=bb*c-bb*b
  print(s)
# Judge status: Wrong Answer
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
D = list(map(int, input().split()))
D.sort()
for k in range(min(D),max(D)):
    arc = 0
    abc = 0
    for i in range(n):
        if D[i] >= k:
            arc += 1
        else:
            abc += 1
    if arc == abc:
        count += 1
print(count)
# Judge status: Accepted
makeA = lambda c: (ord('z')-ord(c)+1) % 26
s = list(map(makeA,list(input())))
#print(s)
K = int(input())
len_s = len(s)
#print(len_s)
for i in range(len_s-1):
    if s[i] <= K:
        K -= s[i]
        s[i] = 0
        #print(s)
if K > 0:
    s[-1] = (s[-1] + 26 - (K % 26)) % 26
#print(s)
makeS = lambda n: chr((26-n)%26+ord('a'))
print(''.join(list(map(makeS,s))))
# Judge status: Accepted
N, M, X = map(int, input().split())
C = [0] * N
A = [[0] * M for _ in range(N)]
for i in range(N):
    C[i], *A[i] = map(int, input().split())
ans = float('inf')
for bit in range(1 << N):
    score = [0] * M
    price = 0
    for i in range(N):
        if bit >> i & 1:
            price += C[i]
            for j in range(M):
                score[j] += A[i][j]
    if all(s >= X for s in score):
        ans = min(ans, price)
print(ans if ans < float('inf') else -1)