def parse(inFile):
engines = [inFile.readline() for i in xrange(inFile.getInt())]
return (len(engines),[engines.index(inFile.readline()) for i in xrange(inFile.getInt())])
def solve((N,requests)):
numSwitches = 0
numUsed = 0
requested = [False] * N
for req in requests:
if not requested[req]:
if (numUsed == N-1):
numSwitches += 1
numUsed = 0
requested = [False] * N
numUsed += 1
requested[req] = True
return numSwitches
if __name__ == "__main__":
from GCJ import GCJ
GCJ(parse, solve, "/Users/lpebody/gcj/2008_q/", "a").run()
ZGVmIHBhcnNlKGluRmlsZSk6CiAgICBlbmdpbmVzID0gW2luRmlsZS5yZWFkbGluZSgpIGZvciBpIGluIHhyYW5nZShpbkZpbGUuZ2V0SW50KCkpXQogICAgcmV0dXJuIChsZW4oZW5naW5lcyksW2VuZ2luZXMuaW5kZXgoaW5GaWxlLnJlYWRsaW5lKCkpIGZvciBpIGluIHhyYW5nZShpbkZpbGUuZ2V0SW50KCkpXSkKCmRlZiBzb2x2ZSgoTixyZXF1ZXN0cykpOgogICAgbnVtU3dpdGNoZXMgPSAwCiAgICBudW1Vc2VkID0gMAogICAgcmVxdWVzdGVkID0gW0ZhbHNlXSAqIE4KICAgIGZvciByZXEgaW4gcmVxdWVzdHM6CiAgICAgICAgaWYgbm90IHJlcXVlc3RlZFtyZXFdOgogICAgICAgICAgICBpZiAobnVtVXNlZCA9PSBOLTEpOgogICAgICAgICAgICAgICAgbnVtU3dpdGNoZXMgKz0gMQogICAgICAgICAgICAgICAgbnVtVXNlZCA9IDAKICAgICAgICAgICAgICAgIHJlcXVlc3RlZCA9IFtGYWxzZV0gKiBOCiAgICAgICAgICAgIG51bVVzZWQgKz0gMQogICAgICAgICAgICByZXF1ZXN0ZWRbcmVxXSA9IFRydWUKICAgIHJldHVybiBudW1Td2l0Y2hlcwoKaWYgX19uYW1lX18gPT0gIl9fbWFpbl9fIjoKICAgIGZyb20gR0NKIGltcG9ydCBHQ0oKICAgIEdDSihwYXJzZSwgc29sdmUsICIvVXNlcnMvbHBlYm9keS9nY2ovMjAwOF9xLyIsICJhIikucnVuKCkKCiAgICAgICAgICAgIAo=