This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
int w[100005];
int h[100005];
int ans = 0;
int width = 0;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    for(int i = 0; i < n; i++)cin >> h[i];
        for(int i = 0; i < n; i++){
        cin >> w[i];
        width += w[i];
        // ans += (h[i]-1)*w[i]; // vertical rectangle for h=2
    }
    //cout << ans << "\n";
    if(width % 2 == 0){ // all rectangle for h=1
        ans += (width+1)*(width/2);
    } else {
        ans += (width*(width-1)/2)+width;
    }
    //cout << ans << "\n";
    width = 0;
    for(int i = 0; i < n; i++){
        if(h[i] > 1){
            width += w[i];
        } else {
            if(width % 2 == 0){ // all rectangle for h=2
                ans += (width+1)*(width/2)*2;
            } else {
                ans += ((width*(width-1)/2)+width)*2;
            }
            width = 0;
        }
        if(i == (n-1)){
            if(width % 2 == 0){ // all rectangle for h=2
                ans += (width+1)*(width/2)*2;
            } else {
                ans += ((width*(width-1)/2)+width)*2;
            }
            width = 0;
        }
    }
    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... |