package main import ( "fmt" ) // Prime number const P = 1000000007 func main() { var n, z int64 m := make(map[int64]int64) fmt.Scan(&n) z = n * (n - 1) * (n - 2) / 6 for i := int64(0); i < n; i++ { var a int64 fmt.Scan(&a) m[a]++ } for _, x := range m { if x < 2 { continue } if x >= 2 { z -= (n - x) * x * (x - 1) / 2 } if x >= 3 { z -= x * (x - 1) * (x - 2) / 6 } } fmt.Println(z % P) }