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.
The first line contains two integers t and a separated by a single space (1≤t≤21, 1≤a≤79): the volumes of oxygen and nitrogen (in litres) needed to complete the task.
The second line contains one integer n (1≤n≤1000): the number of available cylinders.
Each of the next n lines contains three integers ti, ai, wi separated by single spaces (1≤ti≤21, 1≤ai≤79, 1≤wi≤800): the volume of oxygen, the volume of nitrogen, and the weight of the i-th cylinder. Volumes are given in litres and the weight in decagrams.
Print one integer: the minimal total weight of the cylinders the frogman has to take to complete the task.