#include <bits/stdc++.h>
#define rep(_i, _j) for(int _i = 1; _i <= _j; ++_i)
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef double DB;
using namespace std;
const int maxn = 500 + 20;
int limit, n, g[maxn][maxn], link[maxn];
bool vis[maxn];
bool dfs(int u) {
for(int v = 1; v <= n; ++v) {
if(g[u][v] <= limit && !vis[v]) {
vis[v] = true;
if(link[v] == -1 || dfs(link[v])) {
link[v] = u;
return true;
}
}
}
return false;
}
bool check() {
for(int i = 1; i <= n; ++i) {
link[i] = -1;
}
for(int i = 1; i <= n; ++i) {
memset(vis, false, sizeof vis);
if(!dfs(i)) return false;
}
return true;
}
int main() {
scanf("%d", &n);
int low = -1e6, up = 1e6;
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
scanf("%d", &g[i][j]);
}
}
while(low < up) {
limit = (low + up) >> 1;
if(check()) {
up = limit;
} else {
low = limit + 1;
}
}
printf("%d\n", up);
limit = up;
check();
for(int i = 1; i <= n; ++i) {
printf("%d %d\n", link[i], i);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgcmVwKF9pLCBfaikgZm9yKGludCBfaSA9IDE7IF9pIDw9IF9qOyArK19pKQpjb25zdCBpbnQgSU5GID0gMHgzZjNmM2YzZjsKdHlwZWRlZiBsb25nIGxvbmcgTEw7CnR5cGVkZWYgZG91YmxlIERCOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY29uc3QgaW50IG1heG4gPSA1MDAgKyAyMDsKCmludCBsaW1pdCwgbiwgZ1ttYXhuXVttYXhuXSwgbGlua1ttYXhuXTsKYm9vbCB2aXNbbWF4bl07CmJvb2wgZGZzKGludCB1KSB7Cglmb3IoaW50IHYgPSAxOyB2IDw9IG47ICsrdikgewoJCWlmKGdbdV1bdl0gPD0gbGltaXQgJiYgIXZpc1t2XSkgewoJCQl2aXNbdl0gPSB0cnVlOwoJCQlpZihsaW5rW3ZdID09IC0xIHx8IGRmc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