#include using namespace std; int main() { int a, b, c, d, e; int count =0; cin >> a>>b>>c>>d>>e; for(int i=min(a,b); (min(a,b)<=i)&&(i<=max(a, b)); i++){ if(e-1==count){ break; } for(int j=min(c,d); (min(c,d)<=j)&&(j<=max(c,d));j++){ int f = (i + j) % e; count = max(f, count); if(e-1==count){ break; } } } cout << count; }