use std::io::*; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let n: usize = itr.next().unwrap().parse().unwrap(); let a: Vec = (0..n) .map(|_| itr.next().unwrap().parse().unwrap()) .collect(); // n C 3 - let mut cnt: Vec = vec![0; 100010]; for i in 0..n { cnt[a[i]] += 1; } let mut ans = n * (n - 1) * (n - 2) / 3 / 2; for i in 0..100005 { if cnt[i] >= 3 { ans -= cnt[i] * (cnt[i] - 1) * (cnt[i] - 2) / 3 / 2; } if cnt[i] >= 2 { ans -= cnt[i] * (cnt[i] - 1) / 2 * (n - cnt[i]); } } println!("{}", ans % 1_000_000_007); }