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
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    M = I()
    L = [LI() for i in range(M)]
    L = L[::-1]
    temp = 0
    ans = 0
    for a, b in L:
        temp += a*b
        ans += b
        while temp >= 10:
            temp2 = temp // 10
            ans += temp2
            temp = (temp % 10) + temp2

    print(ans-1)
    
if __name__ == "__main__":
    main()

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

M = int(input())
dcs = map(int, read().split())

digit_sum = 0
digit_count = 0

for d, c in zip(dcs, dcs):
    digit_sum += d * c
    digit_count += c

print((digit_sum - 1) // 9 + digit_count - 1)

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

main()

Solution (Python):
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def f(S, res, d, c):
    if c == 0:
        return S, res
    
    if c % 2 == 1:
        S += d
        res += 1
        if S >= 10:
            S -= 9
            res += 1
        
    t = d * 2
    res += c // 2
    if t >= 10:
        t -= 9
        res += c // 2
    return f(S, res, t, c // 2)


def main():
    M = int(input())
    S = 0
    res = -1
    for _ in range(M):
        d, c = read_values()
        S, res = f(S, res, d, c)
    
    print(res)


if __name__ == "__main__":
    main()

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

dnum =0
dsum =0

for i in range(n):
  d,c=map(int,input().split())
  dnum += c
  dsum += d*c
  
ans = dnum-1 + (dsum-1)//9

print(ans)

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

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

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

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

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


M = I()
digit = 0  
digit_sum = 0  
for i in range(M):
    d,c = MI()
    digit += c
    digit_sum += d*c

print(digit+(digit_sum-1)//9-1)

Solution (Python):
def main():
    M = int(input())
    n, s = 0, 0
    for _ in range(M):
        d, c = list(map(int, input().split()))
        n += c
        s += d * c
    
    print((9 * n + s - 10) // 9)


if __name__ == '__main__':
    main()

Solution (Python):
def steps(c, s):
    
    q, r = divmod(s, 9)
    if r != 0:
        cnt = (c-1) + q
    else:
        cnt = (c-1) + q-1
        r = 9
    return cnt, r

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

ans, r = steps(tot_c, tot_s)
print(ans)

Solution (Python):
def steps(c, s):
    
    q, r = divmod(s, 9)
    if r != 0:
        cnt = (c-1) + q
    else:
        cnt = (c-1) + q-1
        r = 9
    return cnt, r

m = int(input())
r0 = 0; ans = 0   
for _ in range(m):
    d, c = map(int, input().split())
    cnt, r = steps(c, d*c)
    ans += cnt
    cnt, r0 = steps(2, r0+r)
    ans += cnt
print(ans-1)

Solution (Python):
mat = [[[0, 0]]*10 for _ in range(10)]
def dsr(i):
    x, cnt = 0, 0
    for j in range(10):
        w = x + i
        if w > 9:
            x = w - 9
            cnt += 2
        else:
            x = w
            cnt += 1
        mat[i][j] = [x, cnt-1]
    
    x0 = mat[i][9][1] - mat[i][8][1]   
    for j in range(10):
        mat[i][j][1] += x0 

for i in range(10):
    dsr(i)


m = int(input())
cnt = 0; x0 = 0   
for _ in range(m):
    d, c = map(int, input().split())
    q, r = divmod(c-1, 9)
    cnt += mat[d][8][1]*q + mat[d][r][1] - mat[d][0][1] 
    x = mat[d][r][0]
    
    w = x0 + x
    if w > 9:
        x0 = w - 9
        cnt += 2
    else:
        x0 = w
        cnt += 1
    
print(cnt-1)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    m = int(input())
    DC = [list(map(int, input().split())) for _ in range(m)]
    total = 0
    res = 0
    for d, c in DC:
        r = c * d
        res += c
        while r // 10:
            q, r = divmod(r, 10)
            res += q
            r += q
        total += r

    while total // 10:
        q, total = divmod(total, 10)
        res += q
        total += q

    print(res - 1)


if __name__ == '__main__':
    resolve()

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7





M = getN()

que = [getList() for i in range(M)]







cnt = 0
left = 0
for d, c in que:
    cnt += c
    left += d * c

while left >= 10:
    t = left // 10
    cnt += t
    left %= 10
    left += t
print(cnt - 1)

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

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

ans = -1

s = 0

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

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

Solution (Python):
m = int(input())
s = ""
S = 0
C = 0

"""
各桁をa,bとすると
(1)a+b < 10 
(2)a+b >= 10
で場合分け
1234567890 -> 桁がn, 総和がs
(1)の操作 : n-1, s
(2)の操作 : n, s-9
POINT (1),(2) 両方の操作でも、9n+sの値が9ずつ減っていく
"""

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

n = S
while n >= 10:
    cnt = 0
    for s in str(n):
        cnt += int(s)
    n = cnt

begin = S + 9*C
end = n + 9
print((begin-end-1)//9 + 1)

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

D,S=0,0
for d,c in DC:
    D +=c
    S +=d*c
print(D-1+(S-1)//9)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7

    m=I()
    ans=-1
    sm=0
    for i in range(m):
        d,c=MI()
        ans+=c
        sm+=d*c
    while sm>=10:
        ans+=sm//10
        sm=sm%10+sm//10
    
    print(ans)
    
        
                
                
    
        
        
        
        




if __name__=="__main__":
    main()

Solution (Python):
import sys

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


def main():
    from collections import Counter
    M = int(readline())
    C = Counter()

    for _ in range(M):
        d, c = map(int, readline().split())
        C[d] += c
    ans = 0
    ans += C[0]
    s = ""
    for i in range(1, 10):
        p = str(i) * 10 + "*"
        cnt = 0
        while len(p) > 2:
            p = str(int(p[0]) + int(p[1])) + p[2:]
            cnt += 1

        while C[i] >= 10:
            k = C[i] // 10
            C[i] = C[i] % 10 + k
            ans += k * cnt
        s += str(i) * C[i]

    s += "*"
    while len(s) > 2:
        s = str(int(s[0]) + int(s[1])) + s[2:]
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
M = int(input())
d, c = zip(*[[int(x) for x in input().split()] for _ in range(M)])
n_digits = sum(c) 
sum_digits = sum(d[i] * c[i] for i in range(M))
ans = n_digits - 1 + (sum_digits - 1) // 9
print(ans)

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

Solution (Python):

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


print(result1+result2)

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

Solution (Python):
m = int(input())
DC = [tuple(int(x) for x in input().split()) for _ in range(m)]
ans = sum(c for _, c in DC) - 1
S = sum(d * c for d, c in DC)
ans += (S - 1) // 9
print(ans)

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

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


print(n_digit-1+(n_sum-1)//9)

Solution (Python):
M = int(input())
D = 0
S = 0

for _ in range(M):
    d, c = map(int,input().split())
    D += c
    S += c * d

ans = D - 1 + (S - 1) // 9

print(ans)

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

Solution (Python):
def main():
    m = int(input())
    arr = [list(map(int, input().split())) for _ in range(m)]
    ans = 0
    sm = 0
    tmp = 0
    for i in range(m):
        sm += arr[i][0] * arr[i][1]
        tmp += arr[i][1]
    ans += tmp-1
    ans += (sm-1)//9
    print(ans)


if __name__ == "__main__":
    main()

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

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

ans += kaisu
print(ans)

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

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


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

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


m = int(input())
s = 0
l = 0
for i in range(m):
    d,c = map(int, input().split())
    s += c*d
    l += c
val = s + 9*l
ans = (val-18)//9 + int((val-18)%9!=0)
print(ans)

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

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

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

Solution (Python):
m=int(input())
n=0
ans=0
for i in range(m):
  x,y=map(int,input().split())
  n+=y
  ans+=x*y
n-=1
ans-=1
n+=ans//9
print(n)

Solution (Python):







import sys
input = sys.stdin.readline

M = int(input())
s, n = 0, 0

for _ in range(M):
    d, c = map(int, input().split())
    s += d*c
    n += c
    
print(n-1+(s-1)//9)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
m = int(readline())
ans = 0
chk = -1
for i in range(m):
  d,c = map(int,readline().split())
  ans += c
  chk += d*c
  if chk > 8:
    ans += chk//9
    chk %= 9
print(ans-1)

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

cur = 0

keta = 0
csum = 0
for _ in range(M):
  d,c = map(int,input().split())
  s = 0
  for i in str(d):
    s += int(i)
  csum += s * c
  keta += c


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

Solution (Python):
m = int(input())
digit = 0
total = 0
for i in range(m):
    d,c = map(int,input().split())
    total += d*c
    digit += c

moveup = (total-1)//9

print(digit + moveup - 1)

Solution (Python):
M = int(input())
Keta=0
Sum=0

for _ in range(M):
    d,c = map(int,input().split())
    Keta+=c
    Sum+=d*c
print(Keta-1 + (Sum-1)//9)

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

Solution (Python):
n = int(input())
d, d_sum = 0, 0
for _ in range(n):
    a, b = map(int, input().split())
    d += b
    d_sum += a * b

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

Solution (Python):


import sys
input=sys.stdin.readline

def main():
    M=int(input())
    dc=[tuple(map(int,input().split())) for i in range(M)]
    ans=0
    n=0
    for i in range(M):
        n+=dc[i][0]*dc[i][1]
        ans+=dc[i][1]
    ans-=1
    def aint(x):
        ret=0
        cnt=0
        while(x>0):
            cnt+=1
            ret+=x//10
            x//=10
        cnt-=1
        return int(ret)-cnt
            
    if n>=10:
        ans+=aint(n)
        

    while(n>=10):
        ns=str(n)
        n=0
        for i in range(10):
            c=ns.count(chr(i+ord("0")))
            n+=i*c
        ans+=len(ns)-1
        if n>=10:
            ans+=aint(n)
    print(ans)
        
    
    
    
if __name__=="__main__":
    main()

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

digit = 0
sum = 0

for _ in range(M):
    d, c = map(int, input().split())
    digit += c
    sum += d * c

print(digit - (-(sum - 9) // 9) - 1)

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):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    M = int(input())
    
    
    sumc = 0
    sumd = 0
    for i in range(M):
        td, tc = map(int, input().split())
        
        
        sumc += tc
        sumd += td*tc
    
    
    
    
    
    print(sumc-1+(sumd-1)//9)

if __name__ == "__main__":
    main()

Solution (Python):
import sys

read = sys.stdin.buffer.read


def main():
    M, *DC = map(int, read().split())

    total = digits = 0
    for d, c in zip(DC[::2], DC[1::2]):
        total += d * c
        digits += c

    print(digits - 1 + (total - 1) // 9)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    M, *DC = map(int, read().split())

    total = digits = 0
    for d, c in zip(DC[::2], DC[1::2]):
        total += d * c
        digits += c

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    M, *DC = map(int, read().split())

    total = digits = 0
    for d, c in zip(DC[::2], DC[1::2]):
        total += d * c
        digits += c

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

M = int(input())
dc = [list(mapint()) for _ in range(M)]
ans = 0
nowd = 0
for m in range(M):
    d, c = dc[m]
    s = nowd + d*c
    ans += c+s//10
    nowd = s%10+s//10
    while nowd>=10:
        ans += nowd//10
        nowd = nowd%10+nowd//10
print(ans-1)

Solution (Python):
n=int(input())
import sys
d=0
now=0
input=sys.stdin.readline
for i in range(n):
  a,b=map(int,input().split())
  now+=a*b
  d+=b
print((now-1)//9+d-1)

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

m = int(input())
total = 0
ans = 0
for _ in range(m):
    d, c = map(int, input().split())
    total += d*c
    ans -= (d - 1)*c
while total > 9:
    temp = total%10
    total -= temp
    ans += total//10 * 10
    total = total//10 + temp
ans += total - 1
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())

print(sum(c)-1+(sum([c[i]*d[i] for i in range(m)])-1)//9)

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

Solution (Python):



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

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

def main():
    m = int(input())
    a = [list(map(int, input().split())) for _ in range(m)]
    wa = 0
    length = 0
    for i,j in a:
        wa += i*j
        length += j
    
    print(length-1+(wa-1)//9)
    
    
if __name__=="__main__":
    main()

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

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

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





def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))





def main():
	m=II()
	di=0
	su=0
	for _ in range(m):
		d,c=MI()
		di+=c
		su+=d*c

	print((su-1)//9+di-1)

if __name__ == "__main__":
	main()

Solution (Python):
m,*dc = map(int,open(0).read().split())
d = dc[::2]
c = dc[1::2]

dc_sum = sum(di*ci for di,ci in zip(d,c))
c_sum = sum(c)

ans = c_sum -1 + (dc_sum-1)//9
print(ans)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    M, *DC = map(int, read().split())
    D = DC[::2]
    C = DC[1::2]

    total = sum(d * c for d, c in zip(D, C))
    ans = sum(C) - 1 + (total - 1) // 9
    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    M, *DC = map(int, read().split())
    total = sum(d * c for d, c in zip(DC[::2], DC[1::2]))
    ans = sum(DC[1::2]) - 1 + (total - 1) // 9
    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    M, *DC = map(int, read().split())
    D = DC[::2]
    C = DC[1::2]

    total = sum(d * c for d, c in zip(D, C))
    ans = sum(C) - 1 + (total - 1) // 9
    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    M, *DC = map(int, read().split())
    D = DC[::2]
    C = DC[1::2]

    total = sum(d * c for d, c in zip(D, C))
    q, r = divmod(total, 9)
    ans = sum(C) - 1 + q - (r == 0)
    print(ans)
    return


if __name__ == '__main__':
    main()

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


def solve():
    M = int(input())
    ans, s = 0, 0

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

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

solve()

Solution (Python):
M = int(input())
ans, s = 0, 0

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

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

Solution (Python):
M = int(input())
ans, s = 0, 0

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

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

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

c1 = []
for _ in range(M):
    d, c = map(int, input().split())
    v1 = ((d*c)//9)-((d*c)%9==0 and d*c>0)
    v2 = c-1
    ans += v1+v2
    c1.append(d*c-9*v1)

ans += M-1
s = sum(c1)
ans += (s//9)-(s%9==0 and s>0)
print(ans)

Solution (Python):
import sys

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


m = readint()

a = 0
b = 0

for i in range(m):
    d,c = readints()
    a+=c
    b+=c*d

print(a-1+(b-1)//9)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    M = I()
    dc = [LI() for _ in range(M)]

    s = sum([i[0]*i[1] for i in dc])
    print((sum([i[1] for i in dc])-1)+(s-1)//9)

if __name__ == '__main__':
    resolve()

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

if now==0:
    ans-=1

print(ans)

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

D,S=0,0
for d,c in DC:
    D +=c
    S +=d*c
print(D-1+(S-1)//9)

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

Solution (Python):
N = int(input())
digit = 0
d_sum = 0
for i in range(N):
    x,y = map(int, input().split())
    digit += y
    d_sum += x*y
print(digit-1+(d_sum-1)//9)

Solution (Python):
icase=0
if icase==0:
    m=int(input())
    dc=[[0]*2 for i in range(m)]
    for i in range(m):
        dc[i]=list(map(int,input().split()))
elif icase==1:
    m=1
    dc=[[5,2]]

    
dsum=0
csum=0
for i in range(m):
    dsum+=dc[i][0]*dc[i][1]
    csum+=dc[i][1]

ans=(dsum-1)//9+csum-1

print(ans)

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

s = 0
dig = 0
for i in range(M):
    d, c = map(int, input().split())
    s += d * c
    dig += c

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

Solution (Python):

import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline

def resolve():
    N = int(inp())

    S = 0
    D = 0
    for i in range(N):
        d, c = map(int, inp().split())
        S += d*c
        D += c

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

if __name__ == "__main__":
    resolve()

Solution (Python):

def resolve():
    N = int(input())

    S = 0
    D = 0
    for i in range(N):
        d, c = map(int, input().split())
        S += d*c
        D += c

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

if __name__ == "__main__":
    resolve()

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

def main():
    M,*cd = map(int, read().split())

    D = 0
    S = 0
    for d, c in zip(*[iter(cd)]*2):
        D += c
        S += c * d
    
    ans = (D - 1) + (S - 1) // 9
    print(ans)


if __name__ == "__main__":
    main()

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())
tmp, ans = 0, 0
for i in range(M):
    d, c = map(int, input().split())
    tmp += d * c
    ans += c
    
print(ans-1 + (tmp-1) // 9)

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

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

print(k - 1 - (-(s - 9) // 9))

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

sm=0
cnt=0
for tmp in dc:
    d,c=tmp
    cnt+=c
    sm+=d*c
print(cnt-1 + (sm-1)//9)

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

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

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

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

Solution (Python):
m = int(input())
a = 0
b = 0
for _ in range(m):
    d, c = [int(i) for i in input().split()]
    a += c
    b += d * c

print(a - 1 + (b - 1) // 9)

Solution (Python):
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

M = int(input())
Dsum = 0
digit = 0

for _ in range(M):
    d, c = map(int, input().split())
    Dsum += d * c
    digit += c

ans = digit - 1
div, mod = divmod(Dsum, 9)
if mod:
    ans += div
else:
    ans += div - 1

print(ans)

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    M=int(input())
    DC=[tuple(map(int, input().split())) for _ in range(M)]
    Dsum=sum(d*c for d,c in DC)
    Csum=sum(c for d,c in DC)
    print(Csum-1 + (Dsum-1)//9)

if __name__ == '__main__':
    main()

Solution (Python):


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    M=I()
    dig=0
    S=0
    for i in range(M):
        d,c=MI()
        dig+=c
        S+=d*c

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

main()

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

D = 0
C = 0
for d, c in DC:
    D += d * c
    C += c

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

Solution (Python):
def solve():
    m = int(input())
    s = 0
    d = 0
    for _ in range(m):
        a,b = map(int,input().split())
        d+=b
        s+=a*b
    print((s-1)//9 + d-1)
if __name__=='__main__':
    solve()

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

sumd = sumc = 0
for d,c in DC:
    sumd += d*c
    sumc += c

ans = sumc-1 + (sumd-1)//9
print(ans)

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

M = int(readline())
DC = list(tuple(map(int, readline().split())) for _ in range(M))
res = sum(c*d for c, d in DC)
Z = sum(c for _, c in DC)
print((Z-1)+(res-1)//9)