Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from itertools import product

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

C = []
A = []
for i in range(N):
    t = list(map(int, input().split()))
    C.append(t[0])
    A.append(t[1:])

result = float('inf')
for p in product([True, False], N):
    t = [0] * M
    c = 0
    for j in range(N):
        if not p[j]:
            continue
        c += C[j]
        for k in range(M):
            t[k] += A[j][k]
    if all(x >= X for x in t):
        result = min(result, c)
print(result)


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

C = []
A = []
for i in range(N):
    t = list(map(int, input().split()))
    C.append(t[0])
    A.append(t[1:])

result = -1
for i in range(1 << N):
    t = [0] * M
    c = 0
    for j in range(N):
        if (i >> j) & 1 == 0:
            continue
        c += C[j]
        a = A[j]
        for k in range(M):
            t[k] += a[k]
    if all(x >= X for x in t):
        if result == -1:
            result = c
        else:
            result = min(result, c)
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

result = 0
for i in range(N):
    a = A[i]
    b = a + i
    for j in range(1, N - a - i):
        if j == A[j + b]:
            result += 1
print(result)


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

c1 = {}
c2 = {}

for i in range(N):
    c1.setdefault(i + A[i], 0)
    c1[i + A[i]] += 1
    c2.setdefault(i - A[i], 0)
    c2[i - A[i]] += 1

result = 0
for k in set(c1).intersection(c2):
    result += c1[k] * c2[k]
print(result)

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

result = 0
for i in range(N):
    for j in range(i + A[i], N):
        if j - i == A[i] + A[j]:
            result += 1
print(result)


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

c1 = {}
c2 = {}

for i in range(N):
    c1.setdefault(i + A[i], 0)
    c1[i + A[i]] += 1
    c2.setdefault(i - A[i], 0)
    c2[i - A[i]] += 1

result = 0
for k in set(c1).intersection(c2):
    result += c1[k] * c2[k]
print(result)

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

result = 0
for i in range(N):
    for j in range(i + A[i], N):
        if abs(i - j) == A[i] + A[j]:
            result += 1
print(result)


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

c1 = {}
c2 = {}

for i in range(N):
    c1.setdefault(i + A[i], 0)
    c1[i + A[i]] += 1
    c2.setdefault(i - A[i], 0)
    c2[i - A[i]] += 1

result = 0
for k in set(c1).intersection(c2):
    result += c1[k] * c2[k]
print(result)

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

result = 0
for i in range(N):
    for j in range(i + A[i], N):
        if abs(i - j) == A[i] + A[j]:
            result += 1
print(result)


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

c1 = {}
c2 = {}

for i in range(N):
    c1.setdefault(i + A[i], 0)
    c1[i + A[i]] += 1
    c2.setdefault(i - A[i], 0)
    c2[i - A[i]] += 1

result = 0
for k in set(c1).intersection(c2):
    result += c1[k] * c2[k]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations

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

d = {}
for i in range(N):
    if A[i] < N:
        d[i] = A[i]

result = 0
for a, b in combinations(d, 2):
    if abs(a - b) == A[a] + A[b]:
        result += 1
print(result)


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

c1 = {}
c2 = {}

for i in range(N):
    c1.setdefault(i + A[i], 0)
    c1[i + A[i]] += 1
    c2.setdefault(i - A[i], 0)
    c2[i - A[i]] += 1

result = 0
for k in set(c1).intersection(c2):
    result += c1[k] * c2[k]
print(result)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

sieve = [0] * (100000 + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, 100000 + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, 100000 + 1, i):
        if sieve[j] == 0:
            sieve[j] = i

p = []
for i in range(N - 1, -1, -1):
    if sieve[i] == i:
        p.append(i)
p.append(1)

t = set()
pp = 0
for i in range(M):
    x = i + 1
    y = x + p[pp]
    while y in t:
        pp += 1
        y = x + p[pp]
    t.add(x)
    t.add(y)
    print(x, y)
    pp += 1


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

for i in range(1, M + 1):
    if i % 2 == 1:
        j = (i - 1) // 2
        print(1 + j, M + 1 - j)
    else:
        j = (i - 2) // 2
        print(M + 2 + j, 2 * M + 1 - j)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

result = [0] * N
for a in A:
    result[a - 1] += 1
print('\n'.join(result))


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

d = {}

for i in range(N - 1):
    if A[i] in d:
        d[A[i]].append(i + 2)
    else:
        d[A[i]] = [i + 2]

for i in range(1, N + 1):
    if i in d:
        print(len(d[i]))
    else:
        print(0)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())

MOD = 10 ** 9 + 7

cache = {}
def f(k, n):
    if k == 1:
        return 1
    if k in cache:
        return cache[k]
    result = pow(k, n, MOD)
    for i in range(2, k + 1):
        result -= f(k // i, n)
        result %= MOD
    cache[k] = result
    return result


result = 0
for i in range(K + 1):
    result += f(K // i, N) * i
    result %= MOD
print(result)


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

MOD = 10 ** 9 + 7

cache = {}
def f(k, n):
    if k == 1:
        return 1
    if k in cache:
        return cache[k]
    result = pow(k, n, MOD)
    for i in range(2, k + 1):
        result -= f(k // i, n)
        result %= MOD
    cache[k] = result
    return result

result = 0
for i in range(2, K + 1):
    result += f(K // i, N) * i
result += f(K, N)
result %= MOD
print(result)
Buggy python submission (verdict: Runtime Error):
N, X, Y = map(int, input().split())

t = [0] * (N - 1)
for i in range(1, N):
    for j in range(i + 1, N + 1):
        t[min(j - i, abs(X - i) + 1 + abs(Y - j)) - 1] += 1
#print('\n'.join(map(str, t)))
print(*result, sep='\n')


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

t = [0] * (N - 1)
for i in range(1, N):
    for j in range(i + 1, N + 1):
        t[min(j - i, abs(X - i) + 1 + abs(Y - j)) - 1] += 1
print('\n'.join(map(str, t)))
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

for i in range(1000):
    t = str(i)
    if len(t) != N:
        continue
    ok = True
    for s, c in sc:
        if t[int(s)] != int(c):
            ok = False
            break
    if ok:
        print(i)
        exit()
print(-1)


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

t = [-1] * N
for _ in range(M):
    s, c = map(int, input().split())
    s -= 1
    if t[s] != -1 and t[s] != c:
        print(-1)
        exit()
    t[s] = c

if N == 1 and t[0] == 0:
    print(0)
    exit()

if N == 1 and t[0] == -1:
    print(0)
    exit()

if t[0] == 0:
    print(-1)
    exit()

if t[0] == -1:
    t[0] = 1

for i in range(1, N):
    if t[i] == -1:
        t[i] = 0

print(''.join(map(str, t)))
Buggy python submission (verdict: Runtime Error):
N = int(input())

d = {}
for _ in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1

m = max(d.values)
l = []
for k in d:
    v = d[k]
    if v != m:
        continue
    l.append(v)

for s in sorted(l):
    print(s)


Fixed submission:
N = int(input())

d1 = {}
for _ in range(N):
    S = input()
    if S in d1:
        d1[S] += 1
    else:
        d1[S] = 1

d2 = {}
for key in d1:
    value = d1[key]
    if value in d2:
        d2[value].append(key)
    else:
        d2[value] = [key]

key = sorted(d2.keys(), reverse=True)[0]
for s in sorted(d2[key]):
    print(s)
Buggy python submission (verdict: Runtime Error):
N = input()
K = int(input())

a = 1
b = [0] * (K + 1)
b[0] = 1
b[1] = int(N[0]) - 1

for c in N[1:]:
    t = int(c)
    for i in range(K - 1, -1, -1):
        b[i + 1] += b[i] * 9
    if t != 0:
        b[a + 1] += t - 1
        b[a] += 1
        a += 1

if a == K:
    print(b[K] + 1)
else:
    print(b[K])


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

a = [0] * (K + 1)
b = [0] * (K + 1)

t = int(N[0])

a = 1
b[0] = 1
b[1] = t - 1

for c in N[1:]:
    t = int(c)
    for i in range(K - 1, -1, -1):
        b[i + 1] += b[i] * 9
    if t != 0:
        if t != 1 and a + 1 <= K:
            b[a + 1] += t - 1
        if a <= K:
            b[a] += 1
        a += 1

if a == K:
    print(b[K] + 1)
else:
    print(b[K])
Buggy python submission (verdict: Runtime Error):
# エラトステネスの篩, フェルマーの小定理
from math import sqrt


def mpow(x, n):
    result = 1
    while n != 0:
        if n & 1 == 1:
            result *= x
            result %= 1000000007
        x *= x
        x %= 1000000007
        n >>= 1
    return result


max_A = 1000000

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

sieve = [0] * (max_A + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, int(sqrt(max_A)) + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, max_A + 1, i):
        if sieve[j] == 0:
            sieve[j] = i

lcm_factors = {}
for i in range(N):
    t = []
    a = A[i]
    while a != 1:
        if len(t) != 0 and t[-1][0] == sieve[a]:
            t[-1][1] += 1
        else:
            t.append([sieve[a], 1])
        a //= sieve[a]
    for k, v in t:
        if k not in lcm_factors or lcm_factors[k] < v:
            lcm_factors[k] = v

lcm = 1
for k in lcm_factors:
    for i in range(lcm_factors[k]):
        lcm *= k
        lcm %= 1000000007

result = 0
for i in range(N):
    result += lcm * mpow(A[i], 1000000007-2)
    result %= 1000000007
print(result)


Fixed submission:
def mpow(x, n):
    result = 1
    while n != 0:
        if n & 1 == 1:
            result *= x
            result %= 1000000007
        x *= x
        x %= 1000000007
        n >>= 1
    return result


max_A = 1000000

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

sieve = [0] * (max_A + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, max_A + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, max_A + 1, i):
        if sieve[j] == 0:
            sieve[j] = i

lcm_factors = {}
for i in range(N):
    t = []
    a = A[i]
    while a != 1:
        if len(t) == 0:
            t.append([sieve[a], 1])
        elif t[-1][0] == sieve[a]:
            t[-1][1] += 1
        else:
            t.append([sieve[a], 1])
        a //= sieve[a]
    for k, v in t:
        if k not in lcm_factors or lcm_factors[k] < v:
            lcm_factors[k] = v

lcm = 1
for k in lcm_factors:
    for i in range(lcm_factors[k]):
        lcm *= k
        lcm %= 1000000007

result = 0
for i in range(N):
    result += lcm * mpow(A[i], 1000000007-2)
    result %= 1000000007
print(result)
Buggy python submission (verdict: Runtime Error):
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	N := readInt()
	M := readInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = readInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	U := A[0] * 2
	L := A[N-1] * 2

	// cgs[i] は パワーがi以上のゲストの数
	cgs := make([]int, U+1)
	for _, a := range A {
		cgs[a]++
	}
	for i := U; i > 0; i-- {
		cgs[i-1] += cgs[i]
	}

	isOk := func(n int) bool {
		m := 0
		for _, a := range A {
			m += cgs[max(n-a, 0)]
		}
		return m >= M
	}

	ok := L
	ng := U + 1
	for ng-ok != 1 {
		m := ok + (ng-ok)/2
		if isOk(m) {
			ok = m
		} else {
			ng = m
		}
	}

	// cps[i] は A[0]～A[i] の累積和
	cps := make([]int, N)
	cps[0] = A[0]
	for i := 1; i < N; i++ {
		cps[i] = A[i] + cps[i-1]
	}

	result := 0
	for _, a := range A {
		guests := cgs[max(ok-a, 0)]
		if guests != 0 {
			result += a*guests + cps[guests-1]
			M -= guests
		}
	}
	result += ok * M
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

A.sort(reverse=True)
U = A[0] * 2

# cgs[i] は パワーがi以上のゲストの数
cgs = [0] * (U + 1)
for a in A:
    cgs[a] += 1
for i in range(U, 0, -1):
    cgs[i - 1] += cgs[i]


def is_ok(n):
    m = 0
    for a in A:
        m += cgs[max(n - a, 0)]
    return m >= M


ok = A[-1] * 2
ng = U + 1
while ng - ok > 1:
    m = (ok + ng) // 2
    if is_ok(m):
        ok = m
    else:
        ng = m

# cps[i] は A[0]～A[i] の累積和
cps = A[:]
for i in range(1, N):
    cps[i] += cps[i - 1]

result = 0
for a in A:
    t = cgs[max(ok - a, 0)]
    if t != 0:
        result += a * t + cps[t - 1]
        M -= t
result += ok * M
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from sys import setrecursionlimit
  setrecursionlimit(100000)

  N = int(input())
  ab = [list(map(int, input().split())) for _ in range(N - 1)]

  nodes = [[] for _ in range(N)]
  for a, b in ab:
    nodes[a-1].append(b-1)
    nodes[b-1].append(a-1)

  used = [set() for _ in range(N)]
  K = max(len(nodes[i]) for i in range(N))
  print(K)

  colors = [[-1] * N for _ in range(N)]

  def f(node, out, p, nodes, colors):
    cn = 1
    for n in nodes[node]:
      if n == p:
        continue
      if cn == out:
        cn += 1
      colors[node][n] = cn
      colors[n][node] = cn
      f(n, cn, node, nodes, colors)
      cn += 1

  f(0, -1, -1, nodes, colors)

  for a, b in ab:
    print(colors[a-1][b-1])
main()


Fixed submission:
from sys import setrecursionlimit


def genid(a, b):
    if b < a:
        a, b = b, a
    return a * 100000 + b


def paint(currentNode, usedColor, parentNode, edges, colors):
    color = 1
    for childNode in edges[currentNode]:
        if childNode == parentNode:
            continue
        if color == usedColor:
            color += 1
        colors[genid(currentNode, childNode)] = color
        paint(childNode, color, currentNode, edges, colors)
        color += 1


setrecursionlimit(100000)

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]

edges = [[] for _ in range(N)]
for a, b in ab:
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

colors = {}
paint(0, -1, -1, edges, colors)

print(max(len(e) for e in edges))
for a, b in ab:
    print(colors[genid(a - 1, b - 1)])

Buggy python submission (verdict: Time Limit Exceeded):
from sys import setrecursionlimit
setrecursionlimit(100000)

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]

nodes = [[] for _ in range(N)]
for a, b in ab:
  nodes[a-1].append(b-1)
  nodes[b-1].append(a-1)

used = [set() for _ in range(N)]
K = max(len(nodes[i]) for i in range(N))
print(K)

colors = [[-1] * N for _ in range(N)]

def f(node, out, p):
  cn = 1
  for n in nodes[node]:
    if n == p:
      continue
    if cn == out:
      cn += 1
    colors[node][n] = cn
    colors[n][node] = cn
    f(n, cn, node)
    cn += 1

f(0, -1, -1)

for a, b in ab:
  print(colors[a-1][b-1])


Fixed submission:
from sys import setrecursionlimit


def genid(a, b):
    if b < a:
        a, b = b, a
    return a * 100000 + b


def paint(currentNode, usedColor, parentNode, edges, colors):
    color = 1
    for childNode in edges[currentNode]:
        if childNode == parentNode:
            continue
        if color == usedColor:
            color += 1
        colors[genid(currentNode, childNode)] = color
        paint(childNode, color, currentNode, edges, colors)
        color += 1


setrecursionlimit(100000)

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]

edges = [[] for _ in range(N)]
for a, b in ab:
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

colors = {}
paint(0, -1, -1, edges, colors)

print(max(len(e) for e in edges))
for a, b in ab:
    print(colors[genid(a - 1, b - 1)])
Buggy python submission (verdict: Runtime Error):
H, W, K = map(int, input().split())
s = [input() for _ in range(H)]

a = [[-1] * W for _ in range(H)]

sbs = []
n = 1
for i in range(H):
  si = s[i]
  for j in range(W):
    if si[j] == '#':
      a[i][j] = n
      n += 1
      sbs.append((i, j))

for sb in sbs:
  i, j = sb
  n = a[i][j]
  t, l = i - 1, j - 1
  r = j + 1
  while t > -1:
    if a[t][j] != -1:
      break
    t -= 1
  t += 1
  while l > -1:
    if a[i][l] != -1:
      break
    l -= 1
  l += 1
  while r < W:
    if a[i][r] != -1:
      break
    r += 1
  r -= 1
  for l in range(y, i + 1):
    al = a[l]
    for m in range(x, r):
      al[m] = n

for h in range(H - 1, -1, -1):
  if a[h][0] != -1:
    break
h += 1

if h != H:
  for i in range(h, H):
    ai1 = a[i - 1]
    ai = a[i]
    for j in range(W):
      ai[j] = ai1[j]

for i in range(H):
  ai = a[i]
  for w in range(W - 1, -1, -1):
    if ai[w] != -1:
      break
  w += 1

  if w != W:
    n = ai[w - 1]
    for j in range(w, W):
      ai[j] = n

for i in range(H):
  print(*a[i])


Fixed submission:
H, W, K = map(int, input().split())
s = [input() for _ in range(H)]

a = [[-1] * W for _ in range(H)]

sbs = []
n = 1
for i in range(H):
  si = s[i]
  for j in range(W):
    if si[j] == '#':
      a[i][j] = n
      n += 1
      sbs.append((i, j))

for sb in sbs:
  i, j = sb
  n = a[i][j]
  t, l = i - 1, j - 1
  r = j + 1
  while t > -1:
    if a[t][j] != -1:
      break
    t -= 1
  t += 1
  while l > -1:
    if a[i][l] != -1:
      break
    l -= 1
  l += 1
  while r < W:
    if a[i][r] != -1:
      break
    r += 1
  r -= 1
  for y in range(t, i + 1):
    ay = a[y]
    for x in range(l, r + 1):
      ay[x] = n

for h in range(H - 1, -1, -1):
  if a[h][0] != -1:
    break
h += 1

if h != H:
  for i in range(h, H):
    ai1 = a[i - 1]
    ai = a[i]
    for j in range(W):
      ai[j] = ai1[j]

for i in range(H):
  ai = a[i]
  for w in range(W - 1, -1, -1):
    if ai[w] != -1:
      break
  w += 1

  if w != W:
    n = ai[w - 1]
    for j in range(w, W):
      ai[j] = n

for i in range(H):
  print(*a[i])
Buggy python submission (verdict: Runtime Error):
from math import asin, atan, pi

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

if x == a * a * b:
  print(0)
elif x >= a * a * b / 2:
  print(atan((a*a*b-x)/(a*a*a)*2)/(2 * pi)*360)
else:
  print(90 - asin(x/(a*b/2))/(2 * pi)*360)


Fixed submission:
from math import atan, pi

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

if x == a * a * b:
  print(0)
elif x >= a * a * b / 2:
  print(atan((a*a*b-x)/(a*a*a)*2)/(2 * pi)*360)
else:
  print(90 - atan(x/(a*b*b/2))/(2 * pi)*360)

Buggy python submission (verdict: Runtime Error):
from math import asin, atan, pi

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

if x == a * a * b:
  print(0)
if x >= a * a * b / 2:
  print(atan((a*a*b-x)/(a*a*a)*2)/(2 * pi)*360)
else:
  print(90 - asin(x/(a*b/2))/(2 * pi)*360)


Fixed submission:
from math import atan, pi

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

if x == a * a * b:
  print(0)
elif x >= a * a * b / 2:
  print(atan((a*a*b-x)/(a*a*a)*2)/(2 * pi)*360)
else:
  print(90 - atan(x/(a*b*b/2))/(2 * pi)*360)

Buggy python submission (verdict: Runtime Error):
from math import asin, atan, pi

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

if x >= a * a * b / 2:
  print(atan((a*a*b-x)/(a*a*a)*2)/(2 * pi)*360)
else:
  print(90 - asin(x/(a*b*b/2))/(2 * pi)*360)

Fixed submission:
from math import atan, pi

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

if x == a * a * b:
  print(0)
elif x >= a * a * b / 2:
  print(atan((a*a*b-x)/(a*a*a)*2)/(2 * pi)*360)
else:
  print(90 - atan(x/(a*b*b/2))/(2 * pi)*360)
Buggy python submission (verdict: Runtime Error):
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	N := readInt()
	L := make([]int, N)
	for i := 0; i < N; i++ {
		L[i] = readInt()
	}

	sort.Sort(sort.IntSlice(L))
	result := 0
	for i := 0; i < N-2; i++ {
		for j := i + 1; j < N-1; j++ {
			result += sort.SearchInts(L, L[i]+L[j]) - j - 1
		}
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Fixed submission:
from bisect import bisect_left, bisect_right

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

L.sort()
result = 0
for i in range(N - 2):
  a = L[i]
  for j in range(i + 1, N - 1):
    b = L[j]
    result += bisect_left(L, a + b) - j - 1
print(result)

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

L.sort()
result = 0
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    a = L[i]
    b = L[j]
    for k in range(j + 1, N):
      c = L[k]
      if c >= a + b:
        break
      if a < b + c and b < c + a:
        result += 1
print(result)


Fixed submission:
from bisect import bisect_left, bisect_right

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

L.sort()
result = 0
for i in range(N - 2):
  a = L[i]
  for j in range(i + 1, N - 1):
    b = L[j]
    result += bisect_left(L, a + b) - j - 1
print(result)