atcoder#ABC285E. [ABC285E] Work or Rest
[ABC285E] Work or Rest
Score : points
Problem Statement
In the world where Takahashi lives, a week has days.
Takahashi, the king of the Kingdom of AtCoder, assigns "weekday" or "holiday" to each day of week. The assignments should be the same for all weeks. At least one day of week should be assigned "holiday".
Under such conditions, the productivity of the -th day of week is defined by a sequence of length as follows:
- if the -th day of week is "holiday", its productivity is ;
- if the -th day of week is "weekday", its productivity is , if the last holiday is days before and the next one is days after.- Note that the last/next holiday may belong to a different week due to the periodic assignments. For details, see the Samples.
- Note that the last/next holiday may belong to a different week due to the periodic assignments. For details, see the Samples.
Find the maximum productivity per week when the assignments are chosen optimally. Here, the productivity per week refers to the sum of the productivities of the -st, -nd, , and -th day of week.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
7
10 10 1 1 1 1 1
50
For example, we can assign "holiday" to the -nd and -th day of week and "weekday" to the rest to achieve a productivity of per week:
- the -st day of week ... and , so its productivity is .
- the -nd day of week ... it is holiday, so its productivity is .
- the -st day of week ... and , so its productivity is .
- the -th day of week ... it is holiday, so its productivity is .
- the -th day of week ... and , so its productivity is .
- the -th day of week ... and , so its productivity is .
- the -th day of week ... and , so its productivity is .
It is impossible to make the productivity per week or greater.
10
200000000 500000000 1000000000 800000000 100000000 80000000 600000 900000000 1 20
5100000000
20
38 7719 21238 2437 8855 11797 8365 32285 10450 30612 5853 28100 1142 281 20537 15921 8945 26285 2997 14680
236980