QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 512 MB مجموع النقاط: 100

#4650. Triangle Rotation

الإحصائيات

The image above shows a grid of size $N \times M$. Each cell $(i, j)$ (where $1 \le i \le N$ and $1 \le j \le M$) contains a non-negative integer $A_{i, j}$.

You start at cell $(1, 1)$ and want to reach cell $(N, M)$. In each step, you can move to an adjacent cell (up, down, left, or right). You cannot visit the same cell more than once in a single path.

Let the sequence of cells visited be $(r_1, c_1), (r_2, c_2), \dots, (r_k, c_k)$, where $(r_1, c_1) = (1, 1)$ and $(r_k, c_k) = (N, M)$. The cost of the path is defined as the bitwise XOR sum of the values in the visited cells: $A_{r_1, c_1} \oplus A_{r_2, c_2} \oplus \dots \oplus A_{r_k, c_k}$.

Find the maximum possible cost of a path from $(1, 1)$ to $(N, M)$.

Input

The first line contains two integers $N$ and $M$ ($1 \le N, M \le 5$).

The next $N$ lines each contain $M$ integers, representing the grid $A$. Each $A_{i, j}$ satisfies $0 \le A_{i, j} \le 10^9$.

Output

Output a single integer representing the maximum possible XOR sum.

Examples

Input 1

2 2
1 2
4 8

Output 1

15

Input 2

3 3
1 0 0
0 0 0
0 0 1

Output 2

1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.