#P8779. Range Sum Query with Partial Information

    ID: 21943 Type: Default 1000ms 256MiB

Range Sum Query with Partial Information

Range Sum Query with Partial Information

Consider an integer sequence (A_1, A_2, \ldots, A_N) of length (N). Xiao Lan wants to know the sum of the subarray from index (l) to (r): [ \sum_{i=l}^{r}A_i = A_l + A_{l+1} + \cdots + A_r. ] However, he does not know the value of every element. Instead, he is given (M) partial sums. For the (i)th given information, you are provided three integers (l_i), (r_i) and (S_i) which satisfy [ \sum_{j=l_i}^{r_i}A_j = S_i. ] Your task is to determine the value of the sum (\sum_{j=l}^{r}A_j) for a given query. It is guaranteed that if the sum can be uniquely determined using the provided information, then output the value; otherwise, output UNKNOWN.

inputFormat

The first line contains two integers (N) and (M) separated by a space. Each of the next (M) lines contains three integers (l_i), (r_i) and (S_i) (with (1 \le l_i \le r_i \le N)) representing that (\sum_{j=l_i}^{r_i}A_j = S_i). The last line contains two integers (l) and (r) (with (1 \le l \le r \le N)) representing the query interval.

outputFormat

Output a single line containing the value of (\sum_{j=l}^{r}A_j) if it can be uniquely determined from the given information. Otherwise, output UNKNOWN.

sample

5 3
1 3 6
2 5 10
3 5 7
2 4
5