Pokemon Hunt

Pokemon sit on houses along a line, each with a candy value and a deadline; starting at house K, maximize candy collected while walking one house per second.

Medium7Dynamic programmingIntervalsNo attempts yetTime limit1sMemory limit512 MB

Problem

Branimirko plays Pokemon Go a lot. He recently decided to organize a Pokemon catching competition. It is held in Ilica street in Zagreb, and his friend Slavko sponsors it. The reward is candy, of course.

Ilica is the longest street in Zagreb. NN houses stand on one side of the street, numbered 11 through NN. The competition starts at house KK.

Before the competition Branimirko looked at the map and found MM Pokemon. Pokemon ii sits at house AiA_i, is worth BiB_i candy, and can be caught only before TiT_i seconds have passed since the start. The moment TiT_i seconds pass it disappears from the map and cannot be caught any more. No two Pokemon sit at the same house.

Branimirko moves to a neighboring house in one second. At the start, that is at second 00, he stands at house KK. When he reaches a house at a time smaller than the TiT_i of the Pokemon there, he catches that Pokemon and it disappears from the map. Catching takes no time. He may walk over a house he has already visited.

Find the largest amount of candy Branimirko can get.

Input

The first line contains the number of houses NN, the starting house number KK and the number of Pokemon MM (1KN10001 \le K \le N \le 1000, 1M1001 \le M \le 100).

Each of the next MM lines contains AiA_i, BiB_i and TiT_i of one Pokemon (1AiN1 \le A_i \le N, 1Bi1001 \le B_i \le 100, 1Ti20001 \le T_i \le 2000).

The Pokemon are given in increasing order of house number AiA_i.

Output

Print the largest amount of candy Branimirko can get, on one line.

Note

In the first example Branimirko catches the Pokemon at house 3 (5 candy), then the one at house 7 (10 candy), then the one at house 9 (100 candy), for 115 candy in total. He cannot catch the Pokemon at house 1. Walking there from the starting house 5 takes 4 seconds, and that Pokemon disappears the moment 4 seconds pass.