Problem:


Score: 500 points

Problem Statement

N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals.

The preliminary stage consists of several rounds, which will take place as follows:

All the N contestants will participate in the first round.

When X contestants participate in some round, the number of contestants advancing to the next round will be decided as follows:

The organizer will choose two consecutive digits in the decimal notation of X, and replace them with the sum of these digits. The number resulted will be the number of contestants advancing to the next round.

For example, when X = 2378, the number of contestants advancing to the next round will be 578 (if 2 and 3 are chosen), 2108 (if 3 and 7 are chosen), or 2315 (if 7 and 8 are chosen).

When X = 100, the number of contestants advancing to the next round will be 10, no matter which two digits are chosen.

The preliminary stage ends when 9 or fewer contestants remain.

Ringo, the chief organizer, wants to hold as many rounds as possible.
Find the maximum possible number of rounds in the preliminary stage.

Since the number of contestants, N, can be enormous, it is given to you as two integer sequences d_1, \ldots, d_M and c_1, \ldots, c_M, which means the following: the decimal notation of N consists of c_1 + c_2 + \ldots + c_M digits, whose first c_1 digits are all d_1, the following c_2 digits are all d_2, \ldots, and the last c_M digits are all d_M.

Constraints

1 \leq M \leq 200000

0 \leq d_i \leq 9

d_1 \neq 0

d_i \neq d_{i+1}

c_i \geq 1

2 \leq c_1 + \ldots + c_M \leq 10^{15}

Input

Input is given from Standard Input in the following format:

M
d_1 c_1
d_2 c_2
:
d_M c_M

Output

Print the maximum possible number of rounds in the preliminary stage.

Sample Input 1

2
2 2
9 1

Sample Output 1

3

In this case, N = 229 contestants will participate in the first round. One possible progression of the preliminary stage is as follows:

229 contestants participate in Round 1, 49 contestants participate in Round 2, 13 contestants participate in Round 3, and 4 contestants advance to the finals.

Here, three rounds take place in the preliminary stage, which is the maximum possible number.  

Sample Input 2

3
1 1
0 8
7 1

Sample Output 2

9

In this case, 1000000007 will participate in the first round.  



Sample input:
2
2 2
9 1


Sample output:
3

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

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

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

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

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

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

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

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

	ans = 0
	while True:
		if len(n) <= 1:
			break

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

				#print(val + n[i-1])

				tmp = val + n[i-1]
				if val + n[i-1] >= 10:
					flg = True

					ans += 1
					tmp2 = str(tmp)
					tmp2 = list(tmp2)

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

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

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

		n.remove(99)

	print(ans)


if __name__ == "__main__":
	main()

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]
if M==1 and CiDi[1]== 1:
    print("1")
else:
    ans1 = int(countSum//10)
    ans = (digitSum-1) + ans1
    #print(countSum)
    # #print(digitSum)
    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+=ct//(10**(i-1))
print(ans)

Submission status: Wrong Answer

Solution code:

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

m = int(input())
#a = [int(i) for i in readline().split()]

keta = 0
wa = 0

for i in range(m):
    d,c = [int(i) for i in readline().split()]
    keta += c
    wa += d*c

#print(keta,wa)
print(keta-1 + wa//9)

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]
      while ci*di>9:
        cd=(0--10//di)
        ci,di,cci,ddi=ci//cd,ds(cd*di),c[i]-(c[i]//cd*cd),d[i]
        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())
a=0
ans=-1
for i in range(m):
  x,y=map(int,input().split())
  a+=x*y
  ans+=y
    
if a%9==0:
  ans+=(a/9)-1
else:
  ans+=a//9
  
print(ans)

Submission status: Wrong Answer

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


def main():
    m = int(input())
    dc = [list(map(int, input().split())) for i in range(m)]

    ans = 0
    n = []
    for i in range(m):
        if dc[i][0] == 0:
            n.append(0)
            ans += dc[i][1] - 1
            continue
        v = 10 / dc[i][0]
        ans += (dc[i][1] - 1)
        if dc[i][1] / v >= 1:
            ans += (1 + 2 * (dc[i][1] / v - 1))
            n.append(dc[i][1] / v)
        else:
            n.append(dc[i][0] * dc[i][1])

    i = 0
    while len(n) - 1 > i:
        #print(n, i)
        v1 = n[i]
        v2 = n[i+1]
        if v1 + v2 >= 10:
            s = str(v1 + v2)
            n[i] = (int(s[0]))
            n[i + 1] = (int(s[1]))
        else:
            n[i+1] = (v1+v2)
            i += 1
        ans+=1

    print(ans)


if __name__ == '__main__':
    main()

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]
    for u in up:
        ans += int(u)

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

print(ans)
exit()

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

m = ri()
ls = rils(m)
res = -1
s = 0
for d, c in ls:
    res += c
    s += d * c
while s > 0:
    res += s // 10
    s //= 10
print(res)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

M, = map(int, sys.stdin.readline().rstrip().split(" "))


def contract_list(ds):
    d, c = 0, 0
    for next_d, next_c in ds:
        c += next_c
        d += next_d
        if d >= 10:
            d = d % 10 + 1
            c += 1
    return d, c

def contract_pair(d, orig_c):
    c = 0
    ds = [(d, c)]
    for _ in range(int(math.log(orig_c, 2)) + 1):
        d = d + d
        c = c*2 +1
        if d >= 10:
            d = d % 10 + 1
            c += 1
        ds.append((d, c))
    # print(ds)

    ds_for_calc = []
    for i, b in enumerate(reversed(bin(orig_c)[2:])):
        # print(bin(orig_c), b)
        if b == "1":
            ds_for_calc.append(ds[i])
    # print("for_cal", ds_for_calc)

    return contract_list(ds_for_calc)


ds_for_calc = []
for _ in range(M):
    d, c = map(int, sys.stdin.readline().rstrip().split(" "))
    ds_for_calc.append(contract_pair(d, c))
    # print(ds_for_calc[-1])
# print("last_list", ds_for_calc)
print(contract_list(ds_for_calc)[1] + M -1)

exit(0)

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

    t = s[0][0]
    s[0][1] -= 1
    for i in range(len(s)):
        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())
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]
      while ci*di>9:
        cd=(0--10//di)
        ci,di,cci,ddi=ci//cd,ds(cd*di),c[i]-(c[i]//cd*cd),d[i]
        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())
digit = [list(map(int, input().split())) for _ in range(m)]

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

M = int(input())

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

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

print(ans + sum(C) - 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//10
#print("fig_sum",fig_sum)
#print("keta",keta)
print(sub)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#DISCO C
import sys
import math
import collections
#sys.setrecursionlimit(100000)

m=int(input())


total=0
ketatotal=0
for i in range(0,m):
	tmp = input().split()
	d,c = list(map(lambda a: int(a), tmp))
	total+=d*c
	ketatotal+=c
ans=0
ans+=total//10
ans+=ketatotal-1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math



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

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

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

Submission status: Wrong Answer

Solution code:
def main():

    M = int(input())

    a, b = [], []
    for _ in range(M):
        d, c = map(int, input().split())
        a.append(d)
        b.append(c)
    ans = sum(b) - 1
    tot = sum([a[i]*b[i] for i in range(M)])
    ans += tot // 10
    return ans

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

Submission status: Wrong Answer

Solution code:

import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions
from operator import itemgetter


import sys
def input():
	return sys.stdin.readline().strip()


M = int(input())
num_list = deque()
dc_list = []
for _ in range(M):
	dc_list.append(tuple(map(int, input().split())))

ans = 0
for i in range(M - 1, -1, -1):
	ans += dc_list[i][1] - 1
	dc = dc_list[i][0]*dc_list[i][1]
	if dc == 0:
		num_list.appendleft(0)
		continue
	while True:
		num_list.appendleft(dc % 10)
		dc = dc // 10
		if dc == 0:
			break

while True:
	total = sum(num_list)
	ans += len(num_list) - 1
	if total <= 9:
		break
	num_list2 = deque()
	while True:
		num_list2.appendleft(total % 10)
		total = total // 10
		if total == 0:
			break
	num_list = copy.deepcopy(num_list2)


print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

m = ri()
ls = rils(m)
res = -1
s = 0
for d, c in ls:
    res += c
    s += d * c
res += s // 10
print(res)

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

def piyo(d,c,m):  
    hoge = sum(c)
    # Nはhoge桁の数
    # 仮に繰り上がりがなかったらN-1
    fuga = sum(map(lambda x:d[x]*c[x],range(m)))

    mm = fuga//10
    
    if mm == 0:
        #print(hoge)
        return hoge - 1
    else:
        p = piyo([1,fuga%10],[mm,1],2)
        #print(d,c,m,hoge,fuga,p)
        return hoge+p

print(piyo(D,C,M))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile

INF = float("inf")


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in readi(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[0]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    sys.setrecursionlimit(10**5)
    M=readi()
    digits=[]
    ans=0
    def digit_sum(n):
        s=str(n)
        if len(s) == 1:
            return n
        dst = sum(map(int, s))
        nonlocal ans
        ans+=len(s)-1
        return digit_sum(dst)
    for _ in range(M):
        d,c=readi(2)
        digits.append(str(digit_sum(d*c)))
        ans+=c-1
    digit_sum(int(''.join(digits)))
    print(ans)

if __name__ == "__main__":
    main()

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

Submission status: Wrong Answer

Solution code:

m = int(input())

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


num = int("".join(map(str, dc)))


count=sum(c)-m+1

while num>9:
  dc[-2] = dc[-1]
  dc = dc[:-1]
  #print(dc)
  num = int("".join(map(str, dc)))
  count+=1

num = int("".join(map(str, dc)))

print(count)

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

ans -= 1
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
i = 0
while True:
    i += 1
    t = cnt // 10**i
    if t == 0:
        break
    ans += t
    

print(ans)

Submission status: Wrong Answer

Solution code:
m=int(input())
l=list(input().split() for i in range(m))
l=list([int(j) for j in i] for i in l)
count=0
flag=0
for i in l:
  count+=i[0]*i[1]
  if count>=10:
    flag=1
    break
  else:
    flag=0
ans=0
for i in l:
    ans+=i[1]
if flag==1:
  print(ans)
else:
  print(ans-1)

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
#print(count_sum)
additional = count_sum//10
print(keta-1 + (count_sum+additional)//10)

Submission status: Wrong Answer

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

def count_reduce(x, n):
    count = 0

    if n == 1:
        return 0, x
    
    num, left = count_reduce(x, n//2)
    count += 2*num
    if left >= 5:
        count += 2
        left = (2 * left) % 9
    else:
        count += 1
        left = 2 * left

    # Pluse the left over
    if n & 1 == 1:
        if left + x > 9:
            count += 2
            left = (left + x) % 9
        else:
            left = left + x
            count += 1
    return count, left

out_arr = [0 for _ in range(M)]

count = 0
for i in range(M):
    ct, tmp = count_reduce(D[i],C[i])
    count += ct
    out_arr[i] = tmp

lh = out_arr[0]

for i in range(1, M):
    rh = out_arr[i]
    if (lh + rh) > 9:
        count += 2
        lh = (lh + rh) % 9
    else:
        lh = lh + rh
        count += 1


print(count)

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

Submission status: Wrong Answer

Solution code:
m=int(input())
s=0
c=0

for i in range(m):
    x,y=map(int,input().split())
    s+=x*y
    c+=y

print(c+s//10)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
m=int(input())
a=0
n=""
for i in range(m):
  x,y=map(int,input().split())
  a+=x*y
  for j in range(y):
    n+=str(x)
    
ans=len(n)-1
if a%9==0:
  ans+=(a/9)-1
else:
  ans+=a//9
  
print(ans)

Submission status: Wrong Answer

Solution code:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


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


def test(n):
    round = {str(n)}
    ret = 0
    while round:
        next_round = set()
        for n in round:
            for i in range(len(n) - 1):
                s = n[:i] + str(int(n[i]) + int(n[i + 1])) + n[i + 2:]
                if len(s) > 1:
                    next_round.add(s)
                else:
                    print('test', ret)

        round = next_round
        print(round)
        ret += 1
    print(ret)


# @lru_cache()
# def solve(n):
#     n = str(n)
#     if len(n) == 1:
#         return 0, n
#     num = 0
#     ret = 0
#     for c in str(n):
#         ret += 1
#         num += int(c)
#         if num >= 10:
#             ret += 1
#             num = num % 10 + 1
#
#

#
# ans = 0
# num = 0
# for d, c in DC:
#     if d == 0:
#         ans += c
#         n = num + d * c
#         ans += n // 10
#         num = n % 10
#     if d == 1:
#         ans += c
#         n = num + d * c
#         ans += n // 10
#         num = n % 10
#     if d == 2:
#         ans += c
#         n1 = c // 5
#
#         n
#         n = num + d * c
#         ans += c
#         ans += n // 10
#         num = n % 10

#
# n = ''
# for d, c in DC:
#     n += str(d) * c
# test(n)

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

Submission status: Wrong Answer

Solution code:
m = int(input())

sumd = 0
sumc = 0

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

ans = 0
while sumd != 0:
  sumd //= 10
  ans += sumd

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

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

    return ans -1 


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

amari = 0
ans = 0
for i in range(m):
    a, b = info[i]
    while b != 0:
        if a == 0:
            ans += b
            break
        elem_num = -((-10) // a)
        kumi_num = b // elem_num
        if amari == 0:
            ans += max(0, (b % elem_num) -1)
        else:
            ans += max(0, (b % elem_num))
        amari += a * (b % elem_num)
        ans += kumi_num * (elem_num - 1)
        ans += kumi_num
        a = (a * elem_num) // 10 + ((a * elem_num) % 10)
        b = kumi_num
        if amari > 10:
            ans += 1
            amari = amari // 10 + (amari % 10)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

def read_tokens():
    return input().strip().split(' ')

def read_ints():
    return [int(token) for token in read_tokens()]

n, = read_ints()
c = [0] * n
d = [0] * n

s = ''
for i in range(n):
    d[i] = (i + 1) % 10
    c[i] = 10**15 // n
    # d[i], c[i] = read_ints()
    # s += str(d[i]) * c[i]



# print(f's={s}')
# cache = {}
# def f(s):
#     global cache
#     x = int(s)
#     if x <= 9:
#         return 0
#     if s in cache:
#         return cache[s]
#     ans = 0
#     best = ''
#     for i in range(len(s) - 1):
#         a = int(s[i])
#         b = int(s[i+1])
#         t = f(s[:i] + str(a+b) + s[i+2:])
#         ans = max(ans, t + 1)
#         if t + 1 == ans:
#             best = s[:i] + str(a+b) + s[i+2:]

#     for i in range(len(s) - 1):
#         a = int(s[i])
#         b = int(s[i+1])
#         t = f(s[:i] + str(a+b) + s[i+2:])
#         if t + 1 != ans:
#             print(f'!!! {s} {i} {s[:i] + str(a+b) + s[i+2:]} {t + 1} {bedt} {ans}')

#     cache[s] = ans
#     return ans

# print(f(s))

# while True:
#     s, = read_tokens()
#     print(f(s))

def processBlock(n, c):
    if not (c > 0):
        while True:
            pass
    if c == 1:
        return n, 0
    if c % 2 == 0:
        if 2 * n < 10:
            rn, rc = processBlock(2 * n, c // 2)
            return rn, rc + c // 2
        else:
            d = (2 * n) // 10 + (2 * n) % 10
            rn, rc = processBlock(d, c // 2)
            return rn, rc + c
    rn, rc = processBlock(n, c - 1)
    if n + rn < 10:
        return n + rn, rc + 1
    else:
        d = (n + rn) // 10 + (n + rn) % 10
        return d, rc + 2

def solve(D, C):
    ret = 0
    a = []
    for d, c in zip(D, C):
        n, cc = processBlock(d, c)
        ret += cc
        a.append(n)
    while len(a) > 1:
        d1 = a.pop()
        d2 = a.pop()
        ret += 1
        if d1 + d2 < 10:
            a.append(d1 + d2)
        else:
            a.append(1)
            a.append((d1 + d2) % 10)
    return ret

print(solve(d, c))
# print(f(s))

Submission status: Wrong Answer

Solution code:
import math

M = int(input())

digitSum = 0
countSum = 0
ans =0

for i in range(0,M):
    CiDi = [int(i) for i in input().split()]
    countSum = countSum +  CiDi[0] * CiDi[1]
    digitSum = digitSum +  CiDi[1]
ans1 = int(countSum//10)
ans = (digitSum-1) + ans1
#print(countSum)
#print(digitSum)
print(ans)

Submission status: Wrong Answer

Solution code:
m=int(input())
s=0
c=0

for i in range(m):
    x,y=map(int,input().split())
    s+=x*y
    c+=y

print(c-1+s//10)

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)
print ( sum(lis) -1 + able // 10 )

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


def func(t):
    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]


ans = 0
for i in range(M):
    ans += c[i]-1
    d[i] = d[i]*c[i]
    k = []
    for j in str(d[i]):
        k.append(int(j))
    a, d[i] = func(k)
    ans += a

a, _ = func(d)
ans += a
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())

def piyo(d,c,m):  
    hoge = sum(c)
    # Nはhoge桁の数
    # 仮に繰り上がりがなかったらN-1
    fuga = sum(map(lambda x:d[x]*c[x],range(m)))

    mm = fuga//10
    
    p = -1
    if mm != 0:
        p = piyo([1],[mm],1)

    #print(d,c,m,hoge,fuga,p)
    
    return hoge+p

print(piyo(D,C,M))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

ans = 0
n = 0
for d, c in DC:
    t = n
    T = []
    S = []
    while True:
        t += d
        r = 1
        if t > 9:
            t -= 9
            r = 2
        T.append(t)
        S.append(r)
        if t%9 == n:
            break
    loop = c//len(T)
    rem = c%len(T)
    ans += loop*sum(S)
    for r in range(rem):
        ans += S[r]
    n = T[rem-1]

print(ans-1)

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
#print(count_sum)
print(keta-1 + count_sum//10)

Submission status: Wrong Answer

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

M = int(input())

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

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

print(ans + sum(C) - 1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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