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 itertools
import os
import sys

from functools import lru_cache

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


def test(n):
    round = {str(n)}
    ret = 0
    while round:
        next_round = set()
        for n in round:
            for i in range(len(n) - 1):
                s = n[:i] + str(int(n[i]) + int(n[i + 1])) + n[i + 2:]
                if len(s) > 1:
                    next_round.add(s)
        round = next_round
        print(round)
        ret += 1
    print('test:', ret)
    print()


@lru_cache(maxsize=None)
def solve(n):
    n = str(n)
    if len(n) == 1:
        return 0, int(n)
    num = 0
    ret = 0
    for c in str(n):
        ret += 1
        num += int(c)
        while num >= 10:
            ret += 1
            num = num % 10 + 1
    return ret - 1, num

























memo = [[None] * 11 for _ in range(10)]
for i, j in itertools.product(range(10), range(11)):
    memo[i][j] = solve(str(i) * j)


def kurikaesi(d, c):
    if c < 10:
        return memo[d][c]
    cnt, n1 = memo[d][10]
    ret = cnt * (c // 10)
    c2, n2 = kurikaesi(n1, c // 10)
    c3, n3 = memo[d][c % 10]
    ret += c2
    ret += c3
    c4, n4 = solve(str(n2) + str(n3))
    ret += c4
    return ret, n4









ans = 0
num = 0
for d, c in DC:
    cnt, n = kurikaesi(d, c)
    ans += cnt
    c2, n2 = solve(str(num) + str(n))
    ans += c2
    num = n2
print(ans - 1)

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

for d, c in DC:
    s += d * c
    ans += c

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
m=int(input())
dc=[list(map(int,input().split())) for i in range(m)]
tmp=0
ans=0
for i in range(m):
    tmp+=dc[i][0]*dc[i][1]
    ans+=dc[i][1]

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

Solution (Python):
M = int(input())
dc = [[int(i) for i in input().split()] for _ in range(M)]

ret = 0
s = 0
for d, c in dc :
    s += d * c
    t = s // 10
    ret += t
    s %= 10
    s += t
    
while s >= 10 :
    t = s // 10
    ret += t
    s %= 10
    s += t

for d, c in dc :
    ret += c
        
print(ret - 1)

Solution (Python):
import sys
import math

M=int(input())
ans=0
a=[list(map(int,input().split())) for i in range(M)]
b=[0 for i in range(M)]

for i in range(M):
    ans+=a[i][1]-1
    b[i]=a[i][0]*a[i][1]
    while b[i]>=10:
        ans+=b[i]//10
        b[i]=b[i]//10+b[i]%10


ans+=M-1
x=sum(b)
while x>=10:
    ans+=x//10
    x=x//10+x%10
print(int(ans))

Solution (Python):
M = int(input())
ans = 0
prev = 0
arr = []
for _ in range(M):
    d, c = map(int, input().split())
    ans += c-1
    total = 0
    a = (c-1) // 9
    b = (c-1) % 9 + 1
    if d == 1:
        ans += a
        total = b
    elif d == 2:
        ans += a * 2
        if b >= 5: ans += 1
        total = [2,4,6,8,1,3,5,7,9][b-1]
    elif d == 3:
        ans += (c-1) // 3
        total = ((c-1) % 3 + 1) * 3
    elif d == 4:
        ans += a * 4
        if b >= 3: ans += 1
        if b >= 5: ans += 1
        if b >= 7: ans += 1
        total = [4,8,3,7,2,6,1,5,9][b-1]
    elif d == 5:
        ans += a * 5
        if b >= 2: ans += 1
        if b >= 4: ans += 1
        if b >= 6: ans += 1
        if b >= 8: ans += 1
        total = [5,1,6,2,7,3,8,4,9][b-1]
    elif d == 6:
        ans += ((c-1) // 3) * 2
        b = (c-1) % 3 + 1
        if b >= 2: ans += 1
        total = [6,3,9][b-1]
    elif d == 7:
        ans += a * 7
        if b >= 2: ans += 1
        if b >= 3: ans += 1
        if b >= 4: ans += 1
        if b >= 6: ans += 1
        if b >= 7: ans += 1
        if b >= 8: ans += 1
        total = [7,5,3,1,8,6,4,2,9][b-1]
    elif d == 8:
        ans += a * 8
        if b >= 2: ans += 1
        if b >= 3: ans += 1
        if b >= 4: ans += 1
        if b >= 5: ans += 1
        if b >= 6: ans += 1
        if b >= 7: ans += 1
        if b >= 8: ans += 1
        total = [8,7,6,5,4,3,2,1,9][b-1]
    elif d == 9:
        ans += (c-1)
        total = 9
    elif d == 0:
        total = 0
    
    
    
    
    arr.append(total)
p = arr[0]
for m in arr[1:]:
    ans += 1
    if p + m >= 10:
        ans += 1
        p = (p + m - 1) % 9 + 1
    else:
        p = p + m
print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

m = inp()
d = [0] * m
c = [0] * m
res = 0
for i in range(m):
    d[i], c[i] = inpl()
    res += d[i]*c[i]
tmp = 0
if res % 9 == 0:
    tmp -= 1
print(res//9+tmp+sum(c)-1)

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

M = int(input())

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

tmp = 0
ans = 0
for i in range(M):
    tmp += D[i] * C[i]
    if tmp % 9 == 0:
        k = tmp // 9 - 1
        r = 9
    else:
        k = tmp // 9
        r = tmp % 9
    if tmp >= 10:
        ans += k
        tmp = r

print(ans + sum(C) - 1)

Solution (Python):



m= int(input())
dc=[]
s=0
for i in range(m):
    dc.append(list(map(int,input().split())))
    s+=dc[i][0]*dc[i][1]


ans=s//9

for i in range(m):
    ans+=dc[i][1]

if s%9==0:
    ans-=1

print(ans-1)

Solution (Python):
def sum_lr(l, r, cnt):
    cnt += 1
    lr = l + r
    if lr < 10:
        l = lr
        return l, cnt
    else:
        l = lr // 10
        r = lr % 10
        return sum_lr(l, r, cnt)

from collections import defaultdict
aaa = defaultdict(lambda:{})
for l in range(10):
    for r in range(10):
        aaa[l][r] = sum_lr(l,r,0)
        

def dc_compression(d, c, ret, cnt):
    if c == 1:
        ret.append((d, 1))
        return ret, cnt
    
    if c % 2 == 1:
        ret.append((d, 1))
        c -= 1
    d, tmp_cnt = aaa[d][d]
    c = c // 2
    cnt += tmp_cnt * c
    
    return dc_compression(d, c, ret, cnt)
    
    
    
        

M = int(input())

nums = []
l = 0
cnt = 0
import sys
input = sys.stdin.readline
for _ in range(M):
    d, c = map(int, input().split())
    tmp_nums, tmp_cnt= dc_compression(d,c,[], 0)
    for t,_ in tmp_nums:
        nums.append(t)
    
    cnt += tmp_cnt
    

    
for d in nums:
    l, tmp_cnt = aaa[l][d]
    cnt += tmp_cnt

print(cnt-1)

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

ans = 0
res = []
for d,c in DC:
    while c>0:
        if c%2==1:
            res.append(d)
            c -=1
        d *= 2
        if d>=10:
            d = d//10 + d%10
            ans += c
            c//=2
        else:
            ans += c//2
            c//=2

tmp = 0
for r in res:
    ans += 1
    tmp += r
    if tmp >= 10:
        tmp -=9
        ans += 1
ans -=1
print(ans)

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

ans = 0

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

nums = str(num)
if len(nums) <= 1:
    print(ans)
    exit()

while len(nums) > 1:
    up = nums[:len(nums)-1]
    ans += int(up)

    num = int(up) + int(nums[-1])
    nums = str(num)

print(ans)
exit()

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

def func(D, C):
    A, B = D, D
    rests = []
    num = 0
    while True:
        if C%2:
            rests.append(A)
            C -= 1
        if C == 0:
            break
        num += C//2
        X = A+B
        if X >= 10:
            A, B = X//10, X%10
        else:
            A, B = X, X
            C //= 2

    rests = rests[::-1]
    ret, E = func_naive(rests)
    return num+ret, E

def func_naive(Xs):
    num = 0
    while True:
        if len(Xs) == 1:
            break
        B = Xs.pop()
        A = Xs.pop()
        X = A+B
        if X >= 10:
            Xs.append(X//10)
            Xs.append(X%10)
        else:
            Xs.append(X)
        num += 1
    return num, Xs[0]

M = int(input())
dcs = [tuple(map(int, input().split())) for _ in range(M)]

ans = 0
Es = []
for d, c in dcs:
    num, E = func(d, c)
    ans += num
    Es.append(E)

num, E = func_naive(Es)
ans += num

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
from collections import deque
l=deque()
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):
import sys
def input():
    return sys.stdin.readline()[:-1]
M=int(input())
S,s=0,0
for i in range(M):
    d,c=map(int,input().split())
    S+=d*c
    s+=c
if S%9==0:
    a=S//9-1
else:
    a=S//9
a+=s-1
print(a)

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

Solution (Python):

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

m = int(input())


keta = 0
wa = 0

for i in range(m):
    d,c = [int(i) for i in readline().split()]
    keta += c
    wa += d*c


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

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

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

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

tmp = sumd // 10
while tmp > 0:
    pre = sumd
    sumd += tmp
    tmp = sumd // 10 - pre // 10

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

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

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

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

if s % 9 == 0:
    x = s//9 - 1
else:
    x = s//9

n = sum(c)

print(x + n - 1)

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

amari = 0
ans = 0
for i in range(m):
    a, b = info[i]
    while b != 0:
        if a == 0:
            ans += b
            break
        elem_num = -((-10) // a)
        kumi_num = b // elem_num
        if amari == 0:
            ans += max(0, (b % elem_num) -1)
        else:
            ans += max(0, (b % elem_num))
        amari += a * (b % elem_num)
        ans += kumi_num * (elem_num - 1)
        ans += kumi_num
        a = (a * elem_num) // 10 + ((a * elem_num) % 10)
        b = kumi_num
        if amari >= 10:
            ans += 1
            amari = amari // 10 + (amari % 10)
print(ans)

Solution (Python):
def main():
    M = int(input())
    reduced = [0] * M
    loop = [[] for _ in range(10)]
    for i in range(10):
        sm = i
        cnt = 0
        while True:
            loop[i].append((sm, cnt))
            if sm == i and cnt != 0:
                break
            sm += i
            cnt += 1
            if sm >= 10:
                sm = (sm % 10) + 1
                cnt += 1
        
    ans = 0
    for i in range(M):
        d, c = map(int, input().split())
        cycle = len(loop[d]) - 1
        a = (c-1) % cycle
        b = (c-1) // cycle
        ans += loop[d][cycle][1] * b + loop[d][a][1]
        reduced[i] = loop[d][a][0]
    
    
    sm = 0
    for i in range(M):
        sm += reduced[i]
        if sm >= 10:
            sm = (sm % 10) + 1
            ans += 1
    ans += M-1
    print(ans)


if __name__ == "__main__":
    main()

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

total_d = 0
total_len = 0
for d,c in DC:
    total_d += d*c
    total_len += c

ans = (total_d - 1)//9 + total_len - 1
print(ans)

Solution (Python):
def canc_loop(d):
    a = 2
    b = 1
    s = d + d
    if s > 10:
        s = 1 + s % 10
        b += 1
    while s != d:
        s += d
        a += 1
        b += 1
        if s >= 10:
            s = 1 + s % 10
            b += 1
    return a, b


def main():
    db = []
    for i in xrange(10):
        db.append(canc_loop(i))
    m = input()
    count = 0
    degi = []
    for _ in xrange(m):
        d, c = map(int, raw_input().split())
        a, b = db[d]
        while c >= a:
            count += c / a * b
            c = c / a + c % a
        degi.extend([d] * c)
    if not degi:
        return count
    d = degi.pop()
    while degi:
        d += degi.pop()
        count += 1
        if d >= 10:
            d = d % 10 + 1
            count += 1
    return count


print main()

Solution (Python):
import numpy as np

m = int(input())
cur_nums = np.zeros(10, dtype = np.int64)
for _ in range(m):
	d, c = list(map(int, input().split()))
	cur_nums[d] += c

nxt_nums = np.zeros(10, dtype = np.int64)

cnt = 0
while True:
	
	nxt_nums = np.zeros(10, dtype = np.int64)
	
	cnt += cur_nums[0] // 2
	nxt_nums[0] += cur_nums[0] // 2
	nxt_nums[0] += cur_nums[0] % 2
	
	cnt += cur_nums[1] // 2
	nxt_nums[2] += cur_nums[1] // 2 
	nxt_nums[1] += cur_nums[1] % 2 
	
	cnt += cur_nums[2] // 2
	nxt_nums[4] += cur_nums[2] // 2 
	nxt_nums[2] += cur_nums[2] % 2 
	
	cnt += cur_nums[3] // 2
	nxt_nums[6] += cur_nums[3] // 2 
	nxt_nums[3] += cur_nums[3] % 2 
	
	cnt += cur_nums[4] // 2
	nxt_nums[8] += cur_nums[4] // 2 
	nxt_nums[4] += cur_nums[4] % 2 
	
	cnt += cur_nums[5] // 2
	nxt_nums[0] += cur_nums[5] // 2 
	nxt_nums[1] += cur_nums[5] // 2 
	nxt_nums[5] += cur_nums[5] % 2 
	
	cnt += cur_nums[6] // 2
	nxt_nums[2] += cur_nums[6] // 2 
	nxt_nums[1] += cur_nums[6] // 2 
	nxt_nums[6] += cur_nums[6] % 2 
	
	cnt += cur_nums[7] // 2
	nxt_nums[4] += cur_nums[7] // 2 
	nxt_nums[1] += cur_nums[7] // 2 
	nxt_nums[7] += cur_nums[7] % 2 
	
	cnt += cur_nums[8] // 2
	nxt_nums[6] += cur_nums[8] // 2 
	nxt_nums[1] += cur_nums[8] // 2 
	nxt_nums[8] += cur_nums[8] % 2
	
	cnt += cur_nums[9] // 2
	nxt_nums[8] += cur_nums[9] // 2 
	nxt_nums[1] += cur_nums[9] // 2 
	nxt_nums[9] += cur_nums[9] % 2  
	if (cur_nums == nxt_nums).all():
		break
	cur_nums = nxt_nums

rest = [i for i in range(10) if cur_nums[i] == 1]




while len(rest) >= 2:
	
	a = rest.pop()
	b = rest.pop()
	rest.extend(map(int, list(str(a + b))))
	cnt += 1

print(cnt)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    m=int(input())
    D=[0]*m;C=[0]*m
    for i in range(m):
        D[i],C[i]=map(int,input().split())

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

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

digits_num = 0
total = 0
for d, c in dc:
    digits_num += c
    total += d * c

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

print(ans)

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

    for d, c in DC:
        cS += c
        S += d*c

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

if __name__ == "__main__":
    main()

Solution (Python):

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))






def main():
    m = ii()
    count = 0
    csum = 0
    for i in range(m):
        d,c = mi()
        count+= d*c
        csum +=c
    
    ans = 0
    ans+= csum-1

    while count > 9:
        ans+=count//10
        tmp = count//10
        count %= 10
        count += tmp


    print(ans)

    
main()

Solution (Python):
import sys
input = sys.stdin.readline
m = int(input())
dc = [list(map(int, input().split())) for _ in range(m)]
s = sum([d * c for d, c in dc])
k = sum([c for d, c in dc])
d = 1
if s % 9:
    d = 0
print(k - 1 + s // 9- d)

Solution (Python):

import bisect
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True

def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    m = II()
    dc = XLMIIS(m)

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

    if s % 9 == 0:
        ans = k + s//9 - 2
    else:
        ans = k + s//9 - 1

    print(ans)






if __name__ == '__main__':
    main()

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

Solution (Python):
M = int(input())
keta = 0
kei = 0
for i in range(M):
    [dtmp,ctmp] = list(map(int,input().split()))
    keta += ctmp
    kei += dtmp*ctmp

kei10 = kei//9

if kei%9==0:
    kei10-=1

output = keta-1 + kei10
print(output)

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

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

if(kari==0):
  print(ans-2)
else:
  print(ans-1)

Solution (Python):
def examD():
    M = I()
    cur = 0; ans = 0
    for i in range(M):
        c, d = LI()
        cur += d*c
        ans += d
    ans += (cur-1)//9 -1
    print(ans)

def examE():
    return

import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

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
    ans=digit-1
    m=s%9
    if m==0:
        m=9
    ans+=(s-m)//9
    print(ans)
    
if __name__=='__main__':
    main()

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

Solution (Python):
import sys

pre1 = [
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1],
    [0, 2, 4, 6, 8, 1, 3, 5, 7, 9, 2],
    [0, 3, 6, 9, 3, 6, 9, 3, 6, 9, 3],
    [0, 4, 8, 3, 7, 2, 6, 1, 5, 9, 4],
    [0, 5, 1, 6, 2, 7, 3, 8, 4, 9, 5],
    [0, 6, 3, 9, 6, 3, 9, 6, 3, 9, 6],
    [0, 7, 5, 3, 1, 8, 6, 4, 2, 9, 7],
    [0, 8, 7, 6, 5, 4, 3, 2, 1, 9, 8],
    [0, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9],
]
pre2 = [
    [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
    [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 10],
    [0, 0, 1, 2, 3, 5, 6, 7, 8, 9, 11],
    [0, 0, 1, 2, 4, 5, 6, 8, 9, 10, 12],
    [0, 0, 1, 3, 4, 6, 7, 9, 10, 11, 13],
    [0, 0, 2, 3, 5, 6, 8, 9, 11, 12, 14],
    [0, 0, 2, 3, 5, 7, 8, 10, 12, 13, 15],
    [0, 0, 2, 4, 6, 7, 9, 11, 13, 14, 16],
    [0, 0, 2, 4, 6, 8, 10, 12, 14, 15, 17],
    [0, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18],
]
m = int(input())
ans = -1
tmp = 0
for line in sys.stdin:
    d, c = map(int, line.split())
    round10 = pre2[d][-1]
    while c >= 10:
        c10, c9 = divmod(c, 10)
        ans += round10 * c10
        c = c10 + c9
    ans += pre2[d][c]
    after_d = pre1[d][c]
    tmp += after_d
    ans += 1
    if tmp >= 10:
        td, tm = divmod(tmp, 10)
        tmp = td + tm
        ans += 1
print(ans)

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

ans = 0
n = D[0]
C[0] -= 1
for i in range(M):
    c = C[i]
    d = D[i]
    while c != 0:
        if c%2==0:
            ans += c//2*((2*d)//10+1)
            d = (2*d)//10+(2*d)%10
            c //= 2
        else:
            ans += c//2*((2*d)//10+1)
            ans += (n+d)//10+1
            n = (n+d)//10+(n+d)%10
            d = (2*d)//10+(2*d)%10
            c //= 2
print(ans)

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

print(((gokei-1)//9)+cry-1)

Solution (Python):
n = int(input())
digit = [ 0 for i in range(10) ]
l = 0
for i in range(n):
    a, b = [ int(v) for v in input().split() ]
    digit[a] += b
    l += b

x = 0
for i in range(10):
    x += i*digit[i]

ans = l-1 

a, b = divmod(x, 9)
if b == 0:
    a -= 1

ans += a
print(ans)

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

A=0
keta=0
for d,c in DC:
    A+=d*c
    keta+=c

ANS=A//10+keta-1

A=A//10+A%10

while A>=10:
    ANS+=A//10
    A=A//10+A%10

print(ANS)

Solution (Python):
import sys

input = sys.stdin.readline

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

digit = 0
numsum = 0
for di, ci in dc:
	digit += ci
	numsum += di*ci

ans = digit-1 + (numsum-1)//9
print(ans)

Solution (Python):

import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0
count2=0

m=int(input())
for i in range(m):
    d,c=map(int,input().split())
    count+=d*c//9
    count2+=d*c%9
    ans+=c
print(ans-1+(count+(count2-1)//9))

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):
m,*t=map(int,open(0).read().split())
a=b=0
for d,c in zip(*[iter(t)]*2):
    m=[b]
    while c//2:
        cd=c//2
        a+=cd
        if c%2:
            m+=d,
        d*=2
        if d>9:
            a+=cd
            d=d//10+d%10
        c=cd
    for t in m[::-1]:
        d+=t
        a+=1
        if d>9:
            d=d//10+d%10
            a+=1
    b=d
print(a-1)

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict


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


def main():
	M = int(input())
	C = 0
	D = 0
	for i in range(M):
		d, c = getlist()
		C += c
		D += d * c
	ans = C - 1
	while True:
		if D >= 10:
			ans += D // 10
			D = D // 10 + D % 10
			
		else:
			break
	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

M = I()
dc = [IL() for i in range(M)]

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

print(cnt - 1 + math.ceil(num/9) - 1)

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

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


def calc(s_list):
    cnt = 0
    while len(s_list) > 1:
        cnt += 1
        s1 = s_list.pop()
        s2 = s_list.pop()
        new = str(s1 + s2)
        if len(new) == 1:
            s_list.append(int(new))
        else:
            s_list.append(int(new[0]))
            s_list.append(int(new[1]))

    return cnt


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

ten_num = [0] * 10
for i in range(10):
    ten_num[i] = calc([i] * 10)

ans = 0
s_list = []
for i in range(M):
    d, c = D[i], C[i]
    while c > 10:
        div, mod = divmod(c, 10)
        ans += ten_num[d] * div
        c = div + mod
    s_list.extend([d] * c)

ans += calc(s_list)
print(ans)

Solution (Python):
from sys import stdin
from itertools import repeat
def main():
    m = int(stdin.readline())
    dat = map(int, stdin.read().split(), repeat(10, 2 * m))
    s = sum(dat[i*2] * dat[i*2+1] for i in xrange(m))
    l = sum(dat[1::2])
    print l - 1 + (s - 1) / 9
main()

Solution (Python):
m = int(input())
ans = -1
all = 0
for i in range(m):
	a,b = map(int, input().split())
	ans += b
	all += a * b

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

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

import numpy as np
M = int(readline())
DC = np.array(read().split(),np.int64)

D = DC[::2]; C = DC[1::2]





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

y = x % 9
if y == 0:
    y = 9
y += 9
answer = (x - y) // 9
print(answer)

Solution (Python):
m = int(input())
cnt = 0
res = None
for _ in range(m):
    d,c = map(int,input().split())
    while c:
        if c%2:
            if res is None:
                res = d
            else:
                res += d
                cnt += 1
                if res > 9:
                    res = res//10 + res%10
                    cnt += 1 
        d *= 2
        c //= 2
        cnt += c
        if d > 9:
            d = d//10 + d%10
            cnt += c
print(cnt)

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

Solution (Python):
n = int(input())
ans = -1
num = 0
for i in range(n):
    a,b = map(int,input().split())
    ans += b
    num += a * b
    if num > 9:
        ans += num // 9
        num %= 9
        if num == 0:
            ans -= 1
            num = 9
print(ans)

Solution (Python):
import sys
readline = sys.stdin.readline
M = int(readline())
ans = 0
res = 0
for _ in range(M):
    d, c = map(int, readline().split())
    ans += d*c
    res += c

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

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

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

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

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

print(ans)

Solution (Python):
M = int(input())
DC = [list(map(int, input().split())) for _ in range(M)]
sumC = 0
su = 0
for d, c in DC:
    sumC += c
    su += d * c
ans = sumC-1 + (su-1)//9
print(ans)

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

Solution (Python):
import sys
input = sys.stdin.readline
m = int(input())
C = [list(map(int,input().split())) for i in range(m)]

cs = sum([i[1] for i in C])
ans = cs-1
mo = 0
for i in range(m):
    mo += C[i][0] * C[i][1]
    ans += mo // 9
    mo %= 9

if mo == 0:
    ans -= 1
print(ans)

Solution (Python):
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors



n = int(input())
ans1=0
keta=0
for i in range(n):
    p,q = list(map(int, input().split()))
    ans1 += p*q
    keta+=q
print((ans1-1)//9 + (keta-1))

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

Solution (Python):
m=int(input())
nums=[list(map(int,input().split())) for i in range(m)]
S=0
Slen=0
for i in nums:
  S+=i[0]*i[1]
  Slen+=i[1]
if S%9==0:
  kuriagari=S//9-1
else:
  kuriagari=S//9
print(Slen-1+kuriagari)

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)