| MITIT Spring 2026 Invitationals Finals |
|---|
| Закончено |
Busy Beaver downloaded a new game on his phone and needs your help to play it!
In this game, a level consists of $$$N^2$$$ starting fruits in a line, each of a type numbered $$$1$$$ through $$$N$$$, with $$$N$$$ fruits of each type. A move consists of the following:
You are given an array of $$$N^2$$$ integers $$$a_1, \dots, a_{N^2}$$$, each in the range $$$[0, N]$$$. Count the number of ways to replace each $$$0$$$ in the array with an integer in $$$[1, N]$$$, so that the resulting sequence is a winnable level. Output the answer modulo $$$10^9 + 7$$$.
The first line contains a single integer $$$N$$$ ($$$2 \le N \le 11$$$).
The second line contains $$$N^2$$$ space-separated integers $$$a_1, \dots, a_{N^2}$$$ ($$$0 \le a_i \le N$$$).
It is guaranteed that each value in $$$[1, N]$$$ appears at most $$$N$$$ times in the array $$$a$$$.
Output a single nonnegative integer: the number of possible winnable levels modulo $$$10^9 + 7$$$.
There are three subtasks for this problem.
20 0 1 0
2
41 0 0 0 0 1 0 0 0 0 0 0 0 0 0 3
30608
In the first sample, we count two winnable levels:
| Название |
|---|


