CT1023

Nils and the Even Minus Odd

EasyL2 · Byte BanditAcceptance: 0.0%XP: 10

Caravans arrive at the moonlit lagoon of Selene with crates of coins, and Nils the chronicler must account for every last one. Task: Read n integers and print the sum of values at even 1-based positions minus the sum at odd positions. Input format: First line: n. Second line: n space-separated integers. Output format: Print (sum of even-positioned) - (sum of odd-positioned). Constraints: 1 <= n <= 34; 0 <= a[i] <= 1000000000; answers fit a signed 64-bit integer.

Example 1:

Input: 10 724586003 486036656 535539643 788670529 130702206 436763438 870362862 452366226 428825651 675344775
Output: -149165259

Example 2:

Input: 2 123190192 322998280
Output: -199808088

Example 3:

Input: 2 237960804 77555326
Output: 160405478

Constraints:

1 <= n <= 34; 0 <= a[i] <= 1000000000; answers fit a signed 64-bit integer.

Loading...
Test Cases:No test cases
No test cases available.