/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
Scanner in
=new Scanner
(System.
in); int n = in.nextInt();
int w[][] = new int[n][n];
for( int i = 0 ; i < n ; i++ ){
for( int j = 0 ; j < n ; j++ ){
w[i][j] = in.nextInt();
}
}
for( int k = 0 ; k < n ; k++ ){
for( int i = 0 ; i<n ; i++ ){
for( int j=0 ; j<n ; j++ ){
w
[i
][j
] = Math.
min(w
[i
][j
], w
[i
][k
] + w
[k
][j
]); }
}
}
for( int i = 0 ; i < n ; i++ ){
for( int j = 0 ; j < n ; j++ ){
System.
out.
print(w
[i
][j
] + " "); }
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgSWRlb25lCnsKCXB1YmxpYyBzdGF0aWMgdm9pZCBtYWluIChTdHJpbmdbXSBhcmdzKSB0aHJvd3MgamF2YS5sYW5nLkV4Y2VwdGlvbgoJewoJCQlTY2FubmVyIGluID1uZXcgU2Nhbm5lcihTeXN0ZW0uaW4pOwoJCQlpbnQgbiA9IGluLm5leHRJbnQoKTsKCQkJaW50IHdbXVtdID0gbmV3IGludFtuXVtuXTsJIAoJCQlmb3IoIGludCBpID0gMCA7IGkgPCBuIDsgaSsrICl7CgkJCQlmb3IoIGludCBqID0gMCA7IGogPCBuIDsgaisrICl7CgkJCQkJd1tpXVtqXSA9IGluLm5leHRJbnQoKTsKCQkJCX0KCQkJfQoJCgkJCWZvciggaW50IGsgPSAwIDsgayA8IG4gOyBrKysgKXsKCQkJCWZvciggaW50IGkg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