/* -*- coding: utf-8 -*- * * 1150.cc: No.1150 シュークリームゲーム(Easy) - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int MAX_N2 = MAX_N * 2; const long long LINF = 1LL << 62; /* typedef */ typedef long long ll; /* global variables */ int as[MAX_N2]; ll ass[MAX_N2 + 1]; /* subroutines */ /* main */ int main() { int n, s, t; scanf("%d%d%d", &n, &s, &t); s--, t--; int n2 = n * 2; for (int i = 0; i < n; i++) scanf("%d", as + i), as[i + n] = as[i]; for (int i = 0; i < n2; i++) ass[i + 1] = ass[i] + as[i]; int s0, t0, t1, s1; if (s < t) s0 = s, t0 = t1 = t, s1 = s + n; else s0 = s, t0 = t + n, t1 = t, s1 = s; int k = t0 - (s0 + 1), l = s1 - (t1 + 1); int hk = k / 2, hl = l / 2; int w0 = t0 - hk, w1 = t1 + 1 + hl; ll x = as[s], y = as[t]; if (! (k & 1) || ! (l & 1)) { x += (ass[w0] - ass[s0 + 1]) + (ass[s1] - ass[w1]); y += (ass[t0] - ass[w0]) + (ass[w1] - ass[t1 + 1]); } else { if (as[w0] > as[w1]) { x += (ass[w0] - ass[s0 + 1]) + (ass[s1] - ass[w1 + 1]); y += (ass[t0] - ass[w0]) + (ass[w1 + 1] - ass[t1 + 1]); } else { x += (ass[w0 - 1] - ass[s0 + 1]) + (ass[s1] - ass[w1]); y += (ass[t0] - ass[w0 - 1]) + (ass[w1] - ass[t1 + 1]); } } printf("%lld\n", x - y); return 0; }