logo AlgoBeat OnlineJudge
登录 注册

#216110. [ICPC 2021 NAC] You be The Judge, Again

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

You are a judge, again! The contest you’re judging includes the following problem:

“You have one L-shaped triomino of each of different colors. Tile a by grid using each of these triominos such that there is exactly one blank square and all other squares are covered by exactly one square of such a triomino. All triominos must be used.”

Your team is to write a checker for this problem. Validation of the input values and format has already taken place. You will be given a purported tiling of a by grid, where each square in the grid is either or a positive integer from to representing one of the colors. Determine if it is, indeed, a covering of the grid with unique triominos and a single empty space.

L-shaped triominos look like this:

:::align{center} :::

输入格式

The first line of input contains a single integer (), which is the of the description.

Each of the next lines contains integers (), where represents an empty space, and any positive number is a unique identifier of a triomino.

输出格式

Output a single integer, which is if the given grid is covered with unique triominos and a single empty space. Otherwise, output .

样例

样例输入 1

2
1 1 2 2
1 3 3 2
4 4 3 5
4 0 5 5

样例输出 1

1

样例输入 2

1
1 1
1 1

样例输出 2

0