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

Fixed submission:
n = int(input())
if n % 2 == 0:
    print(n)
else:
    print(n * 2)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
sadlist = []
for h in range(n):
    a[h] = a[h] - (h + 1)
for i in a:
    sad = 0
    for j in range(n):
        sad = sad + abs(a[j] - i)
    sadlist.append(sad)
print(min(sadlist))
Problem p03209 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
n, x = map(int, input().split())
layers = [1]
pats = [1]
cnt = 1
p_cnt = 1
for _ in range(n):
  cnt = cnt * 2 + 3
  p_cnt = p_cnt * 2 + 1
  layers.append(cnt)
  pats.append(p_cnt)
def solve(lev, rest):
  if rest == 0:
    return 0
  if lev == 0:
    return 1
  if rest - 1 <= layers[lev - 1]:
    return solve(lev - 1, rest - 1)
  elif rest - 1 == layers[lev - 1]:
    return pats[lev - 1] + 1
  else:
    return pats[lev - 1] + 1 + solve(lev - 1, rest - 1 - layers[lev - 1] - 1)

print(solve(n, x))

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
layers = [1]
pats = [1]
cnt = 1
p_cnt = 1
for _ in range(n):
  cnt = cnt * 2 + 3
  p_cnt = p_cnt * 2 + 1
  layers.append(cnt)
  pats.append(p_cnt)
def solve(lev, rest):
  if rest == 0:
    return 0
  if rest - 1 <= (layers[lev] - 3) // 2:
    return solve(lev - 1, rest - 1)
  elif rest - 1 == (layers[lev] - 3) // 2:
    return pats[lev - 1] + 1
  else:
    return pats[lev - 1] + 1 + solve(lev - 1, rest - 1 - layers[lev - 1] - 1)

print(solve(n, x))
Problem p03077 (python)

Fixed submission:
import math
N = int(input())
s = [input() for i in range(5)]
s = [int(i) for i in s]
s_min = min(s)
time = math.ceil(N/s_min) + 4
print(time)

Buggy submission (verdict: Runtime Error):
N = int(input())
s = [input() for i in range(5)]
s_min = min(s)

print(N//s_min + 5)
Problem p03127 (python)

Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split(" ")))

a_min = min(a)
ans = 1e10
for i in a:
    tmp = fractions.gcd(a_min, i)
    if(tmp < ans): ans = tmp

print(ans)

Buggy submission (verdict: Runtime Error):
import fraction

n = int(input())
a = list(map(int, input().split(" ")))

a_min = min(a)
ans = 1e10
for i in a:
    tmp = fraction.gcd(a_min, i)
    if(tmp < ans): ans = tmp

print(ans)
Problem p03041 (python)

Fixed submission:
n, k = map(int, input().split())
s = list(input())
s[k-1] = s[k-1].lower()
print("".join(s))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
s = list(input())
s[k] = s[k].lower()
print("".join(s))
Problem p03127 (python)

Fixed submission:
from functools import reduce

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

def gcd_list(numbers):
    return reduce(gcd, numbers)


N = input()
A = input().split()
for i in range(len(A)):
    A[i] = int(A[i])
answer = gcd_list(A)
print("{}".format(answer))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce



def gcd_list(numbers):
    return reduce(math.gcd, numbers)


N = input()
A = input().split()
for i in range(len(A)):
    A[i] = int(A[i])
answer = gcd_list(A)
print("{}".format(answer))

Buggy submission (verdict: Runtime Error):
import fraction
from functools import reduce


def gcd_list(numbers):
    return reduce(fraction.gcd, numbers)


N = input()
A = input().split()
for i in range(len(A)):
    A[i] = int(A[i]) 
print("{}".format(gcd_list(A)))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


N = input()
A = input().split()
for i in range(len(A)):
    A[i] = int(A[i]) 
print("{}".format(gcd_list(A)))
Problem p03104 (python)

Fixed submission:
#!/usr/bin/env python3

from math import log2

def func(n):
    # (2x) ^ (2x+1) = 1 の性質を利用
    # n = 2mのとき
    # 0^1^...^2m = (0^1) ^ (2^3) ^ ... ^ (2m-2- ^ 2m-1) ^ 2m
    # = 1^...^1 ^ 2m (1はm個)

    # n = 2m+1 のとき
    # 0^1^...^2m+1 = (0^1)^...(2m ^ 2m+1)
    # = 1^...^1 (1は m+1個)

    if n % 2 == 0:
        m = n // 2
        if m % 2 == 0:
            return n
        else:
            return n ^ 1
    else:
        m = (n-1) // 2
        return 0 if m % 2 == 1 else 1

def main():
    a, b = list(map(int, input().split()))

    #f(a, b) = f(0, a-1) ^ f(0, b)
    # f(0, n)をfunc(n)とする
    print(func(b) ^ func(a-1))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

from functools import reduce


def main():
    a, b = list(map(int, input().split()))
    l = list(range(a, b + 1))
    result = reduce(lambda x, y : x^y, l)
    print(result)


if __name__ == '__main__':
    main()
Problem p03075 (python)

Fixed submission:
a = int(input())
b = input()
c = input()
d = input()
e = int(input())
k = int(input())

if e - a > k:
  print(':(')
else:
  print('Yay!')

Buggy submission (verdict: Runtime Error):
import numpy as np

def prod(p, q, r):
    return A[p] + B[q] + C[r]

x, y, z, k = [int(a) for a in input().split()]
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]
C = [int(a) for a in input().split()]

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

progress = [(0, 0, 0, prod(0,0,0))]


def expand(p, q, r):
    result = []
    if p + 1 < x:
        result.append((p+1, q, r, prod(p+1, q, r)))
    if q + 1 < y:
        result.append((p, q+1, r, prod(p, q+1, r)))
    if r + 1 < z:
        result.append((p, q, r+1, prod(p, q, r+1)))
    return result

for i in range(k):
    prods = [tup[-1] for tup in progress]

    max_val = max(prods)
    max_idx = prods.index(max_val)
    p, q, r, _ = progress[max_idx]

    print(max_val)
    progress.pop(max_idx)
    progress.extend(expand(p, q, r))
    progress = list(set(progress))
Problem p03135 (python)

Fixed submission:
t, x = [ int(s) for s in input().split(' ')]
result = t/x
print(result)

Buggy submission (verdict: Runtime Error):
t, x = [ s for s in int(input())]
result = t/x
print(result)
Problem p03209 (python)

Fixed submission:
N, X = map(int, input().split(' '))
height = [1]

for i in range(N):
	height.append(height[-1]*2 + 3)

def patty(N,X):
	if N==1:
		l = [0,1,2,3,3]
		return l[X-1]
	elif N>=2:
		if X == 1:
			return 0
		elif X <= height[N-1]+1:
			return patty(N-1,X-1)
		elif X == height[N-1]+2:
			return patty(N-1,height[N-1])+1
		elif X == height[N]:
			return patty(N-1,height[N-1])*2+1
		elif X >= height[N-1]+3:
			return patty(N-1,height[N-1])+1+ patty(N-1,X-2-height[N-1])

print(patty(N,X))

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split(' '))
height = [1]

for i in range(N):
	height.append(height[-1]*2 + 3)

def patty(N,X):
	if N==1:
		l = [0,1,2,3,3]
		return l[X-1]
	elif N>=2:
		if X<(height[N]+1)/2:
			return patty(N-1,X-1)
		elif X==(height[N]+1)/2:
			return patty(N-1,height[N-1]) + 1
		elif X>(height[N]+1)/2:
			return patty(N-1,height[N-1]) + 1 + patty(N-1,X-2-height[N-1])

print(patty(N,X))
Problem p03242 (python)

Fixed submission:
n = str(input())
s = ''
for i in range(3):
  if n[i] == '1':
    s += '9'
  elif n[i] == '9':
    s += '1'
  else:
    s += n[i]
print(s)

Buggy submission (verdict: Runtime Error):
n = str(input())
for i in range(2):
  if n[i] == '1':
    n[i] = '9'
  elif n[i] == '9':
    n[i] = '1'
print(n)
Problem p03327 (python)

Fixed submission:
print('ABD') if int(input())>=1000 else print('ABC')

Buggy submission (verdict: Runtime Error):
N = int(input())
print('ABD{%03d}'.format(N-1000)) if N>=1000 else print('ABC{%03d}',format(N))
Problem p03631 (python)

Fixed submission:
s = str(input())
print('Yes') if s==s[::-1] else print('No')

Buggy submission (verdict: Runtime Error):
print('Yes') if str(input())==str(input())[::-1] else print('No')
Problem p03774 (python)

Fixed submission:
N,M=map(int,input().split(' '))
S = [list(map(int,input().split(' '))) for i in range(N)]
C = [list(map(int,input().split(' '))) for i in range(M)]
for i in range(N):
  l = [abs(S[i][0]-C[j][0])+abs(S[i][1]-C[j][1]) for j in range(M)]
  print(l.index(min(l))+1)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split(' '))
S = [list(map(int,input().split(' '))) for i in range(N)]
C = [list(map(int,input().split(' '))) for i in range(M)]
for i in range(N):
  l = [abs(S[i][0]-C[i][0])+abs(S[i][1]-C[i][1]) for i in range(M)]
  print(l.index(min(l))+1)
Problem p03041 (python)

Fixed submission:
n,k=map(int,input().split())
s=list(input())
s[k-1]=s[k-1].lower()
print("".join(s))

Buggy submission (verdict: Runtime Error):
n,k=tuple(int,input().split())
s=list(input())
s[k-1]=s[k-1].lower()
print("".join(s))
Problem p03038 (python)

Fixed submission:
n,m = map(int, input().split())
a = sorted(list(map(int,input().split())))
bc = [list(map(int, input().split())) for _ in range(m)]
bc.sort(key=lambda x: x[1], reverse=True )
count = 0
for b,c in bc:
    for _ in range(b):
        if count == n or a[count] >= c:
            break

        a[count] = c
        count += 1

print(sum(a))

Buggy submission (verdict: Runtime Error):
n = 0
for b,c in bc:
    for i in range(b):
        if i == n or a[i] >= c:
            break

        a[i] = c
        n += 1

print(sum(a))
Problem p03072 (python)

Fixed submission:
n = int(input())
h = [int(n) for n in input().split()]

max = h[0]
ans = 0

for i in h:
    if max<=i:
        ans += 1
        max = i
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(n) for n in input().split()]

a = 0
b = 1
ans = 1

for i in range(n.length-2):
    if n[a]<n[b]:
        ans += 1
    a += 1
    b += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(n) for n in input().split()]

a = 0
b = 1
ans = 1

for i in range(n.length-1):
    if n[a]<n[b]:
        ans += 1
    a += 1
    b += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(n) for n in input().split()]

a = 0
b = 1
ans = 1

while b<n.length
    if n[a]<n[b]:
        ans += 1
    a += 1
    b += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(n) for n in input().split()]

a = 0
b = 1
ans = 1
while b != h.length-1:
    while h[a]<h[b]:
        ans = ans + 1
        a = a + 1
        b = b + 1
    a += 1
    b += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(n) for n in input().split()]

a = 0
b = 1
ans = 1
while h[a]<h[b]:
    ans = ans + 1
    a = a + 1
    b = b + 1
    continue

print(ans)
Problem p03077 (python)

Fixed submission:
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
 
min = min(A, B, C, D, E)
 
ans = 4 + int(N/min)
if N % min != 0:
    ans = ans + 1
print(ans)

Buggy submission (verdict: Runtime Error):
src = [int(input()) for _ in range(6)]
t = min(src[1:])
    if src[0]%t:
        print(4 + src[0]//t + 1)
    else:
        print(4 + src[0]//t)

Buggy submission (verdict: Runtime Error):
src = [int(input()) for _ in range(6)]
t = min(src[1:])
	if src[0]%t:
		print(4 + src[0]//t + 1)
	else:
		print(4 + src[0]//t)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

min = min(A, B, C, D, E)

ans = 4 + int(N/min)
    if N % min != 0:
        ans = ans + 1
print(ans)
Problem p03038 (python)

Fixed submission:
from sys import stdin, exit

N, M = map(int, stdin.readline().split())
A = list(map(int, stdin.readline().split()))
p = [(A[i], 1) for i in range(N)]
for _ in range(M):
    B, C = map(int, stdin.readline().split())
    p.append((C, B))

p.sort(reverse=True)

ans, cnt = 0, N
for (v, c) in p:
    use = min(c, cnt)
    ans += use * v
    cnt -= use

print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin, exit

N, M = map(int, stdin.readline().split())
nums = [0]*100000
A = list(map(int, stdin.readline().split()))
for a in A:
    nums[a] += 1
for _ in range(M):
    B, C = map(int, stdin.readline().split())
    for _ in range(B):
        nums[C] += 1

ans = 0
count = 0
for i in range(99999, -1, -1):
    if nums[i] != 0:
        if count >= N:
            print(ans)
            exit()
        if nums[i] + count >= N:
            ans += (N-count)*i
            print(ans)
            exit()
        else:
            ans += (nums[i] * i)
            count += nums[i]

print(ans)
Problem p03242 (python)

Fixed submission:
n = input()

ans = ''
for i, v in enumerate(n):
    if v == '9':
        ans += '1'
    elif v == '1':
        ans += '9'
    else:
        ans += v

print(ans)

Buggy submission (verdict: Runtime Error):
n = input()

for i,v in enumerate(n):
  if v == '9':
    n[i] = '1'
  elif v == '1':
    n[i] = '9'
    
print(n)
Problem p03803 (python)

Fixed submission:
a, b = ((int(x) - 2) % 100 for x in input().split())
print('Draw' if a == b else 'Alice' if a > b else 'Bob')

Buggy submission (verdict: Runtime Error):
a, b = ((int(x) - 2) % 100 for x in input().split())
print('Draw' if a == b else 'Alice' a > b else 'Bob')
Problem p03242 (python)

Fixed submission:
def answer(in0):

    result = ''

    for ch in str(in0):
        if ch == '9':
            result += '1'
        elif ch == '1':
            result += '9'

    return result


print(answer(input()))

Buggy submission (verdict: Runtime Error):

def answer(in0, in1):
    even = {}
    odd = {}

    list = in1.split(" ")

    for i in range(len(list)):
        n = list[i]
        if i % 2 == 0:
            odd[n] = odd.get(n, 0) + 1
        else:
            even[n] = even.get(n, 0) + 1

    odd = sorted(
        [{'key': k, 'value': odd[k]} for k in odd],
        key=lambda x: (-x['value'], int(x['key'])))

    even = sorted(
        [{'key': k, 'value': even[k]} for k in even],
        key=lambda x: (-x['value'], int(x['key'])))

    oddMax = odd[0]
    evenMax = even[0]

    #print(odd)
    #print(even)

    # 奇数偶数ともにトップのキーが一緒
    if oddMax['key'] == evenMax['key']:
        # 文字列が全部同じだからどっちかを書き換えればOK
        if len(even) == 1 and len(odd) == 1:
            return int(int(in0) / 2)

        if oddMax['value'] > evenMax['value']:
            evenMax = even[1]
        else:
            oddMax = odd[1]

    oddCount = 0
    evenCount = 0

    for v in odd:
        if v['key'] != oddMax['key']:
            oddCount += v['value']

    for v in even:
        if v['key'] != evenMax['key']:
            evenCount += v['value']

    return oddCount + evenCount

print(answer(input(), input()))
Problem p03265 (python)

Fixed submission:
def answer(in0):
    nums = [int(n) for n in in0.split(" ")]
    x1 = int(nums[0])
    y1 = int(nums[1])
    x2 = int(nums[2])
    y2 = int(nums[3])

    width = (x2 - x1)
    height = (y2 - y1)

    x3 = x2 - height
    y3 = y2 + width
    x4 = x1 - height
    y4 = y1 + width

    print(x3, y3, x4, y4)

answer(input())

Buggy submission (verdict: Runtime Error):
def answer(in0, in1, in2, in3):
    x1 = int(in0)
    y1 = int(in1)
    x2 = int(in2)
    y2 = int(in3)

    width = (x2 - x1)
    height = (y2 - y1)

    x3 = x2 - height
    y3 = y2 + width
    x4 = x1 - height
    y4 = y1 + width

    print(x3, y3, x4, y4)

answer(input(), input(), input(), input())
Problem p03038 (python)

Fixed submission:
from operator import itemgetter

N, M = map(int, input().split())
in_hand = list(map(int, input().split()))
in_hand.sort()

change_list = []

for line in range(M):
    change_count, change_number = map(int, input().split())

    change_list.append([change_count, change_number])


change_list.sort(key=itemgetter(1), reverse=True)

index = 0
try:
    for change in change_list:
        for i in range(change[0]):
            if in_hand[i+index] < change[1]:
                in_hand[i+index] = change[1]
            else:
                break
        else:
            index += change[0]
            continue
        break
except:
    pass

print(sum(in_hand))

Buggy submission (verdict: Runtime Error):
from operator import itemgetter

N, M = map(int, input().split())
in_hand = list(map(int, input().split()))
in_hand.sort()

change_list = []

for line in range(M):
    change_count, change_number = map(int, input().split())

    change_list.append([change_count, change_number])


change_list.sort(key=itemgetter(1), reverse=True)

index = 0
for change in change_list:
    for i in range(change[0]):
        if in_hand[i+index] < change[1]:
            in_hand[i+index] = change[1]
        else:
            break
    else:
        index += change[0]
        continue
    break

print(sum(in_hand))
Problem p03036 (python)

Fixed submission:
def read_input():
    a,b,c=map(int, input().split())
    if 2<=a<=5 and 1<=b<=100 and b<c<=200:
        return a,b,c
    else :
        print("Error")
        exit()

def main():
    num = 10

    r,D,x=read_input()
    sum_x=x

    for i in range(num):
        sum_x=r*sum_x-D
        print(sum_x)
        sum_x=sum_x



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
!/work/yota509/env_python3/bin/python3                                                              
# -*- coding: utf-8 -*-                                                                              


def read_input():
    a,b,c=map(int, input().split())
    if 2<=a<=5 and 1<=b<=100 and b<c<=200:
        return a,b,c
    else :
        print("Error")
        exit()

def main():
    num = 10
    # r=None                                                                                         
    # d=None                                                                                         
    # x=None                                                                                         

    r,D,x=read_input()
    sum_x=x

    for i in range(num):
        sum_x=r*sum_x-D
        print(sum_x)
        sum_x=sum_x



if __name__ == "__main__":
    main()
Problem p03072 (python)

Fixed submission:
import sys


def CheckRangeInt(input_str,_min,_max):

    if input_str.isdecimal()==0 or int(input_str)<_min or int(input_str)>_max:
        print("error")
        sys.exit()

    return int(input_str)


def CheckRangeList(input_list,_min,_max):
    for i in range(len(input_list)) :
        if H[i]<_min or H[i]>_max :
            print("error")
            sys.exit()
    return input_list

N=input()

# if N.isdecimal()==0 or int(N)<1 or int(N)>20:                                                                                                                                                             
#     print("error")                                                                                                                                                                                        
#     sys.exit()                                                                                                                                                                                            

# N=int(N)                                                                                                                                                                                                  
N=CheckRangeInt(N,1,20)


H=list(map(int,input().strip().split()))

if len(H)!=N :
    print("error")
    sys.exit()

# for i in range(N) :                                                                                                                                                                                       
#     if H[i]<1 or H[i]>100 :                                                                                                                                                                               
#         print("error")                                                                                                                                                                                    
#         sys.exit()                                                                                                                                                                                        

H=CheckRangeList(H,1,100)

highest=0
can_see=0

for i in range(N):
    if H[i]>=highest :
        can_see=can_see+1
        highest=H[i]

print(can_see)

Buggy submission (verdict: Runtime Error):
import sys


def CheckRangeInt(input_str,_min,_max):

    if input_str.isdecimal()==0 or int(input_str)<_min or int(input_str)>_max:
        print("error")
        sys.exit()

    return int(input_str)


def CheckRangeList(input_list,_min,_max):
    for i in range(len(input_list)) :
        if H[i]<_min or H[i]>_max :
            print("error")
            sys.exit()
    return input_list

N=input()
N=CheckRangeInt(N,1,20)


H=list(map(int,input().strip().split()))
if len(H)!=N :
    print("error")
    sys.exit()
H=CheckRangeList(H,1,100)

highest=0
can_see=0

for i in range(N):
    if H[i]>=highest :
	can_see=can_see+1
        highest=H[i]

print(can_see)
Problem p03785 (python)

Fixed submission:
passengers, bus_size, time_lim = map(int, input().split())
pass_list = [int(input()) for passenger in range(passengers)]
pass_list.sort()
front = 0
now = 0
cnt = 0
ans = 0
for psngr_lst in pass_list:
    if cnt == 0:
        front = psngr_lst
        now = psngr_lst
        cnt += 1
    elif cnt == bus_size:
        front = psngr_lst
        now = psngr_lst
        cnt = 1
        ans += 1
    elif now - front <= time_lim:
        if psngr_lst - front <= time_lim:
            now = psngr_lst
            cnt += 1
        else:
            front = psngr_lst
            now = psngr_lst
            cnt = 1
            ans += 1
if cnt:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
passengers, bus_size, time_lim = map(int, input().split())
pass_list = [int(input()) for passenger in range(passengers)]
pass_list.sort()
front = 0
now = 0
cnt = 0
ans = 0
for psngr_lst in pass_list:
    if cnt == 0:
        front = i
        now = i
        cnt += 1
    elif cnt == bus_size:
        front = i
        now = i
        cnt = 1
        ans += 1
    elif now - front <= time_lim:
        if i - front <= time_lim:
            now = i
            cnt += 1
        else:
            front = i
            now = i
            cnt = 1
            ans += 1
if cnt:
    ans += 1
print(ans)
Problem p03821 (python)

Fixed submission:
a=[]
b=[]
n=int(input())
for i in range(n):
    j,k=map(int,input().split())
    a.append(j)
    b.append(k)
x=0
for i in range(n-1,-1,-1):
    n,m=a[i],b[i]
    y=(n+x)%m
    if y!=0:x+=m-y
print(x)

Buggy submission (verdict: Runtime Error):
seq_a = []
seq_b = []
seq_n = int(input())
for i in range(seq_n):
    num_a,num_b=map(int,input().split())
    seq_a.append(num_a)
    seq_b.append(num_b)
x = 0
for i in range(seq_n - 1, -1 ,-1):
    seq_n , elem_b = seq_a[i],seq_b[i]
    y = (seq_n + x)% elem_b
    if y != 0: x += (m-y)
print(x)

Buggy submission (verdict: Runtime Error):
seq_a = []
seq_b = []
seq_n = int(input())
for i in range(seq_n):
    num_a,num_b=map(int,input().split())
    seq_a.append(num_a)
    seq_b.append(num_b)
x = 0
for i in range(seq_n - 1, -1 ,-1):
    elem_a , elem_b = seq_a[i],seq_b[i]
    y = (elem_a + x)% elem_b
    if y != 0: x += (m-y)
print(x)

Buggy submission (verdict: Runtime Error):
seq_a = []
seq_b = []
seq_n = int(input())
for i in range(seq_n):
    num_a,num_b=map(int,input().split())
    a.append(num_a)
    b.append(num_b)
x = 0
for i in range(seq_n - 1, -1 ,-1):
    elem_a , elem_b = seq_a[i],seq_b[i]
    y = (elem_a + x)% elem_b
    if y != 0: x += (m-y)
print(x)