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

#GD0000087. Những người đốn gỗ (Woodcutters)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Những người đốn gỗ (Woodcutters)

Woodcutters

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn trees at strictly increasing coordinates x1<⋯<xnx_1<\cdots<x_n, with heights hi>0h_i>0. Each tree may remain standing at xix_i or be felled left to occupy [xi−hi,xi][x_i-h_i,x_i], or right to occupy [xi,xi+hi][x_i,x_i+h_i]. No fallen tree may overlap the occupied position or interval of another tree, including touching endpoints. Maximize the number of felled trees.

Input

The first line contains nn. Each of the next nn lines contains xi,hix_i,h_i in strictly increasing xix_i order.

Output

Print the maximum number of trees that can be felled.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; 1≤x1<⋯<xn≤1091\le x_1<\cdots<x_n\le10^9; 1≤hi≤1091\le h_i\le10^9.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le2000; 1≤x1<⋯<xn≤1091\le x_1<\cdots<x_n\le10^9; 1≤hi≤1091\le h_i\le10^9.
  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤x1<⋯<xn≤1091\le x_1<\cdots<x_n\le10^9; 1≤hi≤1091\le h_i\le10^9.

Examples

Input

5
1 2
2 1
5 2
10 9
19 1

Output

4

Explanation

Fell the tree at 11 left, at 22 right, at 55 right and at 1919 right; leave the tree at 1010 standing. Four trees can be felled, and the greedy process shows this is maximal.