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: Wrong Answer

Solution code:
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 = sum(d)
    sum_c = sum(c)
    ans = (sum_c - 1) + (sum_d - 1) // 9
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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//9+b-1)

Submission status: Wrong Answer

Solution code:
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+9-1)//9
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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(c * d, 9)
  count += q
  tmp += m
  if tmp >= 9:
    count += 1
    tmp %= 9
  total += d
if m == 0 or tmp == 0:
  count -= 1
print(total - 1 + count)

Submission status: Wrong Answer

Solution code:
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(c * d, 9)
  count += q
  tmp += m
  if tmp >= 9:
    count += 1
    tmp %= 9
  total += d
print(total - 1 + count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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(c-1 + dsum // 9)

Submission status: Wrong Answer

Solution code:
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
    if d >= 10:
        return c//2 * 2 + calc(1+d%10, c//2)
    return c//2 + calc(d, c//2)
    

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

Submission status: Wrong Answer

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
    return add, rem

def solve():
    input = sys.stdin.readline
    M = int(input())
    count = 0
    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: Wrong Answer

Solution code:
import sys
from collections import deque

def q(d, c): #dは9以下、cは桁数
    if c == 1: return 0, d
    if d < 5: 
        add, rem = q(2 * d, c//2)
        add += c//2
    else:
        add, rem = q(2 * d - 9, c//2)
        add += c
    if c % 2 == 1:
        rem += d
        add += 1
        if rem > 9:
            rem -= 9
            add += 1
    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: Wrong Answer

Solution code:
import sys
from collections import deque

def q(d, c): #dは9以下、cは桁数
    if c == 1: return 0, [d]
    if d < 5: 
        add, seq = q(2 * d, c//2)
        add += c//2
    else:
        add, seq = q(2 * d - 9, c//2)
        add += c
    if c % 2 == 1: seq.append(d)
    return add, seq

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

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

def q(d, c): #dは9以下、cは桁数
    if c == 1: return 0, [d]
    if d < 5: 
        add, seq = q(2 * d, c//2)
        add += c//2
    else:
        add, seq = q(2 * d - 9, c//2)
        add += c
    if c % 2 == 1: 
        seq.append(d)
        add += 1
    return add, seq

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

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

def q(d, c, dq, digit): #dは9以下、cは桁数
    if c == 1: 
        digit += 1
        dq.append(d)
        return 0
    a = d * 2
    if a < 10: add = q(a, c//2, dq, digit)
    else:
        add = q(a - 9, c//2, dq, digit)
        add += c//2
    add += c//2
    if c % 2 == 1: 
        digit += 1
        dq.append(d)
    return add

def solve():
    input = sys.stdin.readline
    M = int(input())
    count = 0
    dq = deque()
    digit = 0
    for _ in range(M):
        d, c = map(int, input().split())
        add = q(d, c, dq, digit)
        #print(dq, add, count)
        count += add
        a = dq.pop()
        for k in range(digit):
            count += 1
            a += dq.pop()
            if a >= 10: 
                a -= 9
                count += 1
        dq.append(a)
        digit = 1

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque

def q(d, c):
    if c == 1: 
        if d < 10: return [str(d)], 0
        else: return [str(d // 10), str(d % 10)], 0
    if d >= 10: 
        lem, count = q(d // 10 + d % 10, c)
        return lem, count + c
    elif c % 2 == 0:
        lem, count = q(d * 2, c // 2)
        return lem, count + c // 2
    elif c % 2 == 1:
        lem, count = q(d * 2, c //2)
        lem.append(str(d))
        return lem, count + c // 2

def solve():
    input = sys.stdin.readline
    M = int(input())
    N = ""
    count = 0
    dq = deque()
    digit = 0
    for _ in range(M):
        d, c = map(int, input().split())
        lem, add = q(d, c)
        for s in lem: 
            dq.append(s)
            digit += 1
        count += add

    while digit > 1:
        #print(dq)
        a = int(dq.pop())
        a += int(dq.pop())
        if a >= 10:
            dq.append(str(a % 10))
            dq.append(str(a // 10))
        else: 
            dq.append(str(a))
            digit -= 1

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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//9)

Submission status: Wrong Answer

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//10)

Submission status: Wrong Answer

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 // 9 - 1)
    return


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

Submission status: Wrong Answer

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 // 9)
    return


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

Submission status: Wrong Answer

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_sum += c

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

Submission status: Wrong Answer

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:
    tot = tot // 10 + tot % 10
    ans += tot
print(ans - 1)

Submission status: Wrong Answer

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:
    tot //= 10
    ans += tot
print(ans - 1)

Submission status: Wrong Answer

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 += 1
    tot //= 10
print(ans - 1)

Submission status: Wrong Answer

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 += 1
    tot = tot / 10 + 1
print(ans - 1)

Submission status: Wrong Answer

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):
    C = []
    for i in range(10):
        s = i
        s += i
        c = 1
        p = 1
        while s != i:
            s += i
            c += 1
            p += 1
            if s >= 10:
                s = s % 10 + s // 10
                p += 1
        C.append((i, c+1, p))
    C[0] = (0, 1, 1)

    ans = 0
    rem = []
    for d, c in CD:
        if d == 0:
            ans += c
            continue
        _, dc, dv = C[d]
        while c >= dc:
            v = c // dc
            ans += v * dv
            c = c % dc + v
        for _ in range(c):
            rem.append(d)

    while len(rem) > 1:
        a = rem.pop()
        b = rem.pop()
        c = a + b
        ans += 1
        if c >= 10:
            c = c % 10 + c // 10
            ans += 1
        rem.append(c)

    return ans


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: Wrong Answer

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//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: Wrong Answer

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(d)-1+z//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: Wrong Answer

Solution code:
M, *DC = map(int, input().split())

D, C = DC[::2], DC[1::2]
print (M,DC, D,C)
S = sum(d * c for d, c in zip(D, C))
print(sum(C) - 1 + (S - 1) // 9)

Submission status: Wrong Answer

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//9)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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
    
print(K-1+S//9)

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

Solution code:
M = int(input())
D = []
C = []
for i in range(M):
  d,c = map(int,input().split())
  D.append(d)
  C.append(c)
n = sum(C)
S = 0
for i in range(M):
  S += D[i] * C[i]
#print(9 * n + S)
print((9 * n + S - 9) // 9)

Submission status: Wrong Answer

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
    while True:
        if t >= 10:
            cnt += t // 10
            t //= 10
        else:
            break
    print(cnt - 1)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
M = int(input())

D, S = 0, 0

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin

input = stdin.readline

m, *t = map(int, open(0).read().split())


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)
    print(a, c//2, ca)

    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 zip(*[iter(t)] * 2):
    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: Wrong Answer

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, a in enumerate(A[1:], 1):
    a += A[i-1]
    ans += 1
    if a >= 10:
        A[i] = int(str(a)[0]) + int(str(a)[1])
        ans += 1
print(ans)

Submission status: Wrong Answer

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

sumc = 0
for i in range(m):
  sumc += li[i][1]
sumd = 0
for i in range(m):
  sumd += li[i][0]*li[i][1]
ans = 0
ans += sumc
ans += sumd//9
print(ans-1)

Submission status: Wrong Answer

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
while s:
    ans += s // 10 + (s // 10 % 10 + s % 10 >= 10)
    s //= 10
print(ans)

Submission status: Wrong Answer

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
while s:
    s //= 10
    ans += s
print(ans)

Submission status: Wrong Answer

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, a in enumerate(A[1:], 1):
    a += A[i-1]
    ans += 1
    if a >= 10:
        a = int(str(a)[0]) + int(str(a)[1])
        ans += 1
print(ans)

Submission status: Wrong Answer

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)[1] + str(a)[0])
            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, a in enumerate(A[1:], 1):
    a += A[i-1]
    ans += 1
    if a >= 10:
        a = int(str(a)[1] + str(a)[0])
        ans += 1
print(ans)

Submission status: Wrong Answer

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
if digits_length == 0:
    digits_length = 1

# print(digits_sum, digits_length)

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

Submission status: Wrong Answer

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 // 9))

Submission status: Wrong Answer

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//9
    print(ans)
        
        

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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 = 0
S = 0
for i in range(M):
	D += c[i]
	S += d[i] * c[i]
print((D - 1) + S // 9)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = []
res = 0
t = 0
r = 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]
  x = (d * c + t) // 10
  y = (d * c + t) % 10
  res += x
  if x + y >= 10:
    res += 1
  t = 0
  if x > 0: t = (x + y) % 10 == 0
  t += (x + y) % 10
  r += c
  #print(x, y, t)
print(res + r - 1)

Submission status: Wrong Answer

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//9)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = []
res = 0
t = 0
r = 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]
  x = (d * c + t) // 10
  y = (d * c + t) % 10
  res += x
  if x + y >= 10:
    res += 1
  t = (x + y) % 10
  t += t == 0
  r += c

print(res + r - 1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = []
res = 0
t = 0
r = 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]
  x = (d * c + t) // 10
  y = (d * c + t) % 10
  res += x
  if x + y >= 10:
    res += x
  t = (x + y) % 10
  r += c
print(res + r - 1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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+S//9-1)

Submission status: Wrong Answer

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
    
print(l-1+num//10)

Submission status: Wrong Answer

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

num=""
count=0
for d,c in dc:
    count+=c-1+d*c//10
    num+=str(d*c%10)
    
while len(num)>=2:
    a=str(int(num[0])+int(num[1]))
    num=a+num[2:]
    count+=1
    
print(count)