0.2 Zoya's Enchanted Scroll Adventure
Zoya, a young adventurer, has discovered a magical scroll with a numerical riddle that holds the key to her next quest. To decipher the scroll’s mystery, Zoya must first collect energies from the enchanted stones placed in a sequence. She begins by summing the mystical energies of stones in odd positions—1st, 3rd, 5th, and so on. Next, she balances these energies with the forces from stones in even positions—2nd, 4th, 6th, and so forth. The scroll then guides her to uncover the hidden secret by calculating the difference between these two sums. This result will reveal the number that unlocks the next stage of her adventure and leads her to new, undiscovered realms.
Zoya can now use the hidden secret to continue her magical adventure!
Constraints
1≤n≤10^5
Each element in the list can be any integer within the range [−10^9,10^9]
Input Format
The first line contains a single integer n — the number of stones.
The second line contains n integers representing the energies of the enchanted stones, individual elements seperated by a single whitespace
Output Format
An integer representing the hidden secret, which is the difference between the sum of energies at odd positions and the sum of energies at even positions.
Example 1
Input:
5
1 2 3 4 5
Output:
3
Explanation:
Hidden secret: 9 - 6 = 3
Log In to solve the Question