Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02760 (python)

Fixed submission:
a,b,c  = map(int, input().split())
d,e,f  = map(int, input().split())
g,h,i  = map(int, input().split())
n=int(input())
A = []
for j in range(n):
    A.append(int(input()))
if (a in A) and (b in A) and (c in A):
    print("Yes")
elif d in A and e in A and f in A:
    print("Yes")
elif g in A and h in A and i in A:
    print("Yes")
elif a in A and d in A and g in A:
    print("Yes")
elif b in A and e in A and h in A:
    print("Yes")
elif c in A and f in A and i in A:
    print("Yes")
elif a in A and e in A and i in A:
    print("Yes")
elif c in A and e in A and g in A:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a,b,c  = map(int, input().split())
d,e,f  = map(int, input().split())
g,h,i  = map(int, input().split())
n=int(input())
A = []
for _ in range(n):
    A.append(int(input())
if (a and b and c) in A:
    print("Yes")
elif (d and e and f) in A:
    print("Yes")
elif (g and h and i) in A:
    print("Yes")
elif (a and d and g) in A:
    print("Yes")
elif (b and e and h) in A:
    print("Yes")
elif (c and f and i) in A:
    print("Yes")
elif (a and e and i) in A:
    print("Yes")
elif (c and e and g) in A:
    print("Yes")
else:
    print("No")
Problem p02761 (python)

Fixed submission:
n,m=map(int,input().split())
s = [0] * m
c = [0] * m
for i in range(m):
    s[i], c[i] = map(int, input().split())
k=["0"]*n
if m==0 and n==1:
    print(0)
elif m==0 and n!=1:
    print(10**(n-1))
else:
    for i in range(m):
        if k[s[i]-1]=="0":
            k[s[i]-1]=c[i]
        elif k[s[i]-1]==c[i]:
            k[s[i]-1]=c[i]
        else:
            print(-1)
            break

    else:
        t=0
        if k[0]=="0":
            k[0]=1
        if k[0]==0 and n==1:
            print(0)
        elif k[0]==0 and n!=1:
            print(-1)
        else:
            for i in range(n):
                t=t+10**(n-1-i)*int(k[i])
            print(t)

Buggy submission (verdict: Runtime Error):
a,b,c  = map(int, input().split())
d,e,f  = map(int, input().split())
g,h,i  = map(int, input().split())
n=int(input())
A = []
for i in range(n):
    A.append(int(input()))
if (a in A) and (b in A) and (c in A):
    print("Yes")
elif d in A and e in A and f in A:
    print("Yes")
elif g in A and h in A and i in A:
    print("Yes")
elif a in A and d in A and g in A:
    print("Yes")
elif b in A and e in A and h in A:
    print("Yes")
elif c in A and f in A and i in A:
    print("Yes")
elif a in A and e in A and i in A:
    print("Yes")
elif c in A and e in A and g in A:
    print("Yes")
else:
    print("No")
Problem p02789 (python)

Fixed submission:
a, b = map(int, input().split())
if a==b:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a==b:
    pront("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a==b:
    pront("Yes")
else:
    print("No")
Problem p02791 (python)

Fixed submission:
N=int(input())
A = list(map(int, input().split()))
count=1
m=A[0]
for i in range(1,N):
    if m>=A[i]:
        count=count+1
        m=A[i]
print(count)

Buggy submission (verdict: Runtime Error):
N=int(input())
A = list(map(int, input().split()))
if N==1:
    print(1)
else:
    count=0
    for i in range(N-1):
        for j in range(i,N):
            if A[i]<=A[j+1]:
                count=count+1
                break
    print(count)
Problem p02802 (python)

Fixed submission:
n,m = map(int, input().split())
p = [0]*m 

for i in range(m):
    p[i] = input().split()
AC=[[0,-1] for j in range(n)]
k=0
WA=0
for i in range(m):
    if p[i][1]=="AC" and AC[int(p[i][0])-1][0]==0 :
        AC[int(p[i][0])-1][0]=1
        AC[int(p[i][0])-1][1]=i
        k=k+1
for i in range(m):
    if p[i][1]=="WA" and AC[int(p[i][0])-1][0]==1 and AC[int(p[i][0])-1][1]>i:
        WA=WA+1

print(k,WA)

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
p = [0]*m 
for i in range(m):
    p[i] = input().split()
for i in range(m):
    p[i][0]=int(p[i][0])
AC=[]
WA=0
for i in range(m):
    if p[i][1]=="AC" and p[i][0] not in AC:
        AC.append(p[i][0])
    elif s[i]=="WA" and p[i][0] not in AC and [p[i][0],"AC"] in p:
        WA=WA+1
print(len(AC),WA)

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
p = [0] * m
s = [0] * m
for i in range(m):
    p[i], s[i] = map(int, input().split())
AC=[]
AC1=[]
WA=0
for i in range(m):
    if s[i]=="AC" and p[i] not in AC:
        AC.append(p[i])
        AC1.append(i)
for i in range(m):
    if s[i]=="WA" and p[i] in AC:
        if AC1[AC.index(p[i])]>i:
            WA=WA+1
print(len(AC),WA)
Problem p02813 (python)

Fixed submission:
import itertools
n=int(input())
p=tuple(input().split())
q=tuple(input().split())
h=[]
for i in range(n):
    h+=str(i+1)
k=list(itertools.permutations(h))
p2=-1
q2=-1
for i in range(len(k)):
    if p==k[i]:
        p2=i
    if q==k[i]:
        q2=i
    if p2 != -1 and q2 !=-1:
        break
print(abs(p2-q2))

Buggy submission (verdict: Runtime Error):
n=int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
import math
r=sorted(p)
t=0
l=0
s=0
for i in range(n):
    if p[i]>q[i]:
        l=p
        s=q
        break
    elif q[i]>p[i]:
        l=q
        s=p
        break
else:
    l=p
    s=q
for i in range(n):
    if l[i]>=s[i]:
        t=t+(r.index(l[i])-r.index(s[i])-1)*math.factorial(n-i-1)
    else:
        t=t+(n-r.index(s[i])-1+r.index(l[i])-1)*math.factrial(n-i-1)

print(t)
Problem p02817 (python)

Fixed submission:
S,T = input().split()
print(T+S)

Buggy submission (verdict: Runtime Error):
S,T = input().split()
ptint(T+S)
Problem p02823 (python)

Fixed submission:
n,a,b=map(int,input().split())
if abs(a-b)%2==0:
    print(abs(a-b)//2)
else:
    if n-b>a-1:
        print(a+(b-a-1)//2)
    else:
        print(n-b+1+(b-a-1)//2)

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
if abs(a-b)%2==0:
    print(abs(a-b)//2)
else:
    if n-b>a-1:
        print(a+(b-a-1)//2)
    else:
        print(n-b+1(b-a-1)//2)
Problem p02995 (python)

Fixed submission:
import fractions
a,b,c,d=map(int,input().split())
count=0
def cc(a,b,c):
    if a%c==0:
        k=a
    else:
        k=a+c-(a%c)
    return ((b//c)-(k//c)+1)
print(b-a+1-cc(a,b,c)-cc(a,b,d)+cc(a,b,(c*d)//fractions.gcd(c,d)))

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d=map(int,input().split())
count=0
def cc(a,b,c):
    if a%c==0 or b%c==0:
        return (b-a)//c+1
    else:
        return (b-a)//c
print(b-a+2-cc(a,b,c)-cc(a,b,d)+cc(a,b,(a*b)//math.gcd(c,d)))
Problem p03156 (python)

Fixed submission:
n=int(input())
a,b=map(int,input().split())
H=list(map(int,input().split()))
d=[]
e=[]
f=[]
for i in range(n):
    k=H[i]
    if k<=a:
        d.append(k)
    elif a<k<=b:
        e.append(k)
    else:
        f.append(k)
print(min(len(d),len(e),len(f)))

Buggy submission (verdict: Runtime Error):
n=int(input())
a,b=map(int,input().split())
d=[]
e=[]
f=[]
for i in range(n):
    k=int(input())
    if k<=a:
        d.append(k)
    elif a<k<=b:
        e.append(k)
    else:
        f.append(k)
print(min(len(d),len(e),len(f)))
Problem p03437 (python)

Fixed submission:
x,y=map(int,input().split())
if x%y==0:
    print(-1)
else:
    if x*(y+1)<=10**18:
        print(x*(y+1))
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
if x%y==0:
    print(-1)
else:
    if x*(y+1)<=10**18:
        print(x*(y+1))
    else:
        print(-1)
Problem p03827 (python)

Fixed submission:
n=int(input())
s=input()
k=0
x=0
for i in range(n):
    if s[i]=="I":
        x+=1
        if x>k:
            k=x
    else:
        x+=-1
print(k)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
k=0
for i in range(n):
    if s[i]=="I":
        x+=1
        if x>k:
            k=x
    else:
        x+=-1
print(k)
Problem p04030 (python)

Fixed submission:
s=input()
n=len(s)
k=""
t=0
for i in range(n):
    if s[i]=="B" and t!=0:
        k=k[:-1]
        t=t-1
    if s[i]=="0":
        k=k+"0"
        t=t+1
    if s[i]=="1":
        k=k+"1"
        t=t+1
print(k)

Buggy submission (verdict: Runtime Error):
x=int(input())
if x>=2000:
    print(1)
else:
    if (x//100)*100<=x<=(x//100)*105:
        print(1)
    else:
        print(0)
Problem p02556 (python)

Fixed submission:
from operator import itemgetter, attrgetter

class P:
    def __init__(self, x, y):
        self.x, self.y = x, y
    def __add__(self, p): return P(self.x + p.x, self.y + p.y)
    def __sub__(self, p): return P(self.x - p.x, self.y - p.y)
    def dot(self, p): return (self.x*p.x + self.y*p.y)
    def cross(self, p): return (self.x*p.y - self.y*p.x)
    def abs(self): return (abs(self.x) + abs(self.y))

def convex_hull(Ps):
    Ps.sort(key=attrgetter('x', 'y'))
    ret1, ret2 = list(), list()
    for i in range(len(Ps)):
        k = len(ret1)
        while k>=2 and (Ps[i]-ret1[k-1]).cross(ret1[k-1]-ret1[k-2]) <= 0:
            ret1.pop()
            k = len(ret1)
        ret1.append(Ps[i])
    for i in range(len(Ps)):
        k = len(ret2)
        while k>=2 and (Ps[i]-ret2[k-1]).cross(ret2[k-1]-ret2[k-2]) >= 0:
            ret2.pop()
            k = len(ret2)
        ret2.append(Ps[i])
    return ret1 + ret2[::-1]

N = int(input())
Ps = list()
for i in range(N):
    x, y = list(map(int, input().split()))
    Ps.append(P(x, y))

# produce convex hull
CPs = convex_hull(Ps)

# brute force
ans = 0
for i in range(len(CPs)):
    for j in range(i, len(CPs)):
        mdis = (CPs[i]-CPs[j]).abs()
#        print(i, j, mdis)
        if ans < mdis: ans = mdis

print (ans)

Buggy submission (verdict: Runtime Error):
from dataclasses import dataclass
from operator import itemgetter, attrgetter

@dataclass
class P:
    x: float
    y: float
    def __add__(self, p: P): return P(self.x + p.x, self.y + p.y)
    def __sub__(self, p: P): return P(self.x - p.x, self.y - p.y)
    def dot(self, p: P): return (self.x*p.x + self.y*p.y)
    def cross(self, p: P): return (self.x*p.y - self.y*p.x)
    def abs(self): return (abs(self.x) + abs(self.y))

def convex_hull(Ps):
    Ps.sort(key=attrgetter('x', 'y'))
    ret1, ret2 = list(), list()
    for i in range(len(Ps)):
        k = len(ret1)
        while k>=2 and (Ps[i]-ret1[k-1]).cross(ret1[k-1]-ret1[k-2]) <= 0:
            ret1.pop()
            k = len(ret1)
        ret1.append(Ps[i])
    for i in range(len(Ps)):
        k = len(ret2)
        while k>=2 and (Ps[i]-ret2[k-1]).cross(ret2[k-1]-ret2[k-2]) >= 0:
            ret2.pop()
            k = len(ret2)
        ret2.append(Ps[i])
    return ret1 + ret2[::-1]

N = int(input())
Ps = list()
for i in range(N):
    x, y = list(map(int, input().split()))
    Ps.append(P(x, y))

# produce convex hull
CPs = convex_hull(Ps)

# brute force
ans = 0
for i in range(len(CPs)):
    for j in range(i, len(CPs)):
        mdis = (CPs[i]-CPs[j]).abs()
#        print(i, j, mdis)
        if ans < mdis: ans = mdis

print (ans)
Problem p02573 (python)

Fixed submission:
#import array
#import random
#import sys

#N, M = 200000, 200000
N, M = list(map(int, input().split()))
R = [[] for _ in range(N+1)]
G = [0] * (N+1)
Z = [0] * (N+1)

def grp(R, grpid, i, G, Z):
    stack = [i]
    while len(stack) > 0:
        k = stack.pop()
        if G[k] > 0: continue
        G[k] = grpid
        Z[grpid] += 1
        for l in range(len(R[k])):
            stack.append(R[k][l])
        
for i in range(M):
    a, b = list(map(int, input().split()))
#    a, b = random.choice(range(N)), random.choice(range(N))
    R[a].append(b)
    R[b].append(a)

grpid = 0
for i in range(1, N+1):
    if G[i] > 0: continue
    grpid += 1
    grp(R, grpid, i, G, Z)
    
Z.sort(reverse=True)
print(Z[0])

Buggy submission (verdict: Runtime Error):
import array
#import random
import sys

#N, M = 100000, 100000
N, M = list(map(int, input().split()))
R = [[] for _ in range(N+1)]
sys.setrecursionlimit(200000)

def grp(R, i, S):
    S[i] = True
    ret = 1
    for j in range(len(R[i])):
        if S[ R[i][j] ]: continue
        ret += grp(R, R[i][j], S)
    return ret

for i in range(M):
    a, b = list(map(int, input().split()))
#    a, b = random.choice(range(N)), random.choice(range(N))
    R[a].append(b)
    R[b].append(a)

S = [False] * (N+1)
maxgrp = 1
for i in range(1, N+1):
    if S[i]: continue
    grpsize = grp(R, i, S)
#    print (grpsize)
    maxgrp = max(grpsize, maxgrp)

print(maxgrp)

Buggy submission (verdict: Runtime Error):
import array

N, M = list(map(int, input().split()))
R = [[] for _ in range(N+1)]

def grp(R, i, S):
    S[i] = True
    ret = 1
    for j in range(len(R[i])):
        if S[ R[i][j] ]: continue
        ret += grp(R, R[i][j], S)
    return ret

for i in range(M):
    a, b = list(map(int, input().split()))
    R[a].append(b)
    R[b].append(a)

S = [False] * (N+1)
maxgrp = 1
for i in range(1, N+1):
    if S[i]: continue
    grpsize = grp(R, i, S)
#    print (grpsize)
    maxgrp = max(grpsize, maxgrp)

print(maxgrp)

Buggy submission (verdict: Runtime Error):
import array

N, M = list(map(int, input().split()))
R = [[] for _ in range(N+1)]

def grp(R, i, S):
    S[i] = True
    ret = 1
    for j in range(len(R[i])):
        if S[ R[i][j] ]: continue
        ret += grp(R, R[i][j], S)
    return ret

for i in range(M):
    a, b = list(map(int, input().split()))
    R[a].append(b)
    R[b].append(a)

S = [False] * (N+1)
maxgrp = 1
for i in range(N):
    if S[i]: continue
    grpsize = grp(R, i, S)
#    print (grpsize)
    maxgrp = max(grpsize, maxgrp)

print(maxgrp)
Problem p02615 (python)

Fixed submission:
import bisect
import statistics
n = int(input())
a = list((int(x) for x in input().split()))

a.sort()
incl = []
score = 0

for i in range(len(a)):
    ain = a.pop()
    incl.append(ain)
    if i==0: continue
    if (len(incl)%2 == 1):
        score += incl[ int(len(incl)/2) ]
    else:
        # smaller of middle two
        score += incl[ int(len(incl)/2)-1 ]

print(score)

Buggy submission (verdict: Runtime Error):
import bisect
import statistics
n = int(input())
a = list((int(x) for x in input().split()))

a.sort()
incl = []
score = 0

for i in range(len(a)):
    ain = a.pop()
    incl.append(ain)
    if i==0: continue
    if (len(incl)%2 == 1):
        score += incl[ int(len(incl))/2 ]
    else:
        # smaller of middle two
        score += incl[ int(len(incl)/2)-1 ]

print(score)
Problem p02630 (python)

Fixed submission:
import array

N = int(input())
A = array.array('L', list(map(int, input().split())))
MAX = 10**5+1
X = array.array('L', [0]) * MAX
Y = array.array('L', range(MAX))

for i in range(len(A)): X[A[i]] += 1
    
Q = int(input())
cur = sum(array.array('L', (X[i]*Y[i] for i in range(len(X)))))

for i in range(Q):
    [b, c] = list(map(int, input().split()))
    cur = cur - X[b]*b + X[b]*c
    print(cur)
    X[c] += X[b]
    X[b] = 0

Buggy submission (verdict: Runtime Error):
import array

N = int(input())
A = array.array('L', list(map(int, input().split())))
MAX = 10**5
X = array.array('L', [0]) * MAX
Y = array.array('L', range(MAX))

for i in range(len(A)): X[A[i]] += 1
    
Q = int(input())
cur = sum(array.array('L', (X[i]*Y[i] for i in range(len(X)))))

for i in range(Q):
    [b, c] = list(map(int, input().split()))
    cur = cur - X[b]*b + X[b]*c
    print(cur)
    X[c] += X[b]
    X[b] = 0

Buggy submission (verdict: Runtime Error):

N = int(input())
A = array.array('L', list(map(int, input().split())))
MAX = 10**5
X = array.array('L', [0]) * MAX
Y = array.array('L', range(MAX))

for i in range(len(A)): X[A[i]] += 1
    
Q = int(input())
cur = sum(array.array('L', (X[i]*Y[i] for i in range(len(X)))))

for i in range(Q):
    [b, c] = list(map(int, input().split()))
    cur = cur - X[b]*b + X[b]*c
    print(cur)
    X[c] += X[b]
    X[b] = 0

Buggy submission (verdict: Runtime Error):
import numpy as np
#import random
from numba import jit

@jit
def main():
    #N = 100000
    #A = random.choices(range(1, N), k=N)
    N = int(input())
    A = np.array(list(map(int, input().split())), dtype=np.uintc)
    MAX = 10**5
    X = np.zeros(MAX, dtype=np.uintc)
    Y = np.array(range(MAX), dtype=np.uintc)
    
    for i in range(len(A)): X[A[i]] += 1
    
    Q = int(input())
    #Q = MAX
    OUT = np.zeros(Q, dtype=np.uintc)
    for i in range(Q):
        [b, c] = list(map(int, input().split()))
        #b, c = random.choice(range(1, N)), random.choice(range(1, N))
        X[c] += X[b]
        X[b] = 0
        OUT[i] = int(np.sum(X*Y))
    return OUT

OUT = main()
print("\n".join(map(str, list(OUT))))

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
MAX = 10**5
X = np.zeros(MAX)
Y = np.array(range(MAX))

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

Q = int(input())
for i in range(Q):
    [b, c] = list(map(int, input().split()))
    X[c] += X[b]
    X[b] = 0
    print(int(np.sum(X*Y)))
Problem p02631 (python)

Fixed submission:
import array
from functools import reduce
from operator import xor

N = int(input())
A = array.array("L", map(int, input().split()))

Q = array.array("L", [0]) * N

R = reduce(xor, A)
for i in range(N):
    print(R^A[i])

Buggy submission (verdict: Runtime Error):
import array
from functools import reduce
from operator import xor

N = int(input())
A = array.array("L", map(int, input().split()))

Q = array.array("L", [0]) * N

array.array("L", (A[n] for n in range(N) if n!=i))

R = reduce(xor, A)
for i in range(N):
    print(R^A[i])

Buggy submission (verdict: Runtime Error):
import array
from functools import reduce
from operator import xor

N = int(input())
A = array.array("L", map(int, input().split()))

Q = array.array("L", [0]) * N

array.array("L", (A[n] for n in range(N) if n!=i))

R = reduce(xor, A)
for i in range(N):
    print(R^A[i])

Buggy submission (verdict: Runtime Error):
import array
from functools import reduce
from operator import xor

N = int(input())
A = array.array("L", map(int, input().split()))

Q = array.array("L", [0]) * N

array.array((A[n] for n in range(N) if n!=i))

R = reduce(xor, A)
for i in range(N):
    print(R^A[i])
Problem p02657 (python)

Fixed submission:
A, B = list(map(int, input().split()))

print(A*B)

Buggy submission (verdict: Runtime Error):
A, B = list(map(int, input().split))

print(A*B)
Problem p02660 (python)

Fixed submission:
from collections import Counter
import math

N = int(input())
c = Counter()

for i in range(2, math.ceil(math.sqrt(N)+1)+1):
    while N%i == 0:
        c.update([i])
        N = N // i
if N!=1: c.update([N])
            
def R(n):
    ret = 0
    for i in range(1, n+1):
        if n>=i:
            ret += 1
            n -= i
        else:
            break
    return ret
 
ans = 0
for n in c:
    ans += R(c[n])
print(ans)

Buggy submission (verdict: Runtime Error):
	from collections import Counter
import math

NN = int(input())
c = Counter()
# create sieve
#MAXLEN = math.ceil(math.sqrt(N+1))+1
#sv = [False] * (MAXLEN+1)
#pr = list()
#for i in range(2, MAXLEN+1):
#    if sv[i]: continue
#    pr.append(i)
#    for j in range(i, MAXLEN+1, i):
#        sv[j] = True
#if N!=1: pr.append(N)
N = NN
for i in range(2, math.ceil(math.sqrt(N)+1)+1):
    while N%i == 0:
        c.update([i])
        N = N // i
if N!=1: c.update([N])
            
def R(n):
    ret = 0
    for i in range(1, n+1):
        if n>=i:
            ret += 1
            n -= i
        else:
            break
    return ret
 
ans = 0
for n in c:
    ans += R(c[n])
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
c = Counter()
# create sieve
MAXLEN = math.ceil(math.sqrt(N+1))+1
sv = [False] * (MAXLEN+1)
pr = list()
for i in range(2, MAXLEN+1):
    if sv[i]: continue
    pr.append(i)
    for j in range(i, MAXLEN+1, i):
        sv[j] = True
if N!=1: pr.append(N)

i = 2
for i in range(len(pr)):
    p = pr[i]
    while N%p == 0:
        c.update([p])
        N = N // p
            
def R(n):
    ret = 0
    for i in range(1, n+1):
        if n>=i:
            ret += 1
            n -= i
        else:
            break
    return ret
 
ans = 0
for n in c:
    ans += R(c[n])
print(ans)
Problem p02684 (python)

Fixed submission:
N, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))

path = [0]*(N+1)
visited = set()

pos = 1
for i in range(N+1):
    if pos in visited: break
    path[i] = pos
    visited.add(pos)
    pos = A[pos]

loc = path.index(pos)
head = path[:loc]
rep = path[loc:i]

if K < len(head):
    print(head[K])
else:
    print(rep[(K - len(head)) % len(rep)])

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))

path = [0]*N

pos = 1
for i in range(K):
    if pos in path: break
    path[i] = pos
    pos = A[pos]

head = path[:path.index(pos)]
rep = path[path.index(pos):i]

print(rep[(K - len(head)) % len(rep)])
Problem p02756 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    s = str(input())
    q = int(input())
    s = s.strip()
    a = [''] * (10**5*2)
    a.extend(list(s))
    a.extend([''] * (10**5*2))
    start = 10**5*2
    end = start + len(s) - 1
    frip = False
    for i in range(q):
        query = input().split()
        if query[0] == '1':
            frip = not frip
        elif query[0] == '2':
            if (query[1] == '1' and frip == False) or (query[1] == '2' and frip == True):
                a[start-1] = query[2]
                start -= 1
            else:
                a[end+1] = query[2]
                end += 1
    if frip:
        a.reverse()
        tmp = end
        end = len(a)-start-1
        start = len(a)-tmp-1
    print(''.join(a[start:end+1]))


main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    s = list(input())
    q = int(input())
    s.pop(-1)
    a = [''] * (10**5*2)
    a.append(*s)
    a.extend([''] * (10**5*2))
    start = 10**5*2
    end = start + len(s) - 1
    for i in range(q):
        query = input().split()
        if query[0] == '1':
            tmp = a[start]
            a[start] = a[end]
            a[end] = tmp
        elif query[0] == '2':
            if query[1] == '1':
                a[start-1] = query[2]
                start -= 1
            elif query[1] == '2':
                a[end+1] = query[2]
                end += 1
    print(''.join(a[start:end+1]))


main()
Problem p02774 (python)

Fixed submission:
import sys
import numpy as np
INF = 10**18+5
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a = np.sort(a)
    ap = a[a > 0]
    an = a[a < 0]
    zc = n * (n - ap.size - an.size)

    l = -INF
    r = INF
    while(l+1 < r):
        x = (l+r)//2

        total = (n-np.searchsorted(a, -(-x // an), side='left')).sum()
        if x >= 0:
            total += zc
        total += np.searchsorted(a, x // ap, side='right').sum()
        total -= a[a*a <= x].size
        total //= 2
        if total < k:
            l = x
        else:
            r = x

    print(r)


main()

Buggy submission (verdict: Runtime Error):
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    table = [0] * (n*(n-1)//2+1)
    c = 0
    for i in range(n):
        for j in range(i+1, n):
            table[c] = a[i]*a[j]
            c += 1
    table = sorted(table)
    print(table[k])


main()