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 = 0
S = 0
for i in range(M):
    c,d = map(int,input().split())
    D += d
    S += c*d
print(D-1+(S-1)//9)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: tuple(map(int,input().split()))
M = int(input())
S = 0
ans = -1
for _ in range(M):
    d, c = inpl()
    S += d * c
    ans += c

while S >= 10:
    c = S % 10
    ans += S//10
    S = S//10 + c
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    m=int(input())
    dc=[list(map(int, input().split())) for _ in range(m)]
    k=s=0
    for d,c in dc:
        k+=c
        s+=d*c
    print((9*k+s-10)//9)

main()

Submission status: Accepted

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


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

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

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

        S += d * c
        N += c

    print((N - 1) + (S - 1) // 9)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/ddcc2020-qual/submissions/8587774

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]
    if s % 9 != 0:
        ans += s // 9
        s = s % 9
    else:
        ans += s//9 - 1 
        s = 9
print(ans)

Submission status: Accepted

Solution code:
m=int(input())
s,k=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: Accepted

Solution code:
import sys
read = sys.stdin.read

M = int(input())
dc = map(int, read().split())
dig = [0] * 10
cnt = 0
answer = 0
for d, c in zip(*[iter(dc)] * 2):
    dig[d] += c

trans = dict()
for i in range(10):
    if i < 5:
        trans[i] = i + i
    elif i == 5:
        trans[i] = 1
    else:
        trans[i] = trans[i - 1] + 2

while True:
    tmp = [0] * 10
    for i, x in enumerate(dig):
        q, r = divmod(x, 2)
        if x >= 2:
            if i < 5:
                answer += q
                tmp[trans[i]] += q
                tmp[i] += r
            else:
                answer += q * 2
                tmp[trans[i]] += q
                tmp[i] += r
        else:
            tmp[i] += x

    dig = tmp.copy()
    for i in dig:
        if i > 1:
            break
    else:
        break

last = [i for i in range(10) if dig[i] == 1]
while len(last) > 1:
    a = last.pop()
    b = last.pop()
    c = a + b
    if c >= 10:
        answer += 2
        last.append(c // 10 + c % 10)
    else:
        answer += 1
        last.append(c)

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
M = int(input())
S = -1
res = -1
for _ in range(M):
    d, c = map(int, input().split())
    res += c
    S += d*c

res += S // 9
print(res)

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
    print(digit-1+(s-1)//9)
    
if __name__=='__main__':
    main()

Submission status: Accepted

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

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

for i in range(m):
    d,c = map(int,input().split())
    sum1 += d * c
    sumc += c

ans += sumc + (sum1 - 1) // 9 - 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
m = int(input())
cd = [list(map(int, input().split())) for _ in range(m)]
result = -1
s = 0
for i in range(m):
    result += cd[i][1]
    s += cd[i][0]*cd[i][1]

result += (s-1)//9

print(result)

Submission status: Accepted

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


# 桁数*9 + 総和が 9 ずつ減る
M = int(sys.stdin.buffer.readline())
DC = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

s = 0
l = 0
for d, c in DC:
    l += c
    s += d * c
ans = (l * 9 + s - 1) // 9 - 1
print(ans)

Submission status: Accepted

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

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

    a = collections.defaultdict(int)
    for _ in range(m):
        d, c = map(int, sys.stdin.readline().split())
        a[d] += c
    

    b = 0
    for i in range(10):
        b += (i + 9) * a[i]
    
    ans = math.ceil((b - 9)/ 9) - 1
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
m = int(input())
dc=[list(map(int, input().split())) for i in range(m)]
b = [[(1,0)]]
f = []
ans = 0
now = 0
for i in range(1,10):
  mini_b = []
  c = i
  d = 0
  c += i
  d += 1
  while (c // 10):
    c = c % 10 + 1
    d += 1
  mini_b.append((d,c))
  while c != i:  
    c += i
    d += 1
    while (c // 10):
      c = c % 10 + 1
      d += 1
    mini_b.append((d,c))
  b.append(mini_b)
for d,c in dc:
  if d:
    if c > 1:
      x,y = divmod(c-1,len(b[d]))
      if y == 0:
        ans +=  b[d][-1][0] * x
        f.append(d)
      else:
        ans +=  b[d][-1][0] * x + b[d][y-1][0]
        f.append(b[d][y-1][1])
    else:
      f.append(d)
  else:
    ans += c-1
    f.append(0)
for i in f:
  now += i
  ans += 1
  while (now//10):
    now = now % 10 + 1
    ans += 1
  
print(ans-1)

Submission status: Accepted

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

Solution code:
def main():

    M = int(input())

    ans = 0
    a = 0
    b = 0
    for i in range(M):
        d, c = map(int, input().split())
        a += c
        b += c * d
    v = b + a * 9

    if v % 9 == 0:
        return v // 9 - 2
    else:
        return v // 9 - 1

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
m=int(input())
DC=[]
for i in range(m):
  DC.append(tuple(map(int,input().split())))
tot=0
for d,c in DC:
  tot+=c*(9+d)
print((tot-1)//9-1)

Submission status: Accepted

Solution code:

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


ans = 0
M = inp()
zan = []
for m in range(M):
    d,c = inpl()

    while True:
        if c == 1:
            zan.append(d)
            break
        elif c%2 == 0:
            if d == 0:
                ans += c
                break
            elif d <= 4:
                ans += c//2
                d *= 2
                c //= 2
            else:
                ans += c
                d = d*2 - 9
                c //= 2
        else:
            zan.append(d)
            c -= 1

zan.reverse()

bx = zan[0]
for x in zan[1:]:
    d = x + bx
    if d >= 10:
        bx = d - 10 + 1
        ans += 2
    else:
        bx = d
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
#繰り上がりごとに各桁の総和は9減る
#9*最初の桁数+最初の総和がそれで減る
#それは順番によらない

m = int(input())
sm=  0
d = []
c = []
for i in range(m):
    di,ci = map(int, input().split( ))
    d.append(di)
    c.append(ci)
    sm += di*ci

x = sum(c)*9 + sm
y =  x%9
if y==0:
    y = 9
    
print((x-y)//9-1)

Submission status: Accepted

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-1)//9
    ans+=t
    s-= t*9

ans -= 1
print(ans)

Submission status: Accepted

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


def func(a, b):
    return((a+b // 10) + (a+b)-10)


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

print(math.ceil((num-18) / 9))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = []


co = 0

c = 0

for i in range(n):
    a,b = m()

    co += a*b

    c += b

c += (co-1)//9

print(c-1)

Submission status: Accepted

Solution code:
M = int(input())
s = 0
t = 0
for _ in range(M):
    d, c = map(int,input().split())
    s += d * c
    t += c

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read

M = int(input())
dc = map(int, read().split())
dig_sum = 0
dig = 0
for d, c in zip(*[iter(dc)] * 2):
    dig_sum += d * c
    dig += c

answer = (dig_sum - 1) // 9 + dig - 1
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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)-1 + (able-1) // 9 )

Submission status: Accepted

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

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

keta = 0
goukei = 0

for i in range(m):
  keta += dc_list[i][1]
  goukei += dc_list[i][0] * dc_list[i][1]


print(keta -1 + (goukei-1) // 9)

Submission status: Accepted

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 % 9 == 0:
            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: Accepted

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

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

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    m = int(readline())
    dl = []
    cl = []
    s = 0
    for _ in range(m):
        d, c = list(map(int, readline().split()))
        dl.append(d)
        cl.append(c)
        s += d * c
    cnt = 0
    while True:
        if s >= 10:
            cnt += s // 10
            s = s // 10 + s % 10
        else:
            break
    print(sum(cl) + cnt - 1)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

ans = 0
digitsum = 0
digit = 0

for i in range(M):
    digitsum += D[i][0]*D[i][1]
    digit += D[i][1]
print((digitsum-1)//9+digit-1)

Submission status: Accepted

Solution code:
M = int(input())

res = 0
able =0

for i in range(M):

    d,c = map(int,input().split())

    res += c

    able += d * c
    
print ( res-1 + (able-1) // 9 )

Submission status: Accepted

Solution code:
m = int(input())
dc =  [list(map(int,input().split())) for _ in range(m)]
flag = 0
ans = -1
x = 0
for i in range(m):
  x += dc[i][0]*dc[i][1]
  ans += dc[i][1]
if x % 9 == 0:
  ans += x//9-1
else:
  ans += x//9
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
M = int(input())
nums = [tuple(map(int, input().split())) for _ in range(M)]
digits = sum(t[1] for t in nums)
d_sum = sum(t[0] * t[1] for t in nums)
ans = digits - 1 + (d_sum - 1) // 9
print(ans)

Submission status: Accepted

Solution code:
import sys
def input() -> str:
    return sys.stdin.readline()
m = int(input())
n, s = 0, 0
for i in range(m):
  d, c = [int(i) for i in input().split()]
  n += c
  s += d * c
print(n + (s - 1) // 9 - 1)

Submission status: Accepted

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

def main():
    m = int(input())
    ans = 0
    a = 0
    for i in range(m):
        d, c = map(int, input().split())
        ans += c
        a += d * c
    print(ans + (a - 1) // 9 - 1)

main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(m):
    ans += c[i]*d[i]

print((ans-1)//9 + sum(c)-1)

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

m = inn()
cnt = 0
a = []
for i in range(m):
    d,c = inm()
    while c>1:
        if c%2 == 1:
            a.append(d)
            c -= 1
        if d<5:
            d = 2*d
            cnt += c//2
        else:
            d = 2*d-9
            cnt += c
        c //= 2
    a.append(d)

ddprint("cnt {}  a:".format(cnt))
ddprint(a)

x = a.pop()
while len(a)>0 or x>9:
    if x>9:
        x = (x//10)+(x%10)
        cnt += 1
    else:
        y = a.pop()
        x += y
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import math
import sys
input = sys.stdin.readline
def solve():
  m = int(input())
  digit = 0
  s = 0
  for i in range(m):
    d,c = (int(i) for i in input().split())
    digit += d*c
    s += c
  print((digit-1)//9+s-1)
solve()

Submission status: Accepted

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

ans = 0
p = 0
for d, c in DC:
    p += d*c
    ans += c

a = (p-1)%9+1
ans += (p-a)//9-1
print(ans)

Submission status: Accepted

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]
    if s % 9 != 0:
        ans += s // 9
        s = s % 9
    else:
        ans += s//9 - 1 
        s = 9
print(ans)

Submission status: Accepted

Solution code:
M = int(input())
dcnt = 0
calc = 0
for i in range(M) :
    c,d = map(int,input().split())
    dcnt += d
    calc += d*c
calc -= 1
res = calc//9 + dcnt - 1
print(res)

Submission status: Accepted

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-1)//9))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
cha=[0,2,4,6,8,1,3,5,7,9]
m=int(input())
ans=0
l=[]
for _ in range(m):
    d,c=map(int,input().split())
    while c>1:
        if c%2:
            c-=1
            l.append(d)
        c//=2
        ans+=c if d<5 else c*2
        d=cha[d]
    l.append(d)

k=len(l)
while k>1:
    a=l.pop()
    b=l.pop()
    x=a+b
    ans+=1
    if x>9:
        s=str(x)
        l.append(int(s[0]))
        l.append(int(s[1]))
    else:
        l.append(x)
        k-=1
print(ans)

Submission status: Accepted

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
for i in range(m):
  a+=d[i]*c[i]
  dd=(a-1)//9
  ans+=dd
  a-=dd*9
print(ans)

Submission status: Accepted

Solution code:
def main():
    #print = out.append
    ''' Cook your dish here! '''
    m = get_int()
    sm = 0
    smc = 0
    for _ in range(m):
        a, b = get_list()
        sm += a*b
        smc += b
    print(smc-1 + ((sm-1)//9))

''' Coded with love at India by Satyam Kumar '''
import sys
#from collections import defaultdict
import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')

Submission status: Accepted

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 - 1) // 9
print(res)

Submission status: Accepted

Solution code:
M = int(input())
keta = 0
count_sum = 0
for _ in range(M):
    d,c= map(int,input().split(' '))
    keta += c
    count_sum += d*c
additional = count_sum//10
if 9 < count_sum:
    print(keta-1 + (count_sum-1)//9)
else:
    print(keta-1)

Submission status: Accepted

Solution code:
import itertools
import os
import sys

from functools import lru_cache

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)
        round = next_round
        print(round)
        ret += 1
    print('test:', ret)
    print()


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


# 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

memo = [[None] * 11 for _ in range(10)]
for i, j in itertools.product(range(10), range(11)):
    memo[i][j] = solve(str(i) * j)


def kurikaesi(d, c):
    if c < 10:
        return memo[d][c]
    cnt, n1 = memo[d][10]
    ret = cnt * (c // 10)
    c2, n2 = kurikaesi(n1, c // 10)
    c3, n3 = memo[d][c % 10]
    ret += c2
    ret += c3
    c4, n4 = solve(str(n2) + str(n3))
    ret += c4
    return ret, n4


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

ans = 0
num = 0
for d, c in DC:
    cnt, n = kurikaesi(d, c)
    ans += cnt
    c2, n2 = solve(str(num) + str(n))
    ans += c2
    num = n2
print(ans - 1)

Submission status: Accepted

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

for d, c in DC:
    s += d * c
    ans += c

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

Submission status: Accepted

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

Submission status: Accepted

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

ret = 0
s = 0
for d, c in dc :
    s += d * c
    t = s // 10
    ret += t
    s %= 10
    s += t
    
while s >= 10 :
    t = s // 10
    ret += t
    s %= 10
    s += t

for d, c in dc :
    ret += c
        
print(ret - 1)

Submission status: Accepted

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
    b[i]=a[i][0]*a[i][1]
    while b[i]>=10:
        ans+=b[i]//10
        b[i]=b[i]//10+b[i]%10


ans+=M-1
x=sum(b)
while x>=10:
    ans+=x//10
    x=x//10+x%10
print(int(ans))

Submission status: Accepted

Solution code:
M = int(input())
ans = 0
prev = 0
arr = []
for _ in range(M):
    d, c = map(int, input().split())
    ans += c-1
    total = 0
    a = (c-1) // 9
    b = (c-1) % 9 + 1
    if d == 1:
        ans += a
        total = b
    elif d == 2:
        ans += a * 2
        if b >= 5: ans += 1
        total = [2,4,6,8,1,3,5,7,9][b-1]
    elif d == 3:
        ans += (c-1) // 3
        total = ((c-1) % 3 + 1) * 3
    elif d == 4:
        ans += a * 4
        if b >= 3: ans += 1
        if b >= 5: ans += 1
        if b >= 7: ans += 1
        total = [4,8,3,7,2,6,1,5,9][b-1]
    elif d == 5:
        ans += a * 5
        if b >= 2: ans += 1
        if b >= 4: ans += 1
        if b >= 6: ans += 1
        if b >= 8: ans += 1
        total = [5,1,6,2,7,3,8,4,9][b-1]
    elif d == 6:
        ans += ((c-1) // 3) * 2
        b = (c-1) % 3 + 1
        if b >= 2: ans += 1
        total = [6,3,9][b-1]
    elif d == 7:
        ans += a * 7
        if b >= 2: ans += 1
        if b >= 3: ans += 1
        if b >= 4: ans += 1
        if b >= 6: ans += 1
        if b >= 7: ans += 1
        if b >= 8: ans += 1
        total = [7,5,3,1,8,6,4,2,9][b-1]
    elif d == 8:
        ans += a * 8
        if b >= 2: ans += 1
        if b >= 3: ans += 1
        if b >= 4: ans += 1
        if b >= 5: ans += 1
        if b >= 6: ans += 1
        if b >= 7: ans += 1
        if b >= 8: ans += 1
        total = [8,7,6,5,4,3,2,1,9][b-1]
    elif d == 9:
        ans += (c-1)
        total = 9
    elif d == 0:
        total = 0
    # if prev + total >= 10:
    #     ans += 1
    #     total = (prev + total - 1) % 9 + 1
    # prev = total
    arr.append(total)
p = arr[0]
for m in arr[1:]:
    ans += 1
    if p + m >= 10:
        ans += 1
        p = (p + m - 1) % 9 + 1
    else:
        p = p + m
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

m = inp()
d = [0] * m
c = [0] * m
res = 0
for i in range(m):
    d[i], c[i] = inpl()
    res += d[i]*c[i]
tmp = 0
if res % 9 == 0:
    tmp -= 1
print(res//9+tmp+sum(c)-1)

Submission status: Accepted

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]
    if tmp % 9 == 0:
        k = tmp // 9 - 1
        r = 9
    else:
        k = tmp // 9
        r = tmp % 9
    if tmp >= 10:
        ans += k
        tmp = r

print(ans + sum(C) - 1)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

m= int(input())
dc=[]
s=0
for i in range(m):
    dc.append(list(map(int,input().split())))
    s+=dc[i][0]*dc[i][1]


ans=s//9

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

if s%9==0:
    ans-=1

print(ans-1)

Submission status: Accepted

Solution code:
def sum_lr(l, r, cnt):
    cnt += 1
    lr = l + r
    if lr < 10:
        l = lr
        return l, cnt
    else:
        l = lr // 10
        r = lr % 10
        return sum_lr(l, r, cnt)

from collections import defaultdict
aaa = defaultdict(lambda:{})
for l in range(10):
    for r in range(10):
        aaa[l][r] = sum_lr(l,r,0)
        

def dc_compression(d, c, ret, cnt):
    if c == 1:
        ret.append((d, 1))
        return ret, cnt
    
    if c % 2 == 1:
        ret.append((d, 1))
        c -= 1
    d, tmp_cnt = aaa[d][d]
    c = c // 2
    cnt += tmp_cnt * c
    #print(d, c, ret, cnt)
    return dc_compression(d, c, ret, cnt)
    
    
    
        

M = int(input())

nums = []
l = 0
cnt = 0
import sys
input = sys.stdin.readline
for _ in range(M):
    d, c = map(int, input().split())
    tmp_nums, tmp_cnt= dc_compression(d,c,[], 0)
    for t,_ in tmp_nums:
        nums.append(t)
    
    cnt += tmp_cnt
    
#print(nums)    
    
for d in nums:
    l, tmp_cnt = aaa[l][d]
    cnt += tmp_cnt

print(cnt-1)

Submission status: Accepted

Solution code:
m = int(input())

ans = 0

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

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

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

    num = int(up) + int(nums[-1])
    nums = str(num)

print(ans)
exit()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
cha=[0,2,4,6,8,1,3,5,7,9]
m=int(input())
ans=0
from collections import deque
l=deque()
for _ in range(m):
    d,c=map(int,input().split())
    while c>1:
        if c%2:
            c-=1
            l.append(d)
        c//=2
        ans+=c if d<5 else c*2
        d=cha[d]
    l.append(d)

k=len(l)
while k>1:
    a=l.pop()
    b=l.pop()
    x=a+b
    ans+=1
    if x>9:
        s=str(x)
        l.append(int(s[0]))
        l.append(int(s[1]))
    else:
        l.append(x)
        k-=1
print(ans)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
M=int(input())
S,s=0,0
for i in range(M):
    d,c=map(int,input().split())
    S+=d*c
    s+=c
if S%9==0:
    a=S//9-1
else:
    a=S//9
a+=s-1
print(a)

Submission status: Accepted

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

Submission status: Accepted

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-1)//9)