#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(I,A,B) for(int I = (A); I < (B); ++I) typedef long long ll; int main(){ ll N, H, M, T; cin >> N >> H >> M >> T; ll mm = 60 * H + M; mm += (N - 1) * T; cout << mm / 60 << endl; cout << mm % 60 << endl; return 0; }