Problem:


Three Meals

You are running a restaurant that serves dishes only three times a day. Each of your customer has his/her own separate time zones for eating breakfast, lunch and supper. Thus, your customer enjoys your dish only when he/she visits your restaurant to meet your serving time settings. Your wish is to modify your serving time arrangement so that as many as possible of your customers can enjoy your meals three times a day.
  

  Write a program to enable as many as possible of customers can enjoy your service three times a day, i.e. breakfast, lunch, and supper. A list of customers eating time zones is given, which you cannot change. Settings of your service time are your option. Coincidence between your service time and either edge of customer’s time zone (start or end time) does not hinder you to provide your service.

Input

  The input is given in the following format.

N
ast_1 aet_1 hst_1 het_1 bst_1 bet_1
ast_2 aet_2 hst_2 het_2 bst_2 bet_2
:
ast_N aet_N hst_N het_N bst_N bet_N

The first line provides the number of customers N(1≤N≤50). Each of subsequent N lines provides time zone information of i-th customer: start and end time of breakfast zone (ast_i, aet_i), those of lunch zone (hst_i, het_i) and those of supper zone (bst_i, bet_i). The end time must be later in time as the start time. Time zones do not overlap, i.e. hst_i is later in time than aet_i, and so on. Each time settings must not cross 0:00 midnight.

h m

  Each time information is given by hour h (0≤h≤23) and minute m(0≤m≤59).

Output

  Output the maximum number of customers that can be served all three meals (breakfast, lunch, and supper).

Sample Input 1

5
1 0 2 0 3 30 4 30 6 0 7 0
2 30 3 0 4 0 5 0 5 30 6 30
1 30 2 30 4 30 5 0 6 30 7 0
2 30 3 0 5 0 6 0 6 30 7 0
1 0 2 0 3 0 3 30 4 0 5 0

Sample Output 1

3



Sample input:
5
1 0 2 0 3 30 4 30 6 0 7 0
2 30 3 0 4 0 5 0 5 30 6 30
1 30 2 30 4 30 5 0 6 30 7 0
2 30 3 0 5 0 6 0 6 30 7 0
1 0 2 0 3 0 3 30 4 0 5 0


Sample output:
3

Submission status: Accepted

Solution code:
n = int(input())
lst = [list(map(int, input().split())) for _ in range(n)]
a_start = [x[0] * 60 + x[1] for x in lst]
a_end = [x[2] * 60 + x[3] for x in lst]
h_start = [x[4] * 60 + x[5] for x in lst]
h_end = [x[6] * 60 + x[7] for x in lst]
b_start = [x[8] * 60 + x[9] for x in lst]
b_end = [x[10] * 60 + x[11] for x in lst]

def make_sets(start, end):
  sets = []
  member = []
  for i in range(1440):
    upd = False
    for j in range(n):
      if start[j] == i:
        member.append(j)
        upd = True
      if end[j] == i - 1:
        member.remove(j)
        upd = True
    if upd:
      sets.append(set(member))
  return sets

a_sets = make_sets(a_start, a_end)
h_sets = make_sets(h_start, h_end)
b_sets = make_sets(b_start, b_end)

ans = 0
for s1 in a_sets:
  for s2 in h_sets:
    for s3 in b_sets:
      ans = max(ans, len(s1 & s2 & s3))

print(ans)