100 atcoder#ABC165C. [ABC165C] Many Requirements
[ABC165C] Many Requirements
Score : points
Problem Statement
Given are positive integers , , , and quadruples of integers ( , , , ).
Consider a sequence satisfying the following conditions:
- is a sequence of positive integers.
- .
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 .
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
110
When , its score is . Under these conditions, no sequence has a score greater than , so the answer is .
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
357500
10 10 1
1 10 9 1
1