#![allow(unused)]
use std::collections::*;
use std::io;
fn take_int() -> usize {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
return input.trim().parse::<usize>().unwrap();
}
fn take_tuple() -> (i64, i64) {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let mut it = input.trim().split_whitespace().map(|x| x.parse::<i64>().unwrap());
(it.next().unwrap(), it.next().unwrap())
}
fn closest_pair(pts: &[(i64, i64)]) -> i64 {
let mut p: Vec<(i64, i64)> = pts.to_vec();
p.sort_unstable();
let mut best = i64::MAX;
let mut active: BTreeSet<(i64, i64)> = BTreeSet::new(); // stored as (y, x)
let mut left = 0;
for i in 0..p.len() {
let (x, y) = p[i];
while left < i && (x - p[left].0) * (x - p[left].0) >= best {
active.remove(&(p[left].1, p[left].0));
left += 1;
}
let h = best.isqrt();
for &(qy, qx) in active.range((y - h, i64::MIN)..=(y + h, i64::MAX)) {
let d = (x - qx) * (x - qx) + (y - qy) * (y - qy);
if d < best {
best = d;
}
}
active.insert((y, x));
}
best
}
fn main() {
let mut n = take_int();
let mut pts: Vec<(i64, i64)> = Vec::with_capacity(n);
for _ in 0..n {
pts.push(take_tuple());
}
let res = closest_pair(&pts);
println!("{res}");
}