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

~/algor $ cat problems/rekursiya-massivdagi-eng-katta-element

Largest element of an array

Easy 1000 ms 64 MB 31%
Share

You are given an array of $n$ integers. Using a recursive function, find the largest (maximum) element of the array.

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

The array elements as bars, the tallest one highlighted

Input

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

Output

The largest element of the array.

Note

$1 \le n \le 100$, $-10^9 \le a_i \le 10^9$

Examples

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

Sign in to submit a solution

Signing up is free and takes a minute.