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.
  • L will always be less than or equal to R.
  • Both L and R are valid indices of the list.
Input
  • The first line contains an integer n, the size of the list.
  • The second line contains n space-separated integers.
  • The third line contains two integers L and R.
Output
  • Print a single integer — the sum of all even elements between index L and R.
Example
Input
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.

Online