#include #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; const int mod = 1000000007; int C[500][500]; void comb() { C[0][0] = 1; for (int i = 0; i <= 400; ++i) { for (int j = 0; j <=i; ++j) { C[i + 1][j] += C[i][j] % mod; C[i + 1][j + 1] += C[i][j] % mod; } } } int main() { int n; cin >> n; vector A(n); rep(i, n) cin >> A[i]; comb(); vector res = A; auto result = unique(res.begin(), res.end()); res.erase(result, res.end()); if (res.size() == A.size()) { int ans = C[n][3] % mod; cout << ans << endl; return 0; } int sol = 1; for (int i = 0; i < res.size(); ++i) { int k = count(A.begin(), A.end(), res[i]); sol *= k; sol %= mod; } int ans2 = C[res.size()][3] * sol % mod; cout << ans2 << endl; return 0; }