#include #include using namespace std; int main() { int p1, d1, p2, d2, k; cin >> p1 >> d1 >> p2 >> d2 >> k; vector v(5005, 0); for(int i = p1; i < p1 + d1; i++) { v[i] = 1; } int res = 0; vector tmp = v; for(int i = p2 - k; i < p2 - k + d2; i++) { tmp[i] = 1; } int cnt = 0; for(int i = 0; i <= 5000; i++) { cnt += tmp[i]; } res = max(res, cnt); tmp = v; for(int i = p2 + k; i < p2 + k + d2; i++) { tmp[i] = 1; } cnt = 0; for(int i = 0; i <= 5000; i++) { cnt += tmp[i]; } res = max(res, cnt); v = vector(5005, 0); for(int i = p2; i < p2 + d2; i++) { v[i] = 1; } tmp = v; for(int i = p1 - k; i < p1 - k + d1; i++) { tmp[i] = 1; } cnt = 0; for(int i = 0; i <= 5000; i++) { cnt += tmp[i]; } res = max(res, cnt); tmp = v; for(int i = p1 + k; i < p1 + k + d1; i++) { tmp[i] = 1; } cnt = 0; for(int i = 0; i <= 5000; i++) { cnt += tmp[i]; } res = max(res, cnt); cout << res << endl; return 0; }