import java.util.*; class No0296{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt() - 1; int h = sc.nextInt(); int m = sc.nextInt(); int t = sc.nextInt(); for(int i = 0; i < n; i++){ m += t; } if(m / 60 > 0){ h = h + (m / 60); m = m % 60; } System.out.println(h); System.out.println(m); } }