All problems

Problem 640

Detonate the Maximum Bombs

Medium · 20 pts · Graph, Breadth-First Search, Geometry

Problem

Each bomb has a position (x, y) and a radius r. When a bomb explodes, every bomb whose centre lies within distance r of its centre (on the circle counts) explodes too, which can set off more bombs in a chain. You may detonate exactly one bomb by hand. Find the largest number of bombs that can explode in total. Bomb i reaches bomb j when (xi - xj)² + (yi - yj)² <= ri²; this relation is not symmetric, so build a directed graph and run a search from every bomb.

Input

The first line contains N. Each of the next N lines contains x, y and r for one bomb.

Output

Print the maximum number of bombs that can be detonated.

Constraints

1 <= N <= 100; 1 <= x, y, r <= 100000

Example input

2
2 1 3
6 1 4

Example output

2

Explanation

The bombs at (2,1) and (6,1) are 4 apart. The first has radius 3, so it cannot reach the second, but the second has radius 4 and does reach the first. Detonating the second bomb explodes both, so the answer is 2.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Checking Existence of Edge Length Limited Paths Next: Count Vowels Permutation