Problem:
 Score: 500 points    Problem Statement  N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.  The preliminary stage consists of several rounds, which will take place as follows:   All the N contestants will participate in the first round.  When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:  The organizer will choose two consecutive digits in the decimal notation of X , and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round. For example, when X = 2378 , the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen). When X = 100 , the number of contestants advancing to the next round will be 10 , no matter which two digits are chosen.    The preliminary stage ends when 9 or fewer contestants remain.   Ringo, the chief organizer, wants to hold as many rounds as possible.
Find the maximum possible number of rounds in the preliminary stage.  Since the number of contestants, N , can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M , which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1 , the following c_2 digits are all d_2 , \ldots , and the last c_M digits are all d_M .      Constraints   1 \leq M \leq 200000  0 \leq d_i \leq 9  d_1 \neq 0  d_i \neq d_{i+1}  c_i \geq 1  2 \leq c_1 + \ldots + c_M \leq 10^{15}         Input  Input is given from Standard Input in the following format:  M  d_1  c_1  d_2  c_2  :  d_M  c_M       Output  Print the maximum possible number of rounds in the preliminary stage.        Sample Input 1 2
2 2
9 1      Sample Output 1 3  In this case, N = 229 contestants will participate in the first round. One possible progression of the preliminary stage is as follows:   229 contestants participate in Round 1 , 49 contestants participate in Round 2 , 13 contestants participate in Round 3 , and 4 contestants advance to the finals.   Here, three rounds take place in the preliminary stage, which is the maximum possible number.       Sample Input 2 3
1 1
0 8
7 1      Sample Output 2 9  In this case, 1000000007 will participate in the first round.

Solution (Python):


import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7


D = {
    0: (0, 1),
    1: (2, 1),
    2: (4, 1),
    3: (6, 1),
    4: (8, 1),
    5: (1, 2),
    6: (3, 2),
    7: (5, 2),
    8: (7, 2),
    9: (9, 2),
}

M = INT()
C = Counter()
for i in range(M):
    d, c = MAP()
    C[d] += c

def calc(a, cnt):
    sm = 0
    odd = []
    while cnt > 1:
        if cnt % 2 == 1:
            odd.append(a)
            cnt -= 1
        cnt //= 2
        sm += cnt * D[a][1]
        a = D[a][0]
    for b in odd:
        a += b
        sm += 1
        if a >= 10:
            a = int(str(a)[0]) + int(str(a)[1])
            sm += 1
    return (a, sm)

ans = 0
A = []
for k, v in C.items():
    a, sm = calc(k, v)
    ans += sm
    A.append(a)

for i in range(1, len(A)):
    A[i] += A[i-1]
    ans += 1
    if A[i] >= 10:
        A[i] = int(str(A[i])[0]) + int(str(A[i])[1])
        ans += 1
print(ans)

Solution (Python):
m=int(input())
S = D = 0
for _ in range(m):
    d, c=map(int, input().split())
    S+=d*c
    D+=c
print((S-1)//9+D-1)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

M = int(input())
order = 0
total = 0
for i in range(M):
    d,c = map(int,input().split(' '))
    order += c
    total += d*c
print(order-1+(total-1)//9)

Solution (Python):
M = int(input())
DC = [list(map(int, input().split())) for _ in range(M)]

digits_sum = 0
digits_length = 0
for d, c in DC:
    digits_sum += d*c
    digits_length += c



print((digits_length - 1) + ((digits_sum-1) // 9))

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    M=int(input())
    d=[0]*M
    c=[0]*M
    ans=0
    l=[]
    for i in range(M):
        d[i],c[i]=map(int,input().split())
    ans+=sum(c)-1
    x=0
    for i in range(M):
        x+=c[i]*d[i]
    ans+=(x-1)//9
    print(ans)
        
        

if __name__ == '__main__':
    main()

Solution (Python):
s=n=0
for _ in range(int(input())):
    a,b=map(int,input().split())
    s+=a*b
    n+=b
print(~-n+~-s//9)

Solution (Python):
M = int(input())

cnt = 0
cnt_c = 0
L = []
for _ in range(M):
    d, c = map(int, input().split())
    cnt += c*d
    cnt_c += c   

ans = (cnt-1) // 9 + cnt_c - 1

print(ans)

Solution (Python):
m=int(input())
ans=0
tmp=0
dig=0
for i in range(m):
    q,r=map(int,input().split())
    tmp+=q*r
    dig+=r

ans+=(tmp-1)//9
print(ans+dig-1)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = []
D = 0
S = 0
for _ in range(N):
  d, c = list(map(int, input().split()))
  a.append((d, c))
for i in range(N):
  d, c = a[i]
  D += c
  S += d * c
print(D - 1 + (S - 1) // 9)

Solution (Python):
m=int(input())
counter=0
s=0
for i in range(m):
  d,c=map(int,input().split())
  counter+=d*c
  s+=c
print(s-1+(counter-1)//9)

Solution (Python):
M = int(input())
d = [0] * M
c = [0] * M
for i in range(M):
    d[i], c[i] = map(int, input().split())

D = sum(c)
S = 0
for i in range(M):
    S += d[i] * c[i]

print(D - 1 + (S - 1) // 9)

Solution (Python):
M=int(input())
N=0
S=0
for i in range(M):
  d,c=map(int,input().split())
  N +=c
  S+=d*c
print(N-1+(S-1)//9)

Solution (Python):
m=int(input())
dc=[list(map(int,input().split())) for i in range(m)]

num=0
l=0
for d,c in dc:
    num+=d*c
    l+=c

if num%9==0:
    print(l+num//9-2)
else:
    print(l+num//9-1)

Solution (Python):
import sys
import numpy as np

stdin = sys.stdin
 
ni = lambda:int(ns())
na = lambda:list(map(int,stdin.readline().split()))
ns = lambda:stdin.readline().rstrip()  

M = ni()
D = [] ; C = []

for i in range(M):
    d, c = na()
    D.append(d)
    C.append(c)

D = np.array(D) ; C = np.array(C)

x = C.sum() * 9 + (C * D).sum()

answer = (x + 8) // 9 - 2
print(answer)

Solution (Python):
m=int(input())
a=[list(map(int, input().split())) for i in range(m)]
x=0
y=0

for i in range(m):
    x+=a[i][1]
    y+=a[i][0]*a[i][1]



print(x-1+(y-1)//9)

Solution (Python):
def main():
    import sys
    input = sys.stdin.buffer.readline
    M = int(input())
    ans = 0
    dc_sum = 0
    for i in range(M):
        d, c = (int(i) for i in input().split())
        dc_sum += d*c
        ans += c
    if dc_sum % 9 == 0:
        print(ans - 1 + dc_sum//9 - 1)
    else:
        print(ans - 1 + dc_sum//9)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    M = int(input())
    ans = 0
    dc_sum = 0
    for i in range(M):
        d, c = (int(i) for i in input().split())
        dc_sum += d*c
        ans += c
    if dc_sum % 9 == 0:
        print(ans - 1 + dc_sum//9 - 1)
    else:
        print(ans - 1 + dc_sum//9)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    M = int(input())
    ans = 0
    dc = [[int(i) for i in input().split()] for _ in range(M)]
    dc_sum = 0
    for i in range(M):
        d = dc[i][0]
        c = dc[i][1]
        dc_sum += d*c
        ans += c
    if dc_sum % 9 == 0:
        print(ans - 1 + dc_sum//9 - 1)
    else:
        print(ans - 1 + dc_sum//9)


if __name__ == '__main__':
    main()

Solution (Python):

M = int(input())
d = 0
c = 0
for _ in range(M):
    c1, d1 = map(int, input().split())
    d += d1
    c += c1 * d1

if c % 9 != 0:
    s = c // 9
else:
    s = c // 9 - 1

print((d - 1) + s)

Solution (Python):
import numpy as np
M=int(input())
D=0
C=0
for i in range(M):
  d,c=map(int,input().split())
  D+=c*d
  C+=c



print((C-1)+(D-1)//9)

Solution (Python):
n = int(input())
d, c = 0, 0

for i in range(n):
    p, q = map(int, input().split())
    d = d + q
    c = c + p*q

print((d-1)+(c-1)//9)

Solution (Python):
m = int(input())
dc = [list(map(int, input().split())) for _ in range(m)]

sm = 0
n = 0
for d, c in dc:
    sm += d * c
    n += c

ans = n - 1 + (sm - 1) // 9
print(ans)

Solution (Python):
M = int(input())
dcs = []
for i in range(M):
  d, c = map(int, input().split())
  dcs.append((d, c))
r = sum([c for d, c in dcs])-1+(sum([d*c for d, c in dcs])-1)//9
print(r)

Solution (Python):
M = int(input())
CD = C = 0
for i in range(M):
  d, c = map(int, input().split())
  CD += c * d
  C += c
print(C - 1 + (CD - 1) // 9)

Solution (Python):
from sys import stdin
M = int(stdin.readline().rstrip())
D = [0]*M
C = [0]*M

for i in range(M):
    D[i],C[i] = [int(x) for x in stdin.readline().rstrip().split()]

N = 0
S = 0

for j in range(M):
    N += C[j]
    S += D[j]*C[j]

print((N-1)+(S-1)//9)

Solution (Python):
n = int(input())
d = [0]*n
c = [0]*n
s = []
digit_sum = 0 
digit_cnt = 0
for i in range(n):
  d[i],c[i] = map(int,input().split())
  digit_sum += d[i]*c[i]
  digit_cnt += c[i]
print((digit_cnt*9+digit_sum-1)//9-1)

Solution (Python):


import sys
import math
import collections

M, = map(int, sys.stdin.readline().rstrip().split(" "))
total_sum = 0
total_digits = 0
for _ in range(M):
    d, c = map(int, sys.stdin.readline().rstrip().split(" "))
    total_digits += c
    total_sum += d*c
answer = ((total_sum-1) // 9) + total_digits -1
print(answer)
exit(0)

Solution (Python):
a=0
m=int(input())
for i in range(m):
    d,c=map(int,input().split())
    a+=c*9+d*c
print((a-10)//9)

Solution (Python):
m, *L = map(int, open(0).read().split())
cnt = -1
s = 0
for d, c in zip(*[iter(L)] * 2):
	s += d * c
	cnt += c
print(cnt + s // 9 - (s % 9==0))

Solution (Python):
def solve() -> '操作回数':
    m = int(input())

    digits = 0
    sum_ = 0
    for _ in range(m):
        d, c = map(int, input().split())
        digits += c
        sum_ += d * c

    return (digits - 1) + (sum_ - 1) // 9
    
    
    
    
    


print(solve())

Solution (Python):
m=int(input())
a,b=0,0
for i in range(m):
    d,c=[int(j) for j in input().split()]
    a+=d*c
    b+=c
print(b-1+(a-1)//9)

Solution (Python):
_,*t=open(0)
a=b=0
for t in t:d,c=map(int,t.split());a+=d*c;b+=c
print(~-a//9+b-1)

Solution (Python):
import math

M = int(input())
ans, sumD = -1, 0
for _ in range(M):
    d, c = map(int, input().split())
    ans += c
    sumD += d * c
print(ans + math.floor((sumD - 1) / 9))

Solution (Python):
import sys

def answer():
    input = sys.stdin.readline
    M = int(input())

    digits = 0
    total = 0

    for i in range(M):
        c, d = map(int, input().split())
        digits += d
        total += d * c

    ans = (digits-1) + (total-1) // 9

    print(ans)


if __name__ == '__main__':
    answer()

Solution (Python):
import sys

def answer():
    input = sys.stdin.readline
    M = int(input())

    Ds = [0] * M
    Cs = [0] * M
    total = 0

    for i in range(M):
        c, d = map(int, input().split())
        Cs[i] = c
        Ds[i] = d
        total += d * c

    digits = sum(Ds)

    ans = (digits-1) + (total-1) // 9

    print(ans)


if __name__ == '__main__':
    answer()

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    M = int(input())
    count = 0
    wa = 0
    for _ in range(M):
        d, c = [int(x) for x in input().split()]
        count += c
        wa += d * c
    
    print(count - 1 + ((wa - 1) // 9))
    



if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: tuple(map(int,input().split()))

M = int(input())
S = 0
ans = -1
for _ in range(M):
    d, c = inpl()
    S += d * c
    ans += c

while S >= 10:
    q, r = S//10, S % 10
    ans += q
    S = q + r
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
m=int(input())
ans=0
S=0
D=0
for i in range(m):
    d,c=map(int,input().split())
    S+=d*c
    D+=c
ans=D-1+(S-1)//9
print(ans)

Solution (Python):
M = int(input())
D = 0
S = 0
for i in range(M):
    c,d = map(int,input().split())
    D += d
    S += c*d
print(D-1+(S-1)//9)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: tuple(map(int,input().split()))
M = int(input())
S = 0
ans = -1
for _ in range(M):
    d, c = inpl()
    S += d * c
    ans += c

while S >= 10:
    c = S % 10
    ans += S//10
    S = S//10 + c
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    m=int(input())
    dc=[list(map(int, input().split())) for _ in range(m)]
    k=s=0
    for d,c in dc:
        k+=c
        s+=d*c
    print((9*k+s-10)//9)

main()

Solution (Python):
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353


def main():
    M = int(input())
    N = 0
    S = 0

    for i in range(M):
        d, c = list(map(int, input().split()))

        if d == 0 and i == 0:
            continue

        S += d * c
        N += c

    print((N - 1) + (S - 1) // 9)


if __name__ == '__main__':
    main()

Solution (Python):


M = int(input())
dc = [list(map(int, input().split())) for _ in range(M)]
 
d = [dc[i][0] for i in range(M)]
c = [dc[i][1] for i in range(M)]
 
ans = sum(c) - 1
s = 0
 
for i in range(M):
    s += c[i] * d[i]
    if s % 9 != 0:
        ans += s // 9
        s = s % 9
    else:
        ans += s//9 - 1 
        s = 9
print(ans)

Solution (Python):
M = int(input())
d = [0] * M
c = [0] * M
for i in range(M):
	d[i], c[i] = map(int, input().split())
D = 0
S = 0
for i in range(M):
	D += c[i]
	S += d[i] * c[i]
print((D - 1) + (S - 1) // 9)

Solution (Python):
m=int(input())
s,k=0,0
for i in range(m):
  d,c=map(int,input().split())
  s+=d*c
  k+=c
print(k-1+(s-1)//9)

Solution (Python):
M = int(input())
ans = 0
hoge = 0
for _ in range(M):
    d,c = map(int,input().split())
    while c:
        if c % 2 == 1:
            hoge += d
            ans += 1
            if hoge > 9:
                hoge = (hoge%10)+1
                ans += 1
        c //= 2
        ans += c
        d = d*2
        if d > 9:
            ans += c
            d = d%10+1

print(ans-1)

Solution (Python):
import sys
read = sys.stdin.read

M = int(input())
dc = map(int, read().split())
dig = [0] * 10
cnt = 0
answer = 0
for d, c in zip(*[iter(dc)] * 2):
    dig[d] += c

trans = dict()
for i in range(10):
    if i < 5:
        trans[i] = i + i
    elif i == 5:
        trans[i] = 1
    else:
        trans[i] = trans[i - 1] + 2

while True:
    tmp = [0] * 10
    for i, x in enumerate(dig):
        q, r = divmod(x, 2)
        if x >= 2:
            if i < 5:
                answer += q
                tmp[trans[i]] += q
                tmp[i] += r
            else:
                answer += q * 2
                tmp[trans[i]] += q
                tmp[i] += r
        else:
            tmp[i] += x

    dig = tmp.copy()
    for i in dig:
        if i > 1:
            break
    else:
        break

last = [i for i in range(10) if dig[i] == 1]
while len(last) > 1:
    a = last.pop()
    b = last.pop()
    c = a + b
    if c >= 10:
        answer += 2
        last.append(c // 10 + c % 10)
    else:
        answer += 1
        last.append(c)

print(answer)

Solution (Python):
m=int(input())
su=0
res=-1
for i in range(m):
    d,c=map(int,input().split())
    su+=d*c
    res+=c
print(res+(su-max(1,su%9))//9)

Solution (Python):
M = int(input())
S = -1
res = -1
for _ in range(M):
    d, c = map(int, input().split())
    res += c
    S += d*c

res += S // 9
print(res)

Solution (Python):
import sys
input=sys.stdin.readline

def main():
    m=int(input())
    DC=[list(map(int,input().split())) for _ in range(m)]
    s=0
    digit=0
    for d,c in DC:
        digit+=c
        s+=d*c
    print(digit-1+(s-1)//9)
    
if __name__=='__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline

m = int(input())
sum1 = 0
sumc = 0
ans = 0

for i in range(m):
    d,c = map(int,input().split())
    sum1 += d * c
    sumc += c

ans += sumc + (sum1 - 1) // 9 - 1

print(ans)

Solution (Python):
M = int(input())
a = 0
csum = 0
for i in range(M):
    d,c = map(int, input().split())
    a += d*c
    csum += c
print((a - 1) // 9 + 1 + csum - 2)

Solution (Python):
m = int(input())
cd = [list(map(int, input().split())) for _ in range(m)]
result = -1
s = 0
for i in range(m):
    result += cd[i][1]
    s += cd[i][0]*cd[i][1]

result += (s-1)//9

print(result)

Solution (Python):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7




M = int(sys.stdin.buffer.readline())
DC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

s = 0
l = 0
for d, c in DC:
    l += c
    s += d * c
ans = (l * 9 + s - 1) // 9 - 1
print(ans)

Solution (Python):

import sys
import collections
import math

def main():
    m = int(sys.stdin.readline().rstrip())

    a = collections.defaultdict(int)
    for _ in range(m):
        d, c = map(int, sys.stdin.readline().split())
        a[d] += c
    

    b = 0
    for i in range(10):
        b += (i + 9) * a[i]
    
    ans = math.ceil((b - 9)/ 9) - 1
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
m = int(input())
dc=[list(map(int, input().split())) for i in range(m)]
b = [[(1,0)]]
f = []
ans = 0
now = 0
for i in range(1,10):
  mini_b = []
  c = i
  d = 0
  c += i
  d += 1
  while (c // 10):
    c = c % 10 + 1
    d += 1
  mini_b.append((d,c))
  while c != i:  
    c += i
    d += 1
    while (c // 10):
      c = c % 10 + 1
      d += 1
    mini_b.append((d,c))
  b.append(mini_b)
for d,c in dc:
  if d:
    if c > 1:
      x,y = divmod(c-1,len(b[d]))
      if y == 0:
        ans +=  b[d][-1][0] * x
        f.append(d)
      else:
        ans +=  b[d][-1][0] * x + b[d][y-1][0]
        f.append(b[d][y-1][1])
    else:
      f.append(d)
  else:
    ans += c-1
    f.append(0)
for i in f:
  now += i
  ans += 1
  while (now//10):
    now = now % 10 + 1
    ans += 1
  
print(ans-1)

Solution (Python):
m = int(input())
count = 0
sum1 = 0
for i in range(m):
    d,c = map(int,input().split())
    sum1 += d*c
    count += c
if (sum1%9 == 0):
    print(sum1//9 - 1 + count - 1)
else:
    print(sum1//9 + count - 1)

Solution (Python):
def main():

    M = int(input())

    ans = 0
    a = 0
    b = 0
    for i in range(M):
        d, c = map(int, input().split())
        a += c
        b += c * d
    v = b + a * 9

    if v % 9 == 0:
        return v // 9 - 2
    else:
        return v // 9 - 1

if __name__ == '__main__':
    print(main())

Solution (Python):
import sys
input = sys.stdin.readline
m=int(input())
DC=[]
for i in range(m):
  DC.append(tuple(map(int,input().split())))
tot=0
for d,c in DC:
  tot+=c*(9+d)
print((tot-1)//9-1)

Solution (Python):

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


ans = 0
M = inp()
zan = []
for m in range(M):
    d,c = inpl()

    while True:
        if c == 1:
            zan.append(d)
            break
        elif c%2 == 0:
            if d == 0:
                ans += c
                break
            elif d <= 4:
                ans += c//2
                d *= 2
                c //= 2
            else:
                ans += c
                d = d*2 - 9
                c //= 2
        else:
            zan.append(d)
            c -= 1

zan.reverse()

bx = zan[0]
for x in zan[1:]:
    d = x + bx
    if d >= 10:
        bx = d - 10 + 1
        ans += 2
    else:
        bx = d
        ans += 1

print(ans)

Solution (Python):




m = int(input())
sm=  0
d = []
c = []
for i in range(m):
    di,ci = map(int, input().split( ))
    d.append(di)
    c.append(ci)
    sm += di*ci

x = sum(c)*9 + sm
y =  x%9
if y==0:
    y = 9
    
print((x-y)//9-1)

Solution (Python):
M = int(input())
dc = [list(map(int,input().split())) for _ in range(M)]
ans = 0
s = 0
for i in dc:
  d = i[0]
  c = i[1]
  ans += c
  s+=d*c
  if s>=10:
    t = (s-1)//9
    ans+=t
    s-= t*9

ans -= 1
print(ans)

Solution (Python):
import math
M = int(input())
dc = [tuple(map(int, input().split())) for i in range(M)]


def func(a, b):
    return((a+b // 10) + (a+b)-10)


num = 0
for i in range(M):
    num += dc[i][1]*9 + dc[i][1]*dc[i][0]

print(math.ceil((num-18) / 9))

Solution (Python):
M = int(input())
dc = [list(map(int,input().split())) for _ in range(M)]
ans = 0
s = 0
for i in dc:
  d = i[0]
  c = i[1]
  ans += c
  s+=d*c

ans -= 1
ans += (s-1)//9
print(ans)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = []


co = 0

c = 0

for i in range(n):
    a,b = m()

    co += a*b

    c += b

c += (co-1)//9

print(c-1)

Solution (Python):
M = int(input())
s = 0
t = 0
for _ in range(M):
    d, c = map(int,input().split())
    s += d * c
    t += c

ans = (s-1)//9 + t-1
print(ans)

Solution (Python):
n=int(input())
ds=0
d=0
for i in range(n):
  d1,c=map(int,input().split())
  ds+=d1*c
  d+=c
print((ds-1)//9+d-1)

Solution (Python):
import sys
read = sys.stdin.read

M = int(input())
dc = map(int, read().split())
dig_sum = 0
dig = 0
for d, c in zip(*[iter(dc)] * 2):
    dig_sum += d * c
    dig += c

answer = (dig_sum - 1) // 9 + dig - 1
print(answer)

Solution (Python):
m=int(input())
d=[0]*m
c=[0]*m
for i in range(m):
  d[i],c[i]=map(int,input().split())
a=0
for i in range(m):
  a=a+d[i]*c[i]
print(sum(c)-1+(a-1)//9)

Solution (Python):
M = int(input())

lis = [0] * 10
able =0

for i in range(M):

    d,c = map(int,input().split())

    lis[d] += c

    able += d * c
    
print ( sum(lis)-1 + (able-1) // 9 )

Solution (Python):
import sys
input = sys.stdin.readline

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

keta = 0
goukei = 0

for i in range(m):
  keta += dc_list[i][1]
  goukei += dc_list[i][0] * dc_list[i][1]


print(keta -1 + (goukei-1) // 9)

Solution (Python):
m = int(input())
L = []
for _ in range(m):
    L.append(list(map(int, input().split())))

short = []
additional = 0
for elm in L:
    additional += (elm[1] - 1)
    total = elm[0] * elm[1]
    if total > 9:
        if total % 9 == 0:
            additional += (total // 9) - 1
        else:
            additional += total // 9
        
    if total > 9:
        if total % 9 == 0:
            res = 9
        else:
            res = total % 9
    else:
        res = total
    short.append(res)

prev = 0
additional += len(short) - 1
for elm in short:
    prev = prev + elm
    if prev > 9:
        prev -= 9
        additional += 1

print(additional)

Solution (Python):
m = int(input())
s = 0
ans = -1
for i in range(m):
  d,c = map(int,input().split())
  s += d*c
  ans += c

print(ans + (s-1)//9)

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    m = int(readline())
    dl = []
    cl = []
    s = 0
    for _ in range(m):
        d, c = list(map(int, readline().split()))
        dl.append(d)
        cl.append(c)
        s += d * c
    cnt = 0
    while True:
        if s >= 10:
            cnt += s // 10
            s = s // 10 + s % 10
        else:
            break
    print(sum(cl) + cnt - 1)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
input = sys.stdin.readline

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

ans = 0
digitsum = 0
digit = 0

for i in range(M):
    digitsum += D[i][0]*D[i][1]
    digit += D[i][1]
print((digitsum-1)//9+digit-1)

Solution (Python):
M = int(input())

res = 0
able =0

for i in range(M):

    d,c = map(int,input().split())

    res += c

    able += d * c
    
print ( res-1 + (able-1) // 9 )

Solution (Python):
m = int(input())
dc =  [list(map(int,input().split())) for _ in range(m)]
flag = 0
ans = -1
x = 0
for i in range(m):
  x += dc[i][0]*dc[i][1]
  ans += dc[i][1]
if x % 9 == 0:
  ans += x//9-1
else:
  ans += x//9
print(ans)

Solution (Python):
n = int(input())
s = 0
cot = 0
for _ in range(n):
    a,b=list( map(int, input().split(" ")))
    s += a* b
    cot += b
cot -= (1 )
cot +=  (s -1)//9
print(cot)

Solution (Python):
M = int(input())
nums = [tuple(map(int, input().split())) for _ in range(M)]
digits = sum(t[1] for t in nums)
d_sum = sum(t[0] * t[1] for t in nums)
ans = digits - 1 + (d_sum - 1) // 9
print(ans)

Solution (Python):
import sys
def input() -> str:
    return sys.stdin.readline()
m = int(input())
n, s = 0, 0
for i in range(m):
  d, c = [int(i) for i in input().split()]
  n += c
  s += d * c
print(n + (s - 1) // 9 - 1)

Solution (Python):
from collections import Counter

mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft

def main():
    m = int(input())
    ans = 0
    a = 0
    for i in range(m):
        d, c = map(int, input().split())
        ans += c
        a += d * c
    print(ans + (a - 1) // 9 - 1)

main()

Solution (Python):
M=int(input())
D,C=zip(*[map(int,input().split()) for i in range(M)])
X=[d*c for d,c in zip(D,C)]
print(sum(C)-1+(sum(X)-1)//9)

Solution (Python):
m = int(input())
c = []
d = []
for i in range(m):
    D,C = map(int,input().split())
    c.append(C)
    d.append(D)

ans = 0
for i in range(m):
    ans += c[i]*d[i]

print((ans-1)//9 + sum(c)-1)

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

m = inn()
cnt = 0
a = []
for i in range(m):
    d,c = inm()
    while c>1:
        if c%2 == 1:
            a.append(d)
            c -= 1
        if d<5:
            d = 2*d
            cnt += c//2
        else:
            d = 2*d-9
            cnt += c
        c //= 2
    a.append(d)

ddprint("cnt {}  a:".format(cnt))
ddprint(a)

x = a.pop()
while len(a)>0 or x>9:
    if x>9:
        x = (x//10)+(x%10)
        cnt += 1
    else:
        y = a.pop()
        x += y
        cnt += 1
print(cnt)

Solution (Python):
import math
import sys
input = sys.stdin.readline
def solve():
  m = int(input())
  digit = 0
  s = 0
  for i in range(m):
    d,c = (int(i) for i in input().split())
    digit += d*c
    s += c
  print((digit-1)//9+s-1)
solve()

Solution (Python):
M = int(input())
DC = [list(map(int, input().split())) for _ in range(M)]

ans = 0
p = 0
for d, c in DC:
    p += d*c
    ans += c

a = (p-1)%9+1
ans += (p-a)//9-1
print(ans)

Solution (Python):
M = int(input())
dc = [list(map(int, input().split())) for _ in range(M)]
 
d = [dc[i][0] for i in range(M)]
c = [dc[i][1] for i in range(M)]
 
ans = sum(c) - 1
s = 0
 
for i in range(M):
    s += c[i] * d[i]
    if s % 9 != 0:
        ans += s // 9
        s = s % 9
    else:
        ans += s//9 - 1 
        s = 9
print(ans)

Solution (Python):
M = int(input())
dcnt = 0
calc = 0
for i in range(M) :
    c,d = map(int,input().split())
    dcnt += d
    calc += d*c
calc -= 1
res = calc//9 + dcnt - 1
print(res)

Solution (Python):
m=int(input())
l=[list(map(int,input().split())) for i in range(m)]
ct=0;sum=0
for i in range(m):
  ct+=l[i][0]*l[i][1]
  sum+=l[i][1]
print(sum-1+((ct-1)//9))

Solution (Python):
N=int(input())
d=[];c=[]
for i in range(N):
    di,ci=map(int,input().split())
    d.append(di);c.append(ci)


s=sum([d[i]*c[i] for i in range(N)])

t=0
while s>=10:
    t+=s//10
    s=s//10+s%10

ans=sum(c)-1+t
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
cha=[0,2,4,6,8,1,3,5,7,9]
m=int(input())
ans=0
l=[]
for _ in range(m):
    d,c=map(int,input().split())
    while c>1:
        if c%2:
            c-=1
            l.append(d)
        c//=2
        ans+=c if d<5 else c*2
        d=cha[d]
    l.append(d)

k=len(l)
while k>1:
    a=l.pop()
    b=l.pop()
    x=a+b
    ans+=1
    if x>9:
        s=str(x)
        l.append(int(s[0]))
        l.append(int(s[1]))
    else:
        l.append(x)
        k-=1
print(ans)

Solution (Python):
m=int(input())
d,c=[],[]
ans=-1
for i in range(m):
  dd,cc=map(int,input().split())
  d.append(dd)
  c.append(cc)
  ans+=cc
a=0
for i in range(m):
  a+=d[i]*c[i]
  dd=(a-1)//9
  ans+=dd
  a-=dd*9
print(ans)

Solution (Python):
def main():
    
    ''' Cook your dish here! '''
    m = get_int()
    sm = 0
    smc = 0
    for _ in range(m):
        a, b = get_list()
        sm += a*b
        smc += b
    print(smc-1 + ((sm-1)//9))

''' Coded with love at India by Satyam Kumar '''
import sys

import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()

print(*out, sep='\n')

Solution (Python):
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

m = ri()
ls = rils(m)
res = -1
s = 0
for d, c in ls:
    res += c
    s += d * c
res += (s - 1) // 9
print(res)

Solution (Python):
M = int(input())
keta = 0
count_sum = 0
for _ in range(M):
    d,c= map(int,input().split(' '))
    keta += c
    count_sum += d*c
additional = count_sum//10
if 9 < count_sum:
    print(keta-1 + (count_sum-1)//9)
else:
    print(keta-1)