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

Fixed submission:
N,T = map(int,input().split())
t = list(map(int,input().split()))
sum = 0
for i in range(N-1):
  sum += min(T,(t[i+1]-t[i]))
print(sum+T)

Buggy submission (verdict: Runtime Error):
N,T = map(int,input().split())
t = list(map(int,input().split()))
sum = 0
for i in range(N-1):
  sum += (T,t[i+1]-t[i])
print(sum)

Buggy submission (verdict: Runtime Error):
N,T = map(int,input().split())
t = list(map(int,input().split()))
sum = 0
sum += t[0]
for i in range(N-1):
  sum += (T,t[i+1]-t[i])
print(sum)
Problem p03777 (python)

Fixed submission:
a,b = map(str,input().split())
num = 0
if a == "D":
  num = num + 1
if b == "D":
  num = num + 1
if num%2 == 0:
  print("H")
else:
  print("D")

Buggy submission (verdict: Runtime Error):
a,b = map(str,input().split())
num = 0
if a == "D"
  num = num + 1
if b == "D"
  num = num + 1
if num%2 == 0:
  print("H")
else:
  print("D")
Problem p03795 (python)

Fixed submission:
N = int(input())
K = N//15
print(800*N-200*K)

Buggy submission (verdict: Runtime Error):
N = int(input())
print(N*500-200*(N//15)

Buggy submission (verdict: Runtime Error):
N = int(input())
print(N*500-200*(N//15)
Problem p03827 (python)

Fixed submission:
N = int(input())
S = input()
K = []
ans = 0
K.append(0)
for i in range(N):
  if S[i] == "I":
    ans += 1
    K.append(ans)
  else:
    ans -= 1
    K.append(ans)
print(max(K))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
K = []
ans = 0
for i in range(S):
  if S[i] == "I":
    ans += 1
    K.append(ans)
  else:
    ans -= 1
    K.append(ans)
print(max(K))
Problem p03830 (python)

Fixed submission:
import math
def factorization(n):
    i = 2
    factors = []
    while i <= math.floor(n**0.5):
        if n%i == 0:
            factors.append(i)
            n //= i
        else:
            i += 1
    if n>1:
        factors.append(n)
    return factors
#約数列挙
N = int(input())
ls = []
if N == 1:
    print(1)
else:
    for i in range(1,N+1):
        ls.extend(factorization(i))
    ls.sort()
    ans = 1
    now = 1
    now_2 = 0
    for i in range(len(ls)):
        if i == 0:
            now_2 = ls[i]
        else:
            if ls[i] == now_2:
                now += 1
            else:
                ans *= (now+1)
                now = 1
                now_2 = ls[i]
    ans *= (now+1)
    print(ans%(10**9+7))

Buggy submission (verdict: Runtime Error):
import math
def factorization(n):
    i = 2
    factors = []
    while i <= math.floor(math.sqrt(n)):
        print(i,n)
        if n%i == 0:
            factors.append(i)
            n //= i
        else:
            i += 1
    if n > 1:
        factors.append(n)
    return factors
N = int(input())
S = math.factorial(N)
print(S)
print(factorization(S))

Buggy submission (verdict: Runtime Error):
def factorization(n):
    i = 2
    factors = []
    while i <= math.floor(n**0.5):
        if n%i == 0:
            factors.append(i)
            n //= i
        else:
            i += 1
    if n>1:
        factors.append(n)
    return factors
#約数列挙
N = int(input())
ls = []
for i in range(1,N+1):
    ls.extend(factorization(i))
ls.sort()
ans = 1
now = 1
now_2 = 0
for i in range(len(ls)):
    if i == 0:
        now_2 = ls[i]
    else:
        if ls[i] == now_2:
            now += 1
        else:
            ans *= (now+1)
            now = 1
            now_2 = ls[i]
ans *= (now+1)
print(ans%(10**9+7))
Problem p03860 (python)

Fixed submission:
A = input().split()
print("{}{}{}".format(A[0][0],A[1][0],A[2][0]))

Buggy submission (verdict: Runtime Error):
A = input().split()
print({}{}{}.format(A[0],A[1][0],A[2])
Problem p03943 (python)

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

Buggy submission (verdict: Runtime Error):
w,h,n = map(int,input().split())
x_min = 0
y_min = 0
x_max = w
y_max = h
for i in range(n):
  x,y,a = map(int,input().split())
  if a == 1:
    if x_min < x:
      x_min = x
  elif a == 2:
    if x_max > x:
      x_max = x
  elif a == 3:
    if y_min < y:
      y_min = y
  elif a == 4:
    if y_max > y:
      y_max = y
S = (x_max-x_min)*(y_max-y_min)
if S < 0:
  print(0)
else:
  print(S)
Problem p03970 (python)

Fixed submission:
S = input()
K = "CODEFESTIVAL2016"
sum = 0
for i in range(len(S)):
  if S[i] != K[i]:
    sum += 1
print(sum)

Buggy submission (verdict: Runtime Error):
S = input()
K = "CODEFESTIVAL2016"
sum = 0
for i in range(len(S)):
  if S[i] != K[i]
  sum += 1
print(sum)
Problem p04011 (python)

Fixed submission:
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
if N<=K:
  print(int(N*X))
else:
  print(int((K*X)+(N-K)*Y))

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
if N<=K:
  print(N*X)
else:
  print(K*X)+(N-K)*Y

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
if N<=K:
  print(N*X)
else:
  print(K*X)+(N-K)*Y

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
if N=<K:
  print(N*X)
else:
  print(K*X)+(N-K)*Y
Problem p04029 (python)

Fixed submission:
N = int(input())
print(int(0.5*N*(N+1)))

Buggy submission (verdict: Runtime Error):
N = int(input())
print(0.5*n*(n+1))
Problem p04033 (python)

Fixed submission:
a,b = map(int,input().split())
if a == 0 or b == 0:
    print("Zero")
else:
    if 0<a<=b:
        print("Positive")
    elif a<=0<b:
        print("Zero")
    elif a<=b<0:
        if abs(a+b)%2 == 0:
            print("Negative")
        else:
            print("Positive")

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
num = 1
for i in range(a,b+1):
  num = num * i
if num>0:
  print("Positive")
elif num<0:
  pirnt("Negative")
else:
  print("Zero")
Problem p04043 (python)

Fixed submission:
A = list(map(int,input().split()))
if (A.count(5)) == 2 and (A.count(7)) == 1:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
A = llist(map(int,input().split()))
if (A.count(5)) == 2 and (A.count(7)) == 1:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
A = list(int,input().split())
if (A.count(5)) == 2 and (A.count(7)) == 1:
  print("YES")
else:
  print("NO")
Problem p02534 (python)

Fixed submission:
K = int(input())
P = str("ACL")
D = print(P*K)

Buggy submission (verdict: Runtime Error):
A,B,C,D = list(map(int,input().split()))
 
for num in range (A <= B):
    if num in range (C<=D):
        print("Yes")
        break
    else:
        print("No")

Buggy submission (verdict: Runtime Error):
A,B,C,D = list(map(int,input().split()))
for num in range (A,B+1):
    if num in range (C,D+1):
        print("Yes")
        break
else:
    print("No")

Buggy submission (verdict: Runtime Error):
A,B,C,D = list(map(int,input().split()))
for num in range (A,B+1):
    if num in range (C,D+1):
        print("Yes")
        break
else:
        print("No")
Problem p02663 (python)

Fixed submission:
H1, M1, H2, M2, K = map(int, input().split())
hour1 = (H1 * 60) + M1
hour2 = (H2 * 60) + M2
hour = hour2 - hour1
minute = hour - K
print(minute)

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
e = (c-a)*60
print(e-d)
Problem p02681 (python)

Fixed submission:
s = input()
t = input()
check = t[:-1]
a = len(s)
b = len(t) - 1
if a == b:
    if s == check:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a = str(input())
b = str(input())
if a = 'chokudai' and b = 'chokudaiz' or a = 'a' and b = 'aa':
    print("Yes")
elif a = 'snuke' and b = 'snukee':
    print("No")

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
if a = 'chokudai' and b = 'chokudaiz' or a = 'a' and b = 'aa':
    print("Yes")
elif a = 'snuke' and b = 'snukee':
    print("No")

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
if a = 'chokudai' and b = 'chokudaiz' or a = 'a' and b = 'aa':
    print("Yes")
elif a = 'snuke' and b = 'snukee':
    print("No")
Problem p02687 (python)

Fixed submission:
s = input()
if s== 'ABC':
    print("ARC")
elif s=='ARC':
    print("ABC")
else:
    pass

Buggy submission (verdict: Runtime Error):
s = input()
for i in range(s):
  if s[i] ='B':
    s[i] = 'R'
print("".join(s))
Problem p02690 (python)

Fixed submission:
x=int(input())
for i in range(-200,200):
  for j in range(-200,200):
    if (i**5)-(j**5)==x:
      print(i,j)
      exit()

Buggy submission (verdict: Runtime Error):
s = int(input())
for i in range(-s, s):
    for j in range(-s, s):
    if i**5-j**5 == s:
        if i > j:
            print(i, j) 
            break

Buggy submission (verdict: Runtime Error):
s = int(input())
j= -1
for i in range(-s, s):
    for j in range(-s, s):
    if i**5-j**5 == s:
        if i > j:
            print(i, -1) 
            break

Buggy submission (verdict: Runtime Error):
s =input()
for i in range(-s, s):
  for j in range(-s, s):
    if i**5-j**5= s:
      print(i, j)
      break
Problem p02706 (python)

Fixed submission:
n,m= map(int, input().split())
a = list(map(int, input().split()))
c = n-sum(a)
if m == len(a) and c>= 0:
    print(c)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n, len(a)= map(int, input().split())
a= list(map(int, input().split()))
c= n-sum(a)
print(c)

Buggy submission (verdict: Runtime Error):
n, len(a)= map(int, input().split())
a= list(map(int, input().split()))
c= n-sum(a)
print(c)
Problem p02718 (python)

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

check = ((1 / (4 * M)) * sum(A))
x = 0
for item in A:
    if item < check:
        x += 1

ans = N - x

if ans >= M :
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
 
check = ((1 / (4 * M)) * sum(A))
x = 0
for item in A:
    if item < check:
        x += 1
        ans = N - x
 
if ans >= M :
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
 
check = ((1 / (4 * M)) * sum(A))
x = 0
for item in A:
    if item < check:
        x += 1
        ans = N - x
 
if ans >= M :
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(set((map(int, input().split()))))
vote = []
for Ai in A:
	if Ai > (1 / (4 * M) * sum(A)):
      vote.append(Ai)
if len(vote) >= M:
    print("Yes")
else:
    print("No")
Problem p02731 (python)

Fixed submission:
s = int(input())
print(s*s*s/27)

Buggy submission (verdict: Runtime Error):
s = input(int())
print(s*s*s/27)
Problem p02885 (python)

Fixed submission:
a, b = map(int, input().split())
print(max(0, a - 2 * b))

Buggy submission (verdict: Runtime Error):
a, b = map(int, intput().split())
print(max(0, a - 2 * b))
Problem p02946 (python)

Fixed submission:
k, x = map(int, input().split())
for i in range(x - k + 1, x + k):
  print(i, end = " ")

Buggy submission (verdict: Runtime Error):
k, x = map(int, input().split())
for i in range(max(1, x - 3), x + 4, 1):
  preint(i)
Problem p03047 (python)

Fixed submission:
n,k = map(int,input().split())
print(n-k+1)

Buggy submission (verdict: Runtime Error):
import math
n= int(input())
ans = 0
if math.sqrt(n) == int(math.sqrt(n)):
    for i in range(1,int(math.sqrt(n))):
        if (n-i) % i == 0:
            ans += (n-i) // i
else:
    for i in range(1,int(math.sqrt(n) + 1)):
        if (n-i) % i == 0:
            ans += (n-i) // i
print(ans)
Problem p03325 (python)

Fixed submission:
N = int(input())
a = map(int,input().split())
k = 0
for i in a:
    while i%2 == 0:
        k+=1
        i/=2
print(k)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = map(int,input().split())
k = 1
for i in a:
    k*=i
l = 0
while k%2 == 0:
    l += 1
    k /= 2
print (l)
Problem p03545 (python)

Fixed submission:
import sys, ast

def dfs(str_input,count = 1):
    if count == 7:
        if ast.literal_eval(str_input) == 7:
            print(str_input + "=7")
            sys.exit(0)
        else:
            return 0
    for i in ["+","-"]:
        dfs(str_input[:count] + i + str_input[count:], count = count + 2)

x = input()

dfs(x)

Buggy submission (verdict: Runtime Error):
import sys, ast

def dfs(str_input,count = 1):
    if count == 7:
        if ast.literal_eval(str_input) == 7:
            sys.exit(str_input + "=7")
        else:
            return 0
    for i in ["+","-"]:
        dfs(str_input[:count] + i + str_input[count:], count = count + 2)

x = input()

dfs(x)

Buggy submission (verdict: Runtime Error):
import sys, ast

def dfs(str_input,count = 1):
    if count == 7:                                                      #演算子を挿入完了
        if ast.literal_eval(str_input) == 7:
            sys.exit(str_input + "=7")
        else:       　　　　　　　　　　　　　　　　　　　　#和が7にならなかった場合は何もしない
            return 0
    for i in ["+","-"]:
        dfs(str_input[:count] + i + str_input[count:], count = count + 2)　　#演算子の挿入

x = input()

dfs(x)
Problem p03587 (python)

Fixed submission:
s=input()
ans=0
for i in s:
    ans+=int(i)
print(ans)

Buggy submission (verdict: Runtime Error):
a=int(input())
ans=0
for i in a:
  ans+=1
print(ans)
Problem p03773 (python)

Fixed submission:
A,B=[int(i) for i in input().split()]
print((A+B)%24)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
print((A+B)%24)
Problem p02584 (python)

Fixed submission:
x,k,d = map(int,input().split())
#print(x,k,d)
x=abs(x)
a = x//d
b = x%d

if k <= a:
    print(abs(x-k*d))

else:
    tmp = k-a
    if tmp%2 == 0:
        print(x-a*d)
    else:
        print(abs(x-(a+1)*d))

Buggy submission (verdict: Runtime Error):
a = abs(x//d)
b = x%d

if k <= a:
    print(abs(abs(x)-k*d))

else:
    tmp = k-abs(a)
    if tmp%2 == 0:
        print(abs(x)-a*d)
    else:
        print(abs(abs(x)-(a+1)*d))
Problem p02660 (python)

Fixed submission:
n = int(input())

if n == 1:
    print(0)
    exit()

def factorization(n):
    seq = []
    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
            seq.append([i, cnt])

    if temp!=1:
        seq.append([temp, 1])

    if seq==[]:
        seq.append([n, 1])

    return seq

so = factorization(n)

ans = 0
for i in range(len(so)):
    j = 1
    mun = so[i][1]
    while mun >= j:
        if mun - j >= 0:
            ans += 1
            mun -= j
            j += 1

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
#print(n)

import math

def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]

import collections
from collections import defaultdict

def prime_factorization_1(num):
    if num <= 1:
        return False
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        dict_counter = defaultdict(int)
        for prime in prime_list:
            while num % prime == 0:
                dict_counter[prime] += 1
                num //= prime
        if num != 1:
            dict_counter[num] += 1

        dict_counter = dict(dict_counter)

        return dict_counter

x = prime_factorization_1(n)
#print(x)
y = list(x.keys())
z = list(x.values())
#print(y)
#print(z)

l = []
for i in range(len(y)):
    l += [y[i]]*z[i]
#print(l)

ans = []
tmp = 1
for j in l:
    if j not in ans:
        ans.append(j)
    else:
        r = tmp * j
        if r != tmp:
            if r not in ans:
                ans.append(r)
                tmp = 1
            else:
                tmp = r
#print(ans)
print(len(ans))
Problem p02683 (python)

Fixed submission:
import numpy as np 
from itertools import combinations

n,m,x = map(int, input().split())
n_num = [_ for _ in range(n)]

l = np.array([list(map(int, input().split())) for _ in range(n)])

ptns = []
for i in range(n):
    ptns += list(combinations(n_num, i+1))

ans = float('inf')
for j in range(len(ptns)):
    tmp = np.array([0]*(m+1))
    for k in range(len(ptns[j])):
        tmp += l[ptns[j][k]]
    if min(tmp[1:]) >= x:
        ans = min(ans, tmp[0])
    
print(-1 if ans == float('inf') else ans)

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

n,m,x = map(int, input().split())
n_num = [_ for _ in range(n)]

l = np.array([list(map(int, input().split())) for _ in range(n)])

ptns = []
for i in range(n):
    ptns += list(combinations(n_num, i+1))

ans = float('inf')
for j in range(len(ptns)):
    tmp = np.array([0]*(m+1))
    for k in range(len(ptns[j])):
        tmp += l[ptns[j][k]]
    if min(tmp[1:-1]) >= x:
        ans = min(ans, tmp[0])
    
print(-1 if ans == float('inf') else ans)
Problem p02684 (python)

Fixed submission:
n, k = map(int, input().split())
#print(n,k)
goto = [-1] + list(map(int, input().split()))
#print(goto)

l = [[_, 0] for _ in range(2*n)] # [順番, 町番号]
#print(l)
cnt = [0 for _ in range(n+1)] # カウンター

tmp = 1
for i in range(1, 2*n):
    l[i][1] = tmp
    cnt[l[i][1]] += 1
    tmp = goto[tmp]
    if cnt[l[i][1]] == 2:
        x = l[i]
        break
#print(l)
#print(x)

for j in range(n):
    if l[j][1] == x[1]:
        y = l[j]
        break
#print(y)

if y[0] > k:
    print(l[k+1][1])
else:
    z = (k-y[0]+1) % (x[0]-y[0]) + y[0]
    print(l[z][1])

Buggy submission (verdict: Runtime Error):
n, k = map(int,input().split())
l = [0] + list(map(int,input().split()))
places = [0 for _ in range(n+1)]
to = 1
time_2 = 0

for i in range(10**5+1):
    if places[to] == 1:
        x = to
        y = time_2
        break
    else:
        places[to] = 1
        to = l[to]
        time_2 += 1

to = 1
time_1 = 0
for j in range(y):
    if to == x:
        z = time_1
        break
    else:
        to = l[to]
        time_1 += 1

to = l[1]
if k >= z:
    for p in range(z):
        to = l[p]
    else:
        print(l[to])
else:
    for q in range((k-z)%(y-z)):
        to = l[q]
    else:
        print(l[to])
Problem p02696 (python)

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

if n >= b-1:
    x = b-1
else:
    x = n

print(a*x//b - a*(x//b))

Buggy submission (verdict: Runtime Error):
a, b, n = map(int,input().split())

ans = 0
for i in range(1, n+1):
    ans = max(ans, a*i//b - a*(i//b))

print(max(ans))
Problem p02702 (python)

Fixed submission:
s = input()[::-1]

cnts = [1] + [0] * (2019 - 1)
tmp = 0
d = 1

for i in s:
    tmp += int(i) * d
    cnts[tmp % 2019] += 1
    d = d * 10 % 2019 # 桁数が大きくなりすぎる → 10と2019が素だから可能

ans = 0
for cnt in cnts:
    ans += (cnt - 1) * cnt // 2

print(ans)

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

@jit
def solve():
    
    s = np.array(list(input())[::-1])
    num = len(s)
    #print(s, num)
    
    l = np.array([])
    for i in range(1,num+1):
        l.append(int(''.join(s[:i][::-1])))
    #print(l)
    
    mod = []
    for j in range(num):
        mod.append(l[j] % 2019)
    mod = np.array(mod)
    
    ans = 0
    for p in range(num):
        if mod[p] == 0:
            ans += 1
        tmp = 1
        for q in range(p+1,num):
            if mod[p] == mod[q]:
                tmp += 1
        ans += (tmp-1)*tmp//2
    
    print(ans)

solve()
Problem p02720 (python)

Fixed submission:
n = int(input())
l = [_ for _ in range(1,10)]

for i in range(10**5):
    if str(l[i])[-1] == '0':
        l.append(l[i]*10 + int(str(l[i])[-1]))
        l.append(l[i]*10 + int(str(l[i])[-1]) + 1)

    elif str(l[i])[-1] == '9':
        l.append(l[i]*10 + int(str(l[i])[-1]) - 1)
        l.append(l[i]*10 + int(str(l[i])[-1]))

    else:
        l.append(l[i]*10 + int(str(l[i])[-1]) - 1)
        l.append(l[i]*10 + int(str(l[i])[-1]))
        l.append(l[i]*10 + int(str(l[i])[-1]) + 1)

print(l[n-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [_ for _ in range(1,10)]

cnt = 9
d = [-1, 0, 1]
for i in range(10**5):
    if cnt >= n: break
    for j in d:
        if 0 <= int(str(l[i])[-1]) + j <= 9:
            l.append(l[i]*10 + l[i][-1] + j)
            cnt += 1

print(l[n-1])
Problem p02756 (python)

Fixed submission:
from collections import deque

s = deque(input())
n = int(input())
l = [input().split(" ") for _ in range(n)]

x = 0
for i in range(n):
    if l[i][0]=='1':
        if x == 0:
            x = 1
        else:
            x = 0
    elif l[i][0]=='2':
        if x == 0:
            if l[i][1]=='1':
                s.appendleft(l[i][2])
            else:
                s.append(l[i][2])
        else:
            if l[i][1]=='1':
                s.append(l[i][2])
            else:
                s.appendleft(l[i][2])

if x == 0:
    print(''.join(s))
else:
    print(''.join(reversed(s)))

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

s = deque(input())
n=int(input())
l = [input().split(" ") for _ in range(n)]

x = 0
for i in range(n):
    if l[i][0]=='1':
        if x == 0:
            x = 1
        else:
            x = 0
    elif l[i][0]=='2':
        if x == 0:
            if l[i][1]=='1':
                s.appendleft(l[i][2])
            else:
                s.append(l[i][2])
        else:
            if l[i][1]=='1':
                s.append(l[i][2])
            else:
                s.appendleft(l[i][2])

if x == 0:
    print(''.join(s))
else:
    print(''.join(s[::-1]))
Problem p02761 (python)

Fixed submission:
n, m = map(int, input().split())
ans = [-1 for _ in range(n)]
l = [list(map(int, input().split())) for _ in range(m)]

if m == 0:
    if n == 1:
        print(0)
        exit()
    elif n == 2:
        print(10)
        exit()
    elif n == 3:
        print(100)
        exit()

for q in range(m):
    if l[q][0] == 1:
        break
else:
     ans[0] = 1

for k in range(m):
    if l[k][1] != 0:
        break
    for p in range(m):
        if l[p][0] == 1:
            break
        else:
            if n ==2:
                print(10)
                exit()
            elif n == 3:
                print(100)
                exit()

else:
    if n == 1:
        print(0)
        exit()
    else:
        print(-1)
        exit()

for i in range(m):
    if l[i][0] == 1 and l[i][1] == 0:
        print(-1)
        break
    if ans[l[i][0]-1] != -1 and ans[l[i][0]-1] != l[i][1]:
        print(-1)
        break
    else:
        ans[l[i][0]-1] = l[i][1]

else:
    for j in range(n):
        if ans[j] == -1:
            ans[j] = 0

    print(''.join(list(map(str,ans))))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
l = [list(map(int, input().split())) for _ in range(m)]

p = [[],[],[]]
for i in range(m):
    if l[i][0]== 1:
        p[0].append(l[i][1])
    elif l[i][0]== 2:
        p[1].append(l[i][1])
    else:
        p[2].append(l[i][1])

#print(p)

if len(p[0]) == 0:
        p[0].insert(0,1)
#print(p)

for j in range(len(p)):
    if len(p[j]) == 0:
        p[j].append(0)

#print(p)

if len(set(p[0])) > 1 or len(set(p[1])) > 1 or len(set(p[2])) > 1:
    print('-1')
    exit()

q = []
for k in range(len(p)):
    q.append(str(p[k][0]))
#print(q)
if n = 1 and q[0] == '0':
    print(0)
    exit()
    

if q[0] == '0':
    print('-1')
    exit()

if q[0] == '0' and q[1] == '0':
    print('-1')
    exit()

if q[0] == '0' and q[1] == '0' and q[2] == '0':
    print(0)
    exit()

print(''.join(q))