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

Fixed submission:
# coding: utf-8
N, K = map(int, input().split())
mod = 10**9 + 7
A = list(map(int, input().split()))
l = []
for i in range(N):
    tmp = [0, 0]
    for j in range(N):
        if j < i:
            if A[i] < A[j]:
                tmp[0] += 1
        else:
            if A[i] < A[j]:
                tmp[1] += 1
    l.append(tmp[:])
ans = 0
for i in range(N):
    ans += l[i][0]*K*(K+1) // 2
    ans %= mod
    ans += l[i][1] * K * (K - 1) // 2
    ans %= mod
print(ans % mod)

Buggy submission (verdict: Runtime Error):
import streams, sequtils, strutils, algorithm, math, future, sets, tables, hashes
proc `ceilDiv`*[T](x, y: T): T = x div y + ord(x mod y != 0)
proc `//=`*(x: var SomeInteger; y: SomeInteger) = x = x div y
proc `%=`*(x: var SomeInteger; y: SomeInteger) = x = x mod y

var
    L = stdin.readLine.split.map(parseInt)
    N = L[0]
    K = L[1]
    A = stdin.readLine.split.map(parseInt)
    MOD = 10^9 + 7
    ans = 0.int64
    jun = newSeqWith(N, 0)
    inv = newSeqWith(N, 0)
for i in 0..N-1:
    for j in 0..N-1:
        if j < i:
            if A[i] < A[j]:
                jun[i] += 1
        else:
            if A[i] < A[j]:
                inv[i] += 1
for i in 0..N-1:
    ans += K * (((jun[i] * (K+1)) + (inv[i] * (K-1))) div 2)
    ans %= MOD
    # ans += (inv[i] * (K-1)) mod MOD
    # ans %= MOD
echo ans mod MOD
Problem p02975 (python)

Fixed submission:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort()
d = {}
for i in range(N):
    a = A[i]
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1
if len(d.keys()) == 1:
    if list(d.keys())[0] == 0:
        print("Yes")
    else:
        print("No")
elif len(d.keys()) == 2:
    keys = list(sorted(list(d.keys())))
    if d[keys[0]] == N // 3:
        print("Yes")
    else:
        print("No")
elif len(d.keys()) == 3:
    keys = list(d.keys())
    if keys[0] ^ keys[1] ^ keys[2] == 0:
        if d[keys[0]] == d[keys[1]] == d[keys[2]]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort()
d = {}
for i in range(N):
    a = A[i]
    if a not in d.keys():
        d[a] = 1
    else:
        d[a] += 1
if len(d.keys()) == 1:
    if d.keys()[0] == 0:
        print("Yes")
    else:
        print("No")
elif len(d.keys()) == 2:
    keys = list(sorted(list(d.keys())))
    if d[keys[0]] == N // 3:
        print("Yes")
    else:
        print("No")
elif len(d.keys()) == 3:
    keys = list(d.keys())
    if keys[0] ^ keys[1] ^ keys[2] == 0:
        if d[keys[0]] == d[keys[1]] == d[keys[2]]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")
Problem p02995 (python)

Fixed submission:
# coding: utf-8
from math import ceil, floor
from fractions import gcd
A, B, C, D = map(int, input().split())
lcm = (C * D) // gcd(C, D)
c_cnt = B // C - (A-1) // C
d_cnt = B // D - (A-1) // D
cd_cnt = B // (lcm) - (A-1) // (lcm)
minus = c_cnt + d_cnt - cd_cnt
print(B - A - minus + 1)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
from math import ceil, floor, gcd
A, B, C, D = map(int, input().split())
lcm = (C * D) // gcd(C, D)
# c_cnt = ceil((B) / C) - (A-1) // C
# d_cnt = ceil((B) / D) - (A-1) // D
# cd_cnt = ceil((B) / (lcm)) - (A-1) // (lcm)
c_cnt = B // C - (A-1) // C
d_cnt = B // D - (A-1) // D
cd_cnt = B // (lcm) - (A-1) // (lcm)
minus = c_cnt + d_cnt - cd_cnt
# print(c_cnt, d_cnt, cd_cnt)
print(B - A - minus + 1)
Problem p03049 (python)

Fixed submission:
#coding: utf-8
N = int(input())
ans = 0
l_B = 0
r_A = 0
lbra = 0
for _ in range(N):
	tmp = input()
	ans += tmp.count("AB")
	if tmp[0] == "B":
		if tmp[-1] == "A":
			lbra += 1
		else:
			l_B += 1
	elif tmp[-1] == "A":
		r_A += 1
        
if lbra == 0:
    ans += min(l_B, r_A)
else:
    if l_B + r_A > 0:
        ans += lbra + min(l_B, r_A)
    else:
        ans += lbra - 1
print(ans)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
N = int(input())
ans = 0
l_B = 0
r_A = 0
lbra = 0
for _ in range(N):
	tmp = input()
	ans += tmp.count("AB")
	if tmp[0] == "B":
		if tmp[-1] == "A":
			lbra += 1
		else:
			l_B += 1
	elif tmp[-1] == "A":
		r_A += 1
l.sort()
print(ans + lbra + min(l_B, r_A))
Problem p03061 (python)

Fixed submission:
#coding: utf-8
try:
    from math import gcd
except:
    from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
AL = [0] * N  # 左からGCD
AR = [0] * N  # 右からGCD
for i in range(1, N):
    AR[i] = gcd(AR[i-1], A[i-1])
for i in range(N-1)[::-1]:
    AL[i] = gcd(AL[i+1], A[i+1])
A_list = [gcd(AL[i], AR[i]) for i in range(N)]
print(max(A_list))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
try:
    from math import gcd
except:
    from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
A.sort()
l = []
for i in range(2, A[0]+1):
    if A[0] % i == 0:
        l.append(i)
for i in range(2, A[1]+1):
    if A[1] % i == 0:
        l.append(i)
l = list(set(l))
ans = []
for i in l:
    cnt = 0
    for a in A:
        if a % i != 0:
            cnt += 1
    if cnt == 1:
        ans.append(i)
print(max(ans))
Problem p03069 (python)

Fixed submission:
#coding: utf-8
N = int(input())
S = list(input())
ans = S.count(".")
cnt = ans
for i in range(N):
    if S[i] == "#":
        cnt += 1
    else:
        cnt -= 1
    ans = min(ans, cnt)
print(ans)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
N = int(input())
S = list(input())
ans = 0
for j in range(i, N):
    if S[j] == ".":
        ans += 1
print(ans)
Problem p03086 (python)

Fixed submission:
#coding: utf-8
S = input()
enki = ["A", "T", "G", "C"]
a = []
ans = ""
max_ = 0
for i in range(len(S)):
    if S[i] in enki:
        ans += S[i]
    else:
        ans = ""
    a.append(ans)
    max_ = max(max_, len(ans))
print(max_)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
S = list(input())
enki = ["A", "T", "G", "C"]
cnt = 0
index = 0
a = []
ans = ""
for i in range(len(S)):
    if S[i] in enki:
        ans += S[i]
        a.append(ans)
    else:
        ans = ""
print(len(max(a)))

Buggy submission (verdict: Runtime Error):
#coding: utf-8
S = list(input())
enki = ["A", "T", "G", "C"]
cnt = 0
index = 0
a = []
ans = ""
for i in range(len(S)):
    if S[i] in enki:
        ans += S[i]
    else:
        a.append(ans)
        ans = ""
print(len(max(a)))
Problem p03087 (python)

Fixed submission:
#coding: utf-8
N, Q = map(int, input().split())
S = input()
T = [0]
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        T.append(T[i] + 1)
    else:
        T.append(T[i])
for j in range(Q):
    l, r = map(int, input().split())
    print(T[r-1] - T[l-1])

Buggy submission (verdict: Runtime Error):
#coding: utf-8
N, Q = map(int, input().split())
S = input()
T = [0]
for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        T.append(T[i] + 1)
    else:
        T.append(T[i])
print(T)
for j in range(Q):
    l, r = map(int, input().split())
    print(T[r-1] - T[l-1])

Buggy submission (verdict: Runtime Error):
#coding: utf-8
N, Q = map(int, input().split())
S = input()
T = [0]
for i in range(N):
    if S[i] == "A" and S[i+1] == "C":
        T.append(T[i] + 1)
    else:
        T.append(T[i])
for j in range(Q):
    l, r = map(int, input().split())
    print(T[r] - T[l-1])

Buggy submission (verdict: Runtime Error):
#coding: utf-8
N, Q = map(int, input().split())
S = input()
S_l = []
for i in range(len(S)):
    if S[i] == "A" and S[i+1] == "C":
        S_l.append([i+1, i+2])
for i in range(Q):
    l, r = map(int, input().split())
    cnt = 0
    for j in range(len(S_l)):
        if l <= S_l[j][0] <=r and l <= S_l[j][1] <= r:
            cnt += 1
    print(cnt)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
N, Q = map(int, input().split())
S = input()
for i in range(Q):
    q1 = list(map(int, input().split()))
    cnt = 0
    qs = S[q1[0]-1: q1[1]]
    print(qs)
    print(qs.count("AC"))
Problem p03102 (python)

Fixed submission:
#coding: utf-8
import numpy as np
N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
A = np.array([list(map(int, input().split())) for _ in range(N)])
sum_ = np.array([np.sum(A[i] * B) + C for i in range(N)])
print(np.sum(sum_ > 0))

Buggy submission (verdict: Runtime Error):
#coding: utf-8
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = list(map(int, input().split())) for _ in range(N))
l []
for i in range(N):
    A = list(map(int, input().split()))
    l.append(sum(A[j] * B[j] for j in range(M)) + C > 0)
print(l)

Buggy submission (verdict: Runtime Error):
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
l = []
for i in range(N):
    l.append(list(map(int, input().split())))
for j in range(N):
    sum_ = [l[j][i] * B[i] for i in range(M)]
print(sum([sum_[i] > -C for i in range(N)]))
Problem p03103 (python)

Fixed submission:
#coding: utf-8
import numpy as np
N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
money = 0
col_num = 0
AB = AB[np.argsort(AB[:, col_num])]
if M <= AB[np.argmin(AB[:, 0]), 1]:
    money += AB[0, 0] * M
else:
    i = 0
    while M > 0:
        money += AB[i, 0] * AB[i, 1]
        M -= AB[i, 1]
        if M <= 0:
          money += AB[i, 0] * M
        i += 1
print(money)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
money = 0
AB = sorted(AB, key=lambda x: x[0])
if M <= AB[0][1]:
  money += AB[0][0] * AB[0][1]
else:
  i = 0
  while M >= 0:
    money += AB[i][0] * AB[i][1]
    M -= AB[i][1]
    if M < 0:
      money += AB[i][0] * M
    i += 1
print(money)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
money = 0
AB = sorted(AB, key=lambda x: x[0])
if M <= AB[0][1]:
  money += AB[0][0] * AB[0][1]
else:
  i = 0
  while M >= 0:
    money += AB[i][0] * AB[i][1]
    M -= AB[i][1]
    if M <= 0:
      money += AB[i][0] * M
    i += 1
print(money)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
import numpy as np
N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
money = 0
col_num = 0
AB = AB[np.argsort(AB[:, col_num])]
if M <= AB[np.argmin(AB[:, 0]), 1]:
    money += AB[0, 0] * M
else:
    i = 0
    while M >= 0:
        money += AB[i, 0] * AB[i, 1]
        M -= AB[i, 1]
        if M <= 0:
          money += AB[i, 0] * M
        i += 1
print(money)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
import numpy as np
N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
money = 0
col_num = 0
AB = AB[np.argsort(AB[:, col_num])]
if M <= AB[np.argmin(AB[:, 0]), 1]:
    money += AB[0, 0] * M
else:
    i = 0
    while M >= 0:
        money += AB[i, 0] * AB[i, 1]
        M -= AB[i, 1]
        if M < 0:
          money += AB[i, 0] * M
        i += 1
print(money)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
import numpy as np
N, M = map(int, input().split())
AB = np.array([list(map(int, input().split())) for _ in range(N)])
money = 0
col_num = 0
AB = AB[np.argsort(AB[:, col_num])]
print(AB)
if M <= AB[np.argmin(AB[:, 0]), 1]:
    money += AB[0, 0] * M
else:
    i = 0
    while M >= 0:
        money += AB[i, 0] * AB[i, 1]
        M -= AB[i, 1]
        if M < 0:
          money += AB[i, 0] * M
        i += 1
print(money)
Problem p03111 (python)

Fixed submission:
# coding: utf-8
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out
    
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
ans = float("inf")
for i in range(4**N):
    bits = Base_10_to_n(i, 4).zfill(N)
    a, b, c = 0, 0, 0
    cost = 0
    for j in range(len(bits)):
        if bits[j] == "0":
            pass
        elif bits[j] == "1":
            a += L[j]
            cost += 10
        elif bits[j] == "2":
            b += L[j]
            cost += 10
        else:
            c += L[j]
            cost += 10
    if min(a, b, c) > 0:
        ans = min(ans, cost + abs(a-A)+abs(b-B)+abs(c-C) - 10*3)
print(ans)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
import numpy as np

N, A, B, C = map(int, input().split())
bumboo = np.array([int(input()) for _ in range(N)])
magic = 0
for i in [A, B, C]:
    bumboo_diff = bumboo - i
    bumboo_diff = np.where(bumboo_diff >= 0)
    if np.sum(bumboo_diff) >= 2:
        magic += 10
    else:
        magic += np.min(bumboo_diff)
print(magic)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
import numpy as np

N, A, B, C = map(int, input().split())
bumboo = np.array([int(input()) for _ in range(N)])
magic = 0
for i in [A, B, C]:
    bumboo_diff = bumboo - i
    bumboo_diff = np.where(bumboo_diff >= 0)
    if np.sum(bumboo_diff) == 2:
        magic += 10
    else:
        magic += np.min(bumboo_diff)
print(magic)
Problem p03125 (python)

Fixed submission:
A, B = map(int, input().split())
if B % A == 0:
  print(A+B)
else:
  print(B-A)

Buggy submission (verdict: Runtime Error):
N = int(input())
monstar = list(map(int, input().split()))
monstar.sort()
min1, min2 = monstar[0], monstar[1]
while min1 > 0 and min2 > 0:
  if min1 <= min2:
    min2 -= min1
  else:
    min1 -= min2
print(max(min1, min2))

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())
menu = np.array([])
for i in range(N):
  a = np.array(input().split())
  menu = np.append(menu, a[1:])
menu = np.array(menu).astype(int).ravel()
count = 0
for i in range(1, M+1):
  if np.sum(menu == i) == N:
    count += 1
print(count)
Problem p03129 (python)

Fixed submission:
N, K = map(int, input().split())
if (N+1)/K >= 2:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
K, A, B = map(int, input().split())
bis = 0
C = int(B/A)
D = int(K/A)
if C >= 2 and K>A:
  if K >= A*D+D:
    K -= A*D+D
    print(K+B*D)
  else:
    K -= A*(D-1)+D-1
    print(K+B*(D-1))
else:
  print(K+1)

Buggy submission (verdict: Runtime Error):
K, A, B = map(int, input().split())
C = int(B/A)
D = int(K/A)
if C >= 2:
  if K >= A*D+D:
    K -= A*D+D
    print(K+B*D)
  else:
    K -= A*(D-1)+D-1
    print(K+B*(D-1))
else:
  print(K+1)

Buggy submission (verdict: Runtime Error):
K, A, B = map(int, input().split())
bis = 0
C = int(B/A)
D = int(K/A)
if C >= 2:
  if K >= A*D+D:
    K -= A*D+D
    print(K+B*D)
  else:
    K -= A*(D-1)+D-1
    print(K+B*(D-1))
else:
  print(K+1)
Problem p03200 (python)

Fixed submission:
# coding: utf-8

s = list(input())
time = 0
count = 0
for i in range(len(s)):
  if s[i] == "W":
    time += i - count
    count += 1

print(time)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
def calc(state, print_state):
  times = 0
  while "BW" in print_state:
      for i in range(len(state)):
          if state[i] == "B":
              if i < len(state)-1 and state[i+1] == "W":
                  state[i] = "W"
                  state[i+1] = "B"
                  times += 1
                  print_state = "".join(state)            
  print(times)
    
if __name__ == "__main__":
  start = time.time()
  state = list(input())
  print_state = "".join(state)
  calc(state, print_state)
Problem p03219 (python)

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

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input())
print(int(X + Y/2))

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input())
print(X + Y/2)

Buggy submission (verdict: Runtime Error):
a, b = map(int, input())
print(a+b/2)
Problem p03229 (python)

Fixed submission:
# coding: utf-8
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
A.sort()
L1, L2 = [0] * N, [0] * N
L1[0] = A[N//2]
L2[0] = A[N//2]
for i in range(1, N):
    if i % 2 == 0:
        L1[i] = A[i//2-1]
        L2[i] = A[-i//2]
    else:
        L1[i] = A[-i//2]
        L2[i] = A[i//2]
a1, a2 = 0, 0
for i in range(N-1):
    a1 += abs(L1[i] - L1[i+1])
    a2 += abs(L2[i] - L2[i+1])
print(max(a1, a2))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
A.sort()
L = []
if A[N//2] < A[N//2+1]:
    flag = True
else:
    flag = False
for i in range(N//2):
    if flag:
        L.append(A[N//2-1-i])
        L.append(A[-1-i])
    else:
        L.append(A[-1-i])
        L.append(A[N//2-1-i])
ans = 0
if N % 2 == 1:
    L.append(A[N//2])
for i in range(N-1):
    ans += abs(L[i] - L[i+1])
print(ans)
Problem p03238 (python)

Fixed submission:
N = int(input())
if N == 1:
  print("Hello World")
else:
  A = int(input())
  B = int(input())
  print(A+B)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())
if N == 1:
  print("Hello World")
else:
  print(A+B)
Problem p03246 (python)

Fixed submission:
#coding: utf-8
from collections import Counter
N = int(input())
l = list(map(int,input().split()))
if len(set(l)) > 1:
  o, e = [], []
  for i in range(N):
    if i % 2==0:
      e.append(l[i])
    else:
      o.append(l[i])
  oc, oe = Counter(o).most_common(2), Counter(e).most_common(2)
  print(len(l) - oc[0][1] - oe[0][1] if oc[0][0] != oe[0][0] else len(l) - max(oc[0][1] + oe[1][1], oc[1][1] + oe[0][1]))

else:
  print(len(l) // 2)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
from collections import Counter
N = int(input())
l = list(map(int,input().split()))
if len(set(l)) > 1:
  o, e = [], []
  for i in range(N):
    if i % 2==0:
      e.append(l[i])
    else:
      o.append(l[i])
  oc, oe = Counter(o).most_common(2), Counter(e).most_common(2)
  print(len(l) - oc[0][1] - oe[0][1] if oc[0][1] != oe[0][1] else len(l) - max(oc[0][1] + oe[1][1], oc[1][1] + oe[0][1]))

else:
  print(len(l) // 2)
Problem p03262 (python)

Fixed submission:
#coding: utf-8
from functools import reduce
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [abs(X - x[i]) for i in range(N)]
l = reduce(gcd, x)
print(l)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
from math import gcd
from functools import reduce
N, X = map(int, input().split())
x = list(map(int, input().split()))
x = [abs(X - x[i]) for i in range(N)]
l = reduce(gcd, x)
print(l)
Problem p03282 (python)

Fixed submission:
#coding: utf-8
N = input()
K = int(input())
ans = 0
for i in range(min(K, len(N))):
    if int(N[i]) != 1:
        ans = N[i]
        #print(N[i])
        break
print(ans if ans != 0 else 1)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
N = list(map(int, list(input())))
K = int(input())
if N[0] == 1:
    print(N[1])
else:
    print(N[0])
Problem p03476 (python)

Fixed submission:
# coding: utf-8
from bisect import bisect_left, bisect_right
def check(x):
    flag = True
    for i in range(2, int(x**0.5) + 1):
        if x % i == 0:
            flag = False
            break
    return flag

def primes(n):  
    is_prime = [True] * (n + 1)  
    is_prime[0] = False  
    is_prime[1] = False  
    for i in range(2, int(n**0.5) + 1):  
        if not is_prime[i]:  
            continue  
        for j in range(i * 2, n + 1, i):  
            is_prime[j] = False  
    return [i for i in range(n + 1) if is_prime[i]]
def primes_plus(l):
    # l: 素数の配列
    L = []
    for p in l:
        if check((p+1)//2):
            L.append(p)
    return L
l_primes = primes(10**6)
l_primes = primes_plus(l_primes)[1:]
# print(len(l_primes))
Q = int(input())
for i in range(Q):
    ans = 0
    l, r = map(int, input().split())
    r += 1
    l_idx = bisect_left(l_primes, l)
    r_idx = bisect_left(l_primes, r)
    # print(l_idx, r_idx)
    if l == r and l_idx == r_idx and l == l_primes[l_idx]:
        print(1)
    else:
        print(r_idx - l_idx)
# print(l_primes)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
from bisect import bisect_left, bisect_right
def eratosthenes(N):
    # 素数判定
    flag = True
    for i in range(2, int(N**0.5) + 1):
        if N % i == 0:
            flag = False
            break
    return flag

def make_prime_nums(N):
    # Nまでの素数のリストを作成
    prime_tf = [True for _ in range(N+1)]
    prime_tf[0] = False
    prime_tf[1] = False
    for i in range(N+1):
        if prime_tf[i]:
            if eratosthenes(i):
                for j in range(i*2, N+1, i):
                    prime_tf[j] = False
    primes = [i for i in range(N+1) if prime_tf[i]]
    return primes

def make_prime_new(L):
    new_primes = []
    for l in L:
        tmp = (l+1) // 2
        if eratosthenes(tmp):
            new_primes.append(l)
    return new_primes

primes = make_prime_nums(10**5)
primes = make_prime_new(primes)[1:]
# print(primes)
N = int(input())
for _ in range(N):
    l, r = map(int, input().split())
    l_idx = bisect_left(primes, l)
    r_idx = bisect_left(primes, r)
    if l == r and l_idx == r_idx and l == primes[l_idx]:
        print(1)
    else:
        print(r_idx - l_idx)
Problem p03583 (python)

Fixed submission:
# coding: utf-8
N = int(input())
for h in range(1, 3501)[::-1]:
    for n in range(1, 3501)[::-1]:
        if 4*h*n-N*(h+n) == 0:
            continue
        w = (N*(h*n)) / (4*h*n-N*(h+n))
        if w != int(w) or w <= 0:
            continue
        w = int(w)
        if 4/N == (n*w+h*w+h*n)/(h*n*w):# and 1 <= h <= 3500 and 1 <= n <= 3500 and 1 <= w <= 3500:
            print(h, n, w)
            exit()

Buggy submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        w = (N*(h+n)) / (4*h*n-N)
        if w != int(w) or w < 0:
            continue
        if N == 4*h*n*w / (h+n+w):
            print(h, n, int(w))
            exit()
Problem p03627 (python)

Fixed submission:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Aset = list(set(A))
Aset.sort(reverse=True)
a, b = 0, 0
L = []
cnt = 1
for i in range(1, N):
    if A[i] == A[i-1]:
        cnt += 1
    else:
        L.append(cnt)
        cnt = 1
if A[-1] == A[-2]:
    L.append(cnt)
idx = 0
for i in range(len(L)):
    if L[i] >= 4:
        a, b = Aset[i], Aset[i]
        break
    elif L[i] >= 2:
        a = Aset[i]
        idx = i + 1
        break
if b <= 0:
    for i in range(idx, len(L)):
        if L[i] >= 2:
            b = Aset[i]
            break
print(a * b)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
Aset = list(set(A))
Aset.sort(reverse=True)
a, b = 0, 0
L = []
cnt = 1
for i in range(1, N):
    if A[i] == A[i-1]:
        cnt += 1
    else:
        L.append(cnt)
        cnt = 1
if A[-1] == A[-2]:
    L.append(cnt)
idx = 0
for i in range(len(Aset)):
    if L[i] >= 4:
        a, b = Aset[i], Aset[i]
        break
    elif L[i] >= 2:
        a = Aset[i]
        idx = i + 1
        break
if b <= 0:
    for i in range(idx, len(Aset)):
        if L[i] >= 2:
            b = Aset[i]
            break
print(a * b)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort()
# cnts = Counter(A)
cnts = {}
for i in range(N):
    if A[i] not in cnts.keys():
        cnts[A[i]] = 1
    else:
        cnts[A[i]] += 1
d = {}
for k in cnts.keys():
    if cnts[k] >= 2:
        d[k] = cnts[k] // 2 
ids = list(d.keys())[::-1]
if d[ids[0]] >= 2:
    ans = ids[0] ** 2
elif len(ids) >= 2:
    ans = ids[0] * ids[1]
else:
    ans = 0
print(ans)