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

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

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)
p=[0]*10
for i in range(m):
    p[d[i]]+=c[i]
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])
            if s[i]>=5:
                i5+=1
        ret+=-(-i5//4)
        z=sum(s)
    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())
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//10
print(ans-1)

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 f(x,y):
  ret=y-1
  t=x*y
  while t>=10:
    ret+=t//10
    t//=10
  return ret
def g(x,y):
  ret=x*y
  while ret>=10:
    ret2=0
    for tt in str(ret):
      ret2+=int(tt)
    ret=ret2
  return ret
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:
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

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

Submission status: Wrong Answer

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

res = dcnt-1+(0 if calc < 10 else int(str(calc)[:-1]))
print(res)

Submission status: Wrong Answer

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

for i in range(1, len(str(sumd))+1):
    tmp = sumd // (10 ** i)
    sumd += tmp

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

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

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    m = int(input())
    dc = [list(map(int, input().split())) for i in range(m)]
    
    ans = 0
    n = []
    for i in range(m):
        if dc[i][0] == 0:
            n.append(0)
            ans += dc[i][1] - 1
            continue
        v = 10 / dc[i][0]
        ans += (dc[i][1] - 1)
        if dc[i][1] / v >= 1:
            ans += (1 + 2 * (dc[i][1] / v - 1))
            n.append(dc[i][1] / v)
        else:
            n.append(dc[i][0] * dc[i][1])
    
    #print(n, ans)
    
    l = []
    heapify(l)
    for i in range(len(n)):
        heappush(l, -n[i])

    while len(l) >= 2:
        v = -heappop(l)
        v2 = -heappop(l)
        if v + v2 >= 10:
            s = str(v+v2)
            heappush(l, -(int(s[0])))
            heappush(l, -(int(s[1])))

        else:
            heappush(l, -(v + v2))
        ans += 1
    print(ans)        
    


    
                    


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(1, len(str(sumd))):
    tmp = sumd // (10 ** i)
    sumd += tmp

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

Submission status: Wrong Answer

Solution code:
m = int(input())

sumd = 0
sumc = 0

for i in range(m):
  tmp = list(map(int, input().split()))
  d = tmp[0]
  c = tmp[1]
  sumd += d * c
  sumc += c

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N=int(input())
sum=0
ans=0
for i in range(N):
	c, d=map(int, input().split())
	sum=sum+c*d
	ans=ans+d
print(ans-1+sum//10)

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)
p=[0]*10
for i in range(m):
    p[d[i]]+=c[i]
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])
            if s[i]>=5:
                i5+=1
        ret+=i5//2
        z=sum(s)
    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:
# -*- 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, p))

        
    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())
s = 0
t = 0
for _ in range(M):
    d, c = map(int,input().split())
    s += d * c
    t += c

ans = (s//10) + t-1
print(ans)

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,0
for d,c in zip(D,C):
    x+=d*c//10
    y+=f(d*c)
print(sum(C)-1+x+y//10)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import bisect
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True

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


    m = II()
    dc = XLMIIS(m)

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

    print(k + s//9 - 1)






if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

kei10 = kei//9

output = keta-1 + kei10
print(output)

Submission status: Wrong Answer

Solution code:
def test(n):
    s = str(n)*100
    ste = 0
    while 1:
        ste += 1
        s = str(sum(map(int, s[:2])))+s[2:]
        done = 1
        for i in "0123456789":
            if i != str(n) and i in s:
                done = 0
                break
        if done:
            break
    return (ste, 100-len(s))

dct = []

for i in range(10):
    dct.append(test(i))

st = []
ans = 0

m = int(input())
for i in range(m):
    di, mu = map(int, input().split())
    for j in range(mu % dct[di][1]):
        st.append(di)
    ans += dct[di][0] * (mu // dct[di][1])


st = st[::-1]

while len(st) > 1:
    ans += 1
    a, b = st[-1], st[-2]
    st.pop()
    st.pop()
    s = str(a+b)[::-1]
    for c in s:
        st.append(int(c))

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) // 10
  y = (d * c) % 10
  res += x
  if x + y + t >= 10:
    res += 1
  t = (x + y + t) % 10
  r += c
print(res + r - 1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

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

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

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

print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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)
p=[0]*10
for i in range(m):
    p[d[i]]+=c[i]
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
        for i in range(len(s)):
            s[i]=int(s[i])
        z=sum(s)
    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())

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

ans = cnt//10 + cnt_c - 1
print(ans)

Submission status: Wrong Answer

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

# tmp = sumd
# while tmp > 10:
#     tmp = tmp // 10
#     sumd += tmp
sumd += sumd // 10
ans = sumd // 10 + sumc - 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

tmp = sumd
while tmp > 10:
    tmp = tmp // 10
    sumd += tmp

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

Submission status: Wrong Answer

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

kei10 = kei//10

output = keta-1 + kei10
print(output)

Submission status: Wrong Answer

Solution code:

m = int(input())

res = -1
sum = 0

def solve(sum) :
    r = 0;
    while r > 0 :
        r += sum%10
        r /= 10
    return r

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


while len(str(sum)) > 1 :
    res += len(str(sum)) - 1
    sum = solve(sum)

print(res)

Submission status: Wrong Answer

Solution code:
import math

M = int(input())
A = []

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]
ans = (digitSum-1) + countSum//10

#print(countSum)
#print(digitSum)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    m=int(input())
    ans=-1
    dsum=0
    for _ in range(m):
        d,c=map(int,input().split())
        ans+=c
        dsum+=c*d

    dsum=str(dsum)
    while(len(dsum)>1):
        ans+=len(dsum)-1
        dsum=sum(int(s) for s in dsum)
        dsum=str(dsum)
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys


def solve(M: int, d: "List[int]", c: "List[int]"):
    k = sum([dd*cc for (dd, cc) in zip(d, c)])
    counter = sum(c) - 1
    while k >= 10:
        s = 0
        while k > 0:
            s += k % 10
            k //= 10
            counter += 1
        counter -= 1
        k = s
    print(counter)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    M = int(next(tokens))  # type: int
    d = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        d[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(M, d, c)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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=0
for i in range(50):
    A+=S//(10**i)
print(C-1+A//10)

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=0
for i in range(25):
    A+=S//(10**i)
print(C-1+A//10)

Submission status: Wrong Answer

Solution code:
M = int(input())

dcnt = 0
calc = 0

S = ""
for i in range(M) :
    c,d = map(int,input().split())
    S += str(d)*c
    dcnt += d

    calc += d*c

res = dcnt-1 + calc//10
print(res)

Submission status: Wrong Answer

Solution code:
import sys

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

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
cha=[0,2,4,6,8,1,3,5,7,9]
m=int(input())
ans=0
from collections import deque
l=deque()
for _ in range(m):
    d,c=map(int,input().split())
    while c>1:
        if c%2:
            c-=1
            l.append(d)
        c//=2
        ans+=c
        d=cha[d]
    l.append(d)

k=len(l)
while k>1:
    a=l.pop()
    b=l.pop()
    x=a+b
    ans+=1
    if x>9:
        s=str(x)
        l.append(int(s[0]))
        l.append(int(s[1]))
    else:
        l.append(x)
        k-=1
print(ans)

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=0
for i in range(1,25):
    A+=S//(10**i)
print(C-1+A)

Submission status: Wrong Answer

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

ans = 0
len_ans = 0
for i in range(m):
    a, b = info[i]
    len_ans += b
    ans += a*b

ans = str(ans)
tmp = 0
for i in range(len(ans) - 1):
    t = (len(ans)-i-1) * ans[i]
    tmp += int(t)
print(tmp + len_ans - 1)

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())))
keta=0
tot=0
for d,c in DC:
  keta+=c
  tot+=d*c
ans=keta-1
while tot>=10:
  ans+=tot//10
  tot//=10
print(ans)

Submission status: Wrong Answer

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

#print(((gokei-1)//9)+cry)
if gokei%9==1:
    print(((gokei-1)//9)+cry-2)
else:
    print(((gokei-1)//9)+cry-1)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    v = LIR(n)
    ans = 0
    l = []
    p = [10**(i+1) for i in range(20)]
    for d,c in v:
        k = d*c
        f = 0
        for i in p:
            f += k//i
        ans += c-1+f
        k = list(map(int, list(str(k))))
        while len(k) > 1:
            s = sum(k)
            k = list(map(int, list(str(s))))
        l += k
    m = len(l)
    for i in range(m):
        l[i] = int(l[i])
    while len(l) > 1:
        ans += 1
        x = l.pop()
        y = l.pop()
        x += y
        k = list(map(int, list(str(x))))
        l += k
    print(ans)
    return

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

Submission status: Wrong Answer

Solution code:
def main():
    M = int(input())
    DC = [list(map(int, input().split())) for _ in range(M)]
    S = 0
    cS = 0
    for d, c in DC:
        cS += c
        S += d*c
    ans = cS - 1 + S//10
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    v = LIR(n)
    ans = 0
    l = []
    for d,c in v:
        k = d*c
        ans += c-1+(k//10)
        k = list(map(int, list(str(k))))
        while len(k) > 1:
            s = sum(k)
            k = list(map(int, list(str(s))))
        l += k
    m = len(l)
    for i in range(m):
        l[i] = int(l[i])
    while len(l) > 1:
        ans += 1
        x = l.pop()
        y = l.pop()
        x += y
        k = list(map(int, list(str(x))))
        l += k
    print(ans)
    return

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

Submission status: Wrong Answer

Solution code:
m = int(input())
keta = 0
fig_sum = 0
for i in range(m):
    a, b = map(int, input().split())
    fig_sum+=a
    keta+=b

sub = keta-1
sub+= fig_sum//10
print(sub)

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)
print(sum(c)-1)

Submission status: Wrong Answer

Solution code:
m = 0  # int(input())


def a(x):
    k = 0
    while len(x) > 1:
        x = str(int(str(int(x[0]) + int(x[1])) + x[2:len(x)]))
        k += 1
    return x, k


k = 0
x = ""
for _ in range(m):
    d, c = [int(i) for i in input().split()]
    x += str(d) * c
    x, ka = a(x)
    k += ka
print(k)

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)
print(sum(c))

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = -1
sss = 0

for i in range(n):
    ss = input().split(' ')
    x = int(ss[0])
    y = int(ss[1])
    ans += y
    sss += x*y
    ans += sss//9
    sss %= 9

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

ANS=A//10+keta-1

while A>=10:
    B=0
    for s in str(A):
        B+=int(s)

    ANS+=B//10
    A=B

print(ANS)

Submission status: Wrong Answer

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

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

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

print(sumc + sum1 // 10 - 1)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

# 桁数が減って総和は不変 or 桁数が不変で総和が-9
# 手順によらない
# 「桁数 * 9 + 和」が9ずつの減少量

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

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

Submission status: Wrong Answer

Solution code:
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	M = int(input())
	C = 0
	D = 0
	for i in range(M):
		d, c = getlist()
		C += c
		D += d * c
	ans = C - 1
	while True:
		if D >= 10:
			ans += D // 10
			D = sum(list(map(int, list(str(D)))))
		else:
			break
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

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())))
keta=0
tot=0
for d,c in DC:
  keta+=c
  tot+=d*c
print(keta-1+tot//10)

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


M = int(sys.stdin.buffer.readline())
DC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

ans = 0
num = 0
for i, (d, c) in enumerate(DC):
    n = num + d * c
    ans += c
    ans += n // 10
    num = n % 10
print(ans - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = -1
tmp = 0
for i in range(n):
  d, c = map(int, input().split())
  ans += c
  tmp += d * c
  ans += tmp // 10
  tmp %= 10 
print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    v = LIR(n)
    ans = 0
    l = []
    for d,c in v:
        ans += c-1
        k = d*c
        k = list(map(int, list(str(k))))
        l += k
    m = len(l)
    for i in range(m):
        l[i] = int(l[i])
    while len(l) > 1:
        ans += 1
        x = l.pop()
        y = l.pop()
        x += y
        k = list(map(int, list(str(x))))
        l += k
    print(ans)
    return

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

Submission status: Wrong Answer

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

ans += all // 10
print(ans)