题目描述
Problem Description
Once upon a time, a rabbit tried to write the first $ N $ rows of Pascal's triangle. Let $ C[i][j] $ be the value written in the $ j $-th position of the $ i $-th row from the top ($0 \le i < N$, $0 \le j \le i$). The rabbit attempted to calculate each $ C[i][j] $ using the following procedure:
for i = 0 to N - 1:
C[i][0] = C[i][i] = 1
for j = 1 to i - 1:
C[i][j] = C[i - 1][j - 1] + C[i - 1][j]
However, the rabbit made exactly one mistake in the addition (in the 4th line of the pseudocode) and ended up with a larger integer than the correct sum.
Furthermore, over time, some of the integers written by the rabbit have disappeared.
You are given integers $ A_{i,j} $ ($0 \le i < N$, $0 \le j \le i$) representing the information about the triangle written by the rabbit.
- When $ A_{i,j} = 0 $, the integer written in the $ j $-th position of the $ i $-th row from the top is unknown.
- When $A_{i,j} \ne 0$, the integer written in the $ j $-th position of the $ i $-th row from the top is $ A_{i,j} $.
Determine which $ (i, j) $ the rabbit made a mistake in the addition (which $ C[i][j] $ calculation). If there are multiple possible $ (i, j) $ or if there is an error and no such $ (i, j) $ exists, report accordingly.
Input Format
$ N $ $ A_{0,0} $ $ A_{1,0} $ $ A_{1,1} $ $\vdots$ $ A_{N-1,0} $ $ A_{N-1,1} $ $\cdots$ $ A_{N-1,N-1} $
Output Format
Output the $ (i, j) $ where the rabbit made a mistake in the addition in the order of $ i $, $ j $. If there are multiple possible $ (i, j) $, output AMBIGUOUS. If no such $ (i, j) $ exists, output IMPOSSIBLE.
Sample Input and Output
Sample Input #1
6
1
1 1
1 0 1
1 3 0 1
1 0 7 0 1
1 0 11 0 6 1
Sample Output #1
3 2
Sample Input #2
4
1
1 1
1 0 1
1 0 0 1
Sample Output #2
AMBIGUOUS
Sample Input #3
4
1
1 1
1 0 1
1 4 5 1
Sample Output #3
IMPOSSIBLE
Notes/Hints
Constraints
- $1 \le N \le 500$.
- $0 \le A_{i,j} \le 10^9$.
- For $i = 0, 1, \ldots, N - 1$, $ A_{i,0} = A_{i,i} = 1 $.
Partial Points
- If you solve the dataset satisfying $N \le 50$, you will be awarded $ 20 $ points.
- If you solve the dataset without additional constraints, you will be awarded an additional $ 80 $ points.
Sample Explanation 1
In this case, the triangle written by the rabbit before the integers disappeared could have been as follows. The rabbit mistakenly calculated $ 2 + 1 $ as $ 4 $ when calculating $ C[3][2] $, so output $ (i, j) = (3, 2) $.
1
1 1
1 2 1
1 3 4 1
1 4 7 5 1
1 5 11 12 6 1
Sample Explanation 2
All the addition places have disappeared, so there is a possibility of error at any location.
Sample Explanation 3
The given triangle is inconsistent with Pascal's triangle, so it is impossible to determine the correct location of the mistake.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分