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>
using namespace std;
const int NMAX = 3e5 + 5;
const int MOD = 1e9 + 7;
int v[NMAX];
int main() {
int n;
cin >> n;
for(int i = 0; i < n; i++)
cin >> v[i];
sort(v, v + n);
int cnt1 = 0;
int i = 0;
while(i < n && v[i] == v[0]) {
i++;
cnt1++;
}
int cnt2 = 0;
while(i < n && v[i] == v[n - 1]) {
i++;
cnt2++;
}
if(cnt1 + cnt2 == n)
cout << 1LL * (cnt2 - 2) * (cnt2 - 1) / 2 % MOD * (cnt1 - 1) % MOD;
else {
int ans = 0;
for(int a = 1; a <= n - 3; a++) {
ans = (ans + (1LL * (n - a - 2) * (n - a - 1) / 2 % MOD)) % MOD;
}
cout << ans;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |