Amagi Brilliant Contests runs a business making and hosting contests on its online platform for competitive programmers who want to run their own contests.

After several weeks and dozens of contests later, word got around about how great Amagi Brilliant Contests was, and now ABC is facing an unforeseen problem: business is booming and it has too many potential customers who wish to purchase problemsets!

For each of the customers, there are three possible problem sets to sell to them: Poor, Average, Good. Each problemset has two attributes: , the preparation time, in minutes, and , the monetary worth of the problemset, in dollars. Of course, the names of the problemsets imply that and .

While Amagi Brilliant Contests wants to provide each customer with a Good problemset, it has strict deadlines to meet — namely, ABC has at most minutes in total to prepare problemsets for their customers. In this state of emergency, the management has decided that if necessary, they will sell some of the Poor and Average problemsets in order to make the most money. Sometimes, ABC will even have to turn customers down, if selling to them won't let ABC make the most money.

You are the head of the optimization problems department at Amagi Brilliant Contests, and so you have been tasked with determining the maximum profit ABC can make.

#### Constraints

For each problemset,

For test cases worth 25% of the total marks, .

For test cases worth an additional 25% of the total marks, .

#### Input Specification

The first line of input will have , separated by a single space.

The next lines each contain six integers: for the problemsets offered to that customer.

#### Output Specification

The first and only line of output should contain the maximum amount of money ABC can earn from the customers.

#### Sample Input 1

```
2 300
100 10 200 20 300 30
100 20 400 80 600 120
```

#### Sample Output 1

`40`

#### Explanation for Sample Input 1

ABC will give the first customer an Average problemset and the second customer a Poor problemset. 40 dollars is the most money ABC can make from these two customers.

#### Sample Input 2

```
2 250
100 30 150 30 200 30
50 5 200 10 400 15
```

#### Sample Output 2

`35`

#### Explanation for Sample Input 2

One way to obtain 35 dollars is to give the first customer a Good problemset and the second customer a Poor problemset.

## Comments

You have some nice variable names there. https://dmoj.ca/submission/3101910

How do I fix out of memory error?

Concerning this problem, you only care about the previous DP state. Therefore, there is no need to have an array N by K size. K or 2 by K array with modulo operations to check for previous DP state will suffice.

I have an array of size NT.