Folding the Card Strip
Alice and Bob found a long paper strip divided into n cards, each printed with an integer (some of them negative). They play a folding game: starting from the left end, they take turns folding the next few cards onto the growing folded stack, and whoever makes a fold scores the total value of everything in the stack at that moment. The game is over once the whole strip has been folded.
Formally, the cards are a_1, a_2, …, a_n. The state of the game is a number c, the count of cards already folded; initially c = 0. Let m = n − c be the number of cards still unfolded. A move chooses an integer k and sets c to c + k, where
- if
m ≥ L, thenL ≤ k ≤ min(R, m); - if
m < L, thenk = m(the last few cards are folded all at once).
The player making the move scores a_1 + a_2 + … + a_c, using the new value of c. The players alternate, Alice moves first, and the game ends when c = n.
Both players play optimally: each of them wants to maximize their own total score minus the other player's total score. Find Alice's total score minus Bob's total score.
Input
The first line contains three integers n, L and R (1 ≤ n ≤ 2·10^5, 1 ≤ L ≤ R ≤ n).
The second line contains n integers a_1, a_2, …, a_n (−10^9 ≤ a_i ≤ 10^9).
Output
Print a single integer: Alice's total score minus Bob's total score when both play optimally.
Notes
In the first example L = 1 and R = 2. Alice folds two cards and scores 3 + (−1) = 2. Bob folds one more card and scores 3 − 1 + 4 = 6. Alice folds the last two cards and scores the whole strip, 10. The difference is 2 + 10 − 6 = 6, and no strategy of Alice's does better against Bob's best replies.
In the second example Alice must fold two or three cards. If she folds two, she scores −3 and Bob folds the remaining two for 5. If she folds three, she scores −2, only one card is left, which is fewer than L = 2, so Bob folds it and scores 5. The second option is better for Alice, giving −2 − 5 = −7.
The answer may not fit in a 32-bit integer.