The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank.
One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible.
Vasya has just reached a new rank of a, but he dreams of holding the rank of b. Find for how many more years Vasya should serve in the army until he can finally realize his dream.
Input
The first input line contains an integer n (2 ≤ n ≤ 100). The second line contains n - 1 integers di (1 ≤ di ≤ 100). The third input line contains two integers a and b (1 ≤ a < b ≤ n). The numbers on the lines are space-separated.
Output
Print the single number which is the number of years that Vasya needs to rise from rank a to rank b.
Examples
Input
3
5 6
1 2
Output
5
Input
3
5 6
1 3
Output
11
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We are given: n ranks, from 1 to n (1 lowest, n highest). To rise from rank i to i+1, need exactly d_i years. So d_i given for i=1 to n-1. Vasya currently has rank a (he just reached a) and wants rank b (with a<b). Need total years to go from rank a to rank b.
We need to sum d_i for i from a to b-1 inclusive. Because to go from a to a+1 need d_a, then to go from a+1 to a+2 need d_{a+1}, ... up to from b-1 to b need d_{b-1}. So answer is sum_{i=a}^{b-1} d_i.
Check constraints: n up to 100, d_i up to 100, sum may fit in integer.
Input: first line integer n. Second line n-1 integers d_i (presumably in order d1, d2, ..., d_{n-1}). Third line a and b. Output sum.
Examples: n=3, d = [5,6], a=1,b=2 -> sum d1 =5. Output 5. a=1,b=3 -> sum d1+d2=5+6=11. Output 11.
That's it.
We just need to read input, compute sum. Could be done in Python.
Edge cases: a,b are guaranteed a<b and within [1,n]. So no need to check.
Implementation: read n, then read list of n-1 ints, then read a,b. Then sum from index a-1 (0-based) to b-2 inclusive? Actually if we store d as list indices 0..n-2 corresponding to d1..d_{n-1}. Then need sum of d[i] for i from (a) to (b-1) inclusive? Let's map: d[0] is for 1->2, i=1. d[k] is for (k+1) -> (k+2). So to go from a to b, need d for ranks i = a, a+1, ..., b-1. So indices: for rank i, d_i corresponds to index i-1 (since d_1 at index 0). So indices needed: from a-1 to b-2 inclusive. So slice d[a-1:b-1]? Because Python slice end exclusive: d[a-1 : b-1] includes indices a-1 up to b-2 inclusive. That's correct because b-1 exclusive: stops at b-2. So we can sum(d[a-1:b-1]) . Equivalent to sum(d[a-1:b-1]) . Let's test: a=1,b=2 => a-1=0, b-1=1 => slice d[0:1] includes index 0, sum d1. a=1,b=3 => slice d[0:2] includes indices 0,1, sum d1+d2. Good.
Alternatively we can loop.
We'll output the sum.
The problem statement is straightforward.
Given we are ChatGPT, we need to output solution code. Probably in Python.
But maybe they want in C++? The instruction: "The Berland Armed Forces System consists..." typical from Codeforces? It doesn't specify language. But the user likely wants the solution code in Python. Usually we provide Python solution.
I'll produce Python code:
def main():
import sys
data = sys.stdin.read().strip().split()
if not data: return
it = iter(data)
n = int(next(it))
d = [int(next(it)) for _ in range(n-1)]
a = int(next(it))
b = int(next(it))
ans = sum(d[a-1:b-1])
print(ans)
if name == "main":
main()
That's it.
Consider if n=2: only one d. a=1,b=2 -> slice d[0:1] works.
All good. ```python
import sys
def main() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
n = int(next(it)) # number of ranks, not directly needed
d = [int(next(it)) for _ in range(n - 1)] # d1 .. d_{n-1}
a = int(next(it))
b = int(next(it))
code
# sum of d_i for i from a to b-1
answer = sum(d[a - 1 : b - 1])
print(answer)