import re

pattern = str(eval(input()))

words = []

while True:

    line = str(eval(input()))

    if line == 'END_OF_TEXT':

        break

    words += line.lower().split()



cnt = 0

for word in words:

    if re.fullmatch(pattern, word):

        cnt += 1

print(cnt)



W = str(eval(input()))

words = []

while True:

    line = str(eval(input()))

    if line == 'END_OF_TEXT':

        break

    words += line.lower().split()



cnt = 0

for word in words:

    if W == word:

        cnt += 1

print(cnt)



import re

pattern = str(eval(input()))
words = []
while True:
    line = str(eval(input()))
    if line == "END_OF_TEXT":
        break
    words += line.lower().split()
cnt = 0
for word in words:
    if re.fullmatch(pattern, word):
        cnt += 1
print(cnt)

W = str(eval(input()))
words = []
while True:
    line = str(eval(input()))
    if line == "END_OF_TEXT":
        break
    words += line.lower().split()
cnt = 0
for word in words:
    if W == word:
        cnt += 1
print(cnt)

-import re - -pattern = str(eval(input())) +W = str(eval(input())) -    if re.fullmatch(pattern, word): +    if W == word: