n = gets.to_i

ticket = Hash.new(Float::INFINITY)
(1..n).each do
	a, b, c = gets.split.map(&:to_i)
	next if a == 0 && b == 0
	if a == 0
		a = Rational(0)
		b = Rational(b, b.abs)
	else
		b = Rational(b, a.abs)
		a = Rational(a, a.abs)
	end
	key = [a, b]
	ticket[key] = c if c < ticket[key]
end

pairs = []
ticket.each do |(a1, b1), c1|
	if (c2 = ticket[[-a1, -b1]]) != Float::INFINITY
		pairs << c1 + c2 if ([a1, b1] <=> [-a1, -b1]) == -1
	end
end

min = Float::INFINITY
if pairs.size >= 2
	min = pairs.sort[0..1].inject(:+)
end

include Math

def normalize(a)
	a -= 2 * PI until a <= 0
	a += 2 * PI until a >= 0
	a
end

angles = ticket.map {|(a, b), c| [normalize(atan2(b, a) + PI * 1.1), c]}

def f(angles, min)
	g = angles.group_by {|a, c| (a * 3/ PI).to_i % 6}
	mins = (0..5).map do |i|
		if g[i]
			g[i].map(&:last).min
		else
			Float::INFINITY
		end
	end
	
	c = mins[0] + mins[2] + mins[4]
	min = c if c < min
	c = mins[1] + mins[3] + mins[5]
	min = c if c < min

	(0..5).each do |i|
		ary = (g[i] || []) + (g[(i+1)%6] || [])+ (g[(i+3)%6] || [])+ (g[(i+4)%6] || [])
		next if ary.size < 3

		t1 = [mins[i], mins[(i+1)%6]].min * 2 + [mins[(i+3)%6], min[(i+4)%6]].min
		t2 = [mins[i], mins[(i+1)%6]].min + [mins[(i+3)%6], min[(i+4)%6]].min * 2
		t = [t1, t2].min
		next if t >= min

		if ary.size == 3
			b = ary.map(&:first).sort
			b << b[0] + 2 * PI
			if b.each_cons(2).all? {|r1, r2| r2 - r1 < PI}
				t = ary.map(&:last).inject(:+)
				min = t if t < min
			end
			next
		end

		zoomed = 
			(g[i] || []).map {|a, c| [normalize((normalize(a-i*PI/3) - PI / 3) * 1.5 + PI / 3), c]} +
			(g[(i+1)%6]||[]).map {|a, c| [normalize((normalize(a-i*PI/3) - PI / 3) * 1.5 + PI / 3), c]} +
			(g[(i+3)%6]||[]).map {|a, c| [normalize((normalize(a-i*PI/3) - PI) * 1.5 + PI), c]} + 
			(g[(i+4)%6]||[]).map {|a, c| [normalize((normalize(a-i*PI/3) - PI) * 1.5 + PI), c]}
		r = f(zoomed, min)
		min = r if r < min
	end

	min
end

c = f(angles, min)
puts c == Float::INFINITY ? -1 : c