#include using namespace std; int main() { int n, h, m, t; cin >> n >> h >> m >> t; n--; while (n-- > 0) { m += t; while (m >= 60) { m -= 60-m; h++; } } if (h >= 24) h %= 24; return 0; }