public static void main(String args[]) throws Exception {
		BufferedReader in  = new BufferedReader(new InputStreamReader(System.in));
		int length = Integer.parseInt(in.readLine());
		int[][] array = new int[length][length];
		
		String[] strArray = null;
		
		for (int i = 0; i < length; i++) {
			strArray = in.readLine().split(" ");
			for (int j = 0; j < strArray.length; j++) {
				array[i][j] = Integer.parseInt(strArray[j]);
			}
		}
		
		calculateBasins(array);
	}