#include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climits> #include <cfloat> #include <functional> using namespace std; int main() { int x1, y1, x2, y2, d; cin >> x1 >> y1 >> x2 >> y2 >> d; /* 象限別に処理する */ /* 222211111 222211111 222211111 222211111 2222原4444 333334444 333334444 333334444 333334444 */ long long ans = 0; /* 原点が正方形に含まれるか調べる */ if(y1 <= 0 && 0 <= y2 && x1 <= 0 && 0 <= x2) ++ ans; for(int i=0; i<4; ++i){ /* 第1象限(0<=x, 0<y)における格子点数を求める */ if(0 < y2 && 0 <= x2){ int yc = max(1, y1); int xc = max(0, x1); int yd = max(1, y2); int xd = max(0, x2); if(yd + xd <= d){ ans += (yd - yc + 1LL) * (xd - xc + 1LL); } else if(yc + xc <= d){ int a = max(d - yd, xc); int b = min(d - yc, xd); int ya = d - a; int xa = a; int yb = d - b; int xb = b; if(xc == xa){ if(yc == ya){ /* □□□□□ □□□□□ ■□□□□ ■■□□□ ■■■□□ */ long long p = ya - yc + 1; ans += p * (p + 1) / 2; } else{ /* □□□ □□□ ■□□ ■■□ ■■■ ■■■ */ long long p = xb - xc + 1; ans += p * (p + 1) / 2; long long q = ya - yc + 1 - p; ans += p * q; } } else{ if(yc == yb){ /* ■■□□□□ ■■■□□□ ■■■■□□ */ long long p = ya - yc + 1; ans += p * (p + 1) / 2; long long q = xb - xc + 1 - p; ans += p * q; } else{ /* ■■□□□ ■■■□□ ■■■■□ ■■■■■ ■■■■■ */ long long p = ya - yc + 1; long long q = xb - xc + 1; ans += p * q; long long r = xd - xa; ans -= r * (r + 1) / 2; } } } } /* 長方形を原点中心に回転させることで、別の象限にも同じ処理を適用できる */ swap(x1, y1); swap(x2, y2); x1 *= -1; x2 *= -1; swap(x1, x2); } cout << ans << endl; return 0; }