#include using namespace std; using ll=long long; using vin=vector; using vll=vector; using vvin=vector>; using vvll=vector>; using vstr=vector; using vvstr=vector>; using vch=vector; using vvch=vector>; using vbo=vector; using vvbo=vector>; using vpii=vector>; using pqsin=priority_queue,greater>; #define mp make_pair #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define decp(n) cout<>n; vin a(n);rep(i,n)cin>>a[i]; vin ls(n),rs(n); ls[0]=a[0];rs[0]=a[n-1]; rep(i,n-1){ ls[i+1]=min(ls[i],a[i+1]); rs[i+1]=min(rs[i],a[n-i-2]); } int ans=inf; rep2(i,1,n-1){ if(a[i]>ls[i-1]&&a[i]>rs[n-i-2]){ ans=min(ans,ls[i-1]+a[i]+rs[n-i-2]); //cout<