Problem:


Score : 400 points

Problem Statement

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.

Constraints

All values in input are integers.

3 \leq N \leq 2 \times 10^3

1 \leq L_i \leq 10^3

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 ... L_N

Constraints

Print the number of different triangles that can be formed.

Sample Input 1

4
3 4 2 1

Sample Output 1

1

Only one triangle can be formed: the triangle formed by the first, second, and third sticks.

Sample Input 2

3
1 1000 1

Sample Output 2

0

No triangles can be formed.

Sample Input 3

7
218 786 704 233 645 728 389

Sample Output 3

23



Sample input:
4
3 4 2 1


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
N=int(input().strip())
L=list(map(int,input().strip().split()))

count=0
for i,a in enumerate(L):
    for  j,b in enumerate(L[i+1:]):
        for c in L[i+1+j+1:]:
            if a<b+c and b<a+c and c<a+b:
                count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
L.append(2*10**3)
 
c = 0
for i in range(N-2):
  for j in range(i+1, N-1):
    kl, kr = j, N+1
    km = (kl + kr) // 2
    li, lj = L[i], L[j]
    while kr > kl+1:
      if L[km] < li + lj:
        kl = km
      else:
        kr = km
      
      km = (kl + kr) // 2
    
    if L[kr] < li + lj:
      c += kr - j
    else:
      c += kl - j

print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int,input().split()))
ans = 0
L.sort()
lst = [0 for i in range(10**3+1)]
for i in range(N):
    lst[L[i]]+=1
for i in range(N-1):
    for j in range(i+1,N):
        p = L[i]+L[j]
        ans += sum(lst[:p])-(j+1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
 
n = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0
for i in range(n):
  for j in range(n-i-1):
    cnt += len([c for c in l[j+i+2:] if c < l[i] + l[j+i+1]])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import sys
input = sys.stdin.readline
 
n = int(input())
l = list(map(int, input().split()))
l.sort()

cnt = 0
for i in range(n):
  a = l[i]
  for j in range(n-i-1):
    b = l[j+i+1]
    cnt += len([c for c in l[j+i+2:] if c < a + b])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))

L.sort()

count = 0
for i in range(0, N - 2):
    for p in range(i + 1, N - 1):
        left = p + 1
        right = N - 1
        tmp = (left + right) // 2
        if left == right:
            if L[i] + L[p] > L[left]:
                count += (left - p)
                break
        while 'true':
            if L[i] + L[p] > L[tmp]:
                left = tmp
                tmp = (left + right) // 2
            else:
                right = tmp
                tmp = (left + right) // 2
            if abs(right - left) <= 1:
                if L[i] + L[p] > L[right]:
                    count += (right - p)
                    break
                elif L[i] + L[p] > L[left]:
                    count += (left - p)
                    break
                else:
                    break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))

L.sort()

count = 0
for i in range(0, N - 2):
    for p in range(i + 1, N - 1):
        left = p + 1
        right = N - 1
        tmp = (left + right) // 2
        while 'true':
            if L[i] + L[p] > L[tmp]:
                left = tmp
                tmp = (left + right) // 2
            else:
                right = tmp
                tmp = (left + right) // 2
            if abs(right - left) <= 1:
                if L[i] + L[p] > L[right]:
                    count += (right - p)
                    break
                elif L[i] + L[p] > L[left]:
                    count += (left - p)
                    break
                else:
                    break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))

L.sort()

count = 0
for i in range(0, N - 2):
    for p in range(i + 1, N - 1):
        for q in range(p + 1, N):
            if L[i] + L[p] > L[q]:
                count += 1
            else:
                break
print(count)

Submission status: Time Limit Exceeded

Solution code:
in_n = int(input());
#in_S = str(input());
in_l = [int(i) for i in input().split()];
#S = [str(s) for s in in_S]
#print(in_N);
#print(in_S);
#print(S);
#calc
total = 0;
tmp_n = in_l;
tmp_n.sort();
#print(tmp_n);
for i in range(in_n-2):
    for j in range(i+1,in_n-1):
        for k in range(j+1,in_n):
            if(tmp_n[k] >= tmp_n[i] + tmp_n[j] ):
                break;
            total += 1;
                #if(tmp_n[j] < tmp_n[k] + tmp_n[i]):
                    #print(i);
                    #print(j);
                    
print(total);

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))

ans = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if(L[i] < (L[j] + L[k]) and L[j] < (L[k] + L[i]) and L[k] < (L[i] + L[j])):
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def solve(ls) -> int:
  n = len(ls)
  assert(3 <= n <= 2 * 10**3)

  def n_possible_cs(a: int, b: int, first_ic: int) -> int:
    def bin_search_le_rightmost(s: int, e: int, target: int):
      if s == e:
        if ls[s] > target:
          return None
        else:
          return s

      mid = s + (e - s) // 2

      if ls[mid] <= target and (mid + 1 < n and ls[mid + 1] > target):
        return mid
      elif ls[mid] <= target:
        return bin_search_le_rightmost(mid + 1, e, target)
      else:
        return bin_search_le_rightmost(s, mid, target)

    idx = bin_search_le_rightmost(first_ic, n - 1, a + b - 1)
    return 0 if idx is None else idx - first_ic + 1

  ret = 0
  for ia in range(0, n - 2):
    for ib in range(ia + 1, n - 1):
      a, b = (ls[ia], ls[ib])
      x = n_possible_cs(a, b, ib + 1)
      ret += x
  return ret


n = int(input().strip())
ls = [int(l) for l in input().split()]

print(solve(sorted(ls)))

Submission status: Time Limit Exceeded

Solution code:
def solve(ls) -> int:
  n = len(ls)
  assert(3 <= n <= 2 * 10**3)

  ret = 0

  ia, ib, ic = (0, 1, 2)
  need_adjust = False
  while True:
    if need_adjust or ic == n:
      ib, ic = (ib + 1, ib + 2)
      if ic == n:
        ia, ib, ic = (ia + 1, ia + 2, ia + 3)
      # index check
      if ic == n:
        break
      need_adjust = False

    a, b, c = (ls[ia], ls[ib], ls[ic])
    if a < b + c and b < c + a and c < a + b:
      ret += 1
    elif c >= a + b:
      need_adjust = True

    ic = ic + 1

  return ret


n = int(input().strip())
ls = [int(l) for l in input().split()]

print(solve(sorted(ls)))

Submission status: Time Limit Exceeded

Solution code:
def solve(ls) -> int:
  n = len(ls)
  assert(3 <= n <= 2 * 10**3)

  ret = 0

  ia, ib, ic = (0, 1, 1)
  while True:
    # index adjustment
    ic = ic + 1
    if ic == n:
      ib, ic = (ib + 1, ib + 2)
      if ic == n:
        ia, ib, ic = (ia + 1, ia + 2, ia + 3)
    # index check
    if ic == n:
      break

    a, b, c = (ls[ia], ls[ib], ls[ic])
    if a < b + c and b < c + a and c < a + b:
      ret += 1

  return ret


n = int(input().strip())
ls = [int(l) for l in input().split()]

print(solve(ls))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(len(l) - 2):
    for j in range(i + 1, len(l) - 1):
        low = j + 1
        high = len(l)
        while low < high:
            mid = (low + high) // 2
            if l[mid] == l[i] + l[j]:
                low = mid
                break
            elif l[mid] < l[i] + l[j]:
                low = mid + 1
            else:
                high = mid
        ans += low - 1 - j
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
L = list(map(int, input().split()))
ans = 0
for i,j,k in list(combinations(L,3)):
  if max(i,j,k)*2 < i+j+k:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L0 = list(map(int, input().split()))
L = sorted(L0)
tri = 0
for left in range(N-2):
    for mid in range(left+1, N-1):
        right = mid+1
        while right <= N-1 and L[right] < L[left] + L[mid]:
            tri += 1
            right += 1

print(tri)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

#in_N = [int(i) for i in input().split()];
in_n = int(input());
#in_S = str(input());
in_l = [int(i) for i in input().split()];
#S = [str(s) for s in in_S]
#print(in_N);
#print(in_S);
#print(S);
#calc
total = 0;
tmp_n = in_l;
#print(tmp_n);
for i in range(in_n):
    if (in_n-i) <= 2 :
        break;
    for j in range(i+1,in_n):
        if (in_n-j) <= 1 :
            break;
        for k in range(j+1,in_n):
            if(tmp_n[i] < tmp_n[j] + tmp_n[k]):
                if(tmp_n[j] < tmp_n[k] + tmp_n[i]):
                    if(tmp_n[k] < tmp_n[i] + tmp_n[j]):
                        #print(i);
                        #print(j);
                        total += 1;
print(total);
#        total +=1;
#    for j in range(len(in_d)-1):
        #print(i);
        #print(j);
#        if(i+j+1 == len(in_d)):break;
#        total += in_d[i]*in_d[i+j+1];
 
#print(in_N - total);

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
nums = list(map(int, input().split()))
nums.sort(reverse=True)
ans = 0
for x in range(len(nums)):
    for y in range(x + 1, len(nums)):
        for z in range(y + 1, len(nums)):
            if nums[x] >= nums[y] + nums[z]:
                break
            #print("{} {} {}".format(x, y, z))
            ans = ans + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = list(map(int, input().split()))
nums.sort(reverse=True)
ans = 0
for x in range(len(nums)):
    for y in range(x + 1, len(nums)):
        for z in range(y + 1, len(nums)):
            if nums[x] >= nums[y] + nums[z]:
                break
            #print("{} {} {}".format(x, y, z))
            ans = ans + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
nums = list(map(int, input().split()))
nums.sort(reverse=True)
ans = 0
for x in range(len(nums)):
    for y in range(x + 1, len(nums)):
        for z in range(y + 1, len(nums)):
            # abs(a - b) >= c
            if abs(nums[x] - nums[y]) >= nums[z]:
                break
            # a + b <= c
            if nums[x] + nums[y] <= nums[z]:
                break
            #print("{} {} {}".format(x, y, z))
            ans = ans + 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
L = list(map(int, input().split()))

from itertools import permutations, combinations,combinations_with_replacement,product
nCr = list(combinations(range(N), 3))

ret = 0
for i in nCr:
  if L[i[0]]<L[i[1]]+L[i[2]] and L[i[1]]<L[i[2]]+L[i[0]] and L[i[2]]<L[i[0]]+L[i[1]]:
    ret +=1
print(ret)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N = int(input())
L = [int(i) for i in input().split()]
c = 0


def check(a, b, c):
    return (a < b+c) and (b < c+a) and (c < a+b)


for i, j, k in combinations(L, 3):
    c += check(i, j, k)

print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
 
n = int(input())
l = list(map(int, input().split()))
l.sort(reverse=True)
 
cnt = 0
for i in range(n):
  a = l[i]
  for j, b in enumerate(l[i+1:]):
    cnt += len([c for c in l[i+j+2:] if c > a - b])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
dlist = list(map(int, input().split()))
dlist.sort(reverse=True)
sum = 0

count_b = 0
count_c = 0
for a in range(N):
    count_b += 1
    count_c = count_b
    for b in range(count_b, N):
        count_c += 1 
        for c in range(count_c, N):
            if dlist[a] < dlist[b] + dlist[c]:
                sum += 1
            else:
                break
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
dlist = list(map(int, input().split()))
dlist.sort(reverse=True)
sum = 0

count_b = 0
count_c = 0
for a in dlist:
    count_b += 1
    count_c = count_b
    for b in range(count_b, N):
        count_c += 1 
        for c in range(count_c, N):
            if a < dlist[b] + dlist[c]:
                sum += 1
            else:
                break
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
dlist = list(map(int, input().split()))
dlist.sort(reverse=True)
sum = 0
N_2 = 2 ** N
for i in range(N_2):
    if bin(i).count('1') == 3:
        bin_i = bin(i)
        i_2 = bin_i.split('0b')[1]
        if len(i_2) < N:
            N_i = (N - len(i_2))
            N_0 = '0' * N_i
            i_2 = N_0 + i_2
        a_find = i_2.find('1')
        b_find = i_2.find('1',a_find + 1)
        c_find = i_2.find('1',b_find + 1)
        a = dlist[a_find]
        b = dlist[b_find]
        c = dlist[c_find]
        if a < b + c:
            sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
dlist = list(map(int, input().split()))

sum = 0
N_2 = 2 ** N
for i in range(N_2):
    if bin(i).count('1') == 3:
        bin_i = bin(i)
        i_2 = bin_i.split('0b')[1]
        if len(i_2) < N:
            N_i = (N - len(i_2))
            N_0 = '0' * N_i
            i_2 = N_0 + i_2
        a_find = i_2.find('1')
        b_find = i_2.find('1',a_find + 1)
        c_find = i_2.find('1',b_find + 1)
        a = dlist[a_find]
        b = dlist[b_find]
        c = dlist[c_find]
        if a < b + c and b < c + a and c < a + b:
            sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=input().split()
#a<b+c
#b<c+a
#c<a+b
#i<j<k
num=0
for i in range(N):
  for j in range(N):
    for k in range(N):
      if i<j and j<k:
        if int(S[i])<int(S[j])+int(S[k]) and int(S[j])<int(S[k])+int(S[i]) and int(S[k])<int(S[i])+int(S[j]):
          num=num+1
      else:
        continue
print(num)

Submission status: Time Limit Exceeded

Solution code:
import bisect
def main():
    N = int(input())
    L = list(map(int,input().split()))
    L.sort()
    Lind = []
    count = 0
    for i in reversed(range(2,N)):
        for j in reversed(range(1,i)):
            if L[i] < 2*L[j]:
                Lind.append([i,j])
    for l in Lind:
        cind = bisect.bisect_left(L,L[l[0]]-L[l[1]])
        for k in range(cind,l[1]):
            if L[l[0]]<L[l[1]]+L[k]:
                count += 1
    print(count)
main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
def main():
    N = int(input())
    L = sorted(list(map(int,input().split())))
    Lind = []
    count = 0
    for i in reversed(range(2,N)):
        for j in reversed(range(1,i)):
            if L[i] < 2*L[j]:
                Lind.append([i,j])
    for l in Lind:
        cind = bisect.bisect_right(L,L[l[0]]-L[l[1]])
        for k in range(cind,l[1]):
            if L[l[0]]<L[l[1]]+L[k]:
                count += 1
    print(count)
main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
def main():
    N = int(input())
    L = sorted(list(map(int,input().split())))
    Lind = []
    count = 0
    for i in reversed(range(2,N)):
        for j in reversed(range(1,i)):
            cind = bisect.bisect_right(L,L[i]-L[j])
            if cind != N-1:
                Lind.append([i,j,cind])
    for l in Lind:
        
        for k in range(cind,l[1]):
            if L[l[0]]<L[l[1]]+L[k]:
                count += 1
    print(count)
main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
def main():
    N = int(input())
    L = list(map(int,input().split()))
    L = sorted(L)
    count = 0
    for i in reversed(range(2,N)):
        for j in reversed(range(1,i)):
            cind = bisect.bisect_right(L,L[i]-L[j])
            
            for k in range(cind,j):
                if L[i]<L[j]+L[k]:
                    count += 1
    print(count)
main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    L = list(map(int,input().split()))
    count = 0
    for i in range(N-2):
        for j in range(i+1,N-1):
            for k in range(j+1,N):
            
                if (L[i]<L[j]+L[k]) and (L[j] < L[i]+L[k]) and (L[k] < L[j]+L[i]):
                    count += 1
    print(count)
main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort()
ans = 0
right = 0
# print(l_list)
for i in range(n-2):
    for j in range(i+1,n-1):
        right = bisect.bisect_left(l_list[j+1:],l_list[i]+l_list[j])
        # print(right)
        ans += right
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l_list = list(map(int,input().split()))
l_list.sort(reverse=True)
temp_sum = 0
check_break = 0
for i in range(n-2):
    check_break = 0
    for j in range(i+1,n-1):
        if check_break == 1:
            break
        # print(temp_sum)
        for k in range(j+1,n):
            if l_list[k] > l_list[i] - l_list[j]:
                temp_sum += 1
            elif k == j+1:
                check_break = 1
                break
            else:
                break


print(temp_sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l_list = list(map(int,input().split()))
temp_sum = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        
        # print(temp_sum)
        for k in range(j+1,n):
            if l_list[i] < l_list[j] + l_list[k] and l_list[j] < l_list[k] + l_list[i] and l_list[k] < l_list[j] + l_list[i]:
                temp_sum += 1


print(temp_sum)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()

num_triangles = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        idx = bisect_left(a=L, x=L[i]+L[j], lo=j+1)
        num_triangles += idx-j-1
print(num_triangles)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))

L.sort()

num_triangles = 0
for i in range(N-2): # stick 1
    for j in range(i+1, N-1): # stick 2; must be larger than 1
        # if a<b then we require c<b+a
        idx = bisect_left(a=L, x=L[i]+L[j], lo=j+1) # find the index at which c<b+a
        num_triangles += idx-(j+1) # c can be, at minimum, b=c
print(num_triangles)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = list(map(int, input().split()))
L.sort()
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        left = j
        right = N
        v = L[i] + L[j]
        while right - left > 1:
            mid = (left + right) // 2
            if L[mid] < v:
                left = mid
            else:
                right = mid
        cnt += left - j
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())
L = [int(i) for i in input().split()]

L.sort()

num_triangles = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        idx = bisect_left(a=L, x=L[i]+L[j], lo=j+1)        
        num_triangles += idx-(j+1) 
print(num_triangles)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split(" ")))

L.sort()

num_triangles = 0
for i in range(N-2): # stick 1
    for j in range(i+1, N-1): # stick 2; must be larger than 1
        # if a<b then we require c<b+a
        idx = bisect_left(a=L, x=L[i]+L[j], lo=j+1) # find the index at which c<b+a
        num_triangles += max(0, idx-(j+1)) # c can be, at minimum, b=c
print(num_triangles)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())
L = [int(i) for i in input().split()]

L.sort()

num_triangles = 0
for i in range(N-2): # stick 1
    for j in range(i+1, N-1): # stick 2; must be larger than 1
        # if a<b then we require c<b+a
        idx = bisect_left(a=L, x=L[i]+L[j]) # find the index at which c<b+a
        num_triangles += max(0, idx-(j+1)) # c can be, at minimum, b=c
print(num_triangles)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split(" ")))

L.sort()

num_triangles = 0
for i in range(N-2): # stick 1
    for j in range(i+1, N-1): # stick 2; must be larger than 1
        # if a<b then we require c<b+a
        idx = bisect_left(a=L, x=L[i]+L[j]) # find the index at which c<b+a
        num_triangles += max(0, idx-(j+1)) # c can be, at minimum, b=c
print(num_triangles)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        left = j
        right = N
        v = L[i] + L[j]
        while right - left > 1:
            mid = (left + right) // 2
            if L[mid] < v:
                left = mid
            else:
                right = mid
        cnt += left - j
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split(" ")))

L.sort()

num_triangles = 0
for i in range(N): # stick 1
    for j in range(i+1, N): # stick 2; must be larger than 1
        # if a<b then we require c<b+a
        idx = bisect_left(a=L, x=L[i]+L[j]) # find the index at which c<b+a
        num_triangles += max(0, idx-(j+1)) # c can be, at minimum, b=c
print(num_triangles)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N = int(input())
L = list(map(int, input().split(" ")))

def satisfy_conditions(L):
    a = L[0]
    b = L[1]
    c = L[2]
    if a < b + c and b < c + a and c < a + b:
        return True
    else:
        return False

num_triangles = 0

stick_combos = combinations(L, 3)
for stick_combo in stick_combos:
    if satisfy_conditions(stick_combo):
        num_triangles += 1
print(num_triangles)

Submission status: Time Limit Exceeded

Solution code:
import itertools

total = input()
edges = sorted(map(int, input().split()))

count = 0

for c in itertools.combinations(edges, 3):
    if c[0] < c[1] + c[2]:
        if c[1] < c[0] + c[2]:
            if c[2] < c[0] + c[1]:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

total = input()
edges = map(int, input().split())

count = 0

for c in itertools.combinations(edges, 3):
    if c[0] < c[1] + c[2]:
        if c[1] < c[0] + c[2]:
            if c[2] < c[0] + c[1]:
                count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

total = input()
edges = map(int, input().split())

count = 0

for c in itertools.combinations(edges, 3):
    if c[0] < c[1] + c[2] and c[1] < c[0] + c[2] and c[2] < c[0] + c[1]:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def bin_search(list,value,low,high):
    middle = int((low + high) / 2)
    if low > high :
        return 'nothing'
    else:
        if list[middle] == value:
            return middle
        elif list[middle] > value:
            return bin_search(list,value,low,middle - 1)
        elif list[middle] < value:
            return bin_search(list,value,middle + 1,high)


n = int(input())
list = [int(x) for x in input().split()]
list.sort()
count = 0
for i in range(n - 1):
    for j in range(i,n-1):
        a = list[n - i - 1]
        b = list[n - j - 2]
        c = a - b + 1
        while b > c :
         if bin_search(list,c,0,len(list)-1) != 'nothing':
             count += 1
         c += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list = [int(x) for x in input().split()]
ans = []
count = 0
for  i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if (list[i] >= list[j] + list[k]) or (list[j] >= list[i] + list[k]) or (list[k] >= list[i] + list[j]):
                continue
            else:
                count+= 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list = [int(x) for x in input().split()]
count = 0
for  i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if not((list[i] >= list[j] + list[k]) or (list[j] >= list[i] + list[k]) or (list[k] >= list[i] + list[j])):
                count+= 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list = [int(x) for x in input().split()]
ans = []
count = 0
for  i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if (list[i] < list[j] + list[k]) and (list[j] < list[i] + list[k]) and (list[k] < list[i] + list[j]):
                count+= 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
L = list(map(int,input().split()))
cnt = 0
for i in itertools.combinations(L, 3):
  if i[0] < i[1]+i[2] and i[1] < i[0]+i[2] and i[2] < i[0]+i[1]:
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def triangleChecker(combi):
    a, b, c = combi
    if a >= b + c :
        return False
    else:
        if b >= c + a:
            return False
        else :
            if c >= a + b:
                return False
            else :
                return True

N = int(input())
numbers = [int(i) for i in input().split()]

combinations = list(itertools.combinations(numbers, 3))

counter = 0
for combi in combinations:
    if triangleChecker(combi):
        # print(combi)
        counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

#in_N = [int(i) for i in input().split()];
in_n = int(input());
#in_S = str(input());
in_l = [int(i) for i in input().split()];
#S = [str(s) for s in in_S]
#print(in_N);
#print(in_S);
#print(S);
#calc
total = 0;
tmp_n = in_l;
#print(tmp_n);
for i in range(in_n):
    for j in range(i+1,in_n):
        for k in range(j+1,in_n):
            #print(k);
            if(tmp_n[i] < tmp_n[j] + tmp_n[k]):
                if(tmp_n[j] < tmp_n[k] + tmp_n[i]):
                    if(tmp_n[k] < tmp_n[i] + tmp_n[j]):
                        total += 1;

print(total);
#        total +=1;
#    for j in range(len(in_d)-1):
        #print(i);
        #print(j);
#        if(i+j+1 == len(in_d)):break;
#        total += in_d[i]*in_d[i+j+1];
 
#print(in_N - total);

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = sorted(list(map(int,input().split())))
count = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        ab = lis[i]+lis[j]
        if ab>lis[n-1]:
            count += n-1-j
        elif ab<=lis[j+1]:
            next
        else:
            l = j+1
            r = n-1
            m = int((r+l)/2)
            while r-l>1:
                if ab>lis[m]:
                    l = m
                else:
                    r = m
                m = int((r+l)/2)
            count += l-j
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = sorted(list(map(int,input().split())))
count = 0
for i in range(n-2):
    a = i
    for j in range(1,n-1-i):
        c = n-j
        m = int((c+a)/2)
        l = i
        r = c
        if lis[a]+lis[c-1]>lis[c]:
            while r-l>1:
                if lis[m]+lis[a]>lis[c]:
                    r = m
                else:
                    l = m
                m = int((r+l)/2)
            count += c-r
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
count=0
for i in range(N-1):
    for j in range(i+1,N):
        right=len(L)
        left=j
        while right-left>1:
            mid=(right+left)//2
            if L[i]+L[j]>L[mid]:
                left=mid
            else:
                right=mid
        count=count+left-j
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
l_list = input().split()

l_list.sort()

num_of_triangle = 0
old_xyz = []

for i in range(n):
	for j in range(i+1, n):
		for k in range(j+1, n):
			len_of_other_two_sides = 0
			x = int(l_list[i])
			y = int(l_list[j])
			z = int(l_list[k])
			xyz = [x, y, z]
			if old_xyz != xyz:
				max_num_index = xyz.index(max(xyz))
				for l in range(len(xyz)):
					if l != max_num_index:
						len_of_other_two_sides += xyz[l]
				if xyz[max_num_index] < len_of_other_two_sides:
					num_of_triangle += 1

print(num_of_triangle)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
l_list = input().split()
l_list_i = [int(s) for s in l_list]

r = 3
ncr_list = list(itertools.combinations(l_list_i, r))

ncr_list = list(set(ncr_list))

num_of_triangle = 0

for ncr in ncr_list:
	len_of_other_two_sides = 0
	max_index = ncr.index(max(ncr))
	for i in range(len(ncr)):
		if i != max_index:
			len_of_other_two_sides += ncr[i]
	if ncr[max_index] < len_of_other_two_sides:
		num_of_triangle += 1

print(num_of_triangle)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
l_list = input().split()
l_list_i = [int(s) for s in l_list]

r = 3
ncr_list = list(itertools.combinations(l_list_i, r))

num_of_triangle = 0

for ncr in ncr_list:
	len_of_other_two_sides = 0
	max_index = ncr.index(max(ncr))
	for i in range(len(ncr)):
		if i != max_index:
			len_of_other_two_sides += ncr[i]
	if ncr[max_index] < len_of_other_two_sides:
		num_of_triangle += 1

print(num_of_triangle)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = sorted(map(int, input().split()))

counter = 0

for i in range(N):
    a = L[i]
    for j in range(i+1, N):
        b = L[j]
        for k in range(j+1, N):
            c = L[k]
            if c >= a + b:
                break
            elif b < c + a and a < b + c:
                counter += 1

print(counter)