PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000107. Đồng nghiệp khó chịu (Annoyed Coworkers)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đồng nghiệp khó chịu (Annoyed Coworkers)

Annoyed Coworkers

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

You need hh help requests assigned among cc coworkers. Coworker ii initially has annoyance aia_i, which increases by bib_i for each request assigned to that coworker. Requests may be assigned repeatedly to anyone. Minimize the maximum final annoyance over all coworkers.

Input

Line 1 contains h,ch,c. The following cc lines contain ai,bia_i,b_i.

Output

Print the minimum possible maximum final annoyance.

Subtasks

  • Subtask 1 (20 points): 1≤h≤121\le h\le 12; 1≤c≤1051\le c\le10^5; 1≤ai≤1091\le a_i\le10^9; 1≤bi≤1091\le b_i\le10^9.
  • Subtask 2 (30 points): 1≤h≤30001\le h\le 3000; 1≤c≤1051\le c\le10^5; 1≤ai≤1091\le a_i\le10^9; 1≤bi≤1091\le b_i\le10^9.
  • Subtask 3 (50 points): 1≤h≤1000001\le h\le 100000; 1≤c≤1051\le c\le10^5; 1≤ai≤1091\le a_i\le10^9; 1≤bi≤1091\le b_i\le10^9.

Examples

Input

4 4
1 2
2 3
3 4
4 5

Output

7

Explanation

Assign three requests to coworker 11, raising annoyance to 3,5,73,5,7, and one request to coworker 22, raising annoyance to 55. Others remain at 3,43,4. The maximum is 77, which is optimal.