#include using namespace std; #define int long long #define rep(i,n) for(int i=0;i<(int)(n);i++) #define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define all(x) (x).begin(),(x).end() #define pb push_back #define mp make_pair #define mt make_tuple typedef pair pii; typedef vector vi; typedef vector vvi; const int inf = 1LL<<60; const int mod = 1e9 + 7; const double eps = 1e-9; /*{ }*/ template class Combination { public: int n; vector fac, finv; Combination(int n_) : n(n_), fac(n_), finv(n_) { fac[0] = 1; for(int i = 1; i < n; i++) fac[i] = fac[i-1]*i%M; finv[n-1] = pow(fac[n-1], M-2); for(int i = n-1; i > 0; i--) finv[i-1] = finv[i]*i%M; } int pow(int a, int b) { if(b == 0) return 1; return pow(a*a%M, b/2)*(b%2?a:1)%M; } int C(int a, int b) { if(b < 0 or a < b) return 0; return fac[a]*finv[a-b]%M*finv[b]%M; } int P(int a, int b) { if(b < 0 or a < b) return 0; return fac[a]*finv[a-b]%M; } int H(int a, int b){ if(a == 0 and b == 0) return 1; return C(a+b-1, b); } }; signed main() { int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; sort(all(a)); a.pb(-1); int ans = 1, cnt = 0, tmp = 1; rep(i, n){ if(a[i] == a[i+1]){ tmp++; }else{ (ans *= tmp) %= mod; tmp = 1; cnt++; } } Combination comb(cnt+1); (ans *= comb.C(cnt, 3)) %= mod; cout << ans << endl; return 0; }