Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

def q(d, c, dq):
    if c == 1: 
        if d < 10: 
            dq.append(d)
            return 0
        else:
            a = d //10 + d % 10
            if a < 10: 
                dq.append(a)
                return 1
            else: 
                dq.append(a-9)
                return 2
    a = d * 2
    if a < 10: count = q(a, c//2, dq)
    else:
        count = q(a - 9, c//2, dq)
        count += c//2
    count += c//2
    if c % 2 == 1: dq.append(d)
    return count

def solve():
    input = sys.stdin.readline
    M = int(input())
    count = 0
    dq = deque()
    digit = 0
    for _ in range(M):
        d, c = map(int, input().split())
        add = q(d, c, dq)
        count += add
    
    digit = len(dq)
    for _ in range(digit - 1):
        #print(dq)
        a = int(dq.pop())
        a += int(dq.pop())
        if a >= 10:
            dq.append(str(a % 10 + a // 10))
            count += 2
        else: 
            dq.append(str(a))
            count += 1

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

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 python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

def q(d, c, dq):
    if c == 1: 
        if d < 10: 
            dq.append(d)
            return 0
        else:
            a = d //10 + d % 10
            if a < 10: 
                dq.append(a)
                return 1
            else: 
                dq.append(a-9)
                return 2
    a = d * 2
    if a < 10: count = q(a, c//2, dq)
    else:
        count = q(a - 9, c//2, dq)
        count += c//2
    count += c//2
    if c % 2 == 1: dq.append(d)
    return count

def solve():
    input = sys.stdin.readline
    M = int(input())
    count = 0
    dq = deque()
    digit = 0
    for _ in range(M):
        d, c = map(int, input().split())
        add = q(d, c, dq)
        count += add
    
    digit = len(dq)
    for _ in range(digit - 1):
        #print(dq)
        a = int(dq.pop())
        a += int(dq.pop())
        if a >= 10:
            dq.append(str(a % 10 + a // 10))
            count += 2
        else: 
            dq.append(str(a))
            count += 1

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

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 python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

def q(d, c):
    if c == 1: 
        if d < 10: return str(d), 0
        else:
            a = d //10 + d % 10
            if a < 10: return str(a), 1
            else: return str(a - 9), 2
    a = d * 2
    if a < 10:
        lem, count = q(a, c//2)
    else:
        lem, count = q(a - 9, c//2)
        count += c // 2
    count += c//2
    if c % 2 == 1: lem += str(d)
    return lem, count

def solve():
    input = sys.stdin.readline
    M = int(input())
    N = ""
    count = 0
    dq = deque()

    for _ in range(M):
        d, c = map(int, input().split())
        lem, add = q(d, c)
        for i in range(len(lem)): 
            dq.append(lem[i])
        count += add
    
    digit = len(dq)
    for _ in range(digit - 1):
        #print(dq)
        a = int(dq.pop())
        a += int(dq.pop())
        if a >= 10:
            dq.append(str(a % 10 + a // 10))
            count += 2
        else: 
            dq.append(str(a))
            count += 1

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

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 python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

def q(d, c):
    if c == 1: 
        if d < 10: return str(d), 0
    if d >= 10: 
        lem, count = q(d // 10 + d % 10, c)
        return lem, count + c
    elif c % 2 == 0:
        lem, count = q(d * 2, c // 2)
        return lem, count + c // 2
    elif c % 2 == 1:
        lem, count = q(d * 2, c //2)
        return lem + str(d), count + c // 2

def solve():
    input = sys.stdin.readline
    M = int(input())
    N = ""
    count = 0
    dq = deque()

    for _ in range(M):
        d, c = map(int, input().split())
        lem, add = q(d, c)
        for i in range(len(lem)): 
            dq.append(lem[i])
        count += add
    
    digit = len(dq)
    for _ in range(digit - 1):
        #print(dq)
        a = int(dq.pop())
        a += int(dq.pop())
        if a >= 10:
            dq.append(str(a % 10 + a // 10))
            count += 2
        else: 
            dq.append(str(a))
            count += 1

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

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 python submission (verdict: Time Limit Exceeded):
import sys

def q(d, c):
    if c == 1: return str(d), 0
    if d >= 10: 
        lem, count = q(d // 10 + d % 10, c)
        return lem, count + c
    elif c % 2 == 0:
        lem, count = q(d * 2, c // 2)
        return lem, count + c // 2
    elif c % 2 == 1:
        lem, count = q(d * 2, c //2)
        return lem + str(d), count + c // 2

def solve():
    input = sys.stdin.readline
    M = int(input())
    N = ""
    count = 0
    for _ in range(M):
        d, c = map(int, input().split())
        lem, add = q(d, c)
        N += lem
        count += add

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

    print(count)
    
    return 0

if __name__ == "__main__":
    solve()

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

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