Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
ax = []
bx = []
for _ in xrange(n):
    a,b = map(int,raw_input().split())
    ax.append(a)
    bx.append(b)

ax = ax[::-1]
bx = bx[::-1]
cnt = 0
for i in xrange(n):
    if (ax[0] + cnt) % bx[0] !=0:
        k = bx[0] - ((ax[0] + cnt) % bx[0])
        cnt += k
        ax.pop(0)
        bx.pop(0)
print cnt


Fixed submission:
n = int(raw_input())
ax = []
bx = []
for _ in xrange(n):
    a,b = map(int,raw_input().split())
    ax.append(a)
    bx.append(b)

ax = ax[::-1]
bx = bx[::-1]
cnt = 0
for i in xrange(n):
    if (ax[i] + cnt) % bx[i] !=0:
        k = bx[i] - ((ax[i] + cnt) % bx[i])
        cnt += k

print cnt

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
ax = []
bx = []
for _ in xrange(n):
    a,b = map(int,raw_input().split())
    ax.append(a)
    bx.append(b)

ax = ax[::-1]
bx = bx[::-1]
cnt = 0
for i in xrange(n):
    if ax[0] % bx[0] !=0:
        k = bx[0] - (ax[0] % bx[0])
        cnt += k
        ax = map(lambda x:x+k,ax)
        ax.pop(0)
        bx.pop(0)
print cnt


Fixed submission:
n = int(raw_input())
ax = []
bx = []
for _ in xrange(n):
    a,b = map(int,raw_input().split())
    ax.append(a)
    bx.append(b)

ax = ax[::-1]
bx = bx[::-1]
cnt = 0
for i in xrange(n):
    if (ax[i] + cnt) % bx[i] !=0:
        k = bx[i] - ((ax[i] + cnt) % bx[i])
        cnt += k

print cnt

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
ax = []
bx = []
for _ in xrange(n):
    a,b = map(int,raw_input().split())
    ax.append(a)
    bx.append(b)

ax = ax[::-1]
bx = bx[::-1]
cnt = 0
for i in xrange(n):
    if ax[i] % bx[i] !=0:
        k = bx[i] - (ax[i] % bx[i])
        cnt += k
        ax = map(lambda x:x+k,ax)
print cnt


Fixed submission:
n = int(raw_input())
ax = []
bx = []
for _ in xrange(n):
    a,b = map(int,raw_input().split())
    ax.append(a)
    bx.append(b)

ax = ax[::-1]
bx = bx[::-1]
cnt = 0
for i in xrange(n):
    if (ax[i] + cnt) % bx[i] !=0:
        k = bx[i] - ((ax[i] + cnt) % bx[i])
        cnt += k

print cnt

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
ax = []
bx = []
for _ in xrange(n):
    a,b = map(int,raw_input().split())
    ax.insert(0,a)
    bx.insert(0,b)

cnt = 0
for i in xrange(n):
    if ax[i] % bx[i] !=0:
        k = bx[i] - (ax[i] % bx[i])
        cnt += k
        ax = map(lambda x:x+k,ax)
print cnt


Fixed submission:
n = int(raw_input())
ax = []
bx = []
for _ in xrange(n):
    a,b = map(int,raw_input().split())
    ax.append(a)
    bx.append(b)

ax = ax[::-1]
bx = bx[::-1]
cnt = 0
for i in xrange(n):
    if (ax[i] + cnt) % bx[i] !=0:
        k = bx[i] - ((ax[i] + cnt) % bx[i])
        cnt += k

print cnt

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
ax = []
bx = []
for _ in xrange(n):
    a,b = map(int,raw_input().split())
    ax.append(a)
    bx.append(b)

ax.reverse()
bx.reverse()
cnt = 0
for i in xrange(n):
    if ax[i] % bx[i] !=0:
        k = bx[i] - (ax[i] % bx[i])
        cnt += k
        ax = map(lambda x:x+k,ax)
print cnt


Fixed submission:
n = int(raw_input())
ax = []
bx = []
for _ in xrange(n):
    a,b = map(int,raw_input().split())
    ax.append(a)
    bx.append(b)

ax = ax[::-1]
bx = bx[::-1]
cnt = 0
for i in xrange(n):
    if (ax[i] + cnt) % bx[i] !=0:
        k = bx[i] - ((ax[i] + cnt) % bx[i])
        cnt += k

print cnt

Buggy python submission (verdict: Time Limit Exceeded):
n = int(raw_input())
ax = []
bx = []
for _ in xrange(n):
    a,b = map(int,raw_input().split())
    ax.append(a)
    bx.append(b)

ax.reverse()
bx.reverse()
cnt = 0
for i in xrange(n):
    if ax[i] % bx[i] !=0:
        cnt += bx[i] - (ax[i] % bx[i])
        k = bx[i] - (ax[i] % bx[i])
        ax = map(lambda x:x+k,ax)

print cnt


Fixed submission:
n = int(raw_input())
ax = []
bx = []
for _ in xrange(n):
    a,b = map(int,raw_input().split())
    ax.append(a)
    bx.append(b)

ax = ax[::-1]
bx = bx[::-1]
cnt = 0
for i in xrange(n):
    if (ax[i] + cnt) % bx[i] !=0:
        k = bx[i] - ((ax[i] + cnt) % bx[i])
        cnt += k

print cnt