Frogman

No attempts yetTime limit1sMemory limit128 MB

Problem

A frogman uses special equipment for diving. The equipment carries a cylinder that holds two separate containers: one with oxygen and one with nitrogen. Depending on how long he wants to stay under water and how deep he dives, the frogman needs different amounts of oxygen and nitrogen.

The frogman has a number of cylinders available. Each cylinder is described by its weight and by the volume of gas it contains: a fixed volume of oxygen and a fixed volume of nitrogen. To complete a task the frogman must take some of the cylinders so that their combined oxygen is at least the required amount and their combined nitrogen is at least the required amount. A cylinder is always taken as a whole.

Write a program that reads the required volumes of oxygen and nitrogen, the number of available cylinders and their descriptions, then computes the minimal total weight of the cylinders the frogman has to take to complete the task.

Note: the given set of cylinders always makes it possible to complete the task.

Input

The first line contains two integers tt and aa separated by a single space (1t211 \le t \le 21, 1a791 \le a \le 79): the volumes of oxygen and nitrogen (in litres) needed to complete the task.

The second line contains one integer nn (1n10001 \le n \le 1000): the number of available cylinders.

Each of the next nn lines contains three integers tit_i, aia_i, wiw_i separated by single spaces (1ti211 \le t_i \le 21, 1ai791 \le a_i \le 79, 1wi8001 \le w_i \le 800): the volume of oxygen, the volume of nitrogen, and the weight of the ii-th cylinder. Volumes are given in litres and the weight in decagrams.

Output

Print one integer: the minimal total weight of the cylinders the frogman has to take to complete the task.