#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define vi vector<int>
#define vs vector<string>
#define vb vector<bool>
#define vpi vector<pi>
#define pb push_back
#define all(a) (a).begin(), (a).end()
const int mod = 1e9 + 7;
int md_inv_2 = 500000004;
void solve()
{
int n;
cin >> n;
int h[n], w[n];
for (int i = 0; i < n; i++)
cin >> h[i];
for (int i = 0; i < n; i++)
cin >> w[i];
int ans = 0;
int tot = 0;
int curr = 0;
for (int i = 0; i < n; i++)
{
tot = (tot + w[i]) % mod;
if (h[i] == 1)
{
ans = (ans + (curr * (curr + 1)) % mod) % mod;
curr = 0;
}
else
{
curr = (curr + w[i]) % mod;
}
}
int val = (tot * (tot + 1)) % mod;
val = (val * md_inv_2) % mod;
ans = (ans + (curr * (curr + 1))) % mod;
ans = (ans + val) % mod;
cout << ans << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
{
solve();
}
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... |