A system of difference constraints is a set of inequations of the kind , where and are integer variables, and is an integer constant. Given a system of difference constraints, a solution is an assignment of values to variables in such a way that all inequations hold.
For instance, the system of difference constraints has, among other solutions, , and .
Write a program that, given a system of difference constraints with variables and inequations among them, tells if there is some solution or not.
Input consists of several cases. Every case begins with and , followed triplets , , , with , for the inequation . Assume , , , and that every pair of and appears at most once. All given numbers are integers.
For every case, print “yes” if the system has some
solution, and print “no” otherwise.
Input
3 3 1 2 4 2 3 -1 3 1 -2 3 3 1 2 3 2 3 -2 3 1 -2 4 6 2 4 -2 4 2 2 1 2 1 1 4 3 4 3 2 3 1 -1
Output
yes no yes