Hiding Acorns

Given K arithmetic-progression rules marking boxes, find the box number where the D-th acorn is placed, counting boxes in increasing order.

Medium6Binary searchPrefix sumMathNo attempts yetTime limit1sMemory limit128 MB

Problem

Suhyeong won DD acorns as the first prize at the HEPC contest. To keep the other squirrels from taking them, he hides every acorn in NN boxes numbered 1 through NN.

There are too many boxes for him to remember which ones hold acorns, so he writes rules instead. A rule is three numbers AA, BB, CC, and it means put one acorn into box AA, box A+CA+C, box A+2CA+2C, and so on, using every such box that does not go past box BB. He is afraid that one rule gives away everything, so he writes KK of them.

For example, take a rule that runs from box 100 to box 150 in steps of 10 and a rule that runs from box 110 to box 150 in steps of 15. Acorns then go into boxes 100, 110, 120, 125, 130, 140 and 150, and boxes 110 and 140 hold two acorns each.

A box holds any number of acorns. Suhyeong fills the positions marked by the rules one acorn at a time, in increasing order of box number, until all DD acorns are placed. Print the number of the box that receives the last acorn.

Input

The first line contains the number of boxes NN, the number of rules KK and the number of acorns DD, separated by spaces. (1N1,000,0001 \le N \le 1{,}000{,}000, 1K10,0001 \le K \le 10{,}000, 1D1,000,000,0001 \le D \le 1{,}000{,}000{,}000)

Each of the next KK lines contains three integers AA, BB and CC describing one rule, separated by spaces. (1CABN1 \le C \le A \le B \le N)

DD is at most the total number of positions marked by the rules.

Output

Print the number of the box that receives the last acorn.