// Partial: exhaustive O(2^N) over all cyclic arc-partitions. Intended for S1 (N<=20).
// For N>24 it cannot run in time, so it gives up (wrong) — mirroring a real brute.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long solve(std::vector<int> H_in, std::vector<int> W_in){
    int n = (int)H_in.size();
    vector<ll> h(H_in.begin(), H_in.end()), w(W_in.begin(), W_in.end());
    if(n==1){ return h[0]*w[0]; }
    if(n>24){ return 0; }            // out of brute range
    ll gmh=0,gmw=0; for(int i=0;i<n;i++){gmh=max(gmh,h[i]);gmw=max(gmw,w[i]);}
    ll best=gmh*gmw;                                 // mask==0: whole cycle is one arc
    for(unsigned mask=1; mask<(1u<<n); mask++){
        int k=__builtin_ctz(mask);                   // some cut edge (after jelly k)
        int startpos=(k+1)%n;
        ll sum=0, mh=0, mw=0;
        for(int j=0;j<n;j++){
            int pos=(startpos+j)%n;
            mh=max(mh,h[pos]); mw=max(mw,w[pos]);
            if((mask>>pos)&1u){ sum+=mh*mw; mh=mw=0; } // edge after jelly pos is cut
        }
        best=max(best,sum);
    }
    return best;
}
