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: Runtime Error

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
from pprint import pprint

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)

    ans = 0
    rem = []
    for d, c in CD:
        if d == 0:
            ans += c
            continue
        _, dc, dv = C[c]
        while c >= dc:
            v = c // dc
            ans += v * dv
            c = c % dc + v
        for _ in range(c):
            rem.append(d)

    while len(rem) > 1:
        a = rem.pop()
        b = rem.pop()
        c = a + b
        ans += 1
        if c >= 10:
            c = c % 10 + c // 10
            ans += 1
        rem.append(c)

    return ans


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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
m=int(input())
d=[]
c=[]
z=0
for i in range(m):
    a,b=map(int,input().split())
    d.append(a)
    c.append(b)
    z+=c*d
ans=0
print(sum(d)-1+z//9)
exit()
def ika(x,y):
    ret=0
    z=x*y
    ret+=y-1
    while z>9:
        s=list(str(z))
        ret+=len(s)-1
        i5=0
        for i in range(len(s)):
            s[i]=int(s[i])
        g=0
        while g<len(s)-1:
            if s[g]+s[g+1]>=10:
                #ret+=1
                g+=2
            else:
                g+=1
        z=sum(s)
        ret+=(z-10)//10
    return [ret,z]
ka=[]
for i in range(m):
    f=ika(d[i],c[i])
    ans+=f[0]
    ka.append(f[1])
print(ans+ika(sum(ka),1)[0]+len(ka)-1)

Submission status: Runtime Error

Solution code:
M=int(input())
#Get the number that needs to be handled
num=''
for _ in range(M):
    x=list(map(int, input().split()))
    num+=''.join([str(x[0]) for _ in range(x[1])])
#print(num)
# get the list from the number
res = [int(x) for x in str(num)]
#print(res)

count=1
#now do the loop
while True:
    count+=1
    #print(count, "->",res[0:2], res[2:])
    s1=sum(res[0:2])
    res.pop(1)
    res.pop(0)
    for i in str(s1):
        res.insert(0,int(i))
    #print(sum(res))
    if (len(res)<=2) and sum(res)<9:
        break
#the sum of the residual should be less than 9
print(count)

Submission status: Runtime Error

Solution code:
M=int(input())
s=[input() for _ in range(M)]
z=[]
for x in s:
    d=list(map(int, x.split()))
    for i in range(d[1]):
        z.append(d[0])
count = len(N)-1
while True:
    if sum(z)>9: 
        z=map(int, str(sum(z)))
        count += 1
    else:
        break
print(count)

Submission status: Runtime Error

Solution code:
M = int(input())

N = ''
for i in range(M):
    d, c = map(int, input().split())
    N += str(d) * c

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())
D = 0
S = 0
for i in range(M):
	D += c[i]
	S += d[i] * c[i]
print((D - 1) + (S // 9)

Submission status: Runtime Error

Solution code:
M = int(input())

N = ''
for i in range(M):
    d, c = map(int, input().split())
    N += str(d) * c

D = len(N)
S = sum(map(int, N))

ans = (D - 1) + S // 9

print(ans)

Submission status: Runtime Error

Solution code:
M = int(input())

N = ''
for i in range(M):
    d, c = map(int, input().split())
    N += str(d) * c

ans = 0
while int(N) >= 10:
    ans += 1
    _max = 0
    for i in range(len(N)-1):
        compress = sum(map(int, N[i:i+2]))
        tmp = int(N[:i] + str(compress) + N[i+2:])
        if tmp < int(N):
            _max = max(_max, tmp)

    N = str(_max)
print(ans)

Submission status: Runtime Error

Solution code:
m = int(input())
ans = 0
num = ""
for i in range(m):
    d, c = map(int, input().split())
    if d == 0:
        ans += c
    else:
        k = str(d) * c
        while len(k) != 1:
            k = str(int(k[0]) + int(k[1])) + k[2:]
            ans += 1
        num += k
while len(num) != 1:
    num = str(int(num[0]) + int(num[1])) + num[2:]
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    M = int(input())
    ans = 0
    dc = [[int(i) for i in input().split()] for _ in range(M)]
    s = "".join(str(d)*c for d, c in dc)
    if len(s) == 1:
        print(0)
    while len(s) > 2:
        s = str(int(s[0]) + int(s[0+1])) + s[0+2:]
        ans += 1
    while len(s) > 1:
        s = str(int(s[0]) + int(s[1]))
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    M = int(input())
    sum1 = 0
    sum2 = 0
    ans = 0
    dc = [[int(i) for i in input().split()] for _ in range(M)]
    s = "".join(str(d)*c for d, c in dc)
    if len(s) == 1:
        print(0)
    while len(s) != 1:
        s = str(int(s[0]) + int(s[0+1])) + s[0+2:]
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


def main():
    M = int(input())
    digits = []
    S = 0

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

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

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

    print((len(d) - 1) + (S - 1) // 9)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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)]
  
cnt = sum(c) - 1
add_two = 0
 
for i in range(m):
  add_two += d[i] * c[i]
  if add_two % 9 == 0:
    cnt += add_to // 9
    add_two = 9
  else:
    cnt += add_two // 9
    add_two = add_two % 9
 
print(cnt)

Submission status: Runtime Error

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)]
  
cnt = sum(c) - 1
add_two = 0

for i in range(m):
  add_two += int(dc[i][0]) * int(dc[i][1])
  if add_two % 9 == 0:
    cnt += add_to // 9
    add_two = 9
  else:
    cnt += add_two // 9
    add_two = add_two % 9

print(cnt)

Submission status: Runtime Error

Solution code:
m = int(input())
dc = []

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

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)]
  
cnt =sum(c) - 1

for i in range(m):
  add_two += int(dc[i][0]) * int(dc[i][1])
  if add_two % 9 == 0:
    cnt += add_to // 9
    add_two = 9
  else:
    cnt += add_two // 9
    add_two = add_two % 9

print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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])
  
cnt = sum_c - 1

for i in range(m):
  add_two += int(dc[i][0]) * int(dc[i][1])
  if add_two % 9 == 0:
    cnt += add_to // 9 - 1
    add_two = 9
  else:
    cnt += add_two // 9
    add_two = add_two % 9

print(cnt)

Submission status: Runtime Error

Solution code:
M = int(input())
d = [0]*M
c = [0]*M
n = 0
S = ""
for i in range(M):
    d[i], c[i] = map(int,input().split())
    N = str(d[i])*c[i]
    while len(N) >= 2:
        N = str(int(N[0])+int(N[1]))+N[2:]
        n += 1

    S += N
    while len(S) >= 2:
        S = str(int(S[0])+int(S[1]))+S[2:]
        n += 1

print(n)

Submission status: Runtime Error

Solution code:
M=int(input())
s=""
for i in range(M):
  d,c=[c for c in input().split()]
  s+=d*int(c)

ans=0
sum=1000000
while(sum>=10):
  sum=0
  for i in range(len(s)):
    sum+=int(s[i])
    ans+=1
  ans-=1
  s=str(sum)
print(ans)

Submission status: Runtime Error

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])
  
cnt = sum_c - 1

for i in range(m):
  add_two += int(dc[i][0]) * int(dc[i][1])
  if add_two % 9 == 0:
    cnt += add_to // 9
    add_two = 9
  else:
    cnt += add_two // 9
    add_two = add_two % 9

print(cnt)

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

N = [0]*M
for j in range(M):
    N[j] = str(d[j])*c[j]

n = 0
for k in range(M):
    while len(N[k]) >= 2:
        N[k] = str(int(N[k][0])+int(N[k][1]))+N[k][2:]
        n += 1

while len(N) >= 2:
    N[0] = str(int(N[0])+int(N[1]))
    if len(N[0]) >= 2:
        N[0] = str(int(N[0][0]) + int(N[0][1]))
        n += 1
    N[1:] = N[2:]
    n += 1


print(n)

Submission status: Runtime Error

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

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

answer = 0

def dfs(count, l):
    global answer
    if len(l) == 1:
        #print(count)
        answer = max(answer, count)
    else:
        i = -2
        sum = l[i] + l[i+1]
        result = l[:i] + [int(x) for x in list(str(sum))]
        #print(result)
        dfs(count+1, result)

dfs(0, L)
print(answer)

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

N = [0]*M
for j in range(M):
    N[j] = str(d[j])*c[j]

n = 0
for k in range(M):
    while len(N[k]) >= 2:
        N[k] = str(int(N[k][0])+int(N[k][1]))+N[k][2:]
        n += 1

K = "".join(N)
while len(K) >= 2:
    K = str(int(K[0])+int(K[1]))+K[2:]
    n += 1

print(n)

Submission status: Runtime Error

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

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

answer = 0

def dfs(count, l):
    global answer
    if len(l) == 1:
        #print(count)
        answer = max(answer, count)
    else:
        i = 0
        sum = l[i] + l[i+1]
        result = l[:i] + [int(x) for x in list(str(sum))] + l[i+2:]
        #print(result)
        dfs(count+1, result)

dfs(0, L)
print(answer)

Submission status: Runtime Error

Solution code:
import sys


def func(n):
    l = []
    for i in range(len(n) - 1):
        l.append(int(n[i]) + int(n[i + 1]))
    i = l.index(max(l))
    return n[:i] + str(int(n[i]) + int(n[i + 1])) + n[i + 2:]


input = sys.stdin.readline
m = int(input())
d = ''
for i in range(m):
    a = list(map(int, input().split()))
    d += str(a[0]) * a[1]

n = d
cnt = 0
while int(n) >= 10:
    n = func(n)
    cnt += 1

print(cnt)

Submission status: Runtime Error

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

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

N = ""
for j in range(M):
    N += str(d[j])*c[j]

n = 0
while True:
    N = str(int(N[0])+int(N[1]))+N[2:]
    n += 1
    if int(N) < 10:
        break

print(n)

Submission status: Runtime Error

Solution code:
def add(x,y):
  return x+y
  if(x+y>=10):
    return 1+(x+y)%10
  else:
    return x+y
  
M=int(input())
s=""
for i in range(M):
  d,c=[c for c in input().split()]
  s+=d*int(c)
  
ans=0
while(len(s)>1):
  M=0
  pos=-1
  for i in range(len(s)-1):
    if(add(int(s[i]),int(s[i+1]))>M):
      M=add(int(s[i]),int(s[i+1]))
      pos=i
  s=s[:pos]+str(M)+s[pos+2:]
  ans+=1
  #print(s)
print(ans)

Submission status: Runtime Error

Solution code:
def add(x,y):
  if(x+y>=10):
    return 1+(x+y)%10
  else:
    return x+y
  
M=int(input())
s=""
for i in range(M):
  d,c=[c for c in input().split()]
  s+=d*int(c)
  
ans=0
while(len(s)>1):
  M=0
  p=-1
  for i in range(len(s)-1):
    if(add(int(s[i]),int(s[i+1]))>M):
      M=add(int(s[i]),int(s[i+1]))
      pos=i
  s=s[:pos]+str(M)+s[pos+2:]
  ans+=1
print(ans)

Submission status: Runtime Error

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

short = []
additional = 0
for elm in L:
    additional += (elm[1] - 1)
    total = elm[0] * elm[1]
    if total > 9:
        if total % 9 == 0:
            additional += (total // 9) - 1
        else:
            additional += total // 9
        # additional += (total - 1) // 9
    if total > 9:
        if total % ９==０：
            res = 9
        else:
            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: Runtime Error

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

short = []
additional = 0
for elm in L:
    additional += (elm[1] - 1)
    total = elm[0] * elm[1]
    if total > 9:
        if total % 9 == 0:
            additional += (total // 9) - 1
        else:
            additional += total // 9
        # additional += (total - 1) // 9
    if total > 9:
        if total % ９＝＝０：
            res = 9
        else:
            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: Runtime Error

Solution code:
def fusion(s):
	if len(s)==2:
		return int(s[0])+ int(s[1])
	pos = 0
	mx = 0
	for i in range(len(s)-1):
		val = int(s[i])+int(s[i+1])
		if val>mx:
			mx = val
			pos=i
	res = ""
	for i in range(pos):
		res+=s[i]
	res+=str(int(s[pos])+int(s[pos+1]))
	for i in range(pos+2,len(s)):
		res+=s[i]
	#~ print("s= ",s, "pos = ",pos, "res = ",res)
	return res
	
def f(s):
	step=0
	while len(s)>1:
		#~ print(s)
		s = str(fusion(s))
		step+=1
	#~ print(s)
	return int(s),step
	

m= int(input())
chaine = ""
ans = 0
for _ in range(m):
	d,c = (int(i) for i in input().split())
	if d==0:
		ans+=c-1
		chaine+="0"
	else:
		r,cnt = (i for i in f(str(d)*c))
		ans+=cnt
		chaine+=str(r)
	
r,cnt = (i for i in f(chaine))
ans+=cnt
print(ans)

Submission status: Runtime Error

Solution code:
M = int(input())
player = ''
for _ in range(M):
    d, c = map(int, input().split())
    player += str(d)*c

ans = 0
while int(player) > 9:
    n = 0
    for i in range(len(player)-1):
        s = int(player[i])+int(player[i+1])
        n = max(n, int(player[:i]+str(s)+player[i+2:]))
    player = str(n)
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
def func(n):
    l = []
    for i in range(len(n) - 1):
        l.append(int(n[i]) + int(n[i + 1]))
    i = l.index(max(l))
    try:
        return n[:i] + str(int(n[i]) + int(n[i + 1])) + n[i + 2:]
    except IndexError:
        return n[:i] + str(int(n[i]) + int(n[i + 1]))


m = int(input())
d = ''
for i in range(m):
    a = list(map(int, input().split()))
    d += str(a[0]) * a[1]

n = d
cnt = 0
while int(n) >= 10:
    n = func(n)
    cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
def func(n):
    l = []
    for i in range(len(n) - 1):
        l.append(int(n[i]) + int(n[i + 1]))
    i = l.index(max(l))
    return n[:i] + str(int(n[i]) + int(n[i + 1])) + n[i + 2:]


m = int(input())
d = ''
for i in range(m):
    a = list(map(int, input().split()))
    d += str(a[0]) * a[1]

n = d
cnt = 0
while int(n) >= 10:
    n = func(n)
    cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
#dfs
import sys
sys.setrecursionlimit(10 ** 7)

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

answer = 0

def dfs(count, l):
    global answer
    if len(l) == 1:
        #print(count)
        answer = max(answer, count)
    else:
        for i in range(len(l)-1):
            sum = l[i] + l[i+1]
            result = l[:i] + [int(x) for x in list(str(sum))] + l[i+2:]
            #print(result)
            dfs(count+1, result)

dfs(0, L)
print(answer)

Submission status: Runtime Error

Solution code:
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-1)//9)
else:
    print(keta-1)
'''

Submission status: Runtime Error

Solution code:
M = int(input())

n = []


for i in range(M):
    d, c = [v for v in input().split()]

    dv = int(d)
    cv = int(c)
    if cv == 1:
        n.append(dv)
    else:
        n.extend([dv] * cv)

def max_i(n):
    n1 = n[-1]
    for i in reversed(range(1, len(n))):
        n2 = n[i]
        n3 = n1 + n2
        if n3 >= 10:
            return i - 1
        n1 = n2

    n1 = n[0]
    for i in range(1, len(n)):
        n2 = n[i]
        n3 = n1 + n2
        if n1 < n3:
            return i - 1
        n1 = n2

def next_n(n, i):
    v = n[i] + n[i + 1]
    if v > 9:
        n[i] = v // 10
        n[i + 1] = v % 10
    else:
        n[i] += n.pop(i + 1)

a = 0
while len(n) > 1:
    #print(n)
    j = max_i(n)
    next_n(n, j)
    a += 1

print(a)

Submission status: Runtime Error

Solution code:
m=int(input())
lst1=[]
lst2=[]
for i in range(m):
  d,c=map(int,input().split())
  lst1.append([d,c])
  lst2.append(c)
lst3=[]
for j in range(m):
  lst3.append(lst1[j][0]*lst1[j][1])
cnt=0
while len(lst3)>1:
  if sum(lst3)>9:
    cnt+=1
    lst3=[]
　　  while i > 0:
    　　  lst3.append(i%10)
    　　  i //= 10 
　　  lst3.reverse()
print(cnt+sum(lst2)-1)

Submission status: Runtime Error

Solution code:
#dfs
import sys
sys.setrecursionlimit(10 ** 7)

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

answer = 20

def dfs(count, l):
    global answer
    if len(l) == 1:
        #print(count)
        answer = min(answer, count)
    elif count > answer:
        return
    else:
        for i in range(len(l)-1):
            sum = l[i] + l[i+1]
            result = l[:i] + [int(x) for x in list(str(sum))] + l[i+2:]
            #print(result)
            dfs(count+1, result)

dfs(0, L)
print(answer)

Submission status: Runtime Error

Solution code:
M = int(input())

N = ''
for i in range(M):
    d, c = map(int, input().split())
    N += str(d) * c

before = int(N)
people = N
ans = 0
while int(N) >= 10:
    ans += 1
    for i in range(len(N)-1):
        _max = 0
        compress = sum(map(int, N[i:i+2]))
        tmp = int(N[:i] + str(compress) + N[i+2:])
        if tmp < int(N):
            _max = max(_max, tmp)

    N = str(_max)

# if int(N) < 10:
#     print()
#
print(ans)

Submission status: Runtime Error

Solution code:
m=int(input())
lst1=[]
lst2=[]
for i in range(m):
  d,c=map(int,input().split())
  lst1.append([d,c])
  lst2.append(c)
lst3=[]
for j in range(m):
  lst3.append(lst1[j][0]*lst1[j][1])
cnt=0
while len(lst3)>1:
  if sum(lst3)>9:
    cnt+=1
    lst3=[]
　　while i > 0:
    　　lst3.append(i%10)
    　　i //= 10 
　　lst3.reverse()
print(cnt+sum(lst2)-1)

Submission status: Runtime Error

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(1,len(sct)):
    ans+=int(ct[0:i])
print(ans)

Submission status: Runtime Error

Solution code:
# 2019-11-23 21:00:35(JST)
import sys

def main():
    m = int(sys.stdin.readline().rstrip())

    S = ''

    total = 0
    for i in range(m):
        d, c = sys.stdin.readline().split()
        c = int(c)
        s = d * c
        count = 0
        while len(s) >= 2:
            s = str(int(s[0]) + int(s[1])) + s[2:]
            count += 1
        total += count
        S += s

    
    while len(S) >= 2:
        S = str(int(S[0]) + int(S[1])) + S[2:]
        total += 1
    
    print(total)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
def input() -> str:
    return sys.stdin.readline()
m = int(input())
n = ""
cnt = 0
for i in range(m):
  d, c = input().split()
  if d == "0":
    cnt += int(c)
  # elif d == "1":
  #   cnt +=
  else:
    n += d * int(c)
# print(n)
while int(n) >= 10:
  n = n[2:] + str(int(n[0]) + int(n[1]))
  cnt += 1
# print(n)
print(cnt)

Submission status: Runtime Error

Solution code:
m = int(input())
d, c = [], []
n = ''

for i in range(m):
    v1, v2 = map(int, input().split())
    d.append(v1)
    c.append(v2)
    n += str(v1) * v2

cnt = 0
length = sum(c)
prev = -2

for i in range(length-1):
    temp = int(n[i]) + int(n[i+1])
    if temp > 9 and i - prev > 1:
        prev = i
        #if int(n[i-1]) + 1 > 9 or (temp % 10) + n[i+2] > 9:
        if i - 1 >= 0 and int(n[i-1]) + 1 > 9:
            cnt += 2
            continue
        if i+2 <= length-1 and (temp % 10) + int(n[i+2]) > 9:
            cnt += 2
            continue
        cnt += 1

# print('n:', n)
# print('length:', length)
# print('cnt:', cnt)

ans = length - 1 + cnt

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
M=int(input())
D=np.zeros(M,dtype=int)
C=np.zeros(M,dtype=int)
for i in range(M):
  d,c=map(int,input().split())
  D[i]=d
  C[i]=c
  
A=np.zeros(C.sum(),dtype=int)
ind=0
for i in range(D.size):
  for j in range(C[i]):
    A[ind]=D[i]
    ind+=1

yosen=0
while A.size>1:
  found=False
  for i in range(A.size-1):
    if A[i]+A[i+1]>=10:
      newa=A[i]+A[i+1]
      A[i]=newa//10
      A[i+1]=newa%10
      found=True
      yosen+=1
      break
  if not found:
    if A.size<=1:
      break
    A[1]=A[0]+A[1]
    yosen+=1
    A=np.delete(A,0)
print(yosen)

Submission status: Runtime Error

Solution code:
import numpy as np
M=int(input())
D=np.zeros(M,dtype=int)
C=np.zeros(M,dtype=int)
for i in range(M):
  d,c=map(int,input().split())
  D[i]=d
  C[i]=c
  
A=np.zeros(C.sum(),dtype=int)
ind=0
for i in range(D.size):
  for j in range(C[i]):
    A[ind]=D[i]
    ind+=1

yosen=0
while A.size>1:
  found=False
  for i in range(A.size-1):
    if A[i]+A[i+1]>=10:
      newa=A[i]+A[i+1]
      A[i]=newa//10
      A[i+1]=newa%10
      found=True
      yosen+=1
      break
  if not found:
    A[1]=A[0]+A[1]
    yosen+=1
    A=np.delete(A,0)
print(yosen)

Submission status: Runtime Error

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


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

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

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

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

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

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

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

    print(ith)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#dfs
import sys
sys.setrecursionlimit(10 ** 7)

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

answer = 15

def dfs(count, l):
    global answer
    if len(l) == 1:
        #print(count)
        answer = min(answer, count)
    else:
        for i in range(len(l)-1):
            sum = l[i] + l[i+1]
            result = l[:i] + [int(x) for x in list(str(sum))] + l[i+2:]
            #print(result)
            dfs(count+1, result)

dfs(0, L)
print(answer)

Submission status: Runtime Error

Solution code:
# 2019-11-23 21:00:35(JST)
import sys

def main():
    m = int(sys.stdin.readline().rstrip())

    s = ''
    for i in range(m):
        d, c = sys.stdin.readline().split()
        c = int(c)
        s += d * c

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




if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


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

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

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

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

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

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

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

    print(ith)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
M = int(input())

n = []


for i in range(M):
    d, c = [v for v in input().split()]

    dv = int(d)
    cv = int(c)
    if cv == 1:
        n.append(dv)
    else:
        n.extend([dv] * cv)

def max_i(n):
    n1 = n[0]
    j = -1
    for i in range(1, len(n)):
        n2 = n[i]
        n3 = n1 + n2
        if n3 >= 10:
            return i - 1
        if j < 0 and n1 < n3:
            j = i - 1
        n1 = n2
    return j

def next_n(n, i):
    v = n[i] + n[i + 1]
    if v > 9:
        n[i] = v // 10
        n[i + 1] = v % 10
    else:
        n[i] += n.pop(i + 1)

a = 0
while len(n) > 1:
    #print(n)
    j = max_i(n)
    next_n(n, j)
    a += 1

print(a)

Submission status: Runtime Error

Solution code:
m=int(input())
lst1=[]
lst2=[]
for i in range(m):
  d,c=map(int,input().split())
  lst1.append([d,c])
  lst2.append(c)
lst=[]
for j in range(m):
  lst.append(lst1[j][0]*lst1[j][1])
cnt=0
while len(lst)>1:
  if sum(lst)>9:
    cnt+=1
    lst=map(int,list(str(sum(lst))))
print(cnt+sum(lst2)-1)

Submission status: Runtime Error

Solution code:
#dfs
import sys
sys.setrecursionlimit(10 ** 7)

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

answer = 30

def dfs(count, l):
    global answer
    if len(l) == 1:
        #print(count)
        answer = min(answer, count)
    else:
        for i in range(len(l)-1):
            sum = l[i] + l[i+1]
            result = l[:i] + [int(x) for x in list(str(sum))] + l[i+2:]
            #print(result)
            dfs(count+1, result)

dfs(0, L)
print(answer)

Submission status: Runtime Error

Solution code:
def fusion(s):
	if len(s)==2:
		return int(s[0])+ int(s[1])
	pos = 0
	mx = 0
	for i in range(len(s)-1):
		val = int(s[i])+int(s[i+1])
		if val>mx:
			mx = val
			pos=i
	res = ""
	for i in range(pos):
		res+=s[i]
	res+=str(int(s[pos])+int(s[pos+1]))
	for i in range(pos+2,len(s)):
		res+=s[i]
	#~ print("s= ",s, "pos = ",pos, "res = ",res)
	return res
	
def f(s):
	step=0
	while len(s)>1:
		#~ print(s)
		s = str(fusion(s))
		step+=1
	#~ print(s)
	return int(s),step
	

m= int(input())
chaine = ""
ans = 0
for _ in range(m):
	d,c = (int(i) for i in input().split())
	r,cnt = (i for i in f(str(d)*c))
	ans+=cnt
	chaine+=str(r)
	
r,cnt = (i for i in f(chaine))
ans+=cnt
print(ans)