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

#GD0000069. Máy in trên băng chuyền (Printing Machine)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Máy in trên băng chuyền (Printing Machine)

Printing Machine

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A conveyor brings NN products past a printer. Product ii is within the print range during the inclusive time interval [Ti,Ti+Di][T_i,T_i+D_i]. Printing is instantaneous but the printer requires at least one microsecond between consecutive prints. Each product can be printed at most once. Maximize the number of printed products.

Input

The first line contains NN. Each of the next NN lines contains Ti,DiT_i,D_i in microseconds.

Output

Print the maximum number of products that can be printed.

Subtasks

  • Subtask 1 (20 points): 1≤N≤241\le N\le 24; 1≤Ti,Di≤10181\le T_i,D_i\le10^{18} for every ii; consecutive prints must be at least one microsecond apart.
  • Subtask 2 (30 points): 1≤N≤20001\le N\le 2000; 1≤Ti,Di≤10181\le T_i,D_i\le10^{18} for every ii; consecutive prints must be at least one microsecond apart.
  • Subtask 3 (50 points): 1≤N≤2000001\le N\le 200000; 1≤Ti,Di≤10181\le T_i,D_i\le10^{18} for every ii; consecutive prints must be at least one microsecond apart.

Examples

Input

5
1 1
1 1
2 1
1 2
1 4

Output

4

Explanation

Print products 2,1,3,52,1,3,5 at times 1,2,3,41,2,3,4. Each is in range at its printing time, and successive printings are at least one time unit apart. Five products cannot all be printed under the time windows, so the optimum is 44.