QOJ.ac

QOJ

Time Limit: 4 s Memory Limit: 256 MB Total points: 100

#3224. Directions

Statistics

Initially, Snuke can’t move at all. There are $n$ tickets, and the price of the $i$-th ticket is $p_i$. If Snuke buys the $i$-th ticket, for all points $(x, y)$ and a nonnegative number $t$, he can move from $(x, y)$ to $(x + ta_i, y + tb_i)$. Snuke wants to buy tickets and he wants to be able to travel between any two points. Compute the minimal possible total price of the tickets he must buy.

Input

First line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$). Then $n$ lines follow; $i$’th of these lines contains three integers $a_i$, $b_i$, $p_i$ ($-10^9 \le a_i, b_i \le 10^9$, $1 \le p_i \le 10^9$).

Output

Print the minimal possible total price of the tickets he must buy in order to be able to move between any two points. If this is impossible, print $-1$ instead.

Examples

Input 1

7
0 3 1
0 3 2
1 -1 2
0 0 1
-2 4 1
-4 0 1
2 1 2

Output 1

4

Input 2

2
1 2 3
4 5 6

Output 2

-1

Note

In the Sample 1 you can, for example, buy tickets 1, 3, 6.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.