Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s = [0] * (n+1)

print(0,flush=True)
a = input()
if a=='Vacant':
    exit()
s[0]=a
s[n]=a

l = 0
r = n
while True:
    m = (r+l)//2
    print(m,flush=True)
    a = input()
    if a=='Vacant':
        exit()
    s[m]=a
    if s[l]==s[r]:
        if s[l]==s[m]:
            if (m-l)%2==1:
                r = m
            else:
                l = m
        else:
            if (m-l)%2==1:
                l = m
            else:
                r = m
    else:
        if s[l]==s[m]:
            if (m-l)%2==1:
                r = m
            else:
                l = m
        else:
            if (m-l)%2==1:
                l = m
            else:
                r = m


Fixed submission:
n=int(input())
s = [0] * (n+1)

print(0,flush=True)
a = input()
if a=='Vacant':
    exit()
s[0]=a
s[n]=a

l = 0
r = n
while True:
    m = (r+l)//2
    print(m,flush=True)
    a = input()
    if a=='Vacant':
        exit()
    s[m]=a
    if s[l]==s[r]:
        if s[l]==s[m]:
            if (m-l)%2==1:
                r = m
            else:
                l = m
        else:
            if (m-l)%2==1:
                l = m
            else:
                r = m
    else:
        if s[l]==s[m]:
            if (m-l)%2==1:
                r = m
            else:
                l = m
        else:
            if (m-l)%2==1:
                l = m
            else:
                r = m

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s = [0] *n

print(0,flush=True)
a = input()
if a=='Vacant':
    exit()
s[0]=a

l = 0
r = n-1
while True:
    m = (r-l)//2+l
    print(m,flush=True)
    a = input()
    if a=='Vacant':
        exit()
    s[m]=a
    if ((m-l)%2==0 and s[m]==s[l]) or ((m-l)%2==1 and s[m]!=s[l]):
        l = m+1
    else:
        r = m-1



Fixed submission:
n=int(input())
s = [0] * (n+1)

print(0,flush=True)
a = input()
if a=='Vacant':
    exit()
s[0]=a
s[n]=a

l = 0
r = n
while True:
    m = (r+l)//2
    print(m,flush=True)
    a = input()
    if a=='Vacant':
        exit()
    s[m]=a
    if s[l]==s[r]:
        if s[l]==s[m]:
            if (m-l)%2==1:
                r = m
            else:
                l = m
        else:
            if (m-l)%2==1:
                l = m
            else:
                r = m
    else:
        if s[l]==s[m]:
            if (m-l)%2==1:
                r = m
            else:
                l = m
        else:
            if (m-l)%2==1:
                l = m
            else:
                r = m
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))

b = [0]*200000
c = []
ans = 0

for x in a:
    b[x-1] += 1

for x in b:
    if x > 0:
        c.append(x)

c.sort()

while len(c) > k:
    ans += c[0]
    c.pop(0)

print(ans)

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

b = [0]*200000
c = []
ans = 0

for x in a:
    b[x-1] += 1

for x in b:
    if x > 0:
        c.append(x)

c.sort()

y = len(c) - k

if y > 0:
    ans = sum(c[:y])

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))

b = [0]*200000
c = []
ans = 0

for x in a:
    b[x-1] += 1

for x in b:
    if x > 0:
        c.append(x)

while len(c) > k:
    ans += min(c)
    c.remove(min(c))

print(ans)

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

b = [0]*200000
c = []
ans = 0

for x in a:
    b[x-1] += 1

for x in b:
    if x > 0:
        c.append(x)

c.sort()

y = len(c) - k

if y > 0:
    ans = sum(c[:y])

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,c = map(int, input().split())

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

stc2 = sorted(stc)

ans = []

for i in range(n):
    ans2 = [list(ans[i]) for i in range(len(ans))]
    time = [stc2[i][0],0,0]
    for j in range(len(ans2)):
        if stc2[i][2] != ans2[j][1]:
            ans2[j][0]+=1
        if ans2[j][0]<time[0]:
            time[0] = ans2[j][0]
            time[1] = ans2[j][1]
            time[2] = j
        elif ans2[j][0]==time[0] and time[1]!=stc2[i][2]:
            time[0] = ans2[j][0]
            time[1] = ans2[j][1]
            time[2] = j
    if time[1] == 0:
        ans.append([0,0])
        time[2]=-1
    ans[time[2]][0]=stc2[i][1]
    ans[time[2]][1]=stc2[i][2]

print(len(ans))

Fixed submission:


N,C = map(int, input().split())

channels =[[]for i in range(C)]

for i in range(N):
    s,t,c = map(int,input().split())
    channels[c-1].append([s,t])

merged_channels = [[]for i in range(C)]
for i in range(len(channels)):
    channels[i].sort()
    if len(channels[i])>0:
        merged_channels[i].append(channels[i][0])
        for j in range(1,len(channels[i])):
            if merged_channels[i][-1][1]==channels[i][j][0]:
                merged_channels[i][-1][1] = channels[i][j][1]
            else:
                merged_channels[i].append(channels[i][j])

tv = [0]*(10**5+1)
for i in range(len(merged_channels)):
    for s,t in merged_channels[i]:
        for k in range(s,t+1):
            tv[k]+=1

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

n,m = map(int, input().split())

connect = np.zeros((n,n))

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

notbridge = 0


for i in range(n):
    for j in range(n):
        if connect[i,j] == 1:
            connect[i,j] = 0
            connect[j,i] = 0
            stack =[1]
            visited = [1]
            while stack:
                p = stack.pop()
                for k in range(n):
                    if connect[p,k] == 1:
                        if k not in visited:
                            stack.append(k)
                            visited.append(k)
            if len(visited) == n:
                notbridge += 1
            connect[i,j] = 1
            connect[j,i] = 1



print(m-notbridge//2)




Fixed submission:
import numpy as np

n,m = map(int, input().split())

connect = np.zeros((n,n))

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

notbridge = 0


for i in range(n):
    for j in range(n):
        if connect[i,j] == 1:
            connect[i,j] = 0
            connect[j,i] = 0
            stack =[1]
            visited = [1]
            while stack:
                p = stack.pop()
                for k in range(n):
                    if connect[p,k] == 1:
                        if k not in visited:
                            stack.append(k)
                            visited.append(k)
            if len(visited) == n:
                notbridge += 1
            connect[i,j] = 1
            connect[j,i] = 1



print(m-notbridge//2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = input().split()
m = int(input())
t = input().split()

for x in t:
    if x in d:
        d.remove(x)
    else:
        print('NO')
        exit()

print('YES')


Fixed submission:
n = int(input())
d = input().split()
m = int(input())
t = input().split()

d.sort()
t.sort()
a = 0

for x in t:
    for i in range(a, n):
        if d[i] > x:
            print('NO')
            exit()
        if x == d[i]:
            a = i+1
            break

print('YES')

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
d = input().split()
m = int(input())
t = input().split()

for i in range(m):
    if t[i] in d:
        d.remove(t[i])
    else:
        print('NO')
        exit()

print('YES')

Fixed submission:
n = int(input())
d = input().split()
m = int(input())
t = input().split()

d.sort()
t.sort()
a = 0

for x in t:
    for i in range(a, n):
        if d[i] > x:
            print('NO')
            exit()
        if x == d[i]:
            a = i+1
            break

print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

for i in range(1,3501):
    for j in range(1,3501):
        if 4*i*j-n*(i+j) != 0:
            w = (n*i*j)/(4*i*j-n*(i+j))
            if w > 0 and int(w)==w:
                print(i,end=' ')
                print(j,end=' ')
                print(int(w))
                exit()


Fixed submission:
n = int(input())

for i in range(1,3501):
    for j in range(1,3501):
        if 4*i*j-n*(i+j) != 0:
            w = (n*i*j)/(4*i*j-n*(i+j))
            if w > 0 and int(w)==w:
                print(i,end=' ')
                print(j,end=' ')
                print(int(w))
                exit()
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]

l = []
a = 0

for i in range(30):
    if k > 2 ** i:
        a = i

for i in range(2 ** a, k):
    ans = 0
    for j in range(n):
        if i == ab[j][0] | i:
            ans += ab[j][1]
        l.append(ans)

print(max(l))


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

l = []

kb = bin(k)
ll = [k]

for i in range(len(kb) - 2):
    if kb[i + 2] == '1':
        ll.append(int(kb[:i + 2] + '0' + '1' * (len(kb) - (i + 3)), 2))

for i in ll:
    ans = 0
    for j in range(n):
        if i == ab[j][0] | i:
            ans += ab[j][1]
        l.append(ans)

print(max(l))
Buggy python submission (verdict: Runtime Error):
import statistics

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

b = []
c = []
for i in range(N):
    b.append(a[i] - 1)
    c.append(a[i] + 1)

x = a + b + c
y = statistics.mode(x)

print(x.count(y))


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

b = []
c = []
for i in range(N):
    if a[i] > 0:
        b.append(a[i] - 1)
        c.append(a[i] + 1)
    else:
        c.append(a[i] + 1)

abc = a + b + c
count = [0] * (max(abc) + 1)

for x in abc:
    count[x] += 1

print(max(count))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))

b = []

for i in range(100000):
    b.append(a.count(i-1) + a.count(i) + a.count(i+1))

print(max(b))


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

b = []
c = []
for i in range(N):
    if a[i] > 0:
        b.append(a[i] - 1)
        c.append(a[i] + 1)
    else:
        c.append(a[i] + 1)

abc = a + b + c
count = [0] * (max(abc) + 1)

for x in abc:
    count[x] += 1

print(max(count))
Buggy python submission (verdict: Runtime Error):
N = int(input())
p = [int(x) for x in input().split()]

l = []

for i in range(len(p)):
    if p[i] == i + 1:
        l.append(p[i])
    else:
        l.append(0)

count = 0
for i in range(len(l)):
    if l[i] > 0:
        l[i] = 0
        l[i + 1] = 0
        count += 1
print(count)


Fixed submission:
N = int(input())
p = [int(x) for x in input().split()]

l = []

for i in range(len(p)):
    if p[i] == i + 1:
        l.append(p[i])
    else:
        l.append(0)

count = 0

for i in range(len(l) - 1):
    if l[i] > 0:
        l[i] = 0
        l[i + 1] = 0
        count += 1
if l[len(l) - 1] != 0:
    count += 1

print(count)

Buggy python submission (verdict: Runtime Error):
N = int(input())
p = [int(x) for x in input().split()]

l = []

for i in range(len(p)):
    if p[i] == i + 1:
        l.append(p[i])
    else:
        l.append(0)

count = 0
for i in renge(len(l)):
    if l[i] > 0:
        l[i] = 0
        l[i + 1] = 0
        count += 1
print(count)



Fixed submission:
N = int(input())
p = [int(x) for x in input().split()]

l = []

for i in range(len(p)):
    if p[i] == i + 1:
        l.append(p[i])
    else:
        l.append(0)

count = 0

for i in range(len(l) - 1):
    if l[i] > 0:
        l[i] = 0
        l[i + 1] = 0
        count += 1
if l[len(l) - 1] != 0:
    count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
a = input()
total = 1 + (len(a) * (len(a) - 1) // 2)

for i in range(len(a)):
    for j in range(i + 1, len(a)):
        if a[i] == a[j]:
            total -= 1

print(total)

Fixed submission:
a = input()
total = 1 + (len(a) * (len(a) - 1) // 2)
trash = 0

for i in range(97, 97 + 26):
    atoz = (a.count(chr(i)) * (a.count(chr(i)) - 1)) // 2
    trash += atoz

print(total - trash)

Buggy python submission (verdict: Time Limit Exceeded):
a = input()

ans = 1

for i in range(len(a)):
    for j in range(i, len(a)):
        if a[j:i:-1] + a[i] != a[i:j + 1] and a[i] != a[j]:
            ans += 1

print(ans)

Fixed submission:
a = input()
total = 1 + (len(a) * (len(a) - 1) // 2)
trash = 0

for i in range(97, 97 + 26):
    atoz = (a.count(chr(i)) * (a.count(chr(i)) - 1)) // 2
    trash += atoz

print(total - trash)

Buggy python submission (verdict: Time Limit Exceeded):
a = input()

ans = [a]

for i in range(len(a)):
    for j in range(i, len(a)):
        rev = a[0:i] + a[j:i:-1] + a[i] + a[j+1:]
        if rev not in ans:
            ans.append(rev)

print(len(ans))


Fixed submission:
a = input()
total = 1 + (len(a) * (len(a) - 1) // 2)
trash = 0

for i in range(97, 97 + 26):
    atoz = (a.count(chr(i)) * (a.count(chr(i)) - 1)) // 2
    trash += atoz

print(total - trash)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
t = [int(input()) for i in range(n)]

for i in range(n - 1):
    t[i + 1] = t[i] * t[i + 1] // math.gcd(t[i], t[i + 1])

print(t[n - 1])


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

n = int(input())
t = [int(input()) for i in range(n)]


for i in range(n - 1):
    t[i + 1] = t[i] * t[i + 1] // gcd(t[i], t[i + 1])

print(t[n - 1])
Buggy python submission (verdict: Runtime Error):
n, k = [int(x) for x in input().split()]
l = [int(y) for y in input().split()]

l.sort()

print(l[-1]+l[-2]+l[-3])


Fixed submission:
n, k = [int(x) for x in input().split()]
l = [int(y) for y in input().split()]

l.sort()

print(sum(l[-k:]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

d = []

for i in range(1, n):
    d.append(abs(sum(a[:i]) - sum(a[i:])))

print(min(d))


Fixed submission:
n = int(input())
a = [int(x) for x in input().split()]

b = sum(a)
c = a[0]
d = a[0]

for i in range(1, n-1):
    c += a[i]
    if abs(b-2*d) > abs(b-2*c):
        d = c

print(abs(b-2*d))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]

x = 1
y = []

while x not in y and x != 2:
    y += [x]
    x = a[x-1]

if x == 2:
    print(len(y))
else:
    print(-1)


Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

x = 1
i = 0

while i < 100000 and x != 2:
    x = a[x-1]
    i += 1

if x == 2:
    print(i)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]

x = 1
y = []

while x not in y and x != 2:
    y.append(x)
    x = a[x-1]

if x == 2:
    print(len(y))
else:
    print(-1)


Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

x = 1
i = 0

while i < 100000 and x != 2:
    x = a[x-1]
    i += 1

if x == 2:
    print(i)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
print('GREATER' if a>b else 'LESS' if a<b else 'EQUAL')

Fixed submission:
a = int(input())
b = int(input())
print('GREATER' if a > b else 'LESS' if a < b else 'EQUAL')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()

a = ['SS','SW','WS','WW']

for j in range(len(a)):
    for i in range(1,n-1):
        if s[i]=='x':
            if a[j][i]==a[j][i-1]:
                a[j]+='W'
            else:
                a[j]+='S'
        else:
            if a[j][i]==a[j][i-1]:
                a[j]+='S'
            else:
                a[j]+='W'
    flag = 0
    if (s[-1] == 'x' and a[j][-1]=='S') or (s[-1] == 'o' and a[j][-1]=='W'):
        if a[j][-2] != a[j][0]:
            flag += 1
    else:
        if a[j][-2] == a[j][0]:
            flag += 1
    if (s[0] == 'x' and a[j][0]=='S') or (s[0] == 'o' and a[j][0]=='W'):
        if a[j][-1] != a[j][1]:
            flag += 1
    else:
        if a[j][-1] == a[j][1]:
            flag += 1
    if flag == 2:
        print(a[j])
        exit()

print(-1)


Fixed submission:
n = int(input())
s = input()

a = ['SS','SW','WS','WW']

for j in range(len(a)):
    for i in range(1,n-1):
        if s[i]=='x':
            if a[j][i]==a[j][i-1]:
                a[j]+='W'
            else:
                a[j]+='S'
        else:
            if a[j][i]==a[j][i-1]:
                a[j]+='S'
            else:
                a[j]+='W'
    flag = 0
    if (s[-1] == 'x' and a[j][-1]=='S') or (s[-1] == 'o' and a[j][-1]=='W'):
        if a[j][-2] != a[j][0]:
            flag += 1
    else:
        if a[j][-2] == a[j][0]:
            flag += 1
    if (s[0] == 'x' and a[j][0]=='S') or (s[0] == 'o' and a[j][0]=='W'):
        if a[j][-1] != a[j][1]:
            flag += 1
    else:
        if a[j][-1] == a[j][1]:
            flag += 1
    if flag == 2:
        print(a[j])
        exit()

print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

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

b = []
for i in range(n):
    a[i] *= -1
    b.append(a[i])

heapq.heapify(b)

while True:
    p = heapq.heappop(b)
    q = a.index(p)
    for i in range(n):
        a[q-i] += n-i
        if a[q-i]>0:
            print('NO')
            exit()
    if set(a) == {0}:
        print('YES')
        exit()
    b = [a[i] for i in range(n)]
    heapq.heapify(b)




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

s = sum(a)

if s%(n*(n+1)//2)!=0:
    print('NO')
    exit()

ss = s//(n*(n+1)//2)

b = [0 for i in range(n)]

# a[i]-a[i-1] = ss-b[i-1]*n
for i in range(n):
    b[i-1] = (ss-a[i]+a[i-1])//n
    if b[i-1]<0:
        print('NO')
        exit()

c = [0 for i in range(n)]
for i in range(n):
    c[0]+=b[i]*(n-i)

for i in range(1,n):
    c[i] = c[i-1] + ss - b[i-1]*n

if a==c:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

ans = 1
b = [0] * ((n + 1) // 2)

if n % 2 == 0:
    for x in a:
        if x % 2 == 0:
            print(0)
            exit()
        b[x // 2] += 1
    for y in b:
        if y != 2:
            print(0)
            exit()
else:
    for x in a:
        if x % 2 != 0:
            print(0)
            exit()
        b[x // 2] += 1
    for y in b[1:]:
        if y != 2:
            print(0)
            exit()
        if b[0] != 1:
            print(0)
            exit()

print((2 ** (n//2)%(10**9+7))


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

b = [0] * ((n + 1) // 2)

if n % 2 == 0:
    for x in a:
        if x % 2 == 0:
            print(0)
            exit()
        b[x // 2] += 1
    for y in b:
        if y != 2:
            print(0)
            exit()
else:
    for x in a:
        if x % 2 != 0:
            print(0)
            exit()
        b[x // 2] += 1
    for y in b[1:]:
        if y != 2:
            print(0)
            exit()
        if b[0] != 1:
            print(0)
            exit()

print((2 ** (n//2)%(10**9+7)))
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())
ans = 0

for i in range(a, b + 1):
    if i % x == 0:
        ans += 1
print(ans)


Fixed submission:
a, b, x = map(int, input().split())
print(b//x-(a-1)//x)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n,m = readints()
x = readints()
modx = [i%m for i in x]

a = [0]*10**5
b = [0]*m
for i in range(n):
    a[x[i]]+=1
    b[modx[i]]+=1

ans = b[0]//2
b[0] = 0
y = m//2
if m%2==0:
    ans += b[m//2]//2
    b[m//2] = 0
else:
    y += 1
for i in range(1,y):
    c = min(b[i],b[m-i])
    b[i]-=c
    b[m-i]-=c
    ans += c
for i in range(n):
    if b[i%m]>1 and a[i]>1:
        c = min(b[i%m],a[i])//2
        ans += c
        b[i%m]-=c*2

print(ans)






Fixed submission:
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

n,m = readints()
x = readints()
modx = [i%m for i in x]

a = [0]*(10**5+1)
b = [0]*m
for i in range(n):
    a[x[i]]+=1
    b[modx[i]]+=1

ans = b[0]//2
b[0] = 0
y = m//2
if m%2==0:
    ans += b[m//2]//2
    b[m//2] = 0
else:
    y += 1
for i in range(1,y):
    c = min(b[i],b[m-i])
    b[i] -= c
    b[m-i] -= c
    ans += c
for i in range(10**5+1):
    if b[i%m]>1 and a[i]>1:
        c = min(b[i%m],a[i])//2
        ans += c
        b[i%m] -= c*2

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]

t = 1
a = 1

for i in range(n):
    x = max(t//ta[i][0], a//ta[i][1])
    if t > ta[i][0] * x or a > ta[i][1] * x
        x += 1
    t = ta[i][0] * x
    a = ta[i][1] * x

print(t+a)

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

t = 1
a = 1

for i in range(n):
    x = max(t//ta[i][0], a//ta[i][1])
    if t > ta[i][0] * x or a > ta[i][1] * x:
        x += 1
    t = ta[i][0] * x
    a = ta[i][1] * x

print(t+a)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ta = [list(map(int, input().split())) for i in range(n)]

t = ta[0][0]
a = ta[0][1]

for i in range(n):
    tt = ta[i][0]
    aa = ta[i][1]
    while t > tt or a > aa:
        tt += ta[i][0]
        aa += ta[i][1]
    t = tt
    a = aa

print(t+a)

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

t = 1
a = 1

for i in range(n):
    x = max(t//ta[i][0], a//ta[i][1])
    if t > ta[i][0] * x or a > ta[i][1] * x:
        x += 1
    t = ta[i][0] * x
    a = ta[i][1] * x

print(t+a)

Buggy python submission (verdict: Runtime Error):
 = int(input())
ta = [list(map(int, input().split())) for i in range(n)]

t = ta[0][0]
a = ta[0][1]

for i in range(n):
    tt = ta[i][0]
    aa = ta[i][1]
    while t > tt or a > aa:
        tt += ta[i][0]
        aa += ta[i][1]
    t = tt
    a = aa

print(t+a)

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

t = 1
a = 1

for i in range(n):
    x = max(t//ta[i][0], a//ta[i][1])
    if t > ta[i][0] * x or a > ta[i][1] * x:
        x += 1
    t = ta[i][0] * x
    a = ta[i][1] * x

print(t+a)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

c = Counter(a)
m = max(a)

flag = True

for i in range(1, m+1):
    if i<=m//2:
        if c[i]>1:
            flag = False
    else:
        if c[i]<2:
        flag = False
        break
if m%2==0 and c[m//2]!=1:
    flag = False
print('Possible' if flag else 'Impossible')

Fixed submission:
from collections import Counter

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

c = Counter(a)
m = max(a)

flag = True

if m%2 == 0:
    for i in range(1,m+1):
        if i<m//2:
            if c[i]!=0:
                flag = False
                break
        elif i==m//2:
            if c[i]!=1:
                flag = False
                break
        else:
            if c[i]<2:
                flag = False
                break
else:
    for i in range(1,m+1):
        if i<=m//2:
            if c[i]!=0:
                flag = False
                break
        elif i==m//2+1:
            if c[i]!=2:
                flag = False
                break
        else:
            if c[i]<2:
                flag = False
                break

print('Possible' if flag else 'Impossible')