Problem:


Score : 200 points

Problem Statement

We have sticks numbered 1, \cdots, N. The length of Stick i (1 \leq i \leq N) is L_i.

In how many ways can we choose three of the sticks with different lengths that can form a triangle?

That is, find the number of triples of integers (i, j, k) (1 \leq i < j < k \leq N) that satisfy both of the following conditions:

L_i, L_j, and L_k are all different.

There exists a triangle whose sides have lengths L_i, L_j, and L_k.

Constraints

1 \leq N \leq 100

1 \leq L_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
L_1 L_2 \cdots L_N

Output

Print the number of ways to choose three of the sticks with different lengths that can form a triangle.

Sample Input 1

5
4 4 9 7 5

Sample Output 1

5

The following five triples (i, j, k) satisfy the conditions: (1, 3, 4), (1, 4, 5), (2, 3, 4), (2, 4, 5), and (3, 4, 5).

Sample Input 2

6
4 5 4 3 3 5

Sample Output 2

8

We have two sticks for each of the lengths 3, 4, and 5. To satisfy the first condition, we have to choose one from each length.

There is a triangle whose sides have lengths 3, 4, and 5, so we have 2 ^ 3 = 8 triples (i, j, k) that satisfy the conditions.

Sample Input 3

10
9 4 6 1 9 6 10 6 6 8

Sample Output 3

39

Sample Input 4

2
1 1

Sample Output 4

0

No triple (i, j, k) satisfies 1 \leq i < j < k \leq N, so we should print 0.



Sample input:
5
4 4 9 7 5


Sample output:
5

Submission status: Accepted

Solution code:
n = int(input())
l = [int(x) for x in input().split()]
o = 0
for i in range(n - 2):
    # print('i', i)
    for j in range(i + 1, n - 1):
        # print('j',j)
        for k in range(j + 1, n):
            # print('k', k)
            if ((l[i] + l[j]) > l[k]) and ((l[i] + l[k]) > l[j]) and ((l[j] + l[k]) > l[i]) and (l[i] != l[j]) and (l[j] != l[k]) and (l[i] != l[k]):
                o += 1
                # print(i, j, k)
print(o)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans = 0
for i in range(n):
  for j in range(i):
    for k in range(j):
      if (a[k]!=a[j] and a[i]!=a[j] and a[k]+a[j] >a[i]):
        ans+=1
print(ans)

Submission status: Accepted

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

answer = 0

if N < 3:
  print(answer)
  exit()

sticks.sort()

for i in range(N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      if sticks[i] + sticks[j] > sticks[k] and sticks[i] != sticks[j] and sticks[j] != sticks[k]:
        answer += 1
print(answer)

Submission status: Accepted

Solution code:
N = int(input())
L = sorted(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] or L[j] == L[k] or L[i] == L[k]:
        pass
      elif L[i] + L[j] > L[k]:
        ans += 1
      else:
        pass

print(ans)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left, bisect_right


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    count = 0
    for j in range(1, N - 1):
        for i in range(j):
            if L[i] == L[j]:
                break
            count += bisect_left(L, L[i] + L[j]) - bisect_right(L, L[j])
    print(count)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

L = tuple(map(int, input().split()))

if len(L)==n:
  ans = 0
  for i in range(len(L)):
    for j in range(len(L)):
      for k in range(len(L)):
        if i<j and j<k:
          if L[i]==L[j]: continue
          if L[i]==L[k]: continue
          if L[k]==L[j]: continue
          if L[i]+L[j]+L[k] <= max(L[i], L[j], L[k])*2: continue
          ans +=1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      a = l[i]
      b = l[j]
      c = l[k]
      if a == b or b == c or c == a:
        continue
      if l[i] + l[j] > l[k]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            l = [a[i], a[j], a[k]]
            l.sort()
            if(l[0]+l[1] > l[2] and l[0]!=l[1] and l[1]!=l[2]):    ans+=1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
L=list(map(int,input().split()))
ans=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] or L[j]==L[k] or L[i]==L[k]:
                continue
            if L[i]<L[j]+L[k] and L[j]<L[i]+L[k] and L[k]<L[j]+L[i]:
                ans+=1
print(ans)

Submission status: Accepted

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):
            ll=[l[i],l[j],l[k]]
            if len(set(ll))!=3:
                continue
            ll.sort()
            if ll[0]+ll[1]>ll[2] and ll[1]+ll[2]>ll[0] and ll[2]+ll[0]>ll[1]:
                ans+=1           
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      a,b,c = L[i],L[j],L[k]
      if a!=b and a!=c and b!=c and a+b>c:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N = int( input() )
L = list( int(x) for x in input().split() )

ans = 0

for i in range( N - 2 ):
    li = L[i]
    for j in range( i + 1 , N - 1 ):
        lj = L[j]
        if li == lj:
            continue
        else:
            for k in range( j + 1 , N ):
                lk = L[k]
                if lk == li or lk == lj:
                    continue
                else:
                    if max(li,lj,lk) < (li + lj + lk - max(li,lj,lk)):
                        ans += 1
                        #print(li,lj,lk)

print(ans)

Submission status: Accepted

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

N = len(L)
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if abs(L[i] - L[j]) < L[k] and L[k] < L[i] + L[j] and (L[i]-L[j])*(L[j]-L[k])*(L[k]-L[i]) != 0:
                ans += 1
                #print(i+1, j+1, k+1)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
l.sort()
cnt = 0
if n<=2:
    print(0)
    exit()
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] and l[j]!=l[k]:
                if l[i]+l[j]>l[k]:
                    cnt+=1
print(cnt)

Submission status: Accepted

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

L.sort()
ans = 0

for i in range(N-2):
    for j in range(i+1,N-1):
        if L[i]==L[j]:
            continue
        for k in range(j+1,N):
            if L[j]==L[k]:
                continue
            elif L[i]+L[j]<=L[k]:
                break
            else:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split(" ")))
ans=0
for x in range(n):
  for y in range(x+1,n):
    for z in range(y+1,n):
      if a[x]+a[y]>a[z] and a[y]+a[z]>a[x] and a[z]+a[x]>a[y] and a[x]!=a[y] and a[y]!=a[z] and a[x]!=a[z]:
        ans=ans+1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
arr = sorted(list(map(int, input().split())))
res = 0
for i in range(0, n - 2):
	for j in range(i, n - 1):
		for k in range(j, n):
			if arr[i] + arr[j] > arr[k] and arr[i] != arr[j] and arr[j] != arr[k] and arr[i] != arr[k]:
 				res += 1
print(res)

Submission status: Accepted

Solution code:
length = int(input())
ar = list(map(int, input().split()))
t_1, t_2 = 0, 0
res = 0

if length < 3:
    print(0)
else:
    while t_1 < length - 2: 
        t_2 = t_1 + 1

        while t_2 < length:
            for i in range(t_2+1, length):
                x, y, z = ar[t_1], ar[t_2], ar[i]
                if x == y or y == z or x == z:
                    continue
                
                if x + y > z and x + z > y and y + z > x:
                    res += 1
            t_2 += 1

        t_1 += 1

    print(res)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
L = LIST()
L.sort()

ans = 0
for i, j, k in combinations(L, 3):
    if i == j or j == k or k == i: continue
    if k < i+j:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
def trianglecheck(a, b, c):
    if (a + b) > c:
        return True
    return False

a = int(input())
arr = sorted(list(map(int, input().split())))
res = 0
for x in range(a - 2):
    for y in range(x + 1, a - 1):
        for z in range(y + 1, a):
            if arr[x] != arr[y] and arr[y] != arr[z] and arr[z] != arr[x] and trianglecheck(arr[x], arr[y], arr[z]):
                res += 1      
print(res)

Submission status: Accepted

Solution code:
gross = int(input())
numbers = input().split()
numbers = list(map(int,numbers))
numbers = sorted(numbers)
count = 0

for n in range(gross-2):
    for m in range(gross-1):
        for l in range(gross):
            if (n < m) and (m < l):
                if (int(numbers[n]) != (int(numbers[m]))) and (int(numbers[n]) != (int(numbers[l]))) and (int(numbers[m]) != (int(numbers[l]))):
                    if (int(numbers[n]) + int(numbers[m])) > int(numbers[l]):
                        count += 1
print(count)

Submission status: Accepted

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

from itertools import combinations

ans = 0
for k in combinations(li,3):
    k = list(k)
    k.sort()
    if k[0]+k[1]>k[2] and k[0]!=k[1] and k[1]!=k[2]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
count = 0
n = int(input())
arr = list(map(int,input().split()))
arr.sort()
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if arr[i]==arr[j] or arr[i]==arr[k] or arr[j]==arr[k]:
        continue
      if arr[i]+arr[j]>arr[k]:
        count+=1
print(count)

Submission status: Accepted

Solution code:
import itertools
import collections


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

C = list(itertools.combinations(L, 3))
c = len(C)

ans = 0
for i in range(c):
    if C[i][0] == C[i][1] or C[i][1] == C[i][2] or C[i][0] == C[i][2]:
        continue
    else:
        if C[i][2] < C[i][0] + C[i][1]:
            if C[i][1] < C[i][0] + C[i][2]:
                if C[i][0] < C[i][1] + C[i][2]:
                    ans += 1
print(ans)

Submission status: Accepted

Solution code:
ct=0
n=int(input())
li=list(map(int,input().split()))
n=len(li)
val=0
for i in range(n):
    side1=li[i]
    for ii in range(i+1,n):
        side2=li[ii]
        for iii in range(ii+1,n):
            side3=li[iii]
            if side1!=side2 and side2!=side3 and side1!=side3:
                if side3<side2+side1 and side2<side1+side3 and side1<side2+side3:
                    # print(side1,side2,side3,i+1,ii+1,iii+1)
                    val+=1
print(val)

Submission status: Accepted

Solution code:
N = int(input())
L = sorted(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[i] != L[j] and L[j] != L[k]:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
import itertools as it
n = int(input())
l = [int(i) for i in input().split()]
c = it.combinations(l,3)
ans = 0

for i in c:
    if i[0]+i[1]>i[2] and i[1]+i[2]>i[0] and i[2]+i[0]>i[1]:
        if i[0]!= i[1] and i[1]!= i[2] and i[0]!= i[2]:
            ans +=1
print(ans)

Submission status: Accepted

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

count = 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] and L[j] != L[k] and L[k] != L[i]:
                if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j]:
                    count += 1
print(count)

Submission status: Accepted

Solution code:
N = int(input())
L = list(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[i] != L[j] and L[j] != L[k]:
                if L[i] + L[j] > L[k]:
                    ans += 1
print(ans)

Submission status: Accepted

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] \
                    and L[i] != L[j] and L[j] != L[k] and L[k] != L[i]:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
    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] or L[j] == L[k] or L[k] == L[i]:
                    continue
                if max(L[i], L[j], L[k]) * 2 < L[i] + L[j] + L[k]:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
s=list(map(int,input().split()))
num=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if (s[i]!=s[j]) and (s[i]!=s[k]) and (s[j]!=s[k]) and (s[i]+s[j]>s[k]) and (s[i]+s[k]>s[j]) and (s[k]+s[j]>s[i]) :
                num+=1

print(num)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
l = list(map(int, input().split()))

ans = 0
for a, b, c in combinations(l, 3):
    if a == b or b == c or c == a:
        continue
    if a + b > c and b + c > a and a + c > b:
        ans += 1

print(ans)