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

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
v = [[] for _ in range(N)]
for _ in range(N-1) :
    a, b = map(int, input().split())
    v[a-1].append(b-1)
    v[b-1].append(a-1)
    
pq = [0 for _ in range(N)]
for _ in range(Q) :
    p, q = map(int, input().split())
    pq[p-1] += q
    
visited = [False] * N
visited[0] = True

ret = [0] * N
def bfs(cur, score) :
    ret[cur] = score + pq[cur]
    for nex in v[cur] :
        if not visited[nex] :
            visited[nex] = True
            bfs(nex, ret[cur])

bfs(0, 0)
    
print(*ret)

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

N, Q = map(int, input().split())
v = [[] for _ in range(N)]
for _ in range(N-1) :
    a, b = map(int, input().split())
    v[a-1].append(b-1)
    v[b-1].append(a-1)
    
visited = [False] * N
visited[0] = True
parent = [[] for _ in range(N)]

def bfs(cur, par) :
    parent[cur] = [cur] + par
    for nex in v[cur] :
        if not visited[nex] :
            visited[nex] = True
            bfs(nex, parent[cur])

bfs(0, [])

pq = [0 for _ in range(N)]
for _ in range(Q) :
    p, q = map(int, input().split())
    pq[p-1]  += q

ret = []
for i in range(N) :
    s = 0
    for j in parent[i] :
        s += pq[j]

    ret.append(s)
    
print(*ret)
Problem p02972 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

N = int(input())
a = [0]+[int(i) for i in input().split()]
ret = [0] * (N+1)

def rec(i) :
    if i == N + 1 :
        return
    rec(i+1)
    s = 0
    for j in range(i, N + 1, i) :
        s ^= ret[j]
    ret[i] = s^a[i]
    
rec(1)
b = []
for i in range(1, N + 1) :
    if ret[i] :
        b.append(str(i))
print(len(b))
print(' '.join(b))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**5)

N = int(input())
a = [0]+[int(i) for i in input().split()]
ret = [0] * (N+1)

def rec(i) :
    if i == N + 1 :
        return
    rec(i+1)
    s = 0
    for j in range(i, N + 1, i) :
        s += ret[j]
    ret[i] = (s%2)^a[i]
    
rec(1)
b = []
for i in range(1, N + 1) :
    if ret[i] :
        b.append(str(i))
print(len(b))
print(' '.join(b))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [0]+[int(i) for i in input().split()]
ret = [0] * (N+1)

def rec(i) :
    if i == N :
        return
    rec(i+1)
    s = 0
    for j in range(i, N + 1, i) :
        s += ret[j]
    ret[i] = s^a[i]
    
rec(1)
b = []
for i in range(1, N + 1) :
    if ret[i] :
        b.append(str(i))
print(len(b))
print(' '.join(b))
Problem p02976 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N, M = map(int, input().split())

if M % 2 == 0 :
    vec = [[] for _ in range(N)]
    for _ in range(M) :
        A, B = map(int, input().split())
        vec[A-1].append(B-1)
        vec[B-1].append(A-1)

    visited = [False] * N
    CD = [[] for _ in range(N)]

    def dfs(cur, pre) :
        for nex in vec[cur] :
            if nex == pre :
                continue
            
            if not visited[nex] :
                visited[nex] = True
                dfs(nex, cur)
            elif not cur in CD[nex] :
                CD[cur].append(nex)
        
        if pre != -1 :
            if len(CD[cur]) % 2 == 0 :
                CD[pre].append(cur)
            else :
                CD[cur].append(pre)

    visited[0] = True            
    dfs(0, -1)

    for i in range(N) :
        for j in CD[i] :
            print(i + 1, j + 1)
else :
    print(-1)

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

if M % 2 == 0 :
    vec = [[] for _ in range(N)]
    for _ in range(M) :
        A, B = map(int, input().split())
        vec[A-1].append(B-1)
        vec[B-1].append(A-1)

    visited = [False] * N
    CD = [[] for _ in range(N)]

    def dfs(cur, pre) :
        for nex in vec[cur] :
            if nex == pre :
                continue
            
            if not visited[nex] :
                visited[nex] = True
                dfs(nex, cur)
            elif not cur in CD[nex] :
                CD[cur].append(nex)
        
        if pre != -1 :
            if len(CD[cur]) % 2 == 0 :
                CD[pre].append(cur)
            else :
                CD[cur].append(pre)

    visited[0] = True            
    dfs(0, -1)

    for i in range(N) :
        for j in CD[i] :
            print(i + 1, j + 1)
else :
    print(-1)
Problem p02978 (python)

Fixed submission:
# ikatakosさんの提出を見てlru_cacheなるものを知った。
# まだまだ知らないことがたくさんありますね。

from functools import lru_cache

N = int(input())
A = [int(i) for i in input().split()]

@lru_cache(maxsize=None)
def rec(l, r, xl, xr) :
    if l + 1 == r :
        return 0
    
    return min(rec(l, m, xl, xl+xr)+rec(m, r, xl+xr, xr)+A[m]*(xl+xr) for m in range(l+1, r))
    
print(A[0] + rec(0, N-1, 1, 1) + A[N-1])

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

int N;
int A[18];

long long rec(int l, int r, long long xl, long long xr) {
    if (r - l == 1) {
        return 0;
    }
    
    long long ret = (long long) 1e18;
    for (int i = l + 1; i < r; i++) {
        long long tmp = A[i] * (xl+xr) + rec(l, i, xl, xl+xr) + rec(i, r, xl+xr, xr);
        ret = min(ret, tmp);
    }
    return ret;
}

int main() {    
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    cout << rec(0, N - 1, 1, 1) + A[0] + A[N - 1];
    
}
Problem p03240 (python)

Fixed submission:
N = int(input())

xyh1 = [] # h > 0
xyh2 = [] # h = 0
for _ in range(N) :
    x, y, h = map(int, input().split())
    if h > 0 :
        xyh1.append((x, y, h))
    else :
        xyh2.append((x, y, h))

def solve() :
    for Cx in range(0, 101) :
        for Cy in range(0, 101) :
            # 特定できるからxyh1は必ず1つは要素を持つ
            x, y, h = xyh1[0]
            H = h + abs(x-Cx) + abs(y-Cy)
            
            flag = False
            for x, y, h in xyh1[1:] :
                if H != h + abs(x-Cx) + abs(y-Cy) :
                    flag = True
                    break
                    
            if flag :
                continue
                
            for x, y, h in xyh2 :
                if H - abs(x-Cx) - abs(y-Cy) > 0 :
                    flag = True
                    break
                    
            if flag :
                continue
                
            return (Cx, Cy, H)
            
print(*solve())

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

xyh1 = [] # h > 0
xyh2 = [] # h = 0
for _ in range(N) :
    x, y, h = map(int, input().split())
    if h > 0 :
        xyh1.append((x, y, h))
    else :
        xyh2.append((x, y, h))

def solve() :
    for Cx in range(0, 101) :
        for Cy in range(0, 101) :
            # 特定できるからxyh1は必ず1つは要素を持つ?
            x, y, h = xyh1[0]
            H = h + abs(x-Cx) + abs(y-Cy)
            
            flag = False
            for x, y, h in xyh1[1:] :
                if H != h + abs(x-Cx) + abs(y-Cy) :
                    flag = True
                    break
                    
            if flag :
                continue
                
            for x, y, h in xyh2 :
                if h + abs(x-Cx) + abs(y-Cy) > 0 :
                    flag = True
                    break
                    
            if flag :
                continue
                
            return (Cx, Cy, H)
            
print(*solve())
Problem p03297 (python)

Fixed submission:
T = int(input())
ABCD = [[int(i) for i in input().split()] for _ in range(T)]

def gcd(a, b) :
    a, b = max(a, b), min(a, b)
    while b != 0 :
        a, b = b, a % b
    return a

def solve(A, B, C, D) :
    if B > A or B > D :
        return 'No'
        
    a0 = A % B
    d = gcd(B, D)
    if a0 + ((C - a0) // d + 1) * d >= B :
        return 'Yes'
        
    return 'No'

for A, B, C, D in ABCD :
    print(solve(A, B, C, D))

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

T = int(input())
ABCD = [[int(i) for i in input().split()] for _ in range(T)]

def solve(A, B, C, D) :
    if B > A or B > D :
        return 'No'
        
    a0 = A % B
    d = gcd(B, D)
    if a0 + ((C - a0) // d + 1) * d >= B :
        return 'Yes'
        
    return 'No'

for A, B, C, D in ABCD :
    print(solve(A, B, C, D))
Problem p03318 (python)

Fixed submission:
K = int(input())

def S(x) :
    ret = 0
    while x :
        ret += x % 10
        x //= 10
    return ret

L = set()
nine = ''
for i in range(16) :
    for j in range(1, 1000) :
        x = int(str(j) + nine)
        L.add(x)
    nine += '9'
    
L = list(L)
L.sort()

v = [1]
n = [1]

for l in L[1:] :
    x = l / S(l)
    while v[-1] > x :
        v.pop()
        n.pop()
    v.append(x)
    n.append(l)

for i in range(K) :
    print(n[i])

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

def S(x) :
    ret = 0
    while x :
        ret += x % 10
        x //= 10
    return ret

v = [1]
n = [1]
for i in range(2, 1000) :
    x = i / S(i)
    while v[-1] > x :
        v.pop()
        n.pop()
    v.append(x)
    n.append(i)

suf = 99
for i in range(2, 14) :
    for j in range(10, 100) :
        k =  j * (10 ** i) + suf
        x = k / S(k)
        while v[-1] > x :
            v.pop()
            n.pop()
        v.append(x)
        n.append(k)
    
    suf = suf * 10 + 9

for i in range(K) :
    print(n[i])

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

def S(x) :
    ret = 0
    while x :
        ret += x % 10
        x //= 10
    return ret

v = [1]
n = [1]
for i in range(2, 1000) :
    x = i / S(i)
    while v[-1] > x :
        v.pop()
        n.pop()
    v.append(x)
    n.append(i)

suf = 99
for i in range(2, 11) :
    for j in range(10, 100) :
        k =  j * (10 ** i) + suf
        x = k / S(k)
        while v[-1] > x :
            v.pop()
            n.pop()
        v.append(x)
        n.append(k)
    
    suf = suf * 10 + 9

for i in range(K) :
    print(n[i])
Problem p03323 (python)

Fixed submission:
A, B = map(int, input().split())
if A > 8 or B > 8 :
  print(':(')
else :
  print('Yay!')

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
if A > 8 or B >  :
  print(':(')
else :
  print('Yay!')
Problem p03343 (python)

Fixed submission:
N, K, Q = map(int, input().split())
A = [int(i) for i in input().split()]

def solve() :
    if Q == 1 : return 0
        
    ret = float('inf')
    for i in range(N) :
        l = -1
        for j in range(i, max(-1, i - K), -1) :
            if A[j] < A[i] :
                l = j
                break
        r = N      
        for j in range(i, min(N, i + K)) :
            if A[j] < A[i] :
                r = j
                break
                
        if r - l - 1 < K :
            continue
            
        B = A[::]
        B.pop(i)
        
        C = [-1]
        for j in range(N - 1) :
            if B[j] < A[i] :
                C.append(j)
        C.append(N - 1)
        
        D = []
        for j in range(len(C) - 1) :
            if C[j+1] - C[j] >= K :
                D += sorted(B[C[j]+1:C[j+1]])[:C[j+1] - C[j] - K]
        
        if len(D) >= Q - 1 :
            D.sort()
            ret = min(ret, D[Q-2] - A[i])

    return ret
    
print(solve())

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right

N, K, Q = map(int, input().split())
A = [int(i) for i in input().split()]

ret = float('inf')
for i in range(N) :
    l = -1
    for j in range(i, max(-1, i - Q), -1) :
        if A[j] < A[i] :
            l = j
            break
    r = N      
    for j in range(i, min(N, i + Q)) :
        if A[j] < A[i] :
            r = j
            break
    # print(A[i], r, l)
    if r - l - 1 < Q :
        continue
        
    # print('最小値', i, A[i])
    B = A[::]
    B.pop(i)
    # print(B)
    
    C = [-1]
    for j in range(N - 1) :
        if B[j] < A[i] :
            C.append(j)
    C.append(N - 1)
    # print(C)
    
    D = []
    for j in range(len(C) - 1) :
        if C[j+1] - C[j] - 1 >= K :
            D += sorted(B[C[j]+1:C[j+1]])[:C[j+1] - C[j] - K]
    # print(D)
    
    if len(D) >= Q - 1 :
        D.sort()
        ret = min(ret, D[Q-2] - A[i])
        # print(D[Q-2], A[i], ret)
    # print()

if ret == float('inf') :
    while True :
        pass
else :
    print(ret)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left, bisect_right

N, K, Q = map(int, input().split())
A = [int(i) for i in input().split()]

ret = float('inf')
for i in range(N) :
    l = 0
    for j in range(i, max(-1, i - Q), -1) :
        if A[j] < A[i] :
            l = j + 1
            break
    r = N - 1        
    for j in range(i, min(N, i + Q + 1)) :
        if A[j] < A[i] :
            r = j - 1
            break
            
    if r - l + 1 < Q :
        continue
        
    B = A[::]
    B.pop(i)

    C = [-1]
    for j in range(N - 1) :
        if B[j] < A[i] :
            C.append(j)
    C.append(N - 1)

    D = []    
    for j in range(len(C) - 1) :
        if C[j+1] - C[j] - 1 >= K :
            D += sorted(B[C[j]+1:C[j+1]])[:C[j+1] - C[j] - K]
    
    if len(D) >= Q - 1 :
        D.sort()
        ret = min(ret, D[Q-2] - A[i])
        
print(ret)
Problem p03573 (python)

Fixed submission:
A, B, C = map(int, input().split())
if A == B :
    print(C)
elif A == C :
    print(B)
else :
    print(A)

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
if A == B :
    print(C)
elif A == C :
    print(B) :
else :
    print(A)
Problem p03689 (python)

Fixed submission:
H, W, h, w = map(int, input().split())

if h == w == 1 :
  print('No')

else :
  a = (10 ** 9 - 1) // (h * w - 1)
  ret = [[a] * W for _ in range(H)]
  for y in range(h - 1, H, h) :
    for x in range(w - 1, W, w) :
      ret[y][x] = - a * (h * w - 1) - 1

  s = 0
  for y in range(H) :
    s += sum(ret[y])
    
  if s > 0 :
    print('Yes')
    for r in ret :
      print(*r)
  else :
    print('No')

Buggy submission (verdict: Runtime Error):
H, W, h, w = map(int, input().split())

a = (10 ** 9 - 1) // (h * w - 1)
ret = [[a] * W for _ in range(H)]
for y in range(h - 1, H, h) :
  for x in range(w - 1, W, w) :
    ret[y][x] = - a * (h * w - 1) - 1

s = 0
for y in range(H) :
  s += sum(ret[y])
  
if s > 0 :
  print('Yes')
  for r in ret :
    print(*r)
else :
  print('No')
Problem p03732 (python)

Fixed submission:
import sys
input = sys.stdin.readline

N, W = map(int, input().split())
wv = [[int(i) for i in input().split()] for _ in range(N)]

s = [[] for _ in range(4)]
w0 = wv[0][0]
for w, v in wv :
    s[w-w0].append(v)
for i in range(4) :
    s[i].sort(reverse=True)
    s[i] = [0] + s[i]
    for j in range(1, len(s[i])) :
        s[i][j] += s[i][j-1]

M = 0
for i0 in range(len(s[0])) :
    for i1 in range(len(s[1])) :
        for i2 in range(len(s[2])) :
            for i3 in range(len(s[3])) :
                if i0*w0+i1*(w0+1)+i2*(w0+2)+i3*(w0+3) <= W :
                    M = max(M, s[0][i0]+s[1][i1]+s[2][i2]+s[3][i3])
                    
print(M)

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

N, W = map(int, input().split())
wv = [[int(i) for i in input().split()] for _ in range(N)]

wv.sort()
s, t = 0, 0
ns, nt = 0, 0
for i in range(N) :
    if s + wv[i][0] <= W :
        s += wv[i][0]
        ns += 1
    else :
        break
for i in range(N-1, -1, -1) :
    if t + wv[i][0] <= W :
        t += wv[i][0]
        nt += 1
    else :
        break
        
if ns == nt :
    wv.sort(key=lambda x: x[1], reverse=True)
    ret = 0
    for w, v in wv :
        if w < W :
            ret += v
            W -= w
    print(ret)
else :
    dp = [[0] * (W + 1) for _ in range(N + 1)]

    for i in range(1, N + 1) :
        w, v = wv[i-1]
        for j in range(W+1) :
            if j < w :
                dp[i][j] = dp[i-1][j]
            else :
                dp[i][j] = max(dp[i-1][j], dp[i-1][j - w] + v)
                
    print(dp[N][W])

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

N, W = map(int, input().split())
wv = [[int(i) for i in input().split()] for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(1, N + 1) :
    w, v = wv[i-1]
    for j in range(W+1) :
        if j < w :
            dp[i][j] = dp[i-1][j]
        else :
            dp[i][j] = max(dp[i-1][j], dp[i-1][j - w] + v)
            
print(dp[N][W])
Problem p03740 (python)

Fixed submission:
X, Y = map(int, input().split())

if abs(X-Y) <= 1 :
    print('Brown')
else :
    print('Alice')

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

def rec(x, y) :
    flg = False
    for i in range(2, x + 1, 2) :
        flg = flg or not rec(x-i, y+i//2)
    for i in range(2, y + 1, 2) :
        flg = flg or not rec(x+i//2, y-i)
        
    return flg
    
if rec(X, Y) :
    print('Alice')
else :
    print('Brown')
Problem p03801 (python)

Fixed submission:
from collections import defaultdict

N = int(input())
a = [int(i) for i in input().split()]

b = defaultdict(lambda : [float('inf'), 0])
for i in range(N) :
    b[a[i]][0] = min(b[a[i]][0], i)
    b[a[i]][1] += 1

# [value, first_appearance, count]
c = [(0, 0, 0)]
for k, v in b.items() :
    c.append((k, v[0], v[1]))
c.sort()

ret = [0] * N
pre_v, pre_i, pre_c = c.pop()
while c :
    cur_v, cur_i, cur_c = c.pop()
    ret[pre_i] += (pre_v - cur_v) * pre_c
    cur_c += pre_c
    pre_v, pre_i, pre_c = cur_v, min(pre_i, cur_i), cur_c
    
for r in ret :
    print(r)

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

N = int(input())
a = [int(i) for i in input().split()]

b = defaultdict(lambda : [float('inf'), 0])
for i in range(N) :
    b[a[i]][0] = min(b[a[i]][0], i)
    b[a[i]][1] += 1

# [value, first_appearance, count]
c = [(0, 0, 0)]
for k, v in b.items() :
    c.append((k, *v))
c.sort()

ret = [0] * N
pre_v, pre_i, pre_c = c.pop()
while c :
    cur_v, cur_i, cur_c = c.pop()
    ret[pre_i] = (pre_v - cur_v) * pre_c
    cur_c += pre_c
    pre_v, pre_i, pre_c = cur_v, cur_i, cur_c
    
for r in ret :
    print(r)
Problem p02603 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
money = 1000
stock = 0

for i in range(N-1):
  if A[i] < A[i+1]:
    stock = money // A[i]
    money += stock * (A[i+1] - A[i])
    
print(money)

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

ls = []
if A[0] < A[1]:
  ls.append(A[0])
for i in range(1,N-1):
  if A[i] == A[i-1]:
    continue
  elif A[i-1] < A[i] <= A[i+1]:
    continue
  elif A[i-1] > A[i] >= A[i+1]:
    continue
  ls.append(A[i])  
if A[-1] > A[-2]:
  ls.append(A[-1])
    
if ls == []:
  print(1000)
else:
  for i,j in enumerate(ls_1):
    if i%2 == 0:
      stock += my_money//j
      my_money %= j
    else:
      my_money += stock*j
      stock = 0
  print(my_money)
Problem p02615 (python)

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

ans = A[0]

for i in range(1,(N-2)//2+1):
  ans += A[i]*2
  
if N % 2 == 1:
  ans += A[(N-2)//2 + 1]

print(ans)

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

A = sorted(A,reverse=True)

if N <= 3:
  print(sum(A[:-1]))
elif N % 2 == 0:
  ans = A[0] + sum(A[1:N//2])*2
elif N % 2 == 1:
  ans = A[0] + sum(A[1:N//2])*2 + A[1+N//2]
  
print(ans)
Problem p02641 (python)

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

if N == 0:
  print(X)
else:
  for i in range(X,-2,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,102):
    if j not in P:
      b = abs(j - X)
      break
  if a <= b:
    print(i)
  else:
    print(j)

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

if N == 0:
  print(X)
  sys.exit()

P = list(map(int,input().split()))

if X not in P:
  print(X)
else:
  for i in range(X-1,-2,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,102):
    if j not in P:
      b = abs(j - X)
      break
      
if a <= b:
  print(i)
else:
  print(j)

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

if N == 0:
  print(X)
  sys.exit()

P = list(map(int,input().split()))

if X not in P:
  print(X)
else:
  for i in range(X-1,min(P)-2,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,max(P)+2):
    if j not in P:
      b = abs(j - X)
      break
      
if a <= b:
  print(i)
else:
  print(j)

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

if N == 0:
  print(X)
  sys.exit()

P = list(map(int,input().split()))

if X not in P:
  print(X)
else:
  a = float("inf")
  b = float("inf")
  for i in range(X-1,0,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,max(P)+2):
    if j not in P:
      b = abs(j - X)
      break
      
if a <= b:
  print(i)
else:
  print(j)

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

if N == 0:
  print(X)
  sys.exit()

P = list(map(int,input().split()))

if X not in P:
  print(X)
else:
  for i in range(X-1,0,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,max(P)+2):
    if j not in P:
      b = abs(j - X)
      break
      
if a <= b:
  print(i)
else:
  print(j)

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

if P == [] or X not in P:
  print(X)
else:
  for i in range(X-1,0,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,max(P)+2):
    if j not in P:
      b = abs(j - X)
      break
      
if a <= b:
  print(i)
else:
  print(j)
Problem p02696 (python)

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

if B > N:
  ans = math.floor(A * N / B)
else:
  ans = math.floor(A * (B - 1) / B)
  
print(ans)

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

if B > N:
  ans = math.floor(A * N / B) - A * math.floor(N // B)
else:
  ans = math.floor(A * (B - 1) / B) - A * math.floor(N // (B - 1))
  
print(ans)

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

if B > N:
  ans = (A * N) // B - A * (N // B)
else:
  ans = (A * (B - 1)) // B - A * (N // (B - 1))
  
print(ans)
Problem p02714 (python)

Fixed submission:
N = int(input())
S = input()

ans = S.count("R") * S.count("G") * S.count("B")

for i in range(1,N-1):
  for j in range(i+1,N):
    k = 2 * j - i
    if k > N:
      break
    if S[i-1] != S[j-1] and S[j-1] != S[k-1] and S[k-1] != S[i-1]:
      ans -= 1
      
print(ans)

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

I = []
J = []
K = []

for n in range(1,N+1):
  if S[n-1] == "R":
    I.append(n)
  elif S[n-1] == "G":
    J.append(n)
  else:
    K.append(n)
    
cnt = 0
for a in I:
  for b in J:
    for c in K:
      ls = [a,b,c]
      ls.sort()a
      if ls[1] - ls[0] != ls[2] - ls[1]:
        cnt += 1
    
print(cnt)
Problem p02813 (python)

Fixed submission:
import itertools
N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
ls = list(itertools.permutations(range(1,N+1)))
print(abs(ls.index(P) - ls.index(Q)))

Buggy submission (verdict: Runtime Error):
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
ls = list(itertools.permutations(range(1,N+1)))
print(abs(ls.index(P) - ls.index(Q)))
Problem p02830 (python)

Fixed submission:
N = int(input())
S,T = input().split()

res = ""
for i in range(N):
  res += S[i]
  res += T[i]

print(res)

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

res = ""
for i in range(N):
  res += S[i]
  res += T[i]

print(res)