n=int(input()) a=[int(i) for i in input().split(" ")] def ret(num,li): count=0 if num<3:return count for i in range(num-2): print("c") for e in range(i+1,num-1): if li[i]==li[e]:continue count+=len([p for p,q in enumerate(li[e+1:]) if (li[i]-li[e])*(li[p+e+1]-li[e])*abs(li[i]-li[p+e+1])>0]) return count print(ret(n,a))