Smoothing is used to reduce noise within an image or to produce a less pixelated image. You have been given an image G of resolution N x N. Image will be represented as a 2D grid G of size N x N where Gi,j will denote intensity of color in a grayscale image of pixel (i,j).
You have been given a filter mask F of size (2∗M+1) x (2∗M+1). Using this filter mask, you have to perform smoothing operation on the G and output the final image NewG. Smoothing operation for any particular pixel (i,j) can be described as:
NewGi,j=∑p=Mp=−M∑q=Mq=−MGi+p,j+q∗Fp,q
In the above formula, if any pixel (x,y) is situated outside of grid of size N x N, then Gx,y=0.
INPUT:
First line of input will consists of two integers N and M. Next 2∗M+1 lines will consists of 2∗M+1 integers denoting filter mask F. (M+1)th integer on (M+2)th line will give the value of F0,0, first integer on second line will give the value of F−M,−M and last integer on (2∗M+2)th line will give the value of FM,M.
Next N lines will consists of N integers denoting the image G.
OUTPUT:
Output the image NewG obtained by smoothing the image G using filter mask F.
CONSTRAINTS
2≤N≤100
1≤M≤10
0≤Gi,j,Fi,j≤100
Apply the filter mask to calculate the image NewG as shown in the image.