Score : 500 points
Problem Statement
In an N-dimensional space, the Manhattan distance d(x,y) between two points x=(x1,x2,…,xN) and y=(y1,y2,…,yN) is defined by:
d(x,y)=i=1∑n∣xi−yi∣.A point x=(x1,x2,…,xN) is said to be a lattice point if the components x1,x2,…,xN are all integers.
You are given lattice points p=(p1,p2,…,pN) and q=(q1,q2,…,qN) in an N-dimensional space.
How many lattice points r satisfy d(p,r)≤D and d(q,r)≤D? Find the count modulo 998244353.
Constraints
- 1≤N≤100
- 0≤D≤1000
- −1000≤pi,qi≤1000
- All values in input are integers.
Input is given from Standard Input in the following format:
N D
p1 p2 … pN
q1 q2 … qN
Output
Print the answer.
When N=1, we consider points in a one-dimensional space, that is, on a number line.
8 lattice points satisfy the conditions: −2,−1,0,1,2,3,4,5.