Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03694 (python)

Fixed submission:
# B - Traveling AtCoDeer Problem
N = int(input())
a = list(map(int, input().split()))
A = set(a)
A1 = sorted(A)
count = 0
for i in range(len(A)-1) :
    count += A1[i+1]-A1[i]

print(count)

Buggy submission (verdict: Runtime Error):
# B - Traveling AtCoDeer Problem
N = int(input())
a = list(map(int, input().split()))
A = set(a)
A1 = sorted(A)
count = 0
for i in range(N-1) :
    count += A1[i+1]-A1[i]

print(count)
Problem p03729 (python)

Fixed submission:
A, B, C = map(str, input().split())

if A[-1] == B[0] and B[-1] == C[0]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
A, B, C = map(str, input().split())

if A[-1] == B[0] and B[-1] == c[0]:
    print("YES")
else:
    print("NO")
Problem p02554 (python)

Fixed submission:
import sys
import math
input = sys.stdin.readline
mod = int(1e9)+7

def solve():
    n=int(input())
    ans = pow(10,n,mod)-(2*pow(9,n,mod)-pow(8,n,mod))
    print(ans%mod)

    
if __name__=="__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
mod = int(1e9)+7

def solve():
    n=int(input())
    if n<3:
        print(0)
        return
    dp=[0]*2001
    dp[3]=dp[4]=dp[5]=1
    for i in range(6,n+1):
        dp[i]=(dp[i-1]+dp[i-3])%mod
    print(dp[n])

if __name__=="__main__":
    solve()
Problem p02573 (python)

Fixed submission:
n,m=map(int,input().split())
d={i:set() for i in range(1,n+1)}
for i in range(m):
    a,b=map(int,input().split())
    d[a].add(b)
    d[b].add(a)

vis = set()
res = 0
for i in range(1,n+1):
    if i not in vis:
        stack=[i]
        ans=1
        vis.add(i)
        while stack:
            cur=stack.pop()
            for j in d[cur]:
                if j not in vis:
                    vis.add(j)
                    ans+=1
                    stack.append(j)
        res=max(res,ans)
print(res)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
M=set(tuple(map(int,input().split())) for _ in range(m))
d={i:set() for i in range(1,n+1)}

for a,b in M:
    if a>b:
        a,b=b,a
    d[a].add(b)

val = max(d,key=d.get)
for i in d[val]:
    if d[i]!=set():
        d[val]|=d[i]
print(len(d[val])+1)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
M=set(tuple(map(int,input().split())) for _ in range(m))
d={i:set() for i in range(1,n+1)}

for a,b in M:
    if a>b:
        a,b=b,a
    d[a].add(b)

val = max(d,key=d.get)
for i in d[val]:
    d[val]|=d[i]
print(len(d[val])+1)
Problem p02574 (python)

Fixed submission:
import sys
import math
input = sys.stdin.readline
def prime_factor(n):
    factors = []
    while n%2==0:
        factors.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            factors.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        factors.append(n)
    return set(factors)


n=int(input())
L=list(map(int,input().split()))
val = L[0]
for i in range(1,n):
    val=math.gcd(val,L[i])
if val!=1:
    print('not coprime')
    sys.exit()
d={}
for i in range(n):
    factors = prime_factor(L[i])
    for j in factors:
        if j not in d.keys():
            d[j]=1
        else:
            print('setwise coprime')
            sys.exit()
print('pairwise coprime')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def prime_factor(n):
    factors = []
    while n%2==0:
        factors.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            factors.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        factors.append(n)
    return set(factors)

def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

n=int(input())
L=list(map(int,input().split()))
val = L[0]
for i in range(1,n):
    val=math.gcd(L[i],val)
if val!=1:
    print('not coprime')
    sys.exit()

d={}
for i in range(n):
    factors = prime_factor(L[i])
    for j in factors:
        if j not in d.keys():
            d[j]=1
        else:
            print('setwise coprime')
            sys.exit()
print('pairwise coprime')
Problem p02600 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n=int(input())
count = 0

L=list(range(400,2001,200))
val=len(L)
ans = 0
for i in range(val-1):
    if L[i]<=n<L[i+1]:
        ans=8-count
        break
    else:
        count+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n=int(input())
count = 0

L=list(range(400,2000,200))
val=len(L)
count=0
for i in range(val-1):
    if L[i]<=n<L[i+1]:
        ans=8-count
        break
    else:
        count+=1
print(ans)
Problem p02614 (python)

Fixed submission:
import sys
input = sys.stdin.readline

h,w,k = map(int,input().split())
M=[input().rstrip() for _ in range(h)]
ans = 0
for ib in range(1<<h):
    for jb in range(1<<w):
        cc = 0 
        for i in range(h):
            if ib&(1<<i):continue
            for j in range(w):
                if jb&(1<<j):continue
                cc+=M[i][j]=='#'
        if cc==k:
            ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
mod = int(1e9+7)
n,k = map(int,input().split())
L=list(map(int,input().split()))

ans = 1

pos = []
neg = []
for i in L:
    if i>=0:
        pos.append(i)
    else:
        neg.append(i)
pos.sort(reverse=True)
neg.sort()
if len(pos) == 0 and k%2!=0:
    for i in range(1,k+1):
        ans*=neg[-i]
        ans%=mod
    print(ans%mod)
    sys.exit()
if k%2!=0:
    ans*=pos.pop(0)
    k-=1
l=[]
for i in range(1,len(pos),2):
    l.append(pos[i]*pos[i-1])

for i in range(1,len(neg),2):
    l.append(neg[i]*neg[i-1])

l.sort(reverse = True)
for i in range(k//2):
    ans*=l[i]
    ans%=mod

print(ans%mod)
Problem p02720 (python)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

n=int(input())
L=deque(list(range(1,10)))
if n<=9:
    ans = L[n-1]
else:
    cnt = 9
    for i in range(1,n):
        c=L.popleft()
        
        if c%10!=0:
            L.append(c*10+(c%10)-1)
            cnt+=1
            if cnt>=n:
                break
        L.append(c*10+(c%10))
        cnt+=1
        if cnt>=n:
            break
        
        if c%10!=9:
            L.append(c*10+(c%10)+1)
            cnt+=1
            if cnt>=n:
                break
    ans = L[-1]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
input = sys.stdin.readline

n=int(input())
L=deque(list(range(1,10)))
if n<=9:
    ans = L[n-1]
else:
    cnt = 9
    for i in range(1,n):
        c=L.popleft()
        
        if c%10!=0:
            L.append(c*10+(c%10)-1)
            cnt+=1
            if cnt>=n:
                break
        L.append(c*10+(c%10))
        cnt+=1
        if cnt>=n:
            break
        
        if c%10!=9:
            L.append(c*10+(c%10)+1)
            cnt+=1
            if cnt>=n:
                break
        print(L)
    ans = L[-1]
print(ans)
Problem p02756 (python)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

s = deque(input().strip())
q=int(input())
count = 0
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        count += 1
    else:
        a,b,c = L
        b = int(b)
        if count&1==1:
            b=3-b
        if b==2:
            s.append(c)
        else:
            s.appendleft(c)
if count&1==1:
    print("".join(list(s)[::-1])) 
else:
    print("".join(s))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

s = list(input().strip())
q=int(input())
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        s.reverse()
    else:
        a,b,c = L
        if int(b)==2:
            s.append(c)
        else:
            s.insert(0,c)
            s = "".join(s)
print(s)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

s = list(input().strip())
q=int(input())
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        s.reverse
    else:
        a,b,c = L
        if int(b)==2:
            s.append(c)
        else:
            s.insert(0,c)
            s = "".join(s)
print(s)
Problem p02586 (python)

Fixed submission:
import sys

def solve():
    input = sys.stdin.readline
    R, C, K = map(int, input().split())
    item = [[0 for _ in range(C)] for r in range(R)]
    for _ in range(K):
        r, c, k = map(int, input().split())
        item[r-1][c-1] = k
    
    DP = [[[-1 for _ in range(C)] for r in range(R)] for i in range(4)]
    DP[0][0][0] = 0
    for r in range(R):
        for c in range(C):
            for i in range(4):
                if DP[i][r][c] > -1:
                    if r + 1 < R: 
                        DP[0][r+1][c] = max(DP[0][r+1][c], DP[i][r][c])
                    if c + 1 < C: 
                        DP[i][r][c+1] = max(DP[i][r][c+1], DP[i][r][c])
                    if i < 3 and item[r][c] > 0:
                        if r + 1 < R: DP[0][r+1][c] = max(DP[0][r+1][c], DP[i][r][c] + item[r][c])
                        if c + 1 < C: DP[i+1][r][c+1] = max(DP[i+1][r][c+1], DP[i][r][c] + item[r][c])

    ans = DP[3][R-1][C-1]
    for i in range(3): ans = max(ans, DP[i][R-1][C-1] + item[R-1][C-1])
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    R, C, K = map(int, input().split())
    item = [[0 for _ in range(C)] for r in range(R)]
    for _ in range(K):
        r, c, k = map(int, input().split())
        item[r-1][c-1] = k
    
    DP = [[[-1 for _ in range(C)] for r in range(R)] for i in range(4)]
    visited = [[False for c in range(C)] for r in range(R)]
    q = deque()
    DP[0][0][1] = 0
    visited[0][0] = True
    if item[0][0] > 0:
        DP[1][0][1] = item[0][0]
        DP[0][1][0] = item[0][0]
    q.append((0, 1))
    q.append((1, 0))
    while q:
        r, c = q.popleft()
        if not visited[r][c]:
            visited[r][c] = True
            for i in range(4):
                if DP[i][r][c] > -1:
                    if r + 1 < R: 
                        DP[0][r+1][c] = max(DP[0][r+1][c], DP[i][r][c])
                        q.append((r+1, c))
                    if c + 1 < C: 
                        DP[i][r][c+1] = max(DP[i][r][c+1], DP[i][r][c])
                        q.append((r, c+1))
                    if i < 3 and item[r][c] > 0:
                        if r + 1 < R: DP[0][r+1][c] = max(DP[0][r+1][c], DP[i][r][c] + item[r][c])
                        if c + 1 < C: DP[i+1][r][c+1] = max(DP[i+1][r][c+1], DP[i][r][c] + item[r][c])

    ans = DP[3][R-1][C-1]
    for i in range(3): ans = max(ans, DP[i][R-1][C-1] + item[R-1][C-1])
    print(ans)
    return 0

if __name__ == "__main__":
    solve()
Problem p02698 (python)

Fixed submission:
import sys
from bisect import bisect_left
sys.setrecursionlimit(1000000)
INF = pow(10, 10)

changed = []
input = sys.stdin.readline
N = int(input())
A = [int(a) for a in input().split()]
Edge = [[] for _ in range(N)]
for _ in range(N-1):
    u, v = map(int, input().split())
    Edge[u-1].append(v-1)
    Edge[v-1].append(u-1)
LIS = [INF] * N

def dfs(i, pre, Ans):
    changeID = bisect_left(LIS, A[i])
    changed.append((changeID, LIS[changeID]))
    LIS[changeID] = min(A[i], LIS[changeID])
    #print(i, LIS)
    #print(changed)
    Ans[i] = bisect_left(LIS, INF) 
    for nextN in Edge[i]:
        if nextN != pre: dfs(nextN, i, Ans)
    backID, backV = changed.pop()
    LIS[backID] = backV
    return 0

def solve():
    Ans = [1] * N
    dfs(0, 0, Ans)
    print("\n".join(map(str, Ans)))
    
    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys
from bisect import bisect_left
changed = []
input = sys.stdin.readline
N = int(input())
A = [int(a) for a in input().split()]
Edge = [[] for _ in range(N)]
for _ in range(N-1):
    u, v = map(int, input().split())
    Edge[u-1].append(v-1)
    Edge[v-1].append(u-1)
LIS = [10 ** 20] * N

def dfs(i, pre, Ans):
    changeID = bisect_left(LIS, A[i])
    changed.append(LIS[changeID])
    LIS[changeID] = A[i]
    Ans[i] = changeID + 1
    for nextN in Edge[i]:
        if nextN != pre: dfs(nextN, i, Ans)
    backNum = changed.pop()
    LIS[changeID] = backNum
    return 0


def solve():
    Ans = [1] * N
    dfs(0, 0, Ans)
    print("\n".join(map(str, Ans)))
    

    return 0

if __name__ == "__main__":
    solve()
Problem p02742 (python)

Fixed submission:
import sys

def solve():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    if H == 1 or W == 1: print(1)
    else: 
        Ans = (H // 2 + H % 2) * (W // 2 + W % 2) + (H // 2) *  (W // 2)
        print(Ans)

    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys

def solve():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    if H == 1 or W == 1: print(1)
    else: Ans = (H // 2 + H % 2) * (W // 2 + W % 2) + (H // 2) *  (W // 2)
    print(Ans)

    return 0

if __name__ == "__main__":
    solve()
Problem p02782 (python)

Fixed submission:
import sys

def f(r, c, fact, revfact, mod):
    return (fact[r + c] * revfact[r] * revfact[c]) % mod

def g(r, c, fact, revfact, mod):
    if r == c == 0: return 1
    elif r == 0: return c + 1
    elif c == 0: return r + 1
    ans = 0
    for i in range(1, c + 2):
        ans += f(r, i, fact, revfact, mod)
        ans %= mod
    return ans

def solve():
    input = sys.stdin.readline
    r1, c1, r2, c2 = map(int, input().split())
    mod = 7 + 10 ** 9
    fact = [1] * (5 + r2 + c2)
    revfact = [1] * (5 + r2 + c2)
    for i in range(1, 5 + r2 + c2): fact[i] = (i * fact[i-1]) % mod
    revfact[4 + r2 + c2] = pow(fact[4 + r2 + c2], mod - 2, mod)
    for i in reversed(range(1, 4 + r2 + c2)): revfact[i] = ((i + 1) * revfact[i + 1]) % mod

    ans = g(r2, c2, fact, revfact, mod) - g(r2, c1 - 1, fact, revfact, mod) - g(r1 - 1, c2, fact, revfact, mod) + g(r1 - 1, c1 - 1, fact, revfact, mod)
    print((ans + mod) % mod)

    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys

def f(r, c, fact, revfact, mod):
    return (fact[r + c] * revfact[r] * revfact[c]) % mod

def g(r, c, fact, revfact, mod):
    if r == c == 0: return 1
    elif r == 0: return c + 1
    elif c == 0: return r + 1
    ans = 0
    for i in range(1, c + 2):
        ans += f(r, i, fact, revfact, mod)
        ans %= mod
    return ans

def solve():
    input = sys.stdin.readline
    r1, c1, r2, c2 = map(int, input().split())
    mod = 7 + 10 ** 9
    fact = [1] * (5 + 10 ** 6)
    revfact = [1] * (5 + 10 ** 6)
    for i in range(1, 5 + 10 ** 6): fact[i] = (i * fact[i-1]) % mod
    revfact[4 + 10 ** 6] = pow(fact[4 + 10 ** 6], mod - 2, mod)
    for i in reversed(range(1, 4 + 10 ** 6)): revfact[i] = ((i + 1) * revfact[i + 1]) % mod

    ans = g(r2, c2, fact, revfact, mod) - g(r2, c1 - 1, fact, revfact, mod) - g(r1 - 1, c2, fact, revfact, mod) + g(r1 - 1, c1 - 1, fact, revfact, mod)
    print((ans + mod) % mod)

    return 0

if __name__ == "__main__":
    solve()
Problem p02786 (python)

Fixed submission:
import sys
from collections import deque, defaultdict
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(10000000)

def Attack(L):
    if L == 1: return 1
    else:
        return 1 + 2 * Attack(L//2)

def solve():
    H = int(input())
    print(Attack(H))

    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque, defaultdict
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush
from math import pi, inf
sys.setrecursionlimit(10000000)

def Attack(L):
    if L == 1: return 1
    else:
        return 1 + 2 * Attack(L//2)

def solve():
    H = int(input())
    print(Attack(H))

    return 0

if __name__ == "__main__":
    solve()
Problem p02787 (python)

Fixed submission:
import sys
from collections import deque, defaultdict
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush

def solve():
    input = sys.stdin.readline
    H, N = map(int, input().split())
    M = [tuple(int(a) for a in input().split()) for _ in range(N)]
    DP = [1000000000] * (H + 2) #ダメージiを与えるのに必要な最小MP, DP[H+1]はH以上のダメージを与えた場合
    DP[0] = 0
    for i, m in enumerate(M):
        a, b = m
        for j in range(max(H-a+1, 0)): DP[j + a] = min(DP[j + a], DP[j] + b)
        for j in range(max(H-a+1, 0), H): DP[H + 1] = min(DP[H + 1], DP[j] + b)
    print(min(DP[H], DP[H + 1]))

    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque, defaultdict
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush

def solve():
    input = sys.stdin.readline
    H, N = map(int, input().split())
    M = [tuple(int(a) for a in input().split()) for _ in range(N)]
    DP = [1000000000] * (H + 2) #ダメージiを与えるのに必要な最小MP, DP[H+1]はH以上のダメージを与えた場合
    DP[0] = 0
    for i, m in enumerate(M):
        a, b = m
        for j in range(H-a+1): DP[j + a] = min(DP[j + a], DP[j] + b)
        for j in range(H-a+1, H): DP[H + 1] = min(DP[H + 1], DP[j] + b)
    print(min(DP[H], DP[H + 1]))

    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque, defaultdict
from itertools import combinations, permutations
from heapq import heapify, heappop, heappush

def solve():
    input = sys.stdin.readline
    H, N = map(int, input().split())
    M = [tuple(int(a) for a in input().split()) for _ in range(N)]
    DP = [[10000000 for _ in range(H + 2)] for i in range(N)]
    a0, b0 = M[0]
    for d in range(100000):
        if d * a0 >= H + 1:
            DP[0][H + 1] = d * b0
            break
        else: DP[0][d * a0] = d * b0
    for i in range(1, N):
        a, b = M[i]
        for j in range(H + 1):
            if DP[i - 1][j] < 10000000:
                if j < a: DP[i-1][j]
                else: DP[i][j] = min(DP[i-1][j], DP[i][j - a] + b)
        DP[i][H + 1] = min(DP[i][H + 1], DP[i-1][H + 1])
        DP[i][H + 1] = min(DP[i][H + 1], min(DP[i][H-a+1:H]) + b)
    
    print(min(DP[N-1][H], DP[N-1][H+1]))
    #print(DP)
    return 0

if __name__ == "__main__":
    solve()
Problem p02806 (python)

Fixed submission:
import sys

def solve():
    N = int(input())
    playlist = dict()
    time = [0] * (N + 1)
    for i in range(N):
        s, t = map(str, input().split())
        playlist[s] = i
        time[i + 1] = time[i] + int(t)
    w = input()

    print(time[N] - time[playlist[w] + 1])


    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    playlist = dict()
    time = [0] * (N + 1)
    for i in range(N):
        s, t = map(str, input().split())
        playlist[s] = i
        time[i + 1] = time[i] + int(t)
    print(time[N] - time[playlist[input()] + 1])


    return 0

if __name__ == "__main__":
    solve()
Problem p02850 (python)

Fixed submission:
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    edge = [[] for _ in range(N)]
    order = dict()
    for i in range(N-1):
        a, b = map(int, input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
        order[(min(a-1, b-1), max(a-1, b-1))] = i
    K = 0
    for i in range(N): K = max(K, len(edge[i]))
    
    q = deque()
    col = [-1] * N
    col[0] = 0
    colE = [-1] * (N - 1)
    colPointer = 1
    for next in edge[0]: 
        q.append((0, next))
        col[next] = colPointer
        colE[order[(0, next)]] = colPointer
        colPointer += 1
    while q:
        parentNode, nowNode = q.popleft()
        colPointer = 1
        for nextNode in edge[nowNode]:
            if nextNode != parentNode:
                q.append((nowNode, nextNode))
                if colPointer == col[nowNode]: colPointer += 1
                col[nextNode] = colPointer
                colE[order[(min(nowNode, nextNode), max(nowNode, nextNode))]] = colPointer
                colPointer += 1

    print(K)
    for c in colE: print(c)

    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    edge = [[] for _ in range(N)]
    order = dict()
    for i in range(N-1):
        a, b = map(int, input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
        order[(min(a-1, b-1), max(a-1, b-1))] = i
    K = 0
    for i in range(N): K = max(K, len(edge[i]))
    
    q = deque()
    col = [-1] * N
    col[0] = 0
    colE = [-1] * (N - 1)
    colPointer = 1
    for next in edge[0]: 
        q.append((0, next))
        col[next] = colPointer
        colE[order[(0, next)]] = colPointer
        colPointer += 1
    while q:
        parentNode, nowNode = q.popleft()
        par[nowNode] = parentNode
        colPointer = 1
        for nextNode in edge[nowNode]:
            if nextNode != parentNode:
                q.append((nowNode, nextNode))
                if colPointer == col[nowNode]: colPointer += 1
                col[nextNode] = colPointer
                colE[order[(min(nowNode, nextNode), max(nowNode, nextNode))]] = colPointer
                colPointer += 1

    print(K)
    for c in colE: print(c)

    return 0

if __name__ == "__main__":
    solve()
Problem p02856 (python)

Fixed submission:
import sys
from collections import deque

def q(d, c): #dは9以下、cは桁数
    digsum = d * c
    add = c - 1 + (digsum - 1) // 9
    rem = digsum - 9 * ((digsum - 1) // 9)
    return add, rem

def solve():
    input = sys.stdin.readline
    M = int(input())
    count = -1
    ans = 0
    for _ in range(M):
        d, c = map(int, input().split())
        add, rem = q(d, c)
        count += add
        ans += rem
        count += 1
        if ans > 9:
            ans -= 9
            count += 1

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys

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

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

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()