#include using namespace std; int Recv(int x, int y, int max_X, int max_Y, int m){ int answer = (x + y) % m; if(x < max_X){ int value = Recv(x + 1, y, max_X, max_Y, m); if(value > answer){ answer = value; } } if(y < max_Y){ int value = Recv(x, y + 1, max_X, max_Y, m); if(value > answer){ answer = value; } } return answer; } int main(){ int a,b,c,d,m; cin >> a >> b >> c >> d >> m; cout << Recv( a, c, b, d, m) << '\n'; return 0; }