Buggy python submission (verdict: Runtime Error):

def findnumberofTriangles(arr): 
	n = len(arr) 
	arr.sort() 
	count = 0
	for i in range(0, n-2):  
		k = i + 2 
		for j in range(i + 1, n):  
			while (k < n and arr[i] + arr[j] > arr[k]): 
				k += 1
			if(k>j): 
				count += k - j - 1

	return count 

n = int(input())
arr=[int(x) for x in input().split()]
print(findnumberoftriangles(arr))



Fixed submission:

def findnumberofTriangles(arr): 
	n = len(arr) 
	arr.sort() 
	count = 0
	for i in range(0, n-2):  
		k = i + 2 
		for j in range(i + 1, n):  
			while (k < n and arr[i] + arr[j] > arr[k]): 
				k += 1
			if(k>j): 
				count += k - j - 1

	return count 

n = int(input())
arr=[int(x) for x in input().split()]
print(findnumberofTriangles(arr))

Buggy python submission (verdict: Time Limit Exceeded):

def findNumberOfTriangles(arr, n): 
	count = 0
	
	
	 
	for i in range(n): 
		for j in range(i + 1, n): 
			
			
			
			for k in range(j + 1, n): 
				
				 
				 
				if (arr[i] + arr[j] > arr[k] and
					arr[i] + arr[k] > arr[j] and
					arr[k] + arr[j] > arr[i]): 
					count += 1
	return count 
n=int(input())
li = [int(x) for x in input().split()]

print( findNumberOfTriangles(li, len(li))) 


Fixed submission:

def findnumberofTriangles(arr): 
	n = len(arr) 
	arr.sort() 
	count = 0
	for i in range(0, n-2):  
		k = i + 2 
		for j in range(i + 1, n):  
			while (k < n and arr[i] + arr[j] > arr[k]): 
				k += 1
			if(k>j): 
				count += k - j - 1

	return count 

n = int(input())
arr=[int(x) for x in input().split()]
print(findnumberofTriangles(arr))

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n=int(input())
li=[int(x) for x in input().split()]
l = list(range(n))
s = combinations(l,3)

d=0
for a,b,c in list(s):
    if li[a]<(li[b]+li[c]):
        if li[b]<(li[a]+li[c]):
            if li[c]<(li[b]+li[a]):
                d=d+1
print(d)

Fixed submission:

def findnumberofTriangles(arr): 
	n = len(arr) 
	arr.sort() 
	count = 0
	for i in range(0, n-2):  
		k = i + 2 
		for j in range(i + 1, n):  
			while (k < n and arr[i] + arr[j] > arr[k]): 
				k += 1
			if(k>j): 
				count += k - j - 1

	return count 

n = int(input())
arr=[int(x) for x in input().split()]
print(findnumberofTriangles(arr))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
li=[int(x) for x in input().split()]
from itertools import combinations
l = list(range(n))
s = combinations(l,3)
s=list(s)
d=0
for a,b,c in s:
    if li[a]<(li[b]+li[c]):
        if li[b]<(li[a]+li[c]):
            if li[c]<(li[b]+li[a]):
                d=d+1
            else:
                pass
        else:
            pass
        
    else:
        pass
print(d)

Fixed submission:

def findnumberofTriangles(arr): 
	n = len(arr) 
	arr.sort() 
	count = 0
	for i in range(0, n-2):  
		k = i + 2 
		for j in range(i + 1, n):  
			while (k < n and arr[i] + arr[j] > arr[k]): 
				k += 1
			if(k>j): 
				count += k - j - 1

	return count 

n = int(input())
arr=[int(x) for x in input().split()]
print(findnumberofTriangles(arr))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
li=[int(x) for x in input().split()]
from itertools import combinations
l = list(range(n))
s = combinations(l,3)
s=list(s)
d=0
for a,b,c in s:
    if li[a]<(li[b]+li[c]) and li[b]<(li[a]+li[c]) and li[c]<(li[b]+li[a]):
        d=d+1
    else:
        pass
print(d)

Fixed submission:

def findnumberofTriangles(arr): 
	n = len(arr) 
	arr.sort() 
	count = 0
	for i in range(0, n-2):  
		k = i + 2 
		for j in range(i + 1, n):  
			while (k < n and arr[i] + arr[j] > arr[k]): 
				k += 1
			if(k>j): 
				count += k - j - 1

	return count 

n = int(input())
arr=[int(x) for x in input().split()]
print(findnumberofTriangles(arr))