시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 512 MB 1 1 1 100.000%

## 문제

Bobo has a large rectangle with lower left and upper right corners at $(0, 0)$ and $(w, 10^6)$. He also has $n$ small axis-parallel rectangles inside the large rectangle. The weight of the $i$-th rectangle is $v_i$. For each rectangle, either its left border or its right border (but not both) coincides with the left or right side of the large rectangle.

Bobo would like to choose a subset of small rectangles in such a manner that the rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Among all the possibilities, he wants the one with the maximum possible sum of weights.

## 입력

The input contains zero or more test cases, and is terminated by end-of-file. For each test case:

The first line contains two integers $n$ and $w$ ($1 \leq n \leq 2000$, $2 \leq w \leq 10^6$) denoting the number of small rectangles and the width of the large rectangle.

The $i$-th of the following $n$ lines contains five integers $\mathit{type}_i$, $l_i$, $a_i$, $b_i$ and $v_i$ ($\mathit{type}_i \in \{0, 1\}$, $0 \leq a_i < b_i \leq 10^6$, $1 \leq l_i < w$, $0 \leq v_i \leq 10^6$) where $v_i$ is the weight of the $i$-th rectangle. Here, $\mathit{type}_i = 0$ means the lower left and upper right corner of the $i$-th rectangle are $(0, a_i)$ and $(l_i, b_i)$, while $\mathit{type}_i = 1$ means the lower left and upper right corner of the $i$-th rectangle are $(w - l_i, a_i)$ and $(w, b_i)$.

It is guaranteed that for all $1 \leq i < j \leq n$, $a_i \ne a_j$, $a_i \ne b_j$, $b_i \ne a_j$ and $b_i \ne b_j$. Additionally, the sum of all $n$ does not exceed $2000$.

## 출력

For each test case, output an integer which denotes the maximum sum of weights.

## 예제 입력 1

3 10
0 3 1 6 12
0 3 3 4 100
1 9 2 5 11
3 10
0 3 1 6 12
0 1 3 4 5
1 9 2 5 11
6 5
1 1 17 32 4
0 3 1 18 7
1 3 4 8 12
1 2 15 20 14
1 1 30 33 16
1 4 2 16 13


## 예제 출력 1

100
16
42


## 힌트

For the third test, Bobo can choose the $3$-rd, $4$-th and $5$-th rectangles.