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()]
if(n<=2):
    print(0)
else:
    
    d = {}
    ss = set();
    for i in l:
        if( i in d.keys()):
            d[i]+=1;
        else:
            d[i] =1
            ss.add(i)
    s = list(ss)
    len = len(s)
    count = 0
    for i in range(len):
        for j in range(i+1,len):
            for k in range(j+1,len):
                if(s[i] + s[j] >s[k] and s[i] + s[k] > s[j] and s[j] + s[k] > s[i]):
                    count = count + d[s[i]] * d[s[j]] * d[s[k]]
    print(count)

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

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):
            I=l[i]
            J=l[j]
            K=l[k]
            if I+J>K and J+K>I and K+I>J and I!=J and I!=K and J!=K:
                ans+=1
print(ans)

Submission status: Accepted

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

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

SList=list(itertools.combinations(List,3))
#print(SList)

ans=0

for i in range(len(SList)):
    #print(SList[i])
    if has_duplicates(SList[i])==False:
        C=sorted(SList[i])[::-1]
        #print("CCCCCCCCCCCC")
        if C[2]+C[1]>C[0]:
            ans+=1
            #print("AAAAAAAAAAAAA",C[0]+C[1],C[2])
    
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]) or (L[i] == L[k]) or (L[j] == L[k])):
        continue
      # a+b>c && b+c>a && c+a>b
      if (((L[i] + L[j]) > L[k])
          and ((L[j] + L[k]) > L[i])
          and ((L[k] + L[i]) > L[j])):
        #print(str(L[i]) + '  ' + str(L[j]) + '  ' + str(L[k]))
        count += 1

print(count)

Submission status: Accepted

Solution code:
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N = int(input())
    L = read_list()
    res = 0
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(j + 1, N):
                T = [L[i], L[j], L[k]]
                if len(set(T)) == 3 and sum(T) > 2 * max(T):
                    res += 1
    print(res)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
_n = int(input())
_lengths = list(map(int, input().split(" ")))
_lengths.sort()

_pre = 0
_index = -1
_sticks = []
for _length in _lengths:
  if _pre != _length:
    _sticks.append([_length, 1])
    _index += 1
    _pre = _length
  else:
    _sticks[_index][1] +=1

_counter = 0
if len(_sticks) >= 3:
  for _i in range(len(_sticks)):
    for _j in range(_i+1, len(_sticks)):
      for _k in range(_j+1, len(_sticks)):
        if _sticks[_i][0] + _sticks[_j][0] > _sticks[_k][0]:
          _counter += _sticks[_i][1] * _sticks[_j][1] * _sticks[_k][1] 
print(_counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

def triang(a,b,c):
  f0 = not ( (a==b) or (b==c) or (c==a) )
  f1 = (a+b>c) and (b+c>a) and (c+a>b)
  return f0 and f1

count=0
for t in itertools.combinations(L,3):
   if triang(*t):
      count+=1

print(count)

Submission status: Accepted

Solution code:
N=int(input())
hk=list(input().split())
h=[int(s) for s in hk]
count=0
if N>2:
  for x in range(N):
    for y in range(N):
      for z in range(N):
        if h[x]!=h[y] and h[y]!=h[z] and h[z]!=h[x]:
          if h[x]+h[y]>h[z] and h[y]+h[z]>h[x] and h[z]+h[x]>h[y]:
            count+=1
count=count//6
print(count)

Submission status: Accepted

Solution code:
import itertools
def has_duplicates(seq):
    return len(seq) != len(set(seq))

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

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

ans = 0
for i in range(len(C)):
    if has_duplicates(list(C[i])):
        continue
    elif list(C[i])[2] >= list(C[i])[0] + list(C[i])[1]:
        continue
    else:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(L)
L = list(set(list(L)))

L.sort()

res = 0

for i in range(len(L) - 2):
  k = i
  for j in range(i + 1, len(L) - 1):
    while k < len(L) and L[k] < L[i] + L[j]:
      k += 1
    #print(i, j, k)
    for p in range(j + 1, k):
      res += c[L[i]] * c[L[j]] * c[L[p]]

print(res)

Submission status: Accepted

Solution code:
#coding: utf-8
import itertools

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

cnt = 0
all_cnt = 0

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

for pair in itertools.combinations(L, 3):
    all_cnt += 1
    if has_duplicates(pair):
        pass
    else:
        b0 = max(pair)
        pair = set(pair) - {b0}
        b1 = list(pair)[0]
        b2 = list(pair)[1]

        if b0 - b1 < b2 < b0 + b1:
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import itertools

mm = int(input())
kk = list(map(int, input().split()))
pp = list(set(kk))
answer_=[]

if len(kk)<2:
  answer=0
else:
  for qq in itertools.combinations(pp, 3):
    rr = list(qq)
    rrr = sorted(rr)
    a = rrr[0]
    b = rrr[1]
    c = rrr[2]
    if a+b>c:
      aa = kk.count(a)
      bb = kk.count(b)
      cc = kk.count(c)
      d = aa*bb*cc
      answer_.append(d)
    else:
      answer_.append(0)
  answer = sum(answer_)
  
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
x=sorted(x,reverse=True)
cnt=0
for i in range(0,n-2):
 l1=x[i]
 for j in range(i+1,n-1):
  l2=x[j]
  for k in range(j+1,n):
   l3=x[k]
   if l1<l2+l3 and l1!=l2 and l2!=l3:
      cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import itertools

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

lst=list(itertools.combinations(seq,3))

#求める組合わせの個数をansとする
ans=0

for i in range(len(lst)):
    if lst[i][0]!=lst[i][1]:
        if lst[i][0]!=lst[i][2]:
            if lst[i][1]!=lst[i][2]:
                if lst[i][0]+lst[i][1] > lst[i][2]:
                    if lst[i][1]+lst[i][2] > lst[i][0]:
                        if lst[i][0]+lst[i][2] > lst[i][1]:
                            ans = ans+1
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
Llist=list(map(int,input().split(' ')))
count=0
Llist_sorted=sorted(Llist)
for i in range(N):
    tri=[]
    tri_i=tri+[Llist_sorted[i]]
    for j in range(i+1,N):
        tri=tri_i
        tri_ij=tri+[Llist_sorted[j]]
        for k in range(j+1,N):
            tri=tri_ij
            tri_ijk=tri+[Llist_sorted[k]]
            if tri_ijk[0]<tri_ijk[1]<tri_ijk[2] and tri_ijk[0]+tri_ijk[1]>tri_ijk[2]:
                count+=1
print(count)

Submission status: Accepted

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

if n <= 2:
  print(0)
  exit()

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

Submission status: Accepted

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

length.sort()
cnt = 0
y_start = 1
for i in range(0, len(length)-2, 1):
    a = length[i]
    for j in range(i+1, len(length)-1, 1):
        b = length[j]
        for k in range(j+1, len(length), 1):
            c = length[k]
            if a == b or b == c:
                continue
            if (a+b) > c:
                cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
x = list(map(int,input().split()))
i = 0
j = 0
k = 0
tri = 0
for i in range(0,N):
    s1 = x[i] 
    j = 0
    for j in range(i+1,N):
        s2 = x[j]
        k = 0
        if s1 != s2:
            for k in range(j+1,N):
                s3 = x[k]
                if s1 != s3 and s2 != s3:
                    sum_1 = s1 + s2
                    sum_2 = s2 + s3
                    sum_3 = s3 + s1
                    if sum_1 > s3 and sum_2 > s1 and sum_3 > s2:
                        tri += 1
print(tri)

Submission status: Accepted

Solution code:
n = int(input())
L = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
    #print(i)
    for j in range(i+1,n-1):
        if L[i] == L[j]:continue
        for k in range(j+1,n):
            #print(L[i], L[j], L[k], "*")
            if ((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])):
              #print(L[i], L[j], L[k])
              cnt += 1
print(cnt)

Submission status: Accepted

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

ans = 0
for i in range(N):
    li = L[i]
    for j in range(i+1, N):
        lj = L[j]
        if li == lj:
            continue
        for k in range(j+1, N):
            lk = L[k]
            if lk in [li, lj]:
                continue
            lMax = max(li, lj, lk)
            ans += li + lj + lk - lMax > lMax

print(ans)

Submission status: Accepted

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

n = int(input())
l_list = list(map(int, input().split()))
p_list = list(itertools.permutations(l_list, 3))
p_list = list(filter(lambda e: len(set(e)) == len(e), p_list))

if len(p_list) < 3:
    print(0)
else:
    count = 0
    for p in p_list:
        if p[0] < p[1] < p[2] and p[2] < p[0] + p[1]:
            count += 1
    print(count)

Submission status: Accepted

Solution code:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def RLI(n=8,a=1,b=10):return [random.randint(a,b)for i in range(n)]
def RI(a=1,b=10):return random.randint(a,b)
def Rtest(T):
    case,err=0,0
    for i in range(T):
        inp=INP()
        a1,ls=naive(*inp)
        a2=solve(*inp)
        if a1!=a2:
            print((a1,a2),inp)
            err+=1
        case+=1
    print('Tested',case,'case with',err,'errors')
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in R(base**n):s=[tb//(base**bt)%base for bt in R(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**9)
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()


show_flg=False
show_flg=True

ans=0

n=I()
l=LI()

for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            a,b,c=l[i],l[j],l[k]
            if a!=b and b!=c and a!=c and 2*max(a,b,c)<a+b+c and 1:
                ans+=1
print(ans)

Submission status: Accepted

Solution code:
import itertools

def duplicate(x):
    return len(x) != len(set(x))

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

cnt = 0

for team in itertools.combinations(S, 3):
    #print(duplicate(team))
    if duplicate(team) == True:
        continue
    else:
        if max(team) < sum(team) - max(team):
            cnt += 1
        else:
            continue

print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
L=list(map(int,input().split()))
L.sort()
c=0
for s in range(N-2):
	for t in range(s+1,N-1):
		two=L[s]+L[t]
		if L[s] != L[t]:
			for u in range(t+1,N):
				if L[u] == L[t]:
					c+=0
				elif two > L[u]:
					c+=1
					#print(s,t,u)
				else:
					break
print(c)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
l = list(map(int, input().split()))
cnt = 0
for i in range(n):
    for j in range(n):
        for k in range(n):
            if i < j < k:
                if l[i] != l[j] and l[i] != l[k] and l[j] != l[k]:
                    if l[i] + l[j] > l[k] and l[j]+l[k] > l[i] and l[k]+l[i]>l[j]:
                        cnt += 1
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):
            a = l[i]
            b = l[j]
            c = l[k]
            if a != b and b != c and c != a and a + b > c and b + c > a and c + a > b:
                ans += 1
print(ans)

Submission status: Accepted

Solution code:
import bisect
import collections
n=int(input())
l=sorted(list(map(int,input().split())))
a=sorted(list(set(l)))
num=len(a)
d=collections.Counter(l)
ans=0
for i in range(num-2):
  for j in range(i+1,num-1):
    c=a[i]+a[j]
    K= bisect.bisect_left(a, c)
    for k in range(j+1,K):
      ans+=d[a[i]]*d[a[j]]*d[a[k]]
print(ans)

Submission status: Accepted

Solution code:
s=int(input())
a = list(map(int,input().split()))
c=[0]*3
count =0
if len(a)>=3:
    for i in range(0,s-2):
        c[0]=a[i]
        for j in range(i+1,s-1):
            c[1]=a[j]
            for k in range(j+1,s):
                c[2]=a[k]
                b=sorted(c,reverse=True)
                if b[0]!=b[1] and b[2]!=b[1] and b[0]!=b[2] and b[0]<b[1]+b[2]:
                    count+=1
print(count)

Submission status: Accepted

Solution code:
import collections
import itertools
def resolve():
    n = int(input())
    l = list(map(int, input().split()))
    c = collections.Counter(l)
    keys = c.keys()
    key_combinations = set(itertools.combinations(keys, 3))

    result = 0
    for combination in key_combinations:
        max_key = max(combination)
        if sum(combination) - max_key > max_key:
            # 三角形になる
            one_combination_result = 1
            for key in combination:
                one_combination_result = one_combination_result * c[key]
            result += one_combination_result
    print(result)
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
L=map(int,input().split())
L=list(L)
L_un=list(set(L))
Lunc=len(L_un)
b=0

for i in range(0,Lunc):
    for m in range(i+1,Lunc):
        for n in range(m+1,Lunc):
            if L_un[i]+L_un[m]>L_un[n] and L_un[m]+L_un[n]>L_un[i] and L_un[n]+L_un[i]>L_un[m]:
                c_i=L.count(L_un[i])
                c_m=L.count(L_un[m])
                c_n=L.count(L_un[n])
                
                b+=c_i*c_m*c_n

print(b)

Submission status: Accepted

Solution code:
n = input()
l_lst = map(int, input().split())
# newlst = list(set(l_lst))
# print(set(l_lst))
# print(newlst)
cnt = 0
startnum = 1
secondstartnum = 2
# for i in range(0, len(newlst)):
    
#     for j in range(startnum, len(newlst)):
#         # startnum += 1
#         # print(startnum)
        
#         for k in range(secondstartnum, len(newlst)):
#             print(i, j, k, secondstartnum)
#             # print(newlst[i], newlst[j], newlst[k])
#             # if newlst[i] + newlst[j] > newlst[k] and newlst[j] + newlst[k] > newlst[i] and newlst[k] + newlst[i] > newlst[j]:
#             #     cnt += 1
#             secondstartnum += 1
#         secondstartnum = 2
#     startnum += 1

import itertools
for pair in itertools.combinations(l_lst, 3):
    # print(pair)
    if pair[0] + pair[1] > pair[2] and pair[1] + pair[2] > pair[0] and pair[2] + pair[0] > pair[1]:
        if pair[0] != pair[1] and pair[1] != pair[2] and pair[2] != pair[0]:
            # print(pair[0], pair[1], pair[2])
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
from itertools import combinations

n = int(input())
num_list = list(map(int, input().split()))
combination = combinations(num_list, 3)
count = 0
for i in combination:
  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:
def mulit(a):
  a_copy = list(a)
  return len(a) == len(set(a_copy))
def isTriangle(x):
  return x[0] + x[1] > x[2]

N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
a_len = len(A)
answer = []
for i in range(0, a_len-2):
  for j in range(i+1, a_len-1):
    for k in range(j+1, a_len):
      answer.append([A[i], A[j], A[k]])
      
answer = [i for i in answer if mulit(i)]
answer = [i for i in answer if isTriangle(i)]
answer_len = len(answer)
print(f"{answer_len}")

Submission status: Accepted

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

Submission status: Accepted

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

count = 0

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

for i in range(0, n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            threenum_list = [length_list[j],length_list[k], length_list[i]]
            if not has_duplicates(threenum_list):

                if (abs(length_list[j]-length_list[k]) < length_list[i]) and (length_list[i] < length_list[j] + length_list[k]):
                    if (abs(length_list[k] - length_list[i]) < length_list[j]) and (length_list[j] < length_list[i] + length_list[k]):
                        if (abs(length_list[i] - length_list[j]) < length_list[k]) and (length_list[k] < length_list[j] + length_list[i]):
                            count += 1


print(count)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
a = b = c = 0

for fi in range(n):
    for si in range(fi+1,n):
        for ti in range(si+1,n):
            a = l[fi]
            b = l[si]
            c = l[ti]
            if a == b or b == c or c == a:
                pass
            else:
                if a+b > c and b+c > a and c+a > b:
                    ans += 1 
print(ans)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	al.sort()
	r=0
	for i, vi in enumerate(al):
		for j, vj in enumerate(al[i:],i):
			if vi == vj:
				continue
			for vk in al[j:]:
				if vi == vk:
					pass
				elif vj == vk:
					pass
				elif vi + vj <= vk:
					pass
				else:
					r+=1
	return r
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    l = list(map(int, input().split()))
    count = 0
    if n < 3:
        return 0
    else:
        for i in range(n-2):
            for j in range(i+1, n):
                for k in range(j+1, n):
                    select = [l[i], l[j], l[k]]
                    # len1 = len(select)
                    # len2 = len(set(select))
                    # maxans = max(select)
                    # sumans = sum(select)
                    # case1 = len(select) == len(set(select))
                    # case2 = max(select)*2 < sum(select)
                    if (len(select) == len(set(select))) and (max(select)*2 < sum(select)):
                        count += 1
        return count


if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
N=int(input())
X = list(map(int,input().split()))
Y=set(X)
Z=list(Y)
NN=len(Z)
AA=0
for i in range(NN-2):
  for ii in range(NN-2-i):
    for iii in range(NN-2-i-ii):
      A=[Z[i], Z[ii+i+1], Z[iii+ii+i+2]]
      if max(A)<Z[i]+Z[ii+i+1]+Z[iii+ii+i+2]-max(A):
        AA+=X.count(Z[i])*X.count(Z[ii+i+1])*X.count(Z[iii+ii+i+2])
if N<3:
  print(0)
else:
  print(AA)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
l_1 = sorted(l)[::-1]
cnt = 0
for i in range(n):
    kizyun = l_1[i]
    for j in range(i+1, n):
        kizyun_2 = l_1[j]
        for k in range(j+1, n):
            kizyun_3 = l_1[k]
            if kizyun_2-kizyun_3 < kizyun < kizyun_2+kizyun_3 and l_1[i] != l_1[j] != l_1[k]:
                cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# ####################################################################
# import io
# import sys

# _INPUT = """\
# 10
# 9 4 6 1 9 6 10 6 6 8
# """
# sys.stdin = io.StringIO(_INPUT)
# ####################################################################
####################################################################
import sys
def _p(*_a):
  #return
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
####################################################################
def _pa(_aa):
  #return
  for _a in _aa: _p(_a)
####################################################################
N = int(input())
L = [int(i) for i in input().split()]

L.sort()

from collections import Counter
A = Counter(L)
K = list(A.keys())

# _p(K)
# for k,v in A.items():
#   _p(k,v)

ans = 0

for i in range(len(K)):
  # _p(K[i], A[K[i]])
  for j in range(i+1,len(K)):
    # _p("  ",K[j], A[K[j]])
    for k in range(j+1,len(K)):
      # _p("    ",K[k], A[K[k]])
      if K[i] + K[j] > K[k]:
        # _p(A[K[i]] , A[K[j]] , A[K[k]])
        # _p(K[i] , K[j] , K[k])
        ans += A[K[i]] * A[K[j]] * A[K[k]]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

n = int(input())
l = list(map(int, input().split()))
p = itertools.combinations(l, 3)
count = 0

for x in p:
    a, b, c = x[0], x[1], x[2]
    if a == b or b == c or a == c:
        continue
    if a + b > c and b + c > a and a + c > b:
        count += 1

print(count)

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()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = int(input())

ans = 0

L = LI()

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

print(str(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import itertools

# 棒の本数
n = int(input())

# 棒のリスト
lods = list(map(int, input().split()))

# 3本なければ三角形は作れない
if (n < 3):
  print(0)
  exit()

# 確認
count = 0
for data in itertools.combinations(lods, 3):
  if (data[0] != data[1]
      and data[1] != data[2]
      and data[2] != data[0]
      and (data[0]+data[1]) > data[2]
      and (data[1]+data[2]) > data[0]
      and (data[2]+data[0]) > data[1]):
    count += 1

print(count)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
L = [int(i) for i in input().split()]
cnt = 0
for v in itertools.combinations(L, 3):
    if (
        (len(set(v)) == 3) and
        (v[0] + v[1] > v[2]) and 
        (v[1] + v[2] > v[0]) and 
        (v[0] + v[2] > v[1])
    ):
         cnt = cnt + 1
print(cnt)

Submission status: Accepted

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

count = 0

temp = []
temp2 = []
while len(L)>=3:
    a = L.pop()
    while len(L)>=2:
        b = L.pop()
        temp2.insert(0, b)
        if b == a:
            continue
        while L:
            c = L.pop()
            temp.insert(0, c)
            if c==b:
                continue
            if c >= a+b:
                break
            count +=1
        L = L + temp
        temp.clear()
    L.extend(temp2)
    temp2.clear()


print(count)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
if(n<3):
    print(0)
else:
    p = 0
    for i in range(2,n):
        for j in range(1,i):
            for k in range(j):
                if(l[i] != l[j] and l[j] != l[k] and l[k] != l[i]):
                    if(l[i]+l[j]+l[k] > 2*max(l[i],l[j],l[k])):
                        p += 1
    print(p)

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):
            a = l[i]
            b = l[j]
            c = l[k]
            if a != b:
                if b != c:
                    if a != c:
                        if a + b > c:
                            if b + c > a:
                                if a + c > b:
                                    count += 1
                        
print(count)