#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);
vector<int> suf(n);
for(int i=0;i<n;i++)
cin>>fences[i].first;
for(int i=0;i<n;i++)
cin>>fences[i].second;
suf[n-1]=fences[n-1].second;
for(int i=n-2;i>=0;i--)
suf[i]=(suf[i+1]+fences[i].second)%mod;
int ans=0;
int w,h,row,col;
for(int i=0;i<n;i++)
{
if(i==0)
{
w=suf[i];
h=fences[i].first;
row=(((h+1)*h)/2)%mod;
col=(((w+1)*w)/2)%mod;
ans=(ans+row*col)%mod;
}
else if(fences[i].first==fences[i-1].first)
{
continue;
}
else
{
h=fences[i].first;
int he=fences[i-1].first;
w=suf[i];
row=((((h+1)*h)/2)-(((he+1)*he)/2))%mod;
col=(((w+1)*w)/2)%mod;
//cout<<row<<" "<<col<<endl;
ans=(ans+row*col)%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... |