// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
const long long MOD=1e9+7;
int main() {
long long n;
cin>>n;
vector<long long> h(n);
long long wossz=0, ans=0;
for(long long i=0; i<n; i++){
cin>>h[i];
}
vector<long long> ket;
long long a;
cin>>a;
if(h[0]==2) ket.push_back(a);
wossz+=a;
for(long long i=1; i<n; i++){
cin>>a;
if(h[i]==h[i-1] && h[i]==2){
ket.back()=(ket.back()+a)%MOD;
}
else if(h[i]==2){
ket.push_back(a);
}
wossz=(wossz+a)%MOD;
}
for(long long x : ket){
ans=(ans+(x*(x+1)%MOD))%MOD;
}
ans=(ans+(wossz*(wossz+1)/2)%MOD)%MOD;
cout<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
30 ms |
960 KB |
Output is correct |
4 |
Correct |
52 ms |
1200 KB |
Output is correct |
5 |
Correct |
52 ms |
1404 KB |
Output is correct |
6 |
Correct |
48 ms |
1216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |