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 list(str(dc_sum)[:-1]):
        if i == '0':
            ans += 10
        else:
            ans += int(i)
    print(ans)
    return


# E
def E():
    print(str(108)[:-1].split(''))
    return


# F
def F():
    return


# Unittest
def resolve():
    D()
    return


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

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%=10

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

Submission status: Wrong Answer

Solution code:
def ngo(a,b):
    if a+b < 10:
        return a+b
    else:
        return a+b-10+1
def f(d,c):
    if c == 1:
        return 0,d
    if c%2 == 0:
        a,b = f(ngo(d,d),c//2)
        return a+c//2,b
    else:
        a,b = f(ngo(d,d),(c-1)//2)
        if d+b < 10:
            return a+(c-1)//2+1,d+b
        else:
            return a+(c-1)//2+2,d+b-10+1

m = int(input())
d = [None]*m
c = [None]*m
for i in range(m):
    d[i],c[i] = map(int,input().split())
ans = 0
for i in range(m):
    a,d[i] = f(d[i],c[i])
    ans += a
    
for i in range(m-1):
    if d[i]+d[i+1] < 10:
        d[i+1] = d[i]+d[i+1]
        ans += 1
    else:
        d[i+1] = d[i]+d[i+1]-10+1
        ans += 2
print(ans)

Submission status: Wrong Answer

Solution code:
M = int(input())
nums_array = []

for _ in range(M):
	d, c = [int(s) for s in input().split(" ")]
	nums_array.extend([d for _ in range(c)])


def isover(a, b):
	return a + b >= 10

sum = 0
for i in range(len(nums_array) - 1):
	sum += isover(nums_array[i], nums_array[i + 1]) + 1

print( sum)

Submission status: Wrong Answer

Solution code:
m = int(input())
l = [] 
#print(m)
for i in range(m):
    d,c = map(int,input().split())
    for j in range(c):
      l.append(d)
print('l',l)
ans =1
cnt = 0
le =len(l)
print(le)
#a = l.pop(0)
#b = l.pop(0)
#配列から値を２つ取り出す
#合計>=10だったら、結果の１０と１の位をまたたす
#合計<10だったら配列の次にいく
#条件の10人以下になるまでくりかえす
for v in l:
  print(v)
  
"""
while cnt < le:
  cnt +=1
  ans +=1
  print('a',a)  
  print('b',b)  
  if a + b >= 10:
    a = (a+b)%10
    b = (a+b)//10
  else:
    a= a+b
    if 
    b= l.pop(0)
print(ans)
"""

Submission status: Wrong Answer

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

ddd = []
for i in range(0, 10):
    tmp = []
    for j in range(1, 10):
        if j == 1:
            tmp.append(i)
        else:
            gomi = tmp[-1]+i
            if gomi >= 10:
                gomi -= 9
            if gomi in tmp:
                break
            tmp.append(gomi)
    ddd.append(tmp)


def calc(d, c):
    res = c - 1
    sum_dc = d * c

    low_len = len(ddd[d-1])
    iii = c % low_len
    if iii == 0:
        iii += low_len
    lower = ddd[d-1][iii-1]

    return res+sum_dc//10, lower


now = 0
for i in range(m):

    d, c = map(int, input().split())
    res, low = calc(d, c)

    now = 10 * now + low
    if now >= 10:
        ans += 1
        now -= 9

    ans += res
else:
    if now >= 10:
        ans += 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) + sum(l)//10 - len(str(sum(l))) + 1
  s = sum(l)
print(ans)

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_c - 1
cnt = cnt // 10
ans += cnt

def f(n):
    res = 0
    for i in range(len(str(n))):
        res += (n%10**(i+1))//10**i
    ans = res//10 + len(str(n)) - 1
    return ans


while cnt > 0:
    t = f(cnt)
    ans += t
    cnt //= 10

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

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





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

    t = 0
    for i in range(len(s)):
        if s[i][0] == 1:
            ans += s[i][1]
            t += s[i][1]
            if t > 9:
                ans += 1
                t = t % 10 + t // 10
            continue
        if s[i][0] == 2:
            ans += s[i][1]
            if s[i][1] >= 4:
                ans += 1
            t += [2, 4, 6, 8, 1, 1, 3, 5, 7, 9, 1][s[i][1]-1]
            if t > 9:
                ans += 1
                t = t % 10 + t // 10
            continue
        while s[i][1]:
            s[i][1] -= 1
            ans += 1
            t += s[i][0]
            if t > 9:
                ans += 1
                t = t % 10 + t // 10

    print(ans - 1)

main()

Submission status: Wrong Answer

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

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:
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]
    s_tmp = s
    t =  s // 10
    s = s - 9 * t
    ans += t
    if s_tmp > 18 and s == 1:
        ans = 1 + (s_tmp - 19) // 90
    
print(ans)

Submission status: Wrong Answer

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

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

print(ans-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
ld=[]
lc=[]
for i in range(n):
  d,c=map(int,input().split())
  ld.append(d)
  lc.append(c)
l1=[]
count=0
for i in range(n):
  d1=ld[i]
  c1=lc[i]
  if d1==0:
    count+=c1
    c1=0
  while c1>1:
    if c1%2==0:
      if d1<10:
        count+=1
        d1=d1*2
        c1=c1//2
      else:
        count+=2
        num=str(d1*2)
        d1=int(num[0])+int(num[1])
        c1=c1//2
    else:
      l1.append(d1)
      c1-=1
      if d1<10:
        count+=1
        d1=d1*2
        c1=c1//2
      else:
        count+=2
        num=str(d1*2)
        d1=int(num[0])+int(num[1])
        c1=c1//2
  if d1!=0:
    l1.append(d1)
for i in range(len(l1)-1):
  sum=l1[i]+l1[i-1]
  if sum<10:
    l1[i]=sum
    count+=1
  else:
    num=int(str(sum)[0])+int(str(sum)[1])
    l1[i]=num
    count+=2
print(count)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
M = int(input())
c_list = []
d_list = []
for i in range(M):
    c, d = map(int, input().split())
    c_list.append(c)
    d_list.append(d)

temp_num = 0
counter = 0
for i in range(len(c_list)):
    c = c_list[i]
    d = d_list[i]
    for j in range(d):
        temp_num += c
        if temp_num > 10:
            temp_num = temp_num // 10 + temp_num % 10
            counter += 1
        counter += 1
print(counter - 1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
M = int(input())

digitSum = 0
countSum = 0
ans =0

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

countSum2 = 0

while(True):
    if(countSum>=10):
        countSum2 = countSum2 + countSum//10
        countSum = countSum//10 
    else:
        break

ans = (digitSum-1) + countSum2
#print(countSum)
#print(digitSum)
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())
    dcnt += d
    calc += d*c
res=0
#res = dcnt-1+(0 if calc < 10 else int(str(calc)[:-1]))
res += dcnt-1+calc//10+(calc%10==0)

print(res)

Submission status: Wrong Answer

Solution code:
num=int(input())
nums=[]
for i in range(num):
  a,b=map(int,input().split())
  for j in range(b):
    nums.append(a)
def re(nums):    
  for i in range(len(nums)-1):
    if nums[i]+nums[i+1]<=10 and i!= len(nums)-2:
      pass
    else:
      nums[i]=nums[i]+nums[i+1]
      del nums[i+1]
      break
  return nums
p=1
while len(nums)>1:
  nums=re(nums)
  p+=1
print(p)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
m=int(input())
dc=[list(map(int,input().split())) for i in range(m)]
tmp=0
ans=0
for i in range(m):
    tmp+=dc[i][0]*dc[i][1]
    ans+=dc[i][1]
# print(tmp)
ans-=1
ans+=tmp//9
print(ans)

Submission status: Wrong Answer

Solution code:
m = int(input())
dd = []
cc = []

for i in range(m):
    d,c = map(int,input().split())
    dd.append(d)
    cc.append(c)

s = 0
for i in range(m):
    s += dd[i]*cc[i]

ss = sum(cc)

ans = ss + s//10 -1

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, CD):
    ans = 0
    r = 0
    C = []
    for i in range(10):
        s = i
        s += i
        c = 1
        p = 1
        while s != i:
            s += i
            c += 1
            p += 1
            if s >= 10:
                s = s % 10 + s // 10
                p += 1
        C.append((i, c+1, p))
    C[0] = (0, 1, 1)
    error_print(C)
    ans = 0
    r = 0
    for c, d in CD:
        if c == 0:
            ans += d
        else:
            while d >= C[c][1]:
                ans += (d // C[c][1]) * C[c][2]
                d = d % C[c][1] + (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:
from collections import Counter

mod = 1000000007


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


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

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





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

    t = 0
    for i in range(len(s)):
        if s[i][0] == 1:
            ans += s[i][1]
            t += s[i][1]
            if t > 9:
                ans += 1
                t = t % 10 + t // 10
            continue
        if s[i][0] == 2:
            ans += s[i][1]
            if s[i][1] >= 4:
                ans += 1
            t += [2, 4, 6, 8, 1, 1, 3, 5, 7, 9, 1][s[i][1]-1]
            if t > 9:
                ans += 1
                t = t % 10 + t // 10
            continue
        while s[i][1]:
            s[i][1] -= 1
            ans += 1
            t += s[i][0]
            if t > 9:
                ans += 1
                t = t % 10 + t // 10

    print(ans)

main()

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

kuriagari = [[0]*10,
             [0]*10,
             [0]*5 + [1]*5,
             [0,0,0,0,1,1,1,2,2,2,3],
             [0,0,0,1,1,2,2,3,3,3,4],
             [0,0,1,1,2,2,3,3,4,4,5],
             [0,0,1,1,2,3,3,4,5,5,6],
             [0,0,1,2,3,3,4,5,6,6,7],
             [0,0,1,2,3,4,5,6,7,7,8],
             [0,0,1,2,3,4,5,6,7,8,9]]

product = [[0]*9,
           [9,1,2,3,4,5,6,7,8],
           [9,2,4,6,8,1,3,5,7],
           [9,3,6,9,3,6,9,3,6],
           [9,4,8,3,7,2,6,1,5],
           [9,5,1,6,2,7,3,8,4],
           [9,6,3,9,6,3,9,6,3],
           [9,7,5,3,1,8,6,4,2],
           [9,8,7,6,5,4,3,2,1],
           [9]*9]

m = ni()
products = []
ans = 0
for _ in range(m):
    d, c = li()
    ans += (c-1) + d * (c//9) + kuriagari[d][c%9]
    prod = product[d][c%9]
    products.append(prod)

while len(products) > 1:
    cur1 = products.pop()
    cur2 = products.pop()
    if cur1 + cur2 >= 10:
        products.append(cur1 + cur2 - 10 + 1)
        ans += 1
    else:
        products.append(cur1 + cur2)
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import math

m = int(input())
dc = []

sum_c = 0
before_num = 0
add_two = 0
kuriage = 0

for i in range(m):
  array = list( map(int, input().split()) )
  dc.append(array)
  sum_c += int(dc[i][1])
  if( i > 0 ):
    add_two = add_two + int(dc[i][0])
    if(add_two >= 10):
      kuriage += 1
      add_two = add_two + 1 - 10
  else:
    add_two =int(dc[i][0])
  
cnt = sum_c - 1 + kuriage

print(cnt)

Submission status: Wrong Answer

Solution code:
m=int(input())
d,c=[],[]
ans=-1
for i in range(m):
  dd,cc=map(int,input().split())
  d.append(dd)
  c.append(cc)
  ans+=cc
a=0
ds=lambda n:sum(list(map(int,list(str(n)))))
for i in range(m):
  if d[i]*c[i]+a<10:a+=d[i]*c[i]
  else:
    if c[i]*d[i]>9:
      ci,di=c[i],d[i]
      if ci*di>9:
        cd=(0--10//di)
        ci,di,cci,ddi=ci//cd,ds(cd*di),ci-(ci//cd*cd),di
        ans+=ci
        if ddi*cci+a>9:ans+=1
        a=ds(ddi*cci+a)
      if di*ci+a>9:ans+=1
      a=ds(di*ci+a)
    else:
      ans+=1
      a=ds(a+c[i]*d[i])
print(ans)

Submission status: Wrong Answer

Solution code:
m=int(input())
dig=[]
for i in range(m):
    q,r=map(int,input().split())
    dig.append([q,r])

if m==1:
    print(0)
    exit()
ans=1
tmp=dig[0][0]
dig[0][1]-=1
for i in range(m):
    if dig[i][0]==0:
        ans+=dig[i][1]-1
    else:
        while dig[i][1]>0:
            tmp+=dig[i][0]
            if tmp>=10:
                g=str(tmp)
                tmp=int(g[0])+int(g[1])
            dig[i][1]-=1
            ans+=1

print(ans)

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)
if len(n) >= 2:
    total = int(n)
    while total >= 10:
        total = list(map(int, list(str(total))))
        ans += len(total) - 1
        total = sum(total)
print(ans)

Submission status: Wrong Answer

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

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

print(ans-1)

Submission status: Wrong Answer

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

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=0
#res = dcnt-1+(0 if calc < 10 else int(str(calc)[:-1]))
res += dcnt-1+calc//10

print(res)

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 += (k + c * d) // 10
        v += c * d

    return ans

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

Submission status: Wrong Answer

Solution code:
total = 0
ans = 0

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

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

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

print(ans)

Submission status: Wrong Answer

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

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:
        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:
import sys
input = sys.stdin.readline

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

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

ans += sumc + sum1 // 9 - 1

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)
            cnt1=0
            while int(s)<10:
                cnt=0
                cnt1+=1
                for i in range(len(s)):
                    cnt+=int(s[i])
                s=str(cnt)
            now=int(s)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

kuriagari = [[0]*10,
             [0]*10,
             [0]*5 + [1]*5,
             [0,0,0,0,1,1,1,2,2,2,3],
             [0,0,0,1,1,2,2,3,3,3,4],
             [0,0,1,1,2,2,3,3,4,4,5],
             [0,0,1,1,2,3,3,4,5,5,6],
             [0,0,1,2,3,3,4,5,6,6,7],
             [0,0,1,2,3,4,5,6,7,7,8],
             [0,0,1,2,3,4,5,6,7,8,9]]

product = [[0]*9,
           [9,1,2,3,4,5,6,7,8],
           [9,2,4,6,8,1,3,5,7],
           [9,3,6,9,3,6,9,3,6],
           [9,4,8,3,7,2,6,1,5],
           [9,5,1,6,2,7,3,8,4],
           [9,6,3,9,6,3,9,6,3],
           [9,7,5,3,1,8,6,4,2],
           [9,8,7,6,5,4,3,2,1],
           [9]*9]

m = ni()
products = []
ans = 0
for _ in range(m):
    d, c = li()
    ans += (c-1) + d * (c//9) + kuriagari[d][c%9]
    prod = product[d][c%9]
    products.append(prod)

while len(products) > 1:
    cur1 = products.pop()
    cur2 = products.pop()
    if cur1 + cur2 >= 10:
        products.append(cur1 + cur2 - 10)
        ans += 1
    else:
        products.append(cur1 + cur2)
    ans += 1

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]
ans=sum-1
sct=str(ct)
if len(sct)>=2:
  for i in range(2,len(sct)+1):
    ans+=int(ct/(10**(i-1)))
print(ans)

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:
        additional += (total - 1) // 9
    if total > 9:
        res = total % 9
    else:
        res = total
    short.append(res)

print(short)
print(additional)
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())
keta = 0
count_sum = 0
for _ in range(M):
    d,c= map(int,input().split(' '))
    keta += c
    count_sum += d*c
additional = count_sum//10
if 9 < count_sum:
    print(keta-1 + (count_sum-additional)//9)
else:
    print(keta-1)
'''
additional = count_sum//10
print(keta-1 + (count_sum+additional)//10)
'''

Submission status: Wrong Answer

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