def trans(time):
return 60*int(time[:2])+int(time[-2:])
def parse(inFile):
T = inFile.getInt()
[NA,NB] = inFile.getInts()
return (T,[[trans(word) for word in inFile.getWords()] for j in xrange(NA)],[[trans(word) for word in inFile.getWords()] for j in xrange(NB)])
def solve((T,ABTrains,BATrains)):
Aevents = [[x[0],+1] for x in ABTrains] + [[x[1]+T,-1] for x in BATrains]
Bevents = [[x[0],+1] for x in BATrains] + [[x[1]+T,-1] for x in ABTrains]
Aevents.sort()
Bevents.sort()
Aevents = [0]+[z[1] for z in Aevents]
Bevents = [0]+[z[1] for z in Bevents]
for i in xrange(len(Aevents)-1):
Aevents[i+1] += Aevents[i]
Bevents[i+1] += Bevents[i]
return "%d %d" % (max(Aevents),max(Bevents))
if __name__ == "__main__":
from GCJ import GCJ
GCJ(parse, solve, "/Users/lpebody/gcj/2008_q/", "b").run()
ZGVmIHRyYW5zKHRpbWUpOgogICAgcmV0dXJuIDYwKmludCh0aW1lWzoyXSkraW50KHRpbWVbLTI6XSkKCmRlZiBwYXJzZShpbkZpbGUpOgogICAgVCA9IGluRmlsZS5nZXRJbnQoKQogICAgW05BLE5CXSA9IGluRmlsZS5nZXRJbnRzKCkKICAgIHJldHVybiAoVCxbW3RyYW5zKHdvcmQpIGZvciB3b3JkIGluIGluRmlsZS5nZXRXb3JkcygpXSBmb3IgaiBpbiB4cmFuZ2UoTkEpXSxbW3RyYW5zKHdvcmQpIGZvciB3b3JkIGluIGluRmlsZS5nZXRXb3JkcygpXSBmb3IgaiBpbiB4cmFuZ2UoTkIpXSkKCmRlZiBzb2x2ZSgoVCxBQlRyYWlucyxCQVRyYWlucykpOgogICAgQWV2ZW50cyA9IFtbeFswXSwrMV0gZm9yIHggaW4gQUJUcmFpbnNdICsgW1t4WzFdK1QsLTFdIGZvciB4IGluIEJBVHJhaW5zXQogICAgQmV2ZW50cyA9IFtbeFswXSwrMV0gZm9yIHggaW4gQkFUcmFpbnNdICsgW1t4WzFdK1QsLTFdIGZvciB4IGluIEFCV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