atcoder#ABC257D. [ABC257D] Jumping Takahashi 2

[ABC257D] Jumping Takahashi 2

Score : 400400 points

Problem Statement

There are NN trampolines on a two-dimensional planar town where Takahashi lives. The ii-th trampoline is located at the point (xi,yi)(x_i, y_i) and has a power of PiP_i. Takahashi's jumping ability is denoted by SS. Initially, S=0S=0. Every time Takahashi trains, SS increases by 11.

Takahashi can jump from the ii-th to the jj-th trampoline if and only if:

  • PiSxixj+yiyjP_iS\geq |x_i - x_j| +|y_i - y_j|.

Takahashi's objective is to become able to choose a starting trampoline such that he can reach any trampoline from the chosen one with some jumps.

At least how many times does he need to train to achieve his objective?

Constraints

  • 2N2002 \leq N \leq 200
  • 109xi,yi109-10^9 \leq x_i,y_i \leq 10^9
  • 1Pi1091 \leq P_i \leq 10^9
  • (xi,yi)(xj,yj) (ij)(x_i, y_i) \neq (x_j,y_j)\ (i\neq j)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

x1x_1 y1y_1 P1P_1

\vdots

xNx_N yNy_N PNP_N

Output

Print the answer.

4
-10 0 1
0 0 5
10 0 1
11 0 1
2

If he trains twice, S=2S=2, in which case he can reach any trampoline from the 22-nd one.

For example, he can reach the 44-th trampoline as follows.

  • Jump from the 22-nd to the 33-rd trampoline. (Since P2S=10P_2 S = 10 and x2x3+y2y3=10|x_2-x_3| + |y_2-y_3| = 10, it holds that P2Sx2x3+y2y3P_2 S \geq |x_2-x_3| + |y_2-y_3|.)
  • Jump from the 33-rd to the 44-th trampoline. (Since P3S=2P_3 S = 2 and x3x4+y3y4=1|x_3-x_4| + |y_3-y_4| = 1, it holds that P3Sx3x4+y3y4P_3 S \geq |x_3-x_4| + |y_3-y_4|.)
7
20 31 1
13 4 3
-10 -15 2
34 26 5
-2 39 4
0 -50 1
5 -20 2
18