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 deque
def main():
    M = int(input())
    deq = []
    for i in range(M):
        deq.append(tuple([int(x) for x in input().split()]))
    deq = deque(list(reversed(deq)))
    res = 0
    i = 0
    while True:
        if len(deq) == 1:
            break
        # print(len(deq))
        # print(deq[-1], deq[-2])
        if deq[-1][1] == 0 or deq[-1][0] == 0:
            deq.pop()
        elif deq[-1][1] == 1:
            nd =deq[-1][0]+deq[-2][0]
            old_last = deq.pop()
            old_second_last = deq.pop()
            new_last = (nd //10, 1)
            new_second_last = (nd % 10, 1)
            new_third_last = (old_second_last[0], old_second_last[1]-1)
            if new_third_last[1] != 0:
                deq.append(new_third_last)
            if new_second_last[1] != 0:
                deq.append(new_second_last)
            if new_last[1] != 0:
                deq.append(new_last)
            res += 1
        else:
            d, c = deq.pop()
            nd = (d * c + (d * c) // 10)%10
            nc = (c - 1 + ((d * c) // 10))
            # print(nc)
            res += nc
            deq.append((nd, 1))
    print(res)
main()



# def main():
#     S = input()
#     i, bans, s = a(S, [])
#     print(i)
#     print(bans)
#     print(s)
# def a(S, bans):
#     if int(S) <= 9:
#         return 0, bans, int(S)
#     res = -1
#     bann = (0,1)
#     ssss = -1
#     for i in range(len(S)-1):
#         m, b, suu = a(S[:i] + str(int(S[i]) + int(S[i+1])) + S[i+2:], [*bans, (i,i+1)])
#         if m > res:
#             bb = b
#             res = m
#             bann = (i,i+1)
#             ssss = suu
#     bans = bb
#     return res + 1, bans, ssss
# main()

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
ds=0
d=0
for i in range(n):
  d1,c=map(int,input().split())
  ds+=d1*c
  d+=c
if d%9==0:
  count=ds//9-1
else:
  count=ds//9
print(count+d-1)

Submission status: Wrong Answer

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

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

answer = dig_sum // 9 + dig - 1
print(answer)

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


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

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)
  
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]
        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)
    
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:
n=int(input())
ds=0
d=0
for i in range(n):
  d,c=map(int,input().split())
  ds+=d*c
  d+=c
if d%9==0:
  count=ds//9-1
else:
  count=ds//9
print(count+d-1)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = []


co = 0

onon = [0 for i in range(10)]
"""
for i in range(n):
    z,x = m()
    if z == 0:
        co += x
    if z == 1:
        kkk = x % 10
        onon[kkk] += 1
        kk = x // 10
        onon[1] += kk
        co += x-1
    if z == 2:
        kkk = x % 5
        onon[kkk*2] += 1
        kk = x // 5
        onon[1] += kk
        co += x-1
    if z == 3:
        kkk = x % 10
        ppp = x//3
        kk = x // 10
        onon[kkk*3 % 10] += 1
        onon[1] += kk + ppp
        co += x-1
    if z == 4:
        kkk = x % 5
        kk = x // 5
        onon[kkk*4%10] += 1
        onon[1] += kk
        if x-kk*5 >= 3:
            onon[1] += 1
        co += x-1
    if z == 5:
        kkk = x % 2
        kk = x // 2
        onon[kkk*5] += 1
        onon[1] += kk
        co += x-1
    if z == 6:
        kkk = x % 5
        kk = x // 5
        onon[kkk*5%10] += 1
        onon[1] += kk
        if x-kk*5 >= 2:
            onon[1] += 1
            if x-kk*5 == 4:
                onon[1] += 1
        co += x-1
    if z == 7:
        op = [0,0,1,2,2,3,4,4,5,6]
        kkk = x % 10
        kk = x // 10
        onon[kkk*7%10] += 1
        onon[1] += op[kkk]
        co += x-1
    if z == 8:
        kkk = x % 5
        kk = x // 5
        co += x-1
    if z == 9:
        kkk = x % 11
        kk = x // 11
        co += x-1
"""

re = [0 for i in range(10)]

for i in range(n):
    z,x = m()
    kkk = z*x
    ppp = kkk%10
    pp = kkk//10
    if pp != 0:
        while pp >= 10:
            p = pp % 10
            onon[p] += 1
            pp //= 10
        onon[pp] += 1
    if pp != 0:
        re[1] = 1
    onon[ppp] += 1
    re[ppp] = 1
    co += x-1
while True:
    if all(onon[po] <= 1 for po in range(1,10)):
        break
    for i in range(9,-1,-1):
        if re[i] == 1:
            z,x = i,onon[i]
            re[i] = 0
            kkk = z*x
            ppp = kkk%10
            pp = kkk//10
            if pp != 0:
                while pp >= 10:
                    p = pp % 10
                    onon[p] += 1
                    pp //= 10
                onon[pp] += 1
            if pp != 0:
                re[1] = 1
            onon[ppp] += 1
            re[ppp] = 1
            break
ni = 0
for i in range(1,11):
    if i == 10:
        i = 0
    if onon[i]:
        ni = ni*10 + i*onon[i]
"""
while True:
    if ni < 10:
        break
    else:
        l = ni%10
        ni //= 10
        ll = ni%10
        ni //= 10
        if l + ll >= 10:
            co += 2
            ni = ni*10 + ((l + ll)%10)
        else:
            co += 1
            ni = ni*10 + ((l + ll)%10)

        
print(co)

"""

Submission status: Wrong Answer

Solution code:
M = int(input())
dc = [list(map(int,input().split())) for _ in range(M)]
ans = 0
s = 0
for i in dc:
  d = i[0]
  c = i[1]
  ans += c
  s+=d*c
  if s>=10:
    t = s//9
    ans+=t
    s-= t*9

ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
M=int(input())
memo=[[[0,i] for _ in range(9)] for i in range(10)]
for c in range(10):
  n=[c]*9
  m=0
  d=0
  while len(n)>1:
    m+=1
    x=n[-1]+n[-2]
    n.pop(-1)
    n.pop(-1)
    if x>=10:
      n.append(x-10)
      n.append(1)
    else:
      n.append(x)
      memo[c][d+1]=[m,x]
      d+=1

N=[]
ans=0
for i in range(M):
  d,c=map(int,input().split())
  N.append(memo[d][(c-1)%9][1])
  ans+=memo[d][(c-1)%9][0]+memo[d][8][0]*(c//9)

while len(N)>1:
  ans+=1
  x=N[-1]+N[-2]
  N.pop(-1)
  N.pop(-1)
  if x>=10:
    N.append(x-10)
    N.append(1)
  else:
    N.append(x)


print(ans)

Submission status: Wrong Answer

Solution code:
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353


def main():
    M = int(input())
    # d = [0] * M
    # c = [0] * M
    digits = []
    # d = sorted(d)

    for i in range(M):
        d, c = list(map(int, input().split()))

        if d == 0 and i == 0:
            continue

        for i in range(c):
            digits.append(d)

    if len(digits) == 1:
        print(0)
        return

    if len(digits) == 2:
        if digits[0] == 0:
            print(0)
        else:
            print(1)
        return

    # print(digits)
    ith = 1
    nxt = digits[0] + digits[1]
    # print(nxt)
    for i in range(2, len(digits)):
        if nxt + digits[i] >= 10:
            nxt = nxt % 10
            ith += 2
        else:
            nxt = nxt + digits[i]
            ith += 1

    print(ith)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
M = int(input())
ans, rem = 0, []

for _ in range(M):
    d, c = map(int, input().split())
    if d == 0:
        ans += c
    else:
        ans += c - 1
        for s in str(d * c):
            rem.append(int(s))

ans += len(rem) - 1
sumr, rem = sum(rem), []

while len(str(sumr)) > 1:
    for s in str(sumr):
        rem.append(int(s))
    ans += len(rem) - 1
    sumr, rem = sum(rem), []

print(ans)

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

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    m = int(readline())
    dl = []
    cl = []
    s = 0
    for _ in range(m):
        d, c = list(map(int, readline().split()))
        dl.append(d)
        cl.append(c)
        s += d * c
    cnt = 0
    while True:
        if s >= 10:
            s = s // 10 + s % 10
            cnt += 1
        else:
            break
    print(sum(cl) + cnt - 1)


if __name__ == '__main__':
    solve()

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

Submission status: Wrong Answer

Solution code:
def f(num):
    out=0
    for n in str(num):
        out+=int(n)
    return out

def solve():
    current=0
    M=int(input())
    total=0
    for m in range(M):
        d,c=[int(x) for x in input().split()]

        total+=(c-1)+d*c//9

        
        now=f(d*c)
        if now+current>=10:
            total+=2
        elif m:
            total+=1
            
        current=now
        
    return total

print(solve())

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

Submission status: Wrong Answer

Solution code:
from math import *
from collections import *
import sys
sys.setrecursionlimit(10**9)
m = int(input())
a = [[0 for i in range(9)] for i in range(10)]
a[1] = [9,1,2,3,4,5,6,7,8]
a[2] = [9,2,4,6,8,1,3,5,7]
a[3] = [9,3,6,9,3,6,9,3,6]
a[4] = [9,4,8,3,7,2,6,1,5]
a[5] = [9,5,1,6,2,7,3,8,4]
a[6] = [9,6,3,9,6,3,9,6,3]
a[7] = [9,7,5,3,1,8,6,4,2]
a[8] = [9,8,7,6,5,4,3,2,1]
a[9] = [9,9,9,9,9,9,9,9,9]
ans = 0
ct = 0
for i in range(m):
	c,d = map(int,input().split())
	ans += a[c][d%9]
	if(c != 0):
		s = 10/c
		ct += d//s + d-1
	else:
		ct += d-1
	#print(ans,ct)
	if(ans >= 10):
		ans += 1
		ans %= 10
		ct += 1
print(int(ct)+m-1)

Submission status: Wrong Answer

Solution code:
M = int(input())
nums = [tuple(map(int, input().split())) for _ in range(M)]
digits = sum(t[1] for t in nums)
d_sum = sum(t[0] * t[1] for t in nums)
ans = digits - 1 + d_sum // 9
print(ans)

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

def main():
    m = int(input())
    ans = 0
    a = 0
    for i in range(m):
        d, c = map(int, input().split())
        ans += c
        a += d * c
    print(ans + a // 9 - 1)

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):
  ret=0
  res=[]
  cur=x
  while y>1:
    if y%2==0:
      if cur>=5:
        ret+=y
        cur=(2*cur)%10+1
      else:
        ret+=y//2
        cur*=2
    else:
      res.append(cur)
      if cur>=5:
        ret+=y-1
        cur=(2*cur)%10+1
      else:
        ret+=y//2
        cur*=2
    y//=2
  res.append(cur)
  if res:
    cur=res[0]
    for i,r in enumerate(res):
      if i==0:
        continue
      else:
        cur+=r
        if cur>=10:
          ret+=1
          cur=cur%10+1

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
M = int(input())
dc = [list(map(int, input().split())) for _ in range(M)]
 
d = [dc[i][0] for i in range(M)]
c = [dc[i][1] for i in range(M)]
 
ans = sum(c) - 1
s = 0
 
for i in range(M):
    s += c[i] * d[i]
    if s % 9 != 0:
        ans += s // 9
    else:
        ans += s//9 - 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 + (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 + sum(l)//10 - len(str(sum(l))) + 1
  s = sum(l)
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//9
print(sum(c)+omake-1)

Submission status: Wrong Answer

Solution code:
m=int(input())
l=[list(map(int,input().split())) for i in range(m)]
ct=0;sum=0
for i in range(m):
  ct+=l[i][0]*l[i][1]
  sum+=l[i][1]
print(sum-1+(ct//9))

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]
    if total > 9:
        if total % 9 == 0:
            additional += (total // 9) - 1
        else:
            additional += total // 9
        # 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())
SU=0
SC=0

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

if SC==1:
    print(1)
    exit()

ans=SC-1+SU//9
print(ans)

Submission status: Wrong Answer

Solution code:
m=int(input())
l=[list(map(int,input().split())) for i in range(m)]
ct=0;sum=0
for i in range(m):
  ct+=l[i][0]*l[i][1]
  sum+=l[i][1]
print(sum-1+(ct//9)-1)

Submission status: Wrong Answer

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

def counter(cur):
    # print(cur)
    if len(cur) >= 2:
        s = cur[0] + cur[1]
        if s >= 10:
            cur[0] = s // 10
            cur[1] = s % 10
            return counter(cur) + 1
        else:
            return counter([s] + cur[2:]) + 1
    else:
        return 0


counter([8,8,8,8,8])
a = []
b = []
for i in range(m):
    d = dc[i][0]
    c = dc[i][1]

    a.append(counter([d] * 10) * (c // 10) + counter([d] * (c % 10)))

    cur = d * c
    while True:
        if cur < 10:
            break
        else:
            cur = cur // 10 + cur % 10
    b.append(cur)

print(counter(b) + sum(a))

Submission status: Wrong Answer

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

def zero(n):
    return n - 1, "0"

def one(n):
    ret = 0
    while n // 10:
        q, r = divmod(n, 10)
        n = q + r
        ret += 10 * q
    ret += n - 1
    return ret, "1"

def two(n):
    ret = 0
    q, r = divmod(n, 5)
    ret += 5 * q
    one_cnt, ones = one(q)
    ret += one_cnt
    ret += r - 1
    return ret, ones + str(2 * r)

def three(n):
    ret = 0
    while n // 4:
        q, r = divmod(n, 4)
        n = q + r
        ret += 4 * q
    ret += n - 1
    return ret, str(3 * n)

def four(n):
    ret = 0
    q, r = divmod(n, 3)
    ret += 3 * q
    three_cnt, threes = three(q)
    ret += three_cnt
    ret += r - 1
    return ret, threes + str(4 * r)

def five(n):
    ret = 0
    q, r = divmod(n, 2)
    ret += 2 * q
    one_cnt, ones = one(q)
    ret += one_cnt
    ret += r - 1
    return ret, ones + str(5 * r)

def six(n):
    ret = 0
    q, r = divmod(n, 2)
    ret += 2 * q
    three_cnt, threes = three(q)
    ret += three_cnt
    ret += r - 1
    return ret, threes + str(6 * r)

def seven(n):
    ret = 0
    q, r = divmod(n, 2)
    ret += 2 * q
    five_cnt, fives = five(q)
    ret += five_cnt
    ret += r - 1
    return ret, fives + str(7 * r)

def eight(n):
    ret = 0
    q, r = divmod(n, 2)
    ret += 2 * q
    one_cnt, ones = seven(q)
    ret += one_cnt
    ret += r - 1
    return ret, ones + str(8 * r)

def nine(n):
    ret = 0
    while n // 2:
        q, r = divmod(n, 2)
        n = q + r
        ret += 2 * q
    ret += n - 1
    return ret, str(9 * n)

new_dc = []
fs = [zero, one, two, three, four, five, six, seven, eight, nine]
for d, c in dc:
    cnt, s = fs[d](c)
    new_dc.append([cnt, s])

s = ""
cnt = 0
for d, c in new_dc:
    s += c
    cnt += d

while len(s) > 1:
    tmp = int(s[-1]) + int(s[-2])
    s = s[:-2] + str(tmp)
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = []


co = 0

onon = [0 for i in range(10)]
"""
for i in range(n):
    z,x = m()
    if z == 0:
        co += x
    if z == 1:
        kkk = x % 10
        onon[kkk] += 1
        kk = x // 10
        onon[1] += kk
        co += x-1
    if z == 2:
        kkk = x % 5
        onon[kkk*2] += 1
        kk = x // 5
        onon[1] += kk
        co += x-1
    if z == 3:
        kkk = x % 10
        ppp = x//3
        kk = x // 10
        onon[kkk*3 % 10] += 1
        onon[1] += kk + ppp
        co += x-1
    if z == 4:
        kkk = x % 5
        kk = x // 5
        onon[kkk*4%10] += 1
        onon[1] += kk
        if x-kk*5 >= 3:
            onon[1] += 1
        co += x-1
    if z == 5:
        kkk = x % 2
        kk = x // 2
        onon[kkk*5] += 1
        onon[1] += kk
        co += x-1
    if z == 6:
        kkk = x % 5
        kk = x // 5
        onon[kkk*5%10] += 1
        onon[1] += kk
        if x-kk*5 >= 2:
            onon[1] += 1
            if x-kk*5 == 4:
                onon[1] += 1
        co += x-1
    if z == 7:
        op = [0,0,1,2,2,3,4,4,5,6]
        kkk = x % 10
        kk = x // 10
        onon[kkk*7%10] += 1
        onon[1] += op[kkk]
        co += x-1
    if z == 8:
        kkk = x % 5
        kk = x // 5
        co += x-1
    if z == 9:
        kkk = x % 11
        kk = x // 11
        co += x-1
"""

re = [0 for i in range(10)]

for i in range(n):
    z,x = m()
    kkk = z*x
    ppp = kkk%10
    pp = kkk//10
    if pp != 0:
        while pp >= 10:
            p = pp % 10
            onon[p] += 1
            pp //= 10
        onon[pp] += 1
    if pp != 0:
        re[1] = 1
    onon[ppp] += 1
    re[ppp] = 1
    co += x-1
while True:
    if all(onon[po] <= 1 for po in range(1,10)):
        break
    for i in range(9,-1,-1):
        if re[i] == 1:
            z,x = i,onon[i]
            re[i] = 0
            kkk = z*x
            ppp = kkk%10
            pp = kkk//10
            if pp != 0:
                while pp >= 10:
                    p = pp % 10
                    onon[p] += 1
                    pp //= 10
                onon[pp] += 1
            if pp != 0:
                re[1] = 1
            onon[ppp] += 1
            re[ppp] = 1
            break
ni = 0
for i in range(1,11):
    if i == 10:
        i = 0
    if onon[i]:
        ni = ni*10 + i*onon[i]


while True:
    if ni < 10:
        break
    else:
        l = ni%10
        ni //= 10
        ll = ni%10
        ni //= 10
        if l + ll >= 10:
            co += 2
            ni = ni*10 + ((l + ll)%10)
        else:
            co += 1
            ni = ni*10 + ((l + ll)%10)

        
print(co)

Submission status: Wrong Answer

Solution code:
m = int(input())
cd = [list(map(int, input().split())) for _ in range(m)]
r = [0 for _ in range(10)]
for i in range(len(cd)):
    r[cd[i][0]] += cd[i][1]
result = sum(r)
x = 0
for i in range(1, 10):
    x += r[i]*i
result += x//10
print(result-1)

Submission status: Wrong Answer

Solution code:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

m = inn()
cnt = 0
a = []
for i in range(m):
    d,c = inm()
    while c>1:
        if c%2 == 1:
            a.append(d)
            c -= 1
        if d<5:
            d = 2*d
        else:
            d = 2*d-9
        c //= 2
        cnt += c
    a.append(d)

ddprint("cnt {}  a:".format(cnt))
ddprint(a)

x = a.pop()
while len(a)>0 or x>9:
    if x>9:
        x = (x//10)+(x%10)
        cnt += 1
    else:
        y = a.pop()
        x += y
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():

    M = int(input())

    a, b = [], []
    ans = -1
    v = 0
    for _ in range(M):
        d, c = map(int, input().split())
        a.append(d)
        b.append(c)
        ans += c
        s = list(str(v))
        k = 0
        for e in s: k += int(e)
        ans += len(s) -1
        ans += (k + c * d) // 10
        v += c * d
    return ans

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

Submission status: Wrong Answer

Solution code:
M = int(input())
dc = [list(map(int,input().split())) for _ in range(M)]
ans = 0
s = 0
for i in dc:
  d = i[0]
  c = i[1]
  ans += c
  s+=d*c
  if s>=9:
    t = s//9
    ans+=t
    s-= t*9
 
ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
def main():

    M = int(input())

    a, b = [], []
    ans = -1
    v = 0
    for _ in range(M):
        d, c = map(int, input().split())
        a.append(d)
        b.append(c)
        ans += c
        s = list(str(v))
        k = 0
        for e in s: k += int(e)
        ans += len(str(k)) - 1
        ans += (k + c * d) // 10
        v += c * d
    return ans

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

Submission status: Wrong Answer

Solution code:
M = int(input())
ans = 0
S = ''
for i in range(M):
    d, c = map(int, input().split())
    ans += (c * d) // 9
    l = str(d * c)[-1]
    S += l


S = list(S)
while len(S) > 1:
    a, b = int(S.pop()), int(S.pop())
    ans += 1
    x = str(a + b)
    if len(x) == 2:
        S.append(x[0])
        S.append(x[1])
    else:
        S.append(x[0])


print(ans)

Submission status: Wrong Answer

Solution code:
def convert(num_list):
    length=len(num_list)
    
    target=0
    max_value=0
    for idx in range(length-1):
        if (max_value < num_list[idx]+num_list[idx+1]):
            target=idx
            max_value=num_list[idx]+num_list[idx+1]
    
    del(num_list[target+1])
    
    converted_list=num_list[0:target]
    converted_list.extend(list(map(int,list(str(max_value)))))
    converted_list.extend(num_list[target:-1])

    print('=>', converted_list)
    
    return converted_list

M=int(input())
number=[]
for _ in range(M):
    d,c=map(int,input().split())
    number.extend([d for _ in range(c)])

print(number, ''.join(list(map(str,number))))

count=0
while (9 < int(''.join(list(map(str,number))))):
    number=convert(number)
    print(number)
    count+=1

print(count)

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:
    t+=s//10
    s=s//+s%10

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

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
sumD = sum(D)
while sumD >= 10:
    sumDd0 = sumD // 10
    ans += sumDd0
    sumD = sumDd0 + sumDd0 % 10
# print(D)
print(ans)