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

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

v = 0
def solve():
    for x in range(N+1):
        if Y // 10000 < x:
            return [-1,-1,-1]
        r = Y - 10000 * x
        for y in range(0, r // 5000 + 1):
            rr = r - 5000 * y
            z = rr // 1000
            if x + y + z == N:
                return [x, y, z]
    return [-1,-1,-1]

print(' '.join(map(str, solve())))

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

v = 0
def solve():
    for x in range(N+1):
        if Y // 10000 < x:
            return [-1,-1,-1]
        r = Y - 10000 * x
        for y in range(0, r // 5000 + 1):
            rr = r - 5000 * y
            z = rr // 1000
            if x + y + z == N:
                return [x, y, z]

print(' '.join(map(str, solve())))
Problem p03493 (python)

Fixed submission:
s = input()
print(s.count('1'))

Buggy submission (verdict: Runtime Error):
n, k = (int(i) for i in input().split())
balls = list(int(i) for i in input().split())
ball_set = set(balls)
freqs = list(balls.count(i) for i in ball_set)
freqs.sort()
print(sum(freqs[k:]))
Problem p02609 (python)

Fixed submission:
arr=[0,1,1,2]
n=4*(10**5)+100
for i in range(4,n):
    b=bin(i)[2:]
    k=b.count('1')
    arr.append(arr[i%k]+1)
    #print(b,arr[i])
n=int(input())
z=input()
l=z.count('1')
l1=l+1
l2=l-1
ans1=0
ans2=0
for i in range(n):
    if(z[i]=='1'):
        u=pow(2,n-1-i,l1)
        ans1=(ans1+u)%l1
        if l2>0:
            ans2=(ans2+pow(2,n-1-i,l2))%l2
for i in range(n):
    if z[i]=='0':
        p=ans1+pow(2,n-1-i,l1)
        p%=l1
        print(1+arr[p])
    else:
        if l2==0:
            print(0)
        else:
            p=ans2-pow(2,n-1-i,l2)
            p%=l2
            print(1+arr[p])

Buggy submission (verdict: Runtime Error):
arr=[0,1,1,2]
n=4*(10**5)+100
for i in range(4,n):
    b=bin(i)[2:]
    k=b.count('1')
    arr.append(arr[i%k]+1)
    #print(b,arr[i])
n=int(input())
z=input()
l=z.count('1')
l1=l+1
l2=l-1
ans1=0
ans2=0
for i in range(n):
    if(z[i]=='1'):
        u=pow(2,n-1-i,l1)
        ans1=(ans1+u)%l1
        if l2!=0:
            ans2=(ans2+pow(2,n-1-i,l2))%l2
for i in range(n):
    if z[i]=='0':
        p=ans1+pow(2,n-1-i,l1)
        p%=l1
        print(1+arr[p])
    else:
        p=ans2-pow(2,n-1-i,l2)
        p%=l2
        print(1+arr[p])

Buggy submission (verdict: Runtime Error):
arr=[0,1,1,2]
n=2*(10**5)+100
for i in range(4,n):
    b=bin(i)[2:]
    k=b.count('1')
    arr.append(arr[i%k]+1)
    #print(b,arr[i])
n=int(input())
z=input()
l=z.count('1')
l1=l+1
l2=l-1
ans1=0
ans2=0
for i in range(n):
    if(z[i]=='1'):
        u=pow(2,n-1-i,l1)
        ans1=(ans1+u)%l1
        if l2!=0:
            ans2=(ans2+pow(2,n-1-i,l2))%l2
for i in range(n):
    if z[i]=='0':
        p=ans1+pow(2,n-1-i,l1)
        p%=l1
        print(1+arr[p])
    else:
        p=ans2+pow(2,n-1-i,l2)
        p%=l2
        print(1+arr[p])

Buggy submission (verdict: Runtime Error):
arr=[0,1,1,2]
n=4*(10**5)+2
for i in range(4,n):
    b=bin(i)[2:]
    k=b.count('1')
    arr.append(arr[i%k]+1)
n=int(input())
z=input()
kk=int(z,2)
d=[1]
for i in range(39):
    d.append(d[-1]*2)
for i in range(n):
    if z[i]=='0':
        print(arr[kk+d[n-1-i]])
    else:
        print(arr[kk-d[n-1-i]])
Problem p02887 (python)

Fixed submission:
n = int(input())
s = input()
idx = 0
idx = 1
ans = 1
if n == 1:
    print(1)
else:
    tmp = s[0]
    while(idx<n):
        if s[idx]==tmp:
            idx += 1
        else:
            tmp = s[idx]
            idx += 1
            ans +=1
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
idx = 0
tmp = s[1]
idx = 1
ans = 1
if n == 1:
    print(1)
else:
    while(idx<n):
        if s[idx]==tmp:
            idx += 1
        else:
            tmp = s[idx]
            idx += 1
            ans +=1
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
idx = 0
tmp = s[1]
idx = 1
ans = 1
while(idx<n):
    if s[idx]==tmp:
        idx += 1
    else:
        tmp = s[idx]
        idx += 1
        ans +=1
print(ans)
Problem p03737 (python)

Fixed submission:
a,b,c=input().split()
print(a[0].upper()+b[0].upper()+c[0].upper())

Buggy submission (verdict: Runtime Error):
a=input()
b=input()

if len(a)>len(b):
    print("GREATER")
elif len(a)<len(b):
    print("LESS")
else:
    for i in range(len(a)):
        if a[i]>b[i]:
            print("GRATER")
            exit()
        elif a[i]<b[i]:
            print("LESS")
            exit()
print("EQUAL")
Problem p03434 (python)

Fixed submission:
n=int(input())
ls = list(map(int,input().split()))
ls.sort()
ls.reverse()
ans=0
t = 1
for i in range(n) :
 ans += t * ls[i]
 t *= -1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
ls = map(int,input().split())
ls.sort()
ls.reverse()
ans=0
t = 1
for i in range(n) :
 ans += t * ls[i]
 t *= -1
print(ans)
Problem p02787 (python)

Fixed submission:
H,N = map(int,input().split())
INF = 10 ** 10
dp = [INF] * (H + 1)
dp[0] = 0

for i in range(N):
  attack,magic = map(int,input().split())
  for j in range(len(dp)):
    if dp[j] == INF:
      continue
    target = j + attack
    if j + attack > H:
      target = H
    if dp[target] > dp[j] + magic:
      dp[target] = dp[j] + magic
      
print(dp[-1])

Buggy submission (verdict: Runtime Error):
import numpy as np

H,N = map(int,input().split())
INF = 10 ** 10
dp = [INF] * (H + 1)
dp[0] = 0

for i in range(N):
  attack,magic = map(int,input().split())
  for j in range(len(dp)):
    if dp[j] == INF:
      continue
    target = j + attack
    if j + attack > H:
      target = H
    if dp[target] > dp[j] + magic:
      dp[target] = dp[j] + magic
      
print(dp[-1])
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5 + 1)
N,M = map(int,input().split())

G = [[] for i in range(N)]
for i in range(M):
  x,y = map(int,input().split())
  G[x - 1].append(y - 1)

dp = [-1] * N # dp[i] = 頂点iから進むことが出来る深さ
def search(v):
  if dp[v] != -1:
    return dp[v]
  max_depth = 0
  for child in G[v]:
    max_depth = max(max_depth, search(child) + 1)
    
  dp[v] = max(dp[v], max_depth)
  return dp[v]

for i in range(N):
  search(i)

print(max(dp))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 * 5 + 1)
N,M = map(int,input().split())

G = [[] for i in range(N)]
for i in range(M):
  x,y = map(int,input().split())
  G[x - 1].append(y - 1)

dp = [-1] * N # dp[i] = 頂点iから進むことが出来る深さ
def search(v):
  if dp[v] != -1:
    return dp[v]
  max_depth = 0
  for child in G[v]:
    max_depth = max(max_depth, search(child) + 1)
    
  dp[v] = max(dp[v], max_depth)
  return dp[v]

for i in range(N):
  search(i)

print(max(dp))

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

G = [[] for i in range(N)]
for i in range(M):
  x,y = map(int,input().split())
  G[x - 1].append(y - 1)

dp = [-1] * N # dp[i] = 頂点iから進むことが出来る深さ
def search(v):
  if dp[v] != -1:
    return dp[v]
  max_depth = 0
  for child in G[v]:
    max_depth = max(max_depth, search(child) + 1)
    
  dp[v] = max(dp[v], max_depth)
  return dp[v]

for i in range(N):
  search(i)

print(max(dp))
Problem p03175 (python)

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

# 末端の頂点は白1通り、黒1通り
# それ以外の頂点は、各子どもの頂点を元に、白:子の全ての場合分けの積、黒:子が全て白の場合分けの積
# で更新していく

N = int(input())
G = [[] for i in range(N)]
MOD = 10 ** 9 + 7

for i in range(N - 1):
  x,y = map(int,input().split())
  G[x - 1].append(y - 1)
  G[y - 1].append(x - 1)
  
dp_black = [-1] * N
dp_white = [-1] * N

# 頂点vの(黒,白)の場合の数を求める
def search(v,parent):
  if dp_black[v] != -1:
    return (dp_black[v],dp_white[v])
  black = 1
  white = 1
  for child in G[v]:
    if child == parent:
      continue
    b,w = search(child, v)
    black *= w
    black %= MOD
    white *= (b + w)
    white %= MOD
  dp_black[v] = black
  dp_white[v] = white
  return (black, white)

print(sum(search(0, -1)) % MOD)

Buggy submission (verdict: Runtime Error):
# 末端の頂点は白1通り、黒1通り
# それ以外の頂点は、各子どもの頂点を元に、白:子の全ての場合分けの積、黒:子が全て白の場合分けの積
# で更新していく

N = int(input())
G = [[] for i in range(N)]
MOD = 10 ** 9 + 7

for i in range(N - 1):
  x,y = map(int,input().split())
  G[x - 1].append(y - 1)
  G[y - 1].append(x - 1)
  
dp_black = [-1] * N
dp_white = [-1] * N

# 頂点vの(黒,白)の場合の数を求める
def search(v,parent):
  if dp_black[v] != -1:
    return (dp_black[v],dp_white[v])
  black = 1
  white = 1
  for child in G[v]:
    if child == parent:
      continue
    b,w = search(child, v)
    black *= w
    black %= MOD
    white *= (b + w)
    white %= MOD
  dp_black[v] = black
  dp_white[v] = white
  return (black, white)

print(sum(search(0, -1)) % MOD)
Problem p03146 (python)

Fixed submission:
s = int(input())
memo = [-1]
memo.append(s)
def a(n):
    if memo[n-1] % 2 == 0:
        pre = memo[n-1]/2
        for i in memo:
            if i == pre:
                return n
        memo.append(pre)
        return a(n+1)
    else:
        pre = 3 * memo[n-1] + 1
        for i in memo:
            if i == pre:
                return n
        memo.append(pre)
        return a(n+1)

print(a(2))

Buggy submission (verdict: Runtime Error):
s = int(input())
memo = [-1]
memo.append(s)
def a(n):
    if memo[n-1] % 2 == 0:
        pre = memo[n-1]/2
        for i in memo:
            if i == pre:
                return n
            else:
                memo.append(pre)
                return a(n+1)
    else:
        pre = 3 * memo[n-1] + 1
        for i in memo:
            if i == pre:
                return n
            else:
                memo.append(pre)
                return a(n+1)

print(a(2))
Problem p03417 (python)

Fixed submission:
n, m = map(int, input().split())
if n == 1:
    if m == 1:
        ans = 1
    else:
        ans = m - 2
elif m == 1:
    ans = n - 2
else:
    ans = (n - 2) * (m - 2)
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
if n == 1:
    print(m - 2)
    return
if m == 1:
    print(n - 2)
    return
print((n - 2) * (m - 2))
Problem p03471 (python)

Fixed submission:
judge = False
N, Y = map(int, input().split())
x = -1
while x <= N and (not judge):
    x += 1
    y = z = 0
   # print('x:' + str(x))
    rest = Y - x * 10000
    if rest <= 0:
        if rest == 0 and x == N:
            judge = True
        break
    while x + y <= N and Y - x * 10000 - y * 5000 >= 0:
        z = (Y - x * 10000 - y * 5000) // 1000
      #  print('y:' + str(y) + 'z:' + str(z))
        if x + y + z == N:
            judge = True
            break
        y += 1
if judge:
    print(str(x) + ' ' + str(y) + ' ' + str(z))
else:
    print('-1 -1 -1')

Buggy submission (verdict: Runtime Error):
judge = False
N, Y = map(int, input().split())
x = 0
while x <= N and (not judge):
    y = 0
    x += 1
    #print('x:' + str(x))
    rest = Y - x * 10000
    if rest <= 0:
        if rest == 0 and x == N:
            judge = True
        break
    while x + y <= N and Y - x * 10000 - y * 5000 >= 0:
        z = (Y - x * 10000 - y * 5000) // 1000
        #print('y:' + str(y) + 'z:' + str(z))
        if x + y + z == N:
            judge = True
            break
        y += 1
if judge:
    print(str(x) + ' ' + str(y) + ' ' + str(z))
else:
    print('-1 -1 -1')
Problem p03545 (python)

Fixed submission:
n = int(input())
a = n // 1000
b = n // 100 - a * 10
c = n // 10 - a * 100 - b * 10
d = n - a * 1000 - b * 100 - c * 10
yet = True
if a+b+c+d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b+c-d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a+b-c+d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b-c-d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b+c+d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b+c-d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b-c+d==7 and yet:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b-c-d==7 and yet:
    print(str(a)+'-'+str(b)+'-'+str(c)+'-'+str(d)+'=7')    
    yet = False

Buggy submission (verdict: Runtime Error):
n = int(input())
a = n // 1000
b = n // 100 - a * 10
c = n // 10 - a * 100 - b * 10
d = n - a * 1000 - b * 100 - c * 10
yet = True
if a+b+c+d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b+c-d==7 and yet:
    print(str(a)+'+'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a+b-c+d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a+b-c-d==7 and yet:
    print(str(a)+'+'+str(b)+'-'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b+c+d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b+c-d==7 and yet:
    print(str(a)+'-'+str(b)+'+'+str(c)+'-'+str(d)+'=7')
    yet = False
if a-b-c+d==7 and yet:
    print(str(a)+'-'+str(b)+'-'+str(c)+'+'+str(d)+'=7')
    yet = False
if a-b-c-d==7 and yet:
    print(str(a)+'
Problem p03555 (python)

Fixed submission:
a = input()
b = input()
if a[0] == b[2] and a[1] == b[1] and a[2] == b[0]:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a = list(map(str, input().split()))
b = list(map(str, input().split()))
if a[0] == b[2] and a[1] == b[1] and a[2] == b[0]:
    print("YES")
else:
    print("NO")
Problem p02706 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
if n < s:
  print(-1)
else:
  print(n - s)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input.split()))
s = sum(a)
if n < s:
  print(-1)
else:
  print(n - a)
Problem p02787 (python)

Fixed submission:
h, n = map(int, input().split())
magic = []
for i in range(n):
    magic.append(list(map(int, input().split())))

# 一次元で可能
dp = [10**10 for _ in range(h+1)]
dp[0] = 0

for damage, cost in magic:
    for j in range(h+1):
        nj = min(j+damage, h)
        dp[nj] = min(dp[nj], dp[j]+cost)

#print(dp)
print(dp[h])

Buggy submission (verdict: Runtime Error):
h, n = map(int, input().split())
magic = []
max_damage = 0
for i in range(n):
    magic.append(list(map(int, input().split())))
    max_damage = max(max_damage, magic[i][0])

# 一次元で可能
dp = [10**10 for _ in range(h+max_damage)]
dp[0] = 0

for damage, cost in magic:
    for j in range(h+max_damage):
        dp[j] = min(dp[j], dp[j-damage]+cost)

#print(dp)
print(min(dp[h:-1]))
Problem p02797 (python)

Fixed submission:
n, k, s = map(int, input().split())
if s == 10**9:
    a = 10**9-1
else:
    a = 10**9
l = [a for _ in range(n)]

if k == n:
    print(' '.join(map(str, [s for _ in range(n)])))
elif k == 0:
    print(' '.join(map(str, l)))
else:
    if s == 1:
        l[0:k] = [s for _ in range(k)]
    elif s % 2 == 0:
        l[0:k+1] = [s//2 for _ in range(k+1)]
    else:
        u, t = (s-1)//2, (s+1)//2
        for i in range(k+1):
            if i % 2 == 0:
                l[i] = u
            else:
                l[i] = t

    print(' '.join(map(str, l)))

Buggy submission (verdict: Runtime Error):
n, k, s = map(int, input().split())
if s == 10**9:
    a = 10**9-1
else:
    a = 10**9
l = [a for _ in range(n)]

if s % 2 == 0:
    l[0:k+1] = [s//2 for _ in range(k+1)]
else:
    s, t = (s-1)//2, (s+1)//2
    for i in range(k+1):
        if i % 2 == 0:
            l[i] = s
        else:
            l[i] = t

print(l)
Problem p02866 (python)

Fixed submission:
import collections

MOD = 998244353
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
    print(0)
    exit()

d.sort()

c = collections.Counter(d)
if c[0] != 1:
    print('0')
else:
    ans = 1
    k = list(c.keys())
    v = list(c.values())
    for i in range(1, len(v)):
        if k[i]-1 != k[i-1]:
            ans *= 0
        ans *= (v[i-1]**v[i]) % MOD
    print(ans % MOD)

Buggy submission (verdict: Runtime Error):
import collections

MOD = 998244353
n = int(input())
d = list(map(int, input().split()))
d.sort()

c = collections.Counter(d)
if c[0] != 1:
    print('0')
else:
    ans = 1
    k = list(c.keys())
    for i in range(1, len(v)):
        print(ans)
        ans *= v[i-1]**v[i]
    print(ans % MOD)
Problem p02928 (python)

Fixed submission:
INF = 1000000007

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans_i = 0
ans_e = 0

for i in range(len(a)):
    for j in range(len(a)):
        if i == j: continue
        #print(a[i], a[j])
        if a[i] > a[j]:
            if i < j:
                ans_i += 1
            else:
                ans_e += 1
x = ans_i * k
ans = ans_i + ans_e
y = ans * ((k * (k-1) ) // 2)
print(int((x + y) % INF))

Buggy submission (verdict: Runtime Error):
INF = 1000000007

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans_i = 0
ans_e = 0

for i in range(len(a)):
    for j in range(len(a)):
        if i == j: continue
        #print(a[i], a[j])
        if a[i] > a[j]:
            if i < j:
                ans_i += 1
            else:
                ans_e += 1
x = ans_i * k
ans = ans_i + ans_e
y = ans * (k * (k-1) )// 2)
print(int((x + y) % INF))
Problem p02936 (python)

Fixed submission:
from collections import deque

n, q = map(int,input().split())
g = [[] for _ in range(n)] # グラフを格納
count = [0 for _ in range(n)]

for _ in range(n-1):
    a, b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1) # どちらが根かわからない

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

que = deque()
que.append(0)

watch = [False] * n
watch[0] = True

while que:
    i = que.popleft()
    watch[i] = True
    for e in g[i]:
        if watch[e] == True: continue
        count[e] += count[i]
        que.append(e)

print(" ".join(map(str, count)))

Buggy submission (verdict: Runtime Error):
import sys

n, q = map(int, sys.stdin.readline().split())
counter = [0 for _ in range(n)]
relation = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, sys.stdin.readline().split())
    relation[a-1].append(b-1)
operate = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

def dfs(start, point):
    visited[start] = True
    for node in relation[start]:
        if visited[node] == False:
            counter[node] += point
            dfs(node, point)

for ope in operate:
    start, point = ope
    start -= 1
    counter[start] += point
    visited = [False for _ in range(n)]
    dfs(start, point)

print(' '.join(map(str, counter)))

Buggy submission (verdict: Runtime Error):
import sys

n, q = map(int, sys.stdin.readline().split())
counter = [0 for _ in range(n)]
relation = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, sys.stdin.readline().split())
    relation[a-1].append(b-1)
operate = [list(map(int, sys.stdin.readline().split())) for _ in range(q)]

def dfs(start, prev, point):
    visited[start] = True
    for node in relation[start]:
        if node == prev: continue
        if visited[node] == False:
            counter[node] += point
            dfs(node, start, point)

for ope in operate:
    start, point = ope
    start -= 1
    counter[start] += point
    visited = [False for _ in range(n)]
    dfs(start, -1, point)

print(' '.join(map(str, counter)))
Problem p02995 (python)

Fixed submission:
import fractions

a,b,c,d = map(int, input().split())

c_min = (a-1) // c
c_max = b // c
c_count = c_max - c_min

d_min = (a-1) // d
d_max = b // d
d_count = d_max - d_min

cd_min = (a-1) // (c * d // fractions.gcd(c, d))
cd_max = b // (c * d // fractions.gcd(c, d))
cd_count = cd_max - cd_min

print(b - (a-1) - c_count - d_count + cd_count)

Buggy submission (verdict: Runtime Error):
import math

a,b,c,d = map(int, input().split())

c_min = (a-1) // c
c_max = b // c
c_count = c_max - c_min

d_min = (a-1) // d
d_max = b // d
d_count = d_max - d_min

cd_min = (a-1) // (c * d // math.gcd(c, d))
cd_max = b // (c * d // math.gcd(c, d))
cd_count = cd_max - cd_min

print(b - (a-1) - c_count - d_count + cd_count)
Problem p03557 (python)

Fixed submission:
import sys
import bisect

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))

a.sort()
b.sort()
c.sort()

b_ans_list = [0 for _ in range(n)]
for i in reversed(range(n)):
    # b[i]における選択可能なcの個数
    if i == n-1:
        b_ans_list[i] = n - bisect.bisect_right(c, b[i])
    else:
        b_ans_list[i] = n - bisect.bisect_right(c, b[i]) + b_ans_list[i+1]

ans = 0
for i in range(n):
    b_index = bisect.bisect_right(b, a[i])
    if b_index < n: ans += b_ans_list[b_index]

print(ans)

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

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
b = list(map(int, sys.stdin.readline().split()))
c = list(map(int, sys.stdin.readline().split()))

a.sort()
b.sort()
c.sort()

b_ans_list = [0 for _ in range(n)]
for i in reversed(range(n)):
    # b[i]における選択可能なcの個数
    if i == n-1:
        b_ans_list[i] = n - bisect.bisect_right(c, b[i])
    else:
        b_ans_list[i] = n - bisect.bisect_right(c, b[i]) + b_ans_list[i+1]

ans = 0
for i in range(n):
    ans += b_ans_list[bisect.bisect_right(b, a[i])]

print(ans)
Problem p03760 (python)

Fixed submission:
from itertools import zip_longest

o = input()
e = input()

for x,y in zip_longest(o, e, fillvalue=""):
  print(x+y,end="")

Buggy submission (verdict: Runtime Error):
o = input()
e = input()

for x,y in zip_longest(o, e, fillvalue=""):
  print(x+y,end="")
Problem p04013 (python)

Fixed submission:
n, a = map(int, input().split())
x = [0] + list(map(int, input().split()))
nx = 2501

# DP: x1からxjまでの間でk枚を選んで合計がsになる組み合わせの数
dp = [ [ [0 for s in range(nx+1)] for k in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 1

for j in range(1, n+1):
    for k in range(n+1):
        for s in range(nx+1):
            if x[j] > s:
                dp[j][k][s] = dp[j-1][k][s]
            elif k >= 1:
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j]]
#print(dp)
ans = 0
for k in range(1, n+1):
    ans += dp[-1][k][a * k]

print(ans)

Buggy submission (verdict: Runtime Error):
n, a = map(int, input().split())
x = [0] + list(map(int, input().split()))
nx = n*max(x)

# DP: x1からxjまでの間でk枚を選んで合計がsになる組み合わせの数
dp = [ [ [0 for s in range(nx+1)] for k in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 1

for j in range(1, n+1):
    for k in range(n+1):
        for s in range(nx+1):
            if x[j] > s:
                dp[j][k][s] = dp[j-1][k][s]
            elif k >= 1:
                dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j]]
#print(dp)
ans = 0
for k in range(1, n+1):
    ans += dp[-1][k][a * k]

print(ans)
Problem p04014 (python)

Fixed submission:
import math

n = int(input())
s = int(input())
ans = -1

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + n%b

#
if n == s: ans = n+1
for i in range(2, int(math.sqrt(n))+1):
    if f(i, n) == s:
        ans = i
        break
if ans == -1:
    for i in range(int(math.sqrt(n)), 0, -1):
        b = int((n-s) / i + 1)
        if b >= 2 and f(b,n) == s:
            ans = b
            break

print(ans)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
s = int(input())
ans = -1

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + n%b

if n == s: ans = n+1
for i in range(2, int(math.sqrt(n))+1):
    if f(i, n) == s:
        ans = i
        break
if ans == -1:
    for i in range(int(math.sqrt(n)), 0, -1):
        b = (n-s) // i + 1
        if f(b,n) == s:
            ans = b
            break

print(ans)