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):
m=int(input())
d=c=-1
for _ in range(m):
  dd,cc=map(int,input().split())
  d+=dd*cc
  c+=cc
print(c+d//9)

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

d = sum(c for _, c in X)
s = sum(d * c for d, c in X)
print(d - 1 + (s - 1) // 9)

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

Solution (Python):
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

def main():
    d = 0
    s = 0
    for _ in range(int(input())):
        a, b = map(int, input().split())
        s += a * b
        d += b
    print(d - 1 + (s - 1) // 9)

main()

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

Solution (Python):
def main():
    M=int(input())
    DC=[list(map(int,input().split())) for _ in range(M)]
    D=sum([c for d,c in DC])
    S=sum([d*c for d,c in DC])
    print((D-1)+(S-1)//9)

main()

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

Solution (Python):
digit = 0
s = 0

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

x = digit - 1
y = s // 9 - (s % 9 == 0)
print(x + y)

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

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

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

s=sum(c[i]*d[i] for i in range(0,M))
digit=sum(c)
if s%9==0:
    print(digit-1+s//9-1)
else:
    print(digit-1+s//9)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    m = I()
    s,d = 0,0
    for i in range(m):
        a,b = LI()
        s += b
        d += a*b
    print(s-1+(d-1)//9)
    return


if __name__ == "__main__":
    solve()

Solution (Python):

import sys
import math
import string
import collections
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = 10 ** 18
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

M = int(input())
d = [0] * M
c = [0] * M
for i in range(M):
    d[i], c[i] = map(int, input().split())  
SUM = 0
for i in range(M):
    SUM += d[i] * c[i]
times = math.ceil(SUM / 9) - 1
print(sum(c) + times - 1)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    M = int(input())  

    d_sum, c_sum = 0, 0
    for _ in range(M):
        d_, c_ = map(int, input().split())
        d_sum += d_ * c_
        c_sum += c_

    ret = ((d_sum - 9 + 8) // 9) + (c_sum - 1)
    print(ret)


if __name__ == '__main__':
    main()

Solution (Python):
m = int(input())
D = 0
S = 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):
import sys
input = sys.stdin.readline

m = int(input())

sum_n = 0
len_n = 0
for i in range(m):
    d,c = map(int, input().split())
    sum_n += d*c
    len_n += c

ans = len_n-1 + (sum_n-1)//9
print(ans)

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

Solution (Python):
'''
https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_d
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    

    
    

    m = int(input())
    res, total = 0, 0

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

if __name__ == '__main__':
    main()

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

Solution (Python):

import sys
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    M = INT()

    SUM = 0
    keta = 0
    for _ in range(M):
        d,c = MAP()
        SUM += c*d
        keta += c
    
    print(keta-1+(SUM-1)//9)
    return

if __name__ == '__main__':
    main()

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


x = sum([C[i] * D[i] for i in range(m)])
ans = sum(C) - 1 + (x - 1) // 9
print(ans)

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

Solution (Python):
import sys
input = sys.stdin.readline
m = int(input())
ans = 0
sum_num = 0
c_sum = 0
for i in range(m):
    d,c = map(int, input().split())
    sum_num += d*c
    c_sum += c

print(c_sum-1 + ((sum_num-1)//9))

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

ds = [list(map(int,input().split(" "))) for _ in range(M)]
ans = 0
s = 0
for d,c in ds:
    ans += c
    s += d * c
ans -= 1
ans += math.ceil((s - 9)/9)
print(ans)

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

def main():
    N = int(input())
    s,keta = 0,0
    for _ in range(N):
        a,b = map(int,input().split())
        s += a*b
        keta += b
        
    print((s-1)//9+keta-1)
        
if __name__ == "__main__":
    main()

Solution (Python):
def solve():
    M = int(input())
    d, c = [0] * M, [0] * M
    for i in range(M):
        d[i], c[i] = map(int, input().split())
    
    sum_d = 0
    for i in range(M):
        sum_d += d[i] * c[i]
    sum_c = sum(c)
    ans = (sum_c - 1) + (sum_d - 1) // 9
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
m = int(input())
d, s = 0, 0
for _ in range(m):
  a, b = map(int, input().split())
  s += a*b
  d += b
print(d-1 + (s-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 = 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())
a=0
b=0
for i in range(m):
  d,c=map(int,input().split())
  a=a+d*c
  b=b+c
print((a-1)//9+b-1)

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

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

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

Solution (Python):
m = int(input())
CD = [list(map(int, input().split())) for _ in range(m)]
count = 0
tmp = -1
total = 0
for c, d in CD:
  q, m = divmod(tmp + c * d, 9)
  count += q
  tmp = m
  total += d
print(total - 1 + count)

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

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

Solution (Python):
import sys

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

Solution (Python):
m = int(input())
csum = 0
dsum = 0
for i in range(m):
  c = [int(x) for x in input().split()]
  csum += c[1]
  dsum += c[0]*c[1]
print(csum-1 + (dsum-1) // 9)

Solution (Python):
m = int(input())
csum = 0
dsum = 0
for i in range(m):
  c = [int(x) for x in input().split()]
  csum += c[1]
  dsum += c[0]*c[1]
print(csum-1 + (dsum-1) // 9)

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

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

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

from collections import deque

q = deque()

def calc(d, c):
    if c&1:
        q.append(d)
    if c == 1:
        return 0
    d *= 2
    c>>=1
    if d >= 10:
        return c * 2 + calc(1+d%10, c)
    return c + calc(d, c)
    

def main():
    M = int(input())
    ans = 0
    for i in range(M):
        d, c = map(int, input().split())
        ans += calc(d, c)
    
    num = q.popleft()
    while len(q) > 0:
        t = q.popleft()
        num += t
        if num >= 10:
            num = 1 + num%10
            ans += 1
        ans += 1
    
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
def g(i,j):
    if i+j<10:
        return 1,i+j
    else:
        a = i+j
        b = a%10+a//10
        return 2,b
def f(c,d):
    if d==1:
        return 0,c
    if d==2:
        return g(c,c)
    if d%2==0:
        a,b = f(c,d//2)
        x,y = g(b,b)
        return 2*a+x,y
    else:
        a,b = f(c,(d-1)//2)
        x1,y1 = g(b,b)
        x2,y2 = g(c,y1)
        return 2*a+x1+x2,y2
M = int(input())
A = [list(map(int,input().split())) for _ in range(M)]
cnt = 0
B = []
for i in range(M):
    c,d = A[i][0],A[i][1]
    a,b = f(c,d)
    cnt += a
    B.append(b)
b = B[0]
for i in range(1,M):
    a,b = g(b,B[i])
    cnt += a
print(cnt)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    m = I()
    aa = [LI() for _ in range(m)]
    r = 0
    cc = collections.defaultdict(int)
    for d,c in aa:
        cc[d] += c
    f = True
    r = 0
    v = []
    for i in range(10):
        s = str(i * 2)
        t = []
        for c in s:
            t.append(int(c))
        v.append(t)

    r = 0
    while f:
        f = False
        for i in range(1,10):
            t = cc[i]
            if t > 1:
                cc[i] = t % 2
                r += t // 2
                for c in v[i]:
                    cc[c] += t // 2
                f = True
    a = []
    for i,c in cc.items():
        if i == 0:
            r += c
        elif c > 0:
            a.append(i)

    t = a[0]
    for c in a[1:]:
        r += 1
        t += c
        while t > 9:
            r += 1
            t = t//10 + t%10

    return r


print(main())

Solution (Python):
import sys
from collections import deque

def q(d, 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()

Solution (Python):
M=int(input())
dig=0
sum=0

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

Solution (Python):
M = int(input())
D = 0
S = 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):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10


def solve():
    m = II()
    Digit = 0
    Sum = 0
    for _ in range(m):
        d, c = LI()
        Digit += c
        Sum += d * c
    print(Digit + (Sum - 1) // 9 - 1)
    return



if __name__ == '__main__':
    solve()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    m = I()
    d,c = 0,0
    for i in range(m):
        a,b = LI()
        d += a*b
        c += b
    print(c-1+(d-1)//9)
    return


if __name__ == "__main__":
    solve()

Solution (Python):
def main():
    m=int(input())
    dc=[list(map(int,input().split())) for _ in [0]*m]
    sum_n=sum([d*c for d,c in dc])
    sum_c=sum([c for d,c in dc])
    print((sum_n-1)//9+sum_c-1)
main()

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



M = I()
d,c = Line(M,2)

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

print(D-1+math.floor((S-1)/9))

Solution (Python):
N = int(input())
s = 0
d = 0
for i in range(N):
    tmp_d, tmp_c = map(int, input().split())
    d += tmp_c
    s += tmp_d * tmp_c
ans = d - 1 + int((s - 1) / 9)
print(ans)

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

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

d_sum = 0
c_sum = 0

for i in range(M):
  d, c = [int(_) for _ in input().split()]
  d_sum += d * c
  c_sum += c

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

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

Solution (Python):
m = int(input())
tot = 0
ans = 0
for i in range(m):
    x, y = map(int, input().split())
    tot += x * y
    ans += y
while tot >= 10:
    ans += tot // 10
    tot = tot // 10 + tot % 10
print(ans - 1)

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub
from pprint import pprint

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, CD):
    S = sum(map(lambda x: x[0] * x[1], CD))
    D = sum(map(lambda x: x[1], CD))
    return D - 1 + (S-1) // 9


def main():
    N = read_int()
    CD = [read_int_n() for _ in range(N)]
    print(slv(N, CD))

    
    
    
    
    


if __name__ == '__main__':
    main()

Solution (Python):
M = int(raw_input())
d = [0] * M
c = [0] * M 
for i in range(M):
    d[i], c[i] = map(int, raw_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())
d=[]
c=[]
z=0
for i in range(m):
    a,b=map(int,input().split())
    d.append(a)
    c.append(b)
    z+=a*b
ans=0
print(sum(c)-1+(z-1)//9)
exit()
def ika(x,y):
    ret=0
    z=x*y
    ret+=y-1
    while z>9:
        s=list(str(z))
        ret+=len(s)-1
        i5=0
        for i in range(len(s)):
            s[i]=int(s[i])
        g=0
        while g<len(s)-1:
            if s[g]+s[g+1]>=10:
                
                g+=2
            else:
                g+=1
        z=sum(s)
        ret+=(z-10)//10
    return [ret,z]
ka=[]
for i in range(m):
    f=ika(d[i],c[i])
    ans+=f[0]
    ka.append(f[1])
print(ans+ika(sum(ka),1)[0]+len(ka)-1)

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

num=''
D,C=[],[]
for _ in range(M):
    D1,C1=map(int, input().split())
    D.append(D1)
    C.append(C1)
S = sum(d * c for d, c in zip(D, C))
print (sum(C)-1+(S-1)//9)

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

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

Solution (Python):
M = int(input())
total = 0
count = 0
for i in range(M):
	a, b = map(int, input().split())
	total += a * b
	count += b
print(count-1+(int((total-1)/9)))

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

Solution (Python):
N=int(input())
K=0
S=0
for i in range(N):
    a,b=map(int,input().split())
    S+=a*b
    K+=b
if S%9==0:
    print(K-2+S//9)
else:
    print(K-1+S//9)

Solution (Python):

import sys
input = sys.stdin.readline

n = int(input())
ans = 0
summation = 0
for i in range(n):
    d, c = [int(item) for item in input().split()]
    ans += c
    summation += d * c
print(ans - 1 + summation // 9 - (summation % 9 == 0))

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    m = int(readline())
    t = 0
    cnt = 0
    for i in range(m):
        d, c = list(map(int, readline().split()))
        t += d * c
        cnt += c
    print(cnt - 1 + (t - 1) // 9)


if __name__ == '__main__':
    solve()

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):
M = int(input())
digit_num, digit_sum = 0, 0
for i in range(M):
    d, c = map(int, input().split())
    digit_num += c
    digit_sum += d * c

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

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

Solution (Python):
M, *DC = map(int, open(0).read().split())

D, C = DC[::2], DC[1::2]
S = sum(d * c for d, c in zip(D, C))

print(sum(C) - 1 + (S - 1) // 9)

Solution (Python):
I = [int(_) for _ in open(0).read().split()]
M = I[0]
D, C = I[1::2], I[2::2]
n = digit = 0
for d, c in zip(D, C):
    n += d * c
    digit += c
print((digit * 9 + n - 10) // 9)

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)


sm = A[0]
for a in A[1:]:
    sm += a
    ans += 1
    if sm >= 10:
        sm = int(str(sm)[0]) + int(str(sm)[1])
        ans += 1
print(ans)

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

Solution (Python):
from sys import stdin

input = stdin.readline

m = int(input())
dc = []
for _ in range(m):
    d, c = map(int,input().split())
    dc.append((d, c))

def cal(d, c):
    if c == 1:
        return [0, d]
    t = 1 + (d + d >= 10)
    a = (d + d >= 10) + (d + d) % 10

    ca = cal(a, c // 2)

    if c % 2:
        return [(c // 2) * t + ca[0] + 1 + (ca[1] + d >= 10), (ca[1] + d >= 10) + (ca[1] + d) % 10]
    else:
        return [(c // 2) * t + ca[0], ca[1]]


ans = 0
now = []
for d, c in dc:
    ca = cal(d, c)
    ans += ca[0]
    now.append(ca[1])

pre = 0
for i in now:
    pre = pre + i
    ans += 1
    if pre >= 10:
        ans += 1
        pre = pre % 10 + 1

print(ans - 1)

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

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)