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: Accepted

Solution code:
M = int(input())
d=[]
c=[]
count = 0
surplas = 0
for i in range(M):
    D, C = map(int, input().split())
    count += C-1
    count += (D*C-1)//9
    surplas += (D*C-1) % 9 + 1
count += M-1
count += (surplas-1) // 9
print(count)

Submission status: Accepted

Solution code:
M=int(input())
lst=[list(map(int, input().split())) for _ in range(M)]
tmpsum=0
length=0
for i in range(M):
  d, c=lst[i]
  tmpsum+=d*c
  length+=c
print(length+(tmpsum-1)//9-1)

Submission status: Accepted

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

tmp = sumd // 10
while tmp > 0:
    pre = sumd
    sumd += tmp
    tmp = sumd // 10 - pre // 10

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
M = int(input())
c = []
d = []
for i in range(M):
    di,ci = map(int,input().split())
    c.append(ci)
    d.append(di)

s = 0#各桁の和
for i in range(M):
    s += c[i] * d[i]

if s % 9 == 0:
    x = s//9 - 1
else:
    x = s//9

n = sum(c)#桁数

print(x + n - 1)

Submission status: Accepted

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: Accepted

Solution code:
def main():
    M = int(input())
    reduced = [0] * M
    loop = [[] for _ in range(10)]
    for i in range(10):
        sm = i
        cnt = 0
        while True:
            loop[i].append((sm, cnt))
            if sm == i and cnt != 0:
                break
            sm += i
            cnt += 1
            if sm >= 10:
                sm = (sm % 10) + 1
                cnt += 1
        #print(i, loop[i])
    ans = 0
    for i in range(M):
        d, c = map(int, input().split())
        cycle = len(loop[d]) - 1
        a = (c-1) % cycle
        b = (c-1) // cycle
        ans += loop[d][cycle][1] * b + loop[d][a][1]
        reduced[i] = loop[d][a][0]
    # print(ans)
    # print(reduced)
    sm = 0
    for i in range(M):
        sm += reduced[i]
        if sm >= 10:
            sm = (sm % 10) + 1
            ans += 1
    ans += M-1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

total_d = 0
total_len = 0
for d,c in DC:
    total_d += d*c
    total_len += c

ans = (total_d - 1)//9 + total_len - 1
print(ans)

Submission status: Accepted

Solution code:
def canc_loop(d):
    a = 2
    b = 1
    s = d + d
    if s > 10:
        s = 1 + s % 10
        b += 1
    while s != d:
        s += d
        a += 1
        b += 1
        if s >= 10:
            s = 1 + s % 10
            b += 1
    return a, b


def main():
    db = []
    for i in xrange(10):
        db.append(canc_loop(i))
    m = input()
    count = 0
    degi = []
    for _ in xrange(m):
        d, c = map(int, raw_input().split())
        a, b = db[d]
        while c >= a:
            count += c / a * b
            c = c / a + c % a
        degi.extend([d] * c)
    if not degi:
        return count
    d = degi.pop()
    while degi:
        d += degi.pop()
        count += 1
        if d >= 10:
            d = d % 10 + 1
            count += 1
    return count


print main()

Submission status: Accepted

Solution code:
import numpy as np

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

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

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

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

# cnt = 0
# rest = [9 for _ in range(900)]

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

print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

digits_num = 0
total = 0
for d, c in dc:
    digits_num += c
    total += d * c

ans = digits_num - 1 + (total - 1) // 9

print(ans)

Submission status: Accepted

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

    for d, c in DC:
        cS += c
        S += d*c

    ans = cS - 1 + (S-1)//9
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))






def main():
    m = ii()
    count = 0
    csum = 0
    for i in range(m):
        d,c = mi()
        count+= d*c
        csum +=c
    
    ans = 0
    ans+= csum-1

    while count > 9:
        ans+=count//10
        tmp = count//10
        count %= 10
        count += tmp


    print(ans)

    
main()

Submission status: Accepted

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

Submission status: Accepted

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

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


    m = II()
    dc = XLMIIS(m)

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

    if s % 9 == 0:
        ans = k + s//9 - 2
    else:
        ans = k + s//9 - 1

    print(ans)






if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

kei10 = kei//9

if kei%9==0:
    kei10-=1

output = keta-1 + kei10
print(output)

Submission status: Accepted

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

Submission status: Accepted

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

if(kari==0):
  print(ans-2)
else:
  print(ans-1)

Submission status: Accepted

Solution code:
def examD():
    M = I()
    cur = 0; ans = 0
    for i in range(M):
        c, d = LI()
        cur += d*c
        ans += d
    ans += (cur-1)//9 -1
    print(ans)

def examE():
    return

import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()

Submission status: Accepted

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

def main():
    m=int(input())
    DC=[list(map(int,input().split())) for _ in range(m)]
    s=0
    digit=0
    for d,c in DC:
        digit+=c
        s+=d*c
    ans=digit-1
    m=s%9
    if m==0:
        m=9
    ans+=(s-m)//9
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
m = int(input())
dc = []
for i in range(m):
    dc.append(list(map(int, input().split())))
num = 0
for i in range(m):
    num += (dc[i][0] * dc[i][1])
keta = 0
for i in range(m):
    keta += dc[i][1]
count = 0
count += ((num - 1) // 9)
count += (keta - 1)
print(count)

Submission status: Accepted

Solution code:
import sys

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

Submission status: Accepted

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

ans = 0
n = D[0]
C[0] -= 1
for i in range(M):
    c = C[i]
    d = D[i]
    while c != 0:
        if c%2==0:
            ans += c//2*((2*d)//10+1)
            d = (2*d)//10+(2*d)%10
            c //= 2
        else:
            ans += c//2*((2*d)//10+1)
            ans += (n+d)//10+1
            n = (n+d)//10+(n+d)%10
            d = (2*d)//10+(2*d)%10
            c //= 2
print(ans)

Submission status: Accepted

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

print(((gokei-1)//9)+cry-1)

Submission status: Accepted

Solution code:
n = int(input())
digit = [ 0 for i in range(10) ]
l = 0
for i in range(n):
    a, b = [ int(v) for v in input().split() ]
    digit[a] += b
    l += b

x = 0
for i in range(10):
    x += i*digit[i]

ans = l-1 # digit

a, b = divmod(x, 9)
if b == 0:
    a -= 1

ans += a
print(ans)

Submission status: Accepted

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

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

ANS=A//10+keta-1

A=A//10+A%10

while A>=10:
    ANS+=A//10
    A=A//10+A%10

print(ANS)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

digit = 0
numsum = 0
for di, ci in dc:
	digit += ci
	numsum += di*ci

ans = digit-1 + (numsum-1)//9
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0
count2=0

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

Submission status: Accepted

Solution code:
m,*t=map(int,open(0).read().split())
a=b=0
for d,c in zip(*[iter(t)]*2):
    m=[b]
    while c//2:
        cd=c//2
        a+=cd
        if c%2:
            m+=d,
        d*=2
        if d>9:
            a+=cd
            d=d//10+d%10
        c=cd
    for t in m[::-1]:
        d+=t
        a+=1
        if d>9:
            d=d//10+d%10
            a+=1
    b=d
print(a-1)

Submission status: Accepted

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

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

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

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

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

M = I()
dc = [IL() for i in range(M)]

num = 0
cnt = 0
for d,c in dc:
  num += d*c
  cnt += c

print(cnt - 1 + math.ceil(num/9) - 1)

Submission status: Accepted

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

Submission status: Accepted

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


def calc(s_list):
    cnt = 0
    while len(s_list) > 1:
        cnt += 1
        s1 = s_list.pop()
        s2 = s_list.pop()
        new = str(s1 + s2)
        if len(new) == 1:
            s_list.append(int(new))
        else:
            s_list.append(int(new[0]))
            s_list.append(int(new[1]))

    return cnt


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

ten_num = [0] * 10
for i in range(10):
    ten_num[i] = calc([i] * 10)

ans = 0
s_list = []
for i in range(M):
    d, c = D[i], C[i]
    while c > 10:
        div, mod = divmod(c, 10)
        ans += ten_num[d] * div
        c = div + mod
    s_list.extend([d] * c)

ans += calc(s_list)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import repeat
def main():
    m = int(stdin.readline())
    dat = map(int, stdin.read().split(), repeat(10, 2 * m))
    s = sum(dat[i*2] * dat[i*2+1] for i in xrange(m))
    l = sum(dat[1::2])
    print l - 1 + (s - 1) / 9
main()

Submission status: Accepted

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

ans += (all-1) // 9
print(ans)

Submission status: Accepted

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

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

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

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

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

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

Submission status: Accepted

Solution code:
m = int(input())
x = 0
n = 0
for i in range(m):
    d, c = map(int, input().split())
    x += d * c
    n += c
print(((x - 10) // 9 + 1 if x > 9 else 0) + n - 1)

Submission status: Accepted

Solution code:
n = int(input())
ans = -1
num = 0
for i in range(n):
    a,b = map(int,input().split())
    ans += b
    num += a * b
    if num > 9:
        ans += num // 9
        num %= 9
        if num == 0:
            ans -= 1
            num = 9
print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
M = int(readline())
ans = 0
res = 0
for _ in range(M):
    d, c = map(int, readline().split())
    ans += d*c
    res += c

print(-((9-ans)//9) + res - 1)

Submission status: Accepted

Solution code:
import math
M = int(input())
S = 0
L = 0
for _ in range(M):
    d, c = map(int, input().split())
    S+=d*c
    L+=c
print(math.ceil((S-9)/9)+L-1)

Submission status: Accepted

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

ans = 0
t = 0
for i in range(M):
  ans += dc[i][1]
  t += dc[i][1] * dc[i][0]

ans -= 1
ans += (t - 1) // 9

print(ans)

Submission status: Accepted

Solution code:
M = int(input())
DC = [list(map(int, input().split())) for _ in range(M)]
sumC = 0
su = 0
for d, c in DC:
    sumC += c
    su += d * c
ans = sumC-1 + (su-1)//9
print(ans)

Submission status: Accepted

Solution code:
m = int(input())
ans = -1
cnt = 0
for _ in range(m):
  a,b = map(int,input().split())
  cnt += a * b
  ans += b
ans += (cnt-1) // 9
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
m = int(input())
C = [list(map(int,input().split())) for i in range(m)]

cs = sum([i[1] for i in C])
ans = cs-1
mo = 0
for i in range(m):
    mo += C[i][0] * C[i][1]
    ans += mo // 9
    mo %= 9

if mo == 0:
    ans -= 1
print(ans)

Submission status: Accepted

Solution code:
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

#a = list(map(int, input().split()))

n = int(input())
ans1=0
keta=0
for i in range(n):
    p,q = list(map(int, input().split()))
    ans1 += p*q
    keta+=q
print((ans1-1)//9 + (keta-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
m=int(input())
nums=[list(map(int,input().split())) for i in range(m)]
S=0
Slen=0
for i in nums:
  S+=i[0]*i[1]
  Slen+=i[1]
if S%9==0:
  kuriagari=S//9-1
else:
  kuriagari=S//9
print(Slen-1+kuriagari)

Submission status: Runtime Error

Solution code:
m = int(input())
a = []
for _ in range(m):
    d, c = map(int, input().split())
    a.extend([d]*c)
#print(a)

cnt = 0
for i in range(len(a)-1):
    w = a[i]+a[i+1] 
    if w > 9:
        a[i+1] = w - 9
        cnt += 2
    else:
        a[i+1] = w
        cnt += 1
#print(a)
print(cnt)

Submission status: Runtime Error

Solution code:
M=int(input())
ans=0
A=[]
def f(x):
  e=str(x)
  n=len(e)
  l=0
  for i in e:
    l+=int(i)
  if l<10:
    return l
  else:
    f(l)
  
for i in range(M):
  d,c=map(int,input().split())
  ans+=(c-1)+d*c//10
  A.append(f(d*c))
  
ans+=len(A)-1
ans+=(sum(A)-1)//9
print(ans)

Submission status: Runtime Error

Solution code:
M=int(input())
ans=0
A=[]
def f(x):
  e=str(x)
  n=len(e)
  l=0
  for i in e:
    l+=int(i)
  if l<10:
    return l
  else:
    f(l)
  
for i in range(M):
  d,c=map(int,input().split())
  ans+=(c-1)+d*c//10
  A.append(f(d*c))
if len(A)==1:
  print(ans)
  exit()
cnt=A[0]
for i in A[1:]:
  if cnt+i<10:
    cnt+=i
    ans+=1
  else:
    e=str(cnt+i)
    cnt=int(e[0])+int(e[1])
    ans+=2
print(ans)

Submission status: Runtime Error

Solution code:
M=int(input())
ans=0
A=[]
def f(x):
  e=str(x)
  n=len(e)
  l=0
  for i in e:
    l+=int(i)
  if l<10:
    return l
  else:
    f(l)
  
for i in range(M):
  d,c=map(int,input().split())
  ans+=(c-1)+d*c//10
  A.append(f(d*c))
  
cnt=A[0]
for i in A[1:]:
  if cnt+i<10:
    cnt+=i
    ans+=1
  else:
    e=str(cnt+i)
    cnt=int(e[0])+int(e[1])
    ans+=2
print(ans)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
G = [[None] * N for _ in range(N)]
for _ in range(M):
    s, t, d, time = map(int, input().split())
    G[s-1][t-1] = (d, time)
    G[t-1][s-1] = (d, time)

INF = 10 ** 9
dist = [[INF] * N for _ in range(1 << N)]
dist[1][0] = 0
count = [[0] * N for _ in range(1 << N)]
count[1][0] = 1
for state in range(1, 1 << N):
    for p in range(N):
        if count[state][p] == 0:
            continue
        for np in range(1, N):
            if state & (1 << np) or G[p][np] is None:
                continue
            d, limit = G[p][np]
            ndist = dist[state][p] + d
            if limit < ndist:
                continue
            nstate = state | (1 << np)
            if ndist == dist[nstate][np]:
                count[nstate][np] += count[state][p]
            elif ndist < dist[nstate][np]:
                dist[nstate][np] = ndist
                count[nstate][np] = 1
ansd = INF
anscount = 0
for p in range(1, N):
    if count[-1][p] == 0 or G[p][0] is None:
        continue
    d, limit = G[p][0]
    ndist = dist[-1][p] + d
    if ndist <= limit:
        if ndist == ansd:
            anscount += 1
        elif ndist < ansd:
            ansd = ndist
            anscount = count[-1][p]
if anscount == 0:
    print("IMPOSSIBLE")
else:
    print(ansd, anscount)

Submission status: Runtime Error

Solution code:
M = int(input())
num = []
rn = 0

for _ in range(M):
  d,c = map(int,input().split())
  num += [d]*(c%9)
  rn += c//9*(9+d)
  
a = num[0]
for i in range(1,len(num)):
  a += num[i]
  rn += 1
  if len(str(a))>1:
    a = int(str(a)[0]) + int(str(a)[1])
    rn += 1
    
print(rn)

Submission status: Runtime Error

Solution code:
M = int(input())
num = []
rn = 0

for _ in range(M):
  d,c = map(int,input().split())
  num += [d]*c
  
a = num[0]
for i in range(1,len(num)):
  a += num[i]
  rn += 1
  if len(str(a))>1:
    a = int(str(a)[0]) + int(str(a)[1])
    rn += 1
    
print(rn)

Submission status: Runtime Error

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

print((sum(c)-1+sum([c[i]*d[i] for i in range(m)]-1)//9) % 1000000007)

Submission status: Runtime Error

Solution code:
MOD = 10 ** 9 + 7
M = int(input())
ans = 0
li = deque([])
for i in range(M):
    d,c = map(int,input().split())
    ans += c-1
    x = c*d
    ans += (x-1) // 9
    if x == 0:
        ans += 1
        li.append(0)
    else:
        x = x%9
        if x == 0:
            li.append(9)
        else:
            li.append(x)
    ans = ans % MOD
while len(li) >= 2:
    ans += 1
    p = li.popleft()
    q = li.popleft()
    r = p+q
    if r < 10:
        li.appendleft(r)
    else:
        li.appendleft(r%10)
        li.appendleft(r//10)
print(ans%MOD)

Submission status: Runtime Error

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

ans = 0
prev_d = 0
for i in range(M):
    d, c = map(int, input().split())
    N += [d] * c
    ans += c
    if prev_d + d > 9:
        ans += 1
    prev_d = d

print(ans-1)

Submission status: Runtime Error

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    M=I()
    d=[0]*M
    c=[0]*M
    for i in range(M):
        d[i]=I()
    for i in range(M):
        c[i]=I()
        
    ans=0
    
    def make(cc,dd):
        ans+=(cc-1)+(dd*cc)//10
        return (cc*dd)%10
    
    new_cnt=0
    new_d=M
    for i in range(M):
        new_cnt+=make(c[i],d[i])
    make(new_cnt,new_d)
    print(ans)

main()

Submission status: Runtime Error

Solution code:
from numpy.random import *

def tester(M,dc):
    ret = 0
    num = ''
    for d,c in dc:
        num += str(d)*c
    while len(num)>1:
        new = str(int(num[0])+int(num[1]))
        num = new + num[2:]
        ret += 1
    return ret
    
    
while True:
    M = randint(1,3)
    dc = [[randint(1,10),randint(1,10)] for _ in range(M)]
    
    ans = 0
    memo_mod = [[0]*10 for _ in range(10)]
    memo_num = [[0]*10 for _ in range(10)]
    
    
    for i in range(10):
        for j in range(10):
            if i==0 and j==0:
                continue        
            num = 1
            mod = i+j
            while mod>=10:
                mod = mod%10 + mod//10
                num += 1
            memo_mod[i][j] = mod
            memo_num[i][j] = num
        
    mod = 0
    flag = True
    for d,c in dc:
        ans += (c-1) + d*c//10
        new_mod = (d*c%10 + (d*c//10))%10
        if not flag:
            ans += memo_num[mod][new_mod]
        else:
            flag = False
        mod = memo_mod[mod][new_mod]
        
    if ans==tester(M,dc):
        print('ok!')
    else:
        print('Wrong Answer')
        print('M=',M)
        print('dc=')
        for d,c in dc:
            print(d,c)
        
        print('ans=',ans)
        print('Correct ans=',tester(M,dc))
        
        break

Submission status: Runtime Error

Solution code:

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

#%%
ans = 0
memo_mod = [[0]*10 for _ in range(10)]
memo_num = [[0]*10 for _ in range(10)]


for i in range(10):
    for j in range(10):
        if i==0 and j==0:
            continue        
        num = 1
        mod = i+j
        while mod>10:
            mod = mod%10 + mod//10
            num += 1
        memo_mod[i][j] = mod
        memo_num[i][j] = num
    
mod = 0
flag = True
for d,c in dc:
    ans += (c-1) + d*c//10
    new_mod = d*c%10
    if not flag:
        ans += memo_num[mod][new_mod]
    else:
        flag = False
    mod = memo_mod[mod][new_mod]

print(ans)

Submission status: Runtime Error

Solution code:
m = int(input())
CD = [list(map(input().split())) for _ in range(m)]
count = 0
tmp = -1
total = 0
for c, d in CD:
  q, m = divmod(c * d, 9)
  count += q
  tmp += m
  if tmp >= 9:
    count += 1
    tmp %= 9
  total += d
print(total - 1 + count)

Submission status: Runtime Error

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    M = int(input())
    N = ""
    for _ in range(M):
        d, c = map(int, input().split())
        N += str(d) * c

    count = 0
    while len(N) >= 2:
        #print(N)
        N = str(int(N[0]) + int(N[1])) + N[2:]
        count += 1

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()