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:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	M = inputInt()
	dc = []
	n = []
	for i in range(M):
		d,c = inputMap()
		dc.append((d,c))
		for i in range(c):
			n.append(d)

	ans = 0
	while True:
		if len(n) <= 1:
			print(ans)
			sys.exit()

		while True:
			for i,val in enumerate(n):
				flg = False
				if i == 0:
					continue

				tmp = val + n[i-1]
				if tmp >= 10:
					flg = True
					ans += 1
					tmp2 = str(tmp)
					tmp2 = list(tmp2)

					n[i-1] = int(tmp2[0])
					n[i]   = int(tmp2[1])
			if flg == False:
				break

		while True:
			if len(n) <= 1:
				print(ans)
				sys.exit()

			max = 0
			for i,val in enumerate(n):
				if i == 0:
					continue
				tmp = val + n[i-1]
				if max < tmp:
					max = tmp

			if max >= 10:
				break

			for i,val in enumerate(n):
				if i == 0:
					continue
				tmp = val + n[i-1]
				if tmp == max:
					ans += 1
					n[i-1] = 99
					n[i]   = max
			#print(n)
			n.remove(99)


if __name__ == "__main__":
	main()

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())))
ans=0
S=[]
def g(x,y):
  ret=x*y
  while ret>=10:
    ret2=0
    for tt in str(ret):
      ret2+=int(tt)
    ret=ret2
  return ret
def f(x,y):
  if y==1:
    return 0
  elif y%2==0:
    if x>=5:
      return y+f(g(x,2),y//2)
    else:
      return y//2+f(g(x,2),y//2)
  else:
    if x>=5:
      if g(x,y-1)+y>=10:
        return y+f(g(x,2),y//2)
      else:
        return y+f(g(x,2),y//2)-1
    else:
      if g(x,y-1)+y>=10:
        return y//2+f(g(x,2),y//2)
      else:
        return y//2+f(g(x,2),y//2)-1


for d,c in DC:
  ans+=f(d,c)
  S.append(g(d,c))
cur=S[0]
for i,s in enumerate(S):
  if i==0:
    continue
  else:
    ans+=1
    cur+=s
    if cur>=10:
      ans+=1
      cur=int(str(cur)[0])+int(str(cur)[1])
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
m=int(input())
ans=0
L=[]
for i in range(m):
    d,c=map(int,input().split())
    D=d*c
    ans+=c-1+D//10
    l=(D+D//100)%10
    L.append(l)
s=L[0]
l=len(L)
for i in range(1,l):
    x=s+L[i]
    if x>=10:
        ans+=2
        s=(x%10+x//10)%10
    else:
        ans+=1
        s=x
print(ans)

Submission status: Wrong Answer

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

m = int(input())
ans = 0
dc = []
prev = 0
for i in range(m):
    d, c = [int(item) for item in input().split()]
    ans += (prev + d * c) // 10
    ans += c 
    if i == m - 1 and (prev + d * c) <= 9:
        break
    prev = (prev + d * c) % 10

print(ans-1)

Submission status: Wrong Answer

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

m = int(input())
sum1 = 0
sumc = 0
ans = 0

for i in range(m):
    d,c = map(int,input().split())
    sum1 += d * c
    sumc += c

ans += sumc + sum1 // 9 - 1

print(ans)

Submission status: Wrong Answer

Solution code:
M=int(input())
C=0
S=0
for i in range(M):
    d,c=map(int,input().split())
    C+=c
    S+=d*c
#print(C,S)
A=S
for i in range(1,25):
    A+=S//10
    
    S//=10
print(C-1+A//10)
#print(A)

Submission status: Wrong Answer

Solution code:
total = 0
ans = 0

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

ans -= 1
if total > 10:
    ans += total // 10 - 1

print(ans, total)

while total >= 10:
    t = str(total)
    ans += len(t) - 1
    s = sum(map(int, t))
    if s > 10:
        ans += s // 10 - 1
    total = s

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    M = int(input())
    S = ""
    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)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
m = int(input())
DC = [list(map(int, input().split())) for _ in range(m)]
keta = sum(c for _, c in DC)
yo = sum(d*c for d, c in DC) // 10
print(keta+yo-1)

Submission status: Wrong Answer

Solution code:
m = int(input())
d = []
c = []
s = 0
ans = -1
for i in range(m):
  d,c = map(int,input().split())
  s += d*c
  ans += c + ((d*c) // 10 - len(str(d*c)) + 1)

while s >= 10:
  tmp = s
  l = []
  while tmp > 0:
    l.append(tmp%10)
    tmp //= 10
  ans += len(l)-1
  s = sum(l) + sum(l)//10 - len(str(sum(l))) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


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


# A
def A():
    X, Y = LI()
    ans = 0
    if X == 1:
        ans += 300000
    elif X == 2:
        ans += 200000
    elif X == 3:
        ans += 100000

    if Y == 1:
        ans += 300000
    elif Y == 2:
        ans += 200000
    elif Y == 3:
        ans += 100000

    if X == 1 and Y == 1:
        ans += 400000

    print(ans)
    return


# B
def B():
    N = I()
    A = LI()
    A_sum = sum(A)
    cnt = 0
    ans = sum(A)
    for i in range(N):
        cnt += A[i]
        sa = abs(A_sum - cnt - cnt)
        ans = min(ans, sa)
    print(ans)
    return


# C
def C():
    H, W, K = LI()
    s = [S() for i in range(H)]
    ans = [[0] * W for i in range(H)]
    cnt = 1
    index = 0
    for i in range(H):
        if '#' in s[i]:
            index = i
            break

    for i in range(i, H):
        ichigo = 0
        for j in range(W):
            if s[i][j] == '#' and ichigo == 0:
                ichigo += 1
                ans[i][j] = cnt
            elif s[i][j] == '#' and ichigo != 0:
                cnt += 1
                ans[i][j] = cnt
            else:
                ans[i][j] = cnt
        if ichigo == 0:
            ans[i] = ans[i - 1]
        else:
            cnt += 1

    for i in range(0, index):
        ans[i] = ans[index]

    for i in range(H):
        print(' '.join([str(j) for j in ans[i]]))
    return


# D
def D():
    M = I()
    d = [0] * M
    c = [0] * M
    for i in range(M):
        d[i], c[i] = LI()
    dc_sum = 0
    c_sum = 0
    for i in range(M):
        dc_sum += d[i] * c[i]
        c_sum += c[i]
    ans = c_sum - 1
    for i in str(dc_sum)[:-1].split():
        if i == '0':
            ans += 10
        else:
            ans += int(i)
    print(ans)
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    D()
    return


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
m=int(input())
answer=0
for i in range(m):
  a,b=map(int,input().split())
  if a==0 and b>1:
    b-=1
  answer+=b
print(answer)

Submission status: Wrong Answer

Solution code:
M = int(input())

digitSum = 0
countSum = 0
ans =0

for i in range(0,M):
    CiDi = [int(i) for i in input().split()]
    countSum = countSum +  CiDi[0] * CiDi[1]
    digitSum = digitSum +  CiDi[1]

ans1 = countSum//10 + countSum//100 + countSum//1000 + countSum//10000 + countSum//100000 
ans2 = countSum//1000000 + countSum//10000000 + countSum//100000000 + countSum//1000000000 + countSum//10000000000 
ans3 = countSum//100000000000 + countSum//1000000000000 + countSum//10000000000000 + countSum//100000000000000 + countSum//1000000000000000
ans4 = countSum//10000000000000000
ans = (digitSum-1) + ans1 + ans2 + ans3 + ans4
#print(countSum)
#print(digitSum)
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def main():
    M = int(input())
    S = 0
    x = 0

    for _ in range(M):
        D, C = map(int, input().split())
        S += D*C
        x += C

    while S > 9:
        x += S//10
        
        s = 0
        S2 = S
        while S2 > 0:
            s += S2%10
            S2 //= 10

        S = s

    print(x-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
d=[];c=[]
for i in range(N):
    di,ci=map(int,input().split())
    d.append(di);c.append(ci)
# print(d) #DB
# print(c) #DB
s=sum([d[i]*c[i] for i in range(N)])
# print(s) #DB
t=0
while s>=10:
    s=s//10+s%10
    t+=s

ans=sum(c)-1+t
print(ans)

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

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):
    ans = 0
    r = 0
    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)
    error_print(C)
    ans = 0
    r = 0
    for c, d in CD:
        if d >= C[c][1]:
            ans += (d // C[c][1]) * C[c][2]
            d %= C[c][1]
        t = [c] * d

        for v in t:
            r += v
            ans += 1
            if r >= 10:
                ans += 1
                r = r % 10 + r // 10

    return ans -1 


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
m = int(input())
dc =  [list(map(int,input().split())) for _ in range(m)]
flag = 0
ans = -1
x = 0
for i in range(m):
  x += dc[i][0]*dc[i][1]
  ans += dc[i][1]
while(flag == 0):
  n = len(str(x))
  ans += x // 10 
  x = sum(list(map(int,str((x)))))
  if n == 1:
    flag = 1
    break
print(ans)

Submission status: Wrong Answer

Solution code:
m = int(input())
c = [0] * 10
n = 0
for i in range(m):
    d, dd = map(int, input().split())
    c[d] += dd
    n += dd

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

print(n - 1 + (s // 10))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

print(s)

ans=s//9

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

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

print(ans-1)

Submission status: Wrong Answer

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

M=int(input())
L=[tuple(map(int,input().split())) for _ in range(M)]
sumD=sum([x for _,x in L])-1
cnt={x:0 for x in range(0,10)}

for x,c in L:
    cnt[x]+=c
ans=0
R=[]
for x in range(1,10):
    c=cnt[x]
    if c==0:continue
    elif c==1:
        R.append(x)
        continue
    while c>0:
        c,mod=divmod(c,2)
        if mod==1:R.append(x)
        x*=2
        if x//10==1:
            x=sum(map(int,(str(x))))
            ans+=c
    R.append(x)
p=0
for x in R:
    p+=x
    if p//10==1:
        x=sum(map(int,str(x)))
        ans+=1
print(ans+sumD)

Submission status: Wrong Answer

Solution code:
m = int(input())
d = []
c = []
s = 0
ans = -1
for i in range(m):
  d,c = map(int,input().split())
  s += d*c
  ans += c + ((d*c) // 10 - 1)

while s >= 10:
  tmp = s
  l = []
  while tmp > 0:
    l.append(tmp%10)
    tmp //= 10
  ans += len(l)-1
  s = sum(l) + sum(l)//10 - 1
print(ans)

Submission status: Wrong Answer

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

m = int(input())
sum1 = 0
sumc = 0
ans = 0

for i in range(m):
    d,c = map(int,input().split())
    sum1 += d * c
    sumc += c
    if d == 9 and c >= 11:
        ans += c // 11

ans += sumc + sum1 // 10 - 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math

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

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


ans+=M-1 + sum(b)//10
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
m=int(input())
ans=0
L=[]
for i in range(m):
    d,c=map(int,input().split())
    D=d*c
    ans+=c-1+D//10
    l=(D+D//100)%10
    L.append(l)
s=L[0]
l=len(L)
for i in range(1,l):
    x=s+L[i]
    if x>=10:
        ans+=2
        s=x%10
    else:
        ans+=1
        s=x
print(ans)

Submission status: Wrong Answer

Solution code:
m=int(input())
answer=-1
for i in range(m):
  a,b=map(int,input().split())
  answer+=b
print(answer)

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
i = 1
r = 0
while(D // (10 ** i) > 0):
  r += D // (10 ** i)
  i += 1
print(C - 1 + r)

Submission status: Wrong Answer

Solution code:
m=int(input())
d=[]
c=[]
for i in range(m):
    a,b=map(int,input().split())
    d.append(a)
    c.append(b)
ans=0
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())
num = [list(map(int,input().split())) for i in range(m)]
sum=0
out=0
for i in range(m):
  sum+=(num[i][0]*num[i][1])
  out+=num[i][1]
#print(sum)  
out+=(sum-sum%10)/10
print(int(out-1))

Submission status: Wrong Answer

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

short = []
additional = 0
for elm in L:
    additional += (elm[1] - 1)
    total = elm[0] * elm[1]
    additional += (total - 1) // 9
    if total > 9:
        res = total % 9
    else:
        res = total
    short.append(res)

prev = 0
additional += len(short) - 1
for elm in short:
    prev = prev + elm
    if prev > 9:
        prev -= 9
        additional += 1

print(additional)

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

Submission status: Wrong Answer

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

M = int(input())

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

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

print(ans + sum(C) - 1)

Submission status: Wrong Answer

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

n = 0
sum = 0
for i in range(m):
    n += digit[i][1]
    sum += digit[i][0]*digit[i][1]
print(n+(sum+1)//10-1)

Submission status: Wrong Answer

Solution code:
M=int(input())
D,C=zip(*[map(int,input().split()) for i in range(M)])
def f(n):
    return sum([int(c) for c in str(n)])
x,y=0,[]
for d,c in zip(D,C):
    z=d*c
    x+=z//10
    w=f(z)
    while w>9:
        w=f(w)
        x+=1
    y.append(w)
v=sum(y)
while v>9:
    v=f(v)
    x+=1
print(sum(C)-1+x+v)

Submission status: Wrong Answer

Solution code:
M = int(input())

lis = [0] * 10
able =0

for i in range(M):

    d,c = map(int,input().split())

    lis[d] = c

    able += d * c

#print (sum(lis),able)

ans = 0
now = 10

while able >= now:
    ans += (able % (now * 10)) // now
    now *= 10
    
print ( sum(lis) - 1 + ans )

Submission status: Wrong Answer

Solution code:
M = int(input())

A = []
for i in range(M):
    t1, t2 = map(int, input().split())
    for _ in range(t2):
        A.append(t1)

    count = 0
B = True
while B == True:
    if len(A) < 2:
        B = False
        break
    tmp1 = A.pop()
    tmp2 = A.pop()

    tmp3 = tmp1 + tmp2
    if tmp3 > 9:
        tmp1 = tmp3 % 10
        tmp2 = (tmp2 -tmp1) // 10
        A.append(tmp2)
        A.append(tmp1)
    else:
        A.append(tmp3)
    count += 1
print(count)

Submission status: Wrong Answer

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

m = inp()
d = [0] * m
c = [0] * m
res = 0
for i in range(m):
    d[i], c[i] = inpl()
    res = d[i]*c[i]

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

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:
            s.append([d, (c % memo[d][2])])
    if not s:
        print(ans)
        return

    t = s[0][0]
    s[0][1] -= 1
    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
        if s[i][0] == 2:
            ans += s[i][1] - 1
            if s[i][1] >= 4:
                ans += 1
            t += [2, 4, 6, 8, 1, 1, 3, 5, 7, 9, 1][s[i][1]-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)

main()

Submission status: Wrong Answer

Solution code:
import sys
import math



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

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


ans+=M-1 + sum(b)//10
print(ans)

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

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):
    ans = 0
    r = 0
    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+1))
    
    error_print(C)
    ans = 0
    r = 0
    for c, d in CD:
        if d >= C[c][1]:
            ans += (d // C[c][1]) * C[c][2]
            d %= C[c][1]
        t = [c] * d

        for v in t:
            r += v
            ans += 1
            if r >= 10:
                ans += 1
                r = r % 10 + r // 10

    return ans -1 


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N=int(input())
d=[];c=[]
for i in range(N):
    di,ci=map(int,input().split())
    d.append(di);c.append(ci)
# print(d) #DB
# print(c) #DB
s=sum([d[i]*c[i] for i in range(N)])
# print(s) #DB
t=0
while s>10:
    s=s//10+s%10
    t+=s

ans=sum(c)-1+t
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    #print = out.append
    ''' Cook your dish here! '''
    m = get_int()
    sm = 0
    smc = 0
    for _ in range(m):
        a, b = get_list()
        sm += a*b
        smc += b
    print(smc-1 + (sm//9))

''' Coded with love at India by Satyam Kumar '''
import sys
#from collections import defaultdict
#import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')

Submission status: Wrong Answer

Solution code:
import sys

def sol(tmp_val, ans):
  while tmp_val >= 10:
    str_tmp_val = str(tmp_val)
    tmp_val = int(str(int(str_tmp_val[0])+int(str_tmp_val[1])) + str_tmp_val[2:])
    ans += 1
  return ans, tmp_val

M = int(input())
ans = 0
prv_val_str = ''
for i in range(M):
  d,c = map(int,sys.stdin.readline().split())
  ans += c-1
  tmp_val = d*c
  ans, prv_val = sol(int(prv_val_str+str(tmp_val)), ans)
  prv_val_str = str(prv_val)
print(ans)

Submission status: Wrong Answer

Solution code:
m = int(input())
d = []
c = []
for i in range(m):
    line = list(map(int, input().split()))
    d.append(line[0])
    c.append(line[1])
omake = 0
cnt = 0
for i in range(m):
    cnt += d[i]*c[i]
omake += cnt//10
print(sum(c)+omake-1)

Submission status: Wrong Answer

Solution code:
m=int(input())
d=[]
c=[]
for i in range(m):
    a,b=map(int,input().split())
    d.append(a)
    c.append(b)
ans=0
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-1
    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)