Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/rekursiya-massiv-elementlari-yigindisi

Sum of array elements

Easy 1000 ms 64 MB 30%
Share

You are given an array of $n$ integers. Using a recursive function, compute the sum of all its elements.

The recurrence:
$$\text{sum}(A, n) = \begin{cases} A[0], & n = 1 \\ A[n - 1] + \text{sum}(A, n - 1), & n > 1 \end{cases}$$

Every call splits the last element off the array, and the split-off elements are added up

Input

The first line contains an integer $n$ ($1 \le n \le 100$). The second line contains $n$ integers $a_i$ separated by spaces ($-1000 \le a_i \le 1000$).

Output

The sum of the array elements.

Note

$1 \le n \le 100$, $-1000 \le a_i \le 1000$

Examples

Input #1
4
1 2 3 4
Output #1
10
Input #2
3
-5 10 -2
Output #2
3

Sign in to submit a solution

Signing up is free and takes a minute.