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 <cstdio>
int n;
long long a[100005];
long long sum[100005];
long long mod = 1e9+7;
int main(){
int t;
scanf("%d",&n);
for (int i=0; i<n; i++) {
scanf("%d",&t);
a[t]++;
}
for (int i=1; i<=100000; i++) {
a[i] *= i;
a[i] %= mod;
}
for (int i=1; i<=100000; i++) {
sum[i] = a[i] + sum[i-1];
sum[i] %= mod;
}
for (int i=1; i<=100000; i++) {
sum[i] = a[i] * (sum[100000] - sum[i]);
sum[i] %= mod;
}
for (int i=1; i<=100000; i++) {
sum[i] += sum[i-1];
sum[i] %= mod;
}
long long res = 0;
for (int i=1; i<=100000; i++) {
res += a[i] * (sum[100000] - sum[i]);
res %= mod;
}
if(res < 0) res += mod;
printf("%lld",res);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |