#abc277h. [abc277_h]Constrained Sums

[abc277_h]Constrained Sums

Problem Statement

Determine whether there is a sequence of NN integers X=(X1,X2,ldots,XN)X = (X_1, X_2, \\ldots ,X_N) that satisfies all of the following conditions, and construct one such sequence if it exists.

  • 0leqXileqM0 \\leq X_i \\leq M for every 1leqileqN1 \\leq i \\leq N.

  • LileqXAi+XBileqRiL_i \\leq X_{A_i} + X_{B_i} \\leq R_i for every 1leqileqQ1 \\leq i \\leq Q.

Constraints

  • 1leqNleq100001 \\leq N \\leq 10000
  • 1leqMleq1001 \\leq M \\leq 100
  • 1leqQleq100001 \\leq Q \\leq 10000
  • 1leqAi,BileqN1 \\leq A_i, B_i \\leq N
  • 0leqLileqRileq2timesM0 \\leq L_i \\leq R_i \\leq 2 \\times M
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN MM QQ A1A_1 B1B_1 L1L_1 R1R_1 A2A_2 B2B_2 L2L_2 R2R_2 vdots\\vdots AQA_Q BQB_Q LQL_Q RQR_Q

Output

If there is an integer sequence that satisfies all of the conditions in the Problem Statement, print the elements X1,X2,ldots,XNX_1, X_2, \\ldots, X_N of one such sequence, separated by spaces. Otherwise, print -1.


Sample Input 1

4 5 3
1 3 5 7
1 4 1 2
2 2 3 8

Sample Output 1

2 4 3 0

For X=(2,4,3,0)X = (2,4,3,0), we have X1+X3=5X_1 + X_3 = 5, X1+X4=2X_1 + X_4 = 2, and X2+X2=8X_2 + X_2 = 8, so all conditions are satisfied. There are other sequences, such as X=(0,2,5,2)X = (0,2,5,2) and X=(1,3,4,1)X = (1,3,4,1), that satisfy all conditions, and those will also be accepted.


Sample Input 2

3 7 3
1 2 3 4
3 1 9 12
2 3 2 4

Sample Output 2

-1

No sequence XX satisfies all conditions.