# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
557871 | FatihSolak | W (RMI18_w) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define N 300005
using namespace std;
const int mod = 1e9 + 7;
long long fact[N];
long long ifact[N];
long long binpow(long long a,long long b){
long long ret = 1;
while(b){
if(b & 1)
ret = ret*a%mod;
a = a*a%mod;
b >>= 1;
}
return ret;
}
long long C(int n,int r){
return fact[n] * ifact[r]%mod*ifact[n-r]%mod;
}
void solve(){
int n;
cin >> n;
map<int,int> cnt;
for(int i = 1;i<=n;i++){
int x;
cin >> x;
mp[x]++;
}
vector<int> v;
for(auto u:mp)
v.push_back(u.second);
if(v[0] < 2 || v[1] < 3){
cout << 0;
return;
}
cout << C(v[0]-2+3,3) *C(v[1]-3+3,3) %mod;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
fact[0] = ifact[i]= 1;
for(int i = 1;i<N;i++){
fact[i] = fact[i-1] * i %mod;
ifact[i] = binpow(fact[i],mod-2);
}
int t = 1;
//cin >> t;
while(t--){
solve();
}
#ifdef Local
cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds.";
#endif
}