# 描述

As an eligible Ingress Resistance Agent you should know your power source, the Exotic Matter.
We call it XM, which is the driving force behind all of our actions in Ingress.
XM allows us to construct items through hacking portals, to attack enemy portals, make links and create fields.

We try to collect XM from the ground. XM concentration come from location based services, meaning that areas with a lot of foot traffic have higher amounts versus places that don’t.
You can collect XM by moving through those areas.
The XM will be automatically harvested by your Scanner when it is within your interaction circle/range.

Alice decides to select a location such that she can collect XM as much as possible.
To simplify the problem, we consider the city as a grid map with size ‘$n * m$’ numbered from $(0,0)$ to $(n-1,m-1)$.
The XM concentration inside the block $(i,j)$ is $p(i,j)$.
The radius of your interaction circle is $r$.
We can assume that XM of the block $(i,j)$ are located in the centre of this block.
The distance between two blocks is the Euclidean distance between their centres.

Alice stands in the centre of one block and collects the XM.
For each block with the distance $d$ smaller than $r$ to Alice, and whose XM concertation is $p(i,j)$, Alice’s scanner can collects $p(i,j)/(1+d)$ XM from it.

Help Alice to determine the maximum XM which she can collect once he stands in the centre of one block.

## Input

There are multiple cases.
For each case, the first line consists two integers $n,m$ ($1≤n,m≤500$) and one float-point number $r$ ($0≤r≤300$).
Each of the following $n$ line consists $m$ non-negative float-point numbers corresponding to the XM concentrations inside each blocks.

## Output

For each case, output the maximum XM which Alice can collect in one line.

# 思路

• 直接暴力算的话复杂度是$O(nmr^2)$显然是会超时的。
• 若利用FFT计算，可以用一个向量表示位置信息和值，另一个向量表示某一个位置平移后的权。这样的复杂度为$O(max(mn,r ^ 2)\log(\max(mn,r ^ 2)))$。
• 向量A表示位置信息的值，最大为$m \times n$；向量B表示某一个偏移量下的权，最大为$r\times r$。向量C表示卷积得到的向量。
$$C(i,j) = \sum_{i_1+i_2=i}\sum_{j_1+j_2=j} A(i_1,j_1) \times B(i_2,j_2)$$
注意到向量C最大为$((m+2R) \times (n+2R))$，方便起见，将其转化为$(M \times M)$的向量，其中$M=\max(m,n)+2R$。
• 这样就可以把二维的情况映射到一维了。
$$A(i,j) = A[i \times M + j]$$
$$B(i,j) = B[(i+R) \times M + j + R]$$
• 这里加上$R$是因为$B$中的偏移量是在$[-R, R]$，但是实现的时候我们不能使用负下标。
• 最后的结果就是向量C:$$C(i,j) = C[M \times (i+R)+j+R]$$

0%