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
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():
        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:
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]
            if s[i][1] >= 4:
                ans += 1
            t += [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:
m=int(input())
dc =[[int(i) for i in input().split()] for j in range(m)]

ans = 0
for d,c in dc:
    ans+=c
    temp = d*c
    if temp!=0:
        ans+=len(str(temp))-1
    else:
        ans-=1

print(ans)

Submission status: Wrong Answer

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


def main():
    M = int(input())
    DC = [list(map(int, input().split())) for _ in range(M)]

    ans = 0
    n = 0
    for d, c in DC:
        t = n
        checked = [False]*10
        T = []
        S = []
        for _ in range(10):
            t += d
            r = 1
            if t > 9:
                t -= 9
                r = 2
            if checked[t]:
                break
            checked[t] = True
            T.append(t)
            S.append(r)

        loop = c//len(T)
        rem = c%len(T)
        ans += loop*sum(S)
        for r in range(rem):
            ans += S[r]
        n = T[rem-1]

    if M > 1:
        ans -= 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
m = int(input())
def xl(n):
    r = [n]
    cr = [0]
    for _ in range(8):
        c = r[-1] + n
        r.append(c if c<10 else c-9)
        cr.append(cr[-1]+1 if c<10 else cr[-1]+2)
    return r, cr

d = dict()
crd = dict()
for i in range(10):
    d[i], crd[i] = xl(i)
#    print(crd[i])

os = []
rr = 0
for _ in range(m):
    x,c=map(int,input().split())
    os.append(d[x][(c%9)-1])
    rr += (crd[x][-1]+(2 if x else 1))*(c//9)
#    print((crd[x][-1]+(2 if x else 1)))
    rr += crd[x][(c%9)-1]
#    print(crd[x][(c%9)-1])

b = os[0]
for o in os[1:]:
    c = b + o
    if c<10:
        b=c
        rr+=1
    else:
        b=c-9
        rr+=2
print(rr)

Submission status: Wrong Answer

Solution code:
m = int(input())

l=[]
sum = 0
ans = 0
for i in range(m):
    d, c=map(int,input().split())
    l.append([d, c])
    sum += d
    ans += c


print(len(str(sum)) + ans - 2)

Submission status: Wrong Answer

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

n = ""
ans = 0

for d, c in DC:
    total = 0
    if c >= 2:
        ans += c - 1
        total = d * c
        while total >= 10:
            total = list(map(int, list(str(total))))
            ans += len(total) - 1
            total = sum(total)
    else:
        total = d
    n = n + str(total)
total = 0
if len(n) >= 2:
    for i in n:
        i = int(i)
        total += i
        ans += 1
        if total >= 10:
            total = 1 + total % 10
            ans += 1
    ans -= 1
print(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 // 10)

Submission status: Wrong Answer

Solution code:
m = int(input())
dc = [0 for _ in range(m)]
ans = 0
for i in range(m):
    d, c = map(int, input().split())
    tmp = d * c
    if len(str(tmp)) == 2:
        tmp = (tmp // 10) + (tmp % 10)
        ans += 1

    dc[i] = tmp
    ans += c - 1

# print(dc, ans)
SUM = 0

m = len(dc)
for i in range(m):
    SUM += dc[i] * 10 ** (m - i - 1)

# print(SUM)
i = 0
while (i < m - 1):
    # print(i, ans, SUM)
    SUM -= (dc[i] * 10 + dc[i + 1]) * 10 ** ((m - i - 2))
    # print(SUM, 12121212)
    ans += 1
    tmp = dc[i] + dc[i + 1]
    # print(tmp, SUM, i)

    if len(str(tmp)) == 2:
        tmp = (tmp // 10) + (tmp % 10)
        ans += 1

    dc[i + 1] = tmp
    SUM += tmp * 10 ** ((m - i - 2))
    i += 1

    if SUM <= 9:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = []
res = 0
t = 0
r = 0
for _ in range(N):
  d, c = list(map(int, input().split()))
  a.append((d, c))
for i in range(N):
  d, c = a[i]
  x = (d * c + t) // 10
  y = (d * c + t) % 10
  res += x
  if x + y >= 10:
    res += 1
  t = (x + y) % 10
  r += c
  #print("t", t)
print(res + r - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = 0
cot = 0
for _ in range(n):
    a,b=list( map(int, input().split(" ")))
    s += a* b
    cot += b
cot -= (1 )
cot +=  s//10
print(cot)

Submission status: Wrong Answer

Solution code:
M = int(input())
sum, k = 0, 0
for i in range(M):
  d, c = [int(x) for x in input().split()]
  sum += d * c
  k += c
ans = k - 1
ans += sum // 9
print(ans)

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

        
        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())
nm = [(0,0)]
for i in range(m):
    di,ci = map(int, input().split( ))
    nm.append((di,ci))
cnt = 0
tmp = 0
try:
    while nm:
        ci,di = nm.pop()
        if di>100:
            tmpy = 1
            tmpz = 1
            tmpx = ci*2
            if tmpx>=10:
                tmpx = str(tmpx)
                tmp2 = int(tmpx[0])+int(tmpx[1])
                tmpy += 1
            while tmpx != ci:
                tmpx += ci
                tmpy +=1
                tmpz +=1
                if tmpx>=10:
                    tmpx = str(tmpx)
                    tmp2 = int(tmpx[0])+int(tmpx[1])
                    tmpy += 1
            cnt += tmpz*(di//tmpy)
            di -= (di//tmpy)*tmpy

        while di:
            cnt += 1
            #print(di,cnt)
            tmp += ci
            di-=1
            if tmp>=10:
                tmp = str(tmp)
                tmp2 = int(tmp[0])+int(tmp[1])
                cnt += 1
            #print(di,cnt)
                tmp = tmp2
except:
    pass
print(cnt-1)

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:
# -*- 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))
    
    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]
            if c != 0:
                d += 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:
import copy
import sys
sys.setrecursionlimit(10**6)

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


def func1(k):
    t = copy.copy(k)
    a = 0
    for i in range(1,len(t)):
        t[i] = t[i]+t[i-1]
        a += 1
        if t[i]>=10:
            t[i] = t[i]//10 + t[i]%10
            a+=1
    return a, t[-1]


dict = {0:[1,0], 1:[1,2], 2:[1,4], 3:[1,6], 4:[1,8], 5:[2,1],
     6:[2,3], 7:[2,5], 8:[2,7], 9:[2,9]}

V = []

def pre(d,c):
    global ans
    if c==1:
        V.append(d)
        return

    if c%2!=0:
        V.append(d)
    ans += dict[d][0]* c//2
    pre(dict[d][1], c//2)




ans = 0
for i in range(M):
    pre(d[i],c[i])
a, _ = func1(V)
print(ans+a)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
M = int(input())
frqs = [0 for _ in range(10)]

for _ in range(M):
    d, c = map(int, input().split(' '))
    frqs[d] += c

# print(frqs)
ans = 0
for i in range(9, -1, -1):
    if frqs[i] > 1:
        n = i * 2
        if n < 10:
            frqs[n] += (frqs[i] // 2) * 2

        else:
            m = n - 10
            n = 1

            frqs[m] += (frqs[i] // 2) * 2
            frqs[n] += (frqs[i] // 2) * 2

        ans += frqs[i] // 2
        frqs[i] = frqs[i] % 2

# print(frqs)

rest = [i for i in range(9, -1, -1) if frqs[i] > 0]
while len(rest) > 1:
    x, y = rest.pop(), rest.pop()
    n = x + y

    if n < 10:
        rest.append(n)
    else:
        rest.append(n - 10)
        rest.append(1)

    ans += 1
    rest.sort(reverse=True)

# print(rest)
print(ans)

Submission status: Wrong Answer

Solution code:
m=int(input())
A=[]
keta=0
for i in range(m):
  c,d=map(int,input().split())
  A.append([c,d])
sum=0
for i in range(m):
  sum+=A[i][0]*A[i][1]
  keta+=A[i][1]
print(keta-1+sum%10)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ans=0

  nxt=0
  for _ in range(n):
    d,c=LI()
    ans+=c

    t=d*c+nxt
    ans+=t//10
    nxt=t%10

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
from math import log10

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
if sum!=sum%10: out+=log10((sum-sum%10)) 
print(int(out-2))

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)
    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:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ans=0

  nxt=0
  for _ in range(n):
    d,c=LI()
    ans+=c

    t=d*c+nxt
    ans+=t//10
    nxt=t%10

  return ans-2

# main()
print(main())

Submission status: Wrong Answer

Solution code:
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,input().split())
  ans += c-1
  tmp_val = d*c
  ans, tmp_val = sol(tmp_val, ans)
  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())
r = 0
ds = []
for i in range(M):
  d, c = map(int, input().split())
  r += c-1
  r += d*c//10
  n = d*c
  while n >= 10:
    n = sum(map(int, str(n)))
  ds.append(n)
r += len(ds)-1
r += sum(ds)//10
print(r)

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]

ans=s//9

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

print(ans-1)

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
    
def main():
    m=inp()
    now = 0
    ans = -1
    for _ in range(m):
        d,c = inpm()
        ans+=c
        now+=d*c
        x=now//10
        y=now-x*10
        if y!=0:
            ans+=x
            now=y
        elif y==0 and x!=0:
            ans+=x-1
            s=str(x)
            while int(s)<10:
                cnt=0
                for i in range(len(s)):
                    cnt+=int(s[i])                
            now=int(s)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import log10

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
if sum!=sum%10: out+=log10((sum-sum%10)) 
print(int(out-2))

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)
        #
        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 math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  ans=0

  nxt=0
  for _ in range(n):
    d,c=LI()
    ans+=c

    t=d*c+nxt
    ans+=t//10
    nxt=t%10

  return ans-1

# main()
print(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>0:
    s//=10
    t+=s

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

Submission status: Wrong Answer

Solution code:
m = int(input())

ans = 0

num = 0
for i in range(m):
    d, c = map(int, input().split())
    num += d * c
    ans += c
ans -= 1

nums = str(num)
if len(nums) <= 1:
    print(ans)
    exit()

while len(nums) > 1:
    up = nums[:len(nums)-1]
    ans += int(up)

    num = 0
    for nu in nums:
        num += int(nu)
    nums = str(num)

print(ans)
exit()

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
                break
            else:
                g+=1
        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))
    
    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]
            d += 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))
  x = sum(list(map(int,str((x)))))
  if n == 1:
    flag = 1
    break
  ans += n-1
print(ans)

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]
    t =  s // 10
    s = s - 9 * t
    ans += t
    
print(ans)

Submission status: Wrong Answer

Solution code:
#D
M = int(input())
DC = [list(map(int,input().split())) for i in range(M)]

ans = 0
now = 0
for dc in DC:
    d,c = dc
    sd = d*c
    if d == 0:
        ans+=(c+(now//10))
        #print(ans)
    else:
        s = int(str(sd)[-1])
        if s+now >= 10:
            ans+=1
            sn = int(str(s+now)[1])
        else:
            sn = s+now
        ans+= c + int((sn)/(10*d))
        now+= s + int(s/(10*d))
        now = int(str(now)[-1])
        #print(ans,now)
        
print(ans-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)
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])
        g=0
        while g<len(s)-1:
            if s[g]+s[g+1]>10:
                ret+=1
                break
            else:
                g+=1
        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())
keta = 0
fig_sum = 0
for i in range(m):
    a, b = map(int, input().split())
    fig_sum+=a*b
    keta+=b

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

Submission status: Wrong Answer

Solution code:
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 = 1
prv_val = 0
for _ in range(M):
  d,c = map(int,input().split())
  ans += c-1 if d!=0 else c
  tmp_val = d*c
  ans, tmp_val = sol(tmp_val, ans)
  ans, prv_val = sol(tmp_val+prv_val, ans)
print(ans)

Submission status: Wrong Answer

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

# print(dc, ans)
SUM = 0

m = len(dc)
for i in range(m):
    SUM += dc[i] * 10 ** (m - i - 1)

# print(SUM)
i = 0
while (i < m - 1):
    # print(i, ans, SUM)
    SUM -= dc[i] * 10 ** (m - i - 1) + dc[i + 1] * 10 ** ((m - i - 2))
    # print(SUM, 12121212)
    ans += 1
    tmp = dc[i] + dc[i + 1]
    # print(tmp, SUM, i)
    if len(str(tmp)) == 2:
        dc[i] = tmp // 10
        dc[i + 1] = tmp % 10
        SUM += tmp * 10 ** ((m - i - 2))
    else:

        dc[i + 1] = tmp
        SUM += tmp * 10 ** ((m - i - 2))
        i += 1

    if SUM <= 9:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
M = int(input())
d = [0]*M
c = [0]*M
for i in range(M):
    d[i],c[i] = map(int, input().split())
N = []
for i in range(M):
    for j in range(c[i]):
        N.append(d[i])
X = sum(N)
Y = X//10
print(len(N)-1+Y)

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//10
    ans+=t
    s-= t*10

print(ans)

Submission status: Wrong Answer

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


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

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

    print(x-1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def digitSum(n):
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)
ans = 0
m = int(input())
D = []
for i in range(m):
  d, c = map(int, input().split())
  ans += c +len(str(d*c))-2
  z = d*c
  while len(str(z)) != 1:
    z = digitSum(z)
  D.append(z)
while len(D) != 1:
  a = D[0] + D[1]
  D[1] = a
  del D[0]
  ans += 1
  if a >=10:
    D[0] = digitSum(D[0])
    ans += 1
print(ans)