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

Fixed submission:
N = int(input())
digitSum = sum(list(map(int,str(N))))
if(N % digitSum == 0):
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N = input()
n = sum(list(map(int,N)))
if(N%n == 0):
  print("Yes")
else:
  print("No")

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

def num(n):
  return list(map(int,n))

if(N%sum(num(N)) == 0):
  print("Yes")
else:
  print("No")
Problem p03337 (python)

Fixed submission:
A, B = map(int,input().split())
add = A + B
sub = A - B
mul = A * B
print(max(add,sub,mul))

Buggy submission (verdict: Runtime Error):
a, b = map(int,input().split())
print(max(A+B,A-B,A*B))
Problem p03353 (python)

Fixed submission:
S = input()
K = int(input())
tmp = set()
for i in range(len(S)):
  for j in range(5):
    tmp.add(S[i:i+j+1])
print(sorted(tmp)[K-1])

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())

tmp = set()
for i in range(len(S)):
  for j in range(5):
    tmp.add(S[i:i+j])
print(sorted(tmp)[K])
Problem p03361 (python)

Fixed submission:
H, W = map(int,input().split())
HW = [input() for _ in range(H)]

ans = "Yes"
for i in range(H-1):
  for j in range(W-1):
    if(HW[i][j] == "."):
      continue
    if(i != 0 and HW[i-1][j] == "#"):
      continue
    if(j != 0 and HW[i][j-1] == "#"):
      continue
    if(j != H and HW[i+1][j] == "#"):
      continue
    if(j != W and HW[i][j+1] == "#"):
      continue
    ans = "No"
print(ans)

Buggy submission (verdict: Runtime Error):
H, W = sorted(map(int,input().split()))
C = [input() for _ in range(H)]

ans = "Yes"
for i in range(H-1):
  for j in range(W-1):
    if(C[i][j] == "#"):
      if(i != 0 and C[i-1][j] == "#"):
        continue
      if(i != H and C[i+1][j] == "#"):
        continue
      if(j != 0 and C[i][j-1] == "#"):
        continue
      if(j != W and C[i][j+1] == "#"):
        continue
      ans = "No"
print(ans)

Buggy submission (verdict: Runtime Error):
H, W = sorted(map(int,input().split()))
C = [input() for _ in range(H)]

ans = "Yes"
for i in range(H):
  for j in range(W):
    if(C[i][j] == "."):
      continue
    if(i > 0 and C[i-1][j] == "#"):
      continue
    if(i+1 < H and C[i+1][j] == "#"):
      continue
    if(j > 0 and C[i][j-1] == "#"):
      continue
    if(j+1 < W and C[i][j+1] == "#"):
      continue
    ans = "No"
print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
ans = "Yes"
for i in range(H):
  for j in range(W):
    if(S[i][j] == "#"):
      if(i != 0 and S[i-1][j] == "#"):
        continue
      if(i != H and S[i+1][j] == "#"):
        continue
      if(j != 0 and S[i][j-1] == "#"):
        continue
      if(j != W and S[i][j+1] == "#"):
        continue
      ans = "No"
print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
ans = "Yes"
for i in range(H):
  for j in range(W):
    if(S[i][j] == "#"):
      if(i != 0 and S[i-1][j] == "#"):
        continue
      if(i != H and S[i+1][j] == "#"):
        continue
      if(j != 0 and S[i][j-1] == "#"):
        continue
      if(j+1 < W and S[i][j+1] == "#"):
        continue
      ans = "No"
print(ans)
Problem p03377 (python)

Fixed submission:
A, B, X = map(int,input().split())
if(A <= X and X <= A+B):
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
A, B, X = map(int,input().split())
if(A <= X and A+B => X):
  print('YES')
else:
  print('NO')
Problem p03385 (python)

Fixed submission:
S = sorted(input())
if(S == ['a','b','c']):
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
S = sorted(input())
if(S = "abc"):
  print("Yes")
else:
  print("No")
Problem p03399 (python)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())
train = min(A, B)
bus = min(C, D)
print(train + bus)

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <cstdio>
using namespace std;

int main(){
  int a, b, c, d;
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> a >> b >> c >> d;
  cout << min(a,b) + min(c,d) << endl;
  return 0;
}
Problem p03408 (python)

Fixed submission:
N = int(input())
Blue = [input() for _ in range(N)]
M = int(input())
Red = [input() for _ in range(M)]
Blue_dic = {b: Blue.count(b) for b in Blue}
for k, v in Blue_dic.items():
  if(k in Red):
    Blue_dic[k] = v - Red.count(k)
print(max(max(Blue_dic.values()),0))

Buggy submission (verdict: Runtime Error):
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

tmp_S = {}
for s in S:
  if(s in tmp_S):
    tmp_S[s] += 1
  else:
    tmp_S[s] = 1
for t in T:
  if(t in tmp_S):
    tmp_S[t] -= 1
print(max(0, tmp_S.values()))
Problem p03415 (python)

Fixed submission:
arr = [input() for i in range(3)]
print(arr[0][0]+arr[1][1]+arr[2][2])

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[1] << c[2];
}
Problem p03470 (python)

Fixed submission:
N = int(input())
d = list(set([int(input()) for _ in range(N)]))
print(len(d))

Buggy submission (verdict: Runtime Error):
N = int(input())
d = list(set([int(input()) for _ in range(N)])
print(len(d))
Problem p03487 (python)

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

d = {}
for i in range(N):
  if(a[i] not in d):
    d[a[i]] = 1
  else:
    d[a[i]] += 1
cnt = 0
for k, v in d.items():
  if(k > v):
    cnt += v
  elif(k < v):
    cnt += v - k
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int,input().split()))
cnt = 0
ind = 1
while A != []:
  A = list(map(lambda x: x - 1, A))
  if(0 in A):
    zero = A.count(0)
    if(zero > ind):
      cnt += abs(zero - ind)
    elif(zero < ind):
      cnt += zero
    A = filter(lambda n: n != 0, A)
  ind += 1
print(cnt)
Problem p03502 (python)

Fixed submission:
N = input()
cnt = 0
for n in N:
  cnt += int(n)
if(int(N)%cnt == 0):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N = input()
if(N%sum(list(map(int,N))) == 0):
  print("Yes")
else:
  print("No")
Problem p03545 (python)

Fixed submission:
import itertools
A, B, C, D = list(input())

op = ['+','-']

for op1,op2,op3 in itertools.product(op,op,op):
  x = A + op1 + B + op2 + C + op3 + D
  if(eval(x) == 7):
    print(x + "=7")
    break

Buggy submission (verdict: Runtime Error):
import itertools
A, B, C, D = list(input())

op = ['+','-']

for a,b,c in itertools.product(op,op,op):
  x = A + op1 + B + op2 + C + op3 + D
  if(eval(x) == 7):
    print(x + "=7")
    break
Problem p03556 (python)

Fixed submission:
N = int(input())

x = N**(0.5)
if(N%x == 0):
  print(N)
else:
  print(int(x)**2)

Buggy submission (verdict: Runtime Error):
x = int(N**(0.5))
if(N%x == 0):
  print(N)
else:
  print((int(N**(0.5))-1)**2)
Problem p03565 (python)

Fixed submission:
S = input()
T = input()

len_S = len(S)
len_T = len(T)
for i in range(len_S-len_T, -1, -1):
  if not all(s in ['?', t] for s, t in zip(S[i:i+len_T], T)):
    continue
  print((S[:i] + T + S[i+len_T:]).replace('?','a'))
  exit()
print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
S = input()
T = input()

len_S = len(S)
len_T = len(T)
for i in range(len_S-len_T, -1, -1):
  if not all(s in ['?', t] for s, t in zip(S[i:i+len_T], T)):
    continue
  print((S[:i] + t + S[i+len_T:]).replace('?','a'))
  exit()
print("UNRESTORABLE")
Problem p03575 (python)

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

v = [i for i in range(1,N+1)]
e = [[]]*(N+1)
for i in range(M):
  a, b = map(int,input().split())
  e[a] = e[a] + [b]
  e[b] = e[b] + [a]

def dfs(v, e):
  for num in v:
    if(len(e[num]) == 1):
      tmp_num = e[num][0]
      v.remove(num)
      e[num] = []
      e[tmp_num].remove(num)
      #print(e,v)
      return dfs(v, e)+1
  return 0
print(dfs(v, e))

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

v = list(range(1,M+1))
edges = [[] for _ in range(M+1)]
for _ in range(M):
  a, b = map(int,input().split())
  edges[a] += [b]
  edges[b] += [a]

def dfs(v, e):
  for x in v:
    if(len(e[x]) == 1):
      t = e[x][0]
      e[x] = []
      e[t].remove(x)
      v.remove(x)
      return dfs(v, e)+1
  return 0

print(dfs(v, edges))

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

v = list(range(1,M+1))
edges = [[] for _ in range(M+1)]
for _ in range(M):
  a, b = map(int,input().split())
  edges[a] += [b]
  edges[b] += [a]

def f(v, e):
  for x in v:
    if(len(e[x]) == 1):
      t = e[x][0]
      e[x] = []
      e[t].remove(x)
      v.remove(x)
      return f(v, e)+1
  return 0

print(dfs(v, edges))

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

v = list(range(1,M+1))
edges = [[] for _ in range(M+1)]
for _ in range(M):
  a, b = map(int,input().split())
  edges[a] += [b]
  edges[b] += [a]

def dfs(v, e):
  for x in v:
    if(len(e[x]) == 1):
      t = e[x][0]
      e[x] = []
      e[t].remove(x)
      v.remove(x)
      return dfs(v, e)+1
  return 0

print(f(v, edges))
Problem p03611 (python)

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

nums = [0]*(10**5+10)
for a in A:
  nums[a] += 1
  nums[a-1] += 1
  nums[a+1] += 1
print(max(nums))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
result = [0]*(1000000001)
for a in A:
  result[a] += 1
  result[a-1] += 1
  result[a+1] += 1
print(max(result))
Problem p03624 (python)

Fixed submission:
S = sorted(input())
dic = "abcdefghijklmnopqrstuvwxyz"
for s in S:
  if(s in dic):
    dic = dic.replace(s,'')
if(dic != ''):
  print(dic[0])
else:
  print("None")

Buggy submission (verdict: Runtime Error):
S = input()
ans = "abcdefghijklmnopqrstuvwxyz"
for s in S:
  ans = ans.replace(s, "")
print(ans[0])
Problem p03625 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
d = {}
for a in A:
  if(a in d):
    d[a] += 1
  else:
    d[a] = 1
x, y = 0, 0
for k, v in d.items():
  if(v >= 2 and k > y):
    if(k >= x):
      if(v >= 4):
        y = k
      else:
        y = x
      x = k
    else:
      y = k
print(x * y)

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

d = {}
for x in X:
  num = A.count(x)
  d[x] = num
result = []
for k, v in d.items():
  if(v >= 4):
    result.append(k)
    result.append(k)
  elif(v >= 2):
    result.append(k)
result.sort()
print(result[-1] * result[-2])

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

two = [0]*N
four = [0]*N 
for x in list(set(A)):
  num = A.count(x)
  if(num >= 4):
    four[x] = x
  elif(num != 1):
    two[x] = x
two.sort()
four.sort()
print(max(four[-1]**2, two[-1]*two[-2]))
Problem p03633 (python)

Fixed submission:
N = int(input())

def gcd(a, b):
  while b:
    a, b = b, a%b
  return(a)

result = []
x = 1
for i in range(N):
  T = int(input())
  x = x * T // gcd(x, T)
  result.append(x)
print(max(result))

Buggy submission (verdict: Runtime Error):
N = int(input())
T = [int(input()) for _ in range(N)]

import math
def lcm(x, y):
  return (x*y) // math.gcd(x, y)

result = []
for i in range(N):
  try:
    result.append(lcm(T[i], T[i+1]))
  except:
    break
print(max(result))
Problem p03639 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
two_ad = 0
four_ad = 0
other = 0
for a in A:
  if a % 4 == 0:
    four_ad += 1
  elif a % 2 == 0:
    two_ad += 1
  else:
    other += 1

ans = "No"
if four_ad >= other:
  ans = "Yes"
elif four_ad == other - 1 and not two_ad:
  ans = "Yes"
print(ans)

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

two_ad = 0
four_ad = 0
other = 0
for _ in range(N):
  a = int(input())
  if a % 4 == 0 and a % 2 == 0:
    four_ad += 1
  elif a % 4 == 0:
    four_ad += 1
  elif a % 2 == 0:
    two_ad += 1
  else:
    other += 1

if not two_ad and not four_ad:
  ans = "No"
elif not two_ad:
  if other == four_ad + 1 or four_ad > other:
    ans = "Yes"
  else:
    ans = "No"
elif not four_ad:
  ans = "No"
elif not other:
  ans = "Yes"
elif four_ad == other == two_ad:
  ans = "Yes"
else:
  ans = "No"
print(ans)
Problem p03645 (python)

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

tmp = [0]*N
check = [0]*N
for _ in range(M):
  a, b = map(int,input().split())
  if(a == 1):
    tmp[b] += 1
  elif(b == N):
    check[a] += 1

for i in range(len(tmp)):
  if(check[i] == 1 and tmp[i] == 1):
    print("POSSIBLE")
    break
else:
  print("IMPOSSIBLE")

"""
tmp = [0]*N
for _ in range(M):
  a, b = map(int,input().split())
  if(a == 1):
    tmp[b] += 1
  elif(b == N):
    tmp[a] += 1

if(2 in tmp):
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")
"""

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

e = [0]*N
for _ in range(M):
  a, b = map(int,input().split())
  if(a == 1):
    e[a] += 1
  elif(b == N):
    e[b] += 1
if(2 in e):
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")
Problem p03679 (python)

Fixed submission:
X, A, B = map(int,input().split())
m = B - A
if(m <= 0):
  print("delicious")
elif(m <= X):
  print("safe")
else:
  print("dangerous")

Buggy submission (verdict: Runtime Error):
X, A, B = map(int,input().split())
m = B - A
if(m <= 0):
  print("delicious")
elif(X => m):
  print("safe")
else:
  print("dangerous")
Problem p03681 (python)

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

def factorical(n):
  ret = 1
  for i in range(1,n+1):
    ret *= i
    ret %= 10**9+7
  return ret

diff = abs(N - M)
max_ = int(1e9+7)

if(diff >= 2):
  print(0)
elif(diff == 1):
  n = N % max_
  m = M % max_
  print((factorical(n)*factorical(m)) % max_)
else:
  n = N % max_
  m = M % max_
  print((2*factorical(n)*factorical(m)) % max_)

Buggy submission (verdict: Runtime Error):
A, B = map(int,input().split())
mod = 10**9+7
def factorical(n):
  ret = 1
  for i in range(1,n+1):
    ret *= i
    ret %= 
  return ret%mod

a = factorical(A)
b = factorical(B)
if(abs(A-B) >= 2):
  print(0)
elif(A == B):
  print(a*b*2%mod)
else:
  print(a*b%mod)

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

def factorical(n):
  ret = 1
  for i in range(1,n+1):
    ret *= i%(10**9+7)
    ret %= (10**9+7)
  return ret%(10**9+7)

a = factorical(A)
b = factorical(B)
if(abs(M-N)>= 2):
  print(0)
elif(A == B):
  print(a*b*2%(10**9+7))
else:
  print(a*b%(10**9+7))
Problem p03721 (python)

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

cnt = 0
for a in A:
  if(cnt < K-a[1]):
    cnt += a[1]
  else:
    print(a[0])
    break
"""
unk buriburi
"""

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
AB = sorted([[list(map(int,input().split())) for _ in range(N)]])

tmp = 0
for a, b in AB:
  if(tmp < K-b):
    tmp += b
  else:
    print(a)
    break

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
AB = sorted([[list(map(int,input().split())) for _ in range(N)]])
cnt = 0
for a, b in AB:
  if(cnt < K - b):
    cnt += b
  else:
    print(a)
    break

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
AB = sorted([[list(map(int,input().split())) for _ in range(N)]])
cnt = 0
for a, b in AB:
  if(cnt < K - b)
    cnt += b
  else:
    print(a)
    break

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

result = [a for j in range(b) for a, b in A]
print(result[K+1])

"""
result = []
for a, b in A:
  for j in range(b):
    result.append(a)
print(result[K-1])
"""
Problem p03815 (python)

Fixed submission:
x = int(input())
ans = x//11 * 2
if(0 < x%11 < 7):
  ans += 1
elif(x%11 > 6):
  ans += 2
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  n = ni()
  ans = n // 11 * 2
  if 0 < x % 11 < 7:
    ans += 1
  elif x % 11 > 6:
    ans += 2
  print(ans)
main()
Problem p03846 (python)

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

mod = 10**9+7
if(N%2 == 0 and len(set(A)) == N//2):
  print(2**(N//2) % mod)
elif(N%2 != 0 and A.count(0) == 1):
  print(2**((N-1)//2) % mod)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))

def main():
  n = ni()
  a = na()

  if n % 2 == 0:
    if 0 in a:
      print(0)
      return 
    else:
      print(2 ** len(list(set(a))))
  else:
    zero = 0
    for aa in a:
      if aa == 0:
        zero += 1
    if zero > 1:
      print(0)
      return
    else:
      if zero == 1:
        print(2 ** (len(list(set(a)) - 1))
      else:
        print(2 ** len(list(set(a)))

main()
Problem p03919 (python)

Fixed submission:
H, W = map(int,input().split())
S = [input().split() for _ in range(H)]

for i in range(H):
  for j in range(W):
    if(S[i][j] == "snuke"):
      print(chr(64+(j+1))+str(i+1))

Buggy submission (verdict: Runtime Error):
H, W = map(int,input().split())
S = [input().split() for _ in range(H)]

w = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"]

for i in range(H):
  for j in range(W):
    if(S[i][j] == "snuke"):
      print(w[j]+str(i+1))
Problem p03943 (python)

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

if((a+b == c) or (b+c == a) or (a+c == b)):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
W, H, N = map(int,input().split())
dx, dy = 0, 0

for i in range(N):
  x, y, a = map(int,input().split())
  if(a == 1):
    dx = max(dx, x)
  elif(a == 2):
    W = min(W, x)
  elif(a == 3):
    dy = max(dy, y)
  else:
    H = min(H, y)
if(dx <= W or dy <= H):
  print(0)
else:
  print((dx-W) * (dy-H))
Problem p03951 (python)

Fixed submission:
N = int(input())
S = input()
T = input()
tmp = 0
for i in range(N, 0, -1):
  if(S[-i:] == T[:i]):
    tmp = i
    break
print(N*2-tmp)

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

for i in range(N, 0, -1):
  if(S[-i:] == T[:i]):
    tmp = i
    break
print(N*2-tmp)
Problem p03999 (python)

Fixed submission:
S = list(input())
"""
if(len(S) == 1):
  print(S[0])
  exit()
cnt = 0
for i in range(1 << len(S)-1):
  f = S[0]
  for j, b in enumerate(format(i, 'b').zfill(len(S)-1)):
    if(b == '1'):
      f += '+'
    f += S[j+1]
  cnt += sum(map(int,f.split('+')))
print(cnt)

"""

cnt = 0
for i in range(1 << len(S)-1):
  f = S[0]
  for j in range(len(S)-1):
    if(((i >> j) & 1)== 1):
      f += '+'
    f += S[j+1]
  cnt += sum(map(int, f.split('+')))
print(cnt)

Buggy submission (verdict: Runtime Error):
S = list(input())
cnt = 0
for i in range(1 << len(S)-1):
  f = S[0]
  for j, b in enumerate(format(i, 'b').zfill(len(S)-1)):
    if(b == '1'):
      f += '+'
    f += S[j+1]
  cnt += sum(map(int,f.split('+')))
print(cnt)
Problem p04013 (python)

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

X = [int(x) - A for x in input().split()]
dp = [[0 for _ in range(100*N+1)] for _ in range(N+1)]
dp[0][50*N] = 1

for i in range(N):
  for j in range(50, 100*N+1-50):
    dp[i+1][j] = dp[i][j] + dp[i][j - X[i]]
print(dp[N][50*N] - 1)

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

X = [int(x) - A for x in input().split()]
dp = [[0 for _ in range(100*N+1)] for _ in range(N+1)]
dp[0][50*N] = 1

for i in range(N):
  for j in range(50, 100*N+1-50):
    dp[i+1][j] = dp[i][j] + dp[i][j - X[i]]
print(dp[N][50*N] - 1)
Problem p02756 (python)

Fixed submission:
import sys
input = sys.stdin.readline
from collections import deque

S = input().rstrip()
S = deque(S)
Q = int(input())
Que = (input().rstrip() for _ in range(Q))

flag = 0 #0:そのまま 1:反転
for elem in Que:
  if elem[0] == '1':
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S.appendleft(elem[4])
    elif s == 2 and flag == 0:
      S.append(elem[4])
    elif s == 1 and flag == 1:
      S.append(elem[4])
    else:
      S.appendleft(elem[4])

if flag == 1:
  S.reverse()
print(''.join(S))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
from collections import deque

S = input().rstrip()
S = deque(S)
Q = int(input())
Que = (input().rstrip() for _ in range(Q))

flag = 0 #0:そのまま 1:反転
for elem in Que:
  if elem[0] == '1':
    flag ^= 1
  else:
    s = int(elem[2])
    if s == 1 and flag == 0:
      S.appendleft(elem[4])
    elif s == 2 and flag == 0:
      S.append(elem[4])
    elif s == 1 and flag == 1:
      S.append(elem[4],0)
    else:
      S.appendleft(elem[4])

if flag == 1:
  S.reverse()
print(''.join(S))
Problem p03125 (python)

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

if b % a == 0:
  print(a+b)
else:
  print(b-a)

Buggy submission (verdict: Runtime Error):
import copy

n, m = map(int, input().rstrip().split())
number_list = list(map(int, input().rstrip().split()))
number_list.sort()
match = [2, 5, 5, 4, 5, 6, 3, 7, 6]
new_match = []
answer = []

for i in number_list:
    new_match.append(match[i-1])


for index in range(m):
    value = new_match[index]
    new_match_tmp = copy.copy(new_match)
    new_match_tmp.remove(value)
    maximum = max(new_match_tmp)
    #商と余りを計算
    quotient = int(n / value)
    remainder = n % value
    answer_tmp = [number_list[index]] * quotient
    #余りがあるなら余りをなくすように組み合わせを考える
    if remainder != 0:
        while True:
            quotient -= 1
            remainder += value
            answer_tmp.pop(0)
            if remainder in new_match:
                answer_tmp.append(number_list[new_match.index(remainder)])
                break
            elif remainder > maximum:
                try:
                    minimum = min(new_match_tmp)
                    remainder -= minimum
                    answer_tmp.append(number_list[new_match.index(minimum)])
                except:
                    answer_tmp = []
                    break
            if remainder == n:
                answer_tmp = []
                break

    if len(answer_tmp) != 0:
        answer.append(answer_tmp)

answer.sort(key=lambda x:len(x), reverse=True)
ans = reversed(answer[0])

print(*ans, sep='')
print()
Problem p03129 (python)

Fixed submission:
# coding: utf-8
n, k = map(int, input().rstrip().split())

tmp = n%2
if tmp == 0:
    ok = int(n/2)
else:
    ok = int(n/2) + 1

if k <= ok:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
n = int(input())
target = [int(input()) for _ in range(n)]

zero = target.count(0)

if zero == 0:
    print(0)
elif zero == 1:
    if len(target[:target.index(0)]) > len(target[target.index(0)+1:]):
        print(sum(target[target.index(0)+1:]))
    else:
        print(sum(target[:target.index(0)]))
Problem p03316 (python)

Fixed submission:
N = int(input())
N_10 = N
S_N = 0
for i in range(10):
  rem = N_10%10
  S_N += rem
  N_10 //= 10
  if N_10 == 0:
    break
if S_N == 0:
    answer = "No"
else:
    if N%S_N == 0:
        answer = "Yes"
    else:
        answer = "No"
print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
N_10 = N
S_N = 0
for i in range(10):
  rem = N%10
  S_N += rem
  N_10 //= 10
  if N_10 == 0:
    break
print("Yes" if N%S_N == 0 else "No")
Problem p03424 (python)

Fixed submission:
N = int(input())
arare = input().rstrip().split()
count = {"P": 0, "W": 0, "G": 0, "Y": 0}
for i in range(N):
  cur = arare[i]
  if cur == "P":
    count["P"] += 1
  elif cur == "W":
    count["W"] += 1
  elif cur == "G":
    count["G"] += 1
  else:
    count["Y"] += 1
print("Four" if count["Y"] >= 1 else "Three")

Buggy submission (verdict: Runtime Error):
N = int(input())
arare = list(map(int, input().rstrip().split()))
count = {"P": 0, "W": 0, "G": 0, "Y": 0}
for i in range(N):
  cur = arare[i]
  if cur == "P":
    count["P"] += 1
  elif cur == "W":
    count["W"] += 1
  elif cur == "G":
    count["G"] += 1
  else:
    count["Y"] += 1
print("Four" if count["Y"] >= 1 else "Three")