#include #include #include using namespace std; const int MAXN = 100000 + 5; const int MAX_LOG = 20; int n, i, j, lg[MAXN], rmq[MAX_LOG][MAXN], m, x, y, cur_result; bool f_swap; long long ans; int main (int argc, char * const argv[]) { scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &rmq[0][i]); for(int i = 2; i <= n; i++) lg[i] = lg[i / 2] + 1; for(int i = 1; i <= lg[n]; i++) for(int j = 0; j < n - (1 << i) + 1; j++) rmq[i][j] = max(rmq[i - 1][j], rmq[i - 1][j + (1 << (i - 1))]); scanf("%d %d %d", &m, &x, &y); for(int i = 1; i <= m; i++) { if (x > y) { f_swap = true; swap(x, y); } else f_swap = false; cur_result = max(rmq[lg[y - x + 1]][x], rmq[lg[y - x + 1]][y - (1 << lg[y - x + 1]) + 1]); ans += cur_result; if (f_swap) swap(x, y); x += 7 + cur_result; if (x >= n) x %= n; y += 11 + cur_result; if (y >= n) y %= n; } printf("%lld\n", ans); return 0; }