#include using namespace std; using ll = long long; int main(){ ll n,h,m,s; cin >> n >> h >> m >> s; ll ans = h*60+m+(s*n)-s; cout << ans/60 << endl << ans%60 << endl; return 0; }