Tug of war
Tug of war is a popular sport with straightforward rules: two teams pull a rope in opposite directions. An annual tug of war competition is organized, and many participants have already signed up. Lady, the main organizer, needs to divide the participants into two teams.
There are participants registered, so each team must consist of participants. The rope has spots on the left side and spots on the right, indicating where participants will stand.
Each participant has chosen exactly one spot on the left and one spot on the right where they prefer to stand. Additionally, Lady knows the strength of each participant. She is having trouble distributing the participants into two teams and needs your help. Your task is to determine if it's possible to divide the participants into two teams such that each participant stands on one of their chosen spots, no two participants share a spot, and the difference in the total strengths of the two teams does not exceed .
Input
The first line contains two integers and (, ) — the number of participants per team and the maximum allowable difference in the sum of the teams' strengths.
Each of the following lines contains three integers , , and (). Here, and are the preferred positions on the left and right teams for the -th participant, and is their strength.
Output
Print "YES" on a single line if it is possible to form the teams according to the conditions. Otherwise, print "NO".
Examples
Note
In the first example, you can assign players , and to the left team (team strength equals ), and participants , and to the right team (team strength equals ). The difference in strengths is .
In the second example, both players with strengths must be on the same team, resulting in a minimum strength difference of .
Scoring
( points): ;
( points): ;
( points): , ;
( points): .