import sys

List = ["X","E","S","T","C","P","B","R","K","NOW","SPEAKER", "HEARER"]
lines = []
def process(lines, t):
	cnt = [0 for i in range(12)]
	for act in lines[2:]:
		act = act.split()
		if len(act) == 1:
			act = act[0]
			assert "ADD_NODE" in act
			idx = List.index(act.split("_")[-1])
			cnt[idx] += 1
	for i in [0, 1, 2, 5, 6]:
		if cnt[i] >= int(t[i]):
			return
	for line in lines:
		print line
	print 

for filename in sys.argv[1:2]:
	print "# this file is generated by"
	print "# ", " ".join(sys.argv)
	for line in open(filename):
		line = line.strip()
		if line == "":
			process(lines, sys.argv[2:])
			lines = []
		else:
			lines.append(line)