XOR path
Given a matrix of size consisting of integers.
Assume that the rows of the matrix are numbered from top to bottom from to , and the columns are numbered from left to right from to . Let denote the number at the intersection of the -th row and the -th column.
You start your path in the cell and can move only down or right. The path must end in the cell . Let be the integers written in the cells you visited.
The cost of the path is defined by the expression .
Find the path from to with the minimum cost.
Input
The first line contains a single integer — the size of the matrix.
Each of the following lines contains integers .
Output
Output a single integer — the minimum possible cost of the path.
Examples
Note
The expression denotes the bitwise XOR operation applied to the numbers and . This operation is supported in all modern programming languages; for example, in C++ and Java, it is denoted as "^", and in Pascal as "xor".