Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = input()
sl = len(s)
dp = {}
ct = [0] * sl
for x in range(sl):
    dp[(0, x)] = x - 1 if s[x] == 'L' else x + 1
for i in range(32):
    for j in range(sl):
        dp[(i + 1, j)] = dp[(i, dp[(i, j)])]
for x in range(sl): ct[dp[(32, x)]] += 1
print(' '.join([str(ct[x]) for x in range(sl)]))

Fixed submission:
a, b, c = map(int, input().split())
print(max(c-a+b, 0))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
sl = len(s)
dp = {}
ct = [0] * sl
for x in range(sl):
    dp[(0, x)] = x - 1 if s[x] == 'L' else x + 1
for i in range(32):
    for j in range(sl):
        dp[(i + 1, j)] = dp[(i, dp[(i, j)])]
for x in range(sl): ct[dp[(32, x)]] += 1
print(' '.join([str(ct[x]) for x in range(sl)]))

Fixed submission:
s = input()
sl = len(s)
dp = {}
ct = [0] * sl
for x in range(sl):
    dp[(0, x)] = x - 1 if s[x] == 'L' else x + 1
for i in range(17):
    for j in range(sl):
        dp[(i + 1, j)] = dp[(i, dp[(i, j)])]
for x in range(sl): ct[dp[(17, x)]] += 1
print(' '.join([str(ct[x]) for x in range(sl)]))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
sl = len(s)
dp = {}
ct = [0] * sl
for x in range(sl):
    dp[(0, x)] = x - 1 if s[x] == 'L' else x + 1
for i in range(32):
    for j in range(sl):
        dp[(i + 1, j)] = dp[(i, dp[(i, j)])]
for x in range(sl): ct[dp[(32, x)]] += 1
print(' '.join([str(ct[x]) for x in range(sl)]))

Fixed submission:
s = input()
sl = len(s)
dp = {}
ct = [0] * sl
for x in range(sl):
    dp[(0, x)] = x - 1 if s[x] == 'L' else x + 1
for i in range(17):
    for j in range(sl):
        dp[(i + 1, j)] = dp[(i, dp[(i, j)])]
for x in range(sl): ct[dp[(17, x)]] += 1
print(' '.join([str(ct[x]) for x in range(sl)]))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
dp = {}
m = 10 ** 5
p = 1
for x in range(1, m+1):
    for i, e in enumerate(s):
        if x == 1: dp[(x, i)] = i - p if e == 'L' else i + p
        else: dp[(x, i)] = dp[(x-1, dp[(1, i)])]
ct = [0] * len(s)
for x in range(len(s)):
    ct[dp[(m, x)]] += 1
print(' '.join([str(ct[x]) for x in range(len(s))]))

Fixed submission:
s = input()
sl = len(s)
dp = {}
ct = [0] * sl
for x in range(sl):
    dp[(0, x)] = x - 1 if s[x] == 'L' else x + 1
for i in range(17):
    for j in range(sl):
        dp[(i + 1, j)] = dp[(i, dp[(i, j)])]
for x in range(sl): ct[dp[(17, x)]] += 1
print(' '.join([str(ct[x]) for x in range(sl)]))
Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n, m = map(int, input().split())
cards = list(map(int, input().split()))
heapq.heapify(cards)
rules = []
for _ in range(m):
    x, y = map(int, input().split())
    rules.append((x, y))
for c, v in rules:
    count = 0
    while count < c:
        p = heapq.heappop(cards)
        if p < v:
            heapq.heappush(cards, v)
            count += 1
        else:
            heapq.heappush(cards, p)
            break
print(sum(cards))

Fixed submission:
import heapq
n, m = map(int, input().split())
cards = list(map(int, input().split()))
heapq.heapify(cards)
rules = []
for _ in range(m):
    x, y = map(int, input().split())
    rules.append((x, y))
for c, v in sorted(rules, key=lambda x: x[1], reverse=True):
    count = 0
    while count < c:
        p = heapq.heappop(cards)
        if p < v:
            heapq.heappush(cards, v)
            count += 1
        else:
            heapq.heappush(cards, p)
            break
print(sum(cards))
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
for _ in range(q):
    l, r = map(int, input().split())
    print(s[l-1:r].count('AC'))

Fixed submission:
n, q = map(int, input().split())
s = input()
hp = [0] * (n+1)
for i in range(len(s)):
  hp[i+1] = hp[i] + (1 if s[i:i+2] == 'AC' else 0)
for _ in range(q):
  l, r = map(int, input().split())
  print(hp[r-1] - hp[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
sh = sorted(h)
u = []
for i in range(len(sh)-k+1):
    a = sh[i:i+k]
    u.append(max(a) - min(a))
print(min(u))

Fixed submission:
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
sh = sorted(h)
print(min([sh[i+k-1]-sh[i] for i in range(n-k+1)]))

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)], reverse=True)
u = []
for i, v in enumerate(h[:-k+1]):
    a = h[i:i+k]
    u.append(max(a) - min(a))
print(min(u))

Fixed submission:
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
sh = sorted(h)
print(min([sh[i+k-1]-sh[i] for i in range(n-k+1)]))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
P = [input().split() for i in range(M)]
print(type(P), P)

Fixed submission:
import math
L, M = map(int,input().split())
list1=[]
for i in range(L):
  X,Y = map(int,input().split())
  r = X**2+Y**2
  if r <= M**2:
    list1.append(r)
print(len(list1))
Buggy python submission (verdict: Runtime Error):
X,Y= map(int,input().split())
if y%2==0 and 2*X<=Y and Y<=4*X:
    print('yes')
else:
    print('No')

Fixed submission:
x,y=map(int,input().split())
 
if(y%2==0 and y>=2*x and y<=4*x):
  print("Yes")
  
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
p,r=input,range
A=sum([list(map(int,p().split()))for _ in r(3)],[])
b=[int(p())for _ in r(int(p()))]
print('YNeos'[[v for v in[7,56,73,84,146,273,292,448]if sum(1<<i for i in r(9)if A[i]in b)&v==v]::2])

Fixed submission:
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

field = 0
for v in b:
	for i in range(9):
		if A[i // 3][i % 3] == v:
			field = field | (1 << i)
ans = False
for v in sum([[273,84],sum([[73<<i,7<<i*3]for i in range(3)],[])],[]):
  ans = ans or field&v==v;
print('Yes' if ans else 'No')

Buggy python submission (verdict: Runtime Error):
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

field = 0
for v in b:
	for i in range(9):
		if A[i // 3][i % 3] == v:
			f|=1<<i
ans = 0
for v in [7,56,73,84,146,273,292,448]:
  ans |= f&v==v;
print('Yes' if ans else 'No')


Fixed submission:
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

field = 0
for v in b:
	for i in range(9):
		if A[i // 3][i % 3] == v:
			field = field | (1 << i)
ans = False
for v in sum([[273,84],sum([[73<<i,7<<i*3]for i in range(3)],[])],[]):
  ans = ans or field&v==v;
print('Yes' if ans else 'No')

Buggy python submission (verdict: Runtime Error):
A=sum([list(map(int,input().split())) for _ in range(3)],[])
N=int(input())
b=[int(input()) for _ in range(N)]
f=0
for i in range(9):if A[i]in b:f|=1<<i
print('Yes'if sum(f&v==v for v in[7,23,56,84,146,273,292,448])else'No')

Fixed submission:
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

field = 0
for v in b:
	for i in range(9):
		if A[i // 3][i % 3] == v:
			field = field | (1 << i)
ans = False
for v in sum([[273,84],sum([[73<<i,7<<i*3]for i in range(3)],[])],[]):
  ans = ans or field&v==v;
print('Yes' if ans else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(input())
result = N
count = 0
white = [1 if n == '.' else 0 for n in a]
for i in range(N+1):
	count = i-sum(white[0:i])+sum(white[i:N])
	if result > count:
		result = count
print(result)

Fixed submission:
N = int(input())
a = list(input())
result = N
count = 0
result = N
white = [0]*(N+1)
for i in range(N):
	white[i+1] = white[i]
	if a[i] == ".":
		white[i+1] += 1
for i in range(N+1):
    count = i-white[i] + white[N] - white[i]
    if count < result:
        result = count
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
arr=[int(i) for i in input().split()]
f=1 
prod=1 
for i in arr:
    prod*=i 
if prod>10**18:
        f=0 
print(prod if f else -1)

Fixed submission:
n=int(input())
arr=[int(i) for i in input().split()]
if 0 in arr:
    print(0)
    exit()
f=1 
prod=1 
for i in arr:
    prod*=i 
    if prod>10**18:
      f=0 
      break
        
print(prod if f else -1)
Buggy python submission (verdict: Runtime Error):
    n=int(input())
    from math import sqrt as S 
    pf=[]
    for i in range(2,int(S(n))+1):
        if n%i==0:
            c=0 
            while n%i==0:
                n//=i 
                c+=1 
            pf.append([i,c])
    if n>1:
        pf.append([n,1])
    cnt=0 
    def search(x):
        i=1 
        while i(i+1)//2<=x:
            i+=1 
        return i-1 
    for x in range(len(pf)):
        a=pf[x][0]
        b=pf[x][1]
        cnt+=search(b)
    print(cnt)

Fixed submission:
n=int(input())
from math import sqrt as S 
pf=[]
for i in range(2,int(S(n))+1):
    if n%i==0:
        c=0 
        while n%i==0:
            n//=i 
            c+=1 
        pf.append([i,c])
if n>1:
    pf.append([n,1])
cnt=0 
def search(x):
    lo=0
    hi=10**9 
    ans=0 
    while lo<=hi:
        mi=(lo+hi)//2 
        if mi*(mi+1)//2<=x:
            ans=mi 
            lo=mi+1 
        else:
            hi=mi-1 
    return ans 
for x in range(len(pf)):
    a=pf[x][0]
    b=pf[x][1]
    cnt+=search(b)
print(cnt)
Buggy python submission (verdict: Runtime Error):
#code
a,b=map(int,input().split())
c,d=map(int,input().spit())
if a==c:
    print(0)
else:
    print(1)

Fixed submission:
#code
a,b=map(int,input().split())
c,d=map(int,input().split())
if a==c:
    print(0)
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[]
for i in range(n): 
    a,b=map(int,input().split())
    l.append([a,b])
    #b afer a days 
#l=[]
l=[l[i] for i in range(n) if l[i][0]<=m]
l.sort(key=lambda x:[-x[1],-x[0]])
#print(l)
sm=0 
day=0 
#print(l)
for i in range(n): 
    #print(day,l[i][0],l[i][1])
    if day+l[i][0]<=m: 
        sm+=l[i][1]
        #print(i,sm)
        day+=1 
    else: 
        pass 
print(sm)

Fixed submission:
from heapq import heappush,heappop
n,m=map(int,input().split())
li=[[]for i in range(10**5+1)]
for i in range(n):
    a,b=map(int,input().split())
    li[a].append(b)
li2=[]
#print(li)
ans=0
for i in range(1,m+1):
    for x in li[i]:
        heappush(li2,-x)
    if li2:
        ans+=heappop(li2)
    #print(li2)
   # print(ans)
print(-ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[int(i) for i in input().split()]
if len(set(l))==1:
    print(n//2)
    exit()
even=[l[i] for i in range(n) if i%2==0]
odd=[l[i] for i in range(n) if i&1]
from collections import Counter 
c1=Counter(even)
c2=Counter(odd)
a=[i for i in c1]
b=[i for i in c2]
maxi=max(c1.values())
maxi=max(maxi,max(c2.values()))
for a1 in a: 
    for b1 in b: 
        if a1==b1:
            continue 
        maxi=max(maxi,c1[a1]+c2[b1])
print(n-maxi)

Fixed submission:
n=int(input())
l=[int(i) for i in input().split()]
if len(set(l))==1:
    print(n//2)
    exit()
even=[l[i] for i in range(n) if i%2==0]
odd=[l[i] for i in range(n) if i&1]
from collections import Counter 
c1=Counter(even)
c2=Counter(odd)
a=[i for i in c1]
b=[i for i in c2]
maxi=max(c1.values())
maxi=max(maxi,max(c2.values()))
a.sort(key=lambda x:-c1[x])
b.sort(key=lambda x:-c2[x])
for a1 in a: 
    for b1 in b: 
        if a1==b1:
            continue 
        maxi=max(maxi,c1[a1]+c2[b1])
        break 
print(n-maxi)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
d=[0]*m 
sm=0 
d[0]=1 
ans=0 
for i in l: 
    sm+=i 
    sm%=m 
    ans+=d[sm]
    d[sm]+=1 
print(ans)

Fixed submission:
from collections import defaultdict
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
d=defaultdict(int)
sm=0 
d[0]=1 
ans=0 
for i in l: 
    sm+=i 
    sm%=m 
    ans+=d[sm]
    d[sm]+=1 
print(ans)
Buggy python submission (verdict: Runtime Error):
q=[]
vis=set() 
q=[i for i in range(1,10)]
nums=[]
while q:
   # nums.append(t)
    t=q.pop(0)
    nums.append(t)
    if not t*10+9 in vis  and t*10+9<=10**15:
        q.append(t*10+9)
        vis.add(t*10+9)
nums.sort()
k=int(input())
for i in range(k):
    print(nums[i])

Fixed submission:
def s(n):
    ret = 0
    while n > 0:
        ret += n % 10
        n //= 10
    return ret
numbers = [999999999999999999]
while numbers[-1] > 1:
    for d in range(0, 100):
        n = numbers[-1]
        m = n - 10 ** d
        if n * s(m) >= m * s(n):
            numbers.append(m)
            break
numbers = list(reversed(numbers))

n = int(input())
for i in range(n):
    print(numbers[i])

Buggy python submission (verdict: Runtime Error):
q=[]
vis=set() 
q=[i for i in range(1,10)]
nums=[]
while q:
   # nums.append(t)
    t=q.pop(0)
    nums.append(t)
    if not t*10+9 in vis  and t*10+9<=10**16:
        q.append(t*10+9)
        vis.add(t*10+9)
nums.sort()
k=int(input())
for i in range(k):
    print(nums[i])

Fixed submission:
def s(n):
    ret = 0
    while n > 0:
        ret += n % 10
        n //= 10
    return ret
numbers = [999999999999999999]
while numbers[-1] > 1:
    for d in range(0, 100):
        n = numbers[-1]
        m = n - 10 ** d
        if n * s(m) >= m * s(n):
            numbers.append(m)
            break
numbers = list(reversed(numbers))

n = int(input())
for i in range(n):
    print(numbers[i])
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())
n=len(s)
l=[]
for i in range(n):
    curr=''
    for j in range(i,min(i+10,n)):
        curr+=s[j]
        if curr not in l:
            l.append(curr)
l.sort()
#print(l)
print(l[k-1])

Fixed submission:
s=input()
k=int(input())
n=len(s)
l=set()
for i in range(n):
    curr=''
    for j in range(i,min(i+7,n)):
        curr+=s[j]
        l.add(curr)
l=[i for i in l]
l.sort()
#print(l)
print(l[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())
n=len(s)
chars=[i for i in set(s)]
chars.sort() 
i=0 
l=[]
cnt=0 
while i<len(chars): 
    #temp=[]
    for ind in range(n): 
        if s[ind]==chars[i]:
            curr=''
            for j in range(ind,n):
                curr+=s[j]
                if curr not in l:
                    l.append(curr)
                    cnt+=1 
    if cnt>k:
        break 
    i+=1 
l.sort()
#print(l)
print(l[k-1])

Fixed submission:
s=input()
k=int(input())
n=len(s)
l=set()
for i in range(n):
    curr=''
    for j in range(i,min(i+7,n)):
        curr+=s[j]
        l.add(curr)
l=[i for i in l]
l.sort()
#print(l)
print(l[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
k=int(input())
n=len(s)
chars=[i for i in set(s)]
chars.sort() 
i=0 
l=[]
while i<len(chars): 
    for ind in range(n): 
        if s[ind]==chars[i]:
            curr=''
            for j in range(ind,n):
                curr+=s[j]
                if curr not in l:
                    l.append(curr)
    if len(l)>k:
        break 
    i+=1 
l.sort()
#print(l)
print(l[k-1])

Fixed submission:
s=input()
k=int(input())
n=len(s)
l=set()
for i in range(n):
    curr=''
    for j in range(i,min(i+7,n)):
        curr+=s[j]
        l.add(curr)
l=[i for i in l]
l.sort()
#print(l)
print(l[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter 
c=Counter(l) 
ans=[]
for i in c: 
    if c[i]>=2:
        ans=ans+[i]*(c[i]//2)
ans.sort(reverse=1)
if len(ans)<=1:
    print(0)
else: 
    print(ans[0]*ans[1])

Fixed submission:
n=int(raw_input())
l=[int(i) for i in raw_input().split()]
from collections import Counter 
c=Counter(l) 
ans=[]
for i in c: 
    if c[i]>=2:
        ans=ans+[i]*(c[i]//2)
ans.sort(reverse=1)
if len(ans)<=1:
    print(0)
else: 
    print(ans[0]*ans[1])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter 
c=Counter(l) 
ans=[]
for i in set(l): 
    if c[i]>=2:
        ans=ans+[i]*(c[i]//2)
ans.sort(reverse=1)
if len(ans)<=1:
    print(0)
else: 
    print(ans[0]*ans[1])

Fixed submission:
n=int(raw_input())
l=[int(i) for i in raw_input().split()]
from collections import Counter 
c=Counter(l) 
ans=[]
for i in c: 
    if c[i]>=2:
        ans=ans+[i]*(c[i]//2)
ans.sort(reverse=1)
if len(ans)<=1:
    print(0)
else: 
    print(ans[0]*ans[1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter 
c=Counter(l)
arr=[i for i in c if c[i]>=2]
arr.sort(reverse=1)
if len(arr)==1 and c[arr[0]]>=4:
    print(0)
else:
    print(arr[0]*arr[1])

Fixed submission:
n=int(raw_input())
l=[int(i) for i in raw_input().split()]
from collections import Counter 
c=Counter(l) 
ans=[]
for i in c: 
    if c[i]>=2:
        ans=ans+[i]*(c[i]//2)
ans.sort(reverse=1)
if len(ans)<=1:
    print(0)
else: 
    print(ans[0]*ans[1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
l=[int(i) for i in input().split()]
from collections import Counter 
c=Counter(l)
arr=[i for i in c if c[i]>=2]
arr.sort(reverse=1)
if len(arr)==1:
    print(0)
else:
    print(arr[0]*arr[1])

Fixed submission:
n=int(raw_input())
l=[int(i) for i in raw_input().split()]
from collections import Counter 
c=Counter(l) 
ans=[]
for i in c: 
    if c[i]>=2:
        ans=ans+[i]*(c[i]//2)
ans.sort(reverse=1)
if len(ans)<=1:
    print(0)
else: 
    print(ans[0]*ans[1])
Buggy python submission (verdict: Runtime Error):
# Python Program to find LCM of n elements 

def find_lcm(num1, num2): 
	if(num1>num2): 
		num = num1 
		den = num2 
	else: 
		num = num2 
		den = num1 
	rem = num % den 
	while(rem != 0): 
		num = den 
		den = rem 
		rem = num % den 
	gcd = den 
	lcm = int(int(num1 * num2)/int(gcd)) 
	return lcm 
n=int(input())
if n==1:
    print(int(input()))
    exit()
l=[int(input()) for i in range(n)]
num1 = l[0] 
num2 = l[1] 
lcm = find_lcm(num1, num2) 
for i in range(2, len(l)): 
	lcm = find_lcm(lcm, l[i]) 
print(lcm) 

# Code contributed by Mohit Gupta_OMG 


Fixed submission:
def gcd(a,b):
    if b==0: 
        return a 
    return gcd(b,a%b)
n=int(input())
l=[int(input()) for i in range(n)]
ans=l[0]
for i in range(1,n):
    ans=(ans*l[i])//gcd(ans,l[i])
print(ans)

Buggy python submission (verdict: Runtime Error):
# Python Program to find LCM of n elements 

def find_lcm(num1, num2): 
	if(num1>num2): 
		num = num1 
		den = num2 
	else: 
		num = num2 
		den = num1 
	rem = num % den 
	while(rem != 0): 
		num = den 
		den = rem 
		rem = num % den 
	gcd = den 
	lcm = int(int(num1 * num2)/int(gcd)) 
	return lcm 
n=int(input())
l=[int(input()) for i in range(n)]

num1 = l[0] 
num2 = l[1] 
lcm = find_lcm(num1, num2) 

for i in range(2, len(l)): 
	lcm = find_lcm(lcm, l[i]) 
	
print(lcm) 

# Code contributed by Mohit Gupta_OMG 


Fixed submission:
def gcd(a,b):
    if b==0: 
        return a 
    return gcd(b,a%b)
n=int(input())
l=[int(input()) for i in range(n)]
ans=l[0]
for i in range(1,n):
    ans=(ans*l[i])//gcd(ans,l[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
x=int(input())
l=[int(i) for i in input().split()]
mat=[[0 for j in range(m)]for i in range(n)]
curr=1 
c=0 
j=0
for i in range(n): 
    for j in range(m):
        mat[i][j]=curr 
        c+=1 
        if c==l[j]: 
            curr+=1 
            j+=1
            c=0 
for i in range(n):
    if i&1:
        mat[i]=mat[i][::-1]
for i in range(n):
    print(*mat[i])

Fixed submission:
n,m=map(int,input().split())
x=int(input())
l=[int(i) for i in input().split()]
mat=[[0 for j in range(m)]for i in range(n)]
curr=1 
c=0 
j1=0
for i in range(n): 
    for j in range(m):
        mat[i][j]=curr 
        c+=1 
        if c==l[j1]: 
            curr+=1 
            j1+=1
            c=0 
for i in range(n):
    if i&1:
        mat[i]=mat[i][::-1]
for i in range(n):
    print(*mat[i])
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
from collections import defaultdict 
d=defaultdict(list)
for i in range(m):
    a,b=map(int,input().split())
    a-=1 
    b-=1 
    d[a].append(b)
    d[b].append(a)
q=[0]
dist=[0]*n 
vis=[0]*n 
vis[0]=1 
while q:
    t=q.pop(0)
    for i in d[t]:
        if not vis[i]:
            vis[i]=1 
            dist[i]=dist[t]+1 
            q.append(i)
print('POSSIBLE' if dist[n-1]==2 else 'IMPOSSIBLE')

Fixed submission:
n,m=map(int,input().split())
from collections import defaultdict 
d=defaultdict(list)
from collections import deque 
for i in range(m):
    a,b=map(int,input().split())
    a-=1 
    b-=1 
    d[a].append(b)
    d[b].append(a)
q=[0]
dist=[0]*n 
vis=[0]*n 
vis[0]=1 
q=deque() 
q.append(0)
while q:
    t=q.popleft()
    for i in d[t]:
        if not vis[i]:
            vis[i]=1 
            dist[i]=dist[t]+1 
            q.append(i)
print('POSSIBLE' if dist[n-1]==2 else 'IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l1=[]
l=[int(i) for i in input().split()]
for i in l:
    l1.append(i)
    l1=l1[::-1]
print(*l1)

Fixed submission:
n=int(input())
l1=[]
l=[int(i) for i in input().split()]
from collections import deque 
l1=deque()
if n%2==0:
   # l1=[]
    p=0 
    for i in l:
        if p==0:
            l1.append(i)
        else:
            l1.appendleft(i)
        p=1-p 
    print(*l1)
else:
   # l1=[]
    p=0 
    for i in l:
        if p==0:
            l1.appendleft(i)
        else:
            l1.append(i)
        p=1-p 
    print(*l1)
Buggy python submission (verdict: Time Limit Exceeded):
from math import ceil 
n,a,b=map(int,input().split())
l=[int(input()) for i in range(n)]
def check(x):
    c=0
    l1=[i-b*x for i in l]
    #print(l1)
    for i in l1: 
         c+=ceil((i)/(a-b))
    return c<=x
lo=0 
ans=-1 
hi=10**19
while lo<=hi:
    mi=(lo+hi)>>1 
    if check(mi):
        ans=mi 
        hi=mi-1
    else:
        lo=mi+1 
print(ans)


Fixed submission:
from math import ceil 
n,a,b=map(int,input().split())
l=[int(input()) for i in range(n)]
def check(x):
    c=0
    l1=[i-b*x for i in l]
    for i in l1: 
         if i<=0:
             continue 
         c+=ceil((i)/(a-b))
    return c<=x
lo=0 
ans=-1 
hi=10**9+4 
while lo<=hi:
    mi=(lo+hi)>>1 
    if check(mi):
        ans=mi 
        hi=mi-1
    else:
        lo=mi+1 
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import ceil 
n,a,b=map(int,input().split())
l=[int(input()) for i in range(n)]
def check(x):
    c=0 
    l1=[i-b*x for i in l]
  #  print(l1)
    bc=x  
    r=x 
    for i in l1: 
        if i<=0:
            continue 
        else:
            c+=ceil(i/a)
            z=i//a 
            z1=a-i%a
            r-=(z1//b)
   # print(r)
    if r>=0:
        c+=ceil((r*b)/a)
    return c<=x
lo=1 
ans=-1 
hi=10**10
#print(check(2))

while lo<=hi:
    mi=(lo+hi)>>1 
    if check(mi):
        ans=mi 
        hi=mi-1
    else:
        lo=mi+1 
print(ans) 
from math import ceil 
n,a,b=map(int,input().split())
l=[int(input()) for i in range(n)]
def check(x):
    c=0 
    l1=[i-b*x for i in l]
  #  print(l1)
    bc=x  
    r=x 
    for i in l1: 
        if i<=0:
            continue 
        else:
            c+=ceil(i/a)
            z=i//a 
            z1=a-i%a
            r-=min((z1//b),x)
   # print(r)
    if r>=0:
        c+=ceil((r*b)/a)
    return c<=x
lo=1 
ans=-1 
hi=10**10
#print(check(2))

while lo<=hi:
    mi=(lo+hi)>>1 
    if check(mi):
        ans=mi 
        hi=mi-1
    else:
        lo=mi+1 
print(ans) 


Fixed submission:
from math import ceil 
n,a,b=map(int,input().split())
l=[int(input()) for i in range(n)]
def check(x):
    c=0
    l1=[i-b*x for i in l]
    for i in l1: 
         if i<=0:
             continue 
         c+=ceil((i)/(a-b))
    return c<=x
lo=0 
ans=-1 
hi=10**9+4 
while lo<=hi:
    mi=(lo+hi)>>1 
    if check(mi):
        ans=mi 
        hi=mi-1
    else:
        lo=mi+1 
print(ans)