#include #include using namespace std; int main() { int n, h, m, t; cin >> n >> h >> m >> t; int res = h * 60 + m + t * (n-1); res %= 24 * 60; cout << res / 60 << "\n" << res % 60 << endl; return 0; }