Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A_dic = defaultdict(int)
B_dic = defaultdict(int)
C_dic = defaultdict(int)

for i in A:
  A_dic[i] += 1
  B_dic[i] = 1

for i in range(N):
  if B_dic[A[i]] == 1:
    B_dic[A[i]] -= 1
    A_dic[A[i]] -= 1
    C_dic[A[i]] += sum([(i*(i-1))//2 for i in list(A_dic.values()) if i >= 2])
    print(C_dic[A[i]])
    A_dic[A[i]] += 1
  else:
    print(C_dic[A[i]])

Fixed submission:
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A_dic = defaultdict(int)

for i in A:
  A_dic[i] += 1

S = sum([(i*(i-1))//2 for i in list(A_dic.values()) if i >= 2])

for i in range(N):
  print(S - A_dic[A[i]] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A_dic = defaultdict(int)

for i in A:
  A_dic[i] += 1

for i in range(N):
  A_dic[A[i]] -= 1
  print(sum([(i*(i-1))//2 for i in list(A_dic.values()) if i >= 2]))
  A_dic[A[i]] += 1

Fixed submission:
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A_dic = defaultdict(int)

for i in A:
  A_dic[i] += 1

S = sum([(i*(i-1))//2 for i in list(A_dic.values()) if i >= 2])

for i in range(N):
  print(S - A_dic[A[i]] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

H, W, K = map(int, input().split())
grid = ""

for _ in range(H):
  grid += input()

ans = 10000

for Hcut in product((0, 1), repeat = H-1):
  Gr_num = sum(Hcut) + 1
  old = [0]*Gr_num
  cnt = 0
  for i in range(W):
    #縦一列のchocoを見る
    choco = grid[i::W]
    new = [0]*Gr_num
    gr = 0
    for j in range(H):
      new[gr] += int(choco[j])
      if j < H-1:
        if Hcut[j] == 1:
          gr += 1
    #そもそも一列でオーバーしてたら詰み。
    if max(new) > K:
      cnt += 10000
      break
    #新しい一列を追加しても大丈夫か確認
    check = [old[gr] + new[gr] for gr in range(Gr_num)]
    if max(check) > K:
      old = new[:]
      cnt += 1
    else:
      old = check[:]
  ans = min(ans, cnt+sum(Hcut))

print(ans)

Fixed submission:
from itertools import product

H, W, K = map(int, input().split())
grid = ""

for _ in range(H):
  grid += input()

ans = 10000

for Hcut in product((0, 1), repeat = H-1):
  Gr_num = sum(Hcut) + 1
  old = [0]*Gr_num
  cnt = 0
  for i in range(W):
    #縦一列のchocoを見る
    choco = grid[i::W]
    new = [0]*Gr_num
    gr = 0
    for j in range(H):
      new[gr] += int(choco[j])
      if j < H-1:
        if Hcut[j] == 1:
          gr += 1
    #そもそも一列でオーバーしてたら詰み。
    if max(new) > K:
      cnt += 10000
      break
    #新しい一列を追加しても大丈夫か確認
    check = [old[gr] + new[gr] for gr in range(Gr_num)]
    if max(check) > K:
      old = new[:]
      cnt += 1
    else:
      old = check[:]
  ans = min(ans, cnt+sum(Hcut))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int, input().split())
count = 0

while N > 0:
  if N >= A + B:
    count += A
  else:
    count += min(A, N)
  N -= A + B

print(count)

Fixed submission:
N, A, B = map(int, input().split())
n, r = divmod(N, A+B)

ans = A * n  + min(A, r)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

S = deque(input())
Q = int(input())

for _ in range(Q):
  q = input()
  
  if q[0] == "1":
    S.reverse()
  
  if q[0] == "2":
    if q[2] == "1":
      S.appendleft(q[4])
    else:
      S.append(q[4])

print("".join(S))

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())
Flag = 1

for _ in range(Q):
  q = input()
  
  if q[0] == "1":
    Flag *= -1
  
  if q[0] == "2":
    if Flag > 0:
      if q[2] == "1":
        S.appendleft(q[4])
      else:
        S.append(q[4])
    else:
      if q[2] == "1":
        S.append(q[4])
      else:
        S.appendleft(q[4])
  
if Flag < 0:
  S.reverse()

print("".join(S))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
ans = [-1] * (N+1)
Flag = True

for i in range(M):
  s, c = map(int, input().split())
  if ans[s-1] < 0:
    ans[s-1] = c
  elif ans[s-1] == c:
    continue
  else:
    Flag = False

if N > 1:
  if ans[0] == 0:
    Flag = False
  elif ans[0] == -1:
    ans[0] = 1
    #三項演算子 真の値 if 条件式 else 偽の値
    ans = [0 if i == -1 else i for i in ans]

ans = ans[:N]

if Flag:
  print(int("".join([str(i) for i in ans])))
else:
  print(-1)

Fixed submission:
N, M = map(int, input().split())
ans = ["0"] * (N)
Flag = True

for i in range(M):
  s, c = map(int, input().split())
  if ans[s-1] == "0":
    ans[s-1] = c
  elif ans[s-1] == c:
    continue
  else:
    Flag = False

if N > 1:
  if ans[0] == 0:
    Flag = False
  elif ans[0] == "0":
    ans[0] = 1

if Flag:
  print(int("".join([str(i) for i in ans])))
else:
  print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M, K = map(int, input().split())

uf = UnionFind(N)
L = [set() for _ in range(N)]

for _ in range(M):
  A, B = map(lambda x: int(x)-1, input().split())
  uf.union(A, B)
  L[A].add(B)
  L[B].add(A)

for _ in range(K):
  C, D = map(lambda x: int(x)-1, input().split())
  L[C].add(D)
  L[D].add(C)

ans = []

for i in range(N):
  ans.append(len(set(uf.members(i)) - L[i]) - 1)

print(*ans)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M, K = map(int, input().split())

uf = UnionFind(N)
Fr = [set() for _ in range(N)]

for _ in range(M):
  A, B = map(lambda x: int(x)-1, input().split())
  uf.union(A, B)
  Fr[A].add(B)
  Fr[B].add(A)

ans = []

for i in range(N):
  ans.append(uf.size(i) - len(Fr[i]) - 1)

for _ in range(K):
  C, D = map(lambda x: int(x)-1, input().split())
  if uf.same(C, D):
    ans[C] -= 1
    ans[D] -= 1

print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
S_lis = []

for i in range(N):
  S_lis.append(input())

S_dic = collections.Counter(S_lis)
m = max(S_dic.values())
ans = []

for i in range(len(S_dic)):
  if S_dic.most_common()[i][1] == m:
    ans.append(S_dic.most_common()[i][0])

ans.sort()
for i in ans:
  print(i)

Fixed submission:
from collections import defaultdict

N = int(input())
S_dic = defaultdict(int)

for i in range(N):
  S = input()
  S_dic[S] += 1

m = max(S_dic.values())
max_S = [i[0] for i in S_dic.items() if i[1] == m ]
max_S.sort()
print("\n".join(max_S))
Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
AB = []
INF = 10**8 + 1

dp = [INF]*(H+1)
dp[0] = 0

for _ in range(N):
  a, b = map(int, input().split())
  AB.append((a, b))

for i in range(1, H+1):
  for j in range(N):
    dp[i] = min(dp[i], dp[max(0, i - AB[j][0])] + AB[j][1])

print(dp[-1])

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

dp = [INF]*(H+1)
dp[0] = 0

for _ in range(N):
  a, b = map(int, input().split())
  AB.append((a, b))

for i in range(1, H+1):
  for j in range(N):
    dp[i] = min(dp[i], dp[max(0, i - AB[j][0])] + AB[j][1])

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
count = 0

for i in range(1, N+1):
  if A[i-1] == 1:
    count += N - i
    break
  else:
    for j in range(1, i+1):
      if A[j-1] < A[i-1]:
        count += 1
        break

ans = N - count
print(ans)

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

M = N+1
ans = 0

for i in range(1, N+1):
  if M > A[i-1]:
    M = A[i-1]
    ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
count = 0

for i in range(1, N+1):
  for j in range(1, i+1):
    if A[j-1] < A[i-1]:
      count += 1
      break

ans = N - count
print(ans)

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

M = N+1
ans = 0

for i in range(1, N+1):
  if M > A[i-1]:
    M = A[i-1]
    ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
K, X = map(int,input().split())

if 500*K >= X:
  print('Yes')
  else:
    print('No')

Fixed submission:
K, X = map(int,input().split())

if 500*K >= X:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
K X = map(int,input().split())
if 500*K >= X:
    print("Yes")
else:
    print("No")

Fixed submission:
K, X = map(int,input().split())

if 500*K >= X:
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
K X = map(int,input().split())
if 500*K >= X:
    print('Yes')
else:
    print('No')

Fixed submission:
K, X = map(int,input().split())

if 500*K >= X:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

count = 0
for i in range(N-3):
  if S[i]S[i+1]S[i+2] == ABC:
    count = +1
  else:
    continue
print(count)

Fixed submission:
N = int(input())
S = input()

count = 0
for i in range(N-2):
  if S[i]+S[i+1]+S[i+2] == "ABC":
    count += 1
  else:
    continue
    
print(count)
Buggy python submission (verdict: Runtime Error):
import math

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

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

print(lcm(A, B))

Fixed submission:
from fractions import gcd

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

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

print(lcm(A, B))
Buggy python submission (verdict: Runtime Error):
import itertools

N = int(input())
P = []
ans = 0

for i in range(N):
  A = int(input())
  p = []
  for j in range(A):
    x, y = map(int, input().split())
    p.append([x-1, y])
  P.append(p)

for YN in itertools.product([1,0], repeat = N):
  s = sum(YN)
  for j in range(len(YN)):
    if YN(j) == 1:
      for k in P[j]:
        if YN(k[0]) != k[1]:
          s = 0
          break
  ans = max(ans, s)

print(ans)

Fixed submission:
#C

N = int(input())
P = []
ans = 0

for i in range(N):
  A = int(input())
  p = []
  for j in range(A):
    x, y = map(int, input().split())
    p.append([x-1, y])
  P.append(p)

#全探索
for i in range(2**N):
  Flag = True
  for j in range(N): #N人の〇×を順に見る
    
    if (i >> j) & 1 == 1: #j桁目が1、つまりj番目が正直者→チェック
      for YN in P[j]:
        if (i >> YN[0]) & 1 != YN[1]:
          Flag = False
          break

    if Flag:
      continue
    else:
      break

  if Flag:
    ans = max(ans, bin(i).count("1"))

print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools

N = int(input())
P = []
ans = 0

for i in range(N):
  A = int(input())
  p = []
  for j in range(A):
    x, y = map(int, input().split())
    p.append([x-1, y])
  P.append(p)

for YN in itertools.product([1,0], repeat = N):
  s = sum(YN)
  for j in range(len(YN)):
    if YN(j) == 1:
      for k in P[j]:
        YN(k[0]) != k[1]
        s = 0
        break
  ans = max(ans, s)

print(ans)

Fixed submission:
#C

N = int(input())
P = []
ans = 0

for i in range(N):
  A = int(input())
  p = []
  for j in range(A):
    x, y = map(int, input().split())
    p.append([x-1, y])
  P.append(p)

#全探索
for i in range(2**N):
  Flag = True
  for j in range(N): #N人の〇×を順に見る
    
    if (i >> j) & 1 == 1: #j桁目が1、つまりj番目が正直者→チェック
      for YN in P[j]:
        if (i >> YN[0]) & 1 != YN[1]:
          Flag = False
          break

    if Flag:
      continue
    else:
      break

  if Flag:
    ans = max(ans, bin(i).count("1"))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
B = [0]*60
mod = 10 ** 9 + 7

for x in A:
  for i in range(60):
    B[i] += (x >> i) & 1

ans = 0
p = 1

for i in range(60):
  if i >= 1:
    p *= 2
    p %= mod
  ans += (N-B[i])*B[i]*p
  ans %= mod

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = [0]*60
mod = 10 ** 9 + 7

for x in A:
  for i in range(60):
    B[i] += (x >> i) & 1

ans = 0
p = 1

for i in range(60):
  if i >= 1:
    p *= 2
    p %= mod
  ans += (N-B[i])*B[i]*p
  ans %= mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

N = int(input())
A = list(map(int, input().split()))
B = [0]*60
mod = 10 ** 9 + 7

for x in A:
  temp = bin(x)[2:]
  for i in range(len(temp)):
    if temp[-1-i] == "1":
      B[i] += 1

ans = 0

for i in range(60):
  ans += (N-B[i])*B[i]*pow(2, i, mod)
  ans %= mod

print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = [0]*60
mod = 10 ** 9 + 7

for x in A:
  for i in range(60):
    B[i] += (x >> i) & 1

ans = 0
p = 1

for i in range(60):
  if i >= 1:
    p *= 2
    p %= mod
  ans += (N-B[i])*B[i]*p
  ans %= mod

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [int(i) for i in input()]

ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      Flag1 = True
      Flag2 = False
      Flag3 = False
      for x in S:
        if Flag3:
          if x == k:
            ans += 1
            break
        if Flag2:
          if x == j:
            Flag2 = False
            Flag3 = True
        if Flag1:
          if x == i:
            Flag1 = False
            Flag2 = True

print(ans)

Fixed submission:
N = int(input())
S = [int(i) for i in input()]

ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      Flag1 = True
      Flag2 = False
      Flag3 = False
      for x in S:
        if Flag3:
          if x == k:
            ans += 1
            break
        if Flag2:
          if x == j:
            Flag2 = False
            Flag3 = True
        if Flag1:
          if x == i:
            Flag1 = False
            Flag2 = True

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      Flag1 = True
      Flag2 = False
      Flag3 = False
      for x in S:
        if Flag3:
          if x == str(k):
            ans += 1
            break
        if Flag2:
          if x == str(j):
            Flag2 = False
            Flag3 = True
        if Flag1:
          if x == str(i):
            Flag1 = False
            Flag2 = True

print(ans)

Fixed submission:
N = int(input())
S = [int(i) for i in input()]

ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      Flag1 = True
      Flag2 = False
      Flag3 = False
      for x in S:
        if Flag3:
          if x == k:
            ans += 1
            break
        if Flag2:
          if x == j:
            Flag2 = False
            Flag3 = True
        if Flag1:
          if x == i:
            Flag1 = False
            Flag2 = True

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = list(input())

rS = reversed(S)
cS = [0]
c1 = set()

for i, x in enumerate(rS):
  if x in c1:
    cS.append(cS[i])
  else:
    c1.add(x)
    cS.append(cS[i] + 1)

cS.reverse()

ans = 0
c2 = set()

for i in range(N-2):
  for j in range(i+1, N-1):
    x = S[i] + S[j]
    if x in c2:
      continue
    else:
      c2.add(x)
      ans += cS[j+1]

print(ans)

Fixed submission:
N = int(input())
S = [int(i) for i in input()]

ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      Flag1 = True
      Flag2 = False
      Flag3 = False
      for x in S:
        if Flag3:
          if x == k:
            ans += 1
            break
        if Flag2:
          if x == j:
            Flag2 = False
            Flag3 = True
        if Flag1:
          if x == i:
            Flag1 = False
            Flag2 = True

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = sorted(map(int, input().split()))
F = sorted(map(int, input().split()), reverse=True)

ng = -1
ok = 0
for i in range(N):
  ok = max(A[i]*F[i], ok)

def is_ok(arg):
  cnt = 0
  for i in range(N):
    cnt += max(A[i] - arg//F[i], 0)
  return cnt <= K

def m_bisect(ng, ok):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

print(m_bisect(ng, ok))

Fixed submission:
N, K = map(int, input().split())
A = sorted(map(int, input().split()))
F = sorted(map(int, input().split()), reverse=True)

ng = -1
ok = 0
for i in range(N):
  ok = max(A[i]*F[i], ok)

def is_ok(arg):
  cnt = 0
  for i in range(N):
    cnt += max(A[i] - arg//F[i], 0)
  return cnt <= K

def m_bisect(ng, ok):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

print(m_bisect(ng, ok))

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = sorted(map(int, input().split()))
F = sorted(map(int, input().split()), reverse=True)

ng = -1
ok = 0
for i in range(N):
  ok = max(A[i]*F[i], ok)

def is_ok(arg):
  cnt = 0
  for i in range(N):
    cnt += max(A[i] - arg//F[i], 0)
  return cnt <= K

def m_bisect(ng, ok):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

print(m_bisect(ng, ok))

Fixed submission:
N, K = map(int, input().split())
A = sorted(map(int, input().split()))
F = sorted(map(int, input().split()), reverse=True)

ng = -1
ok = 0
for i in range(N):
  ok = max(A[i]*F[i], ok)

def is_ok(arg):
  cnt = 0
  for i in range(N):
    cnt += max(A[i] - arg//F[i], 0)
  return cnt <= K

def m_bisect(ng, ok):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

print(m_bisect(ng, ok))
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
#Flag = True

for i in range(N-2):
  for j in range(i+1, N-1):
    k = j + 1
    while L[k-1] == L[k]:
      if k == N-1:
        k = j + 1
        break
      k += 1
    #print(i, j, k)
    cnt += bisect_left(L, L[i]+L[j]) - k
    #print(cnt)

print(cnt)

Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0

for i in range(N-2):
  for j in range(i+1, N-1):
    cnt += max(bisect_left(L, L[i]+L[j]) - (j+1), 0)

print(cnt)

Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0

for i in range(len(L)-2):
  for j in range(i+1, len(L)-1):
    k = j + 1
    while L[k-1] == L[k]:
      k += 1
    cnt += bisect_left(L,L[i]+L[j]) - k

print(cnt)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0

for i in range(N-2):
  for j in range(i+1, N-1):
    cnt += max(bisect_left(L, L[i]+L[j]) - (j+1), 0)

print(cnt)

Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0

for i in range(len(L)-2):
  for j in range(i+1, len(L)-1):
    k = j + 1
    while L[k-1] == L[k]:
      k += 1
    T = L[k:]
    cnt += bisect_left(T,L[i]+L[j])

print(cnt)


Fixed submission:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0

for i in range(N-2):
  for j in range(i+1, N-1):
    cnt += max(bisect_left(L, L[i]+L[j]) - (j+1), 0)

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

INF = 10**9
dp = [[INF]*(1<<N) for _ in range(M+1)]
dp[0][0] = 0

for i in range(M):
  a, b = map(int, input().split())
  c = sum(map(lambda x: 1 << (int(x)-1), input().split()))
  for j in range(1<<N):
    k = j|c
    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][k] = min(dp[i+1][k], dp[i][k], dp[i][j] + a)

ans = dp[-1][-1]

if ans == INF:
  print(-1)
else:
  print(ans)


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

INF = 10**9
dp = [[INF]*(1<<N) for _ in range(M+1)]
dp[0][0] = 0

for i in range(M):
  a, b = map(int, input().split())
  c = sum(map(lambda x: 1 << (int(x)-1), input().split()))
  for j in range(1<<N):
    k = j|c
    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][k] = min(dp[i+1][k], dp[i][k], dp[i][j] + a)

ans = dp[-1][-1]

if ans == INF:
  print(-1)
else:
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

INF = 10**9
dp = [[INF]*(1<<N) for _ in range(M+1)]
dp[0][0] = 0

for i in range(M):
  a, b = map(int, input().split())
  c = sum(map(lambda x: 1 << (int(x)-1), input().split()))
  for j in range(1<<N):
    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][j|c] = min(dp[i+1][j|c], dp[i][j|c], dp[i][j] + a)

ans = dp[-1][-1]

if ans == INF:
  print(-1)
else:
  print(ans)


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

INF = 10**9
dp = [[INF]*(1<<N) for _ in range(M+1)]
dp[0][0] = 0

for i in range(M):
  a, b = map(int, input().split())
  c = sum(map(lambda x: 1 << (int(x)-1), input().split()))
  for j in range(1<<N):
    k = j|c
    dp[i+1][j] = min(dp[i+1][j], dp[i][j])
    dp[i+1][k] = min(dp[i+1][k], dp[i][k], dp[i][j] + a)

ans = dp[-1][-1]

if ans == INF:
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

def rev():
  global A
  for i in range(N):
    a, b = A[-(2+i)], A[-(1+i)]
    if a > b:
      A[-(2+i)] = b
      A[-(1+i)] = a
    else:
      break

for _ in range(M):
  A[-1] = A[-1]//2
  rev()

print(sum(A))

Fixed submission:
from heapq import heappop, heappush

N, M = map(int, input().split())
A = list(map(lambda x: (-1)*int(x), input().split()))

H = []

for i in A:
  heappush(H, i)

for _ in range(M):
  m = (-1) * heappop(H)
  m //= 2
  heappush(H, (-1)*m)

print((-1)*sum(H))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(M):
  A.sort()
  A[-1] = A[-1]//2

print(sum(A))

Fixed submission:
from heapq import heappop, heappush

N, M = map(int, input().split())
A = list(map(lambda x: (-1)*int(x), input().split()))

H = []

for i in A:
  heappush(H, i)

for _ in range(M):
  m = (-1) * heappop(H)
  m //= 2
  heappush(H, (-1)*m)

print((-1)*sum(H))