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

#GD0000097. Làm hài lòng nhiều khách hàng nhất (Keep the Customer Satisfied)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Làm hài lòng nhiều khách hàng nhất (Keep the Customer Satisfied)

Keep the Customer Satisfied

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn orders, order ii needs pip_i consecutive units of processing and must finish by deadline did_i. Only one order can be processed at a time, starting at time zero. You may discard orders. Maximize the number completed on time.

Input

Line 1 contains nn. The following nn lines each contain pi,dip_i,d_i.

Output

Print one integer, the maximum number of orders finished by their deadlines.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le 12; 1≤pi≤1041\le p_i\le10^4; 1≤di≤1041\le d_i\le10^4 for every ii.
  • Subtask 2 (30 points): 1≤n≤15001\le n\le 1500; 1≤pi≤1041\le p_i\le10^4; 1≤di≤1041\le d_i\le10^4 for every ii.
  • Subtask 3 (50 points): 1≤n≤100001\le n\le 10000; 1≤pi≤1041\le p_i\le10^4; 1≤di≤1041\le d_i\le10^4 for every ii.

Examples

Input

4
4 4
3 5
2 7
3 8

Output

3

Explanation

Complete jobs (3,5)(3,5), (2,7)(2,7), (3,8)(3,8) consecutively at times 3,5,83,5,8. Three are possible; all four require 1212 units of work but the latest deadline is 88.