import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto n = readln.strip.to!int;
	int k = 0;
	int [] [] a;
	n.iota.each !(_ => a ~= readln.split.map!(to!int).array);
	n.iota.each !(k =>
		n.iota.each !(i =>
			n.iota.each !(j =>
				a[i][j] = min (a[i][j], a[i][k] + a[k][j])
			)
		)
	);
	a.map !(b => b.minPos!q{a > b}.front).minPos!q{a > b}.front.writeln;
}
