Problem: Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.  He is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:    * a < b + c   * b < c + a   * c < a + b  How many different triangles can be formed? Two triangles are considered different when there is a stick used in only one of them.

Submission attempts (in order):
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(0,n-2):
  for j in range(i+1,n-1):
    x=l[i]+l[j]
    y=bisect.bisect_left(l,x)-1
    ans+=max((y-j),0)
    
print(ans)    
    

n=int(input())
l=list(int,input())
ans=0
for i in range(0,len(l)):
  for j in range(i+1,len(l)):
    for k in range(j+1,len(l)):
      if l[i]>=l[j] and l[i]>=l[k]:
        if l[i]>l[j]+l[k]:
          ans+=1
        else:
          ans+=0
      if l[j]>=l[i] and l[j]>=l[k]:
        if l[j]>l[i]+l[k]:
          ans+=1
        else:
          ans+=0
      if l[k]>=l[i] and l[k]>=l[j]:
        if l[k]>l[i]+l[j]:
          ans+=1
        else:
          ans+=0   
print(ans)          


n=int(input())
l=[map(int,input().split())]
l.sort()
ans=0
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[k]<l[i]+l[j]:
        ans+=1
        
print(ans)        
        


import bisect
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(0,n-2):
  for j in range(i+1,n-1):
    x=l[i]+l[j]
    y=bisect.bisect_left(l,x)-1
    ans+=max((y-j),0)
    
print(ans)    
    


n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i]+l[j]>l[k]:
        ans+=1
        
    
print(ans)

n=int(input())
l=int(input())
ans=0
for i in range(0,len(l)):
  for j in range(i+1,len(l)):
    for k in range(j+1,len(l)):
      if l[i]>=l[j] and l[i]>=l[k]:
        if l[i]>l[j]+l[k]:
          ans+=1
        else:
          ans+=0
      if l[j]>=l[i] and l[j]>=l[k]:
        if l[j]>l[i]+l[k]:
          ans+=1
        else:
          ans+=0
      if l[k]>=l[i] and l[k]>=l[j]:
        if l[k]>l[i]+l[j]:
          ans+=1
        else:
          ans+=0   
print(ans)          


import bisect
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(0,n-1):
  for j in range(i+1,n):
    x=l[i]+l[j]
    y=bisect.bisect_left(l,x)-1
    ans+=max((y-j),0)
    
print(ans)    
    


n=int(input())
l=int(input())
ans=0
for i in range(0,len(l)):
    for j in range(i+1,len(l)):
        for k in range(j+1,len(l)):
            if l[i]>=l[j] and l[i]>=l[k]:
                if l[i]>l[j]+l[k]:
                    ans+=1
                else:
                    ans+=0
            if l[j]>=l[i] and l[j]>=l[k]:
                if l[j]>l[i]+l[k]:
                    ans+=1
                else:
                    ans+=0
            if l[k]>=l[i] and l[k]>=l[j]:
                if l[k]>l[i]+l[j]:
                    ans+=1
                else:
                    ans+=0   
print(ans)       

n=int(input())
l=list(int,input())
ans=0
for i in range(0,len(l)):
  for j in range(i+1,len(l)):
    for k in range(j+1,len(l)):
      if i>=j and i>=k:
        if i>j+k:
          ans+=1
        else:
          ans+=0
      if j>=i and j>=k:
        if j>i+k:
          ans+=1
        else:
          ans+=0
      if k>=i and k>=j:
        if k>i+j:
          ans+=1
        else:
          ans+=0   
print(ans)          

n=int(input())
l=[map(int,input().split)]
l.sort()
ans=0
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[k]<l[i]+l[j]:
        ans+=1
        
print(ans)        
        

import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(0,n-1):
  for j in range(i+1,n):
    x=l[i]+l[j]
    y=bisect.bisect_left(l,x)-1
    ans+=max((y-j),0)
    
print(ans)    
    


Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Accepted