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.  



Sample input:
2
2 2
9 1


Sample output:
3

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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())

Submission status: Accepted

Solution code:
import sys
from collections import deque

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

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

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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

#solve
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


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
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

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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))

    # N = 100
    # CD = [[random.randint(0, 9), random.randint(1, 10000)] for _ in range(N)]
    # print(N)
    # print(CD)
    # print(slv(N, CD))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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:
                #ret+=1
                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)

Submission status: Accepted

Solution code:
M=int(input())
#Get the number that needs to be handled
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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))

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

# 同じ数字2つをマージした時の行き先と増える操作回数
# (nxt, cnt)
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

# 数字aがcnt個あった時に、全てマージした後の数字と費やした操作回数を返す
def calc(a, cnt):
    sm = 0
    odd = []
    # 1つになるまでやる
    while cnt > 1:
        # 奇数だと半分にした時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():
    # 数字毎にマージ、これで残り最大10桁まで減るはず
    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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

# 同じ数字2つをマージした時の行き先と増える操作回数
# (nxt, cnt)
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

# 数字aがcnt個あった時に、全てマージした後の数字と費やした操作回数を返す
def calc(a, cnt):
    sm = 0
    odd = []
    # 1つになるまでやる
    while cnt > 1:
        # 奇数だと半分にした時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():
    # 数字毎にマージ、これで残り最大10桁まで減るはず
    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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

# (nxt, cnt)
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)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

# print(digits_sum, digits_length)

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

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
M = int(input())

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

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

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

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

D = np.array(D) ; C = np.array(C)
#桁数の9倍とそれぞれの数字の総和をx
x = C.sum() * 9 + (C * D).sum()
# 18以下で終了
answer = (x + 8) // 9 - 2
print(answer)

Submission status: Accepted

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

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



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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
M = int(input())
d = 0
c = 0
for _ in range(M):
    c1, d1 = map(int, input().split())
    d += d1
    c += c1 * d1

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

print((d - 1) + s)

Submission status: Accepted

Solution code:
import numpy as np
M=int(input())
D=0
C=0
for i in range(M):
  d,c=map(int,input().split())
  D+=c*d
  C+=c
# 桁数を減らす処理はC-1回行われる

# 桁数を減らさない処理は総和から9減る。(D-1)//9回行われる。
print((C-1)+(D-1)//9)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

N = 0
S = 0

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

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

Submission status: Accepted

Solution code:
n = int(input())
d = [0]*n
c = [0]*n
s = []
digit_sum = 0 #前後の和　桁数−１のリスト 予め0を入れとく。
digit_cnt = 0
for i in range(n):
  d[i],c[i] = map(int,input().split())
  digit_sum += d[i]*c[i]
  digit_cnt += c[i]
print((digit_cnt*9+digit_sum-1)//9-1)

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

    return (digits - 1) + (sum_ - 1) // 9
    # 一回の操作で、
    # 繰り上がりが起こらないとき一桁減る
    # 繰り上がりが起こるとき合計値が9減る
    # 最終的に一桁の数値1～9が残るので、
    # 一桁になるまでの桁減らし回数と、9で割ったときにsum_が1以上残るような割り算の回数を返せばよい


print(solve())

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import sys

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

    digits = 0
    total = 0

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

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

    print(ans)


if __name__ == '__main__':
    answer()

Submission status: Accepted

Solution code:
import sys

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

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

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

    digits = sum(Ds)

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

    print(ans)


if __name__ == '__main__':
    answer()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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