~/algor $ cat problems/dp-simni-bolaklab-sotish
Selling wire in pieces
Medium
1000 ms
128 MB
51%
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?
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