class Array
	def bsearch_first_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_first_index(l, c-1, &pred) || c
		else
			bsearch_first_index(c+1, r, &pred)
		end
	end

	def bsearch_first_item(l = 0, r = size - 1, &pred)
		i = bsearch_first_index(l, r, &pred)
		i ? self[i] : nil
	end

	def bsearch_last_index(l = 0, r = size - 1, &pred)
		return nil if l > r
		c = (l + r) / 2 
		if pred[self[c]]
			bsearch_last_index(c+1, r, &pred) || c
		else
			bsearch_last_index(l, c-1, &pred)
		end
	end

	def bsearch_last_item(l = 0, r = size - 1, &pred)
		i = bsearch_last_index(l, r, &pred)
		i ? self[i] : nil
	end
end

n = gets.to_i

min_cost = Float::INFINITY

normalized = Hash.new(Float::INFINITY)
n.times do
	a, b, cost = gets.split.map(&:to_i)
	next if a == 0 && b == 0
	
	if a == 0
		b /= b.abs
	elsif b == 0
		a /= a.abs
	else
		b /= a.abs
		a /= a.abs
	end
	key = [a, b]
	normalized[key] = cost if cost < normalized[key]
end

if normalized.size < 3
	puts -1
	exit
end

pair_cost = []
normalized.each do |(a, b), cost|
	if normalized[[-a, -b]] != Float::INFINITY
		pair_cost << cost
	end
end
if pair_cost.size >= 4
	min_cost = pair_cost.sort[0..3].inject(:+) / 2
end

include Math
def angle(x, y)
	t = atan2(y, x)
	t < 0 ? 2 * PI + t : t
end

class MinMaxSegmentTree
	def initialize(arr, l = 0, r = arr.size - 1)
		@l = l
		@r = r
		if l == r
			@min = @max = arr[l]
		else
			c = (l + r) / 2
			@left_child = self.class.new(arr, l, c)
			@min = @left_child.min
			@max = @left_child.max
			@right_child = self.class.new(arr, c+1, r)
			r_min, r_max = @right_child.min, @right_child.max
			@min = r_min if r_min < @min
			@max = r_max if r_max > @max
		end
	end

	def query_min(l = @l, r = @r)
		return @min if l == @l && r == @r
		if r <= @left_child.r
			return @left_child.query_min(l, r)
		elsif @right_child.l <= l
			return @right_child.query_min(l, r)
		else
			lm = @left_child.query_min(l, @left_child.r)
			rm = @right_child.query_min(@right_child.l, r)
			return lm < rm ? lm : rm
		end
	end

	attr_reader :min, :max, :l, :r
end

tickets = normalized.keys.sort_by{|a, b| angle(a, b)}
tree = MinMaxSegmentTree.new(tickets.map {|a, b| normalized[[a, b]]})
EPS = 1e-5
(0..tickets.size-3).each do |i|
	t1 = angle(*tickets[i])
	j = tickets.bsearch_last_index {|a, b| angle(a, b) < t1 + PI - EPS}
	next if !j || j == i
	k = tickets.bsearch_first_index {|a, b| angle(a, b) > t1 + PI + EPS}
	next if !k || k == i
	cost = normalized[tickets[i]] + tree.query_min(i+1, j) + tree.query_min(k, tickets.size-1)
	min_cost = cost if cost < min_cost
end

p min_cost