peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    if (A[i] % 2 == 0 and A[i] % 3 != 0 and A[i] % 5 != 0):
        print('DENIED')
        exit(0)
print('APPROVED')
# Judge status: Wrong Answer
n = str(input())
memo = int( n[0] + n[0] + n[0] )
if int(n) < memo:
	print(memo)
else:
	print(memo + 111)
# Judge status: Wrong Answer
def main():
    a=input()
    b=set(a)
    if(len(b)<=2):
        if(a.count(b.pop())==2):
            print('No')
        else:
            print('Yes')
    else:
        print('No')

main()
# Judge status: Wrong Answer
import heapq
n = int(raw_input())
heap = [map(int, raw_input().split(' '))[::-1] for _ in range(n)]
heapq.heapify(heap)

def f(heap):
	t = 0
	while(heap):
		nd,ct = heapq.heappop(heap)
		gap = nd - t
		while(heap and heap[0][0] == nd):
			u,v = heapq.heappop(heap) 
			t += v
			gap -= v
		if gap < 0: return False
		
	return True
print 'Yes' if f(heap) else 'No'
# Judge status: Accepted
from collections import Counter as C
n=int(input())
a=list(map(int,input().split()))
a.sort()
aset=list(set(a))
ca = C(a)
ans=0
for i in aset:
    if ans<ca[i-1]+ca[i]+ca[i+1]:
        ans=ca[i-1]+ca[i]+ca[i+1]
print(ans)
# Judge status: Accepted
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

n = int(input())
print(int(n**0.5)**2)
# Judge status: Accepted
x=[-1]+list(map(int,input().split()))
print(x.index(0))
# Judge status: Accepted
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = float("inf")
for i in range(-101,201):
    if i not in p:
        ans = min(ans,abs(x-i))
if x - ans not in p:
    print(x-ans)
else:
    print(x+ans)
# Judge status: Accepted
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

#ここから書き始める
a, b, x = map(int, input().split())
if a <= x <= a + b:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
a, b, c = map(int, input().split(" "))

if a == b and b == c:
  print(1)
elif a== b or b == c or c == a:
  print(2)
else:
  print(3)
# Judge status: Wrong Answer
a,b,c,d=list(map(int,input().split()))
print("Yes" if c//b <= a//d else "No")
# Judge status: Accepted
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']


def reverse(t):
    return t[::-1]


RT = [reverse(t) for t in T]
RS = reverse(S)
can = True
i = 0
while i < len(RS):
    can2 = False
    for j in range(4):
        sizeT = len(RT[j])
        if RT[j] == RS[i:i + sizeT]:
            i += sizeT
            can2 = True
            break

    if not can2:
        can = False
        break

if can:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n=int(input())
W=input_array()

left=0
right=sum(W)
diff=right

for i in range(n):
	left+=W[i]
	right-=W[i]
	diff_tmp=right-left
	# print(diff,diff_tmp)
	if abs(diff)<=abs(diff_tmp):
		print(abs(diff))
		break
	else:
		diff=diff_tmp
# Judge status: Accepted
import sys

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


def main():
    l = list(map(int, readline().split()))
    l.sort()

    if any([x % 2 == 0 for x in l]):
        print(0)
    else:
        s = l[0] * l[1]
        print(s)


if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
s = input()
t = input()
res = s+t
kekka = n*2
import copy
for i in range(n):
    tmp = list(res)
    del tmp[n]
    target = "".join(tmp)
    if target[:n] == s and target[-n:] == t:
        kekka = len(target)
        #print(target)
    res = copy.deepcopy(tmp)

print(kekka)
# Judge status: Accepted
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
total = sum(A)
total *= 2
mindif = 1e12
sub = 0
for i in range(N):
    sub += 2 * A[i]
    dif = abs(total//2-sub)
    if dif < mindif:
        mindif = dif

print(mindif)
# Judge status: Accepted
S=input()
zero=0
one=0
for i in range(len(S)):
    if S[i]=='1':
        one+=1
    else:
        zero+=1
print(min(zero,one)*2)
# Judge status: Accepted
wlist = []
city, road = map(int, input().split())
for i in range(road):
    wlist.append(list(map(int, input().split())))
dst = []
for i in range(city):
    count = 0
    for k in wlist:
        if i+1 in k:
            count += 1
    dst.append(count)
for d in dst:
    print(d)
# Judge status: Accepted
input()
S = input()
left = right = 0
for c in S:
    if c == "(":
        left += 1
    else:
        if left:
            left -= 1
        else:
            right += 1
print("(" * right + S + ")" * left)
# Judge status: Accepted
import math
n=int(input())
x=0
for i in range(n):
    if math.sqrt(n-i)%1==0.0:
        break
    else:
        x+=1
print(n-x)
# Judge status: Accepted
n, a = map(int, input().split())
b = list(map(int, input().split()))
b.sort()
c = 0
for i in range(n):
  if a < b[i] or (i == n - 1 and b[i] != a):
    break
  a -= b[i]
  c += 1
print(c)
# Judge status: Accepted
def dfs(s, mx):
    if len(s) == n:
        print(s)
        return
    for i in range(ord('a'), mx + 2):
        dfs(s + chr(i), max(mx, i))


n = int(input())
dfs('', ord('a') - 1)
# Judge status: Accepted
from operator import itemgetter
N=int(input())
hako=[]
for i in range(N):
    A,B=input().split()
    hako.append([A,int(B)*-1])
kari=hako.copy()
#print(kari)
hako.sort()
hako=sorted(hako,key=itemgetter(0,1))
#print(hako)
for i in range(N):
    print(kari.index(hako[i])+1)
# Judge status: Accepted
N,M = map(int,input().split())
AC = [0 for _ in range(N)]
WA = [0 for _ in range(N)]

for _ in range(M):
    p,S = input().split()
    p = int(p)-1
    if not AC[p]:
        if S == 'AC':
            AC[p] = 1
        else:
            WA[p] += 1
    else:
        continue
WAcount = 0
for i in range(N):
    if AC[i]:
        WAcount += WA[i]
print(sum(AC),WAcount)
# Judge status: Accepted
s = list(input())

a = [n for n,v in enumerate(s) if v == "A"]
z = [n for n,v in enumerate(s) if v == "Z"]

b = min(a)
y = max(z)

print(y-b+1)
# Judge status: Wrong Answer
N, M = map(int, input().split())

total = N * 2 + M
ans = total // 4
if N > M // 2:
    print(0)
else:
    print(ans)
# Judge status: Accepted
X, Y = map(int,input().split())

MOD = 10**9 + 7

def comb(n, r):
    if n < r or n < 0 or r < 0:
        return 0

    n += 1
    over = 1
    under = 1
    for i in range(1,r + 1):
      over = over * (n - i) % MOD
      under = under * i % MOD
    return over * pow(under, MOD - 2, MOD) % MOD

if (X + Y) % 3 != 0:
    print(0)
else:
    a = (2 * X - Y) // 3
    b = (2 * Y - X) // 3
    print(comb(a+b, a))
# 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 * M - (N * 2 + M * 2 - 4))
# Judge status: Accepted
# -*- coding: utf-8 -*-

N,M = list(map(int, input().rstrip().split()))
ab_list = [list(map(int, input().rstrip().split())) for i in range(N)]
cd_list = [list(map(int, input().rstrip().split())) for i in range(M)]
#-----

for a,b in ab_list:
    dist = (10**8)*2*2 + 1
    
    for i,[c,d] in enumerate(cd_list):
        temp_dist = abs(a-c) + abs(b-d)
        
        if dist > temp_dist:
            dist = temp_dist
            check = i

    print(check+1)
# 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
n = int(input())
ans =0
for i in range(n-1):
    ans += (n-1)//(i+1)
print(ans)
# Judge status: Accepted
a,b,c=map(int,input().split())
d=0
for i in range(a,b+1):
  if i%c==0:
    d+=1
print(d)
# Judge status: Accepted
import sys

n = int(input())

n_concecutive = 0

for _ in range(n):
    d1, d2 = map(lambda x: int(x), input().split())
    if d1 == d2:
        n_concecutive += 1
        if n_concecutive >= 3:
            print('Yes')
            sys.exit()
    else:
        n_concecutive = 0
print('No')
# Judge status: Accepted
import sys
from heapq import heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
works = [[] for _ in range(M+1)]
# M-1日後から選んでいく,
for _ in range(N):
    a, b = lr()
    if a <= M:
        works[a].append(-b)

heap = []
answer = 0
for i in range(1, M+1):
    for x in works[i]:
        heappush(heap, x)
    if heap:
        answer -= heappop(heap) # heap構造なので

print(answer)
# 08
# Judge status: Wrong Answer
N, Q = map(int, input().split())
S = input()
tmp = [0] * N
for i in range(1, N):
    if S[i-1] + S[i] == 'AC':
        tmp[i] += 1

for _ in range(Q):
    l, r = map(int, input().split())
    # print(tmp[l-1:r])
    print(sum(tmp[l-1:r]))
# Judge status: Accepted
import itertools
import math
def dis(X,Y):
    return ((X[0]-Y[0])**2+(X[1]-Y[1])**2)**.5
def main():
    n=int(input())
    L=[list(map(int,input().split())) for _ in range(n)]
    S=itertools.permutations([i for i in range(1,n+1)])
    ans=0
    for s in S:
        for i in range(n-1):
            a = s[i] - 1
            b = s[i+1] - 1
            ans += dis(L[a],L[b])
    ans /= math.factorial(n)
    print(ans)
main()
# Judge status: Wrong Answer
import numpy as np

N,W = map(int,input().split())
"""
DP = np.zeros(W+1,dtype=int)
for _ in range(N):
  w,v = map(int,input().split())
  np.maximum(DP[:-w]+v,DP[w:],out=DP[w:])
print(DP.max())
"""
DP= np.full(N*10000+1,W+1)
DP[0] = 0
for _ in range(N):
  w,v = map(int,input().split())
  np.minimum(DP[:-v]+w,DP[v:],out = DP[v:])
print(np.max(np.where(DP<=W)))
# Judge status: Accepted
from math import gcd
X = int(input())
Y = (X*360)//gcd(X,360)
print(Y//X)
# Judge status: Wrong Answer
n,k=map(int,input().split())
s,p,r=map(int,input().split())
t=input()
a=0
for i in range(k):
    d=1
    for j in range(i,n-k,k):
        #print(t[j])
        if t[j]==t[j+k]:
            d+=1
        else:
            a-=(-d//2)*eval(t[j])
            #print(d,t[j],a)
            d=1
    a-=(-d//2)*eval(t[j+k])
    #print(t[j+k],d,a)
print(a)
# Judge status: Accepted
N,M = [int(x) for x in input().split()]
X = [int(x) for x in input().split()]

X.sort()
diff = []
for i in range(1,len(X)):
    diff.append((X[i] - X[i-1]))

diff.sort()
diff = diff[:M-N]
if(N<M):
    print(sum(diff))
else:
    print("0")
# Judge status: Accepted
s=input()
if len(s)%2==0:
  
  if s[:len(s)//2]==s[len(s)//2:]:
    print("Yes")
  else:
    print("No")
else:
  if s[:len(s)//2]==s[len(s)//2+1:]:
    print("Yes")
  else:
    print("No")
# Judge status: Wrong Answer
import itertools
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))
l=[]
for i in range(1,n+1):
    l.append(i)
l=list(itertools.permutations(l))
l=sorted(l)
k=1
for i in range(1,n+1):
    k*=i
pp=0
qq=0
for j in range(k):
    if l[j]==p:
        pp=j+1
    elif l[j]==q:
        qq=j+1
print(abs(pp-qq))
# Judge status: Accepted
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

A, B = map(int, input().split())
if A <= 5:
    print(0)
elif A <= 12:
    print(int(B/2))
else:
    print(B)
# Judge status: Accepted
a, b , c ,d = map(int, input().split())

print(max(a*c,b*d,a*d,b*c))
# Judge status: Accepted
N, L = map(int, input().split())
ans = 0
tmp = 300
for i in range(N):
    if abs(L + i) < tmp:
        tmp = abs(L + i)
        num = i
        
for i in range(N):
    ans += (L + i)

ans -= (L + num)

print(ans)
# Judge status: Wrong Answer
n = int(input())
mod = 1000000007
print(pow(10, n, mod) - pow(9, n, mod) - pow(9, n, mod) + pow(8, n, mod))
# Judge status: Accepted
N, D = map(int, input().split())

area = 2 * D + 1

if N % area != 0:
    print(N // area + 1)

else:
    print(N // area)
# Judge status: Accepted
import sys
from functools import reduce

MOD = 10 ** 9 + 7

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

def lcm(a, b):
    return abs(a // gcd(a, b) * b)

n, *A = map(int, sys.stdin.read().split())

def main():
    l = reduce(lcm, A, 1) % MOD

    res = 0
    for a in A:
        res += l * pow(a, MOD-2, MOD) % MOD
        res %= MOD
    
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)
# Judge status: Accepted
N=int(input())
ab=[[0 for i in range(9)] for j in range(9)]
for i in range(1,N+1):
  if(i%10!=0):
    s=str(i)
    ab[int(s[0])-1][int(s[-1])-1]+=1
ans=0
for i in range(9):
  for j in range(9):
    ans+=ab[i][j]*ab[j][i]
print(ans)
# Judge status: Wrong Answer
x,y=map(int,input().split())
mod=10**9+7

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def mod_combinations_count(n, r, mod):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    m=(-x+2*y)//3
    if n<0 or m<0:
        print(0)
        exit()
    else:
        print(mod_combinations_count(n,m,mod)%mod)
# Judge status: Accepted
import itertools

n = int(input())
p = tuple(list(map(int, input().split())))
q = tuple(list(map(int, input().split())))
counter = 0
a = 0
b = 0
for i in itertools.permutations(range(1, n+1)):
    counter += 1
    if p == i:
        a = counter
    if q == i:
        b = counter

print(abs(a - b))
# Judge status: Accepted
fruits_sum, num = map(int, input().split())
value_list = list(map(int, input().split())) 
value_list.sort()
sum = 0
for i in range(num):
  sum += value_list[i]
print(sum)
# Judge status: Accepted
N, M = map(int, input().split())

if N == 1:
    if M == 1:
        print(1)
    else:
        print(M - 2)
    exit()
elif M == 1:
    print(N - 2)
    exit()
elif N == 2 or M == 2:
    print(0)
    exit()
else:
    print((N - 2) * (M - 2))
# Judge status: Wrong Answer
# Problem C - Bugged

# input
N = int(input())

# initialization
max_score = 0
score_list = []
for i in range(N):
    tmp = int(input())
    score_list.append(tmp)
score_list = sorted(score_list, reverse=True)

# score update
for score in score_list:
    tmp = max_score + score
    if tmp%10==0:
        tmp = 0
    max_score = max(max_score, tmp)

# output
print(max_score)
# Judge status: Accepted
def computeGCD(x, y): 
  
    if x > y: 
        small = y 
    else: 
        small = x 
    for i in range(1, small+1): 
        if((x % i == 0) and (y % i == 0)): 
            gcd = i 
              
    return gcd 
a,b,c=map(int,input().split())
r=computeGCD(a,b)
if c%r==0:
  print('YES')
else:
  print('NO')
# Judge status: Wrong Answer
N = int(input())
li = [list(map(int, input().split())) for i in range(N - 1)]

for n in range(N):
  if n == N - 1:
    print(0)
    break
  
  ans = 0
  for index, i in enumerate(li):
    if index < n:
      continue

    if ans < i[1]:
      ans += i[1] - ans
    else:
      if ans % i[1] != 0:
        ans += i[2] - (ans % i[1])

    ans += i[0]
  print(ans)
# Judge status: Accepted
s = list(input())
n = len(s)

a = [0] * (n+1)
for i in range(n):
    if s[i] == '<':
        a[i+1] = a[i]+1
for i in reversed(range(n)):
    if s[i] == '>':
        a[i] = max(a[i+1]+1,a[i])
print(sum(a))
# Judge status: Accepted

s = input()

if s == 'ABC':
    print('ARC')
else:
    print('ABC')
# Judge status: Wrong Answer
n=int(input())
s=input()
s_len=len(s)
ans=""
for i in range(s_len):
    char=97+(ord(s[i])+n-97)%26
    ans+=chr(char)
print(ans)
# Judge status: Accepted
N=int(input())
A=[int(input()) for i in range(N)]

temp=sorted(A,reverse=True)
maxi=temp[0]
secmaxi=temp[1]

for a in A:
    if a!=maxi:
        print(maxi)
    else:
        print(secmaxi)
# Judge status: Accepted
A, B, C, D = (int(x) for x in input().split())

while A > 0 and C > 0:
    C = C - B
    if C <= 0:
        print ("Yes")
    else:
        A = A - D
        if A <= 0:
            print ("No")
        else:
            continue
# Judge status: Accepted
import numpy as np

N,M=map(int, input().split())
A=[]
for i in range(N):
    a=list(input())
    A.append(a)
B=[]
for i in range(M):
    b=list(input())
    B.append(b)

A=np.array(A)
B=np.array(B)
ans="No"
for i in range(N):
    for j in range(N):
        if i+M<=N and j+M<=N:
            if (A[i:i+M, j:j+M]==B).all():
                ans="Yes"

print(ans)
# Judge status: Accepted
# https://atcoder.jp/contests/apc001/tasks/apc001_b

n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
t = sum(b) - sum(a)
pos = 0
neg = 0
for i in range(n):
    d = a[i] - b[i]
    if d > 0:
        pos += d
    elif d < 0:
        neg += -1 * d // 2
if pos <= neg:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
r = int(input())
Sr = 3 * r ** 2
S1 = 3 * 1 ** 2
print(Sr // S1)
# Judge status: Wrong Answer
import collections
N=int(input())
a=list(map(int, input().split()))
a.sort(reverse=True)
piv=a[0]
#print(a)
max=0
c=collections.Counter(a)
value=list(c.values())
key=list(c.keys())
for i in range(1,piv-1):
    #print(c[i],c[i+1],c[i+2])
    if max<c[i]+c[i+1]+c[i+2]:
        max=c[i]+c[i+1]+c[i+2]
print(max)
# Judge status: Accepted
a, b, c, x, y = map(int, input().split())
print(min(a*x+b*y, 2*c*x + b*max(0,y-x), 2*c*y + a*max(0, x-y)))
# Judge status: Accepted
k, a, b = map(int, input().split())

if 2 < (b-a):
    if k-(a-1) >= 2:
        q, r = divmod(k-(a-1), 2)
        ans = (b-a)*q+r+a
    else:
        ans = k+1

else:
    ans = k+1

print(ans)
# Judge status: Accepted
N=int(input())
N=str(N)
N = int(N[-1])
if (N==2 or N==4 or N==5 or N==7 or N==9):
  print("hon")
elif (N==0 or N==1 or N==6 or N==8):
  print("pon") 
else:
  print("bon")
# Judge status: Wrong Answer
n,k = [int(x) for x in input().split()]
print(1 + (n-k)%(k-1))
# Judge status: Wrong Answer
import numpy as np

N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h = np.array(sorted(h))
diff_h = np.zeros(N, dtype=np.int16)
diff_h[1:] = np.diff(h)
print(h)
print(diff_h)
cum_diff_h = np.cumsum(diff_h)
print(cum_diff_h)
s = cum_diff_h[K - 1 :] - cum_diff_h[: -K + 1]
print(min(s))
# Judge status: Accepted
X, Y, A, B, C = map(int, input().split())
pl = list(map(int, input().split()))
ql = list(map(int, input().split()))
rl = list(map(int, input().split()))
pl.sort(reverse=True)
ql.sort(reverse=True)
rl.sort(reverse=True)

total = pl[:X]+ql[:Y]+rl[:X+Y]
total.sort(reverse=True)
result = sum(total[:X+Y])

print(result)
# Judge status: Accepted
lis=list(map(int,input().split()))
print(sorted(lis)[0]+sorted(lis)[1])
# Judge status: Wrong Answer
# coding: utf-8

n = int(input().rstrip())
bo = [j * -1 for j in sorted([int(i) * -1 for i in input().rstrip().split(" ")])]

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        canTriangle = True
        for k in range(j+1,n):
            if bo[j] + bo[k] < bo[i]:
                canTriangle = False
                break
            ans += 1
        if not canTriangle:
            break

print(ans)
# Judge status: Wrong Answer
A, B, C = map(int,input().split())
if (A - C) * (B - C) > 0:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
d = int(input())
if d == 25:
    print("Christmas")

elif d ==24:
    print("Christmas Eve")

elif d ==23:
    print("Christmas Eve Eve")

elif d == 22:
    print("Christmas Eve Eve Eve")
# Judge status: Accepted
N, A, B = map(int, input().split())

high = (N - 1) * B + A
low = (N - 1) * A + B
ans = high - low + 1
ans = max(0, ans)

print(ans)
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))
a.sort()
x = sum(a[N::2])
print(x)
# Judge status: Wrong Answer
import math
A,B = map(int, input().split())

# 最大公約数の算出
y = max(A,B)
x = min(A,B)
while y%x != 0:
  tmp = x
  x = y%x
  y = tmp

# 素数および割り切れる数の探索
p = [1]
if x % 2 == 0:	p.append(2)
for val in range(3,int(x/2)+1):
  flag = 1
  if val % 2 != 0 and x % val == 0:
    for i in range(2,int(math.sqrt(val))+1):
      if val % i == 0:
        flag = 0
        break
    if flag == 1:
      p.append(val)
print(len(p))
# Judge status: Accepted
N = int(input())
dp = [[0]*3 for _ in range(N+1)]
for i in range(N):
    a, b, c = list(map(int, input().split()))
    dp[i+1][0] = max(dp[i][1], dp[i][2]) + a
    dp[i+1][1] = max(dp[i][2], dp[i][0]) + b
    dp[i+1][2] = max(dp[i][0], dp[i][1]) + c
print(max(dp[N]))
# Judge status: Accepted
N,M = map(int,input().split())
A = [[0,1] for _ in range(N)]
A.insert(0,[0,0])
A[1][0] = 1
for _ in range(M):
    x,y = map(int,input().split())
    A[y][1] += 1
    if A[x][0]==1:
        A[y][0]=1
    A[x][1] -= 1
    if A[x][1]==0:
        A[x][0]=0
cnt = 0
for i in range(1,N+1):
    cnt += A[i][0]
print(cnt)
# Judge status: Accepted
from operator import itemgetter

N = int(input())
# table = [[i for i in input().split()] for j in range(N)]
table = []
for i in range(N):
    value = list(input().split())
    value[1] = int(value[1])
    value.append(str(i + 1))
    table.append(value)

point_sort = sorted(table, key=itemgetter(1), reverse=True)
alphabet_sort = sorted(point_sort, key=itemgetter(0))

for i in alphabet_sort:
    print(i[2])
# Judge status: Wrong Answer
n = int(input())
T = [0]*n
c,s,f = [0]*(n-1),[0]*(n-1),[0]*(n-1)

for i in range(n-1):
	c[i],s[i],f[i] = map(int,input().split())

for	i in range(n-1):
	T[i] = s[i] + c[i]
	for j in range(i+1,n-1):
		if T[i] > s[j]:
			T[i] += (s[j-1] + c[j-1])%(f[j]) + c[j]
		else:
			T[i] = s[j] + c[j]
	print(T[i])
print(0)
# Judge status: Accepted
a,b= list(map(int,input().split()))
if a==0 or b==0:
    print("Zero")
elif a>0 and b>0:
    print("Positive")
elif a<0 and b>0:
    print("Zero")
else:
    c = abs(b-a)
    if c%2 == 0:
        print("Negative")
    else:
        print("Positive")
# Judge status: Wrong Answer
N = int(input())
L = []
light = [0]*(N+1)
light[0] = 1
cnt = 0

for i in range(N):
    L.append(int(input()) - 1)

for i in range(N+1):
    if light[i] == 1 and light[L[i]] == 0:
        light[i], light[L[i]] = 0, 1
        cnt += 1
        if light[1] == 1:
            print(cnt)
            exit()

print(-1)
# Judge status: Wrong Answer
a,b=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
c.sort()
d=sum(c)
e=0
if a<b:
  print(0)
else:
  for i in range(b):
    e=e+c[-b]
  print(d-e)
# Judge status: Accepted
n, k = map(int,input().split())
s = input()

press = []
temp = s[0]
cnt = 0
for string in s:
    if temp == string:
        cnt += 1
    else:
        press.append(cnt)
        temp = string
        cnt = 1
press.append(cnt)

if len(press) - 2 * k <= 0:
    print(n-1)
    exit()

ans = 2 * k
for i in press:
    ans += i - 1
print(ans)
# Judge status: Wrong Answer
inputArr = input().split(" ")
print(inputArr)
if int(inputArr[0]) * int(inputArr[2]) <= int(inputArr[1]):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n = int(input())
a = int(input())
d = n%500
if a >= d:
  print("Yes")
else: print("No")
# Judge status: Wrong Answer
n=int(input())
dp=[0]*n
a=list(map(int,input().split()))
s=sum(a)
dp[0]=a[0]
ans=s
for i in range(1,n):
  dp[i]=dp[i-1]+a[i]
for j in range(n):
  ans=min(ans,abs(dp[j]*2-s))
print(ans)
# Judge status: Wrong Answer
import math

H, A = map(int, input().split())
print(math.ceil(10 / 4))
# Judge status: Accepted
a,b = map(int,input().split())
if a*b%2==0: print('Even')
else: print('Odd')
# Judge status: Accepted
import math
List = [int(input()) for i in range(5)]
last = list(map(lambda x: x % 10, List))

lastnum = 0

last = sorted(last)
for i in range(5):
  if last[i] == 0:
    lastnum = 10
  else :
    lastnum = last[i]
    break

tensum =  list(map(lambda x: (math.ceil(x / 10))*10, List))

print(sum(tensum) - 10 + lastnum)
# Judge status: Accepted
S, C = [int(i) for i in input().split()]
if S*2 <= C:
    setn = S
    C -= S*2
    setn += C//4
else:
    setn = C//2
print(setn)
# Judge status: Wrong Answer
N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]
ans_1=0
ans=""
for S in s:
    ans_1=s.count(S)
    if s.count(S)>=ans_1:
        ans_1=s.count(S)
        ans=S

if ans_1>t.count(ans):
    print(ans_1-t.count(ans))
else :
    print("0")
# Judge status: Accepted
N = int(input())
array = [int(input()) for _ in range(N)]

next_i = 0
cnt = 0
ans = -1
for i in range(N):
    if next_i == 1:
        ans = cnt
        break
    next_i = array[next_i]-1
    cnt += 1
print(ans)