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

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a_max = max(a)
b_max = sorted(a)[-2]
for j in range(n):
  if a[j] == a_max:
    print(b_max)
  else:
    print(a_max)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
a_max = max(a)
b = a
b.remove(max(b))
b_max = max(b)
for j in range(n):
  if a[j] == a_max:
    print(b_max)
  else:
    print(a_max)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
a_copy = a
for j in range(0,n):
  if max(a) = a[j]:
    a_copy.remove(a_copy[j])
    print(max(a_copy))
  else:
    print(max(a))
Problem p02972 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
key = [0]*n
ans = []
for i in range(n-1,-1,-1):
  if sum(key[i::i+1]) % 2 != a[i]:
    ans.append(i+1)
    key[i] = 1
ans.reverse()
print(len(ans))
print(" ".join(list(map(str,ans))))

Buggy submission (verdict: Runtime Error):
n = int(input().split())
a = list(map(int,input().split()))
ans = []
for i in range(n,0,-1):
  if sum(a[::i]) % 2 == 1:
    ans.append(i)
ans.reverse()
print(len(ans))
print(" ".join(ans))
Problem p03037 (python)

Fixed submission:
N,M = map(int,input().split())
L = []
R = []
for i in range(1,M+1):
  L_val,R_val = map(int,input().split())
  L.append(L_val)
  R.append(R_val)
ans = max(min(R) - max(L) + 1,0)
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
L = []
R = []
for i in range(1,M+1):
  x,y = map(int,input().split())
  L.append(L_val)
  R.append(R_val)
ans = max(min(R) - max(L) + 1,0)
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
L = []
R = []
for i in range(M+1):
  L_val,R_val = map(int,input().split())
  L.append(L_val)
  R.append(R_val)
ans = max(min(R) - max(L) + 1,0)
print(ans)
Problem p03043 (python)

Fixed submission:
import math
N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
      X = K / i
      Y = math.log(X,2)
      if Y * 10 % 10 == 0.0:
        Y_int = int(Y)
      else:
        Y_int = int(Y) + 1
      if i < K:
        Z = 1 / N * (0.5 ** Y_int)
        ans += Z
      else:
        ans += 1 / N

print(ans)

Buggy submission (verdict: Runtime Error):
import math
N,K = map(int,input().split())
ans = 0
for i in range(1,N+1):
      X = K / i
      Y = math.log(X,2)
      if int(Y) * 10 % 10 !== 0:
        Y_int = int(Y) + 1
      else:
        Y_int = int(Y)
      if i < K:
        Z = 1 / N * (0.5 ** Y_int)
        ans += Z
      else:
        ans += 1 / N

print(ans)
Problem p03048 (python)

Fixed submission:
R,G,B,N = map(int,input().split())
cnt = 0
for r in range((N // R) + 1):
    for g in range((N - (r * R)) // G + 1):
        V = N - (r * R + g * G)
        if V >= 0 and V % B == 0:
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
R,G,B,N = map(int,input().split())
cnt = 0
for r in range((N // R) + 1):
    for g in range(N // (r * G) + 1):
        V = N - (r * R + g * G)
        if V >= 0 and V % B == 0:
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
R,G,B,N = map(int,input().split())
cnt = 0
for r in range((N // R) + 1):
    for g in range((N // G) + 1):
        V = N - (r * R + g * G)
        if V >= o and V % B == 0:
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
R,G,B,N = map(int,input().split())
cnt = 0
for r in range((N // R) + 1):
    for g in range((N // G) + 1):
        V = N - (r * R + g * G)
        if V >= o and V % B == 0
            cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
R,G,B,N = map(int,input().split())
cnt = 0
for r in range(3001):
    for g in range(3001):
        V = r * R + g * G 
        if N >= V and (N - V) % == 0:
            cnt += 1
        else:
            continue
print(cnt)

Buggy submission (verdict: Runtime Error):
R,G,B,N = (int(i) for i in input().split())
cnt = 0
for r in range(3001):
  for g in range(3001):
    V = r * R + g * G 
    if N >= V and (N - V) % == 0:
        cnt += 1
    else:
        continue
print(cnt)

Buggy submission (verdict: Runtime Error):
R,G,B,N = map(int,input().split())
cnt = 0
for r in range(3001):
  for g in range(3001):
    V = r * R + g * G 
    if N >= V and (N - V) % == 0:
        cnt += 1
    else:
        continue
print(cnt)

Buggy submission (verdict: Runtime Error):
R,G,B,N = map(int,input().split())
cnt = 0
for r in range(3001):
  for g in range(3001):
    V = r * R + g * G 
    if N >= V and (N - V) % == 0
        cnt += 1
    else:
        continue
print(cnt)

Buggy submission (verdict: Runtime Error):
R,G,B,N = map(int,input().split())
cnt = 0
for r in range(3001):
  for g in range(3001):
    V = r * R + g * G 
    if N > V and (N - V) % == 0
        cnt += 1
    else:
        continue
print(cnt)

Buggy submission (verdict: Runtime Error):
R,G,B,M = map(int,input().split())
cnt = 0
for r in range(3001):
  for g in range(3001):
    V = r * R + g * G 
    if N > V and (N - V) % == 0
        cnt += 1
    else:
        continue
print(cnt)

Buggy submission (verdict: Runtime Error):
R,G,B,M = map(int,input().split())
cnt = 0
for r in range(3001):
  for g in range(r):
    for b in range(g):
      if N = r * R + g * G +b * B:
        cnt += 1
      else:
        continue
print(cnt)
Problem p03060 (python)

Fixed submission:
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
  if v[i] > c[i]:
    ans += (v[i]-c[i])
  else:
    continue
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = 0
for i in range(n):
  if v[i] > c[i]:
    ans + = (v[i]-c[i])
  else:
    continue
print(ans)

Buggy submission (verdict: Runtime Error):
N = input()
V = list(map(int,input(),split()))
C = list(map(int,input(),split()))
for i in range(N+1):
  val= []
  a = V[i] - C[i]
  val.append(a)
val_int = [b for b in val if b > 0]
print(sum(val_int))

Buggy submission (verdict: Runtime Error):
N = input()
V = list(map(int,input(),split()))
C = list(map(int,input(),split()))
for i in range(N+1):
  val= []
  a = V[i] - C[i]
  val.append(a)
val_int = [b for b in val if b > 0]
print(sum(val_int))
Problem p03061 (python)

Fixed submission:
import fractions
n = int(input())
a = list(map(int,input().split()))
m = []
l = [0]
r = [0]
for i in range(n):
  l.append(fractions.gcd(l[i],a[i]))
  r.append(fractions.gcd(r[i],a[-i-1]))
r.reverse()
for i in range(n):
  m.append(fractions.gcd(l[i],r[i+1]))
print(max(m))

Buggy submission (verdict: Runtime Error):
import fractions
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
a.sort()
gcd_list = []
ans = 0
for i in range(1,n):
  gcd_list.append(fractions.gcd(a[0],a[i]))
gcd_list.sort()
gcd_list.remove(gcd_list[0])
for j in range(1,n-2):
  ans = max(ans,fractions.gcd(gcd_list[0],gcd_list[i]))
print(ans)
Problem p03071 (python)

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

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

Fixed submission:
n = int(input())
b = list(map(int,input().split()))
ans = []
flag = 0
if b[0] != 1:
  flag = 1
i = n
key = 0
if flag == 0:
  while(i != 1):
    key = 0
    for j in range(0,i):
      if b[j] == j+1:
        key = j+1
      elif j == i-1 and key == 0:
        flag = 1
        break
    ans.append(key)
    b.pop(key-1)
    i -= 1
ans.reverse()
if b[0] != 1:
  flag = 1
ans.insert(0,b[0])
if flag == 0:
  for k in range(n):
    print(ans[k])
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
n = int(input())
b = list(map(int,input().split()))
ans = []
flag = 0
if b[0] != 1:
  flag = 1
i = n
key = 0
if flag == 0:
  while(i != 1):
    for j in range(0,i):
      if b[j] == j+1:
        key = j+1
      elif j == i and key == 0:
        flag = 1
        break
    ans.append(key)
    b.pop(key-1)
    i -= 1
ans.reverse()
ans.insert(0,b[0])
if flag == 0:
  for k in range(n):
    print(ans[k])
else:
  print(-1)
Problem p03161 (python)

Fixed submission:
def solve():
  n,k = map(int,input().split())
  h = list(map(int,input().split()))
  dp = [float("inf")]*n
  dp[0] = 0
  for i in range(0,n-1):
    for j in range(1,k+1):
      if (i-j)>=-1:
        dp[i+1]=min(dp[i+1],dp[i+1-j]+abs(h[i+1]-h[i+1-j]))
  print(dp[-1])
solve()

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0
def chmin(a,b):
  if a>b:
    a = b
    return true
  else:
    return false
for i in range(0,n):
  for j in range(1,k+1):
    chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0
def chmin(a,b):
  if a>b:
    a = b
    return true
  else:
    return false
for i in range(0,n):
  for j in range(1,k):
    chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0
def chmin(a,b):
  if a>b:
    a = b
    return true
  else:
    return false
for i in range(1,n):
  for j in range(0,k):
    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0
def chmin(a,b):
  if a>b:
    a = b
    return true
  else:
    return false
for i in range(1,n):
  for j in range(1,k):
    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-j]))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0
def chmin(a,b):
  if a>b:
    a = b
    return true
  else:
    return false
for i in range(n):
  for j in range(k):
    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-j]))
print(dp[-1])
Problem p03164 (python)

Fixed submission:
n,w = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(n)]
#dp[i][j]はi番目まででj(価値の合計)になる重さの最小値
sum_value = 0
for i in range(n):
  sum_value += wv[i][1]
dp = [[float("inf")]*(sum_value+1) for j in range(n)]
for k in range(sum_value+1):
  if k == wv[0][1]:
    dp[0][k] = wv[0][0]
for a in range(n-1):
  for b in range(sum_value+1):
    if dp[a][b-wv[a+1][1]] != float("inf"):
      dp[a+1][b] = min(dp[a][b-wv[a+1][1]]+wv[a+1][0],dp[a][b])
    elif b == wv[a+1][1]:
      dp[a+1][b] = min(wv[a+1][0],dp[a][b])
    else:
      dp[a+1][b] = dp[a][b]
ans = 0
for c in range(sum_value+1):
  if dp[-1][c] != float("inf") and w >= dp[-1][c]:
    ans = c
print(ans)

Buggy submission (verdict: Runtime Error):
n,w = map(int,input().split())
wv = [list(map(int,input().split())) for _ in range(n)]
#dp[i][j]はi番目まででj(j<=w)になるもの
dp = [[0]*(w+1) for i in range(n)]
for k in range(w+1):
  if k >= wv[0][0]:
    dp[0][k] = wv[0][1]
  else:
    continue
for i in range(n-1):
  for j in range(w+1):
    if j >= wv[i+1][0]:
      dp[i+1][j] = max(dp[i][j-wv[i+1][0]]+wv[i+1][1],dp[i][j])
    else:
      dp[i+1][j] = dp[i][j]
print(dp[n-1][w])
Problem p03380 (python)

Fixed submission:
n = int(input())
a = sorted(list(map(int,input().split())))
ans_bigger = max(a)
ans_half = ans_bigger / 2
dif = float("inf")
for i in range(n-1):
  x = abs(a[i]-ans_half)
  if dif > x:
    dif = x
    ans_smaller = a[i]
print(ans_bigger,ans_smaller)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
ans_bigger = max(a)
ans_half = a / 2
dif = float("inf")
for i in range(n):
  x = abs(a[i]-ans_half)
  if dif > x:
    dif = x
    ans_smaller = a[i]
print(ans_bigger,ans_smaller)
Problem p03469 (python)

Fixed submission:
s = input()
s_list = list(s)
s_list[3] = "8"
print("".join(s_list))

Buggy submission (verdict: Runtime Error):
s = input()
s_list = list(s)
s_list[3] = "8"
print("",join(s_list))
Problem p03472 (python)

Fixed submission:
N,H = map(int,input().split());
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N):
        if ab[i][1] >= swing:
          H -= ab[i][1]
          ans += 1 
        else:
            continue
        if H <= 0:
            break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)

Buggy submission (verdict: Runtime Error):
from operator import itemgetter
n,h = map(int,input().split())
ab = []
ans = 0
a = 0
for i in range(n):
  ab.append(list(map(int,input.split())))
ab.sort()
swing = ab.pop(-1)
ab = sorted(a,key = itemgetter(1))
ab.reverse
for i in range(len(ab)):
  h -= ab[i][1]
  ans += 1
  if h <= 0:
    print(ans)
    a += 1
    break
if a == 0:
  if h%swing[1] == 0:
    h -= swing[1]
    ans += h // swing[1]
    print(ans+1)
  else:
    h -= swing[1]
    ans += h // swing[1]
    print(ans+2)
Problem p03545 (python)

Fixed submission:
s = input()
def dfs(i,f,sum):
  if i == 3:
    if sum == 7:
      print(f + "=7")
      exit()
  else:
    dfs(i+1,f + "+" + s[i+1],sum+int(s[i+1]))
    dfs(i+1,f + "-" + s[i+1],sum-int(s[i+1]))
dfs(0,s[0],int(s[0]))

Buggy submission (verdict: Runtime Error):
s = input()
def dfs(i,f,sum):
  if i == 3:
    if sum == 7:
      print(f + "=7")
      exit()
  dfs(i+1,f + "+" + s[i+1],sum+int(s[i+1]))
  dfs(i+1,f + "-" + s[i+1],sum-int(s[i+1]))
dfs(0,s[0],int(s[0]))
Problem p03565 (python)

Fixed submission:
import copy
s = list(input())
t = list(input())
ans_list = []
n = len(s)
m = len(t)
for i in range(n-m+1):
  s_copy = copy.copy(s)
  judgement = True
  for j in range(m):
    if s_copy[i+j] != "?" and s_copy[i+j] != t[j]:
      judgement = False
      break
    else:
      s_copy[i+j] = t[j]
  if judgement:
    ans_list.append(s_copy)
x = len(ans_list)
if ans_list != []:
  for l in range(x):
    for k in range(n):
      if ans_list[l][k] == "?":
        ans_list[l][k] = "a"
  ans_list.sort()
  print("".join(ans_list[0]))
else:
  print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s = list(input())
t = list(input())
s_copy = s
ans_list = []
n = len(s)
m = len(t)
flag = 0
flag_2 = 0
for i in range(n):
  if s[i] == "?" or s[i] == t[flag]:
    if flag == m-1:
      flag_2 = 1
      for j in range(flag,-1,-1):
        s[i-(m-1-j)] = t[j]
      ans_list.append(s)
      s = s_copy
    else:
      flag += 1
  else:
    flag = 0
x = len(ans_list)
if flag_2 == 1:
  for l in range(x):
    for k in range(n):
      if s[l][k] == "?":
        s[l][k] = "a"
  ans_list.sort()
  print("".join(ans_list[0]))
else:
  print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s = list(input())
t = list(input())
n = len(s)
m = len(t)
flag = 0
flag_2 = 0
for i in range(n):
  if s[i] == "?" or s[i] == t[flag]:
    if flag == m-1:
      flag_2 = 1
      for j in range(flag,-1,-1):
        s[i-(m-1-j)] = t[j]
      break
    else:
      flag += 1
  else:
    flag = 0
if n<m:
  flag_2 = 0
if flag_2 == 1:
  for k in range(n):
    if s[k] == "?":
      s[k] = "a"
  print("".join(s))
else:
Problem p03625 (python)

Fixed submission:
n = int(input())
a = sorted(list(map(int,input().split())),reverse = True)
use = []
flag = -1
for i in range(n):
  if flag == a[i]:
    use.append(a[i])
    flag = -1
  else:
    flag = a[i]
if len(use)<2:
  print(0)
else:
  use.sort(reverse =True)
  print(use[0]*use[1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = sorted(list(map(int,input().split())),reverse = True)
use = []
flag = -1
for i in range(n):
  if flag == a[i]:
    use.append(a[i])
    flag = -1
  else:
    flag = a[i]
if len(use)<2:
  print(0)
else:
  use.sort(reverese =True)
  print(use[0]*use*[2])
Problem p03645 (python)

Fixed submission:
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for _ in range(m)])
relaypoint = []
for i in range(m):
  if ab[i][0] == 1:
    relaypoint.append(ab[i][1])
  else:
    break
ab.sort(key = lambda ab:ab[1],reverse = True)
relaypoint = set(relaypoint)
x = len(relaypoint)
j = 0
flag = 0
while(ab[j][1] == n):
  if ab[j][0] in relaypoint:
    flag = 1
  j += 1
if flag == 1:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for _ in range(m)])
relaypoint = []
i = 0
while(ab[i][0] == 1):
  relaypoint.append(ab[i][1])
  i += 1
ab.sort(key = lambda ab:ab[1],reverse = True)
relaypoint = set(relaypoint)
x = len(relaypoint)
j = 0
flag = 0
while(ab[j][1] == n):
  if ab[j][0] in relaypoint:
    flag = 1
  j += 1
if flag == 1:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for _ in range(m)])
relaypoint = []
i = 0
while(ab[i][0] == 1):
  relaypoint.append(ab[i][1])
  i += 1
ab.sort(key = lambda ab:ab[1],reverse = True)
relaypoint = list(set(relaypoint))
x = len(relaypoint)
j = 0
flag = 0
while(ab[j][1] == n):
  if ab[j][0] in relaypoint:
    flag = 1
  j += 1
if flag == 1:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
ab = sorted([list(map(int,input().split())) for _ in range(m)])
relaypoint = []
i = 0
while(ab[i][0] == 1):
  relaypoint.append(ab[i][1])
  i += 1
ab.sort(key = lambda ab:ab[1] reverse = True)
relaypoint = list(set(relaypoint))
x = len(relaypoint)
j = 0
flag = 0
while(ab[j][1] == 5):
  if ab[j][0] in relaypoint:
    flag = 1
if flag == 1:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
ab=[list(map(int,input().split()))]
ab.sort()
medium = []
flag = 0
for i in range(m):
  if ab[i][0] == 1:
    medium.append(ab[i][1])
for j in range(m):
  if ab[j][0] in medium and ab[j][1] == n:
    flag = 1
if flag == 1:
  print("POSSIBLE")
else：
  print("IMPOSSIBLE")
Problem p03651 (python)

Fixed submission:
import fractions
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
a_max = max(a)
a_gcd = a[0]
for i in range(n):
  a_gcd = fractions.gcd(a_gcd,a[i])
if k <= a_max and k % a_gcd == 0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import functions
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
a_max = max(a)
a_gcd = a[0]
for i in range(n):
  a_gcd = functions.gcd(a_gcd,a[i])
if k <= a_max and k % a_gcd == 0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")
Problem p03739 (python)

Fixed submission:
def sign(x):
  if x<0:
    return -1
  elif x>0:
    return 1
  else:
    return 0
n = int(input())
a = list(map(int,input().split()))
a_sum_pn = 0
a_sum_np = 0
ans_pn = 0
ans_np = 0
flag = 1
for i in range(n):
  a_sum_pn += a[i]
  a_sum_np += a[i]
  if sign(a_sum_pn) != flag:
    ans_pn += abs(flag-a_sum_pn)
    a_sum_pn = flag
  if sign(a_sum_np) != -flag:
    ans_np += abs(-flag-a_sum_np)
    a_sum_np = -flag
  flag *= -1
print(min(ans_pn,ans_np))

Buggy submission (verdict: Runtime Error):
def sign(x):
  if x<0:
    return -1
  elif x>0:
    return 1
  else:
    retrun 0
n = int(input())
a = list(map(int,input().split()))
cumulative_sum = a[0]
flag = sign(cumulative_sum)
ans = 0
for i in range(1,n):
  cumulative_sum += a[i]
  if sign(cumulative_sum) == flag or sign(cumulative_sum) == 0:
    ans += abs(-flag - cumulative_sum)
  flag = sign(cumulative_sum)
print(ans)
Problem p03786 (python)

Fixed submission:
n=int(input())
a=sorted(list(map(int,input().split())))
flag=0
ans=1
a_cumulative=[0]
for i in range(n):
  flag+=a[i]
  a_cumulative.append(flag)
a.reverse()
a_cumulative.reverse()
for j in range(n-1):
  if a[j] <= a_cumulative[j+1]*2:
    ans+=1
  else:
    break
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=sorted(list(map(int,input().split())))
flag=0
ans=1
a_cumulative=[0]
for i in range(n):
  flag+=a[i]
  a_cumulative.append(flag)
a.reverse()
a_cumulative.reverse()
for j in range(n-1):
  if a[j]＜= a_cumulative[j+1]*2:
    ans+=1
print(ans)
Problem p03965 (python)

Fixed submission:
s = list(input())
n = len(s)
ans = 0
flag = 0
for i in range(n):
  if s[i] == "g" and flag == 0:
    flag+=1
  elif s[i] == "g" and flag != 0:
    flag -= 1
    ans += 1
  elif s[i] == "p" and flag == 0:
    flag += 1
    ans -= 1
  else:
    flag -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = list(input())
n = len(s)
ans = 0
for i in range(n):
  if s[i] == "g" and flag == 0:
    flag+=1
  elif s[i] == "g" and flag != 0:
    flag -= 1
    ans += 1
  elif s[i] == "p" and flag == 0:
    flag += 1
    ans -= 1
  else:
    flag -= 1
print(ans)
Problem p03999 (python)

Fixed submission:
s = list(input())
n = len(s)-1
def dfs(x,y):
  ans = 0
  if x == n:
    return sum(list(map(int,"".join(y).split("+"))))
  else:
    return dfs(x+1,y+"+"+s[x+1])+dfs(x+1,y+s[x+1])
print(dfs(0,s[0]))

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s)
def dfs(i,f):
  if i == n:
    return sum(list(map(int,f.split("+"))))
  return dfs(i + 1, f + s[i + 1]) + \
           dfs(i + 1, f + "+" + s[i + 1])
print(dfs(0,0))
Problem p04013 (python)

Fixed submission:
n,a = map(int,input().split())
x = list(map(int,input().split()))
max_x = max(x)
dp = [[[0]*(n*max_x+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 1
for i in range(n+1):
  for j in range(n+1):
    for k in range(n*max_x+1):
      if i>=1 and k < x[i-1]:
        dp[i][j][k] = dp[i-1][j][k]
      elif i>=1 and j>= 1 and k>= x[i-1]:
        dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]]
      else:
        continue
ans = 0
for j in range(1,n+1):
  if j*a <= n*max_x+1:
    ans += dp[n][j][j*a]
print(ans)

Buggy submission (verdict: Runtime Error):
n,a = map(int,input().split())
x = list(map(int,input().split()))
max_x = max(x)
dp = [[[0]*(n*max_x+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 1
for i in range(n+1):
  for j in range(n+1):
    for k in range(n*max_x+1):
      if i>=1 and k < x[i-1]:
        dp[i][j][k] = dp[i-1][j][k]
      elif i>=1 and j>= 1 and k>= x[i-1]:
        dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i-1]]
      else:
        continue
ans = 0
for j in range(1,n+1):
  ans += dp[n][j][j*a]
print(ans)
Problem p04030 (python)

Fixed submission:
from collections import deque
s = list(str(input()))
ans = deque()
for i in s:
  if i == "B":
    if ans == deque([]):
      continue
    else:
      ans.pop()
  else:
    ans.append(i)
print("".join(ans))

Buggy submission (verdict: Runtime Error):
from collections import deque
s = list(str(input()))
ans = deque()
for i in s:
  if i == "B":
    if ans == []:
      continue
    else:
      ans.pop()
  else:
    ans.append(i)
print("".join(ans))

Buggy submission (verdict: Runtime Error):
s = list(input())
n = len(s)
ans = []
for i in range(n):
  if i == "B":
    if ans == []:
      continue
    else:
      ans.remove(ans[-1])
  else:
    ans.appned(i)
print("".join(ans))

Buggy submission (verdict: Runtime Error):
s = list(map(str,input().split()))
n = len(s)
ans = []
for i in range(n):
  if i == "B":
    if ans == []:
      continue
    else:
      ans.remove(ans[-1])
  else:
    ans.appned(i)
print("".join(ans))
Problem p04032 (python)

Fixed submission:
s = list(input())
n = len(s)
ans_1 = -1
ans_2 = -1
if n == 2:
  if s[0] == s[1]:
    ans_1 = 1
    ans_2 = 2
else:
  for i in range(n-2):
    if s[i] == s[i+1]:
      ans_1 = i+1
      ans_2 = i+2
      break
    elif s[i] == s[i+2]:
      ans_1 = i+1
      ans_2 = i+3
      break
print(ans_1,ans_2)

Buggy submission (verdict: Runtime Error):
from collections import Counter
s = input()
s_con = Counter(s)
mode = s_con.most_common(1)
s_com = mode[0][1]
s_con_str = mode[0][0]
s_rev = s.reverse()
if s_com >= (len(s) / 2):
  print("-1 -1")
else:
  ans_1 = s.find(s_con_str)
  ans_2 = s_rev.find(s_con_str)
  print(str(ans_1) + " " +str(ans_2))