#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
#define CY 505
#define NODE 1005

int ar[CY][CY], f[CY], r[CY];
int N, idx;

void input(int n) {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			scanf("%d", &ar[i][j]);
		}
	}
}

void init_set(int n) {
	for (int i = 0; i < n; ++i) {
		f[i] = i;
		r[i] = 0;
	}
}

int find_set(int u) {
	if (u != f[u])
		f[u] = find_set(f[u]);
	return f[u];
}

void union_set(int u, int v) {
	if (r[u] >= r[v]) {
		if (r[u] == r[v])
			r[u]++;
		f[v] = u;
	} else {
		f[u] = v;
	}
}

void solve(int n) {
	idx = 0;
	for (int k = 0; k < 31; ++k) {
		int p = 1 << k;
		init_set(2 * n);
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (i == j)
					continue;
				int num = p & ar[i][j];
				if ((i & 1) && (j & 1)) {
					if (num) {
						int u = find_set(f[i]);
						int v = find_set(f[j * 2]);
						if (u != v) {
							union_set(u, v);
						}
						int u = find_set(f[i * 2]);
						int v = find_set(f[j]);
						if (u != v) {
							union_set(u, v);
						}
					} else {
						int u = find_set(f[i]);
						int v = find_set(f[j]);
						if (u != v) {
							union_set(u, v);
						}
					}
				} else if ((i & 1) == 0 && (j & 1) == 0) {
					if (num) {
						int u = find_set(f[i * 2]);
						int v = find_set(f[j * 2]);
						if (u != v) {
							union_set(u, v);
						}
					} else {
						int u = find_set(f[i * 2]);
						int v = find_set(f[j]);
						if (u != v) {
							union_set(u, v);
						}
						int u = find_set(f[i]);
						int v = find_set(f[j * 2]);
						if (u != v) {
							union_set(u, v);
						}
					}
				} else {
					if (num) {
						int u = find_set(f[i * 2]);
						int v = find_set(f[j]);
						if (u != v) {
							union_set(u, v);
						}
						int u = find_set(f[i]);
						int v = find_set(f[j * 2]);
						if (u != v) {
							union_set(u, v);
						}
					} else {
						int u = find_set(f[i]);
						int v = find_set(f[j]);
						if (u != v) {
							union_set(u, v);
						}
						int u = find_set(f[i * 2]);
						int v = find_set(f[j * 2]);
						if (u != v) {
							union_set(u, v);
						}
					}
				}
			}
		}
		sort(e, e + idx, cmp);
	}
}

int main(void) {
	while (~scanf("%d", &N)) {
		input(N);
		solve(N);
	}
	return 0;
}