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

Fixed submission:
N = int(input())
line = input()
x = 0
t = 0
for i in range(N):
  if line[i] == 'I':
    t += 1
  elif line[i] == 'D':
    t -= 1
  x = max(t,x)
print(x)

Buggy submission (verdict: Runtime Error):
N = int(input())
line = input()
x = 0
t = 0
for i in range(N):
  if line[i] == 'I':
    t += 1
  else if line[i] == 'D':
    t -= 1
  x = max(t,x)
print(x)
Problem p03963 (python)

Fixed submission:
line = input().split(' ')
print(int(line[1])*((int(line[1])-1)**(int(line[0])-1)))

Buggy submission (verdict: Runtime Error):
ilne = input().split(' ')
print(int(line[0])*((int(line[0])-1)**(int(line[1])-1))
Problem p02573 (python)

Fixed submission:
import collections
import sys

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]

l = []
for _ in range(n):
  l.append([])

# for x in range(n):
#   l[x]

for a, b in ab:
  a -= 1
  b -= 1
  l[a].append(b)
  l[b].append(a)

# c = [None] * n

# for i in range(n):
#   if c[i] is None:
#     c[i] = i
#   for f in l[i]:
#     if c[f] is None:
#       c[f] = i


# https://algo-logic.info/connected-components-num/

color = [None] * n

sys.setrecursionlimit(3*10**5)


def dfs(i, c):
  if color[i] is not None:
    return
  color[i] = c

  for f in l[i]:
    dfs(f, c)


for i in range(n):
  if color[i] is None:
    dfs(i, i)

print(max([v for k, v in collections.Counter(color).items()]))

Buggy submission (verdict: Runtime Error):
import collections

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]

l = []
for _ in range(n):
  l.append([])

# for x in range(n):
#   l[x]

for a, b in ab:
  a -= 1
  b -= 1
  l[a].append(b)
  l[b].append(a)

# c = [None] * n

# for i in range(n):
#   if c[i] is None:
#     c[i] = i
#   for f in l[i]:
#     if c[f] is None:
#       c[f] = i


# https://algo-logic.info/connected-components-num/

color = [None] * n


def dfs(i, c):
  if color[i] is not None:
    return
  color[i] = c

  for f in l[i]:
    dfs(f, c)


for i in range(n):
  if color[i] is None:
    dfs(i, i)

print(max([v for k, v in collections.Counter(color).items()]))

Buggy submission (verdict: Runtime Error):
import collections

n, m = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]

l = []
for _ in range(n):
  l.append([])

# for x in range(n):
#   l[x]

for a, b in ab:
  a -= 1
  b -= 1
  l[a].append(b)
  l[b].append(a)

# c = [None] * n

# for i in range(n):
#   if c[i] is None:
#     c[i] = i
#   for f in l[i]:
#     if c[f] is None:
#       c[f] = i


c = [None] * n

def dfs(i, d):
  if c[i] is not None:
    return
  c[i] = d

  for f in l[i]:
    dfs(f, d)


for i in range(n):
  if c[i] is None:
    dfs(i, i)

print(max([v for k, v in collections.Counter(c).items()]))
Problem p02621 (python)

Fixed submission:
a=int(input())
print(a+a**2+a**3)

Buggy submission (verdict: Runtime Error):
a=int(input())
print(round((a*(a-(-1+math.sqrt(3)*(1j))/2)*(a-(-1-math.sqrt(3)*(1j))/2)).real))
Problem p02641 (python)

Fixed submission:
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))

q = set(range(-1, 100 + 2)) - set(p)

f = []

for e in q:
  f.append((abs(e - x), e - x))

print(x + min(f)[1])

Buggy submission (verdict: Runtime Error):
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))


for i in range(x, 0, -1):
  if not i in p:
    a1 = i
    break

for i in range(x, 100 + 2):
  if not i in p:
    a2 = i
    break

if x - a1 <= a2 - x:
  print(a1)
else:
  print(a2)
Problem p02717 (python)

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

x,y=y,x
x,z=z,x

print(x,y,z)

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

if '7' in str(n):
  print('Yes')
else:
  print('NO')
Problem p02787 (python)

Fixed submission:
import sys
input = sys.stdin.readline
LOCAL = len(sys.argv) > 1 and sys.argv[1] == 'LOCAL'


def dprint(*args):
  if LOCAL:
    print(*args)


h, n = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]

INF = 2 ** 64
dprint(INF)
dp = [INF] * (h + 10 ** 4)
dp[0] = 0

for j in range(h):
  for a, b in ab:
    dp[j + a] = min(dp[j + a], dp[j] + b)

dprint(dp[:10])
print(min(dp[h:]))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
LOCAL = len(sys.argv) > 1 and sys.argv[1] == 'LOCAL'


def dprint(*args):
  if LOCAL:
    print(*args)


h, n = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]

import math
dp = [math.inf] * (h + 10 ** 4)
dp[0] = 0

for j in range(h):
  for a, b in ab:
    dp[j + a] = min(dp[j + a], dp[j] + b)

dprint(dp[:10])
print(min(dp[h:]))
Problem p02805 (python)

Fixed submission:
import sys
input = sys.stdin.readline
LOCAL = len(sys.argv) > 1 and sys.argv[1] == 'LOCAL'


def dprint(*args):
  if LOCAL:
    print(*args)


n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]


import math
import itertools


def distanse(x1, y1, x2, y2):
  return math.sqrt((x1 - x2)**2 + (y1 - y2)**2)


def isValid(ox, oy, r):
  # global ox, oy, r
  global xy
  for x, y in xy:
    if distanse(x, y, ox, oy) - r > 1e-6:
      return False
  return True


rs = []
for (x1, y1), (x2, y2) in itertools.combinations(xy, r=2):
  dprint(x1, y1, x2, y2)
  r = distanse(x1, y1, x2, y2) / 2
  ox = (x1 + x2) / 2
  oy = (y1 + y2) / 2
  dprint(ox, oy, r)
  if isValid(ox, oy, r):
    rs.append(r)
# for c1, c2 in itertools.combinations(xy, r=2):
#   dprint(c1, c2)
#   r = distanse(c1, c2)
#   o=(c1+c2)/2

for (x1, y1), (x2, y2), (x3, y3) in itertools.combinations(xy, r=3):
  # http://www.ambrsoft.com/TrigoCalc/Circle3D.htm
  a = x1 * (y2 - y3) - y1 * (x2 - x3) + x2 * y3 - x3 * y2
  b = (x1**2 + y1**2) * (y3 - y2) + (x2**2 + y2**2) * \
      (y1 - y3) + (x3**2 + y3**2) * (y2 - y1)
  c = (x1**2 + y1**2) * (x2 - x3) + (x2**2 + y2**2) * \
      (x3 - x1) + (x3**2 + y3**2) * (x1 - x2)
  d = (x1 ** 2 + y1 ** 2) * (x3 * y2 - x2 * y3) + (x2 ** 2 + y2 ** 2) * \
      (x1 * y3 - x3 * y1) + (x3 ** 2 + y3 ** 2) * (x2 * y1 - x1 * y2)
  if a == 0:
    continue
  ox = -b / (2 * a)
  oy = -c / (2 * a)
  r = math.sqrt((b ** 2 + c ** 2 - 4 * a * d) / (4 * a ** 2))
  if isValid(ox, oy, r):
    rs.append(r)

dprint(rs)
print('{:.18f}'.format(min(rs)))

Buggy submission (verdict: Runtime Error):
n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]

import math
if n == 2:
  (x1, y1), (x2, y2) = xy
  print(math.sqrt((x2-x1)**2+(y2-y1)**2)/2)

rs=[]
import itertools
for com in itertools.combinations(xy, 3):
  (x1, y1), (x2, y2),(x3,y3)= com
  a=x1*(y2-y3)-y1*(x2-x3)+x2*y3-x3*y2
  b=(x1**2+y1**2)*(y3-y2)+(x2**2+y2**2)*(y1-y3)+(x3**2+y3**2)*(y2-y1)
  c=(x1**2+y1**2)*(x2-x3)+(x2**2+y2**2)*(x3-x1)+(x3**2+y3**2)*(x1-x2)
  d = (x1 ** 2 + y1 ** 2) * (x3 * y2 - x2 * y3) + (x2 ** 2 + y2 ** 2) * (x1 * y3 - x3 * y1) + (x3 ** 2 + y3 ** 2) * (x2 * y1 - x1 * y2)
  if a == 0:
    continue
  x=-b/(2*a)
  y=-c/(2*a)
  r = math.sqrt((b ** 2 + c ** 2 - 4 * a * d) / (4 * a ** 2))
  
  rs.append(r)

print(max(rs))
Problem p02898 (python)

Fixed submission:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

print([x>=k for x in h].count(True))

Buggy submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

print(sum([x>=k for x in h])
Problem p03071 (python)

Fixed submission:
a,b=list(map(int,input().split()))

print(max(a+a-1,b+b-1,a+b))

Buggy submission (verdict: Runtime Error):
#124a
a, b = list(map(int, input().split()))
ans=0
if a > b:
  ans += a
  a -= 1
else:
  ans += b
  b -= 1
ans+=max(a,b)
  
print(ans６)
Problem p03276 (python)

Fixed submission:
import sys
input = sys.stdin.readline
LOCAL = len(sys.argv) > 1 and sys.argv[1] == 'LOCAL'


def dprint(*args):
  if LOCAL:
    print(*args)


n, k = list(map(int, input().split()))
x = list(map(int, input().split()))

k -= x.count(0)

if k <= 0:
  print(0)
  exit()

n = [0]
for e in reversed(x):
  if e < 0:
    n.append(-e)

p = [0]
for e in x:
  if e > 0:
    p.append(e)


dprint(n, p)

anses = []

for i in range(k + 1):
  j = k - i
  if 0 <= i < len(p) and 0 <= j < len(n):
    anses.append(p[i] * 2 + n[j])
    anses.append(p[i] + n[j] * 2)

dprint(anses)

print(min(anses))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
LOCAL = len(sys.argv) > 1 and sys.argv[1] == 'LOCAL'


def dprint(*args):
  if LOCAL:
    print(*args)


n, k = list(map(int, input().split()))
x = list(map(int, input().split()))

k -= x.count(0)

if k <= 0:
  print(0)
  exit()

n = [0]
for e in reversed(x):
  if e < 0:
    n.append(-e)

p = [0]
for e in x:
  if e > 0:
    p.append(e)


dprint(n, p)

anses = []

for i in range(k + 1):
  j = k - i
  if i == 0:
    pass
  elif 0 <= i < len(p) and 0 <= j < len(n):
    anses.append(p[i] * 2 + n[j])
    anses.append(p[i] + n[j] * 2)

dprint(anses)

print(min(anses))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
LOCAL = len(sys.argv) > 1 and sys.argv[1] == 'LOCAL'


def dprint(*args):
  if LOCAL:
    print(*args)


n, k = list(map(int, input().split()))
x = list(map(int, input().split()))

k -= x.count(0)

if k == 0:
  print(0)
  exit()

n = [0]
for e in reversed(x):
  if e < 0:
    n.append(-e)

p = [0]
for e in x:
  if e > 0:
    p.append(e)


dprint(n, p)

anses = []

for i in range(k + 1):
  j = k - i
  if i == 0:
    pass
  elif 0 <= i < len(p) and 0 <= j < len(n):
    anses.append(p[i] * 2 + n[j])
    anses.append(p[i] + n[j] * 2)

dprint(anses)

print(min(anses))
Problem p04020 (python)

Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]

ans = 0
cnt = 0
for x in a:
  if x != 0:
    cnt += x
  else:
    ans += cnt // 2
    cnt = 0

ans += cnt // 2

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]

s=''
for i,x in enumerate(a):
  if x != 0:
    s += str(i+1)*x
  else:
    s += '*'
s += '*'

ans=0
cnt=0
for c in s:
  if c != '*':
    cnt += 1
  else:
    ans += cnt // 2
    cnt=0
  
    
print(ans)
Problem p02727 (python)

Fixed submission:
import heapq
X, Y, a, b, c = map(int, input().split())
p = list(map(lambda x: -int(x), input().split()))
q = list(map(lambda x: -int(x), input().split()))
r = list(map(lambda x: -int(x), input().split()))
p.sort()
q.sort()
t = p[:X] + q[:Y] + r

heapq.heapify(t)

ans = 0
for _ in range(X+Y):
    ap = heapq.heappop(t)
    ans -= ap

print(ans)

Buggy submission (verdict: Runtime Error):
import heapq
X, Y, a, b, c = map(int, input().split())
p = list(map(lambda x: -int(x), input().split()))
q = list(map(lambda x: -int(x), input().split()))
r = list(map(lambda x: -int(x), input().split()))

heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

ans = 0
for _ in range(X):
    ap1 = heapq.heappop(p)
    ap2 = heapq.heappop(r)
    if ap1 <= ap2:
        ans -= ap1
        heapq.heappush(r, ap2)
    else:
        ans -= ap2
        heapq.heappush(p, ap1)

for _ in range(Y):
    ap1 = heapq.heappop(q)
    ap2 = heapq.heappop(r)
    if ap1 <= ap2:
        ans -= ap1
        heapq.heappush(r, ap2)
    else:
        ans -= ap2
        heapq.heappush(q, ap1)

print(ans)
Problem p02775 (python)

Fixed submission:
n = [0] + list(map(int, list(input())))
ans = 0
c_in = 0

while n:
    s = n.pop()
    s += c_in
    if 0 <= s <= 4:
        ans += s
        c_in = 0
    elif 6 <= s:
        ans += abs(10 - s)
        c_in = 1
    else:
        ans += 5
        if 5 <= n[-1]:
            c_in = 1
        else:
            c_in = 0

print(ans)

Buggy submission (verdict: Runtime Error):
n = list(map(int, list(input())))
ans = 0
c_in = 0
q = 0


def carry(x, i, q):
    if x[i] <= 8:
        x[i] += 1
    else:
        x[i] = 0
        if x[i] == x[0]:
            x[i] = 0
            q += 1
        else:
            carry(x, i-1, q)


while len(n) > 0:
    s = n.pop()
    if 0 <= s <= 5:
        ans += s
        if c_in:
            c_in = 0
    elif 6 <= s <= 9:
        ans += 10 - s
        c_in = 1
        carry(n, -1, q)
    print(s, ans)

ans += q
print(ans)
Problem p02780 (python)

Fixed submission:
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
sum_E = np.cumsum(p)
sum_e = np.append([0], sum_E)
ans = -1
for i in range(n-k+1):
    ans = max(ans, sum_e[i+k] - sum_e[i])
print(ans/2)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
sum_e = np.cumsum(p)
ans = 0
for i in range(n-k+1):
    ans = max(ans, sum_e[i+k] - sum_e[i])
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
n, k = map(int, input().split())
p = np.array(list(map(int, input().split())))
p += 1
ans = np.zeros(n-k+1)
for i in range(n-k+1):
    ans += p[i:k+i]
print(max(ans)/2)
Problem p02787 (python)

Fixed submission:
h, n = map(int, input().split())
inf = 10**11

# dp[i]: 体力iを減らす魔力の最小値
dp = [inf] * 20000
dp[0] = 0

for _ in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        dp[j+a] = min(dp[j] + b, dp[j+a])

print(min(dp[h:]))

Buggy submission (verdict: Runtime Error):
h, n = map(int, input().split())
magic = [
    list(map(int, input().split())) for i in range(n)
]
dp = np.full((n+1, h+1), np.inf, dtype=np.int)
dp[1:, 0] = 0
dp[1][1] = magic[0][0]
for i in range(1, n+1):
    for j in range(1, h + 1):
        if i == 1:
            dp[i][j] = magic[i-1][1] * np.ceil(j/magic[i-1][0])
        elif j >= magic[i-1][0]:
            dp[i][j] = min(
                dp[i-1][j], dp[i][j-magic[i-1][0]] + magic[i-1][1],
            )
        else:
            dp[i][j] = dp[i-1][j]
print(dp[n][h])
Problem p02803 (python)

Fixed submission:
import numpy as np
from collections import deque
h, w = map(int, input().split())
r = [list(input()) for i in range(h)]


def dist(s, t):
    if r[s][t] == "#":
        return 0
    else:
        visited = np.zeros((h, w))
        visited[s][t] += 1
        distance = np.zeros((h, w))
        q = deque([[s, t]])
        while len(q) > 0:
            i, j = q.popleft()
            d = distance[i][j] + 1
            if j != w-1:
                if r[i][j+1] == "." and not visited[i][j+1]:
                    q.append([i, j + 1])
                    visited[i][j+1] += 1
                    distance[i][j+1] += d
            if j != 0:
                if r[i][j-1] == "." and not visited[i][j-1]:
                    q.append([i, j - 1])
                    visited[i][j - 1] += 1
                    distance[i][j - 1] += d
            if i != 0:
                if r[i-1][j] == "." and not visited[i-1][j]:
                    q.append([i - 1, j])
                    visited[i-1][j] += 1
                    distance[i-1][j] += d
            if i != h-1:
                if r[i+1][j] == "." and not visited[i+1][j]:
                    q.append([i + 1, j])
                    visited[i+1][j] += 1
                    distance[i+1][j] += d
        return np.max(distance)


ans = 0
for s in range(h):
    for t in range(w):
        ans = max(ans, dist(s, t))

print(int(ans))

Buggy submission (verdict: Runtime Error):
from collections import deque
h, w = map(int, input().split())
mass = [[ord(i) for i in input().split()]for _ in range(h)]
wall = ord("#")
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]


def bfs(s, t):
    if mass[s][t] == wall:
        return 0
    visited = [[0] * w for _ in range(h)]
    depth = [[0] * w for _ in range(h)]
    q1 = deque([s])
    q2 = deque([t])
    while q1:
        x = q1.popleft()
        y = q2.popleft()
        visited[x][y] += 1
        r = depth[x][y] + 1
        for d in range(4):
            nx = x + dx[d]
            ny = y + dy[d]
            if nx < 0 or h - 1 < nx:
                continue
            if ny < 0 or w - 1 < ny:
                continue

            if mass[nx][ny] == wall:
                continue
            if visited[nx][ny]:
                continue

            q1.append(nx)
            q2.append(ny)
            depth[nx][ny] = r

    u = 0
    for row in depth:
        u = max(u, max(row))
    return u


ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, bfs(i, j))
print(int(ans))
Problem p02838 (python)

Fixed submission:
def powmod(x, y, mod):
    if y == 0:
        return 1
    return (((powmod(x, y >> 1, mod) ** 2) % mod) * x ** (y & 1)) % mod


n = int(input())
a = tuple(map(int, input().split()))
mod = 10**9 + 7
cnt = [0] * 60
for i in range(n):
    r = a[i]
    for j in range(60):
        if r & 1:
            cnt[j] += 1
        r >>= 1

ans = 0
for i in range(60):
    ans += powmod(2, i, mod) * cnt[i] * (n-cnt[i])
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
Ans = 0


def xor(x, y):
    X = bin(max(x, y))
    Y = bin(min(x, y))
    w = int(X) ^ int(Y)

    return int(w, 2)


for i in itertools.combinations(a, 2):
    Ans = Ans + xor(i[0], i[1])

print(Ans % mod)

Buggy submission (verdict: Runtime Error):
import itertools
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
Ans = 0


def xor(x, y):
    X = bin(max(x, y))
    Y = bin(min(x, y))
    w = X ^ Y

    return int(w, 2)


for i in itertools.combinations(a, 2):
    Ans = Ans + xor(i[0], i[1])

print(Ans % mod)
Problem p02841 (python)

Fixed submission:
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())

if m1 + 1 == m2 and d2 == 1:
    print(1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
import itertools
n = int(input())
s = tuple(map(int, input()))
a = tuple(set(itertools.combinations(s, 3)))
ans = len(a)
print(ans)
Problem p02844 (python)

Fixed submission:
n = int(input())
s = tuple(map(int, input()))
f = [
    [] for i in range(10)
]
ans = 0

for i in range(n-2):
    if len(f[s[i]]) != 0:
        continue
    else:
        for j in range(i+1, n-1):
            if s[j] in f[s[i]]:
                continue
            else:
                f[s[i]].append(s[j])
                a = tuple(set(s[j+1:]))
                ans += len(a)

print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = tuple(map(int, input()))
f = [
    [] for i in range(n+1)
]
ans = 0

for i in range(n-2):
    if len(f[s[i]]) != 0:
        continue
    else:
        for j in range(i+1, n-1):
            if s[j] in f[s[i]]:
                continue
            else:
                f[s[i]].append(s[j])
                a = tuple(set(s[j+1:]))
                ans += len(a)

print(ans)
Problem p02845 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7

ans = 1
cnt = [0, 0, 0]
for i in a:
    ans *= cnt.count(i)
    for j in range(3):
        if cnt[j] == i:
            cnt[j] += 1
            break
    ans %= mod
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7

ans = 1
cnt = [0, 0, 0]
for i in a:
    ans *= cnt.count(i)
    cnt[cnt.index(i)] += 1
    ans %= mod
print(ans)
Problem p02888 (python)

Fixed submission:
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n-2):
    j = i+1
    k = n-1
    while j < k:
        if l[i]<l[j]+l[k]:
            ans += k-j
            j += 1
        else:
            k -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
ans = 0
for i in range(n):
    j = i+1
    k = n
    while w < k:
        if a[i]<a[j]+a[k]:
            ans += k-j
            j += 1
        else:
            k -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1 n):
        for k in range(j+1,n):
            if l[k]<l[j]+l[i]:
                ans += 1

            
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
#a[b]の答え
at = []
def at_memo(x):
    if x==0:
        return []
    if x in at:
        return at[x]
    atx = [l[x]+l[i] for i in range(x)]  
    at[x] = at[x-1] + atx
    return at[x]

for x in range(1,n):
    for i in range(len(at_memo(x-1))):
        if l[x]-at_memo(x-1)[i]>0:
            ans += 1
        else:
            continue

Buggy submission (verdict: Runtime Error):
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
#a[b]の答え
at = []
def at_memo(x):
    if x==0:
        return []
    if x in at:
        return at[x]
    atx = [l[x]+l[i] for i in range(x)]  
    at[x] = at[x-1] + atx
    return at[x]


for i in range(len(at_memo(x-1))):
    if l[x]-at_memo(x)[i]>0:
         ans += 1
    else:
         continue


print(ans)
Problem p02899 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

ans = [0 for i in range(n)]
for i, name in enumerate(a):
    ans[name-1] = i+1
print(*ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans = [0 for i in range(n)]
for i in reversed(range(1, n+1)):
    ans[a.pop()] = i
    
print(*ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
n = int(input())
a = deque(list(map(int, input().split())))
ans = []
for i in range(1,n+1):
    ans[a.popleft()] = i
    
print(*ans)
Problem p02922 (python)

Fixed submission:
a, b = map(int, input().split())
c = a-1
d = b-1
x = d//c
if d%c != 0:
    print(x+1)
else:
    print(x)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = a-1
d = b-1
x = c//d
if c%d != 0:
    print(x+1)
else:
    print(x)
Problem p02960 (python)

Fixed submission:
s = input()
mod = 10**9 + 7

dp = [[0] * 13 for _ in range(len(s)+1)]
for i in range(10):
    if s[0] == "?":
        dp[1][i] += 1
    else:
        dp[1][int(s[0])] = 1
        break

for i, v in enumerate(s):
    if i == 0:
        continue
    for j in range(13):
        for k in range(10):
            x = (10 * j + k) % 13
            if v != "?":
                if int(v) == k:
                    dp[i + 1][x] += dp[i][j]
                    dp[i + 1][x] %= mod
                else:
                    dp[i + 1][x] += 0
            else:
                dp[i + 1][x] += dp[i][j]
                dp[i + 1][x] %= mod

print(dp[-1][5])

Buggy submission (verdict: Runtime Error):
s = input()
mod = 10**9 + 7

dp = [[0] * 13 for _ in range(len(s)+1)]
for i in range(10):
    if s[0] == "?":
        dp[1][i] += 1
    else:
        dp[1][int(s[0])] = 1
        break

for i, v in enumerate(s):
    if i == 0:
        continue
    for j in range(13):
        if v != "?":
            dp[i + 1][(10 * j + int(v))] += dp[i][j]
            dp[i + 1][(10 * j + int(v))] %= mod
            continue
        for k in range(10):
            x = (10 * j + k) % 13
            dp[i + 1][x] %= mod

print(dp[-1][5])
Problem p02995 (python)

Fixed submission:
def gcd(x, y):
    if x == 0:
        return y
    else:
        return gcd(y % x, x)


def lcm(x, y):
    return x * y // gcd(x, y)


def calc(n, x, y):
    z = lcm(x, y)
    return n // x + n // y - n // z


a, b, c, d = map(int, input().split())
ans = calc(b, c, d) - calc(a-1, c, d)
print(b - a + 1 - ans)

Buggy submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
import math
lcm = c * d / math.gcd(c, d)
#1~a
a_count = (a-1)//c + (a-1)//d - (a-1)//lcm
b_count = b//c + b//d - b//lcm
answer = b_count - a_count
print(b - a + 1 - answer)
Problem p03043 (python)

Fixed submission:
n, k = map(int, input().split())
class Dice:
    def __init__(self,point,count):
        self.point = point
        self.count = count
dice = [Dice(i, 0) for i in range(1,n+1)]
p = []
for i in range(n):
 while 1<= dice[i].point <= k-1:
    dice[i].point *= 2
    dice[i].count += 1

 p.append(0.5 ** dice[i].count)

print(sum(p) / n)

Buggy submission (verdict: Runtime Error):
import numpy as np
from programming_contest.Atcoder2 import *
n, k = map(int, input().split())
dice = np.arange(1, n+1)

m = np.ceil(np.log2(k) - np.log2(dice))
for i in range(n):
    if m[i] <= 0:
        m[i:] = 0
        break
p = (0.5**m)
print(sum(p)/n)