Buggy python submission (verdict: Time Limit Exceeded):
import math
import numpy as np

n = int(input())
a, b = [], []
for _ in range(n):
    t1, t2 = map(int, input().split())
    a.append(t1)
    b.append(t2)

a, b = a[::-1], b[::-1]
a = np.array(a)

dif = 0
ans = 0
for i in range(n):
    if a[i] % b[i] != 0:
        dif =  math.ceil(a[i]/b[i]) * b[i] - a[i]
        ans += dif
        a[i:] += dif

print(ans)

Fixed submission:
n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)

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

n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

ans = 0

for i in range(n-1, -1, -1):
    if not A[i] % B[i] == 0:
        temp = B[i]*((A[i]//B[i])+1) - A[i]
        ans += temp
        A += temp
print(int(ans))


Fixed submission:
n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

ans = 0

for i in range(n-1, -1, -1):
    if not A[i] % B[i] == 0:
        temp = B[i]*((A[i]//B[i])+1) - A[i]
        ans += temp
        A += temp
print(int(ans))

Fixed submission:
n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)

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

n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

ans = 0

for i in range(n-1, -1, -1):
    if A[i] % B[i] == 0:
        pass
    else:
        temp = B[i]*((A[i]//B[i])+1) - A[i]
        ans += temp
        A += temp
print(int(ans))

Fixed submission:
n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

ans = 0

for i in range(n-1, -1, -1):
    if A[i] % B[i] == 0:
        pass
    else:
        temp = B[i]*((A[i]//B[i])+1) - A[i]
        ans += temp
        A += temp
print(int(ans))

Fixed submission:
n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

Fixed submission:
n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)

Buggy python submission (verdict: Runtime Error):
ans = 0

for i in range(10**9):
  ans += 1
  
print(ans

Fixed submission:
n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

ans = 0
A = A[::-1]
B = B[::-1]

for i in range(n):
    if A[i] % B[i] == 0:
        pass
    else:
        temp = B[i]*((A[i]//B[i])+1) - A[i]
        ans += temp
        A += temp
print(int(ans))

Fixed submission:
n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

ans = 0
A = np.array(A)[::-1]
B = np.array(B)[::-1]

for i in range(n):
    if A[i] % B[i] == 0:
        pass
    else:
        temp = B[i]*((A[i]//B[i])+1) - A[i]
        ans += temp
        A += temp
print(ans)

Fixed submission:
n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)