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

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

def main():
    n, q = map(int, input().split())
    a = list(map(int, input().split()))
    
    s = [0]*(n+1)
    odd = [0]*(n+1)
    even = [0]*(n+1)
    for i in range(n):
        s[i+1] += s[i]+a[i]
        odd[i+1] += odd[i]
        even[i+1] += even[i]
        if i%2:
            odd[i+1] += a[i]
        else:
            even[i+1] += a[i]
    
    key = []
    value = dict()
    v = 0
    for i in range(n):
        if i == n-1:
            k = pow(10, 9)
            key.append(k)
            value[k] = v
            continue
            
        k = (a[i+(n-i)//2]+a[i])//2
        v = s[i+(n-i)//2]-s[i]
        if (n-i)%2:
            if i%2:
                v += even[max(0, i)]
            else:
                v += odd[max(0, i)]
        else:
            if i%2:
                v += odd[max(0, i-1)]
            else:
                v += even[max(0, i-1)]
        
        key.append(k)
        value[k] = v
    
    sum_a = s[n]
    
    for i in range(q):
        x = int(input())
        k = key[bisect.bisect_left(key, x)]
        ans = sum_a-value[k]
        print(ans)
    
    
if __name__ == "__main__":
    main()

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

def main():
    n, q = map(int, input().split())
    a = list(map(int, input().split()))
    
    s = [0]*(n+1)
    odd = [0]*(n+1)
    even = [0]*(n+1)
    for i in range(n):
        s[i+1] += s[i]+a[i]
        odd[i+1] += odd[i]
        even[i+1] += even[i]
        if i%2:
            odd[i+1] += a[i]
        else:
            even[i+1] += a[i]
    
    key = []
    value = dict()
    v = 0
    for i in range(n):
        if i == n-1:
            k = pow(10, 9)
            key.append(k)
            value[k] = v
        k = (a[i+(n-i)//2]+a[i])//2
        v = s[i+(n-i)//2]-s[i]
        if (n-i)%2:
            if i%2:
                v += even[max(0, i)]
            else:
                v += odd[max(0, i)]
        else:
            if i%2:
                v += odd[max(0, i-1)]
            else:
                v += even[max(0, i-1)]
        
        key.append(k)
        value[k] = v
    
    sum_a = s[n]
    
    for i in range(q):
        x = int(input())
        k = key[bisect.bisect_left(key, x)]
        ans = sum_a-value[k]
        print(ans)
    
    
if __name__ == "__main__":
    main()
Problem p03160 (python)

Fixed submission:
n = int(input())
h = [int(x) for x in input().split()]
inf = 10**9+7

dp_list = [inf]*(n)

for i in range(n):
  if i == 0:
    dp_list[i] = 0
  elif i == 1:
    dp_list[i] = abs(h[1]-h[0])
  else:
    dp_list[i] = min([dp_list[i-1]+abs(h[i]-h[i-1]), dp_list[i-2]+abs(h[i]-h[i-2])])


print(dp_list[n-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(x) for x in input().split()]

dp_list = [-1]*(n)

def dp(n):
  if dp_list[n] == -1:
    if n == 0:
      dp_list[0] = 0
    elif n == 1:
      dp_list[1] = abs(h[1]-h[0])
    else:
      dp_list[n] = min([dp(n-1)+abs(h[n]-h[n-1]), dp(n-2)+abs(h[n]-h[n-2])])
  return dp_list[n]

ans = dp(n-1)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
h = [int(x) for x in input().split()]

dp_list = [-1]*(n)

def dp(n):
  if n == 0:
    dp_list[0] = 0
    return 0
  if n == 1:
    dp_list[1] = abs(h[1]-h[0])
    return dp_list[1]
  if dp_list[n] == -1:
    dp_list[n] = min([dp(n-1)+abs(h[n]-h[n-1]), dp(n-2)+abs(h[n]-h[n-2])])
  return dp_list[n]

ans = dp(n-1)
print(ans)
Problem p03168 (python)

Fixed submission:
import sys
sys.setrecursionlimit(4000)

n = int(input())
p = [float(x) for x in input().split()]

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

dp[0][0] = 1-p[0]
dp[0][1] = p[0]

for i in range(n-1):
  for j in range(i+2):
    dp[i+1][j] += dp[i][j]*(1-p[i+1])
    dp[i+1][j+1] += dp[i][j]*p[i+1]

ans = 0
for i in range(n//2+1, n+1):
  ans += dp[n-1][i]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
p = [float(x) for x in input().split()]

dp_list = [[0]*(n+1) for i in range(n)]

def dp(i, j):
  if dp_list[i][j] == 0:
    if i == 0:
      if j == 0:
        dp_list[i][j] = 1-p[i]
      if j == 1:
        dp_list[i][j] = p[i]
    elif j-i == 1:
      dp_list[i][j] = dp(i-1, j-1)*p[i]
    elif j == 0:
       dp_list[i][j] = dp(i-1, j)*(1-p[i])
    else:
      dp_list[i][j] = dp(i-1, j)*(1-p[i]) + dp(i-1, j-1)*p[i]
  return dp_list[i][j]

ans = 0
for i in range(n//2+1, n+1):
  ans += dp(n-1, i)
print(ans)
Problem p03169 (python)

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


N = int(input())
memo = [[[-1]*(N+1) for _ in range(N+1)] for _ in range(N+1)]

def dp(a, b, c):
    if a == b == c == 0: return 0
    if memo[a][b][c] != -1:
        return memo[a][b][c]
    
    res = N
    if a > 0: res += a*dp(a-1, b, c)
    if b > 0: res += b*dp(a+1, b-1, c)
    if c > 0: res += c*dp(a, b+1, c-1)
    res /= a+b+c
    
    memo[a][b][c] = res
    return res

def main():
    A = list(map(int, input().split()))
    
    count = Counter(A)
    for i in range(1, 4):
        if not i in count: count[i] = 0
    x, y, z = count[1], count[2], count[3]

    
    ans = dp(x, y, z)
    
    print(ans)
        

    
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

map<ll, double> memo;

double dp(int a, int b, int c, int n){
    if ((a == 0) && (b == 0) && (c == 0)) return 0.0;
    if ((a < 0) || (b < 0) || (c < 0)) return 0.0;
    if ((a > n) || (b > n) || (c > n)) return 0.0;
    ll judge = a*1000000+b*1000+c;
    if (memo[judge] != 0) return memo[judge];
    double res = n;
    res += a*dp(a-1, b, c, n);
    res += b*dp(a+1, b-1, c, n);
    res += c*dp(a, b+1, c-1, n);
    res /= a+b+c;
    memo[judge] = res;
    return res;
}

int main(void){
    int n;
    scanf("%d", &n);
    int a = 0;
    int b = 0;
    int c = 0;
    int sub;
    rep(i, n){
        scanf("%d", &sub);
        if (sub == 1) a++;
        if (sub == 2) b++;
        if (sub == 3) c++;
    }
    
    double ans;
    ans = dp(a, b, c, n);
    
    printf("%.11lf", ans);
    
    return 0;
}
Problem p03220 (python)

Fixed submission:
n = int(input())
t, a = map(int, input().split())
h = list((abs(t-0.006*int(x)-a), s) for x, s in zip(input().split(), range(n)))
k = min(h)
print(k[1]+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
t, a = map(int, input().split())
h = list(abs(t-0.006*int(x)-a), t for x, t in zip(input().split(), range(n)))
k = min(h)
print(k[1])
Problem p03238 (python)

Fixed submission:
n = int(input())
if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a+b)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())
c = a+b
if n == 1:
    print("Hello World")
else:
    print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())
c = a+b
print("Hello World" if n == 1 else c)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())
print("Hello World" if n == 1 else a+b)
Problem p03240 (python)

Fixed submission:
import sys

def height(a, b, c, d, e):
    return abs(a-d)+abs(b-e)+c

n = int(input())
hint = []
q = 0
for i in range(n):
    a, b, c = map(int, input().split())
    hint.append([c, a, b])
hint.sort(reverse=True)

for i in range(101):
    for j in range(101):
        frag = True
        H = height(hint[0][1], hint[0][2], hint[0][0], i, j)
        for h in hint[1:]:
            if h[0] != max(-abs(h[1]-i)-abs(h[2]-j)+H,0):
                frag = False
                break
        if frag:
            print(i, j, H)
            sys.exit()

Buggy submission (verdict: Runtime Error):
import sys

def height(a, b, c, d, e):
    return abs(a-d)+abs(b-e)+c

n = int(input())
hint = []
q = 0
for i in range(n):
    a, b, c = map(int, input().split())
    hint.append(c, a, b)
hint.sort(reverse=True)

for i in range(101):
    for j in range(101):
        frag = True
        H = height(hint[0][1], hint[0][2], hint[0][0] i, j)
        for h in hint[1:]:
            if height(h[1], h[2], h[0], i, j) != H:
                frag = False
                break
        if frag:
            print(i, j, H)
            sys.exit()

Buggy submission (verdict: Runtime Error):
 n = int(input())
hint = []
for i in range(n):
    a, b, c = map(int, input().split())
    hint.append([a, b, c])
frag2 = False
for i in range(101):
    for j in range(101):
        ans_h = -1
        frag = False
        for k in range(n):
            a, b, c = hint[k][0], hint[k][1], hint[k][2]
            if c != 0:
                if ans_h == -1:
                    ans_h = abs(a-i)+abs(b-j)+c
                else:
                    if ans_h != abs(a-i)+abs(b-j)+c:
                        frag = True
                        break
                    else:
                        continue
        if not frag:
            answer = [i, j, ans_h]
            frag2 = True
            break
    if frag2:
        break

for i in range(3):
    print(answer[i], end=" ")
Problem p03260 (python)

Fixed submission:
a, b = map(int, input().split())
if a%2==1 and b%2==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
print("Yes" if i%2==1 for i in [map(int, input().split())] else "No")
Problem p03261 (python)

Fixed submission:
import sys
n = int(input())
yetlist = []
for i in range(n):
    word = input()
    if word in yetlist:
        print("No")
        sys.exit()
    if yetlist:
        if word[0] != yetlist[-1][-1]:
            print("No")
            sys.exit()
    yetlist.append(word)
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
yetlist = []
for i in range(n):
    word = input()
    if word in yetlist:
        print("No")
        sys.exit()
    if word[0] != yetlist[-1][-1]:
        print("No")
        sys.exit()
    yetlist.append(word)
print("Yes")
Problem p03262 (python)

Fixed submission:
def gcd(p, q):
    if p < q:
        p, q = q, p
    while q > 0:
        p, q = q, p%q
    return p
n, x = map(int, input().split())
x_list = [abs(int(i)-x) for i in input().split()]
a = x_list[0]
for i in range(1, n):
    a = gcd(a, x_list[i])
print(a)

Buggy submission (verdict: Runtime Error):
from math import gcd
n, x = map(int, input().split())
x_list = [abs(int(i)-x) for i in input().split()]
a = x_list[0]
for i in range(1, n):
    a = gcd(a, x_list[i])
print(a)
Problem p03263 (python)

Fixed submission:
h, w = map(int, input().split())
a = [0]*h
for i in range(h):
  a[i] = [int(x)%2 for x in input().split()]

ans = 0
ans_list = []
key = 0
for i in range(h):
  if i%2 == 0:
    for j in range(w):
      p = a[i][j]
      if key == 0:
        if p == 0:
          pass
        else:
          key = 1
      else:
        if p == 0:
          key = 1
          ans += 1
          if j == 0:
            ans_list.append([i, j+1, i+1, j+1])
          else:
            ans_list.append([i+1, j, i+1, j+1])
        else:
          key = 0
          ans += 1
          if j == 0:
            ans_list.append([i, j+1, i+1, j+1])
          else:
            ans_list.append([i+1, j, i+1, j+1])
        
      
  else:
    for j in range(w-1, -1, -1):
      p = a[i][j]
      if key == 0:
        if p == 0:
          pass
        else:
          key = 1
      else:
        if p == 0:
          key = 1
          ans += 1
          if j == w-1:
            ans_list.append([i, j+1, i+1, j+1])
          else:
            ans_list.append([i+1, j+2, i+1, j+1])
        else:
          key = 0
          ans += 1
          if j == w-1:
            ans_list.append([i, j+1, i+1, j+1])
          else:
            ans_list.append([i+1, j+2, i+1, j+1])

print(ans)
for i in range(ans):
  print(*ans_list[i])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
mapping = [0]*h
for i in range(h):
  mapping[i] = [int(x)%2 for x in input().split()]

ans = []
side = [0]*h
key = 0
for i in range(h):
  k = 0
  for j in range(w-1):
    if mapping[i][j]:
      if k == 0:
        k = 1
        ans.append([i+1, j+1, i+1, j+2])
      else:
        k = 0
    else:
      if k == 1:
        ans.append([i+1, j+1, i+1, j+2])
      else:
        continue
  if (k == 1 and not mapping[i][w-1]) or (k == 0 and mapping[i][w-1]):
    side[i] = 1
    key += 1
      
k = 0
key //= 2
for i in range(h-1):
  if mapping[i][j]:
    if k == 0:
      k = 1
      ans.append([i+1, w, i+2, w])
    else:
      k = 0
  else:
    if k == 1:
      ans.append([i+1, w, i+2, w])
      key -= 1
    else:
      continue 
  if not key:
    break

print(len(ans))
for i in range(len(ans)):
  print(*ans[i])

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
mapping = [0]*h
for i in range(h):
  mapping[i] = [int(x)%2 for x in input().split()]

ans = []
side = [0]*h
key = 0
for i in range(h):
  k = 0
  for j in range(w-1):
    if mapping[i][j]:
      if k == 0:
        k = 1
        ans.append([i+1, j+1, i+1, j+2])
      else:
        k = 0
    else:
      if k == 1:
        ans.append([i+1, j+1, i+1, j+2])
      else:
        continue
    if j == w-2 and k == 1:
      side[i] = 1
      key += 1
k = 0
key //= 2
for i in range(h-1):
  if mapping[i][j]:
    if k == 0:
      k = 1
      ans.append([i+1, w, i+2, w])
    else:
      k = 0
  else:
    if k == 1:
      ans.append([i+1, w, i+2, w])
      key -= 1
    else:
      continue 
  if not key:
    break

print(len(ans))
for i in range(len(ans)):
  print(*ans[i])
Problem p03274 (python)

Fixed submission:
n, k = map(int, input().split())
x = list(int(i) for i in input().split())
inf = 10**9
max_x = x[-1]
min_x = x[0]
if min_x >= 0:
    print(x[k-1])
elif max_x <= 0:
    print(abs(x[-k]))
else:
    for i in range(n-1):
        if x[i]<0 and x[i+1]>=0:
            key = i+1
            break
    if n-key>=k:
        ans1 = sum(x[key:key+k])
    else:
        ans1 = inf
    if key>=k:
        ans2 = abs(sum(x[key-k:key]))
    else:
        ans2 = inf
    ans3 = inf
    for i in range(max(0, key-k+1), min(n-k+1, key+k-1)):
        a, b = abs(x[i]), abs(x[i+k-1])
        t = max([a, b])+min([a, b])*2
        if t < ans3:
            ans3 = t
    print(min([ans1, ans2, ans3]))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
x = list(int(i) for i in input().split())
inf = 10**9
max_x = x[-1]
min_x = x[1]
if min_x >= 0:
    print(x[k-1])
elif max_x <= 0:
    print(x[-k])
else:
    for i in range(n-1):
        if x[i]<0 and x[i+1]>=0:
            key = i+1
            break
    if n-key>=k:
        ans1 = sum(x[key:key+k])
    else:
        ans1 = inf
    if key>=k:
        ans2 = abs(sum(x[key-k:key]))
    else:
        ans2 = inf
    ans3 = inf
    for i in range(max(0, key-k+1), min(n-k, key+k-1)):
        a, b = abs(x[i]), abs(x[i+k-1])
        t = max([a, b])+min([a, b])*2
        if t < ans3:
            ans3 = t
    print(min([ans1, ans2, ans3]))
Problem p03283 (python)

Fixed submission:
n, m, q = map(int, input().split())
ans = [[0]*n for _ in range(n)]
for i in range(m):
  l, r = map(int, input().split())
  ans[l-1][r-1] += 1

for i in range(n-1, -1, -1):
  for j in range(i+1, n):
    ans[i][j] += ans[i][j-1]
for i in range(n-1, -1, -1):
  for j in range(i+1, n):
    ans [i][j] += ans[i+1][j]

for _ in range(q):
  p, q = map(int, input().split())
  print(ans[p-1][q-1])

Buggy submission (verdict: Runtime Error):
n, m, x = map(int, input().split())
trainlist = {}
for i in range(m):
    a, b = map(str, input().split())
    k = "".join([a.zfill(2), "-", b.zfill(2)])
    if k in trainlist:
        trainlist[k] = trainlist[k] + 1
    else:
        trainlist[k] = 1
        
for i in range(x):
    s, t = map(int, input().split())
    ans = 0
    for w in trainlist:
        if s <= int(w[0])*10+int(w[1]) and int(w[3])*10+int(w[4]) <= t:
            ans += trainlist[w]
    print(ans)

Buggy submission (verdict: Runtime Error):
n, m, x = map(int, input().split())
trainlist = {}
for i in range(m):
    a, b = map(str, input().split())
    k = "".join([a.zfill(2), "-", b.zfill(2)])
    if k in trainlist:
        trainlist[k] = trainlist[k] + 1
    else:
        trainlist[k] = 1
        
for i in range(x):
    s, t = map(int, input().split())
    ans = 0
    for w in trainlist:
        if s <= int(w[0])*10+int(w[1]) and int(w[3])*10+int(w[4]) <= t:
            ans += trainlist[w]
    print(ans)
Problem p03305 (python)

Fixed submission:
import sys
from heapq import *
input = sys.stdin.readline

def main():
  n, m, s, t = map(int, input().split())
  
  inf = pow(10, 15)
  
  tree = [[] for _ in range(n)]
  for i in range(m):
    u, v, a, b = map(int, input().split())
    tree[u-1].append((v-1, a, b))
    tree[v-1].append((u-1, a, b))
  
  ans_yen = [0]*n
  ans_snuke = [0]*n
  
  for start, ans in zip([s-1, t-1], [ans_yen, ans_snuke]):
    already = [False]*n
    not_yet = [(0, start)]
    
    while len(not_yet) > 0:
      c, p = heappop(not_yet)
      if already[p]:
        continue
      ans[p] = c
      already[p] = True
      
      for (value, a, b) in tree[p]:
        if already[value]:
          continue
        if start == s-1:
          cost = a
        else:
          cost = b
        heappush(not_yet, (c+cost, value))
  
  ans = [0]*n
  sub = inf
  for i in range(n-1, -1, -1):
    sub = min(sub, ans_yen[i]+ans_snuke[i])
    ans[i] = sub
  
  sub = inf
  for a in ans:
    print(sub-a)
      
  
  
  
if __name__ == "__main__":
  main()

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

def main():
  n, m, s, t = map(int, input().split())
  
  tree = [[] for _ in range(n)]
  cost_yen = [[0]*n for _ in range(n)]
  cost_snuke = [[0]*n for _ in range(n)]
  for i in range(m):
    u, v, a, b = map(int, input().split())
    tree[u-1].append(v-1)
    tree[v-1].append(u-1)
    cost_yen[u-1][v-1] = a
    cost_yen[v-1][u-1] = a
    cost_snuke[u-1][v-1] = b
    cost_snuke[v-1][u-1] = b
  
  ans_yen = [0]*n
  ans_snuke = [0]*n
  
  for cost, start, ans in zip([cost_yen, cost_snuke], [s-1, t-1], [ans_yen, ans_snuke]):
    already = [False]*n
    not_yet = [(0, start)]
    
    while len(not_yet) > 0:
      c, p = heappop(not_yet)
      if already[p]:
        continue
      ans[p] = c
      already[p] = True
      
      for value in tree[p]:
        if already[value]:
          continue
        heappush(not_yet, (ans[p]+cost[p][value], value))
  
  ans = [0]*n
  sub = 10**15
  for i in range(n-1, -1, -1):
    sub = min(sub, ans_yen[i]+ans_snuke[i])
    ans[i] = sub
  
  sub = 10**15
  for a in ans:
    print(sub-a)
      
  
  
  
if __name__ == "__main__":
  main()
Problem p03328 (python)

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

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
print((b-a)*(b-a-1)//2-a)
Problem p03337 (python)

Fixed submission:
a, b = map(int, input().split())
print(max([a*b, a-b, a+b]))

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

Fixed submission:
import math
n = int(input())
a = [int(x) for x in input().split()]

bit = int(math.log2(max(a+[1])))+1
key = [0]*bit
ans = 0
ans_bef = 0
for i in range(n):
  value = a[i]
  max_len = ans_bef
  for j in range(bit):
    if value%2 == 1:
      if max_len > key[j]:
        max_len = key[j]
      key[j] = 0
    else:
      key[j] += 1
    value //= 2
  ans_bef = max_len+1
  ans += max_len
      
ans += n
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
a = [int(x) for x in input().split()]

bit = int(math.log2(max(a+[1])))+1
key = [0]*bit
ans = 0
ans_bef = 0
for i in range(n):
  value = a[i]
  max_len = ans_bef
  for j in range(bit):
    if value%2 == 1:
      if max_len > key[j]:
        max_len = key[j]
      key[j] = 0
    else:
      key[j] += 1
    value //= 2
  ans_bef = max_len+1
  ans += max_len
      
ans += n
print(ans)
Problem p03352 (python)

Fixed submission:
from sys import exit
n = int(input())
powlist = set()
k = 2
chance = True
if n == 1:
    print(1)
    exit()
while chance:
    for i in range(1, n):
        key = i**k
        if key <= n:
            powlist.add(key)
        else:
            k += 1
            judge = i
            break
    if judge == 2:
        chance = False
print(max(powlist))

Buggy submission (verdict: Runtime Error):
from sys import exit
n = int(input())
powlist = set()
k = 2
chance = True
while chance:
    for i in range(1, n):
        key = i**k
        if key <= n:
            powlist.add(key)
        else:
            k += 1
            judge = i
            break
    if judge == 2:
        chance = False
print(max(powlist))
Problem p03355 (python)

Fixed submission:
def change(n, word):
    for i in range(len(ans)-1, n, -1):
        ans[i] = ans[i-1]
    ans[n] = word

s = input()
k = int(input())
p = min(len(s), k)
key = s[:p]

for i in range(1, len(s)+1-p):
  if key > s[i:i+k]:
    key = s[i:i+k]

ans = [0]*k
for i in range(k):
  if i < p:
    ans[i] = key[:i+1]
  else:
    ans[i] = "zzzzzz"
for i in range(len(s)-p, len(s)):
    for j in range(i+1, len(s)+1):
        for t in range(k):
            if s[i:j] < ans[t] and s[i:j] not in ans:
                change(t, s[i:j])
print(ans[k-1])

Buggy submission (verdict: Runtime Error):
def change(n, word):
    for i in range(len(ans)-1, n, -1):
        ans[i] = ans[i-1]
    ans[n] = word

s = input()
k = int(input())
p = min(len(s), k)
key = s[:p]

for i in range(1, len(s)+1-p):
  if key > s[i:i+k]:
    key = s[i:i+k]

ans = [0]*k
for i in range(k):
  if i < p:
    ans[i] = key[:i+1]
  else:
    ans[i] = "zzzzzz"
for i in range(len(s)-p, len(s)):
    for j in range(i+1, len(s)+1):
        print(s[i:j])
        for t in range(k):
            if s[i:j] < ans[t] and s[i:j] not in ans:
                change(t, s[i:j])
print(ans[k])
Problem p03370 (python)

Fixed submission:
n, x = map(int, input().split())
m = [0]*n
for i in range(n):
  	m[i] = int(input())
m.sort()
ans = 0
flag = False
while x > 0:
    for i in range(n):
        if x >= m[i]:
            x -= m[i]
            ans += 1
        else:
            flag = True
            break
    if flag:
        break
    key = m[0]
    while x > 0:
        if x >= key:
            x -= key
            ans += 1
        else:
            flag = True
            break
    if flag:
        break
print(ans)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
m = [0]*n
for i in range(n):
  	m[i] = int(input())
m.sort()
ans = 0
flag = False
while x > 0:
    for i in range(n):
        if x >= m[i]:
        	x -= m[i]
            ans += 1
        else:
            flag = True
            break
    if flag:
        break
    key = m[0]
    while x > 0:
        if x >= key:
            x -= key
            ans += 1
        else:
            flag = True
            break
    if flag:
        break
print(ans)
Problem p03379 (python)

Fixed submission:
n = int(input())
x = [int(x) for x in input().split()]
x2 = sorted(x)
ans1, ans2 = x2[n//2-1], x2[n//2]
for i in range(n):
    if x[i] <= ans1:
        print(ans2)
    else:
        print(ans1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = map(int, input().split())
x2 = sorted(x)
ans1, ans2 = x2[n//2-1], x2[n//2]
for i in range(n):
    if x[i] <= ans1:
        print(ans2)
    else:
        print(ans1)