#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
int w[n][n];
for( int i=0 ; i<n ; i++ ){
for( int j=0 ; j<n ; j++ ){
cin >> w[i][j];
}
}
for( int k=0 ; k<n ; k++ ){
for( int i=0 ; i<n ; i++ ){
for( int j=0 ; j<n ; j++ ){
w[i][j] = min(w[i][j], w[i][k]+w[k][j]);
}
}
}
for( int i=0 ; i<n ; i++ ){
for( int j=0 ; j<n ; j++ ){
cout << w[i][j] << " ";
}
cout<<endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCQppbnQgbWFpbigpewoJaW50IG47CgljaW4gPj4gbjsKCWludCB3W25dW25dOwoJZm9yKCBpbnQgaT0wIDsgaTxuIDsgaSsrICl7CgkJZm9yKCBpbnQgaj0wIDsgajxuIDsgaisrICl7CgkJCWNpbiA+PiB3W2ldW2pdOwoJCX0KCX0KCQoJZm9yKCBpbnQgaz0wIDsgazxuIDsgaysrICl7CgkJZm9yKCBpbnQgaT0wIDsgaTxuIDsgaSsrICl7CgkJCWZvciggaW50IGo9MCA7IGo8biA7IGorKyApewoJCQkJd1tpXVtqXSA9IG1pbih3W2ldW2pdLCB3W2ldW2tdK3dba11bal0pOwoJCQl9CgkJfQoJfQoJCglmb3IoIGludCBpPTAgOyBpPG4gOyBpKysgKXsKCQlmb3IoIGludCBqPTAgOyBqPG4gOyBqKysgKXsKCQkJY291dCA8PCB3W2ldW2pdIDw8ICIgIjsKCQl9CgkJY291dDw8ZW5kbDsKCX0KfQ==