#include using namespace std; int main() { int N, H, M, T; cin >> N >> H >> M >> T; struct tm t = {}; t.tm_hour = H, t.tm_min = M + T * (N - 1); mktime(&t); cout << t.tm_hour << "\n" << t.tm_min << "\n"; }