TLE '16 Contest 6 (Mock CCC) J5 - Meal Plan


Submit solution


Points:10 (partial)
Time limit:1.0s
Memory limit:256M

Problem type

A first-year student in the University of Fireloo has been given N dollars to pay only for food on campus, also known as his meal plan. The problem is, if he doesn't use up all of his meal plan money, the remaining balance will be lost. So the student wants to use up his meal plan as much as possible.

Every day, the university of Fireloo offers the same B breakfast options, L lunch options, and D dinner options on campus, where the i^{th} breakfast option has an integer cost b_i, the i^{th} lunch option has integer cost l_i, and the i^{th} dinner option has integer cost d_i. The student can use his meal plan only for these options. Each day, the student can order a maximum of one breakfast option, one lunch option, and one dinner option. Also, before ordering lunch, he must have had breakfast on the same day, and before ordering dinner, he must have had lunch on the same day. The student gets hungry very easily, so he must have eaten all three meals before considering breakfast for the next day.

Starting on a new day with no meals eaten yet, what is the lowest possible remaining balance the student can have in his meal plan following these rules? Moreover, how many different ways can he remain with such balance?

Input Specification

The first line will contain N (1 \leq N \leq 2000), the student's current meal plan balance.

The second line will contain space-separated integers B, L, and D (1 \leq B, L, D\leq 50), the number of options for each meal, in that order.

The third line will contain the space-separated integer cost for each of the B breakfast options. You can assume all costs are distinct, and range from 1 to 2000.

The fourth line will contain the space-separated integer cost for each of the L lunch options. You can assume all costs are distinct, and range from 1 to 2000.

The last line will contain the space-separated integer cost for each of the D dinner options. You can assume all costs are distinct, and range from 1 to 2000.

Output Specification

Output two space separated integers: The number of different ways the student can use up his meal plan as much as possible, mod 1\,000\,000\,007, followed by the minimum remaining meal plan balance he could end with. If the student cannot buy anything at all using his meal plan, then there are 0 ways he can use the most of it.

Sample Input

750
2 3 3
100 200
200 400 300
325 300 400

Sample Output

3 25

Explanation for Sample Output

The student can either:

  • pay 100 for breakfast, 300 for lunch, and 325 for dinner;
  • pay 200 for breakfast, 200 for lunch, and 325 for dinner;
  • pay 100 for breakfast, 200 for lunch, 325 for dinner, and 100 for the next breakfast.

Comments

There are no comments at the moment.