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 = Rational(b, a.abs)
		a /= a.abs
	end
	key = [Rational(a, 1), Rational(b, 1)]
	normalized[key] = cost if cost < normalized[key]
end

if normalized.size < 3
	puts -1
	exit
end

pair_cost = []
normalized.each do |(a, b), c1|
	if (c2 = normalized[[-a, -b]]) != Float::INFINITY
		pair_cost << c1 + c2
	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

tickets = normalized.keys.sort_by{|a, b| angle(a, b)}

table = [tickets.map {|a, b| normalized[[a, b]]}]
(1..log2(tickets.size).to_i).each do |k|
	table[k] = []
	(0..table[0].size-1).each do  |i|
		table[k][i] = table[k-1][i]
		j = i + (1 << k-1)
		if j < table[0].size && table[k-1][j] < table[k][i]
			table[k][i] = table[k-1][j]
		end
	end
end

EPS = 1e-10
(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 = j + 1
	k += 1 until k >= tickets.size || angle(*tickets[k]) > t1 + PI + EPS
	next if k >= tickets.size

	c1 = normalized[tickets[i]]
	l = log2(j - i).to_i
	c2 = [table[l][i], table[l][j-2**l+1]].min
	l = log2(tickets.size - k).to_i
	c3 = [table[l][k], table[l][tickets.size-2**l]].min
	cost = c1 + c2 + c3
	min_cost = cost if cost < min_cost
end

puts min_cost