#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define int long long
int mod=1e9+7;
int32_t main()
{
int n;
cin>>n;
vector<pair<int,int>> fences(n);
int ans=0;
for(int i=0;i<n;i++)
{
cin>>fences[i].first;
}
int sum=0;
for(int i=0;i<n;i++)
{
cin>>fences[i].second;
sum=(sum+fences[i].second)%mod;
}
int col;
col=(((sum+1)*sum)/2)%mod;
ans+=col;
int x=0;
for(int i=0;i<n;i++)
{
if(fences[i].first==2)
{
x=(fences[i].second+x)%mod;
}
if(fences[i].first==1)
{
ans+=(((x+1)*x))%mod;
x=0;
}
}
ans+=(((x+1)*x))%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... |
# | 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... |