Question
Sum of Even Elements in a Given Range
You are given a list of integers and two integers
L and R representing a range of indices. Your task is to find the sum of all even elements present in the list from index L to index R (both inclusive).
- Indexing is 0-based.
Lwill always be less than or equal toR.- Both
LandRare valid indices of the list.
Input
- The first line contains an integer
n, the size of the list. - The second line contains
nspace-separated integers. - The third line contains two integers
LandR.
Output
- Print a single integer — the sum of all even elements between index
LandR.
Example
Input
6
1 2 3 4 5 6
1 4
Output
6
Explanation:
Elements between index
Even elements are
Their sum is
6
1 2 3 4 5 6
1 4
Output
6
Explanation:
Elements between index
1 and 4 are: 2, 3, 4, 5.
Even elements are
2 and 4.
Their sum is
2 + 4 = 6.