#abc165c. [abc165_c]Many Requirements
[abc165_c]Many Requirements
Problem Statement
Given are positive integers , , , and quadruples of integers ( , , , ).
Consider a sequence satisfying the following conditions:
- is a sequence of positive integers.
- $1 \\leq A_1 \\leq A_2 \\le \\cdots \\leq A_N \\leq M$.
Let us define a score of this sequence as follows:
- The score is the sum of over all indices such that . (If there is no such , the score is .)
Find the maximum possible score of .
Constraints
- All values in input are integers.
- ( )
- ( )
- (where )
- ( )
Input
Input is given from Standard Input in the following format:
Output
Print the maximum possible score of .
Sample Input 1
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
Sample Output 1
110
When , its score is . Under these conditions, no sequence has a score greater than , so the answer is .
Sample Input 2
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
Sample Output 2
357500
Sample Input 3
10 10 1
1 10 9 1
Sample Output 3
1