Problem:


Score: 500 points

Problem Statement

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

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

All the N contestants will participate in the first round.

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

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

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

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

The preliminary stage ends when 9 or fewer contestants remain.

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

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

Constraints

1 \leq M \leq 200000

0 \leq d_i \leq 9

d_1 \neq 0

d_i \neq d_{i+1}

c_i \geq 1

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

Input

Input is given from Standard Input in the following format:

M
d_1 c_1
d_2 c_2
:
d_M c_M

Output

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

Sample Input 1

2
2 2
9 1

Sample Output 1

3

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

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

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

Sample Input 2

3
1 1
0 8
7 1

Sample Output 2

9

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



Sample input:
2
2 2
9 1


Sample output:
3

Submission status: Wrong Answer

Solution code:
n=int(input())

dnum =0
dsum =0

for i in range(n):
  d,c=map(int,input().split())
  dnum += c
  dsum += d*c
  
ans = dnum-1 + dsum//9

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

dnum =0
dsum =0

for i in range(n):
  d,c=map(int,input().split())
  dnum += c
  dsum += d*c
  
ans = c-1 + dsum//9

print(ans)

Submission status: Wrong Answer

Solution code:
m = int(input())
digit, d_sum = 0, 0
for i in range(m):
    a, b = map(int, input().split())
    digit += b
    d_sum += a * b

d_sum //= 10
print(digit + d_sum - 1)

Submission status: Wrong Answer

Solution code:
mat = [[(0, 0)]*11 for _ in range(10)]
def dsr(i):
    x, cnt = 0, 0
    for j in range(1, 11):
        w = x+ i
        if w > 9:
            x = w - 9
            cnt += 2
        else:
            x = w
            cnt += 1
        mat[i][j] = (x, cnt-1)
for i in range(10):
    dsr(i)
#print2(mat)

m = int(input())
cnt = 0; x0 = 0   
for _ in range(m):
    d, c = map(int, input().split())
    q, r = divmod(c, 9)
    cnt += mat[d][10][1]*q + mat[d][r][1] 
    x = mat[d][r][0]
    #print('x, cnt', x, cnt)
    w = x0 + x
    if w > 9:
        x0 = w - 9
        cnt += 2
    else:
        x0 = w
        cnt += 1
    #print('x0, x, cnt', x0, x,  cnt)    
print(cnt-1)

Submission status: Wrong Answer

Solution code:
mat = [[(0, 0)]*11 for _ in range(10)]
def dsr(i):
    x, cnt = 0, 0
    for j in range(1, 11):
        w = x+ i
        if w > 9:
            x = w - 9
            cnt += 2
        else:
            x = w
            cnt += 1
        mat[i][j] = (x, cnt)
for i in range(10):
    dsr(i)
#print2(mat)

m = int(input())
cnt = 0; x0 = 0   
for _ in range(m):
    d, c = map(int, input().split())
    q, r = divmod(c, 10)
    cnt += mat[d][10][1]*q + mat[d][r][1] - 1
    x = mat[d][r][0]
    #print('x, cnt', x, cnt)
    w = x0 + x
    if w > 9:
        x0 = w - 9
        cnt += 2
    else:
        x0 = w
        cnt += 1
    #print('x0, x, cnt', x0, x,  cnt)    
print(cnt-1)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    m = int(input())
    DC = [list(map(int, input().split())) for _ in range(m)]
    total = 0
    res = 0
    for d, c in DC:
        q, r = divmod(c * d, 10)
        res += q + c
        total += r

    res += total // 10
    print(res - 1)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
mat = [[(0, 0)]*11 for _ in range(10)]
def dsr(i):
    x, cnt = 0, 0
    for j in range(1, 11):
        w = x+ i
        if w > 9:
            x = w - 9
            cnt += 2
        else:
            x = w
            cnt += 1
        mat[i][j] = (x, cnt-1)
for i in range(10):
    dsr(i)
#print2(mat)

m = int(input())
cnt = 0; x0 = 0   
for _ in range(m):
    d, c = map(int, input().split())
    q, r = divmod(c, 10)
    cnt += mat[d][10][1]*q + mat[d][r][1]
    x = mat[d][r][0]
    #print(x, cnt)
    w = x0 + x
    if w > 9:
        x0 = w - 9
        cnt += 2
    else:
        x0 = w
        cnt += 1
print(cnt-1)

Submission status: Wrong Answer

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:
    return f(l)

  
for i in range(M):
  d,c=map(int,input().split())
  ans+=(c-1)+(d*c-1)//9
  A.append(f(d*c))
  
ans+=len(A)-1
ans+=(sum(A)-1)//9
print(ans)

Submission status: Wrong Answer

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:
    return f(l)

print(f(222222))
  
for i in range(M):
  d,c=map(int,input().split())
  ans+=(c-1)+(d*c-1)//9
  A.append(f(d*c))
  
ans+=len(A)-1
ans+=(sum(A)-1)//9
print(ans)

Submission status: Wrong Answer

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:
    return f(l)
  
for i in range(M):
  d,c=map(int,input().split())
  ans+=(c-1)+d*c//9
  A.append(f(d*c))
  
ans+=len(A)-1
ans+=(sum(A)-1)//9
print(ans)

Submission status: Wrong Answer

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:
    return f(l)

print(f(222222))
  
for i in range(M):
  d,c=map(int,input().split())
  ans+=(c-1)+d*c//9
  A.append(f(d*c))
  
ans+=len(A)-1
ans+=(sum(A)-1)//9
print(ans)

Submission status: Wrong Answer

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:
    return 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: Wrong Answer

Solution code:
m = int(input())
s = ""
x = 0
cnt = 0

"""
各桁をa,bとすると
(1)a+b < 10 
(2)a+b >= 10
で場合分け
1234567890 -> 桁がn, 総和がs
(1)の操作 : n-1, s
(2)の操作 : n, s-9
POINT (1),(2)両方の操作でも、9n+sの値が9ずつ減っていく
"""

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    m=I()
    ans=-1
    sm=0
    for i in range(m):
        d,c=MI()
        ans+=c
        sm+=d*c
    while sm>=10:
        ans+=sm//10
        u=str(sm)
        sm=0
        for i in range(len(u)):
            sm+=int(u[i])
    print(ans)
    
        
                
                
    
        
        
        
        




if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import Counter
    M = int(readline())
    C = Counter()

    for _ in range(M):
        d, c = map(int, readline().split())
        C[d] += c
    ans = 0
    ans += C[0]
    s = ""
    for i in range(1, 10):
        while C[i] >= 10:
            k = C[i] // 10
            C[i] = C[i] % 10 + k
            ans += k * 10
        s += str(i) * C[i]

    s += "*"
    while len(s) > 2:
        s = str(int(s[0]) + int(s[1])) + s[2:]
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
m = int(input())
cycle = []
cycle.append([0])  # 1-indexd
cycle.append([10])
cycle.append([5])
cycle.append([4])
cycle.append([3, 2, 2, 2])
cycle.append([2])
cycle.append([2])
cycle.append([2, 1, 1, 2, 1, 1, 2])
cycle.append([2, 1, 1, 1, 1, 1, 2])
cycle.append([2])
ans = 0
query_counter = []
for i in range(m):
    d, c = map(int, input().split())
    if d == 0:
        ans += c
        continue
    tmp_count = c-1
    div = sum(cycle[d])
    tmp_count += c//div
    tmp_c = c
    tmp_c %= div
    if tmp_c > 0:
        t_sum = 0
        for cy in cycle[d]:
            t_sum += cy
            if tmp_c-t_sum >= 0:
                tmp_count += 1
    s = 0
    for j in range(tmp_c):
        s += d
        if s >= 10:
            t = str(s)
            s = 0
            for tt in t:
                s += int(tt)     
    query_counter.append(s)
    ans += tmp_count

s = 0
for i,qc in enumerate(query_counter):
    if i == 0:
        s += qc
        continue
    s += qc
    ans += 1
    if s >= 10:
        t = str(s)
        s = 0
        for tt in t:
            s += int(tt)
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
m = int(input())
DC = [tuple(int(x) for x in input().split()) for _ in range(m)]

def f(a, b):
    p = (a + b) // 10
    r = (a + b) % 10
    return p + r, p + 1

ans = 0
D = []
for d, c in DC:
    if c == 1:
        D.append(d)
        continue
    if c % 2 == 1:
        d0 = d
        c -= 1
    else:
        d0 = -1
    while c > 1:
        d, count = f(d, d)
        ans += count * (c // 2)
        c -= c // 2
    if d0 != -1:
        d, count = f(d, d0)
        ans += count * (c // 2)
    D.append(d)

if len(D) <= 1:
    print(ans)
    exit()

D.reverse()
d = D.pop()
while D:
    e = D.pop()
    d, count = f(d, e)
    ans += count

print(ans)

Submission status: Wrong Answer

Solution code:
M=int(input())

n_digit=0
n_sum=0
for _ in range(M):
  d,c=map(int,input().split())
  n_digit+=c
  n_sum+=d*c
#print(n_digit,n_sum)

print(n_digit-1+n_sum//9)

Submission status: Wrong Answer

Solution code:
M=int(input())

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

def res_sum(x):
  while x>=10:
    num=0
    while x>0:
      num+=x%10
      x//=10
    x=num
  return x

answer=0
dclist2=[]
for d,c in dclist:
  answer+=c-1
  answer+=(d*c)//10
  answer+=max(0,len(str(d*c))-2)
  dclist2.append(res_sum(d*c))
#print(answer,dclist2)
  
m=max(0,len(str(sum(dclist2)))-2)
print(answer+M-1+sum(dclist2)//10+m)

Submission status: Wrong Answer

Solution code:
M=int(input())

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

def res_sum(x):
  while x>=10:
    num=0
    while x>0:
      num+=x%10
      x//=10
    x=num
  return x

answer=0
dclist2=[]
for d,c in dclist:
  answer+=c-1
  answer+=(d*c)//10
  dclist2.append(res_sum(d*c))
#print(answer,dclist2)
  
print(answer+M-1+sum(dclist2)//10)

Submission status: Wrong Answer

Solution code:
M = int(input())
L = [0] * 10

for _ in range(M):
    d, c = map(int,input().split())
    L[d] += c

def dfs(cnt, L):
    if L.count(0) == 9:
        return cnt
    cnt += sum(L) - 1
    S = 0
    for i in range(10):
        S += i * L[i]
    S = str(S)
    for i in range(10):
        L[i] = S.count(str(i))
    return dfs(cnt, L)

ans = dfs(0, L)

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    m = int(input())
    arr = [list(map(int, input().split())) for _ in range(m)]
    ans = 0
    sm = 0
    tmp = 0
    for i in range(m):
        sm += arr[i][0] * arr[i][1]
        tmp += arr[i][1]
    ans += tmp-1
    while sm > 9:
        tmp = sm
        nxt = 0
        cnt = 0
        while tmp > 0:
            cnt += 1
            nxt += tmp % 10
            tmp //= 10
        ans += cnt - 1
        sm = nxt
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
M = int(input())
D = [];C = []
S = 0
ans = -1
for i in range(M):
  d,c = map(int,input().split())
  D.append(d);C.append(c)
  S += d*c
  ans += c
kaisu = S//9
#print(ans,kaisu)
ans += kaisu
print(ans)

Submission status: Wrong Answer

Solution code:
M = int(input())
D = [];C = []
S = 0
ans = -1
for i in range(M):
  d,c = map(int,input().split())
  D.append(d);C.append(c)
  S += d*c
  ans += c
kaisu = S//10
#print(ans,kaisu)
ans += kaisu
print(ans)

Submission status: Wrong Answer

Solution code:
M = int(input())

ans = 0
A = []
for i in range(M):
    d, c = map(int, input().split())
    ans += c - 1 + (d * c // 10)

    if d == 0:
        ans += 1
        continue

    if ((d * c) % 9) != 0:
        A.append((d * c) % 9)
    else:
        A.append(9)

while len(A) > 1:
    ans += 1
    A.extend(list(str(int(A.pop()) + int(A.pop()))))
print(ans)

Submission status: Wrong Answer

Solution code:
M = int(input())

ans = 0
A = []
for i in range(M):
    d, c = map(int, input().split())
    ans += c - 1 + (d * c // 10)

    if d != 9:
        A.append((d * c) % 9)
    else:
        A.append(9)

while len(A) > 1:
    ans += 1
    A.extend(list(str(int(A.pop()) + int(A.pop()))))
print(ans)

Submission status: Wrong Answer

Solution code:
M = int(input())

ans = -1
A = []
for i in range(M):
    d, c = map(int, input().split())
    ans += c + (d * c // 10)
    if c == 1:
        ans -= 1

    if d != 9:
        A.append((d * c) % 9)
    else:
        A.append(9)

while len(A) > 1:
    ans += 1
    A.extend(list(str(int(A.pop()) + int(A.pop()))))
print(ans)

Submission status: Wrong Answer

Solution code:
M = int(input())

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

ans += X // 10
ans -= 1
print(ans)

Submission status: Wrong Answer

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


def main():
    m = int(input())
    sum = 0
    digits = 0
    for _ in range(m):
        d, c = map(int, input().split())
        sum += d * c
        digits += c

    ans = digits - 1
    while sum >= 10:
        sum //= 10
        ans += sum

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


def main():
    m = int(input())
    sum = 0
    digits = 0
    for _ in range(m):
        d, c = map(int, input().split())
        sum += d * c
        digits += c

    ans = digits + sum // 10 - 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())

Sum=0
Len=0

for i in range(N):
    n,c=map(int,input().split())
    Sum+=n*c
    Len+=c

ans=Len-1

while Sum>=10:
    ans+=Sum//10
    Sum//=10
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

Sum=0
Len=0

for i in range(N):
    n,c=map(int,input().split())
    Sum+=n*c
    Len+=c
print(Len+Sum//10-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
m=int(input())
n=0
ans=0
for i in range(m):
  x,y=map(int,input().split())
  n+=y
  ans+=x*y
n-=1
n+=ans//9
print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
m = int(readline())
ans = 0
chk = 0
for i in range(m):
  d,c = map(int,readline().split())
  ans += c
  chk += d*c
  if chk > 9:
    ans += chk//10
    chk %= 10
print(ans-1)

Submission status: Wrong Answer

Solution code:
M = int(input())

cur = 0

keta = 0
csum = 0
for _ in range(M):
  d,c = map(int,input().split())
  s = 0
  for i in str(d):
    s += int(i)
  csum += s * c
  keta += c

print(keta-1 + csum//9)

Submission status: Wrong Answer

Solution code:
m=int(input())
ans,sm=0,0
for i in range(m):
  b,c=map(int,input().split())
  ans+=c
  sm+=b*c
ans+=sm//10
ans-=1
print(ans)

Submission status: Wrong Answer

Solution code:
M = int(input())
Keta=0
Sum=0

for _ in range(M):
    d,c = map(int,input().split())
    Keta+=c
    Sum=d*c
print(Keta-1 + (Sum-1)//9)

Submission status: Wrong Answer

Solution code:
n = int(input())
d, d_sum = 0, 0
for _ in range(n):
    a, b = map(int, input().split())
    d += b
    d_sum += a * b

print(d - 1 + d_sum // 9)

Submission status: Wrong Answer

Solution code:
def digit_sum(n):
    if(n<10): return (n, 0)
    if(n==10): return (1, 1)

    ret = 0
    di = 0
    while(n != 0):
        di += n%10
        n //= 10
        ret += 1
    
    ret -= 1

    if(di < 10): return (di, ret)

    fi, sec = digit_sum(di)

    return fi, sec+ret


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

mul = 0
res = m-1
for d, c in dc:
    mul += d*c
    res += c-1 

fi, se = digit_sum(mul)

print(res+se)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_d

import sys
input=sys.stdin.readline

def main():
    M=int(input())
    dc=[tuple(map(int,input().split())) for i in range(M)]
    ans=0
    n=0
    for i in range(M):
        n+=dc[i][0]*dc[i][1]
        ans+=dc[i][1]
    ans-=1
    def aint(x):
        ret=0
        cnt=0
        while(x>0):
            cnt+=1
            ret+=x//10
            x//=10
        cnt-=1
        return int(ret)-cnt
            
    if n>=10:
        ans+=aint(n)
        
    while(n>=10):
        ns=str(n)
        n=0
        for i in range(10):
            c=ns.count(chr(i+ord("0")))
            n+=i*c
        ans+=len(ns)-1
        if n>=10:
            ans+=aint(n)-1
    print(ans)
        
    
    
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_d

import sys
input=sys.stdin.readline

def main():
    M=int(input())
    dc=[tuple(map(int,input().split())) for i in range(M)]
    ans=0
    n=0
    for i in range(M):
        n+=dc[i][0]*dc[i][1]
        ans+=dc[i][1]
    ans-=1
    def aint(x):
        ret=0
        cnt=0
        while(x>0):
            cnt+=1
            ret+=x//10
            x//=10
        cnt-=1
        return int(ret)-cnt
            
    if n>=10:
        ans+=aint(n)
        
    print(ans,n)
    while(n>=10):
        ns=str(n)
        n=0
        for i in range(10):
            c=ns.count(chr(i+ord("0")))
            n+=i*c
        ans+=len(ns)-1
        if n>=10:
            ans+=aint(n)-1
        print(ans,n)
    print(ans)
        
    
    
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_d

import sys
input=sys.stdin.readline

def main():
    M=int(input())
    dc=[tuple(map(int,input().split())) for i in range(M)]
    ans=0
    n=0
    for i in range(M):
        n+=dc[i][0]*dc[i][1]
        ans+=dc[i][1]
    ans-=1
    if n>=10:
        ans+=int(n//10)-1
    while(n>=10):
        ns=str(n)
        n=0
        for i in range(10):
            c=ns.count(chr(i+ord("0")))
            n+=i*c
        ans+=len(ns)-1
        if n>=10:
            ans+=int(n//10)-1
    print(ans)
        
    
    
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
M = int(input())

digit = 0
sum = 0

for _ in range(M):
    d, c = map(int, input().split())
    digit += c
    sum += d * c

print(digit + sum // 9 - 1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    M = int(input())
    d = [None]*M
    c = [None]*M
    sumd = 0
    for i in range(M):
        td, tc = map(int, input().split())
        d[i] = td
        c[i] = tc
        sumd += td*tc
    # result = sumd%10+sumd//10
    # # print(sumd,c,d,result)
    # if result > 9:
    #     print(sum(c)+sumd//10)
    # else:
    print(sum(c)-1+sumd//10)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    M = int(input())
    d = [None]*M
    c = [None]*M
    sumd = 0
    for i in range(M):
        td, tc = map(int, input().split())
        d[i] = td
        c[i] = tc
        sumd += td*tc
    result = sumd%10+sumd//10
    # print(sumd,c,d,result)
    if result > 9:
        print(sum(c)+sumd//10)
    else:
        print(sum(c)-1+sumd//10)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
M = int(input())

num = ""

ans = 0
for i in range(M):
    d,c = map(int,input().split())
    num += str(d*c)
    ans += c-1
#print("num1",num)
#print("ans1",ans)

while int(num) >= 10:
    tmp = 0
    for i in str(num):
        tmp += int(i)
        ans += 1
        #print("ans",ans)
    ans -= 1
    num = tmp
    #print("num",num)
print(ans)

Submission status: Wrong Answer

Solution code:
M = int(input())

num = ""

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


while int(num) >= 10:
    tmp = 0
    for i in str(ans):
        tmp += int(i)
    num = tmp
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

M = int(input())
dc = [list(mapint()) for _ in range(M)]
ans = 0
nowd = 0
for m in range(M):
    d, c = dc[m]
    s = nowd + d*c
    ans += c+s//10
    nowd = s%10+s//10
    ans += nowd//10
    nowd = nowd%10+nowd//10
print(ans-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
import sys
d=0
now=0
input=sys.stdin.readline
for i in range(n):
  a,b=map(int,input().split())
  now+=a*b
  d+=b
print(now//9+d-1)

Submission status: Wrong Answer

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

m = int(input())
keta = 0
curr_sum = 0
ten_up_cnt = 0
for _ in range(m):
    d,c = map(int, input().split())
    keta += c
    curr_sum += d*c
    ten_up_cnt += curr_sum//10
    # curr_sum%=10

# ans = keta + (curr_sum+curr_sum//10)//10 - 1
cnt = 0
for i in range(1,16):
    cnt += curr_sum//(10**i)
ans = keta + (curr_sum + cnt)//10 -1
print(ans)

Submission status: Wrong Answer

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

m = int(input())
keta = 0
curr_sum = 0
ten_up_cnt = 0
for _ in range(m):
    d,c = map(int, input().split())
    keta += c
    curr_sum += d*c
    ten_up_cnt += curr_sum//10
    # curr_sum%=10

# ans = keta + (curr_sum+curr_sum//10)//10 - 1
cnt = 0
for i in range(1,15):
    cnt += curr_sum//(10**i)
ans = keta + (curr_sum + cnt)//10 -1
print(ans)

Submission status: Wrong Answer

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

m = int(input())
keta = 0
curr_sum = 0
ten_up_cnt = 0
for _ in range(m):
    d,c = map(int, input().split())
    keta += c
    curr_sum += d*c
    ten_up_cnt += curr_sum//10
    # curr_sum%=10

# ans = keta + (curr_sum+curr_sum//10)//10 - 1
cnt = 0
for i in range(0,15):
    cnt += curr_sum//(10**i)
ans = keta + cnt//10 -1
print(ans)

Submission status: Wrong Answer

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

m = int(input())
keta = 0
curr_sum = 0
ten_up_cnt = 0
for _ in range(m):
    d,c = map(int, input().split())
    keta += c
    curr_sum += d*c
    ten_up_cnt += curr_sum//10
    # curr_sum%=10

ans = keta + (curr_sum+curr_sum//10)//10 - 1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

M = ii()
dc = li2(M)

i = M-1
cnt = sum([dc[i][1] for i in range(M)]) - 1
while i >= 0:

    if dc[i][1] == 0:
        continue

    elif dc[i][0] == 9:
        if dc[i][1] > 1:
            cnt += dc[i][1] - 1
        else:
            cnt += 1
            dc[i-1][1] -= 1
    
    elif dc[i][0] >= 5:
        if not dc[i][1] % 2:
            cnt += dc[i][1] // 2
            if i > 0 and dc[i-1][0] == 9:
                cnt += 1
        else:
            cnt += dc[i][1] // 2
            if i > 0 and dc[i-1][0] + dc[i][1] > 9:
                cnt += 1

    else:
        if i > 0 and dc[i-1][0] + dc[i][1] > 9:
            cnt += 1

    i -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

M = ii()
dc = li2(M)

i = M-1
cnt = 0
while i >= 0:
    #print(cnt)
    if dc[i][1] == 0:
        continue

    elif dc[i][0] == 9:
        if dc[i][1] > 1:
            cnt += dc[i][1] - 1
        else:
            cnt += 2
            dc[i-1][1] -= 1
    
    elif dc[i][0] >= 5:
        if not dc[i][1] % 2:
            cnt += dc[i][1] // 2
            if i > 0 and dc[i-1][0] == 9:
                cnt += 1
        else:
            cnt += dc[i][1] // 2
            if i > 0 and dc[i-1][0] + dc[i][1] > 9:
                cnt += 1

    else:
        if dc[i-1][0] + dc[i][1] > 9:
            cnt += 1

    i -= 1

print(cnt + sum([dc[i][1] for i in range(M)])-1)

Submission status: Wrong Answer

Solution code:
import sys
sys.stdin.readline

def main():
    m = int(input())
    a = [list(map(int, input().split())) for _ in range(m)]
    wa = 0
    length = 0
    for i,j in a:
        wa += i*j
        length += j
    print(wa,length)
    print(length-1+(wa-1)//9)
    
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.stdin.readline

def main():
    m = int(input())
    a = [list(map(int, input().split())) for _ in range(m)]
    loop = [0]*10
    rond = [0]*10
    loop[0] = 1
    for i in range(1,10):
        c = 1 #一塊
        r = 0
        now = 0
        if (2*i >= 10):
            now = 2*i
            r += 1
        else:
            now = 2*i
            c = 2
            r += 1
        while True:
            if (now==i):
                break
            r += 1
            if (len(str(now))==1):
                if (now*2 < 10):
                    now = now*2
                    c *= 2
                else:
                    now = now*2
            else:
                now = (now//10 + now%10)
                c *= 2
        loop[i] = c
        rond[i] = r
    print(loop,rond)

    ans = 0
    main = []
    for i,j in a:
        x = (j//loop[i]) + (j%loop[i])
        for k in range(x):
            main.append(i)
    
        ans += rond[i]*(j//loop[i])
    #print(main,ans)

    if (len(main)==1):
        print(ans)
        exit()
    now = [0,0]
    now[1] = main.pop()
    now[0] = main.pop()
    while len(main)>0:
        ans += 1
        x = now[0]+now[1]
        y = str(x)
        if (x>=10):
            now = [int(y[0]),int(y[1])]
        else:
            now[1] = x
            now[0] = main.pop()
        #print(now,ans)
    if (now[0]+now[1]>=10):
        ans += 2
    else:
        ans += 1
    print(ans)
    
    
if __name__=="__main__":
    main()