ZhenlongDai/ACPR huggingface dataset:
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
    if a!=0:
        m = b - (a % b) if b != 1 else 0
    else:
        m = 0
    ans += m
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):
    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())
AB = [list(map(int,input().split())) for i in range(n)]
ans = 0
for i in range(n-1,-1,-1):
    a = AB[i][0]
    b = AB[i][1]
    if b == 1:
        tmp = 0
    elif b >= a:
        tmp = b - a
    else:
        tmp = b - ( a % b )
    AB =[ [AB[k][0] + tmp, AB[k][1]] for k in range(n) ]
    ans += tmp
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 = []
B = []
for i 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 = A[i] + ans
    b = B[i]
    
    if a % b == 0:
        tmp = 0
    else:
        tmp = (a 
    ans += tmp
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):
    add += tmp
    if (arr[i][0]+add) % arr[i][1] == 0:
        continue
    tmp = arr[i][1] - ((arr[i][0]+add) % arr[i][1])
    ans += tmp
print(ans)

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())
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):
N = int(input())
A = []
B = []
ans = 0

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

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

print(ans)

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

Expected output:
8


Actual output:
19


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

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

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

print(ans)
Problem: p03821
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ans = 0

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

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

Expected output:
38


Actual output:
0
37
38


Fixed submission (verdict: Accepted):
n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
ans = 0

for i in range(n-1,-1,-1):
    ans += (ab[i][1]-(ab[i][0]+ans)%ab[i][1])%ab[i][1]
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]:
  a[i]+=ans
  ans+=a[i]%b[i]
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:
8


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 = [list(map(int, input().split())) for _i in range(n)]

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

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

Expected output:
34


Actual output:
30


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

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

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

while(n > 0):
    count += (a[n-1]+count)%b[n-1]
    n-=1

print(count)

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

Expected output:
7


Actual output:
6


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

while(n > 0):
    n -= 1
    count += (b[n] if (a[n]+count)%b[n]!=0 else 0)-(a[n]+count)%b[n]

print(count)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import deque
n=int(input())
A=deque()
B=deque()
ans=0
for i in range(n):
    a,b=map(int,input().split())
    A.appendleft(a)
    B.appendleft(b)
for i in range(n):
    k=B[i]-(A[i]%B[i])
    ans+=k
    for j in range(i,n):
        A[j]+=k
print(ans)

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

Expected output:
19


Actual output:
21


Fixed submission (verdict: Accepted):
from collections import deque
n=int(input())
A=deque()
B=deque()
ans=0
for i in range(n):
    a,b=map(int,input().split())
    A.appendleft(a)
    B.appendleft(b)
while A:
    A[0]+=ans
    if A[0]%B[0]!=0:
        k=B[0]-(A[0]%B[0])
        ans+=k
    A.popleft()
    B.popleft()

print(ans)
Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a=[]
for i in range(n):
  x,y=map(int,input().split())
  a.append([x,y])
ans=0
a=a[::-1]
for i,j in a:
  ans+=j- (i+ans)%j if (i+ans)%j else j
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:
21


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

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):
        if (answer+A[i])%B[i] > 0:
            need = B[i]-(answer+A[i])%B[i]
            answer += need
    print(answer)
    return

if __name__ == '__main__':
    main()


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

Expected output:
21


Actual output:
0


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.4.3), verdict: Wrong Answer):
def main():
    
    N = int(input())
    AB = [
        list(map(int, input().split()))
        for _ in range(N)
    ]

    ans = 0
    for a, b in AB[::-1]:
        c = (a + ans) % b
        if a + ans > b and c == 0:
            pass
        else:
            d = b - c
            
            ans += d

    print(ans)

if __name__ == '__main__':
    main()


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

Expected output:
0


Actual output:
1


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

    ans = 0
    for a, b in AB[::-1]:
        c = (a + ans) % b
        
        if c == 0:
            pass
        else:
            d = b - c
            
            ans += d

    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):
    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):
    if a[i]+ans>b[i]:
        if ((a[i]+ans)%b[i])!=0:
            ans+=b[i]-((a[i]+ans)%b[i])
    else:
        ans+=b[i]-(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.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 A[i]!=0 and B[i]!=1:
        A[i]=(A[i]+ans)%B[i]
        ans+=B[i]-A[i]

print(ans)

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

Expected output:
7


Actual output:
19


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 (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = [0]
B = [1]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
k = 0 
for i in range(N-1,-1,-1):
    A[i-1] += k
    if A[i] % B[i] == 0 :
        continue
    else :
        c = (B[i] - A[i] % B[i])
        k += c

print(k)

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

Expected output:
9


Actual output:
7


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)
k = 0 
for i in range(N-1,-1,-1):
    A[i] += k
    if A[i] % B[i] == 0 :
        pass
    else :
        c = (B[i] - A[i] % B[i])
        k += c

print(k)

Problem: p03821
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = [0]
B = [1]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
k = 0 
for i in range(N-1,-1,-1):
    A[i] += k
    if A[i] % B[i] == 0 :
        continue
    else :
        c = (B[i] - A[i] % B[i])
        k += c

print(k)

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

Expected output:
19


Actual output:
7


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)
k = 0 
for i in range(N-1,-1,-1):
    A[i] += k
    if A[i] % B[i] == 0 :
        pass
    else :
        c = (B[i] - A[i] % B[i])
        k += c

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

while(n > 0):
    n -= 1
    count += (b[n] if b[n]!=1 else 0)-(a[n]+count+b[n])%b[n]

print(count)

Failing test case input:
7
4 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 = [0]*n,[0]*n
count = 0
for i in range(n):
    a[i],b[i] = map(int,input().split())

while(n > 0):
    n -= 1
    count += (b[n] if (a[n]+count)%b[n]!=0 else 0)-(a[n]+count)%b[n]

print(count)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)][::-1]
ans = 0
for a, b in ab:
    a += ans
    if b != 1:
        ans += b - a % b
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())
ab = [tuple(map(int, input().split())) for _ in range(n)][::-1]
ans = 0
for a, b in ab:
    a += ans
    ans += (b - a) % b
print(ans)

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
for i in range(n):
    if b[i]==1:
        continue
    else:
        t = (a[i]+ans) % b[i]
        ans += abs(b[i]-t)

print(ans)

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

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 = []
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
    else:
        if b>1:
            res += b-a%b
print(res)


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

Expected output:
2


Actual output:
6


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):
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 (a + cnt) % b == 0:
    if a + cnt == 0:
      cnt += b
      ans += b
  else:
    t = b - ((a + cnt) % b)
    cnt += t
    ans += t
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())
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())
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):
    if b[i]==1:
        continue
    else:
        t = abs((a[i]+ans) % b[i])
        ans += b[i]-t

print(ans)

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

Expected output:
7


Actual output:
12


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):
import math


def solve(N, ABs):
    count = 0
    for (a, b) in reversed(ABs):
        k = (a + count)
        if k > 0:
            n = b * math.ceil(k / b)
        else:
            n = b
        count += n - k
    return count


if __name__ == "__main__":
    N = int(input())
    ABs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, ABs))


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

Expected output:
1


Actual output:
13


Fixed submission (verdict: Accepted):
import math


def solve(N, ABs):
    count = 0
    for (a, b) in reversed(ABs):
        k = (a + count)
        n = b * math.ceil(k / b)
        count += n - k
    return count

if __name__ == "__main__":
    N = int(input())
    ABs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, ABs))
Problem: p03821
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):


import sys



def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


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

    cnt = 0
    for a, b in zip(A[::-1], B[::-1]):
        if a + cnt == 0 and b > 0:
            cnt += b
            continue
        tmp = (a + cnt) % b
        if tmp != 0:
            cnt += b - tmp
    print(cnt)


if __name__ == "__main__":
    main()


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

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):


import sys



def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


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

    cnt = 0
    for a, b in zip(A[::-1], B[::-1]):
        a += cnt
        cnt += (-a) % b
    print(cnt)


if __name__ == "__main__":
    main()

Problem: p03821
Buggy submission (PyPy3 (2.4.0), 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)
k = 0 
for i in range(N-1,-1,-1):
    if A[i] % B[i] == 0 :
        continue
    else :
        c = (B[i] - A[i] % B[i])
        k += c
        if i != 0 :
            A[i-1] += k

print(k)

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

Expected output:
5


Actual output:
4


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)
k = 0 
for i in range(N-1,-1,-1):
    A[i] += k
    if A[i] % B[i] == 0 :
        pass
    else :
        c = (B[i] - A[i] % B[i])
        k += c

print(k)

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:
    if A[j] != 0:
      continue
  ans += B[j] - (A[j]+ans)%B[j]  
  
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())
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 (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) % b
  else:
    pb += b - a
print(pb)

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

Expected output:
1


Actual output:
13


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

A.reverse()
B.reverse()

ans = 0
before = 0

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


print(ans)

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):
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
before = 0

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

print(ans)

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 == 0:
      ans += 1
  else:
    t = b - ((a + cnt) % b)
    cnt += t
    ans += t
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:
25


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 = []
out = 0
for n in range(N):
    line = [int(i) for i in input().split()]
    A.append(line[0])
    B.append(line[1])
for index in range(0, N)[::-1]:
  A[index] += out
  if B[index] != 1:
    out += B[index] - (A[index] % B[index])
print(out)


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

Expected output:
7


Actual output:
19


Fixed submission (verdict: Accepted):
N = int(input())
A = []
B = []
out = 0
for n in range(N):
    line = [int(i) for i in input().split()]
    A.append(line[0])
    B.append(line[1])
for index in range(0, N)[::-1]:
  A[index] += out
  mod = A[index] % B[index]
  if mod:
    out += B[index] - mod 
print(out)
Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    n = int(input())
    A = []
    B = []
    for _ in range(n):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    btn_cnt = 0
    for i in range(n - 1, -1, -1):
        a, b = A[i], B[i]
        if b == 1:
            continue
        else:
            
            need = b - (a + btn_cnt) % b
            btn_cnt += need
            

    print(btn_cnt)


if __name__ == "__main__":
    main()


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

Expected output:
8


Actual output:
20


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

    btn_cnt = 0
    for i in range(n - 1, -1, -1):
        a, b = A[i] + btn_cnt, B[i]
        if b == 1 or a % b == 0:
            continue
        else:
            
            need = b - a % b
            btn_cnt += need
            

    print(btn_cnt)


if __name__ == "__main__":
    main()

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)
cnt = 0
for i in range(n-1, -1, -1):
    t = (A[i]+cnt) % B[i]
    if B[i]!=1:
        cnt += (B[i]-t)

print(cnt)

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

Expected output:
7


Actual output:
19


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)
cnt = 0
for i in range(n-1, -1, -1):
    t = (A[i]+cnt) % B[i]
    if t!=0:
        cnt += (B[i]-t)

print(cnt)

Problem: p03821
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import accumulate
n = int(input())
lis = []
al=[]
bl=[]
for i in range(n):
    a,b=map(int, input().split())
    c=b-a%b
    al.append(a)
    bl.append(b)
ans=0
for i in range(n-1, -1, -1):
    if bl[i]==1:
        continue
    c=bl[i]-((al[i]+ans)%bl[i])
    ans+=c

print(ans)


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

Expected output:
8


Actual output:
20


Fixed submission (verdict: Accepted):
from itertools import accumulate
n = int(input())
lis = []
al=[]
bl=[]
for i in range(n):
    a,b=map(int, input().split())
    c=b-a%b
    al.append(a)
    bl.append(b)
ans=0
for i in range(n-1, -1, -1):
    if bl[i]==1:
        continue
    if (al[i]+ans)%bl[i]!=0:
        c=bl[i]-((al[i]+ans)%bl[i])
        ans+=c

print(ans)
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 b == 1:
        continue
    
    a += c
    
    c += b-(a%b)
print(c)

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())
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.8.2), verdict: Wrong Answer):
n = int(input())
a = []
b = []

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


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

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

Expected output:
26


Actual output:
31


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

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

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

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

ans = 0
for i in range(N-1, -1, -1):
  j = 1
  while j*B[i] - (A[i] + ans) < 0:
    j += 1
  ans += j*B[i] - (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 = [0]*N, [0]*N
for i in range(N):
  A[i], B[i] = map(int, input().split())

ans = 0
for i in range(N-1, -1, -1):
  ans += (B[i] - ((A[i] + ans) % B[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):
    a_e, b_e = map(int, input().split())
    a_e %= b_e
    a.append(a_e)
    b.append(b_e)

ans = 0

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

if a[0] != 0:
    ans += (b[0] - a[0]) % b[0] 

print(ans)

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

Expected output:
2


Actual output:
4


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

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

print(cnt)

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

Expected output:
8


Actual output:
2
1
4
1
3
1
1
8


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]

cnt = 0
for i in range(n):
	if (cnt + A[i]) % B[i] == 0:
		continue
	else:
		cnt += B[i] - (cnt + A[i]) % B[i]

print(cnt)

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

for _ in range(n):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)
  
for _ in range(n):
  a = A.pop(-1)
  b = B.pop(-1)
  a += ans
  ans += a%b
print(ans)

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

Expected output:
7


Actual output:
2


Fixed submission (verdict: Accepted):
n = int(input())
A = []
B = []
ans = 0
import math

for _ in range(n):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)
  
for _ in range(n):
  a = A.pop(-1)
  b = B.pop(-1)
  a += ans
  ans += math.ceil(a/b)*b - a

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)]
ans = 0
for i in range(n-1,-1,-1):
    a = AB[i][0]
    b = AB[i][1]
    if b == 1:
        tmp = 0
    else:
        tmp = b - ( a % b )
    AB =[ [AB[k][0] + tmp, AB[k][1]] for k in range(n) ]
    ans += tmp
print(ans)

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

Expected output:
2


Actual output:
6


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)
ans = 0
for i in range(n-1,-1,-1):
    a = A[i] + ans
    b = B[i]
    
    if a % b == 0:
        tmp = 0
    else:
        tmp = (a 
    ans += tmp
print(ans)

Problem: p03821
Buggy submission (Python (3.4.3), 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())
    
rA = A[::-1]
rB = B[::-1]
cnt = 0
for i in range(N):
    rA[i] += cnt
    if(rA[i] > rB[i]):
        if(rA[i]%rB[i] != 0):
            cnt += rB[i]-(rA[i]%rB[i])
    else:
        cnt += rB[i]-rA[i]

print(cnt)

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 = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())
    
rA = A[::-1]
rB = B[::-1]
cnt = 0
for i in range(N):
    rA[i] += cnt
    if(rA[i]%rB[i] != 0):
        cnt += rB[i]-(rA[i]%rB[i])

print(cnt)
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)
ans = 0
a = a[::-1]
b = b[::-1]
for i in range(n):
  if a[i] % b[i] == 0:
    next
  else:
    ans += b[i] - ((a[i]+ ans) % b[i])
print(ans)

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

Expected output:
26


Actual output:
25


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)
ans = 0
a = a[::-1]
b = b[::-1]
for i in range(n):
  if (a[i] + ans) % b[i] == 0:
    next
  else:
    ans += b[i] - ((a[i]+ ans) % b[i])
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
    if ab[i][0]%ab[i][1]!=0:
        
        ans+=ab[i][1]-(ab[i][0]%ab[i][1])
    
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())

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())
abl = []
for _ in range(n):
   a,b = map(int,input().split())
   abl.append((a,b))

abl = reversed(abl)

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

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:
30


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

abl = reversed(abl)

ans = 0
for a,b in abl:
    a += ans
    if a % b != 0:
        ans += b - (a % b)

print(ans)

Problem: p03821
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a,b = [],[]
ans = 0
for i in range(n):
    A,B = map(int,input().split())
    a.append(A)
    b.append(B)
def solve(x,y):
    cur = y
    while x>y:
        y += cur
    return y-x
for i in range(n-1,-1,-1):
    a[i] += ans
    ans += solve(a[i],b[i])


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 = [],[]
ans = 0
for i in range(n):
    A,B = map(int,input().split())
    a.append(A)
    b.append(B)
def solve(x,y):
    z = -(-x
    return y*z-x
for i in range(n-1,-1,-1):
    a[i] += ans
    ans += solve(a[i],b[i])


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

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

total = 0
for a, b in pairs:
    a_dash = a + total
    if a_dash == 0:
        target = b
    else:
        target = a_dash 
        if a_dash % b > 0:
            target += b
    total += target - a_dash

print(total)

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

Expected output:
20


Actual output:
26


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

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

total = 0
for a, b in pairs:
    a_dash = a + total
    mod = a_dash % b
    if mod > 0:
        total += b - mod
print(total)

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

while(n > 0):
    n -= 1
    count += (b[n] if b[n]!=1 else 0)-(a[n]+count)%b[n]

print(count)

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())
a, b = [0]*n,[0]*n
count = 0
for i in range(n):
    a[i],b[i] = map(int,input().split())

while(n > 0):
    n -= 1
    count += (b[n] if (a[n]+count)%b[n]!=0 else 0)-(a[n]+count)%b[n]

print(count)

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

if __name__ == "__main__":
    N = int(input())
    A = N*[0]
    B = N*[0]
    for i in range(N):
        A[i],B[i] = list(map(int,input().split()))

    buttons = 0

    for i in range(N-1,-1,-1):
        buttons += B[i] - (A[i]+buttons) % B[i]

    print(buttons)



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

Expected output:
20


Actual output:
21


Fixed submission (verdict: Accepted):

if __name__ == "__main__":
    N = int(input())
    A = N*[0]
    B = N*[0]
    for i in range(N):
        A[i],B[i] = list(map(int,input().split()))

    buttons = 0

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

    print(buttons)

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

N = int(input())
total = 0
A = [None] * N
B = [None] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
	
for i in range(N-1,-1,-1):
	a = A[i] % B[i]
	if a == 0:
		pass
	else:
		total = total + B[i] - a
		for j in range (i):
			A[i] = A[i] + B[i] - a


print (total)
	


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

Expected output:
24


Actual output:
30


Fixed submission (verdict: Accepted):

N = int(input())
total = 0
A = [None] * N
B = [None] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
	
for i in range(N-1,-1,-1):
	b = A[i] + total
	a = b % B[i]
	if a == 0:
		pass
	else:
		total = total + B[i] - a


print (total)
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 b[i] == 1:
        continue
    ans += b[i] - ((a[i]+ans) % b[i])
print(ans)


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

Expected output:
0


Actual output:
4


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 _ in range(N):
    a,b = [int(i) for i in input().split()]
    A.append(a)
    B.append(b)

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

print(ans-B.count(1))


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

Expected output:
3


Actual output:
6


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

ans = 0
for i in range(1,N+1):
    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):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1,-1,-1):
    a = A[i]
    b = B[i]
    
    if b == 1:
        tmp = 0
    else:
        tmp = b - ( a % b )
    A = [A[i] + tmp for i in range(n)]
    ans += tmp
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())
A = []
B = []
for i 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 = A[i] + ans
    b = B[i]
    
    if a % b == 0:
        tmp = 0
    else:
        tmp = (a 
    ans += tmp
print(ans)

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

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

Expected output:
7


Actual output:
11


Fixed submission (verdict: Accepted):
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
a=a[::-1]
p=0
for i in range(n):
  b=(a[i][0]+p)%a[i][1]
  if b!=0:
    p+=a[i][1]-b
print(p)
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(count)

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

Expected output:
5


Actual output:
4


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.4.3), verdict: Wrong Answer):
n = int(input())
l = [[int(i) for i in input().split()] for _ in range(n)]

ans = 0
p = 0
for i in l[::-1]:
    i[0] += p
    ans += i[1] - (i[0] % i[1]) if i[1] > 1 else 0
    p += i[1] - (i[0] % i[1]) if i[1] > 1 else 0
    
print(ans)


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

Expected output:
7


Actual output:
19


Fixed submission (verdict: Accepted):
n = int(input())
l = [[int(i) for i in input().split()] for _ in range(n)]

ans = 0
p = 0
for i in l[::-1]:
    i[0] += p
    ans += i[1] - (i[0] % i[1]) if i[0] % i[1] else 0
    p += i[1] - (i[0] % i[1]) if i[0] % i[1] else 0
    
print(ans)

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 
    ans += m
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())
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())

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

total = 0
for a, b in pairs:
    a_dash = a + total
    if a_dash == 0:
        total += b
    else:
        mod = a_dash % b
        if mod > 0:
            total += b - mod
print(total)

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

Expected output:
1


Actual output:
13


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

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

total = 0
for a, b in pairs:
    a_dash = a + total
    mod = a_dash % b
    if mod > 0:
        total += b - mod
print(total)
Problem: p02791
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import deque

N = int(input())
P = list(map(int,input().split()))

mx = P[0]
mn = mx
count = 0

cut = list(filter(lambda x:mx >= x,P))
ans = deque()

for a in cut:
    if a == 1:
        break
    if mn >= a:
        mn = a
    else:
        cut.pop(cut.index(a))
print(len(cut))

Failing test case input:
5
4 2 5 1 4

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
from collections import deque

N = int(input())
P = list(map(int,input().split()))

mx = P[0]
mn = mx
count = 0

cut = deque(list(filter(lambda x:mx >= x,P)))
ans = deque()

ln = len(cut)

for a in range(ln):
    num = cut.popleft()
    if mx >= num:
        mx = num
        count += 1
    else:
        continue

print(count)

Problem: p02791
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = input()
p = list(map(int, input().split( )))
c = 1
m = p[0]
for a in p[1:]:
    if m - a > 0:
        c += 1
    m = max(m, a)
print(c)


Failing test case input:
6
1 5 9 3 5 6

Expected output:
1


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
p = list(map(int, input().split( )))
c = 1
m = p[0]
for a in p[1:]:
    m = min(m, a)
    if m == a:
        c += 1
print(c)

Problem: p02791
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = list(map(int,input().split()))
cnt = 1
for i in range(n-1):
    if p[i] - p[i+1] >=0:
        cnt +=1
print(cnt)
        


Failing test case input:
6
1 2 0 6 5 15

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n = int(input())
p = list(map(int,input().split()))
min_p = p[0]
cnt=1
for i in range(1,n):
    if p[i] <= min_p:
        min_p = p[i]
        cnt +=1
print(cnt)

Problem: p02791
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = list(map(int,input().split()))
P_min = [2*(10**5)]
for i in range(N-1):
    P_min.append(min(P_min[i],P[i]))
print(P_min)
ans = 0
for i in range(N):
    if P_min[i] >= P[i]:
        ans += 1
print(ans)


Failing test case input:
6
1 2 3 6 9 9

Expected output:
1


Actual output:
[200000, 1, 1, 1, 1, 1]
1


Fixed submission (verdict: Accepted):
N = int(input())
P = list(map(int,input().split()))
P_min = [2*(10**5)]
for i in range(N-1):
    P_min.append(min(P_min[i],P[i]))
ans = 0
for i in range(N):
    if P_min[i] >= P[i]:
        ans += 1
print(ans)

Problem: p02791
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
P = list(map(int, input().split()))

count = 0
m = N
for p in reversed(P):
  m = min(m, p)
  if p <= m:
    count += 1
print(count)

Failing test case input:
6
1 5 3 4 5 6

Expected output:
1


Actual output:
5


Fixed submission (verdict: Accepted):
N = int(input())
P = list(map(int, input().split()))

count = 0
m = N
for p in P:
  m = min(m, p)
  if p <= m:
    count += 1
print(count)
Problem: p02791
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
p=list(map(int,input().split()))
cnt=1
for i in range(1,n):
	if p[i-1]>p[i]:
		cnt+=1
print(cnt)


Failing test case input:
6
0 3 2 3 3 27

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n=int(input())
p=list(map(int,input().split()))
a=p[0]
cnt=1
for i in range(1,n):
	if p[i]<a:
		cnt+=1
		a=p[i]
print(cnt)

Problem: p02791
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
p = list(map(int, input().split()))

cnt = 1
min_p = p[0]

if n == 1:
    print(n)
else:
    for i in range(1, n):
        if p[i] > min_p:
            min_p = p[i]
            cnt += 1
    print(cnt)


Failing test case input:
6
1 2 0 6 5 9

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
p = list(map(int, input().split()))

cnt = 1
min_p = p[0]

if n == 1:
    print(n)
else:
    for i in range(1, n):
        if p[i] < min_p:
            min_p = p[i]
            cnt += 1
    print(cnt)

Problem: p02791
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
l=list(map(int,input().split()))
c=1
b=l[0]
for p in l[1:]:
    if b>=p:
        c+=1
    b=p
print(c)


Failing test case input:
6
1 4 3 4 5 6

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n=int(input())
ps=list(map(int,input().split()))
cnt=0
max_=ps[0]
min_=ps[0]
for p in ps:
    if min_>=p:
        cnt+=1
        min_=p
print(cnt)

Problem: p02791
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
import time
import math
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()


N = int(input())
P = inpl()
P.reverse()
mx = 0
ans = 0
for i in P:
	if i <= mx:
		ans += 1
	mx = max(mx, i)
print(ans)


ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Failing test case input:
6
0 4 2 3 5 27

Expected output:
1


Actual output:
5


Fixed submission (verdict: Accepted):
import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()


N = int(input())
P = inpl()
mn = 1001001001
ans = 0
for i in P:
    mn = min(mn, i)
    if i == mn:
        ans += 1
print(ans)


ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)

Problem: p02791
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
lst = list(map(int,input().split()))

cnt = 1
m = lst[0]

for i in lst:
  if i <= m:
    cnt +=1
    m = i
print(cnt)

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

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
lst = list(map(int,input().split()))
 
cnt = 0
m = lst[0]
 
for i in lst:
  if i <= m:
    cnt +=1
    m = i
print(cnt)