Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n,m=map(int,input().split())
u=[list(map(int,input().split())) for i in range(m)]
s,t=map(int,input().split())
dic=[[] for i in range(n+1)]
for i in range(m):
    a,b=u[i]
    dic[a].append(b)
# print(dic)
itta=[0]*(n+1)
d=deque([[s,0]])
itta[s]=1
itta[t]=2
while d:
    tmp=d.popleft()
    # print(tmp)

    for i in dic[tmp[0]]:
        if (tmp[1]+1)%3==0:
            if itta[i]==1:
                continue
            elif itta[i]==2:
                print((tmp[1]+1)//3)
                quit()
            else:
               itta[i]=1 
        d.append([i,tmp[1]+1])
    # print(itta)
print(-1)

Fixed submission:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

n,m=map(int,input().split())
u=[list(map(int,input().split())) for i in range(m)]
s,t=map(int,input().split())
dic=[[] for i in range(n+1)]
for i in range(m):
    a,b=u[i]
    dic[a].append(b)
# print(dic)
itta=[[0]*3 for i in range(n+1)]
d=deque([[s,0]])
itta[s][0]=1
itta[t][0]=2
while d:
    tmp=d.popleft()
    
    # print(tmp)

    p,cnt=tmp
    for i in dic[p]:
        if itta[i][(cnt+1)%3]==1:
            continue
        elif itta[i][(cnt+1)%3]==2:
            print((cnt+1)//3)
            quit()
        else:
            itta[i][(cnt+1)%3]=1
            d.append([i,cnt+1])
    # print(itta)
print(-1)
Buggy python submission (verdict: Runtime Error):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

# dic={}
# for i in range(n):
#     x,y=xy[i]
#     dic[(x,y)]=1

cnt=0
sadic=defaultdict(int)
for i in range(n):
    x,y=xy[i]
    for j in range(n):
        if i==j:
            continue
        x2,y2=xy[j]
        p,q=x-x2,y-y2
        sadic[(p,q)]+=1
# print(sadic)
print(n-max(sadic.values()))

Fixed submission:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

# dic={}
# for i in range(n):
#     x,y=xy[i]
#     dic[(x,y)]=1
if n==1:
    print(1)
    quit()
cnt=0
sadic=defaultdict(int)
for i in range(n):
    x,y=xy[i]
    for j in range(n):
        if i==j:
            continue
        x2,y2=xy[j]
        p,q=x-x2,y-y2
        sadic[(p,q)]+=1
# print(sadic)
print(n-max(sadic.values()))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

s=input()
n=len(s)
lst=[0]*n
for i in range(n):
    lst[i]=s[i]

i=0
ans=0
while i<n-2:
    # print(i)
    # print(lst[i:i+3])
    if lst[i]=="A" and lst[i+1]=="B" and lst[i+2]=="C":
        lst[i],lst[i+1],lst[i+2]="B","C","A"
        ans+=1
        i=max(0,i-1)
        continue
    i+=1
print(ans)
# print(lst)

Fixed submission:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7

s=input()
n=len(s)
lst=[0]*n
for i in range(n):
    lst[i]=s[i]


ans=0
cnt=0
i=0
while i<n-2:
    if lst[i]=="A":
        cnt+=1
    else:
        cnt=0
    if lst[i]=="A" and lst[i+1]=="B" and lst[i+2]=="C":
        ans+=cnt
        cnt-=1
        lst[i+2]="A"
        i+=1
    # print(lst)
    # print(i,ans,cnt)
    i+=1
print(ans)
# print(lst)
Buggy python submission (verdict: Runtime Error):
# from collections import deque
n,k=map(int,input().split())
a=list(map(int,input().split()))
# v=deque()
# for i in range(n):
#     v.append(a[i])
# print(v)

ans=0
for i in range(1,k+1):
    for j in range(i+1):
        tmp=[]
        # print("{0} {1}".format(i,j))
        for l in range(j):
            if l<k:
                tmp.append(a[l])
        for r in range(i-j):
            if k-1-r>=0:
                tmp.append(a[-1-r])
        # print(tmp)
        tmp.sort(reverse=True)
        # print(tmp)
        # tmp.pop()
        # print(tmp)
        for m in range(k-i):
            if len(tmp)>0:
                tmp.pop()
        ans=max(ans,sum(tmp))

print(ans)

Fixed submission:
# from collections import deque
n,k=map(int,input().split())
a=list(map(int,input().split()))
# v=deque()
# for i in range(n):
#     v.append(a[i])
# print(v)

ans=0
for i in range(1,k+1):
    if i<=n:
        for j in range(i+1):
            tmp=[]
            # print("{0} {1}".format(i,j))
            for l in range(j):
                if l<n:
                    tmp.append(a[l])
            for r in range(i-j):
                if n-1-r>=0:
                    tmp.append(a[-1-r])
            # print(tmp)
            tmp.sort(reverse=True)
            # print(tmp)
            for m in range(k-i):
                if len(tmp)>0:
                    if tmp[-1]<0:
                        tmp.pop()
            ans=max(ans,sum(tmp))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
bc=[list(map(int,input().split())) for i in range(m)]

# print(a)
tmp=[]
for i in range(m):
    for j in range(bc[i][0]):
        tmp.append(bc[i][1])

tmp.sort()
change=tmp[-n:]
change.reverse()
# print(tmp)
# print(change)

for i in range(len(change)):
    if change[i]>a[i]:
        a[i]=change[i]
    else:
        break
print(sum(a))

Fixed submission:
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
bc=sorted([list(map(int,input().split())) for i in range(m)], key=lambda x:x[1], reverse=True)

# print(bc)
# print(a)
tmp=[]
count=0
for i in range(m):
    for j in range(bc[i][0]):
        if count==n:
            break
        tmp.append(bc[i][1])
        count+=1


change=tmp[:n]
# print(tmp)
# print(change)

for i in range(len(change)):
    if change[i]>a[i]:
        a[i]=change[i]
    else:
        break
print(sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
bc=[list(map(int,input().split())) for i in range(m)]

# print(a)
for i in range(m):
    bi=bisect.bisect_left(a,bc[i][1])
    # print(bi)
    for j in range(min(bi,bc[i][0])):
        a[j]=bc[i][1]
    a.sort()
    # print(a)

print(sum(a))

Fixed submission:
import bisect
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
bc=sorted([list(map(int,input().split())) for i in range(m)], key=lambda x:x[1], reverse=True)

# print(bc)
# print(a)
tmp=[]
count=0
for i in range(m):
    for j in range(bc[i][0]):
        if count==n:
            break
        tmp.append(bc[i][1])
        count+=1


change=tmp[:n]
# print(tmp)
# print(change)

for i in range(len(change)):
    if change[i]>a[i]:
        a[i]=change[i]
    else:
        break
print(sum(a))
Buggy python submission (verdict: Runtime Error):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

# MOD combination
def cmb(n, r, mod=10**9+7):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 2*10**5+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans=0
for i in range(n):
    ans+=i*(n-i)*m*m*cmb(n*m-2,k-2)
    ans%=mod

n,m=m,n
for i in range(n):
    ans+=i*(n-i)*m*m*cmb(n*m-2,k-2)
    ans%=mod

print(ans)

Fixed submission:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

# MOD combination
def cmb(n, r, mod=10**9+7):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 2*10**5+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans=0
for i in range(n):
    ans+=i*(n-i)*m*m*cmb(n*m-2,k-2)
    ans%=mod

n,m=m,n
for i in range(n):
    ans+=i*(n-i)*m*m*cmb(n*m-2,k-2)
    ans%=mod

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

class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)

    # 検索
    # 根ならその番号を返す
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    # 併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

uf=UnionFind(n)
for i in range(n-1):
    if vvw[i][2]%2==1:
        uf.union(vvw[i][0], vvw[i][1])

ans=[]
for i in range(1,n+1):
    # print(ans)
    if uf.par[i]==i:
        print(0)
        ans.append(0)
    else:
        # print(uf.par[i])
        if ans[uf.par[i]-1]==1:
            print(0)
            ans.append(0)
        else:
            print(1)
            ans.append(1)

    # print(0 if uf.par[i]%2==0 else 1)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
uvw=[list(map(int,input().split())) for i in range(n-1)]
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weight = [0] * (n+1)


    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]
uf=WeightedUnionFind(n)
for i in range(n-1):
    uf.union(uvw[i][0],uvw[i][1],uvw[i][2])

for i in range(n):
    if uf.diff(i+1,uf.find(i+1))%2==0:
        print(0)
    else:
        print(1)
Buggy python submission (verdict: Runtime Error):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,q=map(int,input().split())
s=input()
td=[input().split() for i in range(q)]
# print(td)

ll,lr=0,n+1
while lr-ll>1:
    mid=(lr+ll)//2
    for i in range(q):
        if mid==0:
            break
        t,d=td[i]
        if s[mid-1]==t:
            if d=="L":
                mid-=1
            else:
                mid+=1
    if mid==0:
        ll=(lr+ll)//2
    else:
        lr=(lr+ll)//2
# print(ll)

ikeru,ikenai=n+1,0
while ikeru-ikenai>1:
    mid=celi(ikeru+ikenai,2)
    for i in range(q):
        if mid==n+1:
            break
        t,d=td[i]
        if s[mid-1]==t:
            if d=="L":
                mid-=1
            else:
                mid+=1
    if mid==n+1:
        ikeru=celi(ikeru+ikenai,2)
    else:
        ikenai=celi(ikeru+ikenai,2)

# print(ikeru)
print(max(0,n-(ll+n+1-ikeru)))

Fixed submission:
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n,q=map(int,input().split())
s=input()
td=[input().split() for i in range(q)]
# print(td)

ll,lr=0,n+1
while lr-ll>1:
    mid=(lr+ll)//2
    for i in range(q):
        if mid==0 or mid==n+1:
            break
        t,d=td[i]
        if s[mid-1]==t:
            if d=="L":
                mid-=1
            else:
                mid+=1
    if mid==0:
        ll=(lr+ll)//2
    else:
        lr=(lr+ll)//2
# print(ll)

ikeru,ikenai=n+1,0
while ikeru-ikenai>1:
    mid=celi(ikeru+ikenai,2)
    for i in range(q):
        if mid==0 or mid==n+1:
            break
        t,d=td[i]
        if s[mid-1]==t:
            if d=="L":
                mid-=1
            else:
                mid+=1
    if mid==n+1:
        ikeru=celi(ikeru+ikenai,2)
    else:
        ikenai=celi(ikeru+ikenai,2)

# print(ikeru)
print(max(0,n-(ll+n+1-ikeru)))
Buggy python submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
tmp=(n+1)//2*(n-2)
# print(tmp)
if n%2==0:
    print(N*(N-2)//2)
else:
    print(((N-1)*(N-3))//2+N-1)
for i in range(n):
    for j in range(i+1,n):
        if (i+1)+(j+1)!=n+(n+1)%2:
            print(i+1,j+1)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
tmp=(n+1)//2*(n-2)
# print(tmp)
if n%2==0:
    print(n*(n-2)//2)
else:
    print(((n-1)*(n-3))//2+n-1)
for i in range(n):
    for j in range(i+1,n):
        if (i+1)+(j+1)!=n+(n+1)%2:
            print(i+1,j+1)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
a,b=map(int,input().split())
ans=a
for i in range(a+1,b+1):
    ans ^= i

print(ans)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
a,b=map(int,input().split())
if a%2==0:
    if b%2!=0:
        if (b+1-a)//2%2==0:
            print(0)
        else:
            print(1)
    else:
        if (b-a)//2%2==0:
            print(b)
        else:
            print(b^1)
else:
    if b%2!=0:
        if (b-a)//2%2==0:
            print(a)
        else:
            print(a^1)
    else:
        if (b+1-a)//2%2==0:
            print(1^a^b)
        else:
            print(a^b)
Buggy python submission (verdict: Runtime Error):
abc=list(map(int,input()))
abc.sort()
print(abc[0]*abc[1])

Fixed submission:
abc=list(map(int,input().split()))
abc.sort()
print(abc[0]*abc[1]//2)
Buggy python submission (verdict: Time Limit Exceeded):
n,p=map(int,input().split())
if n==1:
    print(p)
    exit()
ans=1
for i in range(p+1):
    tmp=pow(i+1,n)
    if tmp>p:
        print(ans)
        break
    if p%tmp==0:
        ans=i+1

Fixed submission:
n,p=map(int,input().split())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

lst=factorization(p)
# print(lst)
ans=1
for a,b in lst:
    if b>=n:
        ans*=pow(a,b//n)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,p=map(int,input().split())
if n==1:
    print(p)
    exit()
ans=1
for i in range(p+1):
    tmp=pow(i+1,n)
    if tmp>p:
        print(ans)
        break
    if p%tmp==0:
        ans=i+1

Fixed submission:
n,p=map(int,input().split())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

lst=factorization(p)
# print(lst)
ans=1
for a,b in lst:
    if b>=n:
        ans*=pow(a,b//n)
print(ans)

Buggy python submission (verdict: Runtime Error):
n,p=map(int,input().split())
if n==1:
    print(p)
    exit()
ans=1
for i in range(p+1):
    tmp=pow(i+1,n)
    if tmp>p:
        print(ans)
        break
    if p%tmp==0:
        ans=i+1

Fixed submission:
n,p=map(int,input().split())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

lst=factorization(p)
# print(lst)
ans=1
for a,b in lst:
    if b>=n:
        ans*=pow(a,b//n)
print(ans)
Buggy python submission (verdict: Runtime Error):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

f="first"
s="second"
# print(a)
if sum(a)==n sum(a)==n+1:
    print(f)
    exit()
# print(sum(a)%2)
if sum(a)%2:
    print(f)
else:
    print(s)

Fixed submission:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

f="first"
s="second"
for i in range(n):
    if a[i]%2==1:
        print(f)
        break
else:
    print(s)
Buggy python submission (verdict: Runtime Error):
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
cnt=0
maxa=max(a)
while 2**cnt<2*maxa:
    cnt+=1
    # print(2**cnt)

lsta=[0]*n
for i in range(1,cnt+1)[::-1]:
    dic=defaultdict(list)
    for j in range(n):
        if 2**i>a[j] and lsta[j]==0:
            if dic[a[j]]!=[]:
                lsta[j]=-1
                lsta[dic[a[j]].pop()]=-1
            else:
                dic[2**i-a[j]].append(j)
    # print(dic)
# print(lsta)
ans=-sum(lsta)//2
print(ans)

Fixed submission:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
cnt=0
maxa=max(a)
while 2**cnt<2*maxa:
    cnt+=1
    # print(2**cnt)

lsta=[0]*n
for i in range(1,cnt+1)[::-1]:
    dic=defaultdict(list)
    for j in range(n):
        if 2**i>a[j] and lsta[j]==0:
            if dic[a[j]]!=[]:
                lsta[j]=-1
                lsta[dic[a[j]].pop()]=-1
            else:
                dic[2**i-a[j]].append(j)
    # print(dic)
# print(lsta)
ans=-sum(lsta)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=[int(input()) for i in range(n)]
a.sort()
# b=sorted(a,reverse=True)
c=[0]*n
ans=0
for i in range((n-1)//2):
    ans-=a[i]
for i in range((n-2)//2):
    ans+=a[n-1-i]
ans*=2
if n%2!=0:
    ans+=a[n//2]+a[n//2+1]
else:
    ans+=a[n//2]-a[n//2-1]

ans2=0
for i in range((n-1)//2):
    ans2+=a[n-1-i]
for i in range((n-2)//2):
    ans2-=a[i]
ans2*=2
if n%2!=0:
    ans2-=a[n//2]+a[n//2-1]
else:
    ans2+=a[n//2]-a[n//2+1]

# print(ans)
# print(ans2)

print(max(ans,ans2))

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=[int(input()) for i in range(n)]
a.sort()
if n==2:
    print(a[1]-a[0])
    quit()

ans=0
for i in range((n-1)//2):
    ans-=a[i]
for i in range((n-2)//2):
    ans+=a[n-1-i]
ans*=2
if n%2!=0:
    ans+=a[n//2]+a[n//2+1]
else:
    ans+=a[n//2]-a[n//2-1]

ans2=0
for i in range((n-1)//2):
    ans2+=a[n-1-i]
for i in range((n-2)//2):
    ans2-=a[i]
ans2*=2
if n%2!=0:
    ans2-=a[n//2]+a[n//2-1]
else:
    ans2+=a[n//2]-a[n//2+1]

# print(ans)
# print(ans2)

print(max(ans,ans2))
Buggy python submission (verdict: Runtime Error):
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
if n==1:
    print("Hello World")
a=int(input())
b=int(input())
print(a+b)

Fixed submission:
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
if n==1:
    print("Hello World")
    quit()
a=int(input())
b=int(input())
print(a+b)