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.

Solution in Scala (2.13.1) (judge verdict: Time Limit Exceeded)

import scala.util.control.Breaks

object Main extends App {
  val n = scala.io.StdIn.readInt()
  val lInput = scala.io.StdIn.readLine()
  val lArray = lInput.split(" ").map(_.toLong).toVector

  val lArraySorted = lArray.toSet.toVector.sorted
  val sortedLength = lArraySorted.length
  var triangleSeq = scala.collection.mutable.Seq.empty[(Long, Long, Long)]

  def setTriangle(head: Long, tail: Vector[Long]): Unit = {
    tail.zipWithIndex.foreach { t =>
      if (head < t._1) {
        val second = (head, t._1)
        setThirdPosition(second, tail.drop(t._2 + 1))
      }
    }
  }

  def setThirdPosition(nihen: (Long, Long), tail: Vector[Long]): Unit = {
    val b = new Breaks
    b.breakable {
      tail.foreach { t =>
        if ((nihen._1 + nihen._2) > t && t > Math.abs((nihen._1 - nihen._2))) {
          triangleSeq :+= (nihen._1, nihen._2, t)
        } else {
          b.break()
        }
      }
    }
  }

  if (sortedLength > 2) {
    var count = sortedLength
    var tempSortedArray = lArraySorted
    while (count > 2) {
      val head = tempSortedArray.head
      tempSortedArray = tempSortedArray.tail
      setTriangle(head, tempSortedArray)
      count = count - 1
    }
    var result = 0
    val groupedMap = lArray.groupBy(l => l)
    triangleSeq.foreach { t =>
      val firstCount = groupedMap.get(t._1).get.size
      val secondCount = groupedMap.get(t._2).get.size
      val thirdCount = groupedMap.get(t._3).get.size
      result = result + (firstCount * secondCount * thirdCount)
    }
    println(result)
  } else {
    println(0)
  }

}