#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<vector<int>> a(n, vector<int>(n));
vector<int> deg(n);
int b = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
cin >> a[i][j];
deg[i] += a[i][j];
if (deg[i] > deg[b]) {
b = i;
}
}
}
if (deg[b] == n - 1) {
cout << -1;
return 0;
}
vector<array<int, 2>> color = {{1, 2}, {3, 1}};
cout << 3 << "\n";
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (!a[i][j]) {
cout << 0 << " ";
continue;
}
cout << color[a[b][i]][a[b][j]] << " ";
}
cout << "\n";
}
return 0;
}