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

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline

    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(input().rstrip('\n'))

    L = [[0] * W for _ in range(H)]
    R = [[0] * W for _ in range(H)]
    U = [[0] * W for _ in range(H)]
    D = [[0] * W for _ in range(H)]
    for h in range(H):
        for w in range(1, W):
            if grid[h][w-1] == '.' and grid[h][w] == '.':
                L[h][w] = L[h][w-1] + 1
    for h in range(H):
        for w in range(W-2, -1, -1):
            if grid[h][w] == '.' and grid[h][w+1] == '.':
                R[h][w] = R[h][w+1] + 1
    for w in range(W):
        for h in range(1, H):
            if grid[h][w] == '.' and grid[h-1][w] == '.':
                U[h][w] = U[h-1][w] + 1
    for w in range(W):
        for h in range(H-2, -1, -1):
            if grid[h][w] == '.' and grid[h+1][w] == '.':
                D[h][w] = D[h+1][w] + 1

    ans = 1
    for h in range(H):
        for w in range(W):
            ans = max(ans, L[h][w] + R[h][w] + U[h][w] + D[h][w] + 1)
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = ""
for i in range(H):
    S += input()

light = [0] * (H*W)
for h in range(H):
    cnt = 0
    pre = "@"
    info = []
    for i in range(h*W, (h+1)*W):
        if S[i] == pre:
            cnt += 1
            if i == (h+1)*W-1:
                if S[i] == ".":
                    info.append(cnt)
                else:
                    info.append(-cnt)
        else:
            if pre == ".":
                info.append(cnt)
                cnt = 1
            elif pre == "#":
                info.append(-cnt)
                cnt = 1
    cnt = h*W
    while len(info) > 0:
        LD = info.pop(0)
        if LD > 0: 
            for i in range(LD):
                light[cnt + i] += LD
            cnt += LD
        else:
            for i in range(-LD):
                light[cnt + i] = 0
            cnt += -LD

for w in range(W):
    cnt = 0
    pre = "@"
    info = []
    for i in range(H):
        if S[w + i * H] == pre:
            cnt += 1
            if i == H-1:
                if S[w + i * H] == ".":
                    info.append(cnt)
                else:
                    info.append(-cnt)
        else:
            if pre == ".":
                info.append(cnt)
                cnt = 1
            elif pre == "#":
                info.append(-cnt)
                cnt = 1
    cnt = w
    while len(info) > 0:
        LD = info.pop(0)
        if LD > 0: 
            for i in range(LD):
                light[w + i * H] += LD
            cnt += LD * H
        else:
            for i in range(-LD):
                light[i] = 0
            cnt += -LD * H
print(max(light)-1)
Problem p03111 (python)

Fixed submission:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N, A, B, C = map(int, input().split())
    L = []
    for _ in range(N):
        L.append(int(input()))

    ans = 10**9
    for i in range(4 ** N):
        AA = []
        BB = []
        CC = []
        ii = i
        for j in range(N):
            k = ii % 4
            if k == 0:
                AA.append(L[j])
            elif k == 1:
                BB.append(L[j])
            elif k == 2:
                CC.append(L[j])
            ii >>= 2
        if len(AA) * len(BB) * len(CC) == 0:
            continue
        ans_new = abs(sum(AA) - A) + 10*(len(AA)-1) + abs(sum(BB) - B) + 10*(len(BB)-1) + abs(sum(CC) - C) + 10*(len(CC)-1)
        ans = min(ans, ans_new)
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
(N,A,B,C)=map(int,input().split())
2
L=[]
3
for i in range(N):
4
  L.append(int(input()))
5
  
6
L_sums=[]
7
costs=[]
8
#bin_is=[]
9
for i in range(2**N+1,2**N+2**N):
10
  bin_i=str(bin(i))[2:]
11
  L_sum=0
12
  cost=-1
13
  for j in range(N):
14
    L_sum+=L[j]*int(bin_i[j+1])
15
    cost+=int(bin_i[j+1])
16
  L_sums.append(L_sum)
17
  costs.append(10*cost)
18
  #bin_is.append(bin_i)
19
​
20
cost_A=[]
21
for i in range(2**N-1):
22
  cost_A.append(costs[i]+abs(L_sums[i]-A))
23
min_cost_A=min(cost_A)
24
min_cost_A_index=cost_A.index(min(cost_A))+1
25
min_cost_A_index_bin=str(bin(min_cost_A_index+2**N))[2:]
26
for i in range(N):
27
  if min_cost_A_index_bin[i+1]=='1':
28
    del(L[i])
29
N=len(L)
30
#-------------------
31
L_sums=[]
32
costs=[]
33
#bin_is=[]
34
for i in range(2**N+1,2**N+2**N):
35
  bin_i=str(bin(i))[2:]
36
  L_sum=0
37
  cost=-1
38
  for j in range(N):
39
    L_sum+=L[j]*int(bin_i[j+1])
40
    cost+=int(bin_i[j+1])
41
  L_sums.append(L_sum)
42
  costs.append(10*cost)
43
  #bin_is.append(bin_i)
44
​
45
cost_B=[]
46
for i in range(2**N-1):
47
  cost_B.append(costs[i]+abs(L_sums[i]-B))
48
min_cost_B=min(cost_B)
49
min_cost_B_index=cost_B.index(min(cost_B))+1
50
min_cost_B_index_bin=str(bin(min_cost_B_index+2**N))[2:]
51
for i in range(N):
52
  if min_cost_B_index_bin[i]=='1':
53
    del(L[i])
54
N=len(L)
55
#-----------------
56
L_sums=[]
57
costs=[]
58
#bin_is=[]
59
for i in range(2**N+1,2**N+2**N):
60
  bin_i=str(bin(i))[2:]
61
  L_sum=0
62
  cost=-1
63
  for j in range(N):
64
    L_sum+=L[j]*int(bin_i[j+1])
65
    cost+=int(bin_i[j+1])
66
  L_sums.append(L_sum)
67
  costs.append(10*cost)
68
  #bin_is.append(bin_i)
69
​
70
cost_C=[]
71
for i in range(2**N-1):
72
  cost_C.append(costs[i]+abs(L_sums[i]-C))
73
min_cost_C=min(cost_C)
74
#min_cost_C_index=cost_C.index(min(cost_C))+1
75
#min_cost_C_index_bin=str(bin(min_cost_C_index))[2:]
76
#for i in range(N):
77
#  if min_cost_C_index_bin[i]=='1':
78
#    del(L[i])
79
#N=len(L)
80
#----------------
81
print(min_cost_A+min_cost_B+min_cost_C)
Problem p03128 (python)

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

number = [6,2,5,5,4,5,6,3,7,6]


dp = [-1*inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
  dp_new = 0
  for j in A:
    if i - number[j] >= 0:
      if dp[i-number[j]] +1 > dp_new:
        dp[i] = dp[i-number[j]] +1
        dp_new = dp[i]

A.sort(reverse=True)
ans = ""
while N > 0:
  for j in A:
    if N - number[j] >= 0:
      if dp[N] == dp[N-number[j]] + 1:
        ans += str(j)
        N -= number[j]
        break

print(int(ans))

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

number = [6,2,5,5,4,5,6,3,7,6]


dp = [-1*inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
  dp_new = 0
  for j in A:
    if i - number[j] >= 0:
      if dp[i-number[j]] +1 > dp_new:
        dp[i] = dp[i-number[j]] +1
        dp_new = dp[i]

A.sort(reverse=True)
ans = ""
while N > 0:
  for j in A:
    if dp[N] == dp[N-number[j]] + 1:
      ans += str(j)
      N -= number[j]
      break

print(int(ans))

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

number = [6,2,5,5,4,5,6,3,7,6]


dp = [-1*inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
  dp_new = 0
  for j in A:
    if i - number[j] >= 0:
      if dp[i-number[j]] +1 > dp_new:
        dp[i] = dp[i-number[j]] +1

A.sort(reverse=True)
ans = ""
while N > 0:
  for j in A:
    if dp[N] == dp[N-number[j]] + 1:
      ans += str(j)
      N -= number[j]
      break

print(int(ans))
Problem p03138 (python)

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

max_A = max(A)
if max_A == 0:
  max_A_bin_len = 1
else:
  max_A_bin_len = len(bin(max_A)) - 2
  if K == 0:
    K_bin_len = 1
  else:
    K_bin_len = len(bin(K)) - 2
max_bin_len = max(max_A_bin_len, K_bin_len)
A_bin = [bin(a)[2:].zfill(max_bin_len) for a in A]
K_bin = bin(K)[2:].zfill(max_bin_len)

ans_cand1 = 0
ans_cand2 = 0
can_choose = 0
can_choose_forever = 0
calc_ans_cand2 = 0
start_calc_ans_cand2 = 0
for bit in range(max_bin_len):
  if not can_choose:
    if K_bin[bit] == '1':
      can_choose = 1
  A_one_num = 0
  for a in A_bin:
    if a[bit] == '1':
      A_one_num += 1
  if can_choose:
    if A_one_num < N-A_one_num:
      if not can_choose_forever:
        can_choose = 0
        if not calc_ans_cand2:
          ans_cand2 = ans_cand1 + (2**(max_bin_len-bit-1)) * A_one_num
          start_calc_ans_cand2 = 1
    else:
      can_choose_forever = 1
    ans_cand1 += (2**(max_bin_len-bit-1)) * (max(A_one_num, N-A_one_num))
  else:
    ans_cand1 += (2**(max_bin_len-bit-1)) * A_one_num
  if calc_ans_cand2:
    ans_cand2 += (2**(max_bin_len-bit-1)) * (max(A_one_num, N-A_one_num))
  if start_calc_ans_cand2:
    calc_ans_cand2 = 1
print(max(ans_cand1, ans_cand2))

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

number = [6,2,5,5,4,5,6,3,7,6]


dp = [-1*inf]*(N+1)
dp[0] = 0
for i in range(1,N+1):
  dp_new = 0
  for j in A:
    if dp[i-number[j]] +1 > dp_new:
      dp[i] = dp[i-number[j]] +1

A.sort(reverse=True)
ans = ""
while N > 0:
  for j in A:
    if dp[N] == dp[N-number[j]] + 1:
      ans += str(j)
      N -= number[j]
      break

print(int(ans))
Problem p03203 (python)

Fixed submission:
import sys
import bisect
from collections import defaultdict
input = sys.stdin.buffer.readline

H, W, N = map(int, input().split())
block = [defaultdict(int) for _ in range(W+1)]
for _ in range(N):
    x, y = map(int, input().split())
    block[y][x] = 1
for w in range(1, W+1):
    block[w][H+1] = 1

h, w = 1, 1
ans = min(list(block[1].keys())) - 1
if ans <= 1:
    print(1)
    exit()
while True:
    if block[w][h+1] == 1:
        ans = min(ans, h)
        break
    h += 1
    if w == W:
        break
    if block[w+1][h] == 0:
        w += 1
        block_w = []
        for k in block[w].keys():
            if block[w][k] == 1:
                block_w.append(k)
        block_w.sort()
        hmin = block_w[bisect.bisect_left(block_w, h)]
        ans = min(ans, hmin-1)

print(ans)

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

H, W, N = map(int, input().split())
block = [defaultdict(int) for _ in range(W+1)]
for _ in range(N):
    x, y = map(int, input().split())
    block[y][x] = 1
for w in range(1, W+1):
    block[w][H+1] = 1

h, w = 1, 1
ans = min(list(block[1].keys())) - 1
if ans <= 1:
    print(1)
    exit()
while True:
    if block[w][h+1] == 1:
        ans = min(ans, h)
        break
    h += 1
    if w == W:
        break
    if block[w+1][h] == 0:
        w += 1
        block_w = []
        for k in block[w].keys():
            if block[w][k] == 1:
                block_w.append(k)
        hmin = block_w[bisect.bisect_left(block_w, h)]
        ans = min(ans, hmin-1)

print(ans)
Problem p03248 (python)

Fixed submission:
import math

s = input()

N = len(s)
s = "#" + s
possible = 1
if s[-1] == "1" or s[1] == "0":
  possible = 0
for i in range(1,math.floor(N/2)):
  if s[i] != s[N - i]:
    possible = 0

if not possible:
  print(-1)
elif N == 2:
  if s[1] == "1" and s[2] == "0":
    print(1, 2)
  else:
    print(-1)
elif N == 3:
  if s[1] == "1" and s[2] == "1":
    print(1,2)
    print(2,3)
  else:
    print(-1)
else:
  destination = [1] * (N+1)
  dest_change = [0] * (N+1)
  root = 2
  max_bit = math.floor(N/2)
  for i in range(max_bit, -1, -1):
    if s[i] == "1":
      #destination = destination[:root+1] + [root]*(i-1) + destination[root+i:]
      dest_change[root + 1] = dest_change[root + 1] + 1
      dest_change[root + i] = dest_change[root + i] - 1
      root += 1
  for i in range(1,N+1):
    destination[i] = destination[i - 1] + dest_change[i]
  for i in range(2,N+1):
    print(i, destination[i])

Buggy submission (verdict: Runtime Error):
import math

s = input()

N = len(s)
s = "#" + s
possible = 1
if s[-1] == "1" or s[1] == "0":
  possible = 0
for i in range(1,math.floor(N/2)):
  if s[i] != s[N - i]:
    possible = 0

if not possible:
  print(-1)
elif N == 2:
  if s[1] == "1" and s[2] == "0":
    print(1, 2)
  else:
    print(-1)
elif N == 3:
  if s[1] == "1" and s[2] == "1":
    print(1,2)
    print(2,3)
  else:
    print(-1)
else:
  destination_1sthalf = [1] * (math.floor(N/2) + 2)
  destination_2ndhalf = [1] * (N - math.floor(N/2) -1)
  root = 2
  max_bit = math.floor(N/2)
  for i in range(max_bit, -1, -1):
    if s[i] == "1":
      destination_1sthalf = destination_1sthalf[:root+1] + [root]*(i-1)
      root += 1
  destination = destination_1sthalf + destination_2ndhalf
  for i in range(2,N+1):
    print(i, destination[i])

Buggy submission (verdict: Runtime Error):
import math

s = input()

N = len(s)
s = "#" + s
possible = 1
if s[-1] == "1":
  possible = 0
for i in range(1,math.floor(N/2)):
  if s[i] != s[N - i]:
    possible = 0

if not possible:
  print(-1)
else:
  destination = [1] * (N+1)
  root = 2
  for i in range(math.floor(N/2), -1, -1):
    if s[i] == "1":
      for j in range(1, i):
        destination[root + j] = root
      root += 1
for i in range(2,N+1):
  print(i, destination[i])
Problem p03268 (python)

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

if K%2 == 1:
  cand = N // K
  ans = cand\
      + cand * (cand-1) * 3\
      + cand * (cand-1) * (cand-2)
  print(int(ans))
else:
  cand_mod0 = N // K
  ans_mod0 = cand_mod0\
           + cand_mod0 * (cand_mod0-1) * 3\
           + cand_mod0 * (cand_mod0-1) * (cand_mod0-2)
  cand_modhalf = N // K if N % K < K / 2 else (N // K) + 1
  ans_modhalf = cand_modhalf\
           + cand_modhalf * (cand_modhalf-1) * 3\
           + cand_modhalf * (cand_modhalf-1) * (cand_modhalf-2)
  print(int(ans_mod0 + ans_modhalf))

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

if K%2 == 1:
  cand = N // K
  print(int(cand + comb(cand,2) * 6 + comb(cand,3) * 6))
else:
  cand_mod0 = N // K
  ans_mod0 = cand_mod0\
           + cand_mod0 * (cand_mod0-1) * 3\
           + cand_mod0 * (cand_mod0-1) * (cand_mod0-2)
  cand_modhalf = N // K if N % K < K / 2 else (N // K) + 1
  ans_modhalf = cand_modhalf\
           + cand_modhalf * (cand_modhalf-1) * 3\
           + cand_modhalf * (cand_modhalf-1) * (cand_modhalf-2)
  print(int(ans_mod0 + ans_modhalf))
Problem p03269 (python)

Fixed submission:
import math

L = int(input())

N = math.floor(math.log(L, 2)) + 1
ans = []
for i in range(1, N):
    ans.append((i, i+1, 0))
    ans.append((i, i+1, 2**(N-i-1)))

tmp = 2 ** (N-1)
for j in range(N-1):
    if L >> j & 1:
        ans.append((1, N-j, (L >> (j+1)) << (j+1)))

print(N, len(ans))
for ans_i in ans:
    print(*ans_i)

Buggy submission (verdict: Runtime Error):
import math

L = int(input())

N = math.floor(math.log2(L)) + 1
ans = []
for i in range(1, N):
    ans.append((i, i+1, 0))
    ans.append((i, i+1, 2**(N-i-1)))

tmp = 2 ** (N-1)
for j in range(N-1):
    if L >> j & 1:
        ans.append((1, N-j, (L >> (j+1)) << (j+1)))

print(N, len(ans))
for ans_i in ans:
    print(*ans_i)
Problem p03276 (python)

Fixed submission:
import bisect

N, K = map(int, input().split())
x = list(map(int, input().split()))

index = bisect.bisect_left(x, 0)
if index < len(x):
  if x[index] != 0:
    x.insert(index, 0)
    N += 1
    K += 1
else:
  x.insert(index, 0)
  N += 1
  K += 1
  index -= 1

start_min = max(index-K+1, 0)
start_max = min(index, N-K)
min_time = 10**9
for i in range(start_min, start_max+1):
  min_time = min(min_time, x[i+K-1]-x[i]+min(abs(x[i+K-1]), abs(x[i])))
print(min_time)

Buggy submission (verdict: Runtime Error):
import bisect
import collections

N, K = map(int, input().split())
x = list(map(int, input().split()))

index = bisect.bisect_left(x, 0)
if x[index] != 0:
  x.insert(index, 0)
  N += 1
  K += 1

start_min = max(index-K+1, 0)
start_max = min(index, N-K)
min_time = 10**9
for i in range(start_min, start_max+1):
  min_time = min(min_time, x[i+K-1]-x[i]+min(abs(x[i+K-1]), abs(x[i])))
print(min_time)
Problem p03404 (python)

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

ans = [['#'] * 100 for _ in range(50)]
ans_ = [['.'] * 100 for _ in range(50)]
ans.extend(ans_)

h = 0
w = 0
for i in range(A-1):
    ans[h][w] = '.'
    w += 2
    if w >= 100:
        h += 2
        w = 0

h = 51
w = 0
for i in range(B-1):
    ans[h][w] = '#'
    w += 2
    if w >= 100:
        h += 2
        w = 0

print(100, 100)
for i in range(100):
    print(''.join(ans[i]))

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

ans = [['#'] * 100 for _ in range(50)]
ans_ = [['.'] * 100 for _ in range(50)]
ans.extend(ans_)

h = 0
w = 0
for i in range(A-1):
    ans[h][w] = '.'
    w += 2
    if w >= 10:
        h += 2
        w = 0

h = 51
w = 0
for i in range(B-1):
    ans[h][w] = '#'
    w += 2
    if w >= 10:
        h += 2
        w = 0

for i in range(100):
    print(''.join(ans[i]))
Problem p03436 (python)

Fixed submission:
from collections import deque


def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while True:
        if len(queue) > 0:
            y, x = queue.popleft()
            if [y, x] == [gy, gx]:
                return visited[y][x]
            for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                new_y, new_x = y+j, x+k
                if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
                    visited[new_y][new_x] = visited[y][x] + 1
                    queue.append([new_y, new_x])
        else:
            return -1


H, W = map(int, input().split())
white = 0
s = ['#' * (W + 2)]
for i in range(H):
    s_i = '#' + input() + '#'
    white += s_i.count('.')
    s.append(s_i)
s.append('#' * (W + 2))

visited = [[-1] * (W+2) for i in range(H+2)]
shortest = bfs(s, visited, 1, 1, H, W)
if shortest > 0:
    print(white - shortest - 1)
else:
    print(-1)

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


def bfs(maze, visited, sy, sx, gy, gx):
    queue = deque([[sy, sx]])
    visited[sy][sx] = 0
    while queue:
        y, x = queue.popleft()
        if [y, x] == [gy, gx]:
            return visited[y][x]
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])


H, W = map(int, input().split())
white = 0
s = ['#' * (W + 2)]
for i in range(H):
    s_i = '#' + input() + '#'
    white += s_i.count('.')
    s.append(s_i)
s.append('#' * (W + 2))

visited = [[-1] * (W+2) for i in range(H+2)]
shortest = bfs(s, visited, 1, 1, H, W)
print(white - shortest - 1)
Problem p03490 (python)

Fixed submission:
s = input()
x, y = map(int, input().split())

flg = 1
x_list = []
y_list = []
tmp = 0
for i, si in enumerate(s):
    if si == 'F':
        tmp += 1
    else:
        if flg == 1:
            x_list.append(tmp)
        else:
            y_list.append(tmp)
        flg *= -1
        tmp = 0
if flg == 1:
    x_list.append(tmp)
else:
    y_list.append(tmp)

x = sum(x_list) - x
y = sum(y_list) - y
if x % 2 != 0 or y % 2 != 0:
    print('No')
    exit()

if x < 0 or y < 0:
    print('No')
    exit()

x //= 2
y //= 2

if s[0] == 'F':
    x_list.reverse()
    x_list.pop()

dpx = [[0] * (x+1) for _ in range(len(x_list)+1)]
dpx[0][0] = 1
dpy = [[0] * (y+1) for _ in range(len(y_list)+1)]
dpy[0][0] = 1
for i in range(len(x_list)):
    for j in range(x+1):
        if dpx[i][j]:
            dpx[i+1][j] = 1
            if j + x_list[i] <= x:
                dpx[i+1][j+x_list[i]] = 1
for i in range(len(y_list)):
    for j in range(y+1):
        if dpy[i][j]:
            dpy[i+1][j] = 1
            if j + y_list[i] <= y:
                dpy[i+1][j+y_list[i]] = 1

if dpx[-1][-1] and dpy[-1][-1]:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
x, y = map(int, input().split())

flg = 1
x_list = []
y_list = []
tmp = 0
for i, si in enumerate(s):
    if si == 'F':
        tmp += 1
    else:
        if flg == 1:
            x_list.append(tmp)
        else:
            y_list.append(tmp)
        flg *= -1
        tmp = 0
if flg == 1:
    x_list.append(tmp)
else:
    y_list.append(tmp)

x = sum(x_list) - x
y = sum(y_list) - y
if x % 2 != 0 or y % 2 != 0:
    print('No')
    exit()
x //= 2
y //= 2

if s[0] == 'F':
    x_list.reverse()
    x_list.pop()

dpx = [[0] * (x+1) for _ in range(len(x_list)+1)]
dpx[0][0] = 1
dpy = [[0] * (y+1) for _ in range(len(y_list)+1)]
dpy[0][0] = 1
for i in range(len(x_list)):
    for j in range(x+1):
        if dpx[i][j]:
            dpx[i+1][j] = 1
            if j + x_list[i] <= x:
                dpx[i+1][j+x_list[i]] = 1
for i in range(len(y_list)):
    for j in range(y+1):
        if dpy[i][j]:
            dpy[i+1][j] = 1
            if j + y_list[i] <= y:
                dpy[i+1][j+y_list[i]] = 1

if dpx[-1][-1] and dpy[-1][-1]:
    print('Yes')
else:
    print('No')
Problem p03651 (python)

Fixed submission:
import fractions
from functools import reduce

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


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if K > max(A):
    print('IMPOSSIBLE')
elif K % gcd_list(A) != 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

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

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


def gcd_list(numbers):
    return reduce(math.gcd, numbers)


if K > max(A):
    print('IMPOSSIBLE')
elif K % gcd_list(A) != 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

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

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


def gcd(numbers):
    return reduce(math.gcd, numbers)

if K > max(A):
    print('IMPOSSIBLE')
elif K % gcd(A) != 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

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

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


def gcd(numbers):
    return reduce(math.gcd, numbers)

if K > max(A):
    print('IMPOSSIBLE')
elif K % gcd(A) != 0:
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')
Problem p03863 (python)

Fixed submission:
from collections import Counter

s = input()

ans = ['Second', 'First']
c = Counter(s)
flag = 0 if len(c) == 2 else 1
same = 1 if s[0] == s[-1] else 0
print(ans[((len(s) + same) % 2) * flag])

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

s = input()

ans = ['Second', 'First']
c = Counter(s)
flag = 0 if len(c) == 2 else 1
same = 1 if s[0] == s[-1] else 0
print(ans[(len(s) % 2 + same) * flag])
Problem p03988 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
yes = 'Possible'
no = 'Impossible'

if N == 2:
    if a[0] != 1 and a[1] != 1:
        print(no)
        exit()
    else:
        print(yes)
        exit()
if a[-1] != (a[0] + 1) // 2:
    print(no)
    exit()
else:
    if a[0] % 2 == 0:
        if a[-2] == a[-1]:
            print(no)
            exit()
    else:
        if a[-3] == a[-1]:
            print(no)
            exit()

ok = [0] * N
for i in range(N):
    ok[a[i]] += 1
for i in range(a[-1] + 1, a[0] + 1):
    if ok[i] < 2:
        print(no)
        exit()

print(yes)

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
yes = 'Possible'
no = 'Impossible'

if N == 2:
    if a[0] != 1 and a[1] != 1:
        print(no)
        exit()
if a[-1] !=  (a[0] + 1) // 2:
    print(no)
    exit()
else:
    if a[0] % 2 == 0:
        if a[-2] == a[-1]:
            print(no)
            exit()
    else:
        if a[-3] == a[-1]:
            print(no)
            exit()

ok = [0] * N
for i in range(N):
    ok[a[i]] += 1
for i in range(a[-1] + 1, a[0] + 1):
    if ok[i] < 2:
        print(no)
        exit()

print(yes)