#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
11 ms |
604 KB |
Output is correct |
4 |
Correct |
41 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
8 ms |
540 KB |
Output isn't correct |
4 |
Incorrect |
27 ms |
604 KB |
Output isn't correct |
5 |
Incorrect |
57 ms |
1108 KB |
Output isn't correct |
6 |
Incorrect |
82 ms |
1360 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
8 |
Incorrect |
24 ms |
776 KB |
Output isn't correct |
9 |
Incorrect |
42 ms |
1124 KB |
Output isn't correct |
10 |
Incorrect |
85 ms |
1536 KB |
Output isn't correct |