PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000049. Suy ra tổng cả dãy (Range Sums)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Suy ra tổng cả dãy (Range Sums)

Range Sums

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

An unknown array consists of nn integers a1,a2,…,ana_1,a_2,\ldots,a_n. You are told the sums of qq contiguous segments. The ii-th piece of information gives the value of ali+ali+1+⋯+aria_{l_i}+a_{l_i+1}+\cdots+a_{r_i} for some 1≤li≤ri≤n1\le l_i\le r_i\le n.

You are not asked to compute the total sum. Instead, determine whether the given segment-sum information always uniquely determines a1+a2+⋯+ana_1+a_2+\cdots+a_n, regardless of the actual numerical values of the segment sums. In other words, any two arrays satisfying exactly the same reported segment sums must have the same whole-array sum.

Only the segment endpoints li,ril_i,r_i are given in the input, since the answer does not depend on the reported values.

Input

The first line contains n,qn,q. Each of the next qq lines contains li,ril_i,r_i.

Output

Print Yes if the total can be determined; otherwise print No.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20, 1≤q≤401\le q\le40; 1≤li≤ri≤n1\le l_i\le r_i\le n; the segments [li,ri][l_i,r_i] are distinct; q≤n(n+1)/2q\le n(n+1)/2.
  • Subtask 2 (30 points): 1≤n≤42001\le n\le4200, 1≤q≤84001\le q\le8400; 1≤li≤ri≤n1\le l_i\le r_i\le n; the segments [li,ri][l_i,r_i] are distinct; q≤n(n+1)/2q\le n(n+1)/2.
  • Subtask 3 (50 points): 1≤n,q≤2⋅1051\le n,q\le2\cdot10^5; 1≤li≤ri≤n1\le l_i\le r_i\le n; the segments [li,ri][l_i,r_i] are distinct; q≤n(n+1)/2q\le n(n+1)/2.

Examples

Input

3 3
1 2
2 3
2 2

Output

Yes

Explanation

Let P0=0P_0=0 and Pi=a1+⋯+aiP_i=a_1+\cdots+a_i. The intervals reveal P2−P0P_2-P_0, P3−P1P_3-P_1, and P2−P1P_2-P_1, making P3−P0P_3-P_0 determinable.