← Home
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func c2(x int64) int64 {
	return x * (x - 1) / 2
}

func c3(x int64) int64 {
	return x * (x - 1) * (x - 2) / 6
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 1<<20)

	var n int
	fmt.Fscan(in, &n)

	a := make([]int, n)
	freq := make(map[int]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
		freq[a[i]]++
	}

	sort.Ints(a)

	x, y, z := a[0], a[1], a[2]
	var ans int64

	if x == y && y == z {
		ans = c3(freq[x])
	} else if x == y {
		ans = c2(freq[x]) * freq[z]
	} else if y == z {
		ans = freq[x] * c2(freq[y])
	} else {
		ans = freq[x] * freq[y] * freq[z]
	}

	fmt.Println(ans)
}