def f(points, l = 0, r = points.size-1)
	if r - l + 1 < 40
		return (l..r).to_a.combination(2).map{|i, j|
			x1, y1 = points[i]
			x2, y2 = points[j]
			(x1 - x2)**2 + (y1 - y2)**2
			}.min
	end
			
	c = (l + r) / 2
	d_l = f(points, l, c)
	d_r = f(points, c + 1, r)
	d = [d_l, d_r].min

	x_c = points[c][0]
	l += 1 until x_c - Math.sqrt(d) < points[l][0]
	return d if l > c
	r -= 1 until points[r][0] < x_c + Math.sqrt(d)
	return d if r <= c

	blocks = {}
	points[c+1..r].each{|x, y|
		(blocks[(y/d).to_i] ||= []) << [x, y]
	}

	ans = d
	points[l..c].each{|x1, y1|
		i = (y1/d).to_i
		[i-1, i, i+1].each{|j|
			next unless blocks[j] 
			blocks[j].each{|x2, y2|
				d2 = (x1 - x2)**2 + (y1 - y2)**2
				ans = d2 if d2 < ans
			}
		}
	}
	ans
end

n = gets.to_i
points = (1..n).map{ gets.split.map(&:to_i) }.sort
p f(points)