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:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
L = LI()
L.sort()

ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1,N-1):
        b = L[j]
        for k in range(j+1,N):
            c = L[k]
            if a != b and b != c and c != a and a+b > c:
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math
import itertools

N = int(input())

line = list(map(int, input().split(" ")))
line_set = set(line)
dic = {}

for num in line_set:
    cnt = line.count(num)
    dic[num] = cnt
    
pattern = list(itertools.combinations(line_set, 3))

sum_ = 0
for lis in pattern:
    a, b, c = lis
    if a + b > c and b + c > a and a + c > b:
        sum_ += dic[a]*dic[b]*dic[c]
print(sum_)

Submission status: Accepted

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

l = set(L)
di = {}
for c in l:
    di[c] = L.count(c)

cnt = 0
L = list(set(L))
L = sorted(L)


if N >= 3:
    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]:
                    cnt += di[L[i]]*di[L[j]]*di[L[k]]
    print(cnt)

else:
    print(0)

Submission status: Accepted

Solution code:
import itertools

def has_duplicates(seq):
    return len(seq) != len(set(seq))


n=int(input())
l=[int(x) for x in input().split()]
l.sort()

ans = 0

for kumi in itertools.combinations(l, 3):
    if has_duplicates(kumi):
        pass
    else:
        if kumi[0]+kumi[1] > kumi[2] and kumi[2] - kumi[0] < kumi[1]:
            ans +=1
    
print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
L = [int(i) for i in input().split()]
count = 0
c = itertools.combinations([i for i in range(N)], 3)
for i, j, k in c:
  if not (L[i] == L[j] or L[j] == L[k] or L[k] == L[i]):
    a, b, c = sorted([L[i], L[j], L[k]])
    if a + b > c:
      count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

total = 0

for i in range(n-2):
    for j in range(i+1, n-1):
        if l[i] == l[j]: continue
        w = l[i] + l[j]
        cnt = 0
        for k in range(j+1, n):
            if l[j] == l[k]: continue
            if l[k] >= w: break
            cnt += 1
        total += cnt

print(total)

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 len({l[i], l[j], l[k]}) == 3 and max(l[i], l[j], l[k]) * 2 < l[i] + l[j] + l[k]:
				ans += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
L = [int(i) for i in input().split()]
#L = list(set(L))
L.sort()
#print(L)
ans = 0

for i, l1 in enumerate(L):
    for j, l2 in enumerate(L[i+1:]):
        if l1 == l2:
            continue
        for l3 in L[i+j+2:]:
            #print(i,j,L[j+1:])
            #print(l1, l2, l3)
            if l2 == l3:
                continue
            elif l3 - l2 < l1 < l3 + l2:
                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):
            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:
N = int(input())
L = list(map(int, input().split()))

ans = 0
if len(L) < 3:
    print(ans)
    exit()

for i in range(0, N-2):
    Li = L[i]
    for j in range(i+1,N-1):
        Lj = L[j]
        if Li == Lj:
            continue
        for k in range(j+1,N):
            Lk = L[k]
            if Li == Lk or Lj == Lk:
                continue
            Llist = [Li, Lj , Lk]
            Llist.sort()
            if Llist[0] + Llist[1] <= Llist[2]:
                continue
            ans += 1

print(ans)

Submission status: Accepted

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

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] or  L[j] ==  L[k] or L[k] == L[i]:
                continue
            # print(L[i], L[j], L[k])
            if L[i] + L[j] > L[k]:
                count += 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
l.sort()
if n <= 2:
    print(0)
    exit()

cnt = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        if l[i] != l[j]:
            for k in l[j+1:]:
                if k < l[i]+l[j] and k != l[i] and k != l[j]:
                    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
s = map(int,input().split())
cnt = 0
t = sorted(s)
 
for i in range(n):
    a = t[i]
    for j in range(i+1, n):
        b = t[j]
        for k in range(j+1, n):
            c = a + b
            if t[k] < (a+b) and a < (b+t[k]) and b < (a+t[k]) and a != b and b != t[k] and a != t[k]:
                cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
L = [int(l) for l in 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 a+b>c and b+c>a and c+a>b and a != b and b!= c and c!= a:
                counter += 1
print(counter)

Submission status: Accepted

Solution code:
n = int(input())
num_list = list(map(int, input().split()))
count = 0
b=0
c=0
a=0


for i in num_list:
  a = i
  for j in num_list:
    if j != a:
      b = j
      for k in num_list:
        if k != a and k != b : 
          c = k    
          if a + b > c and b + c > a and a + c > b :
            count = count + 1
        else:
          continue
    else:
      continue 
      
print(int(count/6))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
r=[]
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] or l[i]==l[j] or l[j]==l[k] or l[i]==l[k]:
        continue
      a=l[i]+l[j]
      b=l[j]+l[k]
      c=l[i]+l[k]
      if a>l[k] and b>l[i] and c>l[j]:
        r.append([l[i],l[j],l[k]])
print(len(r))

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):
    if L[i]==L[j]:
      continue
    for k in range(j+1,N):
      if L[k]==L[i] or L[k]==L[j]:
        continue
      A = sorted([L[i],L[j],L[k]])
      if A[0]+A[1]>A[2]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
print(sum(i!=j!=k!=i and j+k>i and k+i>j and i+j>k for i in l for j in l for k in l)//6)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
L = list(map(int, input().split()))
if N < 3:
    print(0)
    exit()
cnt = 0
Ns = [i for i in range(len(L))]
com = itertools.combinations(Ns, 3)
# print(list(com))
for ns in itertools.combinations(Ns, 3):
    # print(ns)
    if (L[ns[0]] != L[ns[1]] and L[ns[1]] != L[ns[2]] and L[ns[2]] != L[ns[0]]) and (L[ns[0]] + L[ns[1]] > L[ns[2]]) and (L[ns[1]] + L[ns[2]] > L[ns[0]]) and (L[ns[2]] + L[ns[0]] > L[ns[1]]):
        # print(L[ns[0]], L[ns[1]], L[ns[2]])
        cnt += 1

print(cnt)

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

print(count)

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):
            a = L[i]
            b = L[j]
            c = L[k]
            if a == b or b == c or c == a:
                continue
            if a+b>c and b+c>a and c+a>b:
                ans += 1
                # print("i:j:k:{},{},{}".format(i+1,j+1,k+1))
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
# n=5
L=list(map(int,input().split()))
# L=[4,4,9,7,5]


cnt=0

for i in range(n):
    for j in range(n):
        for k in range(n):
            if L[i]<L[j]:
                if L[j]<L[k]:
                    if i!=j:
                        if i!=k:
                            if j!=k:
                                if L[k]<L[i]+L[j]:
                                    cnt+=1

print(cnt)

Submission status: Accepted

Solution code:
def findNumberOfTriangles(arr, n): 
      
    # Count of triangles 
    count = 0
      
    # The three loops select three 
    # different values from array 
    for i in range(n): 
        for j in range(i + 1, n): 
              
            # The innermost loop checks for 
            # the triangle property 
            for k in range(j + 1, n): 
                if(arr[i]!=arr[j] and arr[j]!=arr[k] and arr[i]!=arr[k]):
                    
                # Sum of two sides is greater 
                # than the third 
                    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 
  
# Driver code 

n=int(input())
arr = list(map(int,input().split()))
size = len(arr) 
  
print(findNumberOfTriangles(arr, size))

Submission status: Accepted

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

ans = 0
# リストの頭からループし、1つ目の値を保持する
for i in range(len(Ls)- 2):
    first_side = Ls[i]

    for j in range(i + 1, len(Ls)):
        second_side = Ls[j]
        # 2つ目の値が1つ目と異なる値なら
        if first_side != second_side:
            #2つ目の値以降のリストの中に含まれる、条件を満たす数を数える
            ans = ans + len([i for i in Ls[j+1:] if i != first_side and i != second_side and first_side + second_side > i and first_side + i > second_side and second_side + i > first_side])

print(ans)

Submission status: Accepted

Solution code:
import collections
import statistics as st
N = int(input())
L = list(map(int,input().split()))
L.sort()
M = list(set(L))
M.sort()
C = collections.Counter(L)

ans = 0

for i in range(len(M)):
    for j in range(len(M)):
        for k in range(len(M)):
            if M[i] == M[j] or M[i] == M[k] or M[j] == M[k]:
                continue
            else:
                if M[i]<M[j]<M[k] and M[i]+M[j] > M[k] and M[i]+M[k] > M[j] and M[j]+M[k] > M[i]:
                    ans += list(C.values())[i]*list(C.values())[j]*list(C.values())[k]


print(ans)

Submission status: Accepted

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

ans = 0
if N < 3:
    ans = 0
else:
    for i in range(N):
        for j in range(i,N):
            for k in range(j,N):
                if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                    if S[i] + S[j] > S[k] and S[j] + S[k] > S[i] and S[k] + S[i] > S[j]:
                        ans += 1
print(ans)

Submission status: Accepted

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

FF= []

count =0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            a = L[i]
            b = L[j]
            c = L[k]
            if a != b and b != c and a != c and a + b > c and b + c > a and c + a > b:
                    FF.append(str(a) + str(b) + str(c))
print(len(FF))

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
counter = 0
for i in range(len(L)-2):
    for j in range(i+1,len(L)-1):
        if L[i] == L[j]:
            continue
        for k in range(j+1,len(L)):
            if L[i] == L[k]:
                continue
            elif L[j] == L[k]:
                continue
            if L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[i]+L[k]>L[j]:
                counter += 1
print(counter)

Submission status: Accepted

Solution code:
n = int(input())

list1 = input().split()
list2 = []
for i in range(0,len(list1)):
    list2.append(int(list1[i]))
count = 0
if(n<=2):
    count = 0
for i in range(n):
    if(i+2==len(list2)):
        continue
    for j in range(i+1,n):
        if(i+1==len(list2)):
            continue
        for k in range(j+1,n):
            if(list2[i] != list2[j] and list2[i] != list2[k] and list2[j] != list2[k]):
                ma = max(list2[i],list2[j],list2[k])
                mi = min(list2[i],list2[j],list2[k])
                tyuukann = list2[i]+list2[j]+list2[k]-ma-mi
                if(ma<mi+tyuukann):
                    count = count + 1

print(count)

Submission status: Accepted

Solution code:
N = int(input())
L_list = list(map(int,input().split()))
count = 0
a = 1

for j, b in enumerate(L_list):
    if b == 1:
        continue
    for k, c in enumerate(L_list):
        if c == 1 or c == b:
            continue
        elif (a+b) > c and (b+c) > a and (c+a) > b and a < b < c:
            count += 1


for i, a in enumerate(L_list):
    if a == 1:
        continue
    for j, b in enumerate(L_list):
        if b == 1 or b == a:
            continue
        for k, c in enumerate(L_list):
            if c == 1 or c == b or c == a:
                continue
            elif (a+b) > c and (b+c) > a and (c+a) > b and a < b < c:
                count += 1

print(count)

Submission status: Accepted

Solution code:
import numpy as np
N = input()
bars = list(map(int, input().split(" ")))

length = len(bars)

def check_triangle(a, b, c):
    if a == b or b == c or c == a:
        return 0
    if ((a + b) > c) and ((b + c) > a) and ((c + a) > b):
        return 1
    else:
        return 0


count = 0
for i, li in enumerate(bars):
    for k in range(i+1, length):
        res = np.sum([check_triangle(bars[i], bars[k], bars[j]) for j in range(k+1, length)])
        count += int(res)
print(count)

Submission status: Accepted

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

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

L = sorted(L)
# print(L)
c = collections.Counter(L)
l = list(c)
# print(c.keys())
# print(len(c))
# print(l)
#print(c.len)
#print("4nokosuu",c[l[2]])

if N < 3:
    print(0)
else:
    cnt = 0
    tmp_cnt = 0
    i_tmp_cnt = 0
    for i in range(len(c)-1):
        j=i+1
        k=i+2
        while j < (len(c)-1):
            while k < (len(c)):
                if l[k] - l[i] < l[j] and l[j] < l[k] + l[i]:
                    # print("cnt++",l[i],l[j],l[k])
                    tmp_cnt += 1 * c[l[k]]
                    # print("c[",l[k],"]=",c[l[k]]," tmp_cnt=",tmp_cnt)
                    k += 1
                else:
                    # print("no",l[i],l[j],l[k])
                    k += 1
            # print("tmp_cnt!!",tmp_cnt)
            tmp_cnt = tmp_cnt * c[l[j]]
            # print("tmp_cnt * c[l[j]]=",tmp_cnt)
            # cnt += tmp_cnt * c[l[i]] * c[l[j]]
            # print("j,k finish.")
            j += 1
            k = j + 1
            i_tmp_cnt += tmp_cnt
            tmp_cnt = 0
            # print("i_tmp_cnt=",i_tmp_cnt)
            # print("\n")
        #cnt += tmp_cnt * c[l[i]] * c[l[j-1]] * c[l[k-1]]
        # print("c[",l[i],"]=",c[l[i]])
        cnt += i_tmp_cnt * c[l[i]]
        tmp_cnt = 0
        i_tmp_cnt = 0
        # print("i finish. cnt=",cnt)
        # print("\n")
        

    print(cnt)

Submission status: Accepted

Solution code:
import itertools

n, *l = map(int, open(0).read().split())

def f(a,b,c):
    return a+b>c and b+c>a and a+c>b


a=0
for t in itertools.combinations(range(n), 3):
    s=[l[i] for i in t]
    if len(s) != len(set(s)):
        continue
    if f(*s):
        a+=1

print(a)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
c=0
if n<3:
    print(0)
else:
    for i in range(0,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[k]==l[i] or l[k]==l[j]:
                    continue
                if l[k]+l[i]>l[j] and l[i]+l[j]>l[k] and l[k]+l[j]>l[i]:
                    c+=1
    print(c)

Submission status: Accepted

Solution code:
input_n = input()
n = int(input_n)

input_L = input()
L = str(input_L)

listL = L.split(' ')

max = 0
tmp1 = 0
tmp2 = 0
result = 0

for i in range(n - 2):
    for j in range(i + 1, n - 1):
        for k in range(j + 1, n):
            if int(listL[i]) != int(listL[j]) and int(listL[j]) != int(listL[k]) and int(listL[k]) != int(listL[i]):
                if int(listL[i]) > int(listL[j]):
                    max = int(listL[i])
                    tmp1 = int(listL[j])
                else :
                    max = int(listL[j])
                    tmp1 = int(listL[i])
                if int(listL[k]) > max:
                    tmp2 = max
                    max = int(listL[k])
                else :
                    tmp2 = int(listL[k])
                if max < (tmp1 + tmp2):
                    result += 1

print(str(result))

Submission status: Accepted

Solution code:
import itertools

#import length
S = input()
#import list
l = input().split()

i = 0
if len(l) < 3:
    print('0')
else:

    for v in itertools.combinations(l, 3):
        #print(v)
        if v[0] != v[1] and v[1] != v[2] and v[0] != v[2]:
        #if v[1] + v[2] = 3:
            if int(v[0]) + int(v[1]) > int(v[2]) and int(v[1]) + int(v[2]) > int(v[0]) and int(v[0]) + int(v[2]) > int(v[1]) :
                i = i +1

    print(i)

Submission status: Accepted

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

count = 0
subL = []

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] and L[k] != L[i]):
                if L[i] > L[j]:
                    max = L[i]
                else: max = L[j]
                if L[k] > max:
                    max = L[k]

                if L[i] < L[j]:
                    min =  L[i]
                else: min = L[j]
                if L[k] < min:
                    min = L[k]

                if min < L[i] < max:
                    mid = L[i]
                if min < L[j] < max:
                    mid = L[j]
                if min < L[k] < max:
                    mid = L[k]

                if max < mid + min:
                    count += 1

print(count)

Submission status: Accepted

Solution code:
N = int(input())
num_list = list(map(int, input().split()))
l = sorted(num_list)

count = 0
for i in range(N):
    for j in range(N):
        for k in range(N):
            if i < j and j < k:
                if l[i]<l[j] and l[j]<l[k] and l[i]+l[j]>l[k]:
                    count += 1
print(count)

Submission status: Accepted

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

count = 0

for i in L:
    for j in L:
        for k in L:
            if i < j < k:
                if (i + j) > k:
                    if (i + k) > j:
                        if (k + j) > i:
                            count += 1
print(count)

Submission status: Accepted

Solution code:
n=int(input(""))
lisl=input("").split(" ")
l=[]
for i in lisl:
    l+=[int(i)]
l.sort()
t=0
for i in range(2,n):
    for ii in range(1,i):
        for iii in range(ii):
            if(l[i]<l[ii]+l[iii] and l[i]!=l[ii] and l[ii]!=l[iii]):
                t+=1
print(t)

Submission status: Accepted

Solution code:
n = int(input())
s = [int(x) for x in input().split()]
ans = 0

for i in range(len(s)-2):
  a = s[i]
  for j in range(i + 1, len(s)-1):
    b = s[j]
    if a == b:
      continue
    for k in range(j + 1, len(s)):
      c = s[k]

      if a == c or b == c:
        continue
      if a > b and a > c and a < b + c:
        ans += 1
      elif b > c and b > a and b < c + a:
        ans += 1
      elif c > a and c > b and c < a + b:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
l = LI()
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] and l[j] != l[k] and l[k] != l[i]:
                L = max(l[i], l[j], l[k])
                s = l[i] + l[j] + l[k]
                if s - L > L:
                    ans += 1
print(ans)

Submission status: Accepted

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

l.sort()

count = 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

			if l[i]+l[j] > l[k]:
				count += 1

print(count)

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math
N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
e = 0

for i in range(len(L)):
    s = 0
    s = L[i]
    for j, b in enumerate(L[i+1:]):
        if L[i] == b:
            continue
        g = s + b
        for w, n in enumerate(L[i+j+2:]):
            if n == b or n == L[i]:
                continue

            a = g - n
            if a > 0:
                e += 1

print(e)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
L= list(map(int,input().split()))
#LList = (list(itertools.permutations(L,3)))
cnt = 0

for i in range(N):
    for j in range(i+1,N):
        for n in range(j+1,N):
            if (L[i] < L[j] + L[n]):
                if (L[j] < L[i] + L[n]):
                    if (L[n] < L[i] + L[j]):
                        if(L[n] != L[i]):
                            if(L[j] != L[i]):
                                if(L[n] != L[j]):
                                    cnt += 1
# for i in range(len(LList)):
#     if (LList[i][0] < LList[i][1] + LList[i][2]):
#         if (LList[i][1] < LList[i][0] + LList[i][2]) :
#             if (LList[i][2] < LList[i][0] + LList[i][1]) :
#                 if LList[i][0] != LList[i][1] :
#                     if LList[i][0] != LList[i][2] :
#                         if LList[i][1] != LList[i][2]:
#                             print(LList[i])
#                             cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n=int(input())
s=[int(i) for i in input().split()]
s.sort()
count=0
for x in range(n-2):
  len_one=s[x]
  for f in range(n-x-1):
    len_two=s[f+x+1]
    if len_two==len_one:
      pass
    else:
      for z in range(n-x-f-2):
        len_three=s[z+x+f+2]
        if len_three==len_two or len_three==len_one:
          pass
        else:
          if (len_one+len_two)>len_three:
            count+=1
          else:
            pass
print(count)

Submission status: Accepted

Solution code:
import sys


def read_input_line():
    return sys.stdin.readline().strip()


def task(N: int, L: list):
    edges = sorted(L)
    l = len(edges)
    if l < 3:
        return 0
    count = 0
    triples = []
    i = 0
    while i < l:
        j = i + 1
        while j < l:
            if edges[j] != edges[i]:
                _ = [edge for edge in edges[j+1:] if edge != edges[j] and edge < edges[i] + edges[j]]
                triples.extend([[edges[i], edges[j], edge] for edge in _])
                count += len(_)
            j += 1
        i += 1
    return count


def main():
    N = int(read_input_line())
    L = [int(s) for s in read_input_line().split(' ')]
    result = task(N, L)
    print(result)


main()

Submission status: Accepted

Solution code:
import itertools
x = int(input())
count = 0
c=list(map(int, input().split()))
c_list = list(itertools.combinations_with_replacement(c, 3))
for i in range(len(c_list)):
  if c_list[i][0] != c_list[i][1] and c_list[i][1]!= c_list[i][2] and c_list[i][2] != c_list[i][0]:
    if c_list[i][0] + c_list[i][1]  > c_list[i][2] and c_list[i][1] + c_list[i][2] > c_list[i][0] and c_list[i][0] + c_list[i][2] > c_list[i][1]:
      count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import sys

N = int(input())
if N < 3:
  print(0)
  sys.exit()

lis = list(map(int, input().split()))
count = 0
for tri in itertools.combinations(lis, 3):
  if tri[0] != tri[1] and tri[1] != tri[2] and tri[2] != tri[0]:
    if tri[0]+tri[1] > tri[2] and tri[1]+tri[2] > tri[0] and tri[2]+tri[0] > tri[1]:
      count += 1
print(count)

Submission status: Accepted

Solution code:
import itertools
num = int(input())
lis = list(map(int,input().split()))
tri = list(itertools.combinations(lis,3))
count = 0

for i in range(len(tri)):
    a = tri[i][0]
    b = tri[i][1]
    c = tri[i][2]
    if len(tri[i]) == len(set(tri[i])):
        if a+b > c and b+c > a and a+c > b:
            count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
import itertools
import sys
input = sys.stdin.readline


def check_tri(a, b, c):
    if a + b > c and b + c > a and c + a > b:
        return True
    else:
        return False


def print_ans(lr):
    """Test Case
    >>> print_ans([4, 4, 9, 7, 5])
    5
    >>> print_ans([4, 5, 4, 3, 3, 5])
    8
    >>> print_ans([9, 4, 6, 1, 9, 6, 10, 6, 6, 8])
    39
    >>> print_ans([1,1])
    0
    """
    ans = 0
    c = collections.Counter(lr)
    target = itertools.combinations(list(c.keys()), 3)
    for t in target:
        if check_tri(t[0], t[1], t[2]):
            tmp = (c[t[0]] * c[t[1]] * c[t[2]])
            ans += tmp
    print(ans)


if __name__ == '__main__':
    N = int(input().rstrip())
    lr = list(map(int, input().rstrip().split()))
    print_ans(lr)

Submission status: Accepted

Solution code:
n=int(input())
long=0
middle=0
short=0
count=0
pre=0
a=0
b=0
c=0
list=[]
list=input().split()
for i in range(len(list)):
  list[i]=int(list[i])

for i in range(n-2):
 for s in range(i+1,n-1):
  for t in range(s+1,n):
   if list[i]!=list[s] and list[s]!=list[t] and list[i]!=list[t]:
    if list[i]>list[s] and list[i]>list[t]:
     long=i
     if list[s]>list[t]:
      middle=s
      short=t
     else:
      middle=t
      short=s
#
    if list[s]>list[i] and list[s]>list[t]:
     long=s
     if list[i]>list[t]:
      middle=i
      short=t
     else:
      middle=t
      short=i
#
    if list[t]>list[s] and list[t]>list[i]:
     long=t
     if list[s]>list[i]:
      middle=s
      short=i
     else:
      middle=i
      short=s
    if int(list[long])<int(list[middle])+int(list[short]):
     count+=1
print(count)

Submission status: Accepted

Solution code:
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[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]):
                count += 1
            else:
                continue
print(count)

Submission status: Accepted

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

cnt = 0

for a in range(len(L)-2):
    for b in range(a+1, len(L)-1):
        if L[a] != L[b]:
            for c in range(b+1, len(L)):
                if L[b] != L[c]:
                    if L[a] +L[b] > L[c]:
                        cnt += 1
            


print(cnt)

Submission status: Accepted

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

print(ans)