106_C. Buns
Lavrenty, a baker, is going to make several buns with stuffings and sell them.

Lavrenty has n grams of dough as well as m different stuffing types. The stuffing types are numerated from 1 to m. Lavrenty knows that he has ai grams left of the i-th stuffing. It takes exactly bi grams of stuffing i and ci grams of dough to cook a bun with the i-th stuffing. Such bun can be sold for di tugriks.

Also he can make buns without stuffings. Each of such buns requires c0 grams of dough and it can be sold for d0 tugriks. So Lavrenty can cook any number of buns with different stuffings or without it unless he runs out of dough and the stuffings. Lavrenty throws away all excess material left after baking.

Find the maximum number of tugriks Lavrenty can earn.

Input

The first line contains 4 integers n, m, c0 and d0 (1 ≤ n ≤ 1000, 1 ≤ m ≤ 10, 1 ≤ c0, d0 ≤ 100). Each of the following m lines contains 4 integers. The i-th line contains numbers ai, bi, ci and di (1 ≤ ai, bi, ci, di ≤ 100).

Output

Print the only number — the maximum number of tugriks Lavrenty can earn.

Examples

Input

10 2 2 1
7 3 2 100
12 3 1 10


Output

241

Input

100 1 25 50
15 5 20 10


Output

200

Note

To get the maximum number of tugriks in the first sample, you need to cook 2 buns with stuffing 1, 4 buns with stuffing 2 and a bun without any stuffing.

In the second sample Lavrenty should cook 4 buns without stuffings.
```python
from sys import stdin, setrecursionlimit


def arr_inp(n):
    if n == 1:
        return [int(x) for x in stdin.readline().split()]
    elif n == 2:
        return [float(x) for x in stdin.readline().split()]
    else:
        return list(stdin.readline()[:-1])


def dp(i, rem):
    if rem == 0:
        return 0
    if i >= len(arr):
        if rem:
            return d0 * (rem // c0)
        else:
            return 0

    if mem[i][rem] != -1:
        return mem[i][rem]

    ans1, ans2, ans3 = dp(i + 1, rem), 0, 0

    if rem - arr[i][0] >= 0:
        ans2 = arr[i][1] + dp(i + 1, rem - arr[i][0])
    if rem - c0 >= 0:
        ans3 = d0 + dp(i + 1, rem - c0)

    mem[i][rem] = max(ans1, ans2, ans3)
    return mem[i][rem]


def main():
    ans = 0
    for j in range(len(arr)):
        mem[j][n] = 0

    if arr:
        if n - arr[0][0] >= 0:
            mem[0][n - arr[0][0]] = arr[0][1]

        for j in range(1, len(arr)):
            for i in range(n + 1):
                mem[j][i] = mem[j - 1][i]

                if i + arr[j][0] <= n:
                    if mem[j - 1][i + arr[j][0]] != -1:
                        mem[j][i] = max(mem[j][i], mem[j - 1][i + arr[j][0]] + arr[j][1])
                        ans = max(ans, mem[j][i])

    # print(dp(0, n))
    for j in range(len(arr) + 1):
        for i in range(n, -1, -1):
            ext = (i // c0) * d0
            if mem[j][i] == -1:
                mem[j][i] = ext
            else:
                mem[j][i] += ext
            ans = max(ans, mem[j][i])
    print(ans)


if __name__ == '__main__':
    n, m, c0, d0 = arr_inp(1)
    staff, arr = [arr_inp(1) for i in range(m)], []

    for a in staff:
        arr.extend([[a[2], a[3]] for i in range(a[0] // a[1])])

    mem = [[-1 for i in range(n + 1)] for j in range(len(arr) + 1)]
    main()

```