| 2024 ICPC Belarus Regional Contest |
|---|
| Finished |
The Emperor of Byteland loves to stroll through the inner courtyard of his palace on summer evenings. However, he recently grew tired of the usual sights and came up with a brilliant idea: to instruct his courtiers to paint the grass! To make the result fascinating, he devised intricate rules for selecting the area of grass to be painted.
The inner courtyard is a rectangle measuring $$$n \times m$$$ meters, divided into $$$1 \times 1$$$ meter squares. Two random points are chosen inside this rectangle, after which the rectangle with opposite corners at the given points and sides parallel to the sides of the courtyard is designated for painting the grass.
Each of the two points is selected according to the following procedure. Each $$$1 \times 1$$$ meter square located in the $$$i$$$-th row and $$$j$$$-th column is assigned a weight $$$p_{i,j}$$$. Let $$$P = \sum_{i=1}^{n}{\sum_{j=1}^{m}{p_{i,j}}}$$$. First, one of the squares is chosen with a probability of $$$\frac{p_{i,j}}{P}$$$. Then, the point is chosen uniformly at random within the selected square.
The Emperor enjoyed this event so much that he issued a decree for it to be held weekly. To estimate the costs to the treasury, you, as the court accountant, have been tasked with finding the expected value of the area of painted grass.
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1500$$$): the number of rows and the number of columns of the courtyard.
The $$$i$$$-th of the following $$$n$$$ lines contains $$$m$$$ integers $$$p_{i,1}, p_{i,2}, \ldots, p_{i,m}$$$ ($$$0 \le p_{i,j} \le 250$$$): the weights of the corresponding squares in the $$$i$$$-th row.
It is guaranteed that at least one of the weights $$$p_{i,j}$$$ is not equal to $$$0$$$.
Output the expected value of the area of painted grass modulo $$$10^9 + 7$$$.
Formally, let $$$M = 10^9 + 7$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \le x \lt M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.
3 40 1 1 91 4 1 18 1 0 1
2
5 547 39 34 40 9284 43 40 42 8915 22 64 18 3863 61 26 48 5790 88 21 26 83
400000006
In the first example test, we can show that the expected value of the area of painted grass is equal to $$$2$$$.
| Name |
|---|


