ZhenlongDai/ACPR huggingface dataset:
Problem: p03214
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
*a,=map(int,input().split())
avg=sum(a)

c=[(abs(j-avg),i) for i,j in enumerate(a)]
c.sort(key=lambda x:(x[0],x[1]))
print(c[0][1])

Failing test case input:
4
0 5 12 2

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
n=int(input())
*a,=map(int,input().split())
avg=sum(a)/n

c=[(abs(j-avg),i) for i,j in enumerate(a)]
c.sort(key=lambda x:(x[0],x[1]))
print(c[0][1])

Problem: p03214
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
a=[int(i) for i in input().split()]

ave=(sum(a)/N)

ave_a=[abs(i-ave) for i in a]
print(ave_a)

ans=101
thum=101
for i in range(N):
    if ave_a[i]<thum:
        thum=ave_a[i]
        ans=i

print(ans)

Failing test case input:
4
0 14 6 5

Expected output:
2


Actual output:
[6.25, 7.75, 0.25, 1.25]
2


Fixed submission (verdict: Accepted):
N=int(input())
a=[int(i) for i in input().split()]

ave=(sum(a)/N)

ave_a=[abs(i-ave) for i in a]

ans=101
thum=101
for i in range(N):
    if ave_a[i]<thum:
        thum=ave_a[i]
        ans=i

print(ans)

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

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

goke = 0
ans = 0

for i in range(len(a)):
    goke += a[i]

ave = goke / N

ans = 0
for i in range(len(a)):
    print(ave-a[ans])
    print(ave-a[i])
    if abs(ave-a[ans]) > abs(ave - a[i]):
        ans = i


print(ans)

Failing test case input:
4
5 0 2 5

Expected output:
2


Actual output:
-2.0
-2.0
-2.0
3.0
-2.0
1.0
1.0
-2.0
2


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

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

goke = 0
ans = 0

for i in range(len(a)):
    goke += a[i]

ave = goke / N

ans = 0
for i in range(len(a)):
    if abs(ave-a[ans]) > abs(ave - a[i]):
        ans = i


print(ans)

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

su = sum(a) 
mi = 1000
ans = 0

for i, aa in enumerate(a):
	tmp = abs(aa - su)
	if tmp < mi:
		mi = tmp
		ans = i
		
print(ans)


Failing test case input:
4
3 5 3 5

Expected output:
0


Actual output:
1


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

su = sum(a) / n
mi = 1000
ans = 1000

for i, aa in enumerate(a):
	tmp = abs(aa - su)
	if tmp < mi:
		mi = tmp
		ans = i
		
print(ans)
Problem: p03214
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))
avg = 0
for a in A:
    avg += a
avg = avg / N
B = sorted(A)
target = 0
for b in B:
    dif1 = abs(target-avg)
    dif2 = abs(b-avg)
    if dif2 < dif1:
        target = b
    else:
        break
ans = 0
for i,a in enumerate(A):
    if a == target:
        ans = i
        break
print(ans)

Failing test case input:
4
-4 1 3 4

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int,input().split()))
avg = 0
for a in A:
    avg += a
avg = avg / N
target = 1000
for a in A:
    dif1 = abs(target-avg)
    dif2 = abs(a-avg)
    if dif2 < dif1:
        target = a
ans = 0
for i,a in enumerate(A):
    if a == target:
        ans = i
        break
print(ans)

Problem: p03214
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(i) for i in input().split()]

mean = -1

for i in range(len(A)):
    mean += A[i]

mean /= len(A)

min_value = 1000
min_frame = 0
for i in range(len(A)):
    tmp_value = abs(A[i] - mean)
    if min_value > tmp_value:
        min_value = tmp_value
        min_frame = i

print(min_frame)

Failing test case input:
4
3 4 3 5

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(i) for i in input().split()]

mean = 0

for i in range(len(A)):
    mean += A[i]

mean /= len(A)

min_value = 1000
min_frame = 0
for i in range(len(A)):
    tmp_value = abs(A[i] - mean)
    if min_value > tmp_value:
        min_value = tmp_value
        min_frame = i

print(min_frame)

Problem: p03214
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=[int(i) for i in input().split()]
s=sum(a)
l=len(a)
x=s/l
ans=100
for cnt,i in enumerate(a):
    y=abs(i-x)
    if y<ans:
        ans=cnt
print(ans)

Failing test case input:
4
2 5 3 5

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
n=int(input())
a=[int(i) for i in input().split()]
s=sum(a)
l=len(a)
x=s/l
z=100
for cnt,i in enumerate(a):
    y=abs(i-x)
    if y<z:
        ans=cnt
        z=y
print(ans)

Problem: p03214
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input());
mylist = list(map(int, input().split()));
sum = 0;
for k in mylist:
	sum += k;
sum /= len(mylist);
maxi = 0;
for i in range(len(mylist)):
	if ((mylist[maxi] > sum or mylist[maxi] < mylist[i]) and mylist[i] <= sum):
		maxi = i;
print(maxi);

Failing test case input:
4
-8 0 4 2

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input());
mylist = list(map(int, input().split()));
sum = 0;
for k in mylist:
	sum += k;
sum /= len(mylist);
maxi = 0;
for i in range(len(mylist)):
	if (abs(mylist[maxi] - sum) > abs(mylist[i] - sum)):
		maxi = i;
print(maxi);
Problem: p03214
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = list(map(int, input().split()))
sum = 0
for i in a:
    sum += i
mean = sum / len(a)
min = 101
for i in range(len(a)):
    if min == abs(mean - a[i]):
        break
    if min > abs(mean - a[i]):
        min = abs(mean - a[i])
        ans = i
print(ans)


Failing test case input:
4
1 19 18 2

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
a = list(map(int, input().split()))
sum = 0
for i in a:
    sum += i
mean = sum / len(a)
min = 100
for i in range(len(a)):
    if min == abs(mean - a[i]):
        continue
    if min > abs(mean - a[i]):
        min = abs(mean - a[i])
        ans = i
print(ans)

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

mean = sum(a)/N

a = list(map(lambda x: int(abs(x-mean)), a))

print(a.index(min(a)))

Failing test case input:
4
-4 0 3 8

Expected output:
2


Actual output:
1


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

a = list(map(lambda x: int(abs(N*x-sum(a))), a))

print(a.index(min(a)))

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

A = list(map(int,input().split()))

AVE = sum(A)/len(A)
DIFF = 1000.0
Samu = 0
for i in range(N):
    a = A[i]
    if abs(AVE-a) < DIFF:
        DIFF = AVE-a
        Samu = i
    
        
print(Samu)

Failing test case input:
4
0 13 12 2

Expected output:
3


Actual output:
1


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

A = list(map(int,input().split()))

AVE = sum(A)/len(A)
DIFF = 1000.0
Samu = 0
for i in range(N):
    a = A[i]
    if abs(AVE-a) < DIFF:
        DIFF = abs(AVE-a)
        Samu = i
    
        
print(Samu)

Problem: p03214
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=input().split()
a=list(map(int,a))
mean=sum(a)/len(a)
for i in range(n):
    a[i]=abs(a[i]-mean)
min=a[0]
j=0
for i in range(n):
    if  a[i]<a[0]:
        min=a[i]
        j=i
print(j)

Failing test case input:
4
2 5 3 5

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n=int(input())
a=input().split()
a=list(map(int,a))
mean=sum(a)/n
for i in range(n):
    a[i]=abs(a[i]-mean)
k=a[0]
j=0
for i in range(n):
    if  a[i]<k:
        k=a[i]
        j=i
print(j)

Problem: p03214
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
m = sum(a)
ans = []
for x,y in enumerate(a):
  ans.append([x, abs(m-y)])
ans.sort(key=lambda x:x[1])
print(ans[0][0])

Failing test case input:
4
1 19 12 2

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
m = sum(a)/n
ans = []
for x,y in enumerate(a):
  ans.append([x, abs(m-y)])
ans.sort(key=lambda x:x[1])
print(ans[0][0])
Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):
t = 0
while t == 0:	
	try:
		x,y=[int(i) for i in input().split()]
	except:
		break
	else:
		a = x * y
		if x < y:
			x,y =y,x
		while y > 0:
			r = x % y
			x = y
			y = r
		print(str(x) + " " + str(a/x))

Failing test case input:
10 2
35652232 32102085

Expected output:
2 10
1 1144510982103720


Actual output:
2 10.0
1 1144510982103720.0


Fixed submission (verdict: Accepted):
t = 0
while t == 0:	
	try:
		x,y=[int(i) for i in input().split()]
	except:
		break
	else:
		a = x * y
		if x < y:
			x,y =y,x
		while y > 0:
			r = x % y
			x = y
			y = r
	print(str(x) + " " + str(int(a / x)))

Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):
a,b = map(int, input().split())
if a < b:
    a,b = b,a

def gcd(x,y):
    while y > 0:
        x,y = y,x%y
    return x

def lcm(x,y):
     return x * y / gcd(x, y)

print(gcd(a,b), int(lcm(a,b)))

Failing test case input:
14 6
88904261 49076254

Expected output:
2 42
1 4363088094518294


Actual output:
2 42


Fixed submission (verdict: Accepted):
import sys
for line in sys.stdin:
    a,b = map(int, line.split())
    if a < b:
        a,b = b,a

    def gcd(x,y):
        while y > 0:
            x,y = y,x%y
        return x

    def lcm(x,y):
         return x * y / gcd(x, y)

    print(gcd(a,b), int(lcm(a,b)))

Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):
def gcd(a, b):
	if b == 0: return a
	else: return gcd(b, a % b)

def lcm(a, b):
	return a * b / gcd(a, b)

while True:
	try:
		a, b = map(int, input().split())
		print(gcd(a, b), lcm(a, b))
	except EOFError:
		break

Failing test case input:
14 5
84334371 36268426

Expected output:
1 70
1 3058674893870046


Actual output:
1 70.0
1 3058674893870046.0


Fixed submission (verdict: Accepted):
def gcd(a, b):
	if b == 0: return a
	else: return gcd(b, a % b)

def lcm(a, b):
	return a * b / gcd(a, b)

while True:
	try:
		a, b = map(int, input().split())
		print(int(gcd(a, b)), int(lcm(a, b)))
	except EOFError:
		break

Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):
t = 0
while t == 0:	
	try:
		x,y=[int(i) for i in input().split()]
	except:
		break
	else:
		a = x * y
		if x < y:
			x,y =y,x
		while y > 0:
			r = x % y
			x = y
			y = r
	print(str(x) + " " + str(a / x))

Failing test case input:
14 5
49479848 102314239

Expected output:
1 70
1 5062492993955672


Actual output:
1 70.0
1 5062492993955672.0


Fixed submission (verdict: Accepted):
t = 0
while t == 0:	
	try:
		x,y=[int(i) for i in input().split()]
	except:
		break
	else:
		a = x * y
		if x < y:
			x,y =y,x
		while y > 0:
			r = x % y
			x = y
			y = r
	print(str(x) + " " + str(int(a / x)))
Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):
import sys 
for e in sys.stdin:
    a, b = map(int, e.split())
    p = a * b
    while b:
        a, b = b, a%b
        pass
    print (a,p/a)


Failing test case input:
13 24
38128567 67174073

Expected output:
1 312
1 2561251143043391


Actual output:
1 312.0
1 2561251143043391.0


Fixed submission (verdict: Accepted):
import sys 
for e in sys.stdin:
    a, b = map(int, e.split())
    p = a * b
    while b:
        a, b = b, a%b
        pass
    print (a,p

Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):
def main():
	import sys

	for line in sys.stdin:
		a, b = map(int, line.split())
		c = a*b

		while a % b != 0:
			a, b = b, a%b

		print(b, c*b)

if __name__ == '__main__':
	main()

Failing test case input:
9 6
123795904 14213028

Expected output:
3 18
4 439878662459328


Actual output:
3 162
4 7038058599349248


Fixed submission (verdict: Accepted):
def main():
	import sys

	for line in sys.stdin:
		a, b = map(int, line.split())
		c = a*b

		while a % b != 0:
			a, b = b, a%b

		print(b, c

if __name__ == '__main__':
	main()

Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):
import sys 
for e in sys.stdin:
    a, b = map(int, e.split())
    p = a * b
    while b:
        a, b = b, a%b
        pass
    print (str(a)+' '+str(p/a))


Failing test case input:
13 24
38128567 122348608

Expected output:
1 312
1 4664977097484736


Actual output:
1 312.0
1 4664977097484736.0


Fixed submission (verdict: Accepted):
import sys 
for e in sys.stdin:
    a, b = map(int, e.split())
    p = a * b
    while b:
        a, b = b, a%b
        pass
    print (a,p

Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):
t = 0
while t == 0:	
	try:
		x,y=[int(i) for i in input().split()]
	except:
		break
	else:
		a = x * y
		if x < y:
			x,y =y,x
		while y > 0:
			r = x % y
			x = y
			y = r
		print(str(a/x) + " " + str(x))

Failing test case input:
8 7
34496125 22495953

Expected output:
1 56
1 776023206682125


Actual output:
56.0 1
776023206682125.0 1


Fixed submission (verdict: Accepted):
t = 0
while t == 0:	
	try:
		x,y=[int(i) for i in input().split()]
	except:
		break
	else:
		a = x * y
		if x < y:
			x,y =y,x
		while y > 0:
			r = x % y
			x = y
			y = r
	print(str(x) + " " + str(int(a / x)))

Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):
def gcd(a,b):
 if b==0:
  return a
 return gcd(b,a%b)

while True:
 try:
  a,b=[int(i) for i in input().split()]
 except EOFError:
  break
  

Failing test case input:
4 8
88904261 49076254

Expected output:
4 8
1 4363088094518294


Actual output:

Fixed submission (verdict: Accepted):
def gcd(a,b):
 if b==0:
  return a
 return gcd(b,a%b)

while True:
 try:
  a,b=[int(i) for i in input().split()]
  print(gcd(a,b),(a*b)
 except EOFError:
  break
Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):
a, b = map(int, input().split())

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

def acd(a, b):
    return int(a*b / gcd(a,b))

print(gcd(a,b), acd(a,b))

Failing test case input:
8 6
88904261 24597532

Expected output:
2 24
1 2186825404883852


Actual output:
2 24


Fixed submission (verdict: Accepted):
import sys

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return int(a*b / gcd(a,b))

for s in sys.stdin:
    a, b = map(int, s.split())
    
    print(gcd(a,b), lcm(a,b))

Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):
while True:
    try:
        spam=map(int, input().split(' '))
        spam = [i for i in spam]
        spam.sort()
        cola = spam[0] * spam[1]
        while True:
            if spam[0] == 0:
                print(spam[1])
                print(int(cola/spam[1]))
                break
            pre = spam[0]
            spam[0] = spam[1] % spam[0]
            spam[1] = pre
    except:
        break

Failing test case input:
13 2
183 158763340

Expected output:
1 26
1 29053691220


Actual output:
1
26
1
29053691220


Fixed submission (verdict: Accepted):
while True:
    try:
        spam=map(int, input().split(' '))
        spam = [i for i in spam]
        spam.sort()
        cola = spam[0] * spam[1]
        while True:
            if spam[0] == 0:
                print('{} {}'.format(spam[1],int(cola/spam[1])))
                break
            pre = spam[0]
            spam[0] = spam[1] % spam[0]
            spam[1] = pre
    except:
        break

Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):


while True:
    try:
        a, b = (int(i) for i in input(). split())
        x = a * b
        while True:
            c = a % b
            a = b
            b = c
            if a % b == 0:
                break
        x = x / a
        print("%d %d" % (b, x))
    except:
        break

Failing test case input:
41 8
19587890 97812560

Expected output:
1 328
10 191594166589840


Actual output:
1 41
10 95797083294920


Fixed submission (verdict: Accepted):
def main():
    while True:
        try:
            a, b = map(int, input().split())
            
            gcd = rec(a, b)
            lcm = a * b / gcd

            print(gcd, int(lcm))
        except:
            break

def rec(i, j):
    if i % j == 0:
        return j
    return rec(j, i % j)

if __name__ == '__main__':
    main()
Problem: p00005
Buggy submission (Python3, verdict: Wrong Answer):
def gcd(a,b):
    if a > b:
        x = a
        y = b
    else:
        x = b
        y = a
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

def lcm(a,b,gcd):
    return a*b/gcd

while 1:
    try:
        a,b = [int(x) for x in input().split()]
        gcd = gcd(a,b)
        lcm = lcm(a,b,gcd)
        print('{} {}'.format(gcd,lcm))
    except:
        break

Failing test case input:
13 45
5546023 232288832

Expected output:
1 585
1 1288279204915136


Actual output:
1 585.0


Fixed submission (verdict: Accepted):
def gcd(a,b):
    if a > b:
        x = a
        y = b
    else:
        x = b
        y = a
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

def lcm(a,b,c):
    return int(a*b/c)

while 1:
    try:
        a,b = [int(x) for x in input().split()]
        res_gcd = gcd(a,b)
        res_lcm = lcm(a,b,res_gcd)
        print('{} {}'.format(res_gcd,res_lcm))
    except:
        break
Problem: p03964
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

N = int(input())
TA = []

for _ in range(N):
    TA.append([int(x) for x in input().split()])

x, y = TA[0]

from math import ceil

for i in range(1, N):
    X, Y = TA[i]
    if X <= x or Y <= y:
        mul = max(ceil(x / X), ceil(y / Y))
        x, y = X * mul, Y * mul
    else:
        x, y = X, Y
    print(x, y)

print(x + y)




Failing test case input:
5
3 11
55 28
53 326
591 23
3 2

Expected output:
28565


Actual output:
55 28
106 652
17139 667
17139 11426
28565


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

N = int(input())
TA = []

for _ in range(N):
    TA.append([int(x) for x in input().split()])

x, y = TA[0]

for i in range(1, N):
    X, Y = TA[i]
    if X < x or Y < y:
        mul = max(x 
        x, y = X * mul, Y * mul
    else:
        x, y = X, Y
    

print(x + y)

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math




n = int(input())

tall = 1
aall = 1
for idx1 in range(n):
    t, a = map(int, input().split())
    
    mul = max(math.ceil(tall / t), math.ceil(aall / a))
    tall, aall = t * mul, a * mul
    print(tall, aall)

print(tall + aall)


Failing test case input:
5
2 1
41 1
31 199
231 21
4 2

Expected output:
6588


Actual output:
2 1
41 1
62 398
4389 399
4392 2196
6588


Fixed submission (verdict: Accepted):
import math




n = int(input())

tall = 1
aall = 1
for idx1 in range(n):
    t, a = map(int, input().split())
    
    mul = max(-(-tall 
    tall, aall = t * mul, a * mul
    

print(tall + aall)

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
import math as m
tt , aa = map(int,input().split())
vote = tt + aa
for i in range(n-1):
    t, a = map(int,input().split())
    n = (max(m.floor(tt/t),m.floor(aa/a)))
    tt = t * n
    aa = a * n
    vote = tt + aa
print(vote)

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

Expected output:
10


Actual output:
5


Fixed submission (verdict: Accepted):
n = int(input())
import math as m
t1 , a1 = map(int,input().split())
tt = t1
aa = a1
for i in range(n-1):
    t, a = map(int,input().split())
    n = ((max((tt
    if tt > t*n or aa> a*n:
        n = n + 1
    tt = t * n
    aa = a * n
print(tt + aa)
Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

n = int(input())





for i in range(n):
    
    t, a = [int(i) for i in input().split()]
    if i == 0:
        vote = [t, a]
        continue
    k = max(math.ceil(vote[0] / t),
            math.ceil(vote[1] / a))
    vote = [t * k, a * k]
    print("[{},{}] k:{}".format(t, a, k))
    print("vote:{}".format(vote))
print(vote[0] + vote[1])


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

Expected output:
8


Actual output:
[1,1] k:2
vote:[2, 2]
[3,1] k:2
vote:[6, 2]
8


Fixed submission (verdict: Accepted):
import math

n = int(input())
vote = [0, 0]




vote = [1, 1]
for i in range(n):
    t, a = [int(i) for i in input().split()]
    if vote[0] % t == 0:
        k = vote[0] 
    else:
        k = vote[0] 
    if vote[1] % a == 0:
        k = max(k, vote[1] 
    else:
        k = max(k, vote[1] 
    
    vote = [t * k, a * k]
    
    
print(vote[0] + vote[1])

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

for k in range(n):
    if k:
        m = min(math.ceil(a[k-1][0]/a[k][0]), math.ceil(a[k-1][1]/a[k][1]))
        a[k] = [m*a[k][0], m*a[k][1]]
print(sum(a[n-1]))


Failing test case input:
5
2 1
48 4
31 10
514 23
3 2

Expected output:
860


Actual output:
60


Fixed submission (verdict: Accepted):
import math
from decimal import Decimal
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

for k in range(n):
    if k:
        m0 = math.ceil(Decimal(a[k-1][0])/Decimal(a[k][0]))
        m1 = math.ceil(Decimal(a[k-1][1])/Decimal(a[k][1]))
        m = max(m0, m1)
        a[k] = [m*a[k][0], m*a[k][1]]
print(sum(a[n-1]))

Problem: p03964
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import math


def resolve():
    n = int(input())
    ta = list(list(map(int, input().split())) for _ in range(n))
    takahashi, aoki = ta[0][0], ta[0][1]
    for t, a in ta[1:]:
        k = max(-(-takahashi / t), -(-aoki / a))
        
        takahashi, aoki = k * t, k * a
    print(takahashi + aoki)


if __name__ == "__main__":
    resolve()


Failing test case input:
5
2 1
41 4
31 199
289 37
6 3

Expected output:
4770


Actual output:
770.9081299040976


Fixed submission (verdict: Accepted):
import math


def resolve():
    n = int(input())
    ta = list(list(map(int, input().split())) for _ in range(n))
    takahashi, aoki = ta[0][0], ta[0][1]
    for t, a in ta[1:]:
        k = max(-(-takahashi 
        
        takahashi, aoki = k * t, k * a
    print(takahashi + aoki)


if __name__ == "__main__":
    resolve()
Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N = int(input())
ta = []
for _ in range(N):
    ta.append(list(map(int,input().split())))
ans = sum(ta[0])
for i in range(1,N):
    c = max(math.ceil(ta[i-1][0]/ta[i][0]),math.ceil(ta[i-1][1]/ta[i][1]))
    ans = sum(ta[i])*(c)
    ta[i][0] = ans
    ta[i][1] = ans
print(ans)

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

Expected output:
9


Actual output:
18


Fixed submission (verdict: Accepted):
import math
N = int(input())
ta = []
for _ in range(N):
    ta.append(list(map(int,input().split())))
for i in range(1,N):
    c = max(-(-ta[i-1][0]
    ta[i][0] = ta[i][0]*c
    ta[i][1] = ta[i][1]*c
print(sum(ta[N-1]))

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
import math as m
tt , aa = 1,1
vote = tt + aa
for i in range(n):
    t, a = map(int,input().split())
    n = (max(m.floor(tt/t),m.floor(aa/a)))
    tt = t * n
    aa = a * n
    vote = vote * n
print(vote)

Failing test case input:
5
2 1
43 3
31 165
606 23
4 2

Expected output:
13638


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
import math as m
t1 , a1 = map(int,input().split())
tt = t1
aa = a1
for i in range(n-1):
    t, a = map(int,input().split())
    n = ((max((tt
    if tt > t*n or aa> a*n:
        n = n + 1
    tt = t * n
    aa = a * n
print(tt + aa)

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

from math import ceil


def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
    t, a = arr[0]
    for i, j in arr[1:]:
        r = max(ceil(t / i), ceil(a / j))
        t, a = i * r, j * r
        print(t, a)
    print(t + a)


if __name__ == "__main__":
    main()

Failing test case input:
5
2 1
41 1
31 199
289 91
6 2

Expected output:
1928


Actual output:
41 1
62 398
1445 455
1446 482
1928


Fixed submission (verdict: Accepted):

def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
    t, a = 1, 1
    for i, j in arr:
        r = max((t - 1) 
        t, a = i * r, j * r
    print(t + a)


if __name__ == "__main__":
    main()

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
T,A = ta[0][0],ta[0][1]
for t,a in ta[1:]:
  mul = max(math.ceil(T/t),math.ceil(A/a))
  T,A = max(T,t * mul), max(A,a * mul)
print(T+A)

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

Expected output:
4


Actual output:
12


Fixed submission (verdict: Accepted):
import math
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
T,A = 1,1
for t,a in ta:
  mul = max(-(-A
  T,A = t * mul,a * mul
print(T+A)
Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
ratio = [ list(map(int, input().split())) for i in range(N)]


t1 = 1
t2 = 1
for T1, T2 in ratio:
        tmp_a = int(t1 / T1 + 0.9)
        tmp_b = int(t2 / T2 + 0.9)
        n = int(max(tmp_a, tmp_b))
        t1 = n * T1 
        t2 = n * T2
print(t1 + t2)

Failing test case input:
5
3 11
33 28
31 269
300 23
3 2

Expected output:
12000


Actual output:
6000


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


t1 = 1
t2 = 1
for T1, T2 in ratio:
        tmp_a = -( - t1 
        tmp_b = -( - t2 
        n = max(tmp_a, tmp_b)
        t1 = n * T1 
        t2 = n * T2
print(t1 + t2)

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
t=[tuple(map(int,input().split()))for i in range(n)]
import math
dp=[0]*n
dp[0]=1
for i in range(1,n):
    dp[i]=round(max(t[i-1][0]/t[i][0],t[i-1][1]/t[i][1])*dp[i-1])
x=dp[-1]
print(x*t[n-1][0]+x*t[n-1][1])

Failing test case input:
5
2 1
41 1
31 199
289 46
6 2

Expected output:
3472


Actual output:
1544


Fixed submission (verdict: Accepted):
n=int(input())
t=[tuple(map(int,input().split()))for i in range(n)]
import math
from fractions import Fraction
dp=[0]*n
dp[0]=1
for i in range(1,n):
    dp[i]=math.ceil(max(Fraction(t[i-1][0],t[i][0]),Fraction(t[i-1][1],t[i][1]))*dp[i-1])
x=dp[-1]
print(x*t[n-1][0]+x*t[n-1][1])

Problem: p03964
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from math import ceil
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1

for nt,na in ratio:
    if nt<t:
        r = ceil(t/nt)
        nt = r*nt
        na = r*na
    if na<a:
        r = ceil(a/na)
        na = r*na
        nt = r*nt
    t,a = nt,na
    
print(t+a)


Failing test case input:
5
1 1
48 2
31 199
4 13
1 2

Expected output:
606


Actual output:
768


Fixed submission (verdict: Accepted):
N = int(input())
ratio = [tuple(map(int, input().split())) for _ in range(N)]
t,a = 1,1

for nt,na in ratio:
    if nt<t or na<a:
        r = max((t-1)
        nt *= r
        na *= r
    t,a = nt,na
    
print(t+a)

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
f=lambda:map(int,input().split())
a,b=f()
for _ in range(1,n):
  c,d=f(); x=y=0
  if c<a: t=0--a
  if d<b: t=0--b
  a,b=c,d
print(a+b)

Failing test case input:
5
2 19
11 28
2 8
205 21
3 2

Expected output:
1025


Actual output:
5


Fixed submission (verdict: Accepted):
n=int(input())
f=lambda:map(int,input().split())
a,b=f()
for _ in range(1,n):
  c,d=f()
  t=max(1,0--a
  a,b=c*t,d*t
print(a+b)
Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
import math as m
tt , aa = map(int,input().split())
vote = tt + aa
for i in range(n-1):
    t, a = map(int,input().split())
    n = max(m.ceil(tt/t),m.ceil(aa/a))
    vote = vote * n
print(vote)

Failing test case input:
5
2 1
48 2
31 199
4 23
1 2

Expected output:
621


Actual output:
6


Fixed submission (verdict: Accepted):
n = int(input())
import math as m
t1 , a1 = map(int,input().split())
tt = t1
aa = a1
for i in range(n-1):
    t, a = map(int,input().split())
    n = ((max((tt
    if tt > t*n or aa> a*n:
        n = n + 1
    tt = t * n
    aa = a * n
print(tt + aa)

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


t1 = 1
t2 = 1
for T1, T2 in ratio:
        tmp_a = int(t1 / T1 + 0.9)
        tmp_b = int(t2 / T2 + 0.9)
        n = max(tmp_a, tmp_b)
        t1 = n * T1 
        t2 = n * T2
print(t1 + t2)

Failing test case input:
5
3 1
48 17
31 199
231 23
3 2

Expected output:
6930


Actual output:
0


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


t1 = 1
t2 = 1
for T1, T2 in ratio:
        tmp_a = -( - t1 
        tmp_b = -( - t2 
        n = max(tmp_a, tmp_b)
        t1 = n * T1 
        t2 = n * T2
print(t1 + t2)

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
import math as m
tt , aa = map(int,input().split())
vote = tt + aa
for i in range(n-1):
    t, a = map(int,input().split())
    n = (max(m.floor(tt/t),m.floor(aa/a)))
    tt = t * n
    aa = a * n
    vote = vote * n
print(vote)

Failing test case input:
5
2 1
41 1
31 203
289 65
6 2

Expected output:
2704


Actual output:
1296


Fixed submission (verdict: Accepted):
n = int(input())
import math as m
t1 , a1 = map(int,input().split())
tt = t1
aa = a1
for i in range(n-1):
    t, a = map(int,input().split())
    n = ((max((tt
    if tt > t*n or aa> a*n:
        n = n + 1
    tt = t * n
    aa = a * n
print(tt + aa)

Problem: p03964
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    t, a = map(int, input().split())
    for _ in range(N - 1):
        nt, na = map(int, input().split())
        if t * na == a * nt: continue
        
        
        k = max((t + nt - 1) / nt, (a + na - 1) / na)
        t, a = nt * k, na * k

    print(t + a)




if __name__ == "__main__":
    main()


Failing test case input:
5
2 1
41 1
31 199
231 21
4 2

Expected output:
6588


Actual output:
7960.693548387098


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    t, a = map(int, input().split())
    for _ in range(N - 1):
        nt, na = map(int, input().split())
        if t * na == a * nt: continue
        
        
        k = max((t + nt - 1) 
        t, a = nt * k, na * k

    print(t + a)




if __name__ == "__main__":
    main()
Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

n = int(input())
a,b = 1,1
for _ in range(n):
  x,y = [int(_) for _ in input().split(" ")]
  l = max(math.ceil(a/x), math.ceil(b/y))
  a,b = l*x,l*y
print(x+y)


Failing test case input:
5
3 11
35 26
61 63
304 23
3 1

Expected output:
1216


Actual output:
4


Fixed submission (verdict: Accepted):
import math

n = int(input())
a,b = 1,1
for _ in range(n):
  x,y = [int(_) for _ in input().split(" ")]
  l = max(-(-a
  a,b = l*x,l*y
print(a+b)

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
N = int(input())
T, A = [int(x) for x in input().split()]

for i in range(1,N):
        T2, A2 = [int(x) for x in input().split()]
        n = max(math.ceil(T/T2),math.ceil(A/A2))
        print('n = ',n)
        T = T2*n
        A = A2*n
        print('T = ',T)
        print('A = ',A)

print(T + A)

Failing test case input:
5
3 11
33 28
31 326
300 23
3 2

Expected output:
14500


Actual output:
n =  1
T =  33
A =  28
n =  2
T =  62
A =  652
n =  29
T =  8700
A =  667
n =  2900
T =  8700
A =  5800
14500


Fixed submission (verdict: Accepted):
import math
from decimal import Decimal

N = int(input())
T, A = [Decimal(x) for x in input().split()]

for i in range(1,N):
        T2, A2 = [Decimal(x) for x in input().split()]
        n = Decimal(max(math.ceil(T/T2),math.ceil(A/A2)))
        T = T2 * n
        A = A2 * n

print(T+A)

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

if n == 1:
    print(t[0]+a[0])
else:
    for i in range(1, n):
        for j in range(1, 10**5+1):
            if t[i]*j >= t[i-1] and a[i]*j >= a[i-1]:
                t[i], a[i] = t[i] * j, a[i] * j
                break
print(t[n-1]+a[n-1])

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

Expected output:
4


Actual output:
1


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

if n == 1:
    print(t[0]+a[0])
else:
    for i in range(1, n):
        for j in range(max(t[i-1]
            if t[i]*j >= t[i-1] and a[i]*j >= a[i-1]:
                t[i], a[i] = t[i] * j, a[i] * j
                break
    print(t[n-1]+a[n-1])

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n  =int(input())
ta=[]
for i in range(n):
    ta.append(list(map(int,input().split())))

for i in range(n-1):
    bai = max(int(ta[i][0]/ta[i+1][0]), int(ta[i][1]/ta[i+1][1]))
    ta[i+1][0]=ta[i+1][0]*bai
    ta[i+1][1]=ta[i+1][1]*bai
print(ta[n-1][0]+ta[n-1][1])



Failing test case input:
5
1 10
48 28
31 33
458 23
3 2

Expected output:
2290


Actual output:
0


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

import math
for i in range(n-1):
    bai = max(math.ceil((ta[i][0]-1)
    ta[i+1][0]=ta[i+1][0]*bai
    ta[i+1][1]=ta[i+1][1]*bai
print(ta[n-1][0]+ta[n-1][1])
Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
t = [0] * n
a = [0] * n
for i in range(n):
    tt, aa = map(int, input().split())
    t[i], a[i] = tt, aa

if n == 1:
    print(t[0]+a[0])
else:
    for i in range(1, n):
        for j in range(1, 10**6+1):
            if t[i]*j >= t[i-1] and a[i]*j >= a[i-1]:
                t[i], a[i] = t[i] * j, a[i] * j
                break
print(t[n-1]+a[n-1])

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

Expected output:
4


Actual output:
1


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

if n == 1:
    print(t[0]+a[0])
else:
    for i in range(1, n):
        for j in range(max(t[i-1]
            if t[i]*j >= t[i-1] and a[i]*j >= a[i-1]:
                t[i], a[i] = t[i] * j, a[i] * j
                break
    print(t[n-1]+a[n-1])

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
t_list = []
a_list = []
for i in range(n):
    t, a = map(int, input().split())
    t_list.append(t)
    a_list.append(a)

t_num = t_list[0]
a_num = a_list[0]
for i in range(1, n):
    t, a = t_list[i], a_list[i]
    for m in range(100000):
        if m * t >= t_num and m * a >= a_num:
            t_num = m * t
            a_num = m * a
            break
print(t_num + a_num)


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

Expected output:
4


Actual output:
12


Fixed submission (verdict: Accepted):
n = int(input())
t_list = []
a_list = []
for i in range(n):
    t, a = map(int, input().split())
    t_list.append(t)
    a_list.append(a)

t_num = t_list[0]
a_num = a_list[0]
for i in range(1, n):
    t, a = t_list[i], a_list[i]
    num = max((a_num+a-1)
    t_num = num * t
    a_num = num * a
print(t_num + a_num)

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n  =int(input())
ta=[]
for i in range(n):
    ta.append(list(map(int,input().split())))

for i in range(n-1):
    bai = max(int(ta[i][0]/ta[i+1][0])+1, int(ta[i][1]/ta[i+1][1])+1)
    ta[i+1][0]=ta[i+1][0]*bai
    ta[i+1][1]=ta[i+1][1]*bai
print(ta[n-1][0]+ta[n-1][1])



Failing test case input:
4
1 1
1 1
1 9
1 100

Expected output:
101


Actual output:
404


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

import math
for i in range(n-1):
    bai = max(math.ceil((ta[i][0]-1)
    ta[i+1][0]=ta[i+1][0]*bai
    ta[i+1][1]=ta[i+1][1]*bai
print(ta[n-1][0]+ta[n-1][1])
Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
import math as m
tt , aa = map(int,input().split())
vote = tt + aa
for i in range(n-1):
    t, a = map(int,input().split())
    n = m.floor((max((tt/t),(aa/a))))
    tt = t * n
    aa = a * n
    vote = tt + aa
print(vote)

Failing test case input:
5
3 11
35 28
18 111
300 23
3 2

Expected output:
5000


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
import math as m
t1 , a1 = map(int,input().split())
tt = t1
aa = a1
for i in range(n-1):
    t, a = map(int,input().split())
    n = ((max((tt
    if tt > t*n or aa> a*n:
        n = n + 1
    tt = t * n
    aa = a * n
print(tt + aa)

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
import math
t = 1
a = 1
for i in range(N):
    T, A = map(int,input().split())
    g = max(math.ceil(t/T),math.ceil(a/A))
    t = g*T
    a = g*A
    print(t+a)
ans = t + a
print(ans)

Failing test case input:
5
2 11
11 28
10 6
99 23
3 2

Expected output:
330


Actual output:
13
39
80
244
330
330


Fixed submission (verdict: Accepted):
N = int(input())
import math
t, a = map(int,input().split())
for i in range(N-1):
    T, A = map(int,input().split())
    g = math.ceil(max(-(-t
    t = g*T
    a = g*A
    
ans = t + a
print(ans)

Problem: p03964
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import math

n = int(input())
ta = [tuple(map(int, input().split())) for _ in range(n)]

a, b = ta[0]
for i in range(n):
    x, y = ta[i]
    z = max(-(-a/x), -(-b/y))
    a = x * z
    b = y * z

ans = a + b
print(ans)

Failing test case input:
5
3 10
35 28
12 101
300 23
6 1

Expected output:
4900


Actual output:
1600.9963768115942


Fixed submission (verdict: Accepted):
import math

n = int(input())
ta = [tuple(map(int, input().split())) for _ in range(n)]

a, b = ta[0]
for i in range(n):
    x, y = ta[i]
    z = max(-(-a
    a = x * z
    b = y * z

ans = a + b
print(ans)

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

import sys
input = sys.stdin.readline

from math import ceil


def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
    t, a = 1, 1
    for i, j in arr:
        r = max(ceil(t / i), ceil(a / j))
        t, a = i * r, j * r
        print(t, a)
    print(t + a)


if __name__ == "__main__":
    main()

Failing test case input:
5
3 10
48 17
31 199
231 23
3 2

Expected output:
6930

Actual output:
3 10
48 17
62 398
4158 414
4158 2772
6930


Fixed submission (verdict: Accepted):

def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))
    t, a = 1, 1
    for i, j in arr:
        r = max((t - 1) 
        t, a = i * r, j * r
    print(t + a)


if __name__ == "__main__":
    main()
Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
t = [0] * n
a = [0] * n
for i in range(n):
    tt, aa = map(int, input().split())
    t[i], a[i] = tt, aa

if n == 1:
    print(t[0]+a[0])
else:
    for i in range(1, n):
        for j in range(1, 10**5+1):
            if t[i]*j >= t[i-1] and a[i]*j >= a[i-1]:
                t[i], a[i] = t[i] * j, a[i] * j
                break
    print(t[n-1]+a[n-1])

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

Expected output:
4


Actual output:
1


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

if n == 1:
    print(t[0]+a[0])
else:
    for i in range(1, n):
        for j in range(max(t[i-1]
            if t[i]*j >= t[i-1] and a[i]*j >= a[i-1]:
                t[i], a[i] = t[i] * j, a[i] * j
                break
    print(t[n-1]+a[n-1])

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n=int(input())
x=[1,1]
for i in range(n):
  a0,b0=x
  a ,b =[int(i) for i in input().split()]
  ac=math.ceil(a0/a)*a
  bc=math.ceil(b0/b)*b
  if ac>=bc:
    x=[ac,(ac/a)*b]
  else:
    x=[(bc/b)*a,bc]
  
print(int(sum(x)))

Failing test case input:
5
3 10
35 28
18 111
300 23
3 1

Expected output:
4000


Actual output:
400


Fixed submission (verdict: Accepted):
import math
from fractions import Fraction
n=int(input())
x=[1,1]
for i in range(n):
  a0,b0=x
  a ,b =[int(i) for i in input().split()]
  m=math.ceil(max(Fraction(a0,a),Fraction(b0,b)))
  x=[m*a,m*b]
  
print(int(sum(x)))

Problem: p03964
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline

N = int(input())
TA = []

for _ in range(N):
    TA.append([int(x) for x in input().split()])

x, y = TA[0]

from math import ceil

for i in range(1, N):
    X, Y = TA[i]
    for i in range(1, 10000):
        X2, Y2 = X * i, Y * i
        if X2 >= x and Y2 >= y:
            x, y = X2, Y2
            break
    

print(x + y)




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

Expected output:
2


Actual output:
8


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

N = int(input())
TA = []

for _ in range(N):
    TA.append([int(x) for x in input().split()])

x, y = TA[0]

for i in range(1, N):
    X, Y = TA[i]
    if X < x or Y < y:
        mul = max(x 
        x, y = X * mul, Y * mul
    else:
        x, y = X, Y
    

print(x + y)
Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
t_lst, a_lst = [], []
for i in range(n):
    ti, ai = map(int, input().split())
    t_lst.append(ti)
    a_lst.append(ai)

t, a = 1, 1
for i in range(n):
    ti, ai = t_lst[i], a_lst[i]
    n = max((t+ti-1)/ti, (a+ai-1)/ai)
    t = n*ti
    a = n*ai
print(t+a)

Failing test case input:
5
3 10
48 28
31 199
319 23
3 2

Expected output:
9570


Actual output:
14375.696921124694


Fixed submission (verdict: Accepted):
n = int(input())
t_lst, a_lst = [], []
for i in range(n):
    ti, ai = map(int, input().split())
    t_lst.append(ti)
    a_lst.append(ai)

t, a = 1, 1
for i in range(n):
    ti, ai = t_lst[i], a_lst[i]
    n = max((t+ti-1)
    t = n*ti
    a = n*ai
print(t+a)

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
t=[tuple(map(int,input().split()))for i in range(n)]
import math
dp=[0]*n
dp[0]=1
for i in range(1,n):
    dp[i]=round(max(t[i-1][0]/t[i][0],t[i-1][1]/t[i][1])*dp[i-1])
x=dp[-1]
print(dp)
print(x*t[n-1][0]+x*t[n-1][1])

Failing test case input:
5
3 10
48 28
31 109
231 23
3 2

Expected output:
3850


Actual output:
[1, 0, 0, 0, 0]
0


Fixed submission (verdict: Accepted):
n=int(input())
t=[tuple(map(int,input().split()))for i in range(n)]
import math
from fractions import Fraction
dp=[0]*n
dp[0]=1
for i in range(1,n):
    dp[i]=math.ceil(max(Fraction(t[i-1][0],t[i][0]),Fraction(t[i-1][1],t[i][1]))*dp[i-1])
x=dp[-1]
print(x*t[n-1][0]+x*t[n-1][1])

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
T,A = ta[0][0],ta[0][1]
for t,a in ta[1:]:
  mul = max(math.ceil(T/t),math.ceil(A/a))
  T,A = max(t,t * mul), max(a,a * mul)
print(T+A)

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

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
import math
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]
T,A = 1,1
for t,a in ta:
  mul = max(-(-A
  T,A = t * mul,a * mul
print(T+A)

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
import math as m
tt , aa = map(int,input().split())
vote = tt + aa
for i in range(n-1):
    t, a = map(int,input().split())
    n = max(m.ceil(tt/t),m.ceil(aa/a))
    tt = t
    aa = a
    vote = vote * n
print(vote)

Failing test case input:
5
2 2
41 1
31 203
289 65
6 2

Expected output:
3856


Actual output:
3136


Fixed submission (verdict: Accepted):
n = int(input())
import math as m
t1 , a1 = map(int,input().split())
tt = t1
aa = a1
for i in range(n-1):
    t, a = map(int,input().split())
    n = ((max((tt
    if tt > t*n or aa> a*n:
        n = n + 1
    tt = t * n
    aa = a * n
print(tt + aa)
Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

n = int(input())
t_a = [tuple(map(int, input().split())) for _ in range(n)]

tmp_tuple = t_a[0]
for i in range(1, n):
    if (tmp_tuple[0] / t_a[i][0]) == (tmp_tuple[1] / t_a[i][0]):
        continue
    else:
        factor = max(math.ceil(tmp_tuple[0] / t_a[i][0]), math.ceil(tmp_tuple[1] / t_a[i][1]))

    tmp_tuple = tuple(map(lambda x: x * factor, t_a[i]))

print(sum(tmp_tuple))


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

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
import math

n = int(input())
t_a = [tuple(map(int, input().split())) for _ in range(n)]

tmp_tuple = t_a[0]
ans = sum(tmp_tuple)

for i in range(1, n):
    if (tmp_tuple[0] / t_a[i][0]) == (tmp_tuple[1] / t_a[i][1]):
        continue
    else:
        
        factor = max(math.ceil((tmp_tuple[0] + t_a[i][0] - 1) 

    tmp_tuple = tuple(map(lambda x: x * factor, t_a[i]))
    
    
    ans = sum(tmp_tuple)
    
print(sum(tmp_tuple))

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
import math as m
tt , aa = map(int,input().split())
vote = tt + aa
for i in range(n-1):
    t, a = map(int,input().split())
    n = max(m.ceil(tt/t),m.ceil(aa/a))
    tt = t * n
    aa = a * n
    vote = vote * n
print(vote)

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

Expected output:
8


Actual output:
12


Fixed submission (verdict: Accepted):
n = int(input())
import math as m
t1 , a1 = map(int,input().split())
tt = t1
aa = a1
for i in range(n-1):
    t, a = map(int,input().split())
    n = ((max((tt
    if tt > t*n or aa> a*n:
        n = n + 1
    tt = t * n
    aa = a * n
print(tt + aa)

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
import math as m
tt , aa = 1,1
vote = tt + aa
for i in range(n):
    t, a = map(int,input().split())
    n = m.ceil(max(tt/t,aa/a))
    tt = t * n
    aa = a * n
    vote = vote * n
print(vote)

Failing test case input:
5
2 1
48 17
31 199
231 23
3 3

Expected output:
8316


Actual output:
99792


Fixed submission (verdict: Accepted):
n = int(input())
import math as m
t1 , a1 = map(int,input().split())
tt = t1
aa = a1
for i in range(n-1):
    t, a = map(int,input().split())
    n = ((max((tt
    if tt > t*n or aa> a*n:
        n = n + 1
    tt = t * n
    aa = a * n
print(tt + aa)

Problem: p03964
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import ceil
N = int(input())
A, B = 1, 1
for i in range(N):
    x, y = map(int, input().split())
    n = max(ceil(A/x), ceil(B/y))
    if A > n * x or B > n * y:
        n += 1
    A, B = n*x, n*y
print(A+B)

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

Expected output:
4


Actual output:
5


Fixed submission (verdict: Accepted):
from math import ceil
from fractions import Fraction
N = int(input())
A, B = 1, 1
for i in range(N):
    x, y = map(int, input().split())
    n = max(ceil(Fraction(A,x)), ceil(Fraction(B,y)))
    A, B = n*x, n*y
print(A+B)