import re



c=0

p=input().upper()

ptn=re.compile(r'^'+p+r'$')



while True:

    s=eval(input())

    if s =='END_OF_TEXT':

        break

    a=s.upper().split()

    for i in a:

        if re.match(ptn, i):

            c+=1

print(c)
import re



c=0

ptn=re.compile(r'^'+input().upper()+r'$')



while True:

    s=eval(input())

    if s =='END_OF_TEXT':

        break

    a=s.upper().split()

    for i in a:

        if re.match(ptn, i):

            c+=1

print(c)
import re

c = 0
p = input().upper()
ptn = re.compile(r"^" + p + r"$")
while True:
    s = eval(input())
    if s == "END_OF_TEXT":
        break
    a = s.upper().split()
    for i in a:
        if re.match(ptn, i):
            c += 1
print(c)

import re

c = 0
ptn = re.compile(r"^" + input().upper() + r"$")
while True:
    s = eval(input())
    if s == "END_OF_TEXT":
        break
    a = s.upper().split()
    for i in a:
        if re.match(ptn, i):
            c += 1
print(c)

-p = input().upper() -ptn = re.compile(r"^" + p + r"$") +ptn = re.compile(r"^" + input().upper() + r"$")