#include #include #include using namespace std; const int MOD = (int)1e9 + 7; long long comb(int n, int r) { if (r < 0 || n < r) return 0; long long ret = 1; for (int i = 1; i <= r; i++) (ret *= n--) /= i; return ret; } int main() { int n; cin >> n; vector a(n); for (int &ai: a) cin >> ai; vector cnt(101); for (int ai: a) cnt[ai]++; long long ans = comb(n, 3) % MOD; for (int c: cnt) if (c) { (ans -= comb(c, 2) * comb(n - c, 1) + comb(c, 3)) %= MOD; } cout << ans << endl; return 0; }