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:
from collections import Counter

mod = 1000000007


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft

memo = [
    [0, 1, 1],
    [1,10,9],
    [2,11,9],
    [3,4,3],
    [4,13,9],
    [5,14,9],
    [6,5,3],
    [7,16,9],
    [8,17,9],
    [9,2,1],
]





def main():
    m = int(input())
    dc = [[int(i) for i in input().split()] for _ in range(m)]
    s = []
    ans = 0
    for i in range(m):
        d = dc[i][0]
        c = dc[i][1]
        ans += c // memo[d][2] * memo[d][1]
        if d == 9:
            ans -= 2
            s.append([d, 1])
        else:
            if (c % memo[d][2]) == 0:
                continue
            s.append([d, (c % memo[d][2])])
    if not s:
        print(ans)
        return

    t = 0
    for i in range(len(s)):
        if s[i][0] == 1:
            ans += s[i][1]
            t += s[i][1]
            if t > 9:
                ans += 1
                t = t % 10 + t // 10
            continue
        while s[i][1]:
            s[i][1] -= 1
            ans += 1
            t += s[i][0]
            if t > 9:
                ans += 1
                t = t % 10 + t // 10

    print(ans - 1)

main()

Submission status: Wrong Answer

Solution code:
def main1():
    M = int(input())
    ans = 0
    pre = 0
    for i in range(M):
        d, c = (int(i) for i in input().split())
        if i == 0:
            pre = d*c
            ans += c - 1
            while pre > 10:
                ans += pre//10
                pre = pre//10 + pre % 10
            continue
        pre = pre + d*c
        ans += c - 1
        while pre > 10:
            ans += pre//10
            pre = pre//10 + pre % 10
    print(ans + M - 1)


def main2():
    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
    print(ans - 1 + dc_sum // 9)


if __name__ == '__main__':
    from random import randint
    if randint(0, 4) < 2:
        main1()
    else:
        main2()

Submission status: Wrong Answer

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

s = (c - 1) // 9

print((d - 1) + s)

Submission status: Wrong Answer

Solution code:
def main1():
    M = int(input())
    ans = 0
    pre = 0
    for i in range(M):
        d, c = (int(i) for i in input().split())
        if i == 0:
            pre = d*c
            ans += c - 1
            while pre > 10:
                ans += pre//10
                pre = pre//10 + pre % 10
            continue
        pre = pre + d*c
        ans += c - 1
        while pre > 10:
            ans += pre//10
            pre = pre//10 + pre % 10
    print(ans + M - 1)


def main2():
    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
    print(ans - 1 + dc_sum // 9)


if __name__ == '__main__':
    from random import randint
    if randint(0, 3) < 1:
        main1()
    else:
        main2()

Submission status: Wrong Answer

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

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

print((d - 1) + s)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
m=int(input())
a=[list(map(int, input().split())) for i in range(m)]
x=0
y=0
z=0
y1=float('inf')
ans=0
for i in range(m):
    x+=a[i][1]
    y+=a[i][0]*a[i][1]
    
v=str(y)


while y>9:
    z+=y%10
    if z>9:
        ans+=1
        z=z%10
    
    y=y//10
    ans+=y


print(x-1+ans)

Submission status: Wrong Answer

Solution code:
m=int(input())
a=[list(map(int, input().split())) for i in range(m)]
x=0
y=0
z=0
y1=float('inf')
ans=0
for i in range(m):
    x+=a[i][1]
    y+=a[i][0]*a[i][1]
    
v=str(y)


while y>9:
    y=y//10
    ans+=y
    y+=y%10
    

print(x-1+ans)

Submission status: Wrong Answer

Solution code:
m = int(input())
l = [] 
#print(m)
for i in range(m):
    d,c = map(int,input().split())
    for j in range(c):
      l.append(d)
#print('list',l)

le =len(l)
#print('le',le)

a = l.pop(0)
b = l.pop(0)
cnt = 2
ans =0
while cnt <= le:  
  ans +=1
  if a + b >= 10:
    a = (a+b)%10
    b = (a+b)//10
  else:
    a = a+b
    if cnt == le:
      break
    b = l.pop(0)
    cnt +=1
print(ans)

Submission status: Wrong Answer

Solution code:
m=int(input())
a=[list(map(int, input().split())) for i in range(m)]
x=0
y=0
z=0
y1=float('inf')
ans=0
for i in range(m):
    x+=a[i][1]
    y+=a[i][0]*a[i][1]
    
v=str(y)
w=int(v[-1])


for i in range(len(v)):
    if i==0:
        z+=w
    else:
        ans+=int(v[-(i+1)])*(11*10**(i-1))//10
        z+=int(v[-(i+1)])
    if z>=10:
        ans+=1
        z=z%10
print(x-1+ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def fusion(s):
	if len(s)==2:
		return int(s[0])+ int(s[1])
	pos = 0
	mx = 0
	for i in range(len(s)-1):
		val = int(s[i])+int(s[i+1])
		if val>mx:
			mx = val
			pos=i
	res = ""
	for i in range(pos):
		res+=s[i]
	res+=str(int(s[pos])+int(s[pos+1]))
	for i in range(pos+2,len(s)):
		res+=s[i]
	#~ print("s= ",s, "pos = ",pos, "res = ",res)
	return res
	
def f(s):
	step=0
	while len(s)>1:
		#~ print(s)
		s = str(fusion(s))
		step+=1
	#~ print(s)
	return int(s),step
	

m= int(input())
chaine = ""
ans = 0
for _ in range(m):
	d,c = (int(i) for i in input().split())
	ans+=c-1
	r,cnt = (i for i in f(str(d*c)))
	ans+=cnt
	chaine+=str(r)
	
r,cnt = (i for i in f(chaine))
ans+=cnt
print(ans)

Submission status: Wrong Answer

Solution code:
m=int(input())
a=[list(map(int, input().split())) for i in range(m)]
x=0
y=0
z=0
y1=float('inf')
ans=0
for i in range(m):
    x+=a[i][1]
    y+=a[i][0]*a[i][1]
    
v=str(y)
w=int(v[-1])


while y>9:
    y=y//10
    ans+=y
    y=y+w

print(x-1+ans)

Submission status: Wrong Answer

Solution code:
m=int(input())
a=[list(map(int, input().split())) for i in range(m)]
x=0
y=0
z=0
y1=float('inf')
ans=0
for i in range(m):
    x+=a[i][1]
    y+=a[i][0]*a[i][1]
    
v=str(y)
w=int(v[-1])


for i in range(len(v)):
    ans+=(int(v[-(i+1)])*(10**i))//10
    z+=int(v[-(i+1)])
    if z>=10:
        ans+=1
        z=z%10
print(x-1+ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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]
if digit_sum % 9 == 0:
  print(digit_sum//9 + digit_cnt )
else:print(digit_sum//9 + digit_cnt -1 )

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 // 9) + total_digits -1
print(answer)
exit(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    M = int(input())
    ans = 0
    pre = 0
    for i in range(M):
        d, c = (int(i) for i in input().split())
        if i == 0:
            if M == 1 and d * c < 10:
                return print(0)
            pre = d*c
            ans += c - 1
            while pre > 10:
                ans += pre//10
                pre = pre//10 + pre % 10
            continue
        pre = pre + d*c
        ans += c - 1
        while pre > 10:
            ans += pre//10
            pre = pre//10 + pre % 10
    print(ans + M - 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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
    b+=c
print(b-1+(a-1)//9)

Submission status: Wrong Answer

Solution code:
def main():
    M = int(input())
    sum1 = 0
    sum2 = 0
    ans = 0
    for i in range(M):
        d, c = (int(i) for i in input().split())
        sum1 += c
        sum2 += d*c
        while 9 < sum2:
            ans += 1
            sum2 = sum2//10 + sum2 % 10
        ans += c - 1
    print(ans + M - 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    M = int(input())
    ans = 0
    pre = 0
    for i in range(M):
        d, c = (int(i) for i in input().split())
        if i == 0:
            if M == 1 and d * c < 9:
                return print(1)
            pre = d*c
            ans += c - 1
            while pre > 9:
                ans += pre//9
                pre = pre//9 + pre % 9
            continue
        pre = pre + d*c
        ans += c - 1
        while pre > 9:
            ans += pre//9
            pre = pre//9 + pre % 9
    print(ans + M - 1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    M = int(input())
    sum1 = 0
    sum2 = 0
    for i in range(M):
        d, c = (int(i) for i in input().split())
        sum1 += d*c
        sum2 += c
    print(sum2 - 1 + sum1 // 10)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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):
        d, c = map(int, input().split())
        Ds[i] = d
        Cs[i] = c
        total += d * c

    digits = sum(Ds)

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

    print(ans)


if __name__ == '__main__':
    answer()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def main():
    M = int(input())
    num = []
    wa = []
    for _ in range(M):
        d, c = [int(x) for x in input().split()]
        for _ in range(c):
            num.append(d)
    
    nums = sum(num)
    x = len(num)
    print(x - 1 + (nums // 9))
    



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

S //= 10
while S > 0:
    ans += S
    S //= 10
print(ans)

Submission status: Wrong Answer

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

tab = [[i] for i in range(10)]
for i in range(1, 10):
    sum_tmp = i
    while True:
        sum_tmp += i
        while sum_tmp > 9:
            sum_tmp = (sum_tmp // 10) + (sum_tmp % 10)
            tab[i].append(sum_tmp)
        #
        if sum_tmp == i:
            break
        else:
            tab[i].append(sum_tmp)

left = []
for i, (di, ci) in enumerate(dc):
    idx = ci % len(tab[di])
    left.append(tab[di][idx - 1])
    
# for i in range(M):
#     print("#", i, left[i])

ans = sum([ci - 1 for di, ci in dc])
for i in range(M):
    if i == 0:
        sum_tmp = left[i]
    else:
        sum_tmp += left[i]
        ans += 1
        while sum_tmp > 9:
            sum_tmp = (sum_tmp // 10) + (sum_tmp % 10)
            ans += 1

print(ans)

Submission status: Wrong Answer

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

S //= 10
while S > 0:
    ans += S % 10
    S //= 10
print(ans)

Submission status: Wrong Answer

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+(y//10+1))//10)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read

M = int(input())
dc = map(int, read().split())
dig = [0] * 10
cnt = 0
answer = 0
for d, c in zip(*[iter(dc)] * 2):
    dig[d] += c

trans = dict()
for i in range(10):
    if i < 5:
        trans[i] = i + i
    elif i == 5:
        trans[i] = 1
    else:
        trans[i] = trans[i - 1] + 2

while True:
    tmp = [0] * 10
    for i, x in enumerate(dig):
        q, r = divmod(x, 2)
        if x >= 2:
            if i < 5:
                answer += q
                tmp[trans[i]] += q
                tmp[i] += r
            else:
                answer += q
                tmp[trans[i]] += q
                tmp[i] += r
        else:
            tmp[i] += x

    dig = tmp.copy()
    for i in dig:
        if i > 1:
            break
    else:
        break

last = [i for i in range(10) if dig[i] == 1]
while len(last) > 1:
    a = last.pop()
    b = last.pop()
    c = a + b
    if c >= 10:
        answer += 2
        last.append(c // 10 + c % 10)
    else:
        answer += 1
        last.append(c)

print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read

M = int(input())
dc = map(int, read().split())
dig = [0] * 10
cnt = 0
answer = 0
for d, c in zip(*[iter(dc)] * 2):
    dig[d] += c

trans = dict()
for i in range(10):
    if i < 5:
        trans[i] = i + i
    elif i == 5:
        trans[i] = 1
    else:
        trans[i] = trans[i - 1] + 2

while True:
    tmp = [0] * 10
    for i, x in enumerate(dig):
        q, r = divmod(x, 2)
        if x >= 2:
            if i < 5:
                answer += q
                tmp[trans[i]] += q
                tmp[i] += r
            else:
                answer += x
                tmp[trans[i]] += q
                tmp[i] += r
        else:
            tmp[i] += x

    dig = tmp.copy()
    for i in dig:
        if i > 1:
            break
    else:
        break

last = [i for i in range(10) if dig[i] == 1]
while len(last) > 1:
    a = last.pop()
    b = last.pop()
    if a + b >= 10:
        answer += 2
        last.append((a + b) // 10 + (a + b) % 10)
    else:
        answer += 1
        last.append(a + b)

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read

M = int(input())
dc = map(int, read().split())
dig = [0] * 10
cnt = 0
answer = 0
for d, c in zip(*[iter(dc)] * 2):
    dig[d] += c

trans = dict()
for i in range(10):
    if i < 5:
        trans[i] = i + i
    elif i == 5:
        trans[i] = 1
    else:
        trans[i] = trans[i - 1] + 2

print(trans)

while True:
    tmp = [0] * 10
    for i, x in enumerate(dig):
        q, r = divmod(x, 2)
        if x >= 2:
            if i < 5:
                answer += q
                tmp[trans[i]] += q
                tmp[i] += r
            else:
                answer += x
                tmp[trans[i]] += q
                tmp[i] += r
        else:
            tmp[i] += x

    dig = tmp.copy()
    for i in dig:
        if i > 1:
            break
    else:
        break

last = [i for i in range(10) if dig[i] == 1]
while len(last) > 1:
    a = last.pop()
    b = last.pop()
    if a + b >= 10:
        answer += 2
        last.append((a + b) // 10 + (a + b) % 10)
    else:
        answer += 1
        last.append(a + b)

print(answer)

Submission status: Wrong Answer

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

p=0
for i in range(m):
    p+=l[i][1]
q=0
for i in range(m):
    q+=l[i][0]

print(p+(q-1)//9-1)

Submission status: Wrong Answer

Solution code:
M = int(input())
S = 0
res = -1
for _ in range(M):
    d, c = map(int, input().split())
    res += c
    S += d*c

res += S // 9
print(res)

Submission status: Wrong Answer

Solution code:
M = int(input())
S = 0
res = -1
for _ in range(M):
    d, c = map(int, input().split())
    res += d
    S += c

res += S // 9
print(res)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read

M = int(input())
dc = map(int, read().split())
dig = [0] * 10
cnt = 0
answer = 0
for d, c in zip(*[iter(dc)] * 2):
    dig[d] += c

trans = dict()
for i in range(10):
    if i < 5:
        trans[i] = i + i
    elif i == 5:
        trans[i] = 1
    else:
        trans[i] = trans[i - 1] + 2

while True:
    tmp = [0] * 10
    for i, x in enumerate(dig):
        r, q = divmod(x, 2)
        if x >= 2:
            if i < 5:
                answer += r
                tmp[trans[i]] += r
                tmp[i] += q
            else:
                answer += r
                tmp[trans[i]] += x - q
                tmp[i] += q
        else:
            tmp[i] += x

    dig = tmp.copy()
    for i in dig:
        if i > 1:
            break
    else:
        break

last = [i for i in range(10) if dig[i] == 1]
while len(last) > 1:
    a = last.pop()
    b = last.pop()
    if a + b >= 10:
        answer += 2
        last.append((a + b) // 10 + (a + b) % 10)
    else:
        answer += 1
        last.append(a + b)

print(answer)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read

M = int(input())
dc = map(int, read().split())
dig = [0] * 10
cnt = 0
answer = 0
for d, c in zip(*[iter(dc)] * 2):
    dig[d] += c

trans = dict()
for i in range(10):
    if i < 5:
        trans[i] = i + i
    elif i == 5:
        trans[i] = 1
    else:
        trans[i] = trans[i - 1] + 2

while True:
    tmp = [0] * 10
    for i, x in enumerate(dig):
        r, q = divmod(x, 2)
        if x >= 2:
            if i < 5:
                answer += r
                tmp[trans[i]] += r
                tmp[i] += q
            else:
                answer += r
                tmp[trans[i]] += x - q
                tmp[i] += q
        else:
            tmp[i] += x

    dig = tmp.copy()
    for i in dig:
        if i > 1:
            break
    else:
        break

last = [i for i in range(10) if dig[i] == 1]
while len(last) > 1:
    a = last.pop()
    b = last.pop()
    if a + b > 10:
        answer += 2
        last.append((a + b) // 10 + (a + b) % 10)
    else:
        answer += 1
        last.append((a + b) // 10 + (a + b) % 10)

print(answer)

Submission status: Wrong Answer

Solution code:
print("the questios is too difficult")

Submission status: Wrong Answer

Solution code:
M = int(input())
ans = 0
D = []
for m in range(M):
    d, c = map(int, input().split())
    dtc = d * c
    over = dtc // 10
    ans += c-1 + over
    D += [dtc % 10 + sum(map(int, str(over))) % 10]
ans += len(D) - 1
# print(ans)
# while len(D) >= 2:
#     sumD = sum(map(int, D))
#     over = sumD // 10
#     ans += len(D) - 1 + over
#     D = str(over + sumD % 10)
#     sumD = sum(map(int, D))
ans += (sum(D)-1)//9

print(ans)
# print(sumD)

Submission status: Wrong Answer

Solution code:
m = int(input())
dc=[list(map(int, input().split())) for i in range(m)]
b = [[(1,0)]]
f = []
ans = 0
now = 0
for i in range(1,10):
  mini_b = []
  c = i
  d = 0
  c += i
  d += 1
  while (c // 10):
    c = c % 10 + 1
    d += 1
  mini_b.append((d,c))
  while c != i:  
    c += i
    d += 1
    while (c // 10):
      c = c % 10 + 1
      d += 1
    mini_b.append((d,c))
  b.append(mini_b)
print(b) 
for d,c in dc:
  if d:
    if c > 1:
      x,y = divmod(c-1,len(b[d]))
      if y == 0:
        ans +=  b[d][-1][0] * x
        f.append(d)
      else:
        ans +=  b[d][-1][0] * x + b[d][y-1][0]
        f.append(b[d][y-1][1])
    else:
      f.append(d)
  else:
    ans += c-1
    f.append(0)
print(ans)   
print(f)
for i in f:
  now += i
  ans += 1
  while (now//10):
    now = now % 10 + 1
    ans += 1
  
print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.read

M = int(input())
dc = map(int, read().split())
dig = [0] * 10
cnt = 0
answer = 0
for d, c in zip(*[iter(dc)] * 2):
    dig[d] += c

trans = dict()
for i in range(10):
    if i < 5:
        trans[i] = i + i
    elif i == 5:
        trans[i] = 1
    else:
        trans[i] = trans[i - 1] + 2

while True:
    tmp = [0] * 10
    for i in range(5):
        if dig[i] >= 2:
            answer += dig[i] // 2
            tmp[trans[i]] += dig[i] // 2
            tmp[i] += dig[i] % 2
        else:
            tmp[i] += dig[i]
    for i in range(5, 10):
        if dig[i] >= 2:
            answer += dig[i]
            tmp[trans[i]] += dig[i]
            tmp[i] += dig[i] % 2
        else:
            tmp[i] += dig[i]
    dig = tmp.copy()
    for i in dig:
        if i > 1:
            break
    else:
        break

last = [i for i in range(10) if dig[i] == 1]
while len(last) > 1:
    a = last.pop()
    b = last.pop()
    if a + b > 10:
        answer += 2
        last.append((a + b) // 10 + (a + b) % 10)
    else:
        answer += 1
        last.append((a + b) // 10 + (a + b) % 10)

print(answer)

Submission status: Wrong Answer

Solution code:
# 2019-11-23 21:00:35(JST)
import sys
import collections

def main():
    m = int(sys.stdin.readline().rstrip())

    a = collections.defaultdict(int)
    for _ in range(m):
        d, c = map(int, sys.stdin.readline().split())
        a[d] += c
    

    b = 0
    for i in range(10):
        b += (i + 9) * a[i]
    
    ans = b // 9 - 1
    print(ans)
    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
M = int(input())
ans = 0
D = []
for m in range(M):
    d, c = map(int, input().split())
    dtc = d * c
    over = dtc // 10
    ans += c-1 + over
    D += [dtc % 10 + sum(map(int, str(over))) % 10]
# print(ans)
while len(D) >= 2:
    sumD = sum(map(int, D))
    over = sumD // 10
    ans += len(D) - 1 + over
    D = str(over + sumD % 10)
    sumD = sum(map(int, D))
    
print(ans)
# print(sumD)

Submission status: Wrong Answer

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


# 桁数*9 + 総和が 9 ずつ減る
M = int(sys.stdin.buffer.readline())
DC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

s = 0
l = 0
for d, c in DC:
    l += c
    s += d * c
ans = (l * 9 + s) // 9 - 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
m = int(input())
suuzi_list = []
total = 0
for i in range(0, m):
    d, c = map(int, input().split())
    if d == 0:
        total += c
    else:
        for j in range(0, c):
            suuzi_list.append(d)

while True:
    temp = []
    temp_total = 0
    i = 0
    while i < len(suuzi_list) - 1:
        if suuzi_list[i] + suuzi_list[i+1] == 10:
            temp_total += 2
            temp.append(1)
            i += 1
            if i + 1 == len(suuzi_list) - 1:
                temp.append(suuzi_list[i+1])
                break
        elif suuzi_list[i] + suuzi_list[i+1] > 10:
            temp_total += 1
            temp.append(1)
            temp.append((suuzi_list[i] + suuzi_list[i+1])%10)
            i += 1
            if i + 1 == len(suuzi_list) - 1:
                temp.append(suuzi_list[i+1])
                break
        else:
            temp.append(suuzi_list[i])
        i += 1
    if temp_total == 0:
        temp.clear()
        i = 0
        while i < len(suuzi_list) - 1:
            total += 1
            temp.append(suuzi_list[i] + suuzi_list[i+1])
            i += 1
            if i + 1 == len(suuzi_list) - 1:
                temp.append(suuzi_list[i+1])
                break
            i += 1
    else:
        total += temp_total
    if len(temp) == 1:
        break
    suuzi_list = temp
print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():

    M = int(input())

    ans = 0
    a = 0
    b = 0
    for i in range(M):
        d, c = map(int, input().split())
        a += c
        b += c * d
    v = b + a * 9
    # print(v)
    if v < 10: return 0
    if v % 9  == 1:
        return v // 9
    else:
        return v // 9 - 1

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
m = int(input())
cd = [list(map(int, input().split())) for _ in range(m)]
x = 0
result = -1
for i in range(m):
    x += cd[i][0]*cd[i][1]
    result += cd[i][1]
x = str(x)
result += len(x)-1
while int(x) >= 10:
    y = 0
    for i in range(len(x)):
        y += int(x[i])
    x = str(y)
    result += len(x)-1

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
m=int(input())
DC=[]
for i in range(m):
  DC.append(tuple(map(int,input().split())))
tot=0
for d,c in DC:
  tot+=c*(9+d)
print(tot//9-1)

Submission status: Wrong Answer

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


def func(a, b):
    return((a+b // 10) + (a+b)-10)


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

print(int((num-18-1) / 9) + 1)

Submission status: Wrong Answer

Solution code:
M = int(input())
ans = 0
D = []
for m in range(M):
    d, c = map(int, input().split())
    dtc = d * c
    over = dtc // 10
    ans += c-1 + over
    D += [dtc % 10 + sum(map(int, str(over))) % 10]
# print(ans)
ans += len(D) - 1
sumD = sum(D)
over = sumD // 10
ans += over
ans += over//10 + ((over // 10) % 10 + sumD%10) // 10

print(ans)
# print(sumD)