#include using namespace std; int prev(int x, int N){ if (x == 0){ return N - 1; } else { return x - 1; } } int next(int x, int N){ if (x == N - 1){ return 0; } else { return x + 1; } } int main(){ int N; cin >> N; int s, t; cin >> s >> t; s--; t--; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } vector used(N, false); used[s] = true; used[t] = true; long long X = A[s]; long long Y = A[t]; priority_queue> pq1, pq2; pq1.push(make_pair(A[prev(s, N)], prev(s, N))); pq1.push(make_pair(A[next(s, N)], next(s, N))); pq2.push(make_pair(A[prev(t, N)], prev(t, N))); pq2.push(make_pair(A[next(t, N)], next(t, N))); for (int i = 0; i < N - 2; i++){ if (i % 2 == 0){ while (used[pq1.top().second]){ pq1.pop(); } X += pq1.top().first; int p = pq1.top().second; used[p] = true; pq1.pop(); if (!used[prev(p, N)]){ pq1.push(make_pair(A[prev(p, N)], prev(p, N))); } if (!used[next(p, N)]){ pq1.push(make_pair(A[next(p, N)], next(p, N))); } } if (i % 2 == 1){ while (used[pq2.top().second]){ pq2.pop(); } Y += pq2.top().first; int p = pq2.top().second; used[p] = true; pq2.pop(); if (!used[prev(p, N)]){ pq2.push(make_pair(A[prev(p, N)], prev(p, N))); } if (!used[next(p, N)]){ pq2.push(make_pair(A[next(p, N)], next(p, N))); } } } cout << X - Y << endl; }