module main; // https://kmjp.hatenablog.jp/entry/2015/12/19/0900 より // 2次元グリッド、マンハッタン距離、数え上げ import std; long count(long x1, long x2, long y1, long y2, long D) { if (x1 + y1 > D) return 0; if (x2 + y2 <= D) return (y2 - y1 + 1) * (x2 - x1 +1); D -= x1 + y1; x2 -= x1; y2 -= y1; long ret = 0; if (D > y2) { ret = (D - y2) * (y2 + 1); x2 -= D - y2; D = y2; } x2 = min(x2, D); return ret + (D + 1 + (D + 1 - x2)) * (x2 + 1) / 2; } // -D <= x <= D かつ a <= x <= b である整数xがいくつあるか long range(long a, long b, long D) { long l = -D, r = D; l = max(a, -D); r = min(b, D); if (r < l) return 0; return r - l + 1; } void main() { // 入力 long x1, y1, x2, y2, d; readln.chomp.formattedRead("%d %d %d %d %d", x1, y1, x2, y2, d); // 答えの計算 long ret = 0; if (x2 < 0) x1 = -x1, x2 = -x2, swap(x1, x2); if (y2 < 0) y1 = -y1, y2 = -y2, swap(y1, y2); ret += count(max(1, x1), x2, max(1, y1), y2, d); if (x1 < 0) ret += count(1, -x1, max(1, y1), y2, d); if (y1 < 0) ret += count(max(1, x1), x2, 1, -y1, d); if (x1 < 0 && y1 < 0) ret += count(1, -x1, 1, -y1, d); if (x1 <= 0) ret += range(y1, y2, d); // x軸上の点 if (y1 <= 0) ret += range(x1, x2, d); // y軸上の点 if (x1 <= 0 && y1 <= 0) ret--; // 原点の重複があれば除く // 答えの出力 writeln(ret); }