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

Fixed submission:
from fractions import gcd


def main(input_1, input_2):
    left = [0] * (input_1+1)
    for i in range(input_1):
        left[i+1] = gcd(left[i], input_2[i])

    right = [0] * (input_1 + 1)
    i = input_1 - 1
    while i >= 0:
        right[i] = gcd(right[i+1], input_2[i])
        i -= 1

    while i >= 0:
        right[i] = gcd(right[i+1], input_2[i])

    res = 0
    for i in range(input_1):
        l = left[i]
        r = right[i+1]
        gcd_val = gcd(l, r)
        if gcd_val > res:
            res = gcd_val

    return res


if __name__ == "__main__":
    input_1 = int(input())
    input_2 = list(map(int, input().split()))
    print(main(input_1, input_2))

Buggy submission (verdict: Runtime Error):
from fractions import gcd


def main(input_1, input_2):
    left = [0] * (input_1+1)
    for i in range(input_1):
        left[i+1] = gcd(left[i], input_2[i])

    right = [0] * (input_1 + 1)
    i = input_1 - 1
    while i >= 0:
        right[i] = gcd(right[i+1], input_2[i])
        i -= 1

    while i >= 0:
        right[i] = gcd(right[i+1], input_2[i])

    res = 0
    for i in range(input_1):
        l = left[i]
        r = right[i+1]
        gcd_val = gcd(l, r)
        if gcd_val > res:
            res = gcd_val

    return res


if __name__ == "__main__":
    input_1 = input()
    input_2 = list(map(int, input().split()))
    print(main(input_1, input_2))

Buggy submission (verdict: Runtime Error):
from math import gcd
from itertools import combinations
from functools import reduce


def calc_gcd(nums):
    return reduce(gcd, nums)


def main(input_1, input_2):
    nums_list = list(map(list, list(combinations(input_2, len(input_2)-1))))

    gcd_list = []
    for nums in nums_list:
        calced = calc_gcd(nums)
        gcd_list.append(calced)

    return max(gcd_list)


if __name__ == "__main__":
    input_1 = input()
    input_2 = list(map(int, input().split()))
    print(main(input_1, input_2))

Buggy submission (verdict: Runtime Error):
from math import gcd
from itertools import combinations
from functools import reduce


def calc_gcd(nums):
    return reduce(gcd, nums)


def main(input_1, input_2):
    nums_list = list(map(list, list(combinations(input_2, len(input_2)-1))))

    gcd_list = []
    for nums in nums_list:
        calced = calc_gcd(nums)
        gcd_list.append(calced)

    return max(gcd_list)


if __name__ == "__main__":
    input_1 = input()
    input_2 = list(map(int, input().split()))
    print(main(input_1, input_2))
Problem p02584 (python)

Fixed submission:
import math
def main():
	s = raw_input()
	l = s.split()
	x = int(l[0])
	k = int(l[1])
	d = int(l[2])
	value = x - k * d
	ans = x + k * d
	be = 0
	en = k
	while (be <= en):
	    mid = (be + en) // 2
	    diff = 2 * mid * d
	    if ((value + diff) >= 0):
	        ans = value + diff
	        en = mid - 1
	    else:
	        be = mid + 1

	ans2 = value
	be = 0
	en = k
	while (be <= en):
		mid = (be + en) / 2
		diff = 2 * mid * d
		if ((value + diff) < 0):
		    ans2 = value + diff
		    be = mid + 1
		else:
		    en = mid - 1
	print(int(min(abs(ans), abs(ans2))))	



if __name__ == '__main__':
	main()

Buggy submission (verdict: Runtime Error):
import math
def main():
	s = str(input())
	l = s.split()
	x = int(l[0])
	k = int(l[1])
	d = int(l[2])
	value = x - k * d
	ans = x + k * d
	be = 0
	en = k
	while (be <= en):
	    mid = (be + en) // 2
	    diff = 2 * mid * d
	    if ((value + diff) >= 0):
	        ans = value + diff
	        en = mid - 1
	    else:
	        be = mid + 1

	ans2 = value
	be = 0
	en = k
	while (be <= en):
		mid = (be + en) / 2
		diff = 2 * mid * d
		if ((value + diff) < 0):
		    ans2 = value + diff
		    be = mid + 1
		else:
		    en = mid - 1
	print(int(min(abs(ans), abs(ans2))))	



if __name__ == '__main__':
	main()
Problem p03473 (python)

Fixed submission:
m=input()
print (48-m)

Buggy submission (verdict: Runtime Error):
iko
Problem p02573 (python)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
  
N, M = map(int,input().split()) 
uf = UnionFind(N)
for _ in range(M):
  a, b = map(int,input().split())
  uf.union(a-1,b-1)

ans = 0
for i in range(N):
  ans=max(ans, uf.size(i))
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

def DFS(G,v,seen=None,path=None):
    if seen is None: seen = []
    if path is None: path = [v]

    seen.append(v)

    paths = []
    for t in G[v]:
        if t not in seen:
            t_path = path + [t]
            paths.append(tuple(t_path))
            paths.extend(DFS(G, t, seen[:], t_path))
    return paths
N, M = map(int,input().split())
# Build graph dictionary
G = defaultdict(list)
for _ in range(M):
  s, t = input().split()
  G[s].append(t)
  G[t].append(s)

# Run DFS, compute metrics
all_paths = [p for ps in [DFS(G, n) for n in set(G)] for p in ps]
max_len   = max(len(p) for p in all_paths)
print(max_len)
Problem p02696 (python)

Fixed submission:
A, B, N = map(int, input().split())
x = min(N,B-1)
print(A*x//B-A*(x//B))

Buggy submission (verdict: Runtime Error):
A, B, N = map(int, input().split())
x = min(N,B-1)
return A*x//B-A*(x//B)
Problem p02719 (python)

Fixed submission:
def main():
  N, K = map(int,input().split())
  print(min(N%K, K-N%K))
  return 
main()

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
setlist = set()
tmp = N
ans = float('inf')
while True:
  tmp = abs(N-K)
  ans = min(tmp,ans)
  if tmp in setlist:
    break
  setlist.add(tmp)
return ans
Problem p02720 (python)

Fixed submission:
from collections import deque
K = int(input())
queue = deque([1,2,3,4,5,6,7,8,9])
count = 1
while count <= K:
  num = queue.popleft()
  if num%10!=0:
    queue.append(num*10+num%10-1)
  queue.append(num*10+num%10)
  if num%10!=9:
    queue.append(num*10+num%10+1)
  count+=1
  
print(num)

Buggy submission (verdict: Runtime Error):
from collections import deque
K = int(input())
queue = deque([1,2,3,4,5,6,7,8,9])
count = 1
while count <= K:
  num = queue.popleft()
  if num%10!=0:
    queue.append(num*10+num%10-1)
  queue.append(num*10+num%10)
  if num%!=9:
    queue.append(num*10+num%10+1)
  
print(num)
Problem p02732 (python)

Fixed submission:
import math
N = int(input())
K = list(map(int,input().split()))
hashmap = {}
for k in K:
  if k not in hashmap:
    hashmap[k] = 0
  hashmap[k]+=1
total = 0
for v in hashmap.values():
  if v>=2:
  	total+=math.factorial(v) // (math.factorial(v - 2) * 2)

for k in K:
  print(total-(hashmap[k]-1))

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
K = list(map(int,input().split()))
hashmap = {}
for k in K:
  if k not in hashmap:
    hashmap[k] = 0
  hashmap[k]+=1
total = 0
for v in hashmap.values():
  total+=math.factorial(v) // (math.factorial(v - 2) * 2)

for k in K:
  print(total-(hashmap[k]-1))
Problem p02780 (python)

Fixed submission:
N, K = map(int,input().split())
P = [0]+list(map(int,input().split()))
for i in range(1,N+1):
  p = P[i]
  p = (1+p)/2
  P[i] = p+P[i-1]
ans = 0
for i in range(N-K+1):
  ans = max(ans,P[i+K]-P[i])
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
P = list(map(int,input().split()))
prev = 0
for i in range(N):
  p = P[i]
  p = (1+p)//2
  P[i] = prev+p
  prev+=p
ans = 0
for i in range(N-K+1):
  ans = max(ans,P[i+K]-P[i])
print(ans)
Problem p02797 (python)

Fixed submission:
N, K, S = map(int,input().split())
L = [S]*K
for i in range(N-K):
  if S < 10**9:
  	L.append(S+1)
  else:
    L.append(1)
  
print(' '.join(map(str, L)))

Buggy submission (verdict: Runtime Error):
N, K, S = map(int,input().split())
L = [S]*K
for i in range(N-K):
  if S < 10**9:
  	L.append(S+1)
  else:
    L.append(1)
  
print(' '.join(map(int, L)))

Buggy submission (verdict: Runtime Error):
N, K, S = map(int,input().split())
L = [S]*K
for i in range(N-K):
  if S < 10*9:
  	L.append(S+1)
  else:
    L.append(1)
  
print(' '.join(map(int, L)))

Buggy submission (verdict: Runtime Error):
N, K, S = map(int,input().split())
L = [S]*K
for i in range(N-K):
  L.append(S+1)
  
print(' '.join(map(int, L)))

Buggy submission (verdict: Runtime Error):
N, K, S = map(int,input().split())
L = [S]*K
for i in range(N-K):
  L.append(S+1)
  
print(' '.join(L))

Buggy submission (verdict: Runtime Error):
N, K, S = map(int,input())
L = [S]*K
for i in range(N-K):
  L.append(S+1)
  
print(' '.join(L))
Problem p02803 (python)

Fixed submission:
from collections import deque
import numpy as np

H,W = map(int,input().split())
maze = [input() for _ in range(H)]

ans = 0
for x in range(H):
    for y in range(W):
        #壁からはスタートできない
        if maze[x][y] == "#":
            continue

        distance = [[-1]*W for _ in range(H)]
        distance[x][y] = 0
        #start位置
        stack = deque([[x,y]])

        while stack:
            h,w = stack.popleft()
            for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
                new_h, new_w = h+i, w+j
                if new_h < 0 or new_w < 0 or new_h >= H or new_w >= W:
                    continue
                elif maze[new_h][new_w] != "#" and distance[new_h][new_w] == -1:
                    distance[new_h][new_w] = distance[h][w]+1
                    stack.append([new_h, new_w])

        ans = max(ans, np.max(distance))

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int,input().split())
grid = [list(input().split()) for _ in H]
res = 0
def bfs(tup,visited):
  def helper(tup, total):
    if tup in visited():
      res = max(res, total)
    elif tup[0]>=H or tup[0] < 0 or tup[1]>=W or tup[1]<0 or grid[tup[0]][tup[1]]:
      res = max(res, total)
    else:
      visited.add(tup)
      h, w = tup
      helper((h+1, w),total+1)
      helper((h-1, w),total+1)
      helper((h, w-1),total+1)
      helper((h, w+1),total+1)
  helper(tup,0)
  return res
      
ans = 0
for h in H:
  for w in W:
    if grid[h][w] == '#':
      continue
    ans = max(ans,bfs((h,w),set()))
print(ans)
Problem p02924 (python)

Fixed submission:
def main():
  N = int(input())
  if N==1:
    print(0)
    return
  ans = sum(range(1,N))
  print(ans)
main()

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(range(1,N+1))
B = list(range(2,N+1))+[1]
ans = 0
for i in range(N):
  ans+=A[i]%B[i]
print(ans)
Problem p02658 (python)

Fixed submission:
N = int(input())
*A, = map(int,input().split())
max = 10**18
ans = 1
if 0 in A:
    print(0)
    exit()
for i in range(N):
    ans *= A[i]
    if ans > max:
        print(-1)
        exit()
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np 
inf = 10**18
n = int(input())
A = list(map(int,input().split()))
S = np.prod(A)
if 0 in A:
	print(0)
    break
if S > inf:
	print("-1")
	break
print(S)

Buggy submission (verdict: Runtime Error):
import numpy as np 
inf = 10**18
n = int(input())
A = list(map(int,input().split()))
S = np.prod(A)
if A > inf;
	print("-1")
  else:
    print(S)
Problem p02837 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
tes = [[-1]*N for i in range(N)]
for i in range(N):
    A = int(readline())
    for j in range(A):
        x,y = map(int,readline().rstrip().split())
        tes[i][x-1] = y #ここまでが入力

cnt = 0
for i in range(2**N):
    hon = [0]*N
    for j in range(N):
        if (i>>j)&1:
            hon[j] = 1 #全状態2**N通りを作っておく
    flag = True
    for j in range(N):
        if hon[j]:      #hon=1ならtesとの整合性を比較
            for k in range(N):
                if tes[j][k] == -1:
                    continue    #証言されていない部分は飛ばす
                if tes[j][k] != hon[k]:
                    flag = False
    if flag:
        cnt = max(cnt,hon.count(1))
print(cnt)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
tes = [[] for i in range(N)]
for i in range(N):
    A = int(readline())
    for j in range(A):
        x,y = map(int,readline().rstrip().split())
        tes[i].append((x-1,y))

cnt = 0
for i in range(2**N):
    flag = True
    for j in range(N):
        if (i>>j)&1 == 1:
            for x,y in tes[j]:
                if (i>>x)&1 != y:
                    flag = False
                    break
    if flag:
        cnt = max(cnt,bin(i)[2:].count(1))
print(cnt)
Problem p03210 (python)

Fixed submission:
X=input()
if X in "753":
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
X=input()
if x in "753":
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
X=input()
if x in "753";
    print("YES")
else;
    print("NO")

Buggy submission (verdict: Runtime Error):
X-input()
if x in "753";
    print("YES")
else;
    print("NO")
Problem p03545 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = readline().rstrip()
S = list(N)
bnk = len(N)-1
for i in range(2**bnk):
    op = ["-","-","-"]
    for j in range(bnk):
        if ((i>>j)&1):
            op[bnk-j-1] = "+"
    tmp = ""
    for k in range(3):
        tmp += S[k]+op[k]
    tmp = tmp+S[3]
    if eval(tmp)==7:
        print(tmp+"=7")
        break

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

N = readline()
S = list(N)
bnk = len(N)-1
for i in range(2**bnk):
    op = ["-","-","-"]
    for j in range(bnk):
        if ((i>>j)&1):
            op[bnk-j-1] = "+"
    tmp = ""
    for k in range(bnk):
        tmp += S[k]+op[k]
    tmp = tmp+S[3]
    if eval(tmp)==7:
        print(tmp+"=7")
        exit()
Problem p03671 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

a, b, c = map(int,readline().split())
print(min(a + b, b + c, c + a))

Buggy submission (verdict: Runtime Error):
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

a,b,c = sorted(map(int,input().split()))
print (a + b)
Problem p03738 (python)

Fixed submission:
a = int(input())
b = int(input())
print("GREATER" if a>b else "LESS" if a<b else "EQUAL")

Buggy submission (verdict: Runtime Error):
a,b =map(int,input().split())
print("GREATER" if a>b else "LESS" if a<b else "equal")
Problem p03777 (python)

Fixed submission:
a,b=input().split()
print("H" if a==b else "D")

Buggy submission (verdict: Runtime Error):
a,b=input.split()
print("H" if a==b else "D")
Problem p02953 (python)

Fixed submission:
N = int(input())

H_ls = list(map(int,input().split(" ")))

h_left = H_ls[0]-1

ans = "Yes"
for h in H_ls:
    if h_left < h:
        h-=1
    elif h_left > h:
        ans = 'No'
        break
    h_left = h

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())

H_ls = list(map(int,input().split(" ")))

h_left = H_ls[0]-1

ans = "Yes"
for h in H_ls:
    if h_left < h:
        h-=1:
    elif h_left > h:
        ans = 'No'
        break:
    h_left = h

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())

H_ls = list(map(int,input().split(" ")))

h_left = H_ls[0]-1

ans = "Yes"
for h in H_ls:
    if h_left < h:
        h-=1:
    elif h_left > h:
        ans = 'No'
        break:
    h_left = h

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())

H_ls = list(map(int,input().split("")))

h_left = H_ls[0]-1

ans = "Yes"
for h in H_ls:
    if h_left < h:
        h-=1:
    elif h_left > h:
        ans = 'No'
        break:
    h_left = h

print(ans)

Buggy submission (verdict: Runtime Error):

import numpy as np
from scipy import signal

N = int(input())
H = list(map(int, input().split(" ")))

H = np.array(H)

H_dif = H[1:]-H[:-1]

if (H_dif <=-2).any() == True:
    ans = "No"
elif (H_dif >= 0).all() == True:
    ans = "Yes"

else:
    ans = 'Yes'
    min_ind = signal.argrelmin(H)[0]
    tmp_ind = 0
    for ind in min_ind:
        
        if H[tmp_ind:ind].max() > H[ind]+1:
            ans = 'No'
            break
        tmp_ind = ind

    if H[tmp_ind:ind].max() > H[-1]+1:
        ans = 'No'

print(ans)

Buggy submission (verdict: Runtime Error):

import numpy as np
N = int(input())
H = list(map(int, input().split(" ")))

H = np.array(H)

H_dif = H[1:]-H[:-1]

if (H_dif <=-2).any() == True:
    answer = "No"

elif (H_dif >= 0).all() == True:
    ans = "Yes"
else:
    H_check = (H_dif == -1)
    H_c = H_check[1:].dot(H_check[:-1])
    if (H_c == 1).any() == True:
        ans = "No"
    else:
        ans = "Yes"

print(ans)
Problem p02971 (python)

Fixed submission:
import numpy as np

N = int(input())
A = np.zeros(N)

for i in range(N):
    A[i] = int(input())

ind = A.argsort()[::-1][:2]

first_a = A[ind[0]]
second_a = A[ind[1]]

for i, a in enumerate(A):
    if i == ind[0]:
        print(int(second_a))
    else:
        print(int(first_a))

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

N = int(input())
A = np.zeros(N)

for i in range(N):
    A[i] = int(input())

ind = A.argsort()[:2:-1]

first_a = A[ind[0]]
second_a = A[ind[1]]

for i, a in enumerate(A):
    if i == ind[0]:
        print(second_a)
    else:
        print(first_a)

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

N = int(input())
A = np.zeros(N)

for i in range(N):
    A[i] = int(input())

ind = A.argsort()[:2]

first_a = A[ind[0]]
second_a = A[ind[1]]

for i, a in A:
    if i == ind[0]:
        print(second_a)
    else:
        print(first_a)
Problem p03147 (python)

Fixed submission:
import numpy as np

N = int(input())
h_ls = list(map(int,input().split(" ")))

h_ls = np.array(h_ls)
n = 0
h_len = len(h_ls)
while max(h_ls)!=0:
    max_ind = h_ls.argmax()
    d = 0
    while max_ind+d < h_len -1 and h_ls[max_ind+d+1]==h_ls[max_ind]:
        d+=1
    h_ls[max_ind:max_ind+d+1] =h_ls[max_ind:max_ind+d+1]-1
    n+=1

print(n)

Buggy submission (verdict: Runtime Error):
N = int(input())
h_ls = list(map(int,input().split(" ")))

h_ls = np.array(h_ls)
n = 0
h_len = len(h_ls)
while max(h_ls)!=0:
    max_ind = h_ls.argmax()
    d = 0
    while max_ind+d < h_len -1 and h_ls[max_ind+d+1]==h_ls[max_ind]:
        d+=1
    h_ls[max_ind:max_ind+d+1] =h_ls[max_ind:max_ind+d+1]-1
    n+=1

print(n)

Buggy submission (verdict: Runtime Error):
N = int(input())
h_ls = list(map(int,input().split(" ")))

h_ls = np.array(h_ls)
n = 0
h_len = len(h_ls)
while max(h_ls)!=0:
    max_ind = h_ls.argmax()
    d = 0
    while max_ind+d < h_len -1 and h_ls[max_ind+d+1]==h_ls[max_ind]:
        d+=1
    h_ls[max_ind:max_ind+d+1] =h_ls[max_ind:max_ind+d+1]-1
    n+=1
    print(h_ls)

print(n)
Problem p02554 (python)

Fixed submission:
N = int(input())
ans = 10 ** N - ((9 ** N) * 2 - 8 ** N)
print(ans % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
from scipy.special import comb as c
N = int(input())
if N == 1: print(0)
else:
  ans = 0
  for i in range(1, N):
    ans += c(i+1, N-1, exact=True)
print(ans % (10 ** 9 + 7))
Problem p02582 (python)

Fixed submission:
S = input()
count = 0
ans = 0
for i in range(3):
  if S[i] == "R":
    count += 1
    ans = max(ans, count)
  else:
    ans = max(ans, count)
    count = 0


print(ans)

Buggy submission (verdict: Runtime Error):
D, T, S = map(int,input().split())
if S * T >= D: print("Yes")
else: print("No")
Problem p02756 (python)

Fixed submission:
S = input()
Q = int(input())
Query = list(input().split() for _ in range(Q))

count = 0
L, R = "", ""

for i in range(Q):
  if Query[i][0] == "1": count += 1
  else:
    if Query[i][1] == "1":
      if count % 2 == 0: L = Query[i][2] + L
      else: R += Query[i][2]
    else:
      if count % 2 == 0: R += Query[i][2]
      else: L = Query[i][2] + L

if count % 2 == 0: print(L + S + R)
else: print(R[::-1] + S[::-1] + L[::-1])

Buggy submission (verdict: Runtime Error):
S = input()
Q = int(input())
Query = list(input().split() for _ in range(Q))

count = 0
L, R = "", ""

for i in range(Q):
  if Query[i][0] == "1": count += 1
  else:
    if Query[i][1] == "1":
      if count % 2 == 0: L = Query[i][2] + L
      else: R += Query[i][2]
    else:
      if count % 2 == 0: R += Query[i][2]
      else: L = Query[i][2] + L
  print(L + S + R)

if count % 2 == 0: print(L + S + R)
else: print(R[::-1] + S[::-1] + L[::-1])
Problem p02761 (python)

Fixed submission:
def main():
  N, M = map(int,input().split())
  sc = list(list(input().split()) for _ in range(M))

  li = [""] * N

  for i in range(M):
    j = li[int(sc[i][0]) - 1]
    if j == "": li[int(sc[i][0]) - 1] = sc[i][1]
    elif j != sc[i][1]: return -1

  for i in range(N):
    if i == 0:
      if li[0] == "0" and N != 1: return -1
      if li[0] == "":
        if N == 1: li[0] = "0"
        else: li[0] = "1"
    elif li[i] == "": li[i] = "0"

  return "".join(li)

print(main())

Buggy submission (verdict: Runtime Error):
def main():
  N, M = map(int,input().split())
  sc = list(list(input().split()) for _ in range(M))

  li = [""] * N

  for i in range(M):
    j = li[int(sc[i][0]) - 1]
    if j == "": li[int(sc[i][0]) - 1] = sc[i][1]
    elif j != sc[i][1]: return -1

  for i in range(N):
    if i == 0:
      if li[0] == "0" and N != 1: return -1
      if li[0] == "":
        if N == 1: li[0] = "0"
        elif: li[0] = "1"
    elif li[i] == "": li[i] = "0"

  return "".join(li)

print(main())
Problem p02813 (python)

Fixed submission:
from itertools import permutations as p

N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

j = 0

for i in p(range(1, N + 1)):
  j += 1
  if i == P: a = j
  if i == Q: b = j

if a - b >= 0: print(a - b)
else: print(b - a)

Buggy submission (verdict: Runtime Error):
from itertools import permutations as p

N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

j = 1

for i in p(range(1, N + 1)):
  if i == P: a = j
  elif i == Q: b = j
  j += 1

if a - b >= 0: print(a - b)
else: print(b - a)