#! 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 [false, [[-x1,-x2]]] when x2 == 0 [true, [[1,-x1]]] when x1 > 0 [false,[[x1,x2]]] when x1 == 0 [true,[[1,x2]]] else [true,[[1,-x1],[1,x2]]] end end zx, xs = f(x1,x2) zy, ys = f(y1,y2) c = (zx && zy) ? 1 : 0 for2p(xs, ys) {|x,y| lx = x[1] - x[0] ly = y[1] - y[0] m0 = x[0] + y[0] m1 = x[1] + y[1] l0 = d - m0 case when d < m0 c += 0 when m1 <= d c += (lx + 1) * (ly + 1) when l0 <= lx && l0 <= ly c += nsum(l0 + 1) when l0 <= lx # && ly < l0 c += nsum(l0 + 1) - nsum(lx - ly + 1) when l0 <= ly # && lx < l0 c += nsum(l0 + 1) - nsum(ly - lx + 1) else c += nsum(l0 + 1) - nsum(l0 - lx + 1) - nsum(l0 - ly + 1) end } [[zx,ys], [zy,xs]].each do |z, zs| next if !z zs.each do |e0,e1| case when e1 < d c += e1 - e0 + 1 when e0 <= d && d <= e1 c += d - e0 + 1 end end end puts c