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