#include #define debug(x) cerr << #x << ": " << x << endl #define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endl using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector vll; const ll INF = LLONG_MAX/2; const ll MOD = 1e9+7; const double EPS=1e-12; template struct SegmentTree{ using T = typename M::T; int n; vector dat; SegmentTree(){} SegmentTree(int n_){init(n_);} SegmentTree(const vector &v){build(v);} void init(int n_){ n=1; while(n &v){ int n_=v.size(); init(n_); for(int i=0;i>=1) dat[k]=M::f(dat[(k<<1)|0],dat[(k<<1)|1]); } //[a,b) T query(int a,int b,int k=1,int l=0,int r=-1){ if(r<0)r=n; if(r<=a||b<=l) return M::ti(); if(a<=l&&r<=b) return dat[k]; T vl=query(a,b,k*2,l,(l+r)/2); T vr=query(a,b,k*2+1,(l+r)/2,r); return M::f(vl,vr); } T operator[](const int &k) const {return dat[k + n];} }; struct RminQ { using T = ll; static T ti() { return INT_MAX; } static T f(const T& l, const T & r) { return min(l, r); } }; signed main(){ cin.tie(0); ios::sync_with_stdio(false); ll N;cin>>N; ll a[N]; for(ll i=0;i>a[i]; ll x[N]; for(ll i=0;i>x[i]; ll y[N]; for(ll i=0;i>y[i]; SegmentTree segl(N),segr(N); ll dp=0; for(ll i=0;i