Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import numpy as np

m = 2019
div_list = [0]*m
div_list[0] += 1
S = np.array(list(input()))
N = len(S)
num = 0
for i in range(N):
    num += 10**i*int(S[N-i-1])
    div_list[num%m] += 1

ans = 0
for i, item in enumerate(div_list):
    ans += int(item*(item-1)/2)

print(ans)


### FIXED CODE ###

from sys import stdin
input = stdin.readline

def main():
    S = list(input())
    S.pop()
    m = 2019
    div_list = [0]*m
    num = 0
    for i, l in enumerate(reversed(S)):
        num += pow(10, i, m)*int(l)
        div_list[num%m] += 1

    div_list[0] += 1
    ans = 0
    for item in div_list:
        ans += int(item*(item-1)/2)

    print(ans)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())
# n, *a = map(int, open(0))
# M, D = map(int, input().split())
L = list(map(int, input().split()))
# S = input()
cnt = 0
import itertools
l = list(itertools.combinations(L, 2))
import numpy as np
ary = np.array(L)
for t in l:
    # if t[0] + t[1] > t[2] and t[1] + t[2] > t[0] and t[0] + t[2] > t[1]:
    cnt += np.count_nonzero(ary >= sum(t))
tot = (N * (N-1) * (N-2)) // 6
print(tot - cnt)


### FIXED CODE ###

N=int(input())
L=list(map(int,input().split()))
L.sort()
ans = 0
i = 0
while i < N - 2:
    j = i + 1
    k = j + 1
    while j < N - 1:
        while k < N:
            if L[i] + L[j] <= L[k]:
                ans += k - j - 1
                break
            k += 1
        if k == N:
            ans += k - 1 - j
        j += 1
    i += 1
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = [None] * n
print(str(a.index(1) + 1), end=" ")
for i in range(1, n):
    print(str(a.index(i + 1) + 1), end=" ")
print()


### FIXED CODE ###

import sys
import collections
import bisect


def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = [0] * n
    for i in range(n):
        B[A[i] - 1] = str(i + 1)
    print(" ".join(B))


if __name__ == '__main__':
    main()
### BUGGY CODE ###

s=input()
a=0
now=1
l=[0]*2019
for i in list(s)[::-1]:
    a=a+now*int(i)
    l[a%2019]+=1

    now*=10





ans=0

for i in l:
    ans+=(i-1)*i//2
print(ans+l[0])

### FIXED CODE ###

s=input()
a=0
now=1
l=[0]*2019
for i in list(s)[::-1]:
    a=(a+now*int(i))%2019
    l[a]+=1

    now*=10
    now%=2019
ans=0
for i in l:
    ans+=(i-1)*i//2
print(ans+l[0])
### BUGGY CODE ###


n = int(input())
A = [list(map(int,input().split())) for i in range(n)]

for i in range(n):
    A[i].append(1010 + i)
    for j in range(n):
        A[i][j] -= 1

#print(A)

S = [0] * n

d = 0
while 1:
    co = 0
    i = 0
    F = [0] * n
    ga = 0
    while co < n:
        aite = A[i][S[i]]
        #print(S)
        #print("aite",aite)
        if aite <= 1000 and F[i] == 0 and F[aite] == 0 and A[aite][S[aite]] == i:
            #print("g", i, aite)
            S[i] += 1
            S[aite] += 1
            F[i] = 1
            F[aite] = 1
            co = 0
            ga += 1
        i += 1
        if i == n:
            i = 0
        co += 1
    d += 1
    #print("d", d)
    if ga == 0:
        if sum(S) == (n-1)*n:
            print(d-1)
        else:
            print(-1)
        break



### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
A = [list(map(int,input().split())) for i in range(n)]
for i in range(n):
    for j in range(n-1):
        A[i][j] -= 1

AA = [[j for j in i] for i in A]

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

for i in range(n):
    for j in range(n-1):
        A[i][j] = ID[i][A[i][j]]

M = [[] for i in range(id_)]
IN = [0] * id_
for i in range(n):
    for j in range(n-2):
        M[A[i][j]].append(A[i][j+1])
        IN[A[i][j+1]] +=1
# print(A)
# print(M)

# 以下、トポロジカルソート

S = []
s = 0

for i in range(id_):
    if IN[i] == 0:
        S.append(i)

while s < len(S):
    for x in M[S[s]]:
        IN[x] -= 1
        # print(x,IN)
        if IN[x] == 0:
            S.append(x)
    s += 1

# print(S)

if len(S) < id_:
    print(-1)
else:
    T = [1] * id_
    for i in range(id_):
        for j in M[S[i]]:
            T[j] = max(T[j], T[S[i]] + 1)
    print(max(T))


# 以下、閉路検出(今は削除)

# V = [0] * id_
# S = [0]
# V[0] = 1

# import sys

# def visit(x):
#     if V[x] == 1:
#         print(-1)
#         sys.exit()
#     elif V[x] == 0:
#         V[x] = 1
#         for i in M[x]:
#             visit(i)
#         V[x] = 2

# for i in range(id_):
#     if V[i] == 0:
#         visit(i)
# print("heironasi")

# 閉路検出ここまで
### BUGGY CODE ###

def count(value, P):
    cnt = 0
    for p in P:
        if p & value == value:
            cnt += 1
    return cnt


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    P = []
    for i in range(N):
        for j in range(i+1, N+1):
            P.append(sum(A[i:j]))
    retval = 0
    for idx in range(40, -1, -1):
        tmp = retval + 2**idx
        if count(tmp, P) >= K:
            retval = tmp
    print(retval)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def count(value, P):
    cnt = 0
    for p in P:
        if p & value == value:
            cnt += 1
    return cnt


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    P = []
    for i in range(N):
        s = 0
        for j in range(i, N):
            s += A[j]
            P.append(s)
    retval = 0
    for idx in range(40, -1, -1):
        tmp = retval + 2**idx
        if count(tmp, P) >= K:
            retval = tmp
    print(retval)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

N, K = map(int,input().split())
hN = list(map(int,input().split()))
dp = [1000000000]*N
dp[0] = 0
for n in range(N-1):
  for k in range(min(K,N-n-1)):
    dp[n+k+1] = min(dp[n+k+1], dp[n]+abs(hN[n]-hN[n+k+1]))
print(dp[-1])


### FIXED CODE ###

N, K = map(int,input().split())
hN = list(map(int,input().split()))
dp = [1000000000]*N
dp[0] = 0
for n in range(N-1):
  for k in range(min(K,N-n-1)):
    dp[n+k+1] = min(dp[n+k+1], dp[n]+abs(hN[n]-hN[n+k+1]))
print(dp[-1])
### BUGGY CODE ###

n=int(input())
a=input().split()
sp=' '
ans=''
for i in range(n):
	if i!=0:
		ans+=sp
	ans+=str(a.index(str(i+1))+1)
print(ans)

### FIXED CODE ###

n=int(input())
a=input().split()
lans=[int(i) for i in range(n)]
sp=' '
ans=''

for i in range(n):
	lans[int(a[i])-1]=i+1
ans+=str(lans[0])
for i in range(1,n):
	ans+=sp
	ans+=str(lans[i])
print(ans)
### BUGGY CODE ###

def inpl(): return [int(i) for i in input().split()]

N, K = inpl()
import numpy as np
H = np.zeros((K,K), dtype = np.int32)
for _ in range(N):
    x, y, c = input().split() 
    x = int(x)
    y = int(y)
    t = True
    x %= 2*K
    y %= 2*K
    if x >= K:
        x -= K
        t = not t
    if y >= K:
        y -= K
        t = not t
    if c == 'W':
        t = not t
    if t:
        H[x][y] += 1
        continue
    H[x][y] -= 1

for i in range(K-1):
    H[i+1] += H[i]
H = H.T
for i in range(K-1):
    H[i+1] += H[i]
checkH =  np.zeros((K,K), dtype = np.int32)
for i in range(K):
    for j in range(K):
            checkH[i][j] = H[K-1][K-1] + 2*H[i][j] - H[i][K-1] - H[K-1][j] 
Hans = (N - checkH[K-1][K-1])//2 + checkH

print(max(np.amax(Hans), N-np.amin(Hans)))

### FIXED CODE ###

def inpl(): return [int(i) for i in input().split()]

N, K = inpl()
import numpy as np
H = np.zeros((K,K), dtype = np.int32)
for _ in range(N):
    x, y, c = input().split() 
    x = int(x)
    y = int(y)
    t = c == 'B'
    x %= 2*K
    y %= 2*K
    if x >= K:
        x -= K
        t = not t
    if y >= K:
        y -= K
        t = not t
    if t:
        H[x][y] += 1
        continue
    H[x][y] -= 1

H = H.cumsum(axis=0)
H = H.cumsum(axis=1)

checkH = H[K-1][K-1] + 2*H
for i in range(K):
            checkH[i] -= H[i][K-1]
checkH = checkH.T 
H = H.T
for i in range(K):
            checkH[i] -= H[i][K-1]
Hans = (N - checkH[K-1][K-1])//2 + checkH

print(max(np.amax(Hans), N-np.amin(Hans)))
### BUGGY CODE ###

n, k = map(int, input().split())
positions = [int(i) for i in input().split()]
scores = [int(i) for i in input().split()]
if max(scores) <= 0:
  print(max(scores))
else:
  positions = [0] + positions
  scores = [0] + scores
  max_point = -10 ** 9
  #print(max_point)
  for i in range(1, n + 1):
    s = []
    f_pos = positions[i]
    point = scores[f_pos]
    s.append(point)
    while f_pos != i:
      f_pos = positions[i]
      point += scores[f_pos]
      s.append(point)
    loop = len(s)
    if loop > k:
      point = max(s[:k])
    else:
      loop_c = k // loop
      r = k % loop
      point1 = s[-1] * loop_c
      if r != 0:
        point1 += max(s[:r])
      point2 = s[-1] * (loop_c - 1)
      point2 += max(s)
      point = max(point1, point2)
    max_point = max(max_point, point)
  print(max_point)


### FIXED CODE ###

n, k = map(int, input().split())
positions = [int(i) for i in input().split()]
scores = [int(i) for i in input().split()]
if max(scores) <= 0:
  print(max(scores))
else:
  positions = [0] + positions
  scores = [0] + scores
  max_point = -pow(10, 9)
  #print(max_point)
  for i in range(1, n + 1):
    s = []
    f_pos = positions[i]
    score = scores[f_pos]
    s.append(score)
    while f_pos != i:
      f_pos = positions[f_pos]
      score += scores[f_pos]
      s.append(score)
    loop = len(s)
    if loop >= k:
      point = max(s[:k])
    elif s[-1] <= 0:
      point = max(s)
    else:
      loop_c = k // loop
      r = k % loop
      point1 = s[-1] * loop_c
      if r != 0:
        point1 += max(s[:r])
      point2 = s[-1] * (loop_c - 1)
      point2 += max(0, max(s))
      point = max(point1, point2)
    max_point = max(max_point, point)
  print(max_point)
### BUGGY CODE ###

import copy

N, Q = map(int,input().split())
nord = [[0 for i in range(N)] for j in range(N)]
parents = [0]

for i in range(N-1):
    a, b = map(int,input().split())
    nord[a-1][b-1] = 1
    nord[b-1][a-1] = 1

saveNord = copy.deepcopy(nord)
currentN = []
nextN = []
check = 0
for i in range(N):
    if nord[0][i]==1:
        currentN.append(i)
        nord[0][i]=0
        nord[i][0]=0
        check += 1
while check<N-1:
    for i in currentN:
        for j in range(N):
            if nord[i][j]==1:
                nextN.append(j)
                nord[j][i]=0
                nord[i][j]=0
                check += 1
    parents.extend(currentN)
    currentN = nextN
parents.extend(currentN)

nord_num = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int,input().split())
    nord_num[p-1] = nord_num[p-1] + x
    
arrive = set()
for i in parents:
    arrive.add(i)
    for j in range(N):
        if (saveNord[i][j]==1) and (j in arrive):
            nord_num[i] = nord_num[j] + nord_num[i]


count = 1
for i in nord_num:
    if count == N:
        print(i)
    else:
        print(i, end=" ")
        count += 1


### FIXED CODE ###

N, Q = map(int,input().split())
nord = [set() for i in range(N)]

for i in range(N-1):
    a, b = map(int,input().split())
    nord[b-1].add(a-1)
    
nord_num = [0 for i in range(N)]
for i in range(Q):
    p, x = map(int,input().split())
    nord_num[p-1] = nord_num[p-1] + x
    
for i in range(N):
    for j in nord[i]:
        nord_num[i] = nord_num[j] + nord_num[i]
        
count = 1
for i in nord_num:
    if count == N:
        print(i)
    else:
        print(i, end=" ")
        count += 1
### BUGGY CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
s=[tuple(map(int, input().split())) for i in range(N)]
def me(x,y,z):
    l=[None]*(M+1)
    l[0]=0
    for i,tu in enumerate(s):
        for j in range(M-1,-1,-1):
            if l[j]==None:
                continue
            t=l[j]+tu[0]*x+tu[1]*y+tu[2]*z
            if l[j+1]==None or t>l[j+1]:
                l[j+1]=t
    return l[-1]
print(max(me(1,1,1),me(1,1,-1),me(1,-1,1),me(-1,1,1),me(1,-1,-1),me(-1,-1,1),me(-1,1,-1),me(-1,-1,-1)))


### FIXED CODE ###

import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int,input().split())
s=[tuple(map(int, input().split())) for i in range(N)]
def me(x,y,z):
    l=[None]*(M+1)
    l[0]=0
    for i,tu in enumerate(s):
        for j in range(M-1,-1,-1):
            if l[j]==None:
                continue
            t=l[j]+tu[0]*x+tu[1]*y+tu[2]*z
            if l[j+1]==None or t>l[j+1]:
                l[j+1]=t
    return l[-1]
print(max(me(1,1,1),me(1,1,-1),me(1,-1,1),me(-1,1,1),me(1,-1,-1),me(-1,-1,1),me(-1,1,-1),me(-1,-1,-1)))
### BUGGY CODE ###

# BFS version

#
H, W = list(map(int, input().split()))
M = []
for i in range(H):
    M.append(list(input().rstrip()))

#
def walk(pos):
    queue = [pos]

    while len(queue)>0:
        pos = queue.pop(0)
        x, y = pos
        val = M[y][x]
        #print(x,y,val)

        # up
        if y>0 and (M[y-1][x]=='.' or (isinstance(M[y-1][x], int) and val<M[y-1][x])):
            M[y-1][x] = val + 1
            queue += [(x, y-1)]
        # down
        if y<H-1 and (M[y+1][x]=='.' or (isinstance(M[y+1][x], int) and val<M[y+1][x])):
            M[y+1][x] = val + 1
            queue += [(x, y+1)]
        # left
        if x>0 and (M[y][x-1]=='.' or (isinstance(M[y][x-1], int) and val<M[y][x-1])):
            M[y][x-1] = val + 1
            queue += [(x-1, y)]
        # right
        if x<W-1 and (M[y][x+1]=='.' or (isinstance(M[y][x+1], int) and val<M[y][x+1])):
            M[y][x+1] = val + 1
            queue += [(x+1, y)]
        #print('B')

#
M[H-1][W-1] = 1
walk((W-1, H-1))
#print(M)
#exit()

#
if M[0][0]=='.':
    print(-1)
else:
    blocks = sum([m.count('#') for m in M])
    print(H*W - blocks - M[0][0])


### FIXED CODE ###

# BFS version

#
H, W = list(map(int, input().split()))
M = []
for i in range(H):
    M.append(list(input().rstrip()))

#
def walk(pos):
    queue = [pos]

    while len(queue)>0:
        pos = queue.pop(0)
        x, y = pos
        val = M[y][x]
        #print(x,y,val)

        # up
        if y>0 and (M[y-1][x]=='.' or (isinstance(M[y-1][x], int) and val+1<M[y-1][x])):
            M[y-1][x] = val + 1
            queue += [(x, y-1)]
        # down
        if y<H-1 and (M[y+1][x]=='.' or (isinstance(M[y+1][x], int) and val+1<M[y+1][x])):
            M[y+1][x] = val + 1
            queue += [(x, y+1)]
        # left
        if x>0 and (M[y][x-1]=='.' or (isinstance(M[y][x-1], int) and val+1<M[y][x-1])):
            M[y][x-1] = val + 1
            queue += [(x-1, y)]
        # right
        if x<W-1 and (M[y][x+1]=='.' or (isinstance(M[y][x+1], int) and val+1<M[y][x+1])):
            M[y][x+1] = val + 1
            queue += [(x+1, y)]
        #print('B')

#
M[H-1][W-1] = 1
walk((W-1, H-1))
#print(M)
#exit()

#
if M[0][0]=='.':
    print(-1)
else:
    blocks = sum([m.count('#') for m in M])
    print(H*W - blocks - M[0][0])
### BUGGY CODE ###

from collections import deque
n,m,k=map(int,input().split())
fr=[[]]
bl=[[]]
for i in range(n-1):
  fr.append([])
  bl.append([])
for i in range(m):
  a,b=map(int,input().split())
  fr[a-1].append(b)
  fr[b-1].append(a)
for i in range(k):
  a,b=map(int,input().split())
  bl[a-1].append(b)
  bl[b-1].append(a)

def bfs(k):
  use=deque()
  use.append(k)
  ans=0
  aldic={}
  for i in range(0,10**100):
    if not bool(use):
      minus=0
      for x in bl[k-1]:
        if x in aldic:
          minus+=1
      if k!=n:
        print(ans-len(fr[k-1])-1-minus,end=" ")
      else:
        print(ans-len(fr[k-1])-1-minus)
      break
    else:
      check=use.popleft()
      if not check in aldic:
        aldic[check]=1
        for x in fr[check-1]:
          if not x in aldic:
            use.append(x)
        ans+=1
for i in range(1,n+1):
  bfs(i)

### FIXED CODE ###

from collections import deque
n,m,k=map(int,input().split())
fr=[[]]
for i in range(n-1):
  fr.append([])
for i in range(m):
  a,b=map(int,input().split())
  fr[a-1].append(b)
  fr[b-1].append(a)

belong=[0]*n
anslist=[0]*n
count=0
def bfs(k):
  global count
  if belong[k-1]==0:
    count+=1
    use=deque()
    use.append(k)
    ans=0
    aldic={}
    while use:
      if not bool(use):
        break
      else:
        check=use.popleft()
        if check not in aldic:
          aldic[check]=1
          for x in fr[check-1]:
            use.append(x)
    for x in aldic:
      belong[x-1]=count
      anslist[x-1]=len(aldic)-len(fr[x-1])-1

for i in range(1,n+1):
  bfs(i)
for i in range(k):
  a,b=map(int,input().split())
  if belong[a-1]==belong[b-1]:
    anslist[a-1]-=1
    anslist[b-1]-=1
for i in range(0,len(anslist)):
  if i!=len(anslist)-1:
    print(anslist[i],end=" ")
  else:
    print(anslist[i])
### BUGGY CODE ###

import sys

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

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

nmax=0

Asum=list()
Asum.append(0)
Bsum=list()
Bsum.append(0)

imax_a = N
for i in range(N):
    s = Asum[i]+A[i]
    Asum.append(s)
    if s > K:
        imax_a = i+1
        break

imax_b = M
for i in range(M):
    s = Bsum[i]+B[i]
    Bsum.append(s)
    if s > K:
        imax_b = i+1
        break
        
for i in range(imax_a+1):
    can_update = 1
    for j in range(imax_b, -1, -1):
        time = Asum[i]+Bsum[j]
        # print("i=",i,"j=",j,"time=",time)
        if time <= K:
            if can_update == 1:
                imax_b = j
                can_update = 0

            if nmax < i+j:
                nmax = i+j
                # print("i=",i," j=",j," Asum",Asum[i]," Bsum", Bsum[j], " time=",time, " nmax=", nmax)
                break

print(nmax)

### FIXED CODE ###

import sys

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

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

nmax=0

Asum=list()
Asum.append(0)
Bsum=list()
Bsum.append(0)

imax_a = N
for i in range(N):
    s = Asum[i]+A[i]
    Asum.append(s)
    if s > K:
        imax_a = i+1
        break

imax_b = M
for i in range(M):
    s = Bsum[i]+B[i]
    Bsum.append(s)
    if s > K:
        imax_b = i+1
        break
        
for i in range(imax_a+1):
    for j in range(imax_b, -1, -1):
        time = Asum[i]+Bsum[j]
        # print("i=",i,"j=",j,"time=",time)
        if time <= K:
            imax_b = j

            if nmax < i+j:
                nmax = i+j
                # print("i=",i," j=",j," Asum",Asum[i]," Bsum", Bsum[j], " time=",time, " nmax=", nmax)

            break

print(nmax)
### BUGGY CODE ###

N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
for i in range(N):
  w.append(1+i+a[i])
  s.append(1+i-a[i])
for i in range(N):
  count+=s.count(w[i])
print(count)

### FIXED CODE ###

N=int(input())
count=0
a=list(map(int,input().split()))
w=[]
s=[]
num=[0]*N
maxi=max(a)
for i in range(N):
  s.append(1+i-a[i])
  if 1+i+a[i]<N:
    num[1+i+a[i]]+=1
for i in range(N):
  if s[i]>=0:
    count+=num[s[i]]
print(count)
### BUGGY CODE ###

n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  while n>1and v!=w:
    if v>w:v,w=w,v
    w=(w+n-2)//n
  print(v)

### FIXED CODE ###

n,q,*t=map(int,open(0).read().split())
for v,w in zip(t[::2],t[1::2]):
  if n<2:
    print(min(v,w))
    continue
  s,t=set(),set()
  while v:
    s|={v}
    v=(v+n-2)//n
  while w:
    t|={w}
    w=(w+n-2)//n
  print(max(s&t))
### BUGGY CODE ###

n = int(input())
R = [int(input()) for i in range(n)]
maxv = R[1] - R[0]

for i in range(0, n-1):
    for j in range(i+1, n):
        maxv = R[j] - R[i] if R[j] - R[i] > maxv else maxv

print(maxv)

### FIXED CODE ###

n = int(input())
R = [int(input()) for i in range(n)]
maxv = R[1] - R[0]
minv = R[0]

for j in range(1, n):
    maxv = R[j] - minv if R[j] - minv > maxv else maxv
    minv = R[j] if R[j] < minv else minv

print(maxv)
### BUGGY CODE ###

from itertools import product

N = int(input())
D = list(map(int, input().split()))
if N >= 24:
    print(0)
    exit()

ans = 0
for pr in product([0, 1], repeat=N):
    clocks = []
    for i, is_flipped in enumerate(pr):
        if is_flipped:
            clocks.append(D[i])
        else:
            clocks.append(24 - D[i])
    res = 25
    clocks = [0] + sorted(clocks) + [24]
    for cf, cb in zip(clocks, clocks[1:]):
        res = min(res, cb - cf)
    ans = max(ans, res)
print(ans)


### FIXED CODE ###

from collections import Counter
from itertools import product


N = int(input())
D = list(map(int, input().split()))
D_cnt = Counter(D)
if N >= 24 or D_cnt[0] > 0 or D_cnt[12] > 1 or any(D_cnt[i] > 2 for i in range(1, 12)):
    print(0)
    exit()
clock = [0, 24]
undet = []
if 12 in D_cnt:
    clock.append(12)
for i in range(1, 12):
    if D_cnt[i] == 2:
        clock.append(i)
        clock.append(24 - i)
    elif D_cnt[i] == 1:
        undet.append(i)

ans = 0
for rp in product([0, 1], repeat=len(undet)):
    candidate = clock[:]
    for j, is_flipped in enumerate(rp):
        candidate.append(undet[j]) if is_flipped else candidate.append(24 - undet[j])
    candidate.sort()
    ans = max(ans, min(ca - cb for cb, ca in zip(candidate, candidate[1:])))
print(ans)
### BUGGY CODE ###

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

for i in range(1, N):
    s = A.count(i)
    print(s)

print(0)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
tm = [0] * n

for i in range(n-1):
    tm[a[i] - 1] += 1

for i in tm:
    print(i)
### BUGGY CODE ###

a,b,x=map(int, input().split())
count=0
for i in range(a,b+1):
    if i%x==0:
        count+=1
print(count)    

### FIXED CODE ###

a,b,x=map(int, input().split())
a=(a-1)//x
b//=x
print(b-a)
### BUGGY CODE ###

N,K = map(int, input().split())
A = list(map(int, input().split()))

L = 2
P = 0

P = A[0]

while L <= K:
   P = A[P-1]
   L = L + 1

print(P)


### FIXED CODE ###

#そのまま処理すると時間超過するので、ループを探索する

N, K = map(int, input().split())
A = list(map(int, input().split()))
 
#町の数だけ-1のチェックを生成する

flag = [-1] * N

#１番目の町は必ず踏むので、０にする

flag[0] = 0

#今いる町の位置i、初期値はリスト番号0

i = 0

#移動回数の初期値

num = 0
 
while True:

#移動回数を加算する

    num += 1

#町を移動する、リスト上では-1する必要がある

    i = A[i] - 1

#-1でない場合は、一度到達しているのでループを終了する

    if flag[i] != -1:

#flag[i]には何手目で到達したかが入っているので、ループに突入するまでの処理数としてiniに登録する

        ini = flag[i]
        break

    flag[i] = num

#loopに必要な数を求める、まずはループに突入するまでの処理数iniを引く
 
loop = num - ini
 
#loopに突入するまでの処理数よりも、与えられた処理数が多いとき

if K > ini:

#loopに突入するまでにかかる数を引く

    K -= ini

#ループに入るスタート位置＋ループ後の余の位置＋１
    
    t = flag.index(ini + K % loop) + 1

    print(t)

#それ以外の時、先に-1しているので+1して補正する

else:
    t = flag.index(K) + 1
    print(t)
### BUGGY CODE ###

import sys
from collections import deque

def q(d, c, dq):
    if c == 1: 
        if d < 10: 
            dq.append(d)
            return 0
        else:
            a = d //10 + d % 10
            if a < 10: 
                dq.append(a)
                return 1
            else: 
                dq.append(a-9)
                return 2
    a = d * 2
    if a < 10: count = q(a, c//2, dq)
    else:
        count = q(a - 9, c//2, dq)
        count += c//2
    count += c//2
    if c % 2 == 1: dq.append(d)
    return count

def solve():
    input = sys.stdin.readline
    M = int(input())
    count = 0
    dq = deque()
    digit = 0
    for _ in range(M):
        d, c = map(int, input().split())
        add = q(d, c, dq)
        count += add
    
    digit = len(dq)
    for _ in range(digit - 1):
        #print(dq)
        a = int(dq.pop())
        a += int(dq.pop())
        if a >= 10:
            dq.append(str(a % 10 + a // 10))
            count += 2
        else: 
            dq.append(str(a))
            count += 1

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys
from collections import deque

def q(d, c): #dは9以下、cは桁数
    digsum = d * c
    add = c - 1 + (digsum - 1) // 9
    rem = digsum - 9 * ((digsum - 1) // 9)
    return add, rem

def solve():
    input = sys.stdin.readline
    M = int(input())
    count = -1
    ans = 0
    for _ in range(M):
        d, c = map(int, input().split())
        add, rem = q(d, c)
        count += add
        ans += rem
        count += 1
        if ans > 9:
            ans -= 9
            count += 1

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()