William, like most respectable Italians, pursues his personal conflict of interest with supreme passion. He really loves being both an organizer of the Italian IOIT contests, and coaching his personal team for the same competition! His team (the RoseToPCoders) did not made it through this year’s competition, so it’s time to plan for a better performance next year.
William has already selected a shortlist consisting of students, numbered from to , each of them with a best friend . Remember that best-friendship is always symmetrical: if ’s best friend is , then ’s best friend is . William knows his buddies very well: for each of them, he measured how many points the student is able to score in a typical competition if his best friend is not in the team, and how many points the student is able to score if his best friend is in the team (the presence of a friend is always distracting).
Help William choose the best team consisting of exactly contestants for next year’s competition!
Input data
The first line contains two integers , . Each of the following lines contains integers , , .
Output data
You need to write a single line with an integer: the maximum number of points that a team of exactly contestants (among the given) can score in a typical competition, taking friendships into account.
Constraints and clarifications
- .
- for each .
- for each .
- Best-friendship is symmetrical: if and only if for each .
- is even and no student is best friend of himself: for each .
# | Score | Constraints |
---|---|---|
1 | 5 | Examples |
2 | 10 | |
3 | 25 | |
4 | 20 | |
5 | 20 | |
6 | 20 | No additional limitations. |
Example 1
stdin
4 1
2 20 15
3 70 0
0 10 10
1 50 0
stdout
70
Explanation
In the first sample case, the single best student is number .
Example 2
stdin
6 3
2 40 30
4 90 70
0 75 10
5 20 0
1 80 80
3 50 50
stdout
225
Explanation
In the second sample case, the best team consists of students , and for a total of + + = points (since and are best friends). The best team avoiding friendships would instead be , and scoring + + = points.