ZhenlongDai/ACPR huggingface dataset:
Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

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

c = 0
for a,b in zip(A,B):
    if a%b == 0:
        continue
    
    a += c
    
    c += b-(a%b)
print(c)

Failing test case input:
7
5 2
4 2
5 12
2 4
0 1
2 8
17 6

Expected output:
9


Actual output:
21


Fixed submission (verdict: Accepted):

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

c = 0
for a,b in zip(A,B):
    
    a += c
    
    if a%b == 0:
        continue
    
    c += b-(a%b)
print(c)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
AB = [0] * N
for n in range(N):
  AB[-1-n] = [int(x) for x in input().strip().split()]
ans = 0
cnt = 0
for (a, b) in AB:
  if b == 1:
    if a + cnt == 0:
      ans += 1
  else:
    t = b - ((a + cnt) % b)
    cnt += t
    ans += t
print(ans)


Failing test case input:
7
4 1
4 1
8 12
2 4
6 4
5 8
10 7

Expected output:
16


Actual output:
28


Fixed submission (verdict: Accepted):
N = int(input())
AB = [0] * N
for n in range(N):
  AB[-1-n] = [int(x) for x in input().strip().split()]
ans = 0
cnt = 0
for (a, b) in AB:
  mod = (a + cnt) % b
  if mod:
    t = b - mod
    cnt += t
    ans += t
print(ans)

Problem: p03821
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def main():
    n = int(input())
    A, B = [], []
    for _ in range(n):
        a, b = list(map(int, input().split()))
        A.append(a)
        B.append(b)
    ans = 0
    for a, b in zip(A[::-1], B[::-1]):
        aa = a + ans
        if aa <= b:
            ans += b - aa
        else:
            r = aa % b
            if r != 0:
                ans += b - r
    print(ans)

if __name__ == '__main__':
    main()


Failing test case input:
3
-1 6
6 3
0 9

Expected output:
1


Actual output:
13


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    A, B = [], []
    for _ in range(n):
        a, b = list(map(int, input().split()))
        A.append(a)
        B.append(b)
    ans = 0
    for a, b in zip(A[::-1], B[::-1]):
        aa = a + ans
        r = aa % b
        if r != 0:
            ans += b - r
    print(ans)

if __name__ == '__main__':
    main()
Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a_list = []
b_list = []
ans = 0

for i in range(n):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)

for i,j in zip(a_list[::-1],b_list[::-1]):
    if (i+ans) > j:
        if (i+ans)%j != 0:
            inc = j - ((i+ans)%j)
            ans += inc
    else:
        ans += (j-(i+ans))

print(ans)


Failing test case input:
3
2 1
0 1
8 4

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
a_list = []
b_list = []
ans = 0

for i in range(n):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)

for i,j in zip(a_list[::-1],b_list[::-1]):
    if (i+ans)%j != 0:
        inc = j - ((i+ans)%j)
        ans += inc
print(ans)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
A = []
B = []

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

print(A)
A.reverse()
B.reverse()

ans = 0
for i in range(n):
    temp = B[i] - (A[i] % B[i])
    if temp == B[i]:
        temp = 0
    A = list(map(lambda x: x + temp, A))
    ans += temp

print(ans)

Failing test case input:
3
3 4
2 1
14 4

Expected output:
5


Actual output:
[3, 2, 14]
5


Fixed submission (verdict: Accepted):
n = int(input())
A = []
B = []

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

A.reverse()
B.reverse()

ans = 0
for i in range(n):
    temp = B[i] - ((A[i]+ans) % B[i])
    if temp == B[i]:
        temp = 0
    ans += temp

print(ans)

Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    N = int(input())
    A = list()

    for i in range(N):
        a, b = map(int, input().split())
        A.append([a, b])

    A.reverse()
    ans = 0
    offset = 0

    for pair in A:
        a, b = pair

        if a % b == 0:
                continue
        else:
            n = b - ((a + offset) % b)
            ans += n
            offset += n
    
    print(ans)

if __name__ == "__main__":
    main()

Failing test case input:
7
3 1
4 2
5 12
2 3
5 3
5 15
10 7

Expected output:
20


Actual output:
19


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    A = list()

    for i in range(N):
        a, b = map(int, input().split())
        A.append([a, b])

    A.reverse()
    ans = 0
    offset = 0

    for pair in A:
        a, b = pair

        if (a + offset) % b == 0:
            n = 0
        else:
            n = b - ((a + offset) % b)

        ans += n
        offset += n
        
    print(ans)

if __name__ == "__main__":
    main()
Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = []
b = []

for _ in range(n):
    c, d = map(int, input().split())
    a.append(c)
    b.append(d)

s = 0
for i in range(n-1, -1, 1):
    r = b[i] + s % a[i]
    if r != 0:
        s += r
    
print(s)

Failing test case input:
7
3 1
4 1
0 1
2 6
5 3
5 28
10 7

Expected output:
28


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
a = []
b = []

for _ in range(n):
    c, d = map(int, input().split())
    a.append(c)
    b.append(d)

s = 0
for i in range(n-1, -1, -1):
    r = (a[i] + s) % b[i]
    if r != 0:
        s += b[i] - r
    
print(s)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a = int(input())
ar = []
for i in range(a):
    l = list(map(int,input().split(" ")))
    ar.insert(0,l)
count = 0
for r in ar:
    x = r[0] + count
    y = r[1]
    while True:
        if x > y:
            y += r[1]
        else:
            break
    count += y - x
print(count)

Failing test case input:
3
-1 6
6 3
0 9

Expected output:
1


Actual output:
13


Fixed submission (verdict: Accepted):
a = int(input())
ar = []
for i in range(a):
    l = list(map(int,input().split(" ")))
    ar.append(l)
ar.reverse()
count = 0
for r in ar:
    x = r[0] + count
    y = r[1]
    m = x % y
    if m != 0:
        count += y - m
print(count)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[list(map(int, input().split())) for i in range(n)]
count=0

for i in range(n):
    if a[-(i+1)][0]+count < a[-(i+1)][1]:
        count+= a[-(i+1)][1]- (a[-(i+1)][0]+count)

    elif  (a[-(i+1)][0]+count)%a[-(i+1)][1]==0:
        continue

    else:
        x=(a[-(i+1)][0]+count)% a[-(i+1)][1]
        count+=a[-(i+1)][1]-x
print(count)

Failing test case input:
3
-1 6
6 3
0 9

Expected output:
1


Actual output:
13


Fixed submission (verdict: Accepted):
n=int(input())
a=[list(map(int, input().split())) for i in range(n)]
count=0

for i in range(n):
    if (a[-(i + 1)][0] + count) % a[-(i + 1)][1]==0:
        continue

    else:
        x = (a[-(i + 1)][0] + count) % a[-(i + 1)][1]
        count += a[-(i + 1)][1] - x



print(count)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())

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

pb = 0
for a, b in zip(alist[::-1], blist[::-1]):
  a += pb
  if a > b:
    pb += b - a % b if a % b != 0 else 0
  else:
    pb += b - a

print(pb)

Failing test case input:
3
2 1
0 1
8 4

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())

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

pb = 0
for a, b in zip(alist[::-1], blist[::-1]):
  a += pb
  pb += b - a % b if a % b != 0 else 0
print(pb)
Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    N = int(input())
    A = list()

    for i in range(N):
        a, b = map(int, input().split())
        A.append([a, b])

    A.reverse()
    ans = 0
    offset = 0

    for pair in A:
        a, b = pair

        if b == 1:
                continue
        else:
            n = b - ((a + offset) % b)
            ans += n
            offset += n
    
    print(ans)

if __name__ == "__main__":
    main()

Failing test case input:
7
5 4
4 2
5 12
2 4
0 1
2 8
17 6

Expected output:
11


Actual output:
23


Fixed submission (verdict: Accepted):
def main():
    N = int(input())
    A = list()

    for i in range(N):
        a, b = map(int, input().split())
        A.append([a, b])

    A.reverse()
    ans = 0
    offset = 0

    for pair in A:
        a, b = pair

        if (a + offset) % b == 0:
            n = 0
        else:
            n = b - ((a + offset) % b)

        ans += n
        offset += n
        
    print(ans)

if __name__ == "__main__":
    main()

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

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

ans = 0
for a, b in zip(A, B):
    a += ans
    m = b - (a % b) if b != 1 else 0
    if a == 0:
        m = b
    ans += m
print(ans)

Failing test case input:
7
0 1
4 2
5 12
2 4
6 1
5 8
24 6

Expected output:
8


Actual output:
20


Fixed submission (verdict: Accepted):
N = int(input())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

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

ans = 0
for a, b in zip(A, B):
    a += ans
    if a % b != 0: 
        m = b - (a % b) 
        ans += m
print(ans)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[0]*n;b=a[:]
for i in range(n):
  c,d=map(int,input().split())
  a[i]=c;b[i]=d
ans=0
for i in range(n)[::-1]:
  while a[i]%b[i]!=0:
    a[i]+=1
    ans+=1
print(ans)

Failing test case input:
7
6 1
4 1
5 12
2 4
5 3
5 4
10 7

Expected output:
19


Actual output:
17


Fixed submission (verdict: Accepted):
n=int(input())
a=[0]*n;b=a[:]
for i in range(n):
  c,d=map(int,input().split())
  a[i]=c;b[i]=d
ans=0
for i in range(n)[::-1]:
  a[i]+=ans
  if a[i]%b[i]==0:continue
  ans+=b[i]-(a[i]%b[i])
print(ans)

Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
ab = [input().split() for _ in [0]*n]
a = [int(i) for i, j in ab][::-1]
b = [int(j) for i, j in ab][::-1]
ans = 0
for i in range(n):
    if a[i] % b[i] != 0:
        ans += b[i] - ((a[i]+ans) % b[i])
print(ans)


Failing test case input:
7
4 1
4 2
5 12
2 4
6 1
5 8
10 6

Expected output:
8


Actual output:
7


Fixed submission (verdict: Accepted):
n = int(input())
ab = [input().split() for _ in [0]*n]
a = [int(i) for i, j in ab][::-1]
b = [int(j) for i, j in ab][::-1]
ans = 0
for i in range(n):
    a[i] += ans
    if a[i] % b[i] != 0:
        ans += b[i] - (a[i] % b[i])
print(ans)
Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a, b = [], []

for i in range(n):
    s, t = map(int, input().split())
    a.append(s)
    b.append(t)

ans = 0
for i in range(n):
    aa = a[n-i-1]
    bb = b[n-i-1]
    if bb != 1:
        t = (bb)-(aa+ans)%bb
        ans += t

print(ans)



Failing test case input:
7
6 1
4 1
5 6
2 4
5 3
5 4
10 7

Expected output:
13


Actual output:
19


Fixed submission (verdict: Accepted):
n = int(input())
a, b = [], []

for i in range(n):
    s, t = map(int, input().split())
    a.append(s)
    b.append(t)

ans = 0
for i in range(n):
    aa = a[n-i-1]
    bb = b[n-i-1]
    if (aa+ans)%bb != 0:
        t = (bb)-(aa+ans)%bb
        ans += t

print(ans)

Problem: p03821
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(sys.stdin.readline())
a,b = [],[]
for _ in range(n):
    x,y = map(int,sys.stdin.readline().split())
    a.append(x)
    b.append(y)
ans = 0
print(a,b)
for i in range(n)[::-1]:
    x = -(a[i] + ans) % b[i]
    ans += x
print(ans)


Failing test case input:
7
5 4
4 2
5 12
2 4
0 1
2 8
17 6

Expected output:
11


Actual output:
[5, 4, 5, 2, 0, 2, 17] [4, 2, 12, 4, 1, 8, 6]
11


Fixed submission (verdict: Accepted):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n = int(sys.stdin.readline())
a,b = [],[]
for _ in range(n):
    x,y = map(int,sys.stdin.readline().split())
    a.append(x)
    b.append(y)
ans = 0
for i in range(n)[::-1]:
    x = -(a[i] + ans) % b[i]
    ans += x
print(ans)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
AB =[list(map(int, input().split())) for _ in range(N)]
plus = 0
cnt = 0
while AB:
    a, b = AB.pop()
    p = b - ((a+plus)%b)
    plus += p
    cnt += p
print(cnt)

Failing test case input:
7
3 1
4 2
5 12
2 3
5 3
5 15
10 7

Expected output:
20


Actual output:
21


Fixed submission (verdict: Accepted):
N = int(input())
AB =[list(map(int, input().split())) for _ in range(N)]
plus = 0
cnt = 0
while AB:
    a, b = AB.pop()
    p = b - ((a+plus)%b)
    if p < b:
        plus += p
        cnt += p
print(cnt)
Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
A = [0]*n
B = [0]*n
for i in range(n):
  A[i],B[i] = map(int,input().split())

ans = 0
for i in range(n):
  j = -1-i  
  if B[j] == 1:
    continue
  ans += B[j] - (A[j]+ans)%B[j]  
  
print(ans)  

Failing test case input:
7
0 1
4 2
0 11
2 8
6 1
5 16
24 6

Expected output:
22


Actual output:
24


Fixed submission (verdict: Accepted):
n = int(input())
A = [0]*n
B = [0]*n
for i in range(n):
  A[i],B[i] = map(int,input().split())

ans = 0
for i in range(n)[::-1]:
  j = i  
  tmp = (A[j]+ans) % B[j]
  if tmp:
    ans += B[j] - tmp
  
print(ans)

Problem: p03821
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
t = int(input())
a = list()

for _ in range(t):
    
    c,d = map(int,input().split())
    a.append((c,d))
    
a.reverse()

g = 0

for i in range(t):
    
    f = (a[i][0]+g)%a[i][1]
    f = a[i][1]-f
    g += f

print (g)

Failing test case input:
7
4 1
4 2
5 12
2 4
6 1
5 8
13 6

Expected output:
20


Actual output:
21


Fixed submission (verdict: Accepted):
t = int(input())
a = list()

for _ in range(t):
    
    c,d = map(int,input().split())
    a.append((c,d))
    
a.reverse()

g = 0

for i in range(t):
    
    f = (a[i][0]+g)%a[i][1]
    if(f!=0):
        f = a[i][1]-f
    g += f

print (g)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[]
b=[]
for i in range(n):
    p=[int(j) for j in input().split()]
    a.append(p[0])
    b.append(p[1])

a.reverse()
b.reverse()
ans=0
for i in range(n):
    q=0
    r=1
    while a[i]+ans>b[i]*r:
        r+=1
    ans+=b[i]*r-a[i]-ans

print(ans)
        




Failing test case input:
3
2 1
0 1
8 4

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n=int(input())
a=[]
b=[]
for i in range(n):
    p=[int(j) for j in input().split()]
    a.append(p[0])
    b.append(p[1])

a.reverse()
b.reverse()
ans=0
import math
for i in range(n):
    a[i]+=ans
    ans+=b[i]*math.ceil(a[i]/b[i])-a[i]
print(ans)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
l = []

for i in range(n):
    a, b = map(int, input().split())
    a %= b
    l.append([a, b])

ans = 0

for i in range(1, n)[::-1]:
    ans += (l[i][1] - l[i][0])  
    l[i-1][0] += ans
    l[i-1][0] %= l[i-1][1]

ans += (l[0][1] - l[0][0])

print(ans)

Failing test case input:
7
2 1
4 2
5 12
2 4
6 1
1 13
34 6

Expected output:
20


Actual output:
21


Fixed submission (verdict: Accepted):
n = int(input())
a = []
b = []
for i in range(n):
    a_e, b_e = map(int, input().split())
    a.append(a_e)
    b.append(b_e)

ans = 0

for i in range(n)[::-1]:
    mod = (a[i] + ans) % b[i]
    if mod != 0:
        ans += b[i] - mod

print(ans)
Problem: p03821
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)][::-1]
ans = 0
tmp = 0
add = 0
for i in range(N):
    if arr[i][1] == 1:
        continue
    add += tmp
    tmp = arr[i][1] - ((arr[i][0]+add) % arr[i][1])
    ans += tmp
print(ans)

Failing test case input:
3
3 6
2 2
18 4

Expected output:
3


Actual output:
9


Fixed submission (verdict: Accepted):
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)][::-1]
ans = 0
for i in range(N):
    if (arr[i][0]+ans) % arr[i][1] != 0:
        ans += arr[i][1] - ((arr[i][0]+ans) % arr[i][1])
print(ans)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
import fractions

n = int(stdin.readline().rstrip())
li = [[0,0]]+[list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
li = li[::-1]
count = 0
for i in range(n):
    if li[i][0]%li[i][1] != 0:
        count += li[i][1]-li[i][0]%li[i][1]
        li[i+1][0] += count
    print(li)
print(count)

Failing test case input:
3
2 4
0 1
8 4

Expected output:
2


Actual output:
[[8, 4], [0, 1], [2, 4], [0, 0]]
[[8, 4], [0, 1], [2, 4], [0, 0]]
[[8, 4], [0, 1], [2, 4], [2, 0]]
2


Fixed submission (verdict: Accepted):
from sys import stdin
import fractions

n = int(stdin.readline().rstrip())
li = [[0,0]]+[list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
li = li[::-1]
count = 0
for i in range(n):
    count += -li[i][0]%li[i][1]
    li[i+1][0] += count
print(count)

Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A=[]
B=[]
for _ in range(N):
  a, b=map(int, input().split())
  tmpa=a%b
  A.append(tmpa)
  B.append(b)
ans=0
for i in range(N-1, -1, -1):
  if A[i]==0:
    continue
  tmp=B[i]-(A[i]+ans)%B[i]
  ans+=tmp
print(ans)
  

Failing test case input:
7
4 1
4 2
5 12
2 4
6 1
5 8
2 6

Expected output:
20


Actual output:
19


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

Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
A,B = [],[]
for i in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    
A,B = A[::-1],B[::-1]

num = 0
for i in range(n):
    if A[i]%B[i] !=0:
        A[i] +=num
        num = num + B[i] - A[i]%B[i]

print(num)

Failing test case input:
3
3 5
2 39
14 2

Expected output:
37


Actual output:
42


Fixed submission (verdict: Accepted):
n = int(input())
A,B = [],[]
for i in range(n):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    
A,B = A[::-1],B[::-1]

num = 0
for i in range(n):
    A[i] +=num
    if A[i]%B[i] !=0:
        num = num + B[i] - A[i]%B[i]
        
print(num)
Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
A,B = [],[]
for _ in range(n):
	a,b = map(int,input().split())
	A.append(a)
	B.append(b)
c = 0
for i in reversed(range(n)):
	if B[i] == 1:
		continue
	d = B[i]-A[i]%B[i]
	c += d
	for j in range(i+1):
		A[j] += d
		
print(c)

Failing test case input:
3
0 4
3 3
9 6

Expected output:
4


Actual output:
8


Fixed submission (verdict: Accepted):
n = int(input())
A,B = [],[]
for _ in range(n):
	a,b = map(int,input().split())
	A.append(a)
	B.append(b)
c = 0
for i in reversed(range(n)):
	A[i] += c
	if A[i] % B[i] != 0:
		c += B[i]-(A[i]%B[i])
		
print(c)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from sys import stdin
import fractions

n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)][::-1]

count = 0

for i in range(n-1):
    if li[i][0]%li[i][1] != 0:
        count += li[i][1]-li[i][0]%li[i][1]
        li[i+1][0] += count
if li[-1][0]%li[-1][1] != 0:       
    count += li[-1][1]-li[-1][0]%li[-1][1]
print(count)

Failing test case input:
7
3 1
4 1
5 9
2 6
5 3
5 8
6 7

Expected output:
4


Actual output:
8


Fixed submission (verdict: Accepted):
from sys import stdin
import fractions

n = int(stdin.readline().rstrip())
li = [[0,0]]+[list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
li = li[::-1]
count = 0
for i in range(n):
    count += -li[i][0]%li[i][1]
    li[i+1][0] += count
print(count)

Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A=[]
B=[]
for i in range(N):
    AB=list(map(int,input().split()))
    A.append(AB[0])
    B.append(AB[1])

ans=0
for i in range(N-1,-1,-1):
    if B[i]!=1:
        A[i]=(A[i]+ans)%B[i]
        ans+=B[i]-A[i]

print(ans)

Failing test case input:
3
3 4
3 3
9 6

Expected output:
5


Actual output:
9


Fixed submission (verdict: Accepted):
N=int(input())
A=[]
B=[]
for i in range(N):
    AB=list(map(int,input().split()))
    A.append(AB[0])
    B.append(AB[1])

ans=0
for i in range(N-1,-1,-1):
    A[i]+=ans
    A[i]%=B[i]
    if A[i]!=0:
        ans+=B[i]-A[i]

print(ans)
Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
from math import ceil


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A, B = [], []
    for i in range(n):
        a, b = nm()
        A.append(b - a % b)
        B.append(b)
    for i in range(n - 2, -1, -1):
        if A[i + 1] > A[i]:
            A[i] += B[i] * ceil((A[i + 1] - A[i]) / B[i])
    print(A[0])


if __name__ == '__main__':
    main()


Failing test case input:
7
5 1
4 2
5 12
2 4
6 1
5 8
24 6

Expected output:
8


Actual output:
20


Fixed submission (verdict: Accepted):
import sys
from math import ceil


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A, B = [], []
    for i in range(n):
        a, b = nm()
        if a % b != 0:
            A.append(b - a % b)
        else:
            A.append(0)
        B.append(b)
    for i in range(n - 2, -1, -1):
        if A[i + 1] > A[i]:
            A[i] += B[i] * ceil((A[i + 1] - A[i]) / B[i])
    print(A[0])


if __name__ == '__main__':
    main()

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

res = 0
for i in range(n-1,-1,-1):
    a,b = ab[i]
    a += res
    if b>=a:
        res += b-a
    elif a%b==0:
        pass
    elif b>1:
        res += b-a%b
print(res)


Failing test case input:
3
2 1
0 1
8 4

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):

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

res = 0
for i in range(n-1,-1,-1):
    a,b = ab[i]
    a += res
    if a%b!=0:
        res += b-a%b
    
    
    
    
    
        
print(res)
Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys

def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    N = INT()
    A=[]
    B = []
    for _ in range(N):
        a,b = MAP()
        A.append(a)
        B.append(b)

    answer = 0
    for i in range(N-1,-1,-1):
        need = B[i]-(answer+A[i])%B[i]
        answer += need
    print(answer)
    return

if __name__ == '__main__':
    main()


Failing test case input:
7
3 1
4 1
5 12
2 6
5 3
5 8
10 7

Expected output:
19


Actual output:
21


Fixed submission (verdict: Accepted):

import sys

def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    N = INT()
    A=[]
    B = []
    for _ in range(N):
        a,b = MAP()
        A.append(a)
        B.append(b)

    answer = 0
    for i in range(N-1,-1,-1):
        if (answer+A[i])%B[i] > 0:
            need = B[i]-(answer+A[i])%B[i]
            answer += need
    print(answer)
    return

if __name__ == '__main__':
    main()

Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab = ab[::-1]

z = 0
cnt = 0
for a, b in ab:
  a += z
  if a <= b:
    z += abs(b-a)
  else:
    if a % b != 0:
      z += b - (a % b)
print(z)


Failing test case input:
3
-1 6
6 3
0 9

Expected output:
1


Actual output:
13


Fixed submission (verdict: Accepted):
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab = ab[::-1]

z = 0
cnt = 0
for a, b in ab:
  a += z
  if a % b != 0:
    z += b - (a % b)
print(z)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ans=0
for a,b in ab[::-1]:
    if b!=1:
        ans+=b-(a+ans)%b
print(ans)


Failing test case input:
3
3 4
3 3
9 4

Expected output:
5


Actual output:
9


Fixed submission (verdict: Accepted):

n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ans=0
for a,b in ab[::-1]:
    if (a+ans)%b!=0:
        ans+=b-(a+ans)%b
print(ans)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())

ab=[list(map(int,input().split())) for i in range(n)]

c=[]
ans=ab[n-1][1]-(ab[n-1][0]%ab[n-1][1])

for i in range(n-2,-1,-1):
    ab[i][0]+=ans
    ans+=ab[i][1]-(max(1,ab[i][0]%ab[i][1]))
   
print(ans)

Failing test case input:
7
4 1
4 2
5 12
2 4
5 4
5 8
10 3

Expected output:
8


Actual output:
20


Fixed submission (verdict: Accepted):
n=int(input())

ab=[list(map(int,input().split())) for i in range(n)]

c=[]
ans=0
if ab[n-1][0]%ab[n-1][1]!=0:   
    ans+=ab[n-1][1]-(ab[n-1][0]%ab[n-1][1])

for i in range(n-2,-1,-1):
    ab[i][0]+=ans
    if ab[i][0]%ab[i][1]!=0:
        
        ans+=ab[i][1]-(ab[i][0]%ab[i][1])
    
print(ans)
Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
ls = []
for i in range(n):
    a,b = map(int, input().split())
    ls.append((a,b))
cnt = 0
for i, j in sorted(ls, reverse=True):
    m = (i+cnt) % j
    cnt += 0 if m == 0 else j-m
print(cnt)

Failing test case input:
7
4 1
4 2
5 12
2 4
2 1
5 8
10 3

Expected output:
8


Actual output:
14


Fixed submission (verdict: Accepted):
n = int(input())
ls = []
for i in range(n):
    a,b = map(int, input().split())
    ls.append((a,b))
cnt = 0
for i, j in ls[::-1]:
    m = (i+cnt) % j
    cnt += 0 if m == 0 else (j-m)
print(cnt)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.reverse()
count = 0

for a,b in AB:
  if b == 1:
    continue
  else:
    num_a = a+count
    count += (b-num_a%b)

print(count)

Failing test case input:
3
0 4
3 3
9 6

Expected output:
4


Actual output:
8


Fixed submission (verdict: Accepted):
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.reverse()
count = 0

for a,b in AB:
  a += count
  if a%b != 0:
    count += (b - (a % b))
  else:
    pass
print(count)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
ab = []
for _ in range(n): ab.append([int(x) for x in input().split()])
c = 0
for a, b in ab[::-1]:
    if b == 1: continue
    else: c += b - (a + c) % b
print(c)

Failing test case input:
7
5 2
0 1
3 6
3 3
5 15
1 3
26 6

Expected output:
15


Actual output:
17


Fixed submission (verdict: Accepted):
n = int(input())
ab = []
for _ in range(n): ab.append([int(x) for x in input().split()])
c = 0
for a, b in ab[::-1]:
    if b == 1 or (a + c) % b == 0: continue
    else: c += b - (a + c) % b
print(c)

Problem: p03821
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = []
B = []
count = 0
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)

A.reverse()
B.reverse()

for a,b in zip(A,B):
  if b != 1 and a + count != 0:
    count += b - (a + count) % b
    
print(count)

Failing test case input:
7
0 1
4 2
0 11
2 8
6 1
5 16
24 6

Expected output:
22


Actual output:
24


Fixed submission (verdict: Accepted):
N = int(input())
A = []
B = []
count = 0
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)

A.reverse()
B.reverse()

for a,b in zip(A,B):
  if b != 1 and a + count != 0 and (a + count) % b != 0:
    count += b - (a + count) % b
    
print(count)
Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = []
B = []

for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

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

count = 0
for i in range(N):
    if A[i] % B[i] != 0:
        count += (B[i] - (A[i] + count) % B[i])

print(count)


Failing test case input:
7
0 1
4 2
0 11
2 8
6 1
5 16
24 6

Expected output:
22


Actual output:
14


Fixed submission (verdict: Accepted):
N = int(input())
A = []
B = []

for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

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

count = 0
for i in range(N):
    if (A[i] + count) % B[i] != 0:
        count += (B[i] - (A[i] + count) % B[i])

print(count)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    ab = [list(map(int, input().split())) for i in range(N)]

    a, b = ab[-1]
    count = b - (a%b)
    for i in range(N-2, -1, -1):
        a, b = ab[i]
        tmp = (a + count) % b
        if tmp != 0:
            count += b - tmp
    print(count)

if __name__ == "__main__":
    main()

Failing test case input:
3
2 1
0 1
8 4

Expected output:
0


Actual output:
4


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    ab = [list(map(int, input().split())) for i in range(N)]

    count = 0
    for i in range(N-1, -1, -1):
        a, b = ab[i]
        tmp = (a + count) % b
        if tmp != 0:
            count += b - tmp
    print(count)

if __name__ == "__main__":
    main()

Problem: p03821
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
nums = []
for i in range(N):
    A,B= list(map(int,input().split(" ")))
    nums.append((A,B))

ans = 0
c = 0
nums = nums[::-1]
for temp in nums:
    if temp[1] != 1:
        ad = temp[1] - ( (temp[0] + c) % temp[1])
        ans += ad
        c += ad
print(ans)


Failing test case input:
7
5 1
1 9
5 24
0 6
5 3
9 49
9 3

Expected output:
44


Actual output:
71


Fixed submission (verdict: Accepted):
N = int(input())
nums = []
for i in range(N):
    A,B= list(map(int,input().split(" ")))
    nums.append((A,B))

ans = 0
c = 0
nums = nums[::-1]
for temp in nums:
    if (temp[0] + c) % temp[1] != 0:
        ad = temp[1] - ( (temp[0] + c) % temp[1])
        ans += ad
        c += ad
print(ans)

Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
a.reverse()
b.reverse()

ans = 0
for i in range(n):
    ai = a[i]+ans
    bi = b[i]
    if ai%bi != 0 or ai == 0:
       ans += bi-ai%bi
print(ans)


Failing test case input:
3
-1 6
6 3
0 9

Expected output:
1


Actual output:
13


Fixed submission (verdict: Accepted):
n = int(input())
a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
a.reverse()
b.reverse()

ans = 0
for i in range(n):
    ai = a[i]+ans
    bi = b[i]
    if ai%bi != 0:
       ans += bi-ai%bi
print(ans)
Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):





from sys import stdin,setrecursionlimit

setrecursionlimit(10**6)

n=int(stdin.readline().rstrip())
a=[tuple(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
cnt=0
for i in range(n-1,-1,-1):
    now=(a[i][0]+cnt)%a[i][1]
    print(now)
    cnt+=a[i][1]-now
print(cnt)

Failing test case input:
3
3 4
3 3
9 4

Expected output:
5


Actual output:
1
0
1
9


Fixed submission (verdict: Accepted):





from sys import stdin,setrecursionlimit

setrecursionlimit(10**6)

n=int(stdin.readline().rstrip())
a=[tuple(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
cnt=0
for i in range(n-1,-1,-1):
    now=(a[i][0]+cnt)%a[i][1]
    if now!=0:
        cnt+=a[i][1]-now
print(cnt)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
AB = [0] * N
for n in range(N):
  AB[-1-n] = [int(x) for x in input().strip().split()]
ans = 0
cnt = 0
for (a, b) in AB:
  if b == 1:
    continue
  t = b - ((a + cnt) % b)
  cnt += t
  ans += t
print(ans)

Failing test case input:
7
1 1
4 2
5 12
2 4
6 1
5 8
24 6

Expected output:
8


Actual output:
20


Fixed submission (verdict: Accepted):
N = int(input())
AB = [0] * N
for n in range(N):
  AB[-1-n] = [int(x) for x in input().strip().split()]
ans = 0
cnt = 0
for (a, b) in AB:
  mod = (a + cnt) % b
  if mod:
    t = b - mod
    cnt += t
    ans += t
print(ans)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


N = int(input())
A = []
B = []
for i in range(N):
    s = list(map(int, input().split()))
    A.append(s[0])
    B.append(s[1])

count = 0
for i in reversed(range(N)):
    if A[i] % B[i] == 0:
        continue
    else:
        s = B[i] - (count + A[i]) % B[i]
        count += s

print(count)

Failing test case input:
7
4 1
4 2
5 12
2 4
2 1
5 8
10 3

Expected output:
8


Actual output:
7


Fixed submission (verdict: Accepted):


N = int(input())
A = []
B = []
for i in range(N):
    s = list(map(int, input().split()))
    A.append(s[0])
    B.append(s[1])

count = 0
for i in reversed(range(N)):
    if (count + A[i]) % B[i] == 0:
        continue
    else:
        s = B[i] - (count + A[i]) % B[i]
        count += s

print(count)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = []
for i in range(n):
  a1 = list(map(int, input().split()))
  a.append(a1)
ans = 0
b = 0
for i in a:
  if i[1] != 1:
    c = i[1] - (i[0]+b) % i[1]
    print(c,b)
    ans += c
    b += c
print(ans)

Failing test case input:
7
4 1
4 1
6 12
2 4
6 3
5 8
9 7

Expected output:
18


Actual output:
6 0
4 6
2 10
7 12
7 19
26


Fixed submission (verdict: Accepted):
n = int(input())
a = []
for i in range(n):
  a1 = list(map(int, input().split()))
  a.append(a1)
a.reverse()
ans = 0
b = 0
for i in a:
  if i[1] != 1:
    c = i[1] - (i[0]+b) % i[1]
    if c == i[1]:
      c = 0
    ans += c
    b += c
print(ans)
Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):





from sys import stdin,setrecursionlimit

setrecursionlimit(10**6)

n=int(stdin.readline().rstrip())
a=[tuple(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
cnt=0
for i in range(n-1,-1,-1):
    now=(a[i][0]+cnt)%a[i][1]
    cnt+=a[i][1]-now
print(cnt)

Failing test case input:
3
3 5
2 2
18 4

Expected output:
2


Actual output:
7


Fixed submission (verdict: Accepted):





from sys import stdin,setrecursionlimit

setrecursionlimit(10**6)

n=int(stdin.readline().rstrip())
a=[tuple(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
cnt=0
for i in range(n-1,-1,-1):
    now=(a[i][0]+cnt)%a[i][1]
    if now!=0:
        cnt+=a[i][1]-now
print(cnt)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
abl = [list(map(int,input().split())) for nesya in range(n)]
c = 0
for ab in abl:
  a = ab[0] + c
  b = ab[1]
  if a%b == 0:
    continue
  c += (b - a%b)
print(c)

Failing test case input:
3
2 4
0 1
8 4

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
abl = [list(map(int,input().split())) for nesya in range(n)]
c = 0
abl = abl[::-1]
for ab in abl:
  a = ab[0] + c
  b = ab[1]
  if a%b == 0:
    continue
  c += (b - a%b)
print(c)

Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()

bt = []
ans = 0
diff = []

for i in range(n):
    a, b = inintm()
    if b == 1:
        diff.append(-1)
    elif b >= a:
        diff.append(b-a)
    else:
        diff.append(b - (a % b))
    bt.append([a, b])

for i in range(n)[::-1]:
    if diff[i] == -1:
        continue
    else:
        ans += bt[i][1] - ((bt[i][0]+ans) % bt[i][1])

print(ans)


Failing test case input:
3
3 4
3 3
9 4

Expected output:
5


Actual output:
9


Fixed submission (verdict: Accepted):
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()

bt = []
ans = 0

for i in range(n):
    a, b = inintm()
    bt.append([a, b])

for i in range(n)[::-1]:
    if (bt[i][0]+ans) % bt[i][1] != 0:
        ans += bt[i][1] - ((bt[i][0]+ans) % bt[i][1])

print(ans)
Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7



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

A.reverse()
B.reverse()

inc = 0
for i in range(N):
    A[i] += inc

    if B[i] == 1:
        continue

    
    diff = B[i] - A[i]%B[i]
    inc += diff

print(inc)

Failing test case input:
7
4 1
4 2
5 12
2 4
5 4
5 8
10 3

Expected output:
8


Actual output:
20


Fixed submission (verdict: Accepted):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7



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

A.reverse()
B.reverse()

inc = 0
for i in range(N):
    A[i] += inc

    
    x = A[i]%B[i]
    if x == 0:
        continue

    diff = B[i] - x
    inc += diff

print(inc)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

push = 0
for i in range(N):
    if (A[N-i-1] + push) % B[N-i-1] != 0:
        push += abs(B[N-i-1] - ((push + A[N-i-1]) % B[N-i-1]))
        print(A[N-i-1] , B[N-i-1],push)
print(push)


Failing test case input:
7
5 1
4 2
5 12
2 4
10 1
1 8
17 6

Expected output:
20


Actual output:
17 6 1
1 8 7
2 4 10
5 12 19
4 2 20
20


Fixed submission (verdict: Accepted):

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

push = 0
for i in range(N):
    if (A[N-i-1] + push) % B[N-i-1] != 0:
        push += abs(B[N-i-1] - ((push + A[N-i-1]) % B[N-i-1]))
print(push)

Problem: p03821
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
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):
    A[i] += ans
    if A[i] == 0:
        ans += B[i]
    else:
        ans += B[i] - (A[i] % B[i]) if A[i] % B[i] != 0 else 0
    A[i] += ans

print(ans)


Failing test case input:
3
2 1
0 1
8 4

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
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):
    A[i] += ans
    ans += B[i] - (A[i] % B[i]) if A[i] % B[i] != 0 else 0

print(ans)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.reverse()
count = 0

for a,b in AB:
  num_a = a+count
  if num_a%b != 0 or num_a == 0:
    count += (b-num_a%b)
print(count)

Failing test case input:
3
-1 6
6 3
0 9

Expected output:
1


Actual output:
13


Fixed submission (verdict: Accepted):
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.reverse()
count = 0

for a,b in AB:
  a += count
  if a%b != 0:
    count += (b - (a % b))
  else:
    pass
print(count)
Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
AB = [0] * N
for n in range(N):
  AB[-1-n] = [int(x) for x in input().strip().split()]
ans = 0
cnt = 0
for (a, b) in AB:
  if b == 1:
    if a + cnt == 0:
      cnt += 1
      ans += 1
  else:
    t = b - ((a + cnt) % b)
    cnt += t
    ans += t
print(ans)


Failing test case input:
7
4 1
4 2
5 12
2 4
6 1
10 8
2 6

Expected output:
8


Actual output:
20


Fixed submission (verdict: Accepted):
N = int(input())
AB = [0] * N
for n in range(N):
  AB[-1-n] = [int(x) for x in input().strip().split()]
ans = 0
cnt = 0
for (a, b) in AB:
  mod = (a + cnt) % b
  if mod:
    t = b - mod
    cnt += t
    ans += t
print(ans)

Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
ab = [map(int, input().split()) for _ in range(n)]
a, b = [list(i) for i in zip(*ab)]
 
a.reverse()
b.reverse()
ans = 0
num = 0
ruisekiwa = 0

for j in range(n):
  a[j] += ruisekiwa
  syou = a[j]
  if b[j] == 1:
    num = 0
  else:
    num = b[j]*(syou+1) - a[j]
  ruisekiwa += num
  ans += num

print(ans)

Failing test case input:
7
5 1
4 2
5 12
2 4
10 1
1 8
17 6

Expected output:
20


Actual output:
71708


Fixed submission (verdict: Accepted):
n = int(input())
ab = [map(int, input().split()) for _ in range(n)]
a, b = [list(i) for i in zip(*ab)]
 
a.reverse()
b.reverse()
ans = 0

for j in range(n):
  a[j] += ans
  if a[j] % b[j] != 0:
    ans += b[j] -(a[j] % b[j])

print(ans)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
AB = [list(map(int, input().split())) for i in range(N)][::-1]

ans = 0
for a, b in AB:
  ans += b - (a + ans) % b

print(ans)

Failing test case input:
3
3 5
2 9
9 2

Expected output:
7


Actual output:
12


Fixed submission (verdict: Accepted):
N = int(input())
AB = [list(map(int, input().split())) for i in range(N)][::-1]

ans = 0
for a, b in AB:
  d = (a + ans) % b
  if d: ans += b - d

print(ans)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[]
rn=0
cnt=0
for i in range(n):
    b,c=map(int,input().split())
    a.append([b,c])
a=a[::-1]
print(a)   
for i in range(n):
    b,c=a[i]
    b+=cnt
    cnt+=(c-b%c)%c
print(cnt)


Failing test case input:
7
4 1
1 1
5 12
2 4
3 3
5 8
10 6

Expected output:
7


Actual output:
[[10, 6], [5, 8], [3, 3], [2, 4], [5, 12], [1, 1], [4, 1]]
7


Fixed submission (verdict: Accepted):
n=int(input())
a=[]
rn=0
cnt=0
for i in range(n):
    b,c=map(int,input().split())
    a.append([b,c])
a=a[::-1]
  
for i in range(n):
    b,c=a[i]
    b+=cnt
    cnt+=(c-b%c)%c
print(cnt)
Problem: p03821
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
ab=[map(int,input().split()) for _ in range(n)]
a,b = [list(i) for i in zip(*ab)]

s=0
for i in range(n):
    if a[n-1-i]%b[n-1-i]==0:
        continue
    else:
        c=b[n-1-i]-((a[n-1-i]+s)%b[n-1-i])
        s+=c
print(s)

Failing test case input:
7
4 1
4 1
8 12
2 4
6 4
5 8
10 7

Expected output:
16


Actual output:
28


Fixed submission (verdict: Accepted):
n=int(input())
ab=[map(int,input().split()) for _ in range(n)]
a,b = [list(i) for i in zip(*ab)]

s=0
for i in range(n):
    if (a[n-1-i]+s)%b[n-1-i]==0:
        continue
    else:
        c=b[n-1-i]-((a[n-1-i]+s)%b[n-1-i])
        s+=c
print(s)

Problem: p03821
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
ma = []
for _ in range(n):
    tmp = list(map(int,input().split()))
    ma.append(tmp)
ma.reverse()

count = 0
for m in ma:
    a = m[0]+count
    b = m[1]
    if a == 0:
        count += b
        continue
    if a%b != 0:
        amari = a%b
        addition = b - amari
        count += addition
print(count)

Failing test case input:
3
2 1
0 1
8 4

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
ma = []
for _ in range(n):
    tmp = list(map(int,input().split()))
    ma.append(tmp)
ma.reverse()

count = 0
for m in ma:
    a = m[0]+count
    b = m[1]
    if a == 0:
        
        continue
    if a%b != 0:
        amari = a%b
        addition = b - amari
        count += addition
print(count)

Problem: p03821
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
a = a[::-1]
b = b[::-1]

ans = 0
tmp = 0
for i in range(n):
    if b[i]==1:
        continue
    else:
        t = (a[i]+ans) % b[i]
        ans += b[i]-t

print(ans)

Failing test case input:
7
4 1
4 2
5 12
4 4
5 4
5 8
10 3

Expected output:
8


Actual output:
20


Fixed submission (verdict: Accepted):
n = int(input())
a = []
b = []
for i in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
a = a[::-1]
b = b[::-1]

ans = 0
for i in range(n):
    t = (a[i] + ans) % b[i]
    if t != 0:
        ans += b[i]-t

print(ans)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.reverse()
count = 0

for a,b in AB:
  num_a = a + count
  if num_a%b != 0 or num_a == 0:
    count += (b - (num_a % b))
  else:
    pass
print(count)

Failing test case input:
3
-1 6
6 3
0 9

Expected output:
1


Actual output:
13


Fixed submission (verdict: Accepted):
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
AB.reverse()
count = 0

for a,b in AB:
  a += count
  if a%b != 0:
    count += (b - (a % b))
  else:
    pass
print(count)