#include #include using namespace std; using ll = long long; const int MOD = 1e9 + 7; const int MAX_N = 1e5 + 10; int len[MAX_N], num[MAX_N]; int dp[MAX_N][4]; int main() { int n; cin >> n; map counter; for (int i = 0; i < n; i++) { int a; cin >> a; counter[a]++; } int b_kinds = 0; for (auto it = counter.begin(); it != counter.end(); it++) { len[b_kinds] = it->first; num[b_kinds] = it->second; b_kinds++; } dp[0][0] = 1; for (int i = 0; i < b_kinds; i++) { for (int b = 0; b <= 3; b++) { dp[i + 1][b] += dp[i][b]; dp[i + 1][b] %= MOD; if (b - 1 >= 0) { dp[i + 1][b] += ((ll)dp[i][b - 1] * (ll)num[i]) % MOD; dp[i + 1][b] %= MOD; } } } cout << dp[b_kinds][3] << endl; return 0; }