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(); 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<>(); 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[i], sq2[(i+1)%4]); long x = Math.round(is.x); if (x1 <= x && x <= x2) { ee.add(Math.round(is.x)); } } } ArrayList e = new ArrayList<>(ee); // System.out.println(e); long sum = 0; for(int i=0;i" + c2 + ":" + ((c1 + c2) * (xb - xa + 1) / 2 - c2)); sum += (c1 + c2) * (xb - xa + 1) / 2 - c2; } sum += count(e.get(e.size()-1),y1,y2,d); System.out.println(sum); } //(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 + ")"; } }