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

~/algor $ cat problems/dp-simni-bolaklab-sotish

Selling wire in pieces

Medium 1000 ms 128 MB 51%
Share

A craftsman has a wire $n$ meters long. At the market a piece of wire $k$ meters long sells for $p_{k}$ soums ($k = 1, 2, \dots, n$). The craftsman cuts the wire into pieces of whole meters (or does not cut it at all) and sells them. What is the largest amount he can earn?

A wire cut into whole-meter pieces; the cutting with the largest total price is highlighted

Input

The first line contains a positive integer $n$. The second line contains $n$ space-separated positive integers: $p_{1}, p_{2}, \dots, p_{n}$.

Output

One integer — the largest income.

Note

$1 \le n \le 1000$
$1 \le p_{k} \le 10^{9}$

Examples

Input #1
4
1 5 8 9
Output #1
10
Input #2
1
7
Output #2
7

Sign in to submit a solution

Signing up is free and takes a minute.