Hi, I'm here again requesting your help. `_(xз」∠)_`

This time it is a problem I encountered five years ago, and I still don't know its source.

Here is the problem:

**We call a square grid of non-negative integers beautiful if no matter how we pick elements such that there is exactly one element picked in each row and each column, the sum of these elements is always the same.**

**You are asked to count the number of different $$$n \times n$$$ beautiful grids of non-negative integers, given the values of some places in the grid.**

**$$$1 \leq n \leq 50$$$, each given value is in $$$[0, 9]$$$ and it is guaranteed that the answer is not infinite.**

For example, the number of beautiful grids with the following restriction is $$$24$$$.

```
0 ? ? ?
? 1 ? ?
? ? 2 ?
? ? ? 3
```

Tips: It can be reduced to counting the number of integer solutions $$$(x_1, x_2, \ldots, x_n)$$$ such that $$$0 \leq x_i \leq a_i$$$ ($$$a_i \leq 18$$$) for each $$$i$$$, and $$$x_i \leq x_j + w_{i, j}$$$ ($$$0 \leq w_{i, j} \leq 9$$$) for each $$$i, j$$$ ($$$i \neq j$$$).