#! ruby # yukicoder My Practice # author: Leonardone @ NEETSDKASU def gs() gets.chomp end def gi() gets.to_i end def gss() gets.chomp.split end def gis() gss.map(&:to_i) end def nmapf(n,f) n.times.map{ __send__ f } end def arr2d(h,w,v=0) h.times.map{[v] * w} end def ngs(n) nmapf n,:gs end def ngi(n) nmapf n,:gi end def ngss(n) nmapf n,:gss end def ngis(n) nmapf n,:gis end def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end def nsum(n) n * (n + 1) / 2 end x1, y1, x2, y2, d = gis def f(x1,x2) case when x2 < 0 [[x2.abs,x1.abs].minmax] when x2 == 0 [[0,0],[1,x1.abs].minmax] when x1 > 0 [[x1,x2].minmax] when x1 == 0 [[0,0],[1,x2].minmax] else [[0,0],[1,x1.abs],[1,x2]] end end xs = f(x1,x2) ys = f(y1,y2) c =0 for2p(xs, ys) {|(x0,x1),(y0,y1)| if x0 == 0 && y0 == 0 c += 1 next end lx = x1 - x0 + 1 ly = y1 - y0 + 1 m0 = x0 + y0 m1 = x1 + y1 l0 = d - m0 + 1 case when l0 < 1 c += 0 when m1 <= d c += lx * ly when l0 <= lx && l0 <= ly c += nsum(l0) when l0 <= lx && ly == 1 c += l0 when l0 <= lx && ly < l0 c += nsum(l0) - nsum(lx - ly) when l0 <= ly && lx == 1 c += l0 when l0 <= ly && lx < l0 c += nsum(l0) - nsum(ly - lx) else c += nsum(l0) - nsum(l0 - lx) - nsum(l0 - ly) end } puts c