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

#BF0000036. Người thương nhân xảo quyệt (The Cunning Merchant)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Người thương nhân xảo quyệt (The Cunning Merchant)

The Cunning Merchant

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

A ledger contains monthly income values, which may be negative. Each observation (s,t,v)(s,t,v) asserts the sum from month ss through tt equals vv. Determine whether an income sequence can satisfy every observation.

Monthly incomes may be negative.

This Extended version omits the original count of independent ledgers.

Input

First line contains n,mn,m, then mm triples s,t,vs,t,v.

Output

Print true when consistent, otherwise false.

Subtasks

  • Subtask 1 (20 points): $1\le n\le12; 1\le m\le30; 1\le s\le t\le n; -10^9\le v\le10^9$.
  • Subtask 2 (30 points): $1\le n\le50; 1\le m\le300; 1\le s\le t\le n; -10^9\le v\le10^9$.
  • Subtask 3 (50 points): $1\le n\le99; 1\le m\le999; 1\le s\le t\le n; -10^9\le v\le10^9$.

Examples

Input

3 3
1 2 5
2 3 7
1 3 9

Output

true

Explanation

The monthly incomes (2,3,4)(2,3,4) meet all three observations: 2+3=52+3=5, 3+4=73+4=7, and 2+3+4=92+3+4=9. Consequently the ledger is consistent and the output is true.