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

Submission status: Accepted

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]
num_lst = sorted(list(set(lst)), reverse=True)

count = 0

for d in range(len(num_lst)-2):
    for a in range(d+1, len(num_lst)-1):
        for b in range(a+1, len(num_lst)):
            if num_lst[d] < num_lst[a] + num_lst[b]:
                cd = lst.count(num_lst[d])
                ca = lst.count(num_lst[a])
                cb = lst.count(num_lst[b])
                count += 1*cd*ca*cb
print(count)

Submission status: Accepted

Solution code:
import itertools

def checker(l):
    a, b, c = l
    if abs(a - b) < c and c < a + b and len(set(l)) == 3:
        return True
    else:
        return False

n = input()
l = [int(i) for i in input().split()]
c = 0
for v in itertools.combinations(l, 3):
    if checker(v) is True:        
        c += 1
print(c)

Submission status: Accepted

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

seq = ('a', 'b', 'c', 'd', 'e')
ptr = list(itertools.combinations(L,3))

cnt = 0
for i in range(len(ptr)):
    a = ptr[i][0]
    b = ptr[i][1]
    c = ptr[i][2]
    if a<b+c and b<a+c and c<a+b and a!=b and b!=c and c!=a:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import itertools
N=int(input())
A=list(map(int,input().split()))
if len(A)<3:
  print('0')
  exit()
L=list(itertools.combinations(A,3))
l=map(list,L)
ans=0
for i in l:
  if len(set(i))==3 and i[0]+i[1]>i[2] and i[1]+i[2]>i[0] and i[0]+i[2]>i[1]:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
from  itertools import combinations 

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

count=0
for i in combinations(arr,3):
    a,b,c=i[0],i[1],i[2]
    #print(a,b,c)
    if a!=b and b!=c and a+b>c:
        count+=1
        
print(count)

Submission status: Accepted

Solution code:
#ABC175  B
import itertools
n = int(input())
l = list(map(int, input().split()))
if len(l) <= 2:
  print(0)
else:
  count = 0
  for i in itertools.combinations(l, 3):
    if i[0] != i[1] and i[1] != i[2] and i[2] != i[0]:
      if i[0] > abs(i[1]-i[2]) and i[0] < i[1] + i[2]:
        count += 1
  print(count)

Submission status: Accepted

Solution code:
n = int(input())
l_list = list(map(int,input().split()))
#sorted_list = sorted(l_list,reverse = True)
num_len = len(l_list)
count = 0
for i in range(num_len):
    for j in range(i+1,num_len):
        for k in range(j+1,num_len):
            temp_list = sorted([l_list[i],l_list[j],l_list[k]])
            if len(set(temp_list))<3:
                continue
            elif temp_list[2]-temp_list[1]-temp_list[0]<0:
                count+=1
                #print((i,j,k))
print(count)

Submission status: Accepted

Solution code:
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
L = inintl()

ans = 0

for i in range(n):
    for j in range(n):
        for k in range(n):
            if i < j < k and (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[i] != L[k] and L[j] != L[k]):
                ans += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
li = list(map(int,input().split()))
c = 0
for i in li:
  for j in li:
    for k in li:
      li2 = [i,j,k]
      long = max(li2)
      if long*2 < i + j + k:
        if i!=k:
          if k!=j:
            if i !=j:
              c = c + 1
print(int(c/6))

Submission status: Accepted

Solution code:
import collections

N = int(input())

Ls = list(map(int,input().split()))
c = collections.Counter(Ls)

Ls = list(set(Ls))
Ls.sort()
N = len(Ls)

cnt = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            if Ls[k]<Ls[i]+Ls[j]:
                cnt += 1 * c[Ls[i]]*c[Ls[j]]*c[Ls[k]]


print(cnt)

Submission status: Accepted

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

from collections import Counter

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)
    L = Counter(it)
    ky = sorted(L.keys())
    n = len(ky)

    ans = 0
    for i in range(n-2):
        a = ky[i]
        ai = L[a]
        for j in range(i+1, n-1):
            b = ky[j]
            bi = L[b]
            ab = a + b
            for k in range(j+1, n):
                c = ky[k]
                ci = L[c]
                if ab <= c:
                    break
                ci = L[c]
                ans += ai * bi * ci
    print(ans)



if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())

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

l.sort()
c = 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]:
                if l[i] + l[j] > l[k]:
                    c += 1

print(c)

Submission status: Accepted

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

#print(L)
cnt = 0
for i in range(N-2):
  for j in range(i,N-1):
    for k in range(j,N):
      if L[i] ==L[j] or L[j]==L[k] or L[i]==L[k]:
        continue
      elif L[i] + L[j] > L[k] and L[k] >abs(L[i] - L[j]):
        cnt +=1
        #print(i,j,k)

print(cnt)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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 ll[2]<ll[0]+ll[1] and ll[1]<ll[0]+ll[2] and ll[0]<ll[1]+ll[2] and len(set(ll))==3:
                ans += 1
#                 print(ll)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
res = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):            
            if A[i] + A[j] > A[k] and len(set([A[i], A[j], A[k]])) == 3:
                res += 1

print(res)

Submission status: Accepted

Solution code:
import math
import collections
import bisect
from collections import deque
from copy import copy, deepcopy
 
 
def main():
    N = int(input())
    L = list(map(int,input().split()))
    ans=0
    for i in range(len(L)):
        for j in range(i,len(L)):
            for k in range(j,len(L)):
                if L[i]==L[j] or L[j]==L[k] or L[k]==L[i]:
                    continue
                l = sorted([L[i],L[j],L[k]])
                if l[2]>=l[1]+l[0]:
                    continue

                #print(l,i,j,k)
                ans+=1
    print(ans)

 
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Ls.sort(reverse=True)

count = 0
for k, Lk in enumerate(Ls[:-2]):
    for j, Lj in enumerate(Ls[k+1:-1]):
        for i, Li in enumerate(Ls[k+j+2:]):
            if Lk == Lj or Lj == Li or Li == Lk:
                continue
            if Lk < Lj + Li:
                count += 1

print(count)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
res = 0
for pi,i in enumerate(l):
  for pj,j in enumerate(l[pi+1:],pi+1):
    if j==i:
      continue
    for k in l[pj+1:]:
      if k==j or k==i:
        continue
      if i+j>k and j+k>i and k+i>j:
        res += 1
print(res)

Submission status: Accepted

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

L.sort()
cnt = 0
for i in range(len(L)):
    for j in range(i+1,len(L)):
        for k in range(j+1,len(L)):
            if L[k] < (L[j] + L[i]) and L[i] != L[j] and L[j] != L[k] and L[k] != L[i]:
                cnt = cnt + 1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
lst = list(map(int, input().split()))
comb = combinations(lst, 3)
count = 0

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

Submission status: Accepted

Solution code:
import itertools
N = int(input())
L = list(map(int,input().split()))
combination_list =  list(itertools.combinations(L, 3))
ans = 0
for i in combination_list:
    j = sorted(list(i))
    if j[0] + j[1] > j[2] and j[0] != j[1] and j[1] != j[2] and j[2] != j[0]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def get_array():
    l=list(map(int, input().split()))
    return l
def ab(a,b,c):
	if((a+b>c) and (a+c>b) and (b+c>a)):
		return 1
	else:
		return 0
n=input()
n=int(n)
l=get_array()
c=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(ab(l[i],l[j],l[k])):
					#print(i,j,k)
					c+=1
print(c)

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(N):
        for k in range(N):
            if i != j and j != k and k != i :
                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] :
                        c = c + 1

print(int(c/6))

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int,input().split()))
c = 0
for i in range(len(l)):
    for j in range(i+1, len(l)):

        for k in range(j+1, len(l)):
            if l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[k] + l[i] > l[j]:
                if l[i] != l[j] and l[j] != l[k] and l[i] != l[k]:
                    c += 1


print(c)

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]:
      for k in range(j+1,n):
        if l[k]!=l[j] and l[k]!=l[i] and l[i]+l[j]>l[k]:
          ans=ans+1
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

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

def check(a,b,c):
    if a == b or b == c or c == a:
        return False

    if a + b > c and b +c > a and c + a > b:
        return True
    else:
        return False

ans = 0
for a, b, c in combinations(nums, 3):
    if check(a, b, c):
        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):
        if l[i]==l[j]:
            continue
        for k in range(j+1,n):
            if l[i]!=l[k] and l[j]!=l[k] and abs(l[i]-l[j])<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(reverse=True)
cnt = 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] and l[j] !=l[k] and l[k] != l[i]:
                if l[i] <l[j] + l[k]:
                    cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
l = list(map(int, input().split()))
nums = [i for i in range(len(l))]
ans = 0
for ptr in itertools.combinations(nums, 3):
    table = dict()
    cand = []
    for j in ptr:
        table[j] = l[j]
        cand.append(l[j])
    if len(set(cand)) == 3:
        k = sorted(table.items(), key=lambda x:x[1])
        if k[2][1] < k[0][1] + k[1][1]:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
if n<=2:
  print(0)
  exit()
count=0
a = input().split(" ")
lista = [int(n) for n in a]

for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      b=lista[i]
      c=lista[j]
      d=lista[k]
      if b==c or c==d or d==b or b==c==d:
        continue
      if b+c>d and c+d>b and b+d>c:
        count+=1
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations
class Bar:
  def __init__(self,num,length):
    self.num = num
    self.length = length
    
N = int(input())
T = list(map(int, input().split()))
bars = []
for n in range(N):
  bars.append(Bar(n,T[n]))

bars.sort(key = lambda x: x.length)
combi = list(combinations(bars,3))

ans = 0
for com in combi:
  if com[0].length == com[1].length or com[1].length == com[2].length:
    continue
  elif com[0].length + com[1].length <= com[2].length:
    continue
  else:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
l = list(map(int,input().split()))
ans = 0
if N >= 3:
  l.sort()
  l2 = list(itertools.combinations(l, 3))
  for i in range(len(l2)):
    if (l2[i][0] + l2[i][1] > l2[i][2]) and (l2[i][0] != l2[i][1] != l2[i][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]>L[k]:
                if L[j]+L[k]>L[i]:
                    if L[k]+L[i]>L[j]:
                        if (L[i] - L[j]) !=0:
                            if (L[j] -L[k]) !=0:
                                if (L[k]- L[i]) !=0:
                                    ans=ans+1
print(ans)

Submission status: Accepted

Solution code:
import itertools

def choice_lst(n, choice_number):
    n_lst = []
    for i in range(n):
        n_lst.append(i)
    lst = list(itertools.combinations(n_lst, choice_number))
    return lst


def main():
    n = int(input())
    l_lst = list(map(int, input().split()))
    count = 0

    choices = choice_lst(n, 3)
    for i in range(len(choices)):
        tmp_lst = []
        for j in range(3):
            choiced_number = choices[i][j]
            tmp_lst.append(l_lst[choiced_number])

        tmp_lst.sort()
        l1 = tmp_lst[0]
        l2 = tmp_lst[1]
        l3 = tmp_lst[2]
        if l1 + l2 > l3 and l1 != l2 and l2 != l3:
            count += 1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

N = int(input())
L = list(map(int,input().split()))
count = 0
for x in itertools.combinations(L,3):
  dup = [i for i in set(x) if x.count(i) > 1]
  if dup == [] and x[0] < x[1]+x[2] and x[1] < x[2] + x[0] and x[2] < x[0] + x[1]:
    count += 1
  
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


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

# perms = itertools.permutations(L, 3)
# print(list(perms))

res = 0
for i in range(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] and L[j] != L[k]:
                # abs(a - b) < c < a + b
                if abs(L[i] - L[j]) < L[k] < L[i] + L[j]:
                    # print(i, j, k)
                    res += 1

# for a, b, c in perms:
#     if a != b and b != c:
#         if abs(a - b) < c < a + b:
#             res += 1

print(res)

Submission status: Accepted

Solution code:
import sys
import itertools
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
L = LI()

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

Submission status: Accepted

Solution code:
x = int(input())
d = list(map(int, input().split()))
count = 0
for i in range(len(d)):
  for j in range(i+1,len(d)):
    for k in range(j+1,len(d)):
      temp = []
      temp.extend([d[i],d[j],d[k]])
      temp.sort()
      if temp[0] + temp[1] > temp[2] and len(list(set(temp))) == 3:
        count += 1
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations
from collections import defaultdict

N=int(input())
L=list(map(int,input().split()))
count=defaultdict(int)
for i in range(N):
    count[L[i]]+=1

L=list(set(L))
ans=0
for a,b,c in list(combinations(L,3)):
    if a>abs(b-c) and b>abs(c-a) and c>abs(a-b):
        ans+=count[a]*count[b]*count[c]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
L = list(map(int,input().split()))
#print(L)

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

Submission status: Accepted

Solution code:
p = 0
n = int (input ())
l = [int (x) for x in input().split()]
list.sort (l)
x,y,z = 0,1,2
while x < len(l)-2:
  while y < len(l)-1:
    while z < len(l):
      if l[x]!=l[y] and l[x]!=l[z] and l[y]!=l[z] and l[z] < l[x]+l[y]:
        p += 1
      z += 1
    y += 1
    z = y+1
  x += 1
  y = x+1
  z = y+1
print (p)

Submission status: Accepted

Solution code:
n = int(input())
L = list(map(int, input().split()))
counter = 0

for i in range(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[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]:
          counter += 1
print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import math
N = input()
ln = list(map(int, input().split()))
ans = 0
for i in range(0, len(ln) - 2):
    for j in range(i + 1, len(ln) - 1):
        for k in range(j + 1, len(ln)):
            l3 = [ln[i], ln[j], ln[k]]
            if ln[i] != ln[j] and ln[i] != ln[k] and ln[j] != ln[k] and \
                max(l3) < sum(l3) - max(l3):
                ans = ans + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import combinations

N = int(input())
sticks = [int(i) for i in input().split()]
c = Counter(sticks)
length_pattern = c.keys()
length_combinations = combinations(length_pattern, 3)

cnt = 0
for comb in length_combinations:
    if comb[0] < comb[1] + comb[2] and comb[1] < comb[2] + comb[0] and comb[2] < comb[0] + comb[1]:
        cnt += c[comb[0]] * c[comb[1]] * c[comb[2]]
    
print(cnt)

Submission status: Accepted

Solution code:
#B - Making Triangle
N = int(input())
L = list(map(int,input().split()))
count = 0
for i in range(N-2):
    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[k]>L[j] and L[k]+L[j]>L[i] and L[i] != L[j] and L[j] != L[k] and L[k]!=L[i]:
                count += 1
            else:
                pass

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
if n<3:
    print(0)
else:
    s=set()
    for i in range(n):
        for j in range(n):
            for k in range(n):
                if l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i] and (i,j,k) not in s:
                    if l[i]+l[j]>l[k] and l[j]+l[k]>l[i] and l[k]+l[i]>l[j]:
                        x=sorted([i,j,k])
                        s.add(tuple(x))
    
    print(len(s))

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
l.sort()
ans=0


for i in range(2,n):
    for j in range(1,i):
        for k in range(j):
            if l[k]==l[j] or l[i]==l[j] or l[i]==l[k]:
                continue
            x=l[k]+l[j]

            if x > l[i]:
                ans+=1

print(ans)

Submission status: Accepted

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

def main():
    N = int(input())
    L = sorted(map(int, input().split()), reverse=True)
    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] and L[i] != L[k] and L[j] != L[k]:
                    if L[i] < L[j] +L[k]:
                        ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline

# input functions
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda: list(map(int, input().split()))

def isTriangle(a, b, c):
    if a + b > c and b + c > a and a + c > b:
        return 1
    return 0

def allDiff(a, b, c):
    if a != b and b != c and a != c:
        return 1
    return 0 

def main():
    n = I()
    arr = ARR()
    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 allDiff(arr[i], arr[j], arr[k]) and isTriangle(arr[i], arr[j], arr[k]):
                    ans+=1
    
    
    print(ans)

main()

Submission status: Accepted

Solution code:
import math
import itertools

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] and L[j] != L[k] and L[k] != L[i] and 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: Accepted

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

count = 0

for i in range(len(L)):
  for j in range(i+1,len(L)):
    for k in range(j+1,len(L)):
      if L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[i]+L[k]>L[j]:
        if L[i]!=L[k] and L[j]!=L[k] and L[i]!=L[j]:
          count += 1
        
print(count)

Submission status: Accepted

Solution code:
N = int(input())
Ls = list(map(int, input().split()))
ls = sorted(set(Ls))
ks = [Ls.count(l) for l in ls]
# print(ks)
n = 0
for i, (l, k) in enumerate(zip(ls, ks)):
    lls = ls[i + 1:]
    kks = ks[i + 1:]
    for j, (ll, kk) in enumerate(zip(lls, kks)):
        l3s = lls[j + 1:]
        k3s = kks[j + 1:]
        for l3, k3 in zip(l3s, k3s):
            n += k * kk * k3 * (l3 < l + ll)
#             print(k,kk,k3,l,ll)
print(n)

Submission status: Accepted

Solution code:
import sys,collections,math,random,fractions,bisect,itertools;sys.setrecursionlimit(10**7)
sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n")
def I(i=0): t = [int(x)-i for x in sr().split()];return t
def S(): t = sr().split(); return t if len(t) > 1 else t[0]
L1,L2,L3,L4, = [],[],[],[]
 
n = I()
L1 = I()
df = collections.defaultdict(int)
for e in L1:
    df[e] += 1
cb = itertools.combinations(df, 3)
ans = 0
for e in cb:
    a,b,c = e
    if a + b > c and b + c > a and c + a > b:
        ans += df[a] * df[b] * df[c]
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
Li = list(map(int,input().split()))
cnt=0
for i in range(N):
  for j in range(N):
    for k in range(N):
      if Li[i]!=Li[j] and Li[j]!=Li[k] and Li[k]!=Li[i]:
        if abs(Li[i]-Li[j])<Li[k] and Li[k]<Li[i]+Li[j]:
          cnt+=1
print(int(cnt/6))

Submission status: Accepted

Solution code:
import itertools

n = int(input())
L = list(map(int, input().split()))
cnt = 0
for i, j, k in itertools.combinations(L, 3):
    if i == j or j == k or i == k:
        continue
    if i + j > k and j + k > i and k + i > j:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
if N<3:
    print(0)
    exit()
a=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]:
                a+=1
print(a)

Submission status: Accepted

Solution code:
from collections import Counter
import copy
from itertools import combinations


def A(s):
  if s == 'RRR':
    return 3
  elif s == 'RRS':
    return 2
  elif s == 'RSR':
    return 1
  elif s == 'SRR':
    return 2
  elif s == 'RSS':
    return 1
  elif s == 'SRS':
    return 1
  elif s == 'SSR':
    return 1
  elif s == 'SSS':
    return 0
  l = 0
  max_l = 0
  for i in range(len(s)):
    if i == 0 and s[i] == 'R':
      l += 1
    elif s[i - 1] == s[i] and s[i] == 'R':
      l += 1
    else:
      l = 0
    if l > max_l:
      max_l = l
  return max_l


def B(N, Ls):

  def _can_tri(a, b, c):
    if a == b or a == c or b == c:
      return False
    tmp_a, tmp_b, tmp_c = sorted([a, b, c])
    if tmp_a + tmp_b > tmp_c:
      return True
    return False

  ans = 0
  for i in range(N):
    for j in range(i + 1, N):
      for k in range(j + 1, N):
        if _can_tri(Ls[i], Ls[j], Ls[k]):
          # print(i + 1, j + 1, k + 1)
          ans += 1
  return ans


def C():
  pass


def main():
  # s = input()
  # print(A(s))
  N = int(input())
  Ls = [int(x) for x in input().split(' ')]
  print(B(N, Ls))


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
N = int(input())
input_list = list(map(int, input().split()))
pair_list = []
def triangle_check(a,b,c):
    return all([a+b>c, b+c>a, c+a>b, a!=b, b!=c,c!=a])

if N < 3:
    print(0)
else:
    for i in range(N):
        for j in range(i+1,N):
            for k in range(j+1,N):
                if triangle_check(input_list[i],input_list[j],input_list[k]):
                    pair_list.append([input_list[i],input_list[j],input_list[k]])
    print(len(pair_list))

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
L = defaultdict(int)
for s in input().split():
  L[int(s)] += 1
U = sorted(list(L.keys()), reverse=True)
cnt = 0
for i, a in enumerate(U):
  for j, b in enumerate(U[i+1:]):
    for c in U[i+j+2:]:
      cnt += (L[a] * L[b] * L[c]) if a < b + c else 0
print(cnt)

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[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]: 
        ans += 1
print(ans)

Submission status: Accepted

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

print(ans)