Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
numbers = list(map(int, input().split()))
n = numbers[0]

v = []

for i in range(n):
    numbers = list(map(int, input().split()))
    a = numbers[0]
    
    w = []
    
    for j in range(a):
        z = list(map(int, input().split()))
        w.append(z)
        
    v.append(w)
    
rezultat = 0

max_steps = 2 ** n

for i in range(max_steps):
    w = [-1] * n
    
    for j in range(n):
        if i >> j & 1:
            w[j] = 1
        else:
            w[j] = 0
    
    ok = 1
    
    for j in range(n):
        if ok == 0:
            break
        for a, b in v[j]:
            if w[j] == 1:
                a = a - 1
            if w[a] != b:
                ok = 0
                break
                
    if ok:
        rezultat = rezultat if rezultat > sum(w) else sum(w)
        
print(rezultat)


Fixed submission:
numbers = list(map(int, input().split()))
n = numbers[0]

v = []

for i in range(n):
    numbers = list(map(int, input().split()))
    a = numbers[0]
    
    w = []
    
    for j in range(a):
        z = list(map(int, input().split()))
        w.append(z)
        
    v.append(w)
    
rezultat = 0

max_steps = 2 ** n

for i in range(max_steps):
    w = [-1] * n
    
    for j in range(n):
        if i >> j & 1:
            w[j] = 1
        else:
            w[j] = 0
    
    ok = 1
    
    for j in range(n):
        if ok == 0:
            break
        for a, b in v[j]:
            if w[j] == 1:
                a = a - 1
                if w[a] != b:
                    ok = 0
                    break
                
    if ok:
        rezultat = rezultat if rezultat > sum(w) else sum(w)
        
print(rezultat)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a_list = list(map(int, input().split()))

a_list.sort(reverse=True)
swapped = False
while m > 0:
    a_list[0] = a_list[0] // 2
    m -= 1
    if (n > 1) and (a_list[0] < a_list[1]) and not swapped:
        temp = a_list[0]
        a_list[0] = a_list[1]
        a_list[1] = temp
        swapped = True
    else:
        a_list.sort(reverse=True)
        swapped = False

cost_sum = 0
for a in a_list:
    cost_sum += a

print(cost_sum)


Fixed submission:
from heapq import heappush, heappop

n, m = map(int, input().split())
a_list = list(map(int, input().split()))

hqueue = []
for a in a_list:
    heappush(hqueue, -a)

for i in range(m):
    max_item = -(-heappop(hqueue) // 2)
    heappush(hqueue, max_item)

cost = 0
for i in range(n):
    cost += -heappop(hqueue)

print(cost)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a_list = list(map(int, input().split()))

while m > 0:
    a_list.sort(reverse=True)
    a_list[0] = a_list[0] // 2
    m -= 1

cost_sum = 0
for a in a_list:
    cost_sum += a

print(cost_sum)


Fixed submission:
from heapq import heappush, heappop

n, m = map(int, input().split())
a_list = list(map(int, input().split()))

hqueue = []
for a in a_list:
    heappush(hqueue, -a)

for i in range(m):
    max_item = -(-heappop(hqueue) // 2)
    heappush(hqueue, max_item)

cost = 0
for i in range(n):
    cost += -heappop(hqueue)

print(cost)
Buggy python submission (verdict: Runtime Error):
def __is_even(num):
    return num % 2 == 0


N = int(input())
reported_num_count = {}
if __is_even(N):  # Nが偶数の場合
    # 報告が正しい場合、値は全て奇数であり、1 ~ N-1 (1つ飛ばし) が2回ずつ出現する
    for i in range(1, N, 2):
        reported_num_count[i] = 0
    for i in list(map(int, input().split())):
        if (1 <= i <= N - 1) and not __is_even(i) and reported_num_count[i] < 2:
            reported_num_count[i] += 1
        else:
            print(0)
            exit()
    print(int((2 ** (N / 2)) % (10 ** 9 + 7)))
else:  # N が奇数の場合
    # 報告が正しい場合、値は全て偶数であり、0 が 1回、 2 ~ N-1（1つ飛ばし）が2回ずつ出現する
    for i in range(0, N, 2):
        reported_num_count[i] = 0
    for i in list(map(int, input().split())):
        if (i == 0) and reported_num_count[0] < 1:
            reported_num_count[0] += 1
        elif (2 <= i <= N - 1) and __is_even(i) and reported_num_count[i] < 2:
            reported_num_count[i] += 1
        else:
            print(0)
            exit()
    print(int((2 ** ((N - 1) / 2)) % (10 ** 9 + 7)))


Fixed submission:
def __is_even(num):
    return num % 2 == 0


DIVISOR = 10 ** 9 + 7
ITR_NUM = 1000

N = int(input())
reported_num_count = {}
power_num = 0
if __is_even(N):  # Nが偶数の場合
    # 報告が正しい場合、値は全て奇数であり、1 ~ N-1 (1つ飛ばし) が2回ずつ出現する
    for i in range(1, N, 2):
        reported_num_count[i] = 0
    for i in list(map(int, input().split())):
        if (1 <= i <= N - 1) and not __is_even(i) and reported_num_count[i] < 2:
            reported_num_count[i] += 1
        else:
            print(0)
            exit()
    power_num = int(N / 2)
else:  # N が奇数の場合
    # 報告が正しい場合、値は全て偶数であり、0 が 1回、 2 ~ N-1（1つ飛ばし）が2回ずつ出現する
    for i in range(0, N, 2):
        reported_num_count[i] = 0
    for i in list(map(int, input().split())):
        if (i == 0) and reported_num_count[0] < 1:
            reported_num_count[0] += 1
        elif (2 <= i <= N - 1) and __is_even(i) and reported_num_count[i] < 2:
            reported_num_count[i] += 1
        else:
            print(0)
            exit()
    power_num = int((N - 1) / 2)

result = 1
while power_num > ITR_NUM:
    result *= 2 ** ITR_NUM % DIVISOR
    result %= DIVISOR
    power_num -= ITR_NUM
result *= 2 ** power_num % DIVISOR
print(result % DIVISOR)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()

s_work = s
s_stack = []
while len(s_work) > 0:
    if s_work.startswith("dream"):
        s_stack.append("dream")
        s_work = s_work[len("dream"):]
    elif s_work.startswith("erase"):
        s_stack.append("erase")
        s_work = s_work[len("erase"):]
    else:
        if len(s_stack) == 0 or s_stack[-1].endswith("er"):
            print("NO")
            exit()
        s_work = s_stack.pop() + s_work
        if s_work.startswith("dreamer"):
            s_stack.append("dreamer")
            s_work = s_work[len("dreamer"):]
        elif s_work.startswith("eraser"):
            s_stack.append("eraser")
            s_work = s_work[len("eraser"):]
        else:
            print("NO")

print("YES")


Fixed submission:
s = input()

s_work = s
target_list = ["dream", "dreamer", "erase", "eraser"]

while len(s_work) > 0:
    has_changed = False
    for target in target_list:
        if s_work.endswith(target):
            s_work = s_work[0:-len(target)]
            has_changed = True
            break
    if not has_changed:
        print("NO")
        exit()

print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())

start = a if a >= x else x
end = b
while start <= end:
    if start % x == 0:
        break
    if start == end:
        print(0)
        exit()
    start += 1

result = (end - start) // x + 1
if a == 0:
    result += 1
print(result)


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

start = 0
end = b
if a > x:
    if a % x == 0:
        start = a
    else:
        start = x * (a // x + 1)
else:
    start = x

if start > end:
    result = 0
else:
    result = (end - start) // x + 1
if a == 0:
    result += 1
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())

start = a
end = b
while start <= end:
    if start % x == 0:
        break
    if start == end:
        print(0)
        exit()
    start += 1

result = (end - start) // x + 1
print(result)


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

start = 0
end = b
if a > x:
    if a % x == 0:
        start = a
    else:
        start = x * (a // x + 1)
else:
    start = x

if start > end:
    result = 0
else:
    result = (end - start) // x + 1
if a == 0:
    result += 1
print(result)
Buggy python submission (verdict: Runtime Error):
N = int(input())
x = [0]*N
y = [0]*N
L1_dict = dict()
for i in range(N):
    x[i], y[i] = map(int, input().split())
for i in range(N-1):
    for j in range(i, N):
        if i != j:
            x_diff = x[j] - x[i]
            y_diff = y[j] - y[i]
            if (x_diff, y_diff) not in L1_dict:
                L1_dict[(x_diff, y_diff)] = 1
            else:
                L1_dict[(x_diff, y_diff)] = 1 + L1_dict[(x_diff, y_diff)]
M = max(L1_dict.values())

print(N - M)


Fixed submission:
N = int(input())
x = [0]*N
y = [0]*N
L1_dict = dict()
for i in range(N):
    x[i], y[i] = map(int, input().split())
xy = zip(x, y)
xy = sorted(xy, key=lambda x: (x[0], x[1]))
x, y = zip(*xy)
for i in range(N-1):
    for j in range(i, N):
        if i != j:
            x_diff = x[j] - x[i]
            y_diff = y[j] - y[i]
            if (x_diff, y_diff) not in L1_dict:
                L1_dict[(x_diff, y_diff)] = 1
            else:
                L1_dict[(x_diff, y_diff)] = 1 + L1_dict[(x_diff, y_diff)]
if L1_dict:
    M = max(L1_dict.values())
    print(N - M)
else:
    print(N)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce
import sys

sys.setrecursionlimit(100000)

def gcd(numbers):
  return reduce(fractions.gcd, numbers)

N = int(input())
A = list(map(int,input().split()))
M = 0
gcd_i = [0]*N
gcd_i[0] = A[0] 
for i in range(N):
  tmp = 0
  if i == 0:
    tmp = gcd(A[i+1:])
  elif i == N - 1:
    tmp = gcd(A[:i])
  else:
    tmp = gcd( A[0:i] + A[i+1:])
  M = max(M,tmp)  
print(M)

Fixed submission:
import fractions

def gcd(n1,n2):
  if n1 == 0:
    return n2
  elif n2 == 0:
    return n1
  else:
    return fractions.gcd(n1,n2)

n = int(input())
a = list(map(int,input().split()))
l = [0]*(n+1)
r = [0]*(n+1)
for i in range(n+1):
  if i != 0:
    l[i] = gcd(l[i-1],a[i-1])
    r[n-i] = gcd(r[n+1-i],a[n-i])
m = [gcd(l[i],r[i+1]) for i in range(n)]
print(max(m))
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = input()
c = [int(s[i]) for i in range(n)]
ids = [0]
for i in range(1,n):
  if c[i] != c[i-1]:
    ids.append(i)
ids.append(n)
l = len(ids)
result = []
for i in range(l-1):
  if c[ids[i]] == 0:
    if i + 2*k < l:
      result.append(ids[i+2*k] - ids[i])
    else:
      result.append(n - ids[i])
  else:
    if i + 2*k < l:
      result.append(ids[i+2*k+1] - ids[i])
    else:
      result.append(n - ids[i])
print(max(result))

Fixed submission:
n,k = map(int,input().split())
s = input()
c = [int(s[i]) for i in range(n)]
ids = [0]
for i in range(1,n):
  if c[i] != c[i-1]:
    ids.append(i)
ids.append(n)
l = len(ids)
result = []
for i in range(l-1):
  if c[ids[i]] == 0:
    if i + 2*k < l:
      result.append(ids[i+2*k] - ids[i])
    else:
      result.append(n - ids[i])
  else:
    if i + 2*k + 1 < l:
      result.append(ids[i+2*k+1] - ids[i])
    else:
      result.append(n - ids[i])
print(max(result))

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
s = input()
c = [int(s[i]) for i in range(n)]
count = []
cost = 0
if c[0] == 0:
  cost += -1
else:
  cost += 1
for i in range(1,n):
  if c[i] == c[i-1]:
    cost += -1 if cost < 0 else 1
  else:
    count.append(cost)
    cost = -1 if cost > 0 else 1
count.append(cost)
i = 0
M = 0
l = 0
r = 0
for j in range(len(count)):
  if count[j] < 0:
    M += -count[j]
    i += 1
  else:
    M += count[j]
  if i == k:
    if j < len(count)-2:
      M += count[j+1]
      r = j + 1
    else:
      r = j
    break
tmp = M
if r < len(count) - 2:
  if count[0] < 0:
    tmp += count[0]
    l += 1
    r += 1
    tmp += -count[r]
    if r+1 < k:
      tmp += count[r + 1]
      r += 1
    M = max(M,tmp)
  while r + 1 < K -1:
    tmp -= count[l]
    tmp += count[l+1]
    l += 2
    r += 1
    tmp += -count[r]
    if r+1 < k:
      tmp += count[r + 1]
      r += 1
    M = max(M,tmp)
print(M)
      
    
    


  

  
  

Fixed submission:
n,k = map(int,input().split())
s = input()
c = [int(s[i]) for i in range(n)]
ids = [0]
for i in range(1,n):
  if c[i] != c[i-1]:
    ids.append(i)
ids.append(n)
l = len(ids)
result = []
for i in range(l-1):
  if c[ids[i]] == 0:
    if i + 2*k < l:
      result.append(ids[i+2*k] - ids[i])
    else:
      result.append(n - ids[i])
  else:
    if i + 2*k + 1 < l:
      result.append(ids[i+2*k+1] - ids[i])
    else:
      result.append(n - ids[i])
print(max(result))
Buggy python submission (verdict: Runtime Error):
s = input()
l = 0
l_max = 0
for i in range(len(s)):
  b = S[i]
  if b == 'A' or b == 'C' or b == 'T' or b == 'G':
    l += 1
  else:
    l_max = max(l_max,l)
    l = 0
print(l_max)

Fixed submission:
s = input()
l = 0
l_max = 0
for i in range(len(s)):
  b = s[i]
  if b == 'A' or b == 'C' or b == 'T' or b == 'G':
    l += 1
  else:
    l_max = max(l_max,l)
    l = 0
l_max = max(l_max,l)
print(l_max)
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int,input().split())
s = input()
l = [0]*q
r = [0]*q
for i in range(q):
  l[i],r[i] = map(int,input().split())
count = 0
for i in range(q):
  count = 0
  for j in range(l[i]-1,r[i]-1):
    if s[j] == 'A' and s[j+1] == 'C':
      count += 1
    if j == r[i] - 2:
      print(count)

Fixed submission:
n, q = map(int,input().split())
s = input()
l = [0]*q
r = [0]*q
for i in range(q):
  l[i],r[i] = map(int,input().split())
count = 0
c_sum = [0]*n
for i in range(n-1):
  if s[i] == 'A' and s[i+1] == 'C':
    count += 1
  c_sum[i] = count
for i in range(q):
  print(c_sum[r[i]-2] - c_sum[l[i]-2])
Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())

print(solver(B) ^ solver(A-1))

def solver(N)
  if N % 2 == 1:
    return oddodd(N)
  else:
    return N+1 ^ oddodd(N+1)

def oddodd(N)
  return 1 if (N+1)/2 % 2 == 1 else 0 

Fixed submission:
def solver(N):
  if N % 2 == 1:
    return oddodd(N)
  else:
    return (N+1) ^ oddodd(N+1)

def oddodd(N):
  return 1 if (N+1)/2 % 2 == 1 else 0 

A,B = map(int,input().split())

print(solver(B) ^ solver(A-1))

Buggy python submission (verdict: Time Limit Exceeded):
A,B = map(int,input().split())
b = format(B, "b")
d_num = len(b)
digit_list = [0]*d_num
for num in range(A,B+1):
  num_str = format(num, "0"+str(d_num)+"b")
  digit_list = map(sum,zip(digit_list,[int(c) for c in num_str]))
result = [1 if digit % 2 != 0 else 0 for digit in digit_list]
print(int(''.join(map(str,result)),2))

Fixed submission:
def solver(N):
  if N % 2 == 1:
    return oddodd(N)
  else:
    return (N+1) ^ oddodd(N+1)

def oddodd(N):
  return 1 if (N+1)/2 % 2 == 1 else 0 

A,B = map(int,input().split())

print(solver(B) ^ solver(A-1))

Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
b = format(B, "b")
d_num = len(b)
a = [0]*(B-A + 1)
a[-1] = b
digit_list = [0]*d_num
for i in range(B-A):
  a[i] = format(A + i,"0"+str(d_num) + "b")
for i in range(len(a)):
    digit_list = map(sum,zip(digit_list,[int(c) for c in a[i]])) 
result = [1 if digit % 2 != 0 else 0 for digit in digit_list]
print(int(''.join(map(str,result)),2))

Fixed submission:
def solver(N):
  if N % 2 == 1:
    return oddodd(N)
  else:
    return (N+1) ^ oddodd(N+1)

def oddodd(N):
  return 1 if (N+1)/2 % 2 == 1 else 0 

A,B = map(int,input().split())

print(solver(B) ^ solver(A-1))

Buggy python submission (verdict: Runtime Error):
A,B = map(int,input().split())
b = format(B, "b")
d_num = len(b)
a = [0]*(B-A + 1)
a[-1] = b
digit_list = [0]*d_num
for i in range(B-A):
  a[i] = format(A + i,"0"+str(d_num) + "b")
for i in range(len(a)):
  for digit in a[i]:
    digit_list[i]+=int(digit) 
result = [1 if digit % 2 != 0 else 0 for digit in digit_list]
print(int(''.join(map(str,result)),2))


Fixed submission:
def solver(N):
  if N % 2 == 1:
    return oddodd(N)
  else:
    return (N+1) ^ oddodd(N+1)

def oddodd(N):
  return 1 if (N+1)/2 % 2 == 1 else 0 

A,B = map(int,input().split())

print(solver(B) ^ solver(A-1))
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
if b-a == c-b:
  print("YES")
else
  print("NO")


Fixed submission:
a,b,c = map(int,input().split())
if b-a == c-b:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
import sys
import math
n = map(int,input().split())
T,A = 1,1
for i in range(n):
    t,a = map(int,input().split())
    coef = max((T+t-1)//t,(A+a-1)//a)
    T,A = coef * t, coef * a 
print(T+A)     

    


Fixed submission:
import sys
import math
n = int(input())
T,A = 1,1
for i in range(n):
    t,a = map(int,input().split(" "))
    coef = max((T+t-1)//t,(A+a-1)//a)
    T,A = coef * t, coef * a 
print(T+A)

Buggy python submission (verdict: Runtime Error):
import sys
import math
n = map(int,input())
T,A = 1,1
for i in range(n):
    t,a = map(int,input().split())
    coef = max((T+t-1)//t,(A+a-1)//a)
    T,A = coef * t, coef * a 
print(T+A)     

    


Fixed submission:
import sys
import math
n = int(input())
T,A = 1,1
for i in range(n):
    t,a = map(int,input().split(" "))
    coef = max((T+t-1)//t,(A+a-1)//a)
    T,A = coef * t, coef * a 
print(T+A)
Buggy python submission (verdict: Runtime Error):
a = [int(input()) for i in range(4)]
sum = 0
for i in range(a[0]):
    if i + 1 <= K:
        sum += a[2]
    else:
        sum += a[3]
print(sum)


Fixed submission:
a = [int(input()) for i in range(4)]
sum = 0
for i in range(a[0]):
    if i + 1 <= a[1]:
        sum += a[2]
    else:
        sum += a[3]
print(sum)
Buggy python submission (verdict: Runtime Error):
n=input()
print(n*(n+1)//2)

Fixed submission:
n=int(input())
print(n*(n+1)//2)
Buggy python submission (verdict: Runtime Error):
import itertools
f = lambda n:n*(n+1)//2

def sol():
  res = 0
  while q:
    x0 = q.popleft()
    x1 = q.popleft()
    res += f(max(x0, x1)) + f(min(x0, x1)-1)
    return res

s = input()

q = collections.deque()
for k, g in itertools.groupby(s):
  q.append(len(list(g)))
if len(q) % 2:
  q.append(1)

print(sol())

Fixed submission:
def main():
  s = input().rstrip('\n')
  n = len(s)
  dp = [0] * (1 + n)
  for i,c in enumerate(s):
    if c == '<':
      dp[i+1] = dp[i] + 1
  for i in range(n-1, -1, -1):
    if s[i] == '>':
      dp[i] = max(dp[i], dp[i+1] + 1)
  return sum(dp)

print(main())

Buggy python submission (verdict: Runtime Error):
import itertools
f = lambda n:n*(n+1)//2

def sol():
    res = 0
    while q:
        x0 = q.popleft()
        x1 = q.popleft()
        res += f(max(x0, x1)) + f(min(x0, x1) -1)
    return res

s = input().rstrip("\n")

q = collections.deque()
for k, g in itertools.groupby(s):
    q.append(len(list(g)))
if len(q) % 2:
    q.append(1)

print(sol())


Fixed submission:
def main():
  s = input().rstrip('\n')
  n = len(s)
  dp = [0] * (1 + n)
  for i,c in enumerate(s):
    if c == '<':
      dp[i+1] = dp[i] + 1
  for i in range(n-1, -1, -1):
    if s[i] == '>':
      dp[i] = max(dp[i], dp[i+1] + 1)
  return sum(dp)

print(main())

Buggy python submission (verdict: Runtime Error):
import itertools
f = lambda n:sum(i for i in range(n+1))

def sol():
    res = 0
    while q:
        x0 = q.popleft()
        x1 = q.popleft()
        res += f(max(x0, x1)) + f(min(x0, x1) -1)
    return res

s = input().rstrip("\n")

q = collections.deque()
for k, g in itertools.groupby(s):
    q.append(len(list(g)))
if len(q) % 2:
    q.append(1)

print(sol())


Fixed submission:
def main():
  s = input().rstrip('\n')
  n = len(s)
  dp = [0] * (1 + n)
  for i,c in enumerate(s):
    if c == '<':
      dp[i+1] = dp[i] + 1
  for i in range(n-1, -1, -1):
    if s[i] == '>':
      dp[i] = max(dp[i], dp[i+1] + 1)
  return sum(dp)

print(main())

Buggy python submission (verdict: Runtime Error):
import itertools
f = lambda n:sum(i for i in range(n+1))

def sol():
    res = 0
    while q:
        x0 = q.popleft()
        x1 = q.popleft()
        res += f(max(x0, x1)) + f(min(x0, x1) -1)
    return res

s = input()

q = collections.deque()
for k, g in itertools.groupby(s):
    q.append(len(list(g)))
if len(q) % 2:
    q.append(1)

print(sol())


Fixed submission:
def main():
  s = input().rstrip('\n')
  n = len(s)
  dp = [0] * (1 + n)
  for i,c in enumerate(s):
    if c == '<':
      dp[i+1] = dp[i] + 1
  for i in range(n-1, -1, -1):
    if s[i] == '>':
      dp[i] = max(dp[i], dp[i+1] + 1)
  return sum(dp)

print(main())
Buggy python submission (verdict: Runtime Error):
n = int(input())
nums = map(int, input().split())

nums.sort()
counts = 0

for i in range(n):
  start, end = 0, i - 1
  while start < end:
    if nums[start] + nums[end] > nums[i]:
      counts += end - start
      end -= 1
    else:
      start += 1
print(counts)


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

counts = 0

for i in range(n):
  start, end = 0, i - 1
  while start < end:
    if nums[start] + nums[end] > nums[i]:
      counts += end - start
      end -= 1
    else:
      start += 1
print(counts)

Buggy python submission (verdict: Runtime Error):
n = int(input())
nums = map(int, input().split())

nums.sort()
res = 0
for k in range(n-1, 1, -1):
    i, j = 0, k-1
    while i < j and nums[i] + nums[j] <= nums[k]:
        i += 1
    while i < j and nums[i] + nums[j] > nums[k]:
        res += j - i
        j -= 1
print(res)



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

counts = 0

for i in range(n):
  start, end = 0, i - 1
  while start < end:
    if nums[start] + nums[end] > nums[i]:
      counts += end - start
      end -= 1
    else:
      start += 1
print(counts)

Buggy python submission (verdict: Runtime Error):
n = int(input())
nums = map(int, input().split())

nums.sort()
res = 0
for k in range(n-1, 1, -1):
    i, j = 0, k-1
    while i < j and nums[i] + nums[j] <= nums[k]:
      	i += 1
    while i < j and nums[i] + nums[j] > nums[k]:
      	res += j - i
        j -= 1
print(res)



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

counts = 0

for i in range(n):
  start, end = 0, i - 1
  while start < end:
    if nums[start] + nums[end] > nums[i]:
      counts += end - start
      end -= 1
    else:
      start += 1
print(counts)
Buggy python submission (verdict: Runtime Error):
N = int(input())
count = {}
for x in map(int, input().split()):
    count[x] = count.get(x, 0) + 1

a = sorted(count.values())
sums = a[:]
n = len(a)
for i in range(1, n):
    sums[i] += sums[i-1]
    
def check(k, x):
    pos = bisect.bisect_right(a, x)
    return (sums[pos-1] if pos-1 >= 0 else 0) + x * (n - pos) >= k * x

x = 0
res = []
for k in range(N, 0, -1):
    while check(k, x+1):
        x += 1
    res.append(x)
    
for x in res[::-1]:
    print(x)

Fixed submission:
import bisect
N = int(input())
count = {}
for x in map(int, input().split()):
    count[x] = count.get(x, 0) + 1

a = sorted(count.values())
sums = a[:]
n = len(a)
for i in range(1, n):
    sums[i] += sums[i-1]
    
def check(k, x):
    pos = bisect.bisect_right(a, x)
    if pos == 0:
        return x * n >= k * x
    return sums[pos-1]+ x * (n - pos) >= k * x

x = 0
res = []
for k in range(N, 0, -1):
    while check(k, x+1):
        x += 1
    res.append(x)
    
for x in res[::-1]:
    print(x)