#pragma GCC optimize ("Ofast") #include using namespace std; template inline S max_L(S a,T b){ return a>=b?a:b; } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } template inline S moddw_L(S a, const T b){ a %= b; if(a < 0){ a += b; } return a; } int N; int S; int T; int A[100000]; int xs; int ys; long long x[100000]; long long y[100000]; int main(){ int i; long long res = 0; rd(N); rd(S);S += (-1); rd(T);T += (-1); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){ rd(A[Lj4PdHRW]); } } for(i=(moddw_L((S+1),N));i!=T;i=(moddw_L((i+1),N))){ x[xs++] = A[i]; } for(i=(moddw_L((S-1),N));i!=T;i=(moddw_L((i-1),N))){ y[ys++] = A[i]; } res += A[S]; int xr20shxY = xs/2; for(i=(0);i<(xr20shxY);i++){ res += x[i]; } int KrdatlYV = ys/2; for(i=(0);i<(KrdatlYV);i++){ res += y[i]; } if(xs%2==1 && ys%2==1){ res +=max_L(x[xs/2], y[ys/2]); } if(xs%2==1 && ys%2==0){ res += x[xs/2]; } if(xs%2==0 && ys%2==1){ res += y[ys/2]; } res *= 2; for(i=(0);i<(N);i++){ res -= A[i]; } wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20200509-1 // --- original code --- // int N, S, T, A[1d5]; // int xs, ys; ll x[1d5], y[1d5]; // { // int i; // ll res = 0; // rd(N,S--,T--,A(N)); // // for(i=(S+1)%%N;i!=T;i=(i+1)%%N) x[xs++] = A[i]; // for(i=(S-1)%%N;i!=T;i=(i-1)%%N) y[ys++] = A[i]; // // res += A[S]; // REP(i,xs/2) res += x[i]; // REP(i,ys/2) res += y[i]; // if(xs%2==1 && ys%2==1) res += max(x[xs/2], y[ys/2]); // if(xs%2==1 && ys%2==0) res += x[xs/2]; // if(xs%2==0 && ys%2==1) res += y[ys/2]; // // res *= 2; // rep(i,N) res -= A[i]; // wt(res); // }