National Olympiad in Informatics, China, 2010
Little Z is a minorly famous pianist. Recently, Doctor C has gifted him with a super piano. With it, little Z hopes to create the world's most enchanting music.
The super piano has
A chord consists of a sequence of between
We define the value of a chord as the sum of the values of all its notes.
Little Z decides to compose a piece consisting of
Input Specification
The first line contains four positive integers
The next
Output Specification
The output consists of a single integer, the maximum possible value of a piece that little Z can compose.
Sample Input
4 3 2 3
3
2
-6
8
Sample Output
11
Explanation
There are
- Notes
to , for a total value of - Notes
to , for a total value of - Notes
to , for a total value of - Notes
to , for a total value of - Notes
to , for a total value of
The maximum value chords are
Constraints
There are
Test Case | ||
---|---|---|
All of the test cases satisfy
Furthermore, it is guaranteed that a composition fitting the requirements will exist.
Problem translated to English by , editted by .
Comments