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

n = int(input())
d = list(map(int, input().split()))
d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		m+=bisect.bisect_left(d,d[a]+d[b])-1-j

print(m)

Fixed submission:
import bisect

n = int(input())
d = list(map(int, input().split()))
d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		m+=bisect.bisect_left(d,d[a]+d[b])-1-b

print(m)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

d = list(map(int, input().split()))

d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		for c in range(b+1,n):
			if d[c]<d[b]+d[a]:
				m += 1
				if d[c]==d[a]:
					m -= 1
			else:
				break

print(m)

Fixed submission:
import bisect

n = int(input())
d = list(map(int, input().split()))
d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		m+=bisect.bisect_left(d,d[a]+d[b])-1-b

print(m)

Buggy python submission (verdict: Runtime Error):
n = int(input())

d = list(map(int, input().split()))

d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		for c in range(b+1,n):
			if d[c]<d[b]+d[a]:
				m += 1
				if d[c]==d[a]:
                  m -= 1
			else:
				break

print(m)

Fixed submission:
import bisect

n = int(input())
d = list(map(int, input().split()))
d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		m+=bisect.bisect_left(d,d[a]+d[b])-1-b

print(m)

Buggy python submission (verdict: Runtime Error):
n = int(input())

d = list(map(int, input().split()))

d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		for c in range(b+1,n):
			if d[c]<d[b]+d[a]:
				m += 1
				if d[c]==d[a]:
				m -= 1
			else:
				break

print(m)

Fixed submission:
import bisect

n = int(input())
d = list(map(int, input().split()))
d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		m+=bisect.bisect_left(d,d[a]+d[b])-1-b

print(m)

Buggy python submission (verdict: Runtime Error):
n = int(input())

d = list(map(int, input().split()))

d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		for c in range(b+1,n):
			if d[c]<d[b]+d[a]:
				m += 1
				if d[c]==d[a]:
				m -= 1
			else:
				break

print(m)

Fixed submission:
import bisect

n = int(input())
d = list(map(int, input().split()))
d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		m+=bisect.bisect_left(d,d[a]+d[b])-1-b

print(m)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

d = list(map(int, input().split()))

d.sort()

m = 0



for a in range(n-2):
	for b in range(a+1,n-1):
		for c in range(b+1,n):
			if d[c]==d[a]:
				m -= 1
			if d[c]<d[b]+d[a]:
				m += 1
			else:
				break
			

print(m)

Fixed submission:
import bisect

n = int(input())
d = list(map(int, input().split()))
d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		m+=bisect.bisect_left(d,d[a]+d[b])-1-b

print(m)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

d = list(map(int, input().split()))

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		for c in range(b+1,n):
			if d[a]<d[b]+d[c] and d[b]<d[c]+d[a] and d[c]<d[a]+d[b]:
				m += 1
				#print(str(a)+" "+str(b)+" "+str(c))

print(m)

Fixed submission:
import bisect

n = int(input())
d = list(map(int, input().split()))
d.sort()

m = 0

for a in range(n-2):
	for b in range(a+1,n-1):
		m+=bisect.bisect_left(d,d[a]+d[b])-1-b

print(m)