def solve(x1,y1,x2,y2,d) #p [x1,y1,x2,y2,d] return solve(-x2,y1,-x1,y2,d) if x1 < 0 && x2 < 0 return solve(x1,-y2,x2,-y1,d) if y1 < 0 && y2 < 0 return solve(0,y1,x2,y2,d)+solve(1,y1,-x1,y2,d-1) if x1 < 0 return solve(x1,0,x2,y2,d)+solve(x1,1,x2,-y1,d-1) if y1 < 0 def calc(d); (d+1)*(d+2)/2; end return 0 if x1+y1 > d d -= x1+y1 x2-=x1 y2-=y1 z = calc(d) z -= calc(d-y2-1) if d>y2 z -= calc(d-x2-1) if d>x2 z += calc(d-y2-x2-2) if d>y2+x2 #p ['',calc(d),calc(d-y2-1),calc(d-x2-1),calc(d-y2-x2-2),z] z end while cin = gets p solve(*(cin.split.map(&:to_i))) end