#include using namespace std; int main(){ long long int N,H,M,T; cin >> N >> H >> M >> T; while(N--){ M+=T; } H+=(M/60); M%=60; H/=24; cout << H << endl << M << endl; return 0; }