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

## 문제

There is a housewife who recently won a prize to “shop for free as long as your shopping basket is not full” in a department store.

This housewife is given a shopping basket that can carry a maximal weight of S kilograms.

There are N item types in the department store and the i-th item is worth Vi SGD, weighs Wi kilograms, and there are Ki copies (of exactly same value and weight) of such item i.

For example, there are N = 3 item types: meat, milk, and bread; of which there are: 1 pack of meat, 3 bottles of milk, and 4 loaves of bread (see the last sample test case).

What items should the housewife take to maximize the total value of the items in her shopping basket?

## 입력

The first line of input contains two positive integers, S and N.

The next N lines of input will each contain three integers, where the i-th line contains Vi, Wi and Ki, the value in SGD, weight in kilograms and number of the i-th item respectively.

## 출력

Your program must print to standard output.

Your program should print one integer, representing the maximum total value in SGD of the items that this housewife can take while ensuring the total weight does not exceed S kilograms.

## 제한

• 1 ≤ S ≤ 2000
• 1 ≤ Vi ≤ 1000000
• 1 ≤ Wi ≤ S
• 1 ≤ N ≤ 100000
• 1 ≤ Ki ≤ 109

## 예제 입력 1

15 5
4 12 1
2 1 1
10 4 1
1 1 1
2 2 1


## 예제 출력 1

15


The housewife can take one of items 2, 3, 4, 5 giving a total weight of 1 + 4 + 1 + 2 = 8 and a total value of 2 + 10 + 1 + 2 = 15.

## 예제 입력 2

20 3
5000 15 1
100 1 3
50 1 4


## 예제 출력 2

5400


The housewife take one of item 1, three of item 2 and two of item 3 for a total weight of 15 × 1 + 1 × 3 + 1 × 2 = 20 and a total value of 5000 × 1 + 100 × 3 + 50 × 2 = 5400.