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

Fixed submission:
N = int(input())
t = 0
if N % 4 == 0 or N % 7 == 0:
  ans = "Yes"
else:
  t = 0
  for i in range(1,(N//7)+1):
    x = (N-7*i)/4
    if x == int(x):
      t += 1
    else:
      continue
  if t > 0:
    ans = "Yes"
  else:
    ans = "No"
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
t = 0
if N % 4 == 0 or N % 7 == 0:
  ans = "Yes"
elif N < 4:
  ans = "No"
else:
  for i in range(1, (N//7)+1):
    x = (N - 7*i) / 4
    if int(x) == x:
      ans = "Yes"
    else:
      ans = "No"
print(ans)
Problem p03543 (python)

Fixed submission:
n=str(input())
if n[0]==n[1]==n[2] or n[1]==n[2]==n[3]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n=str(input())
if n[1]==n[2]==n[3] or n[2]==n[3]==n[4]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n=str(input())
if n[1]==n[2]==n[3] or n[2]==n[3]==n[4]:
  print('Yes')
else:
  print('N')
Problem p03160 (python)

Fixed submission:
def totalcost_recur(i,cost,N,lookup):
  if i>=N:
    return 0
  if i in lookup:
      return lookup[i]
  option1 = abs(cost[i]-cost[i+1]) + totalcost_recur(i+1,cost,N,lookup)
  ans = option1
  if i+2<=N:
    option2 = abs(cost[i]-cost[i+2]) + totalcost_recur(i+2,cost,N,lookup)
    ans = min(option2,ans)
  lookup[i] = ans
  return ans



def totalcost_dp(cost,N):
    dp = [0]*(N+1)
    dp[1] = 0
    dp[2] = abs(cost[2]-cost[1])
    i = 3
    while i<=N:
        option1 = dp[i-1]+abs(cost[i]-cost[i-1])
        option2 = dp[i-2]+abs(cost[i]-cost[i-2])
        dp[i] = min(option1,option2)
        i+=1

    return dp[N]


n = int(input())
cost = list(map(int,input().split()))
cost = [0]+cost
lookup = {}

print(totalcost_dp(cost,n))

Buggy submission (verdict: Runtime Error):
def totalcost_recur(i,cost,N,lookup):
  if i>=N:
    return 0
  if i in lookup:
      return lookup[i]
  option1 = abs(cost[i]-cost[i+1]) + totalcost_recur(i+1,cost,N,lookup)
  ans = option1
  if i+2<=N:
    option2 = abs(cost[i]-cost[i+2]) + totalcost_recur(i+2,cost,N,lookup)
    ans = min(option2,ans)
  lookup[i] = ans
  return ans



def totalcost_dp(cost,N,k):
    dp = [float('inf')]*(N+1)
    dp[1] = 0
    
    
    for i in range(1,N+1):
        
        for j in range(i+1,k+i+1):
            if j < N+1:
                dp[j] = min(dp[j],dp[i]+abs(cost[i]-cost[j]))
                
            
        
        

    return dp[N]


n ,k= map(int,input().split())
cost = list(map(int,input().split()))
cost = [0]+cost
lookup = {}

print(totalcost_dp(cost,n,k))

Buggy submission (verdict: Runtime Error):
def totalcost(i,cost,N,lookup):
  if i>=N:
    return 0
  if i in lookup:
      return lookup[i]
  option1 = abs(cost[i]-cost[i+1]) + totalcost(i+1,cost,N,lookup)
  ans = option1
  if i+2<=N:
    option2 = abs(cost[i]-cost[i+2]) + totalcost(i+2,cost,N,lookup)
    ans = min(option2,ans)
  lookup[i] = ans
  return ans

n = int(input())
cost = list(map(int,input().split()))
cost = [0]+cost
lookup = {}
print(totalcost(1,cost,n,lookup))

Buggy submission (verdict: Runtime Error):
def totalcost(i,cost,N):
  if i>=N:
    return 0
  option1 = abs(cost[i]-cost[i+1]) + totalcost(i+1,cost,N)
  ans = option1
  if i+2<=N:
    option2 = abs(cost[i]-cost[i+2]) + totalcost(i+2,cost,N)
    ans = min(option2,ans)
  return ans

n = int(input())
cost = list(map(int,input().split()))
cost = [0]+cost
print(totalcost(1,cost,n))

Buggy submission (verdict: Runtime Error):
def totalcost(i,cost,N):
  if i>=N:
    return 0
  option1 = abs(cost(i)-cost(i+1)) + totalcost(i+1,cost,N)
  ans = option1
  if i+2<=N:
    option2 = abs(cost(i)-cost(i+2)) + totalcost(i+2,cost,N)
    ans = min(option1,ans)
  return ans

n = int(input())
cost = list(map(int,input().split()))
cost = [0]+cost
print(totalcost(1,cost,n))
Problem p03165 (python)

Fixed submission:
def lcs(s,t):
    m = len(s)
    n = len(t)

    dp = [[0]*(n+1) for _ in range(m+1)]

    for i in range(1,m+1):
        for j in range(1,n+1):
            if s[i-1] == t[j-1]:
                dp[i][j] = 1+ dp[i-1][j-1]
            else:
                dp[i][j] = max(dp[i-1][j],dp[i][j-1])
    
    
    substr = ""
    i,j = m,n
    while i>0 and j>0:
        if s[i-1] == t[j-1]:
            substr+=s[i-1]
            i-=1
            j-=1
        elif dp[i][j-1]>dp[i-1][j]:
            j-=1
        else:
            i-=1
    return substr[::-1]
    
    

# s = "abracadabra"
# t = "avadakedavra"
# s = "axyb"
# t = "abyxb"
s = input()
t = input()
print(lcs(s,t))

Buggy submission (verdict: Runtime Error):
def lcs(s,t):
    m = len(s)
    n = len(t)

    dp = [[0]*(n+1) for _ in range(m+1)]

    for i in range(1,m+1):
        for j in range(1,n+1):
            if s[i-1] == t[j-1]:
                dp[i][j] = 1+ dp[i-1][j-1]
            else:
                dp[i][j] = max(dp[i-1][j],dp[i][j-1])
    
    
    substr = ""
    i,j = m,n
    while i!=0 or j!=0:
        if s[i-1] == t[j-1]:
            substr+=s[i-1]
            i-=1
            j-=1
        elif dp[i][j-1]>dp[i-1][j]:
            j-=1
        else:
            i-=1
    return substr[::-1]
    
    

# s = "abracadabra"
# t = "avadakedavra"
# s = "axyb"
# t = "abyxb"
s = input()
t = input()
print(lcs(s,t))
Problem p03167 (python)

Fixed submission:
def grid(maze,h,w):
    mod = 7+10**9
    visited = [[0]*w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if maze[i][j] == "#":
                continue

            if i==0 and j==0:
                visited[i][j] = 1
                
            
            elif i == 0:
                visited[i][j] = visited[i][j-1]
            elif j == 0:
                visited[i][j] = visited[i-1][j]
            else:
                visited[i][j] = (visited[i-1][j]%mod + visited[i][j-1]%mod)%mod
    
    return visited[h-1][w-1]


h,w = map(int,input().split())

maze = []

for _ in range(h):
    maze.append(list(input()))

print(grid(maze,h,w))

Buggy submission (verdict: Runtime Error):
def isInvalid(maze,i,j,dr,dc,visited):
    if i>dr or i<0 or j>dc or j<0:
        return True
    
    if visited[i][j]:
        return True
    
    if maze[i][j] == "#":
        return True
    
    return False

def grid(maze,i,j,dr,dc,visited):
    global count

    if i == dr and j == dc:
        count+=1
        
        return 
    
    if isInvalid(maze,i,j,dr,dc,visited):
        return
    visited[i][j] = True

    grid(maze,i,j+1,dr,dc,visited)
    grid(maze,i+1,j,dr,dc,visited)
    visited[i][j]= False

    



h,w = map(int,input().split())

maze = []

for _ in range(h):
    maze.append(list(input()))

count=0

visited = [[False]*w for _ in range(h)]
grid(maze,0,0,h-1,w-1,visited)
mod = 7+10**9
print(count%mod)
Problem p03760 (python)

Fixed submission:
o = str(input())
s = str(input())
n = ""

if not len(o) == len(s):
	for i in range(min(len(o),len(s))):
		n += o[i]
		n += s[i]

	if len(o) > len(s):
		n += o[len(o)-1]

else:
	for i in range(len(o)):
		n += o[i]
		n += s[i]
		
print(n)

Buggy submission (verdict: Runtime Error):
o = str(input())
s = str(input())
n = ""

if not len(o) == len(s):
	for i in range(min(len(o),len(s))):
		n += o[i]
		n += s[i]

	if len(o) > len(s):
		n += o[len(o)-1]

	if len(s) > len(o):
		n += s[len(s)-1]

else:
	for i in rage(len(o)):
		n += o[i]
		n += s[i]
		
print(n)
Problem p03273 (python)

Fixed submission:
h, w = (int(i) for i in input().split())
list_a = [input() for s in range(0, h)]
list_tmp = []
for i in range(0, h):
    for j in range(0, w):
        if list_a[i][j] == '#':
            list_tmp.append(list(list_a[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_tmp_t = [list(x) for x in zip(*list_tmp)]
list_tmp2 = []
for i in range(0, len(list_tmp_t)):
    for j in range(0, len(list_tmp_t[i])):
        if list_tmp_t[i][j] == '#':
            list_tmp2.append(list(list_tmp_t[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_ans = [list(x) for x in zip(*list_tmp2)]
for i in range(0, len(list_ans)):
    print("".join(list_ans[i]))

Buggy submission (verdict: Runtime Error):
h, w = (int(i) for i in input().split())
list_a = [input() for s in range(0, w)]
list_tmp = []
for i in range(0, w):
    for j in range(0, h):
        if list_a[i][j] == '#':
            list_tmp.append(list(list_a[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_tmp_t = [list(x) for x in zip(*list_tmp)]
list_tmp2 = []
for i in range(0, h):
    for j in range(0, len(list_tmp_t[i])):
        if list_tmp_t[i][j] == '#':
            list_tmp2.append(list(list_tmp_t[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_ans = [list(x) for x in zip(*list_tmp2)]
for i in range(0, len(list_ans)):
    print("".join(list_ans[i]))
Problem p03281 (python)

Fixed submission:
# 105の約数は1, 3, 5, 7, 3 * 5, 3 * 7, 5 * 7, 3 * 5 * 7
# ほかにありえるのは
# ①1, 3, 5, 9, ...
# ②1, 3, 5, 11, ...
# ③1, 3, 7, 9, ...
# ④1, 3, 5, 13, ...
n = int(input())
if n < 105: print(0)
elif n < 135: print(1)
elif n < 165: print(2)
elif n < 189: print(3)
elif n < 195: print(4)
else: print(5)

Buggy submission (verdict: Runtime Error):
# 105の約数は1, 3, 5, 7, 3 * 5, 3 * 7, 5 * 7, 3 * 5 * 7
# ほかにありえるのは
# ①1, 3, 5, 9, ...
# ②1, 3, 5, 11, ...
# ③1, 3, 5, 13, ...
n = int(input())
if n < 105: print(0)
elif n < 135: print(1)
elif n < 165: print(2)
elif n < 195: print(3)
else print(4)
Problem p02817 (python)

Fixed submission:
a,b = map(str, input().split())
print(b+a)

Buggy submission (verdict: Runtime Error):
a,b = map(str, input().split())
print(b+s)
Problem p02957 (python)

Fixed submission:
a,b=map(int,input().split())
a=a+b
if (a)%2==0:
  print(a//2)
else:
  print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
a,b=map(input())
a=a+b
if (a)%2==0:
  print(a//2)
else:
  print('IMPOSSIBLE')
Problem p02866 (python)

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

if D[0] != 0:
    print(0)
    exit(0)
D.sort()

if D[1] == 0:
    print(0)
    exit(0)

for i in range(0, N-1):
    if abs(D[i] - D[i+1]) > 1:
        print(0)
        exit(0)

cnt = [0 for _ in range(N)]

for i in range(0, N):
    cnt[D[i]] += 1

ans = 1

for i in range(0, N-1):
    if cnt[i+1] == 0:
        break
    ans *= pow(cnt[i], cnt[i+1])
    ans %= 998244353

print(ans)

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

if D[0] != 0:
  print(0)
  exit(0)
D.sort()

if D[1] != 0:
  print(0)
  exit(0)

for i in range(0,N-1):
  if abs(D[i] - D[i+1]) > 1:
    print(0)
    exit(0)

cnt = [0 for _ in range(N)]

for i in range(1,N):
  cnt[D[i]] += 1

ans = 1

for i in range(1,N):
  if cnt[i+1] == 0:
    break
  ans *= cnt[i] * cnt[i+1]
  ans %= 998244353
  
print(ans)
Problem p03136 (python)

Fixed submission:
print((lambda l:['No','Yes'][sum(l[:-1])>l[-1]])(sorted(list(map(int,input().split()+input().split()))[1:])))

Buggy submission (verdict: Runtime Error):
input();s=map(int,input().split());print('YNeos'[sum(s)-max(s)*2<1::2])
Problem p03474 (python)

Fixed submission:
def number(c):
    c = str(c)
    ans = 0
    s = "0123456789"
    for i in range(10):
        if c == s[i]:ans = 1
    return ans

A,B = map(int,input().split())
S = input()
flag = 1
for i in range(A):
    if(number(S[i]) != 1):flag = 0
if S[A] != "-":flag = 0
for j in range(B):
    if(number(S[A+1+j]) != 1):flag = 0
if flag:print("Yes")
else:print("No")

Buggy submission (verdict: Runtime Error):
def number(c):
    c = str(c)
    ans = 0
    s = "0123456789"
    for i in range(10):
        if c == s[i]:ans = 1
    return ans

A,B = map(int,input().split())
S = input()
flag = 1
for i in range(A):
    if(number(S[i]) != 1):flag = 0
if S[A] != "-":flag = 0
for j in range(B):
    if(number(S[A+1+i]) != 1):flag = 0
if flag:print("Yes")
else:print("No")
Problem p03481 (python)

Fixed submission:
X,Y = map(int,input().split())
ans = 0
while X <= Y:
	ans += 1
	X *= 2
print(ans)

Buggy submission (verdict: Runtime Error):
import math;print(int((lambda l:math.floor(1e-5+math.log2(l[1]/l[0]))+1))(list(map(int,input().split()))))

Buggy submission (verdict: Runtime Error):
import math;print(int((lambda l:math.floor(1e-9+math.log2(l[1]/l[0]))+1))(list(map(int,input().split()))))
Problem p03826 (python)

Fixed submission:
a,b,c,d=map(int,input().split());print(max(a*b,c*d))

Buggy submission (verdict: Runtime Error):
l = map(int,input().split());print(max(l[0]*l[1],l[2]*l[3]))
Problem p03943 (python)

Fixed submission:
a,b,c=map(int,input().split());print(["No","Yes"][(a+b==c)+(b+c==a)+(c+a==b)])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][bool(a==b+c)+bool(b==a+c)+bool(c==a+b)])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][(a==b+c)+(b==a+c)+(c==a+b)])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][bool(bool(a==b+c)or(bool(b==a+c))or(bool(c==a+b)))])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][bool((a==b+c)or(b==a+c)or(c==a+b))])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][bool(a==b+c or b==a+c or c==a+b)])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][(a==b+c or b==a+c or c==a+b)])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][(a==b+c or b==a+c or c==a+b)])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][a==b+c or b==a+c or c==a+b])

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][a==b+c or b=a+c or c==a+b])
Problem p04029 (python)

Fixed submission:
print(sum([int(i) for i in range(int(input())+1)]))

Buggy submission (verdict: Runtime Error):
print(sum([x for i in range(int(input())+1)]))

Buggy submission (verdict: Runtime Error):
print((lambda x:x* x-~/2)(int(input())))

Buggy submission (verdict: Runtime Error):
print((lambda x:x* x-~/2)(int(input())))
Problem p04043 (python)

Fixed submission:
l=input().split();list.sort(l);print(["NO","YES"][l==["5","5","7"]])

Buggy submission (verdict: Runtime Error):
print(["YES","NO"][bool(len(list(multiset(map(int,input().split()))-multiset([5,5,7]))))])

Buggy submission (verdict: Runtime Error):
print(["YES","NO"][bool(len(list(multiset(input().split())-multiset([5,5,7]))))])

Buggy submission (verdict: Runtime Error):
print(["YES","NO"][bool(len(list(multiset(input.split())-multiset([5,5,7]))))])

Buggy submission (verdict: Runtime Error):
print(["YES","NO"][bool(len([set(input.split())-set([5,5,7])]))])
Problem p02936 (python)

Fixed submission:
N, Q = map(int, input().split())
G = [tuple(map(int, input().split())) for _ in range(N-1)]
W = [tuple(map(int, input().split())) for _ in range(Q)]


# 親に付いている重み
r = [0,] * (N+1)
for p, x in W:
    r[p] += x



# 木の隣接関係
M = [[] for _ in range(N+1)]
for g in G:
    M[g[0]].append(g[1])
    M[g[1]].append(g[0])

# print(M)

# 木の親子関係
P = [[] for _ in range(N+1)]
visited = [0,] * (N+1)

def dfs(start):
    q = []
    q.append(start)
    while q:
        now = q.pop()
        visited[now] = 1
        for child in M[now]:
            if not visited[child]:
                r[child] += r[now]
                q.append(child)


dfs(1)

print(*r[1:])

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
G = [tuple(map(int, input().split())) for _ in range(N-1)]
W = [tuple(map(int, input().split())) for _ in range(Q)]

# 木の隣接関係 (a<bは保証されている)
M = [[] for _ in range(N+1)]
for g in G:
    M[g[0]].append(g[1])

#print(M)

# 木の親子関係
P = [[] for _ in range(N+1)]
# dfs
visited = []

def dfs(start):
    visited[start] = 1
    for child in M[start]:
        if not visited[child]:
            dfs(child)

for parent in range(1, N+1):
    visited = [0,] * (N+1)
    dfs(parent)
    P[parent].extend([i for i, s in enumerate(visited) if s])

#print(P)

res = [0,] * (N+1)
for p, x in W:
    for pp in P[p]:
        res[pp] += x

print(" ".join(map(str, res[1:])))
Problem p02719 (python)

Fixed submission:
n,k = map(int,input().split())
if n % k ==0:
    print(0)
else:
    l = [n]
    p = n//k
    c = n-(p*k)
    half = k//2
    while c > half:
        c = abs(c-k)
    l.append(c)
    print(min(l))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
if n % k ==0:
    print(0)
else:
    l = [n]
    p = n//k
    c = n-(p*k)
half = k//2
while c > half:
    c = abs(c-k)
l.append(c)
print(min(l))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
if n % k ==0:
    print(0)
else:
    l = [n]
    p = n//k
    c = n-(p*k)
half = k//2
while c > half:
    c = abs(c-k)
    l.append(c)
print(min(l))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
if n % k ==0:
print(0)
else:
l = [n]
p = n//k
c = n-(p*k)
half = k//2
while c > half:
c = abs(c-k)
l.append(c)
print(min(l))

Buggy submission (verdict: Runtime Error):
x,y,z = list(map(int,input().split()))
def swap(a,b):
tmp = a
a = b
b = tmp
return (a,b)
x,y = swap(x,y)
x, z = swap(x, z)
print(x,y,z)
n,k = map(int,input().split())
if n % k ==0:
print(0)
else:
l = [n]
p = n//k
c = n-(p*k)
half = k//2
while c > half:
c = abs(c-k)
l.append(c)
print(min(l))
Problem p02765 (python)

Fixed submission:
n = input().split()
if int(n[0]) >= 10:
  print(n[1])
else:
  print(int(n[1]) + 100*(10-int(n[0])))

Buggy submission (verdict: Runtime Error):
N = int(input())
R = int(input())
if N >= 10:
  print(R)
else:
  print(R + 100*(10-N))
Problem p02812 (python)

Fixed submission:
N = input()
S = input()
print(S.count('ABC'))

Buggy submission (verdict: Runtime Error):
N = input()
S = input()
print(s.count('ABC'))

Buggy submission (verdict: Runtime Error):
int N = input()
String S = input()
print(s.count('ABC'))
Problem p02641 (python)

Fixed submission:
X, N = map(int, input().split(' '))
P = []
if N > 0:
  P = sorted(list(map(int, input().split(' '))))
  ans = 0
  i = 0
  while True:
    if (X-i) not in P:
      ans = (X-i)
      break
    elif (X+i) not in P:
      ans = (X+i)
      break
    else:
      i += 1

if N > 0:
  print(ans)
else:
  print(X)

Buggy submission (verdict: Runtime Error):
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int X = scan.nextInt();
		int N = scan.nextInt();
		Integer p[] = new Integer[N];
		//int min = Math.abs(100 - X);
		int min = 100;
        int result = X;

		for (int i = 0; i < N; i++) {
			p[i] = scan.nextInt();
		}

		for (int i = 0; i <= 200; i++) {
			if (Math.abs(X - i) < min && !Arrays.asList(p).contains(i)) {
				min = Math.abs(X - i);
				result = i;
			}
		}

		System.out.println(result);

	}

}
Problem p02732 (python)

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

K = {}
for row in A:
  if row in K:
    K[row] += 1
  else:
    K[row] = 1
        
# 最大数を計算
max = 0
for i in K:
  max += int(K[i]*(K[i]-1)/2)

# 辞書Kに関して全探索
for i in A:
  print(max - int(K[i]*(K[i]-1)/2) + int((K[i]-1)*(K[i]-2)/2) )

Buggy submission (verdict: Runtime Error):
from scipy.special import comb

N = int(input())
A = list(map(int, input().split(' ')))

K = {}
for row in A:
    if row in K:
      K[row] += 1
    else:
      K[row] = 1

# 辞書Kに関して全探索
for row in A:
    ans = 0
    for i in K:
        if i == row:
            ans += comb(K[i]-1,2)
        else:
            ans += comb(K[i],2)
    print(int(ans))
Problem p02756 (python)

Fixed submission:
#パラメータの取得
S = input()
Q = int(input())
cnt = 0   #反転回数カウンタ
head = ''
tail = ''

#処理実体処理
for i in range(Q):
  tmp = str(input())
  #Q各行の値を、T, F, Cに基づいて処理
  if tmp[0] == '1':
    cnt += 1
  else:
    T, F, C = tmp.split(' ')
    if cnt % 2 == 1:
      if F == '1':
        tail = tail + C
      else:
        head = C + head
    else:
      if F == '1':
        head = C + head
      else:
        tail = tail + C
    #cnt = 0
  #print('head=',head)
  #print('tail=',tail)

#print('cnt=',cnt)
if cnt % 2 == 0:
  ans = head + S + tail
else:
  ans = tail[::-1] + S[::-1] + head[::-1]
print(ans)

Buggy submission (verdict: Runtime Error):
def StrConv(S, T, F, C):
  ans = ''
  if T == '1':
    #ans = S[::-1]
  else:
    if F == '1':
      ans = C + S
    else:
      ans = S + C
  return ans
  
#パラメータの取得
S = input()
Q = int(input())
dumy = '|' #仮の文字列くみ上げ変数
cnt = 0   #反転回数カウンタ

#処理実体処理
for i in range(Q):
  tmp = str(input())
  #Q各行の値を、T, F, Cに基づいて処理
  if tmp[0] == '1':
    T = tmp[0]
    F = '-'
    C = '-'
    cnt += 1
  else:
    T, F, C = tmp.split(' ')
  #変換処理本体
  dumy = StrConv(dumy, T, F, C)

#文字列結合処理
if (cnt % 2) == 0:
  ans = dumy[0:dumy.find('|')] + S + dumy[dumy.find('|')+1:]
else:
  ans = dumy[0:dumy.find('|')] + S[::-1] + dumy[dumy.find('|')+1:]
print(ans)
Problem p02761 (python)

Fixed submission:
N, M = (int(x) for x in input().split(' '))
TMP = ['*'] * N
ans = 0

#ループで探しながら置き換え処理 
for i in range(M):
  s, c = (int(x) for x in input().split(' '))

  #既に異なる値が指定されている場合はエラー(-1)とする
  if TMP[s-1] == '*' or TMP[s-1] == c:
    TMP[s-1] = c
  else:
    ans = -1
    break    

# 例外判定。桁数が2桁以上で先頭桁に0が指定された場合。0で始まる2桁以上数は-1とする。
if N > 1 and TMP[0] == 0:
  ans = -1

#未指定文字の置き換え。最上位桁は"1"に、以外は"0"に置き換える。
if ans != -1:
  for x in range(N):
    #先頭の未指定文字は1に置き換え
    if TMP[x] == '*' and x == 0:
      if N == 1 and M == 0: 
        TMP[x] = 0
      else:
      	TMP[x] = 1

    #以外の未指定文字は0に置き換え
    if TMP[x] == '*' and x > 0:
      TMP[x] = 0


if ans != -1:
  ans = int(''.join(map(str, TMP)))
  print(ans)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
N, M = (int(x) for x in input().split(' '))
TMP = [0 for _ in range(M)]
ans = 0

#ループで探しながら処理 
for _ in range(M):
  s, c = (int(x) for x in input().split(' '))

  #前回値判定
  if TMP[s-1] == 0 or TMP[s-1] == c:
    TMP[s-1] = c
  else:
    ans = -1
    break

if ans != -1:
	ans = int(''.join(map(str, TMP)))

print(ans if ans != 0 else -1)
Problem p02621 (python)

Fixed submission:
import math
import sys

S = int(input())
print(S+(S**2)+(S**3))

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

N, M , K = map(int, input().split())
A = deque(map(int, input().split()))
B = deque(map(int, input().split()))


count = 0
time = 0
#もし先にどっちかの玉が尽きた時の問題。
for i in range(400001):
    #本が尽きていない。
    if len(A) != 0 and len(B) != 0:

        if A[0] < B[0]:
            time = time + A[0]
            if time <= K:
                count = count + 1
                A.popleft()

        elif A[0] > B[0]:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
        else:
            time = time + A[0]
            if time <= K:
                count = count + 1
                A.popleft()
    else:
        #どっかの本が尽きている。
        if len(A) == 0 and len(B) != 0:
            time = time + B[0]
            if time <= K:
                count = count + 1
                B.popleft()
        elif len(A) != 0 and len(B) == 0:
            time = time +A[0]
            if time <= K:
                count = count + 1
                A.popleft()
        elif len(A) == 0 and len(B) == 0:
            print(count)
            sys.exit()
               


print(count)
Problem p02639 (python)

Fixed submission:
X1,X2,X3,X4,X5 = map(int, input().split())
lis = [X1,X2,X3,X4,X5]

for i in range(len(lis)):
    if lis[i] == 0:
        print(i+1)

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

if N == 0:
  print(X)
  sys.exit()
  
if X == 100 and N == 100:
  print(-100)
  sys.exit()
  
  
P = list(map(int, input().split()))

lis = []
for i in range (-100,102,1):
    if i not in P:
        lis.append(i)


        
        
        
ans = 10**18
suzi = 0
lis2 = []
for j in lis:
    num = abs(X-j)
    if num < ans:
        ans = num
        suzi = j

print(suzi)