import java.util.Calendar; import java.util.Scanner; class Timer { int sleepH, sleepM, wakeUpH, wakeUpM; public Timer(String[] s) { int[] num = new int[4]; for (int i = 0; i < s.length; i++) { num[i] = Integer.parseInt(s[i]); } this.sleepH = num[0]; this.sleepM = num[1]; this.wakeUpH = num[2]; this.wakeUpM = num[3]; if (this.sleepH > this.wakeUpH) { this.wakeUpH += 24; } } } class Converter { public static int minute(Calendar calendar) { int day = calendar.get(Calendar.DATE); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); return (day - 1) * 1440 + hour * 60 + minute; } } public class No_70 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = Integer.parseInt(sc.nextLine()); Calendar sleep = Calendar.getInstance(); Calendar wakeUp = Calendar.getInstance(); Timer timer; String[] s; int sleepMinute = 0, wakeUpMinute = 0, sleeping = 0; for (int i = 0; i < n; i++) { s = dismantle(sc.nextLine()); timer = new Timer(s); sleep.set(2016, 0, 1, timer.sleepH, timer.sleepM, 0); wakeUp.set(2016, 0, 1, timer.wakeUpH, timer.wakeUpM, 0); sleepMinute = Converter.minute(sleep); wakeUpMinute = Converter.minute(wakeUp); sleeping += wakeUpMinute - sleepMinute; } System.out.println(sleeping); sc.close(); } public static String[] dismantle(String s) { s = s.replaceAll(":", " "); String[] ns = s.split(" "); return ns; } }