Buggy python submission (verdict: Runtime Error):
k = 31
K = 1<<k
nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(1001)]]

N = int(input())
A = [int(a) for a in input().split()]
C = [0] * 1001
for a in A:
    C[a] += 1
B = li(st(nu(C) ** 2))
for a in A:
    if a <= 500: B[2*a] -= 1
for i in range(1001):
    B[i] //= 2
for i in range(1, 1001):
    C[i] += C[i-1]
for i in range(N):
    B[i] += B[i-1]
ans = N*(N-1)*(N-2)//6
for i in range(1, 1001):
    ans -= (N-C[i-1]) * B[i]
print(ans)


Fixed submission:
N = int(input())
A = sorted([int(a) for a in input().split()])
X = [0] * 1001
for a in A:
    X[a] += 1
for i in range(1, 1001):
    X[i] += X[i-1]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += X[min(A[i]+A[j]-1, 1000)] - (j+1)
print(ans)

Buggy python submission (verdict: Runtime Error):
k = 31
K = 1<<k
nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(1001)]]

N = int(input())
A = [int(a) for a in input().split()]
C = [0] * 1001
for a in A:
    C[a] += 1
B = li(st(nu(C) ** 2))
for a in A:
    if a <= 500: B[2*a] -= 1
for i in range(1001):
    B[i] //= 2
for i in range(1, 1001):
    C[i] += C[i-1]
for i in range(N):
    B[i] += B[i-1]
ans = N*(N-1)*(N-2)//6
for i in range(1, 1001):
    ans -= (N-CC[i-1]) * B[i]
print(ans)


Fixed submission:
N = int(input())
A = sorted([int(a) for a in input().split()])
X = [0] * 1001
for a in A:
    X[a] += 1
for i in range(1, 1001):
    X[i] += X[i-1]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += X[min(A[i]+A[j]-1, 1000)] - (j+1)
print(ans)

Buggy python submission (verdict: Runtime Error):
k = 31
K = 1<<k
nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(1001)]]

N = int(input())
A = [int(a) for a in input().split()]
C = [0] * 1001
for a in A:
    C[a] += 1
B = li(st(nu(C) ** 2))
for a in A:
    if a <= 500: B[2*a] -= 1
for i in range(1001):
    B[i] //= 2
for i in range(1, 1001):
    C[i] += C[i-1]
for i in range(N):
    B[i] += B[i-1]
ans = N*(N-1)*(N-2)//6
for i in range(1001):
    ans -= (N-C[i-1]) * B[i]
print(ans)


Fixed submission:
N = int(input())
A = sorted([int(a) for a in input().split()])
X = [0] * 1001
for a in A:
    X[a] += 1
for i in range(1, 1001):
    X[i] += X[i-1]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += X[min(A[i]+A[j]-1, 1000)] - (j+1)
print(ans)

Buggy python submission (verdict: Runtime Error):
k = 31
K = 1<<k
nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(1001)]]

N = int(input())
A = [int(a) for a in input().split()]
C = [0] * 1001
for a in A:
    C[a] += 1
B = li(st(nu(C) ** 2))
for a in A:
    if a <= 500: B[2*a] -= 1
for i in range(1001):
    B[i] //= 2
for i in range(1, 1001):
    C[i] += C[i-1]
for i in range(N):
    B[i] += B[i-1]
ans = N*(N-1)*(N-2)//6
for i in range(1001):
    ans -= (N-CC[i-1]) * B[i]
print(ans)


Fixed submission:
N = int(input())
A = sorted([int(a) for a in input().split()])
X = [0] * 1001
for a in A:
    X[a] += 1
for i in range(1, 1001):
    X[i] += X[i-1]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += X[min(A[i]+A[j]-1, 1000)] - (j+1)
print(ans)