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

#FW0000052. Takahashi nhảy xa 2 (Jumping Takahashi 2)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Takahashi nhảy xa 2 (Jumping Takahashi 2)

Jumping Takahashi 2

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Trampoline i is located at (x_i,y_i) and has power p_i. With integer training level S, a jump i to j is possible if S*p_i is at least their Manhattan distance. Minimize S so that some starting trampoline can reach every other trampoline.

Input

First n; then n lines x_i y_i p_i.

Output

Print the minimum required nonnegative integer S.

Subtasks

  • Subtask 1 (40 points): 2≤n≤7, ∣xi∣,∣yi∣≤20, 1≤pi≤102\le n\le 7,\ |x_i|,|y_i|\le 20,\ 1\le p_i\le 10. All coordinates (x_i,y_i) are pairwise distinct. All input values are integers.
  • Subtask 2 (60 points): $2\le n\le 200,\ |x_i|,|y_i|\le 10^9,\ 1\le p_i\le 10^9$. All coordinates (x_i,y_i) are pairwise distinct. All input values are integers.

Examples

Input

3
0 0 1
2 0 1
4 0 1

Output

2

Explanation

At S=1 no jump can cross the two-unit gap. At S=2, starting at trampoline 1 reaches all via 1→2→3.