#include using namespace std; const int INF=1e9; int main() { int N; cin>>N; vector X(N); for(int i=0;i>t; X[i]|=t< a(N); for(int i=0;i>a[i]; int ans=INF; for(int S=0;S<(1<>i&1) cost+=a[i]; while(true){ bool updated=false; for(int i=0;i>i&1){ if((cur|X[i])==cur){ cur|=1<