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 .
The first line contains two integers and (1 \leq n \leq 30\,000, 1 \leq k \leq 20n) — 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 l_i, r_i, and s_i (1 \leq l_i, r_i \leq n, 1 \leq s_i \leq 20). Here, l_i and r_i are the preferred positions on the left and right teams for the -th participant, and s_i is their strength.
Print «YES» on a single line if it is possible to form the teams according to the conditions. Otherwise, print «NO».
Example 1
Example 2
In the first example, you can assign players , and to the left team (team strength equals 1 + 8 + 2 + 1 = 12), and participants , and to the right team (team strength equals 2 + 2 + 5 + 2 = 11). 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 .
( points): n \leq 10;
( points): n \leq 2\,000;
( points): n \leq 30\,000, s_i = 1;
( points): n \leq 30\,000.