#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pb push_back
#define sz(a) (ll) a.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, a, b) for(ll i=(ll)(a); i<(ll)(b); i++)
#define rrep(i, a, b) for(ll i=(ll)(a); i>=(ll)(b); i--)
#define vl vector<ll>
#define vpll vector<pair<ll, ll>>
#define vvl vector<vector<ll>>
#define pll pair<ll, ll>
const ll md=1e9+7;
ll cnt(ll a, ll b){
ll ret=((((a+1)*(a))/2 % md) * ((((b+1)%md)*(b))/2 % md)) % md;
return ret;
}
void f() {
ll n; cin >> n; ll cntw=0;
vl h(n), w(n);
for(auto& u : h) cin >> u;
for(auto& u : w){ cin >> u; cntw+=u; }
ll ans=cnt(1, (cntw%md));
ans%=md;
ll strt=-1;
rep(i, 0, n){
if(h[i]==2){
strt=i;
break;
}
}
if(strt==-1){
cout << ans;
return;
}
bool two=1; ll sm=w[strt];
rep(i, strt+1, n){
if(((h[i]==2) == two) && two){
sm+=w[i];
} else if(((h[i]==2) == two) && !two){
continue;
} else if(h[i]==2){
sm=w[i];
two=1;
} else {
ans+=2*cnt(1, sm);
sm=0;
two=0;
ans%=md;
}
}
if(h[n-1]==2){
ans+=2*cnt(1, sm);
ans%=md;
}
cout << ans;
}
int main() {
int tc=1;
while (tc--) f();
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |