There are N different sites for viewing lectures, each of which occasionally carries out technical work. Schedule technical work on each site is known in advance. It is necessary to determine what the maximum time during the day you can watch lectures without a break, perhaps switching lectures all the time for this on different sites.

At the entrance: in the first line the number of sites with lectures N (1 <= N <= 100), and in the next lines - the schedule of technical breaks shown on the sites in the following format: the first number k (1 <= k <= 100) - the number of breaks on the corresponding site, then 2k points in time in the form of HH: MM, separated by spaces - the start point and the end point of the technical pause).

On exit: the maximum time of continuous viewing of lectures for in the format HH: MM.

INPUT

2

1 00:30 01:20

2 00:30 00:40 02:40 02:45

OUTPUT

23:50

Closed due to the fact that off-topic participants Xander , aleksandr barakin , Cerbo , user207618, αλεχολυτ 12 May '17 at 19:11 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The message contains only the text of the task, in which there is no description of the problem, or the question is purely formal (" how do I do this task ") . To reopen the question, add a description of the specific problem, explain what does not work, what you see the problem. " - Xander, aleksandr barakin, Cerbo, Community Spirit, αλεχολυτ
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    If you rephrase the task, you get the following: Given N sets of segments, you need to find the length of the longest segment in their union. What exactly is the point here? - Yaant
  • @Yaant Well, for starters how to count the input data. Each time a different number of sites and technical breaks. In an array or how? - Follov
  • Well, yes, in a dynamic array. However, here it will be more convenient for you personally. If there is a desire to heroically overcome difficulties, then one can, for example, be perverted altogether and work with strings in this way. - Yaant
  • @Yaant can help with the code itself. How to count, I have already invented, but with the implementation of the problem. - Follov

1 answer 1

Expand the source data into an array (Time - Change). The beginning of the break - Change = 1, the end - Change = -1. Sort by time and calculate the amount with accumulation. Only in those periods where it is equal to the number of sites, there will be nothing to watch, i.e. All the while, the amount is less, there is something to see.