#K69602. Taco Transformation

    ID: 33123 Type: Default 1000ms 256MiB

Taco Transformation

Taco Transformation

You are given two arrays a and b of length N and M transformation rules. Each rule is represented as a tuple \( (l, r, x) \), meaning that you can apply the following operation on the subarray from index \( l \) to index \( r \) (1-indexed): check if for every index \( i \) in \( [l, r] \) the difference \( b_i - a_i \) is divisible by \( x \) (i.e., \( b_i - a_i \equiv 0 \, (\bmod\, x) \)). If the condition holds, you use this rule to transform that segment and effectively set the difference to zero. Determine whether it is possible to transform array a into b by applying the given rules in the order provided.

Note: The transformation for each rule is only valid when every element in the corresponding subarray satisfies \( (b_i - a_i) \mod x = 0 \). If any element does not, the transformation fails and the answer is "NO". Otherwise, if after applying all the rules all differences are reduced to zero, the answer is "YES".

inputFormat

The input is given from standard input (stdin) and has the following format:

  1. The first line contains two integers \( N \) and \( M \), where \( N \) is the length of the arrays and \( M \) is the number of transformation rules.
  2. The second line contains \( N \) integers representing the array a.
  3. The third line contains \( N \) integers representing the array b.
  4. The next \( M \) lines each contain three integers \( l \), \( r \) and \( x \) describing a transformation rule.

outputFormat

Output a single line to standard output (stdout): either "YES" if it is possible to transform a to b using the given rules, or "NO" otherwise.

## sample
5 2
1 3 5 7 9
3 5 7 5 9
2 4 2
1 5 1
YES