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

Fixed submission:
N=int(input())
P=[int(i) for i in input().split()]
mes=0
for i in range(len(P)):

	if i!=0 and i!=N-1:
		if (P[i+1]<P[i] and P[i+1]<=P[i-1] and P[i]<=P[i-1])or(P[i-1]<P[i] and P[i-1]<=P[i+1] and P[i]<=P[i+1]):
			mes+=1
print(mes)

Buggy submission (verdict: Runtime Error):
N=input()
P=[int(i) for i in input().split()]
mes=[]

for i in range(len(P)):

	if i!=1 and i!=N-1:
		if (P[i+1]<P[i] and P[i+1]<=P[i-1]) or (P[i+1]<P[i] and P[i+1]<=P[i-1]):
			mes+=mes+P[i]

for n in mes:
	print(mes[n])

Buggy submission (verdict: Runtime Error):
N=input()
P=[int(i) for i in input().split()]
mes=[]

for i in range(len(P)):

	if i!=1 and i!=N-1:
		if (P[i+1]<P[i] and P[i+1]<=P[i-1]) or (P[i+1]<P[i] and P[i+1]<=P[i-1]):
			mes+=mes+P[i]

for n in mes:
	print(mes)
Problem p03048 (python)

Fixed submission:
[A,B,C,N]=[int(i) for i in input().split()]
X=[A,B,C]
X.sort()
[C,B,A]=X
cnt=0
for i in range(N//A+1):
  k=N-(i*A)
  for j in range(k//B+1):
    if (k-(B*j))%C==0:
    	cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
[A,B,C,N]=[int(i) for i in input().split()]
[C,B,A]=[A,B,C].sort()
cnt=0
for i in range(N//A):
  k=N-(i*A)
  for j in range(k//B):
    if (k-(B*A))%C==0:cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
[A,B,C,N]=[int(i) for i in input().split()]
[C,B,A]=[A,B,C].sort()
cnt=0
for i in range(N//A):
  k=N-(i*A)
  for j in range(k//B):
    if (k-(B*A))%C=0:cnt+=1
print(cnt)
Problem p02582 (python)

Fixed submission:
s=input()
count=0
max=0
for i in range(len(s)):
  if s[i]=='R':
    count+=1
    max=count
  elif s[i]=='S':
    count=0
      
print(max)

Buggy submission (verdict: Runtime Error):
s=input()
count=0
for i in range(len(s)):
  if s[i]=='R':
    count+=1
    max1=count
  elif s[i]=='S':
    count=0
print(max1)
Problem p02646 (python)

Fixed submission:
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a == b:
    print('YES')
elif v <= w:
    print('NO')
else:
    if t < abs(a - b) / (v - w):
        print('NO')
    else:
        print('YES')

Buggy submission (verdict: Runtime Error):
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a == b:
    print('YES')
elif v < w:
    print('NO')
else:
    if t < abs(a - b) / (v - w):
        print(abs(a - b) / (v - w))
        print('NO')
    else:
        print('YES')
Problem p02665 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a_min = [0] * (n + 1)
a_min[n] = a[n]
for i in range(n - 1, -1, -1):
    a_min[i] = a[i] + a_min[i + 1]

b = [1]
for i in range(n):
    tmp = b[i] - a[i]
    b.append(min(tmp * 2, a_min[i + 1]))
    if tmp < 1 or tmp * 2 < a[i + 1]:
        print(-1)
        break
else:
    if n == 0:
        ans = 1 if a[0] == 1 else -1
        print(ans)
    else:
        print(sum(b))

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

b = [1]
for i in range(n):
    tmp = b[i] - a[i]
    if tmp < 1 or tmp * 2 < a[i + 1]:
        print(-1)
        break
else:
    if n == 0:
        ans = 1 if a[0] == 1 else -1
        print(ans)
    else:
        print(sum(b))
Problem p02706 (python)

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

Buggy submission (verdict: Runtime Error):
import math
r = int(input())
print(2 * r * math.pi)
Problem p02709 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2000 * 2)
n = int(input())
a = list(map(int, input().split()))
a = [(i, v) for i, v in enumerate(a)]
a.sort(key=lambda x: x[1], reverse=True)

dp = [[-1] * (m + 1) for m in range(n + 1)]
# m: 何人選んだか, l: 左を選んだ人数
def f(m, l):
    if m == n: return 0
    if dp[m][l] != -1: return dp[m][l]
    r = n - m + l - 1
    i, v = a[m]
    if i >= l: dp[m + 1][l + 1] = f(m + 1, l + 1)
    if i <= r: dp[m + 1][l] = f(m + 1, l)
    return max(dp[m + 1][l + 1] + v * (i - l), dp[m + 1][l] + v * (r - i))
print(f(0, 0))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2 ** 2000)
n = int(input())
a = list(map(int, input().split()))
a = [(i, v) for i, v in enumerate(a)]
a.sort(key=lambda x: x[1], reverse=True)

dp = [[-1] * (m + 1) for m in range(n + 1)]
# m: 何人選んだか, l: 左を選んだ人数
def f(m, l):
    if m == n: return 0
    if dp[m][l] != -1: return dp[m][l]
    r = n - m + l - 1
    i, v = a[m]
    if i >= l: dp[m + 1][l + 1] = f(m + 1, l + 1)
    if i <= r: dp[m + 1][l] = f(m + 1, l)
    return max(dp[m + 1][l + 1] + v * (i - l), dp[m + 1][l] + v * (r - i))
print(f(0, 0))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a = [(i, v) for i, v in enumerate(a)]
a.sort(key=lambda x: x[1], reverse=True)

dp = [[-1] * (m + 1) for m in range(n + 1)]
# m: 何人選んだか, l: 左を選んだ人数
def f(m, l):
    if m == n: return 0
    if dp[m][l] != -1: return dp[m][l]
    r = n - m + l - 1
    i, v = a[m]
    if i >= l: dp[m + 1][l + 1] = f(m + 1, l + 1)
    if i <= r: dp[m + 1][l] = f(m + 1, l)
    return max(dp[m + 1][l + 1] + v * (i - l), dp[m + 1][l] + v * (r - i))
print(f(0, 0))

Buggy submission (verdict: Runtime Error):
import itertools

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

def make_key(select):
    key = ''
    for i in select:
        key += str(i)
    return key

dp = {}
def f(select):
    try:
        key = make_key(select)
        return dp[key]
    except KeyError:
        if len(select) == 1:
            return 0
        if len(select) == 2:
            i, j = select
            return abs(i - j) * (a[i] + a[j])
        happy = 0
        for i, j in itertools.combinations(select, 2):
            tmp = abs(i - j) * (a[i] + a[j]) + f(select - {i, j})
            happy = max(tmp, happy)
        key = make_key(select)
        dp[key] = happy
        return happy

select = set([i for i in range(n)])
print(f(select))
Problem p02727 (python)

Fixed submission:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

a = []
a.extend(p[:x])
a.extend(q[:y])
a.extend(r)
a.sort(reverse=True)

print(sum(a[:x + y]))

Buggy submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

ans = sum(p[:x]) + sum(q[:y])

i, j = 0, 0
while i < x and j < y and i + j < c:
    change = min(p[x - 1 - i], q[y - 1 - j])
    if r[i + j] > change:
        ans += r[i + j] - change
    elif:
        break
    if p[x - 1 - i] < q[y - 1 - j]:
        i += 1
    elif p[x - 1 - i] > q[y - 1 - j]:
        j += 1
    else:
        s, t = 0, 0
        while i + s < x and j + t < y and i + j + s + t < c:
            if p[x - 1 - i - s] < q[y - 1 - j - s]:
                i += 1
                break
            elif p[x - 1 - i - s] > q[y - 1 - j - s]:
                j += 1
                break
            else:
                s += 1
                t += 1
                if not(i + s < x and j + t < y and i + j + s + t < c):
                    i += 1
                    break

print(ans)
Problem p02732 (python)

Fixed submission:
from collections import Counter

n = int(input())
a_li = list(map(int, input().split()))

ans_sum = 0

counter = Counter(a_li)

for i in counter.values():
    ans_sum += i*(i - 1) // 2

for a in a_li:
    count = counter[a]
    if count == 1:
        print(ans_sum)
    else:
        print(ans_sum - count*(count - 1) // 2 + (count - 1)*(count - 2) // 2)

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

n = int(input())
a_li = list(map(int, input().split()))

ans_sum = 0

counter = Counter(a_li)
print(counter)

for i in counter:
    ans_sum += i*(i - 1)//2

for a in a_li:
    count = counter[a]
    if count == 1:
        print(ans_sum)
    else:
        print(ans_sum - count*(count - 1) // 2 + (count - 1)*(count - 2) // 2)
Problem p02743 (python)

Fixed submission:
a, b, c = map(int, input().split())
ans = 'Yes' if (c - a - b)**2 > 4*(a*b) and c - a - b > 0 else 'No'
print(ans)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
ans = 'Yes' if c - a - b > format(2*(a*b)**0.5, '.1f') else 'No'
print(ans)
Problem p02744 (python)

Fixed submission:
from collections import deque
n = int(input())

num_to_alp = {0:'a', 1:'b', 2:'c', 3:'d', 4:'e', 5:'f', 6:'g', 7:'h', 8:'i', 9:'j'}
alp_to_num = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9}
words = deque([[0]])

def next_letters(x):
    letters = deque([])
    for i in range(x + 2):
        letters.append(i)
    return letters

while len(words[0]) < n:
    word = words.popleft()
    letters = next_letters(max(word))
    for l in letters:
        l = [l]
        words.append(word + l)

for word in words:
    word = [num_to_alp[i] for i in word]
    print(''.join(word))

Buggy submission (verdict: Runtime Error):
from collections import deque
n = int(input())

num_to_alp = {0:'a', 1:'b', 2:'c', 3:'d', 4:'e', 5:'f', 6:'g', 7:'h', 8:'i', 9:'j'}
alp_to_num = {'a':0, 'b':1, 'c':2, 'd':3, 'e':4, 'f':5, 'g':6, 'h':7, 'i':8, 'j':9}
words = deque([deque([0])])

def next_letters(x):
    letters = deque([])
    for i in range(x + 2):
        letters.append(i)
    return letters

while len(words[0]) < n:
    word = words.popleft()
    letters = next_letters(max(word[-1], max(word) - 1))
    for l in letters:
        l = deque([l])
        words.append(word + l)

for word in words:
    word = [num_to_alp[i] for i in word]
    print(''.join(word))
Problem p02761 (python)

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

if n != 1:
    ans = ['1']
    ans.extend(['0'] * (n - 1))
else:
    ans = ['0']
flag = [0] * n

for s, c in s_li:
    if flag[s - 1] == 0:
        ans[s - 1] = '{}'.format(c)
        flag[s - 1] = 1
    elif flag[s - 1] == 1 and int(ans[s - 1]) == c:
        continue
    else:
        ans = ['-1']
        break

ans = int(('').join(ans))

if n != 1 and (ans // 10**(n - 1)) == 0:
    ans = -1

print(ans)

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

if n != 1:
    ans = ['1']
    ans.extend(['0'] * (n - 1))
else:
    ans = ['0']
    flag = [0] * n

for s, c in s_li:
    if flag[s - 1] == 0:
        ans[s - 1] = '{}'.format(c)
        flag[s - 1] = 1
    elif flag[s - 1] == 1 and int(ans[s - 1]) == c:
        continue
    else:
        ans = ['-1']
        break

ans = int(('').join(ans))

if n != 1 and (ans // 10**(n - 1)) == 0:
    ans = -1

print(ans)
Problem p02787 (python)

Fixed submission:
h, n = map(int, input().split())
magic = []
a_max = 0
for i in range(n):
    a, b = map(int, input().split())
    a_max = max(a, a_max)
    magic.append((a, b))

dp = [float('inf')] * (h + a_max)
dp[0] = 0
for i in range(h):
    for a, b in magic:
        if i + a > h + a_max:
            continue
        dp[i + a] = min(dp[i] + b, dp[i + a])

print(min(dp[h:]))

Buggy submission (verdict: Runtime Error):
h, n = map(int, input().split())
magic = []
INF = 10 ** 9
for i in range(n):
    a, b = map(int, input().split())
    magic.append((a, b))
ans = 0
dp = [float('inf')] * (h + 1)

# 入力: 体力, 出力: 魔力の最小値
def magic_cost(hp):
    if dp[hp] != float('inf'):
        return dp[hp]

    cost_min = float('inf')
    for a, b in magic:
        if a >= hp:
            cost = b
        else:
            cost = b + magic_cost(hp - a)
        cost_min = min(cost, cost_min)
    dp[hp] = cost_min
    return cost_min

print(magic_cost(h))
Problem p02802 (python)

Fixed submission:
n, m = map(int, input().split())
p_li, s_li = [], []
for _ in range(m):
    p, s = input().split()
    p_li.append(int(p))
    s_li.append(s)

ac = [0] * n
wa = [0] * n
for i in range(m):
    p, s = p_li[i] - 1, s_li[i]
    if s == 'AC':
        ac[p] += 1
    elif ac[p] == 0:
        wa[p] += 1
    else:
        continue
n_ac, n_wa = 0, 0
for i in range(n):
    if ac[i] != 0:
        n_ac += 1
        n_wa += wa[i]
print('{} {}'.format(n_ac, n_wa))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
p_li, s_li = [], []
for _ in range(m):
    p, s = input().split()
    p_li.append(int(p))
    s_li.append(s)

ac = [0] * n
wa = [0] * n
for i in range(m):
    p, s = p_li[i] - 1, s_li[i]
    if s == 'AC':
        ac[p] += 1
    elif ac[p] == 0:
        wa[p] += 1
    else:
        continue
n_ac, n_wa = 0, 0
for i in range(n):
    if ac[i] != 0:
        n_ac += 1
        n_wa += wa[i]
print('{} {}'.format(ans[0], ans[1]))
Problem p02814 (python)

Fixed submission:
n, m = map(int, input().split())
a_li = list(map(int, input().split()))
# すべてのaを2で割る
a_li = [a // 2 for a in a_li]

from fractions import gcd

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

def count_div_2(a):
    cnt = 0
    while a % 2 == 0:
        a = a // 2
        cnt += 1
    return cnt

# a_lcm: aの最小公倍数, parity: すべてのaの偶奇性, cnt_div: すべてのaの2で割れる回数
a_lcm = 1
cnt_div = count_div_2(a_li[0])

# a_lcmを求める
flag = False
for a in a_li:
    a_lcm = lcm(a, a_lcm)
    # 偶奇が不一致、またはa_lcmがm以上の場合答えなし
    if cnt_div != count_div_2(a) or a_lcm > m:
        flag = True
        break

# 先程弾いた場合以外で答えを出す
if flag:
    ans = 0
else:
    ans = m // a_lcm
    ans = ans // 2 + ans % 2

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a_li = list(map(int, input().split()))
a_li = [a // 2 for a in a_li]

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

def even_or_odd(a):
    parity = 'even' if a % 2 == 0 else 'odd'
    return parity

a_lcm = 1
parity = even_or_odd(a_li[0])
flag = False
for a in a_li:
    if parity != even_or_odd(a):
        flag = True
        break
    a_lcm = lcm(a, a_lcm)

if flag:
    ans = 0
elif parity == 'even':
    if a_lcm % 2 == 0:
        ans = m // a_lcm
    else:
        ans = 0
else:
    ans = m // a_lcm
    if a_lcm % 2 == 0:
        ans = ans // 2
    else:
        ans = ans // 2 + 1 if ans % 2 == 1 else ans // 2
print(ans)
Problem p02838 (python)

Fixed submission:
import numpy as np
import sys
n = int(input())
a = np.array(sys.stdin.read().split(), dtype=np.int64)
mod = 10 ** 9 + 7
ans = 0
for i in range(63):
    b = (a >> i) & 1
    x = np.count_nonzero(b)
    x = x * (n - x)
    ans += x * pow(2, i, mod) % mod
print(ans % mod)

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())), dtype=np.int64)
mod = 10 ** 9 + 7
ans = [0] * 60
for x in a:
    x = bin(x)[2:].zfill(60)
    for i in range(60):
        ans[i] += int(x[i])
for i in range(60):
    ans[i] = ans[i] * (n - ans[i]) % mod
    ans[i] = ans[i] * pow(2, 59 - i, mod) % mod
ans_sum = 0
for x in ans:
    ans_sum = (ans_sum + x) % mod
print(ans_sum)
Problem p02900 (python)

Fixed submission:
from fractions import gcd
from collections import deque

a, b = map(int, input().split())
x = gcd(a, b)
y = int(x ** 0.5)
cd = deque([])
if x ** 0.5 % 1 == 0:
    cd.append(y)
    y -= 1
prime = []
for i in range(y, 0, -1):
    if x % i == 0:
        cd.appendleft(i)
        cd.append(x // i)

def prime_check(x, prime):
    for y in prime:
        if x % y == 0:
            return False
    return True

for x in cd:
    if prime_check(x, prime) and x != 1:
        prime.append(x)
print(len(prime) + 1)

Buggy submission (verdict: Runtime Error):
from fracions import gcd
from collections import deque

a, b = map(int, input().split())
x = gcd(a, b)
y = int(x ** 0.5)
cd = deque([])
if x ** 0.5 % 1 == 0:
    cd.append(y)
    y -= 1
prime = []
for i in range(y, 0, -1):
    if x % i == 0:
        cd.appendleft(i)
        cd.append(x // i)

def prime_check(x, prime):
    for y in prime:
        if x % y == 0:
            return False
    return True

for x in cd:
    if prime_check(x, prime) and x != 1:
        prime.append(x)
print(len(prime) + 1)
Problem p02923 (python)

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

ans, cnt = 0, 0
tmp = 0
for h in h_list:
    if h > tmp:
        ans = max(cnt, ans)
        cnt = 0
    else: cnt += 1
    tmp = h
        
print(max(cnt, ans))

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

ans, cnt = 0, 0
tmp = 0
for h in h_list:
    if h > tmp:
        ans = max(cnt, ans)
        cnt = 0
    else:
      cnt += 1
      tmp = h
print(max(cnt, ans))

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

ans, cnt = 0, 0
tmp = 0
for h in h_list:
    if h > tmp:
        ans = max(cnt, ans)
        cnt = 0
    else: cnt += 1
print(max(cnt, ans))
Problem p02936 (python)

Fixed submission:
import collections

n, q = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n - 1)]
counter = [0] * n
for _ in range(q):
    p, x = map(int, input().split())
    counter[p - 1] += x

tree = [[] for _ in range(n)]
edge = collections.deque(edge)
while len(edge) != 0:
    a, b = edge.popleft()
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

que = collections.deque([0])
flag = [False] * n
while len(que) != 0:
    i = que.popleft()
    flag[i] = True
    for j in tree[i]:
        if flag[j]: continue
        counter[j] += counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

Buggy submission (verdict: Runtime Error):
import collections

n, q = map(int, input().split())
edge = collections.deque([tuple(map(int, input().split())) for _ in range(n - 1)])
query = [tuple(map(int, input().split())) for _ in range(q)]

tree = [[] for _ in range(n)]
flag = [False] * n
flag[0] = True
while len(edge) != 0:
    a, b = edge.popleft()
    a, b = a - 1, b - 1
    if flag[a] or flag[b]:
        edge.append((a, b))
        continue
    if flag[a]:
        tree[a].append(b)
    else:
        tree[b].append(b)

p = [0] * n
for x, y in query:
    p[x - 1] += y
counter = [0] * n

que = collections.deque([0])
while len(que) != 0:
    i = que.popleft()
    counter[i] += p[i]
    for j in tree[i]:
        counter[j] = counter[i]
        que.append(j)

print(' '.join([str(c) for c in counter]))

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

n, q = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n - 1)]
query = [tuple(map(int, input().split())) for _ in range(q)]

tree = [[] for _ in range(n)]
for a, b in edge:
    tree[a - 1].append(b - 1)
p = [0] * n
for x, y in query:
    p[x - 1] += y

counter = [0] * n

def solve(i=0, c=0):
    c += p[i]
    counter[i] = c
    for j in tree[i]:
        solve(j, c)
    return

solve()
for c in counter:
    print(c, end=' ')

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n - 1)]
query = [tuple(map(int, input().split())) for _ in range(q)]

tree = [[] for _ in range(n)]
for a, b in edge:
    tree[a - 1].append(b - 1)
p = [0] * n
for x, y in query:
    p[x - 1] += y

counter = [0] * n

def solve(i=0, c=0):
    c += p[i]
    counter[i] = c
    for j in tree[i]:
        solve(j, c)
    return

solve()
for c in counter:
    print(c, end=' ')
print()
Problem p02995 (python)

Fixed submission:
from fractions import gcd
a, b, c, d = map(int, input().split())

e = (c * d) // gcd(c, d)

c_min = a + (c - a % c) if (a % c) != 0 else a
c_max = b - b % c
d_min = a + (d - a % d) if (a % d) != 0 else a
d_max = b - b % d
e_min = a + (e - a % e) if (a % e) != 0 else a
e_max = b - b % e

n_c = (c_max - c_min) // c + 1 if c_min <= c_max else 0
n_d = (d_max - d_min) // d + 1 if d_min <= d_max else 0
n_e = (e_max - e_min) // e + 1 if e_min <= e_max else 0

ans = b - a + 1 - n_c - n_d + n_e

print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
a, b, c, d = map(int, input().split())

e = (c * d) // gcd(c, d)

c_min = a + (c - a % c) if (a % c) != 0 else a
c_max = b - b % c
d_min = a + (d - a % d) if (a % d) != 0 else a
d_max = b - b % d
e_min = a + (e - a % e) if (a % e) != 0 else a
e_max = b - b % e

n_c = (c_max - c_min) // c + 1 if c_min <= c_max else 0
n_d = (d_max - d_min) // d + 1 if d_min <= d_max else 0
n_e = (e_max - e_min) // e + 1 if e_min <= e_max else 0

ans = b - a + 1 - n_c - n_d + n_e

print(ans)
Problem p03141 (python)

Fixed submission:
n = int(input())
happy, a, b = [], [], []
for i in range(n):
    happy.append(tuple(map(int, input().split())))
happy.sort(key=lambda x: x[0] + x[1], reverse=True)
ans = 0
for i, (a, b) in enumerate(happy):
    if i % 2 == 0:
        ans += a
    else:
        ans -= b
print(ans)

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

sys.setrecursionlimit(10 ** 6)

n = int(input())
a, b = [], []
used = [False] * (n + 1)
used[n] = True
for i in range(n):
    a_i, b_i = map(int, input().split())
    heapq.heappush(a, (-a_i, -b_i, i))
    heapq.heappush(b, (-b_i, -a_i, i))

flag = True
ans = 0
for _ in range(n):
    i, j = n, n
    while used[i]:
        a_i, b_i, i = heapq.heappop(a)
    while used[j]:
        b_j, a_j, j = heapq.heappop(b)
    if abs(a_i - a_j) > abs(b_i - b_j):
        if flag:
            ans -= a_i
        else:
            ans += b_i
        used[i] = True
        heapq.heappush(b, (b_j, a_j, j))
    else:
        if flag:
            ans -= a_j
        else:
            ans += b_j
        used[j] = True
        heapq.heappush(b, (b_i, a_i, i))
    flag = not flag
print(ans)

Buggy submission (verdict: Runtime Error):
import heapq

n = int(input())
a, b = [], []
used = [False] * (n + 1)
used[n] = True
for i in range(n):
    a_i, b_i = map(int, input().split())
    heapq.heappush(a, (-a_i, -b_i, i))
    heapq.heappush(b, (-b_i, -a_i, i))

flag = True
ans = 0
for _ in range(n):
    i, j = n, n
    while used[i]:
        a_i, b_i, i = heapq.heappop(a)
    while used[j]:
        b_j, a_j, j = heapq.heappop(b)
    if abs(a_i - a_j) > abs(b_i - b_j):
        if flag:
            ans -= a_i
        else:
            ans += b_i
        used[i] = True
        heapq.heappush(b, (b_j, a_j, j))
    else:
        if flag:
            ans -= a_j
        else:
            ans += b_j
        used[j] = True
        heapq.heappush(b, (b_i, a_i, i))
    flag = not flag
print(ans)