package no325; import java.util.ArrayList; import java.util.Scanner; import java.util.TreeSet; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long x1 = sc.nextLong(); long y1 = sc.nextLong(); long x2 = sc.nextLong(); long y2 = sc.nextLong(); long d = sc.nextLong(); if (d == 0) { if (x1 <= 0 && 0 <= x2 && y1 <= 0 && 0 <= y2) { System.out.println(1); }else{ System.out.println(0); } return; } Vector2[] sq1 = {new Vector2(x1,y1),new Vector2(x2,y1),new Vector2(x2,y2),new Vector2(x1,y2)}; Vector2[] sq2 = {new Vector2(d,0),new Vector2(0,d),new Vector2(-d,0),new Vector2(0,-d)}; TreeSet ee = new TreeSet<>(); long rmin = Math.max(-d, x1); long rmax = Math.min(d, x2); long[] es = {x1,x2,0L,-d,d}; for(long l:es) { rangeCheckAdd(ee, l, rmin, rmax); } for(int i=0;i<4;i++) { for(int j=0;j<4;j++) { Vector2 is = Vector2.intersect2(sq1[i], sq1[(i+1)%4], sq2[j], sq2[(j+1)%4]); rangeCheckAdd(ee, Math.round(is.x), rmin, rmax); } } ArrayList e = new ArrayList<>(ee); if (e.size() == 0) { System.out.println(0); return; } // System.out.println(e); long sum = 0; for(int i=0;i xb) { continue; } long c1 = count(xa,y1,y2,d); long c2 = count(xb,y1,y2,d); // System.out.println("[" + xa + "," + xb + "]:" + c1 + "->" + c2 + ":" + ((c1 + c2) * (xb - xa + 1) / 2)); sum += (c1 + c2) * (xb - xa + 1) / 2; } for(long x:e) { // System.out.println(x + ":" + count(x,y1,y2,d)); sum += count(x,y1,y2,d); } System.out.println(sum); } public static void rangeCheckAdd(TreeSet ts,long x,long min,long max) { if (min <= x && x <= max) { ts.add(x); } } //(a,b) (a=x,y1<=b<=y2) に、原点からマンハッタン距離がdイカの点がいくつ存在するか数える public static long count(long x,long y1,long y2,long d) { long dy = d - Math.abs(x); if (dy < 0) { return 0; } if (y1 > dy || y2 < -dy) { return 0; } return Math.min(dy, y2) - Math.max(-dy, y1) + 1; } } class Vector2 { public double x; public double y; public Vector2(double x,double y) { this.x = x; this.y = y; } public double dot(Vector2 v) { return this.x*v.x+this.y*v.y; } public double cross(Vector2 v) { return this.x*v.y-this.y*v.x; } public double norm() { return Math.sqrt(this.x*this.x+this.y*this.y); } public Vector2 normalize() { return divide(norm()); } public Vector2 add(Vector2 v) { return new Vector2(x+v.x,y+v.y); } public Vector2 subtract(Vector2 v) { return new Vector2(x-v.x,y-v.y); } public Vector2 multiply(double k) { return new Vector2(x*k,y*k); } public Vector2 divide(double k) { return new Vector2(x/k,y/k); } public Vector2 rotate90() { return new Vector2(-y,x); } public Vector2 rotate270() { return new Vector2(y,-x); } public static Vector2 intersect(Vector2 r1,Vector2 d1,Vector2 r2,Vector2 d2) { return r1.add(d1.multiply(-d2.cross(r2.subtract(r1)) / d1.cross(d2))); } public static Vector2 intersect2(Vector2 v11, Vector2 v12, Vector2 v21, Vector2 v22) { return Vector2.intersect(v11, v12.subtract(v11), v21, v22.subtract(v21)); } public static double dist(Vector2 r1,Vector2 r2,Vector2 p) { return r2.subtract(r1).normalize().cross(p.subtract(r1)); } public String toString() { return "(" + this.x + "," + this.y + ")"; } }