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

s = set()

for i, x in list(enumerate(v))[:-2]:
    for j, y in list(enumerate(v))[i+1:-1]:
        for k, z in list(enumerate(v))[j+1:]:
            if z < x+y and (x, y, z) not in s:
                s.add((x, y, z))

print(len(s))


Fixed submission:
n = int(input())
v = list(sorted(map(int, input().split())))
v.append(2000)
total = n*(n-1)*(n-2) / 6



def bs(left, s):
    right = n+1
    while left < right-1:
        m = (right+left)//2

        if v[m]>=s:
            right = m
        else:
            left = m
    return left+1






for i, x in enumerate(v[:-2]):
    for j, y in enumerate(v[i+1:-1]):
        k = bs(j+1, y+x)
        total -= (n-k)

print(int(total))

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

counts = {}
x = v[0]
c = 0
for i in v:
    if i != x:
        counts[x] = c
        x = i
        c = 0
    c += 1
counts[x] = c

v1 = list(counts)

sums = [0]
for i in range(1, 1005):
    try:
        sums.append(v1.index(i))
    except ValueError:
        sums.append(sums[-1])


total = 0
for i, x in enumerate(v1[:n-2]):
    if x == 1:
        continue
    for j, y in enumerate(v1[i+1:n-1]):
        total += (sums[min(1004, x+y-1)] - sums[y])



for i, c in counts.items():
    if c >= 2:
        total += (sums[min(1004, 2*i-1)] - sums[c])





# v3
total += sum(True if c >= 3 else False for c in counts.values())


print(total)

Fixed submission:
n = int(input())
v = list(sorted(map(int, input().split())))
v.append(2000)
total = n*(n-1)*(n-2) / 6



def bs(left, s):
    right = n+1
    while left < right-1:
        m = (right+left)//2

        if v[m]>=s:
            right = m
        else:
            left = m
    return left+1






for i, x in enumerate(v[:-2]):
    for j, y in enumerate(v[i+1:-1]):
        k = bs(j+1, y+x)
        total -= (n-k)

print(int(total))

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

counts = {}
x = v[0]
c = 0
for i in v:
    if i != x:
        counts[x] = c
        x = i
        c = 0
    c += 1
counts[x] = c

v1 = list(counts)

sums = [0]
for i in range(1, 1005):
    try:
        sums.append(v1.index(i))
    except ValueError:
        sums.append(sums[-1])


total = 0
for i, x in enumerate(v[:n-2]):
    if x == 1:
        continue
    for j, y in enumerate(v[i+1:n-1]):
        total += (sums[min(1004, x+y-1)] - sums[y])



for i, c in counts.items():
    if c >= 2:
        total += (sums[min(1004, 2*i-1)] - sums[c])





# v3
total += sum(True if c >= 3 else False for c in counts.values())


print(total)

Fixed submission:
n = int(input())
v = list(sorted(map(int, input().split())))
v.append(2000)
total = n*(n-1)*(n-2) / 6



def bs(left, s):
    right = n+1
    while left < right-1:
        m = (right+left)//2

        if v[m]>=s:
            right = m
        else:
            left = m
    return left+1






for i, x in enumerate(v[:-2]):
    for j, y in enumerate(v[i+1:-1]):
        k = bs(j+1, y+x)
        total -= (n-k)

print(int(total))

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

counts = {}
x = v[0]
c = 0
for i in v:
    if i != x:
        counts[x] = c
        x = i
        c = 0
    c += 1
counts[x] = c

v1 = list(counts)

sums = [0]
for i in range(1, 1001):
    try:
        sums.append(v1.index(i))
    except ValueError:
        sums.append(sums[-1])


total = 0
for i, x in enumerate(v[:n-2]):
    if x == 1:
        continue
    for j, y in enumerate(v[i+1:n-1]):
        total += (sums[min(1000, x+y-1)] - sums[y])



for i, c in counts.items():
    if c >= 2:
        total += (sums[min(1000, 2*i-1)] - sums[c])





# v3
total += sum(True if c >= 3 else False for c in counts.values())


print(total)

Fixed submission:
n = int(input())
v = list(sorted(map(int, input().split())))
v.append(2000)
total = n*(n-1)*(n-2) / 6



def bs(left, s):
    right = n+1
    while left < right-1:
        m = (right+left)//2

        if v[m]>=s:
            right = m
        else:
            left = m
    return left+1






for i, x in enumerate(v[:-2]):
    for j, y in enumerate(v[i+1:-1]):
        k = bs(j+1, y+x)
        total -= (n-k)

print(int(total))

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

total = 0
for i, x in enumerate(v[:n-2]):
    for j, y in enumerate(v[i+1:n-1]):
        for k, z in enumerate(v[i+j+2:]):
            if z >= x + y:
                break
            total += 1



print(total)

Fixed submission:
n = int(input())
v = list(sorted(map(int, input().split())))
v.append(2000)
total = n*(n-1)*(n-2) / 6



def bs(left, s):
    right = n+1
    while left < right-1:
        m = (right+left)//2

        if v[m]>=s:
            right = m
        else:
            left = m
    return left+1






for i, x in enumerate(v[:-2]):
    for j, y in enumerate(v[i+1:-1]):
        k = bs(j+1, y+x)
        total -= (n-k)

print(int(total))