import sequtils, strutils let n = parseInt readLine stdin xs = (0 ..< n).mapIt split readLine stdin proc fn(s: string): int = let hm = s.split(':').map parseInt h = hm[0] m = hm[1] h * 60 + m var ans = 0 for x in xs: var t = x[1].fn - x[0].fn if t < 0: t.inc (24 * 60) ans.inc t echo ans