In the third semester of the first grade of JOI High School, courses are given for weeks from the first week to the -th week. The courses are numbered from to . In each week, classes are given. The -th class in each week is a class for Course .
Bitaro is a student of the first grade. In each of the classes, he takes one of the following actions.
- Action 1: Bitaro attends the class. If he attends a class for Course , the comprehension level of Course will be increased by .
- Action 2: Bitaro does not attend the class. Instead, he chooses any one of the courses, and studies for the chosen course by himself. If he studies for Course by himself for the duration of a class, the comprehension level of Course will be increased by .
In the beginning, the comprehension level of every course is . Since Bitaro wants to practice competitive programming after school, he will not study outside the duration of the classes. When all the classes in the third semester finish, the final examination will be held.
Bitaro does not want to get a failing grade. Therefore, he wants to maximize the minimum comprehension level of the courses at the moment of the final examination.
Given the length of the semester, the number of courses, and the incremental values of the comprehension levels, write a program which calculates the maximum possible value of the minimum comprehension level of the courses at the moment of the final examination.
Input Specification
Read the following data from the standard input. Given values are all integers.
Output Specification
Write one line to the standard output. The output should contain the maximum possible value of the minimum comprehension level of the courses at the moment of the final examination.
Constraints
- .
- .
- .
- .
Subtasks
- (10 points) .
- (25 points) , .
- (27 points) .
- (29 points) .
- (9 points) No additional constraints.
Sample Input 1
3 3
19 4 5
2 6 2
Sample Output 1
18
Explanation for Sample 1
For example, if Bitaro studies in the following way, the comprehension level of Course will be , respectively.
- In the first week, at the time of Course , he studies for Course by himself.
- In the first week, at the time of Course , he studies for Course by himself.
- In the first week, at the time of Course , he attends the class for Course .
- In the second week, at the time of Course , he attends the class for Course .
- In the second week, at the time of Course , he studies for Course by himself.
- In the second week, at the time of Course , he attends the class for Course .
- In the third week, at the time of Course , he studies for Course by himself.
- In the third week, at the time of Course , he studies for Course by himself.
- In the third week, at the time of Course , he attends the class for Course .
Since the minimum comprehension level of the courses cannot be larger than or equal to , output . This sample input satisfies the constraints of Subtasks 3, 5.
Sample Input 2
2 1
9 7
2 6
Sample Output 2
7
Explanation for Sample 2
This sample input satisfies the constraints of Subtasks 1, 3, 5.
Sample Input 3
5 60000
630510219 369411957 874325200 990002527 567203997
438920902 634940661 593780254 315929832 420627496
Sample Output 3
41397427274960
Explanation for Sample 3
This sample input satisfies the constraints of Subtasks 3, 5.
Sample Input 4
4 25
1 2 3 4
1 2 3 4
Sample Output 4
48
Explanation for Sample 4
This sample input satisfies the constraints of Subtasks 2, 3, 4, 5.
Comments