W = input().lower()
T = []
while True:
    S = input()
    if S == "END_OF_TEXT":
        break
    T.extend([words.lower() for words in S.split()])
print(T.count(W))
279d9555b81ec87357c52adacd2a8301f88770e7
<mask token>

<mask token>
while True:
    S = input()
    if S == 'END_OF_TEXT':
        break
    T.extend([words.lower() for words in S.split()])
print(T.count(W))

W = input().lower()
T = []
while True:
    S = input()
    if S == 'END_OF_TEXT':
        break
    T.extend([words.lower() for words in S.split()])
print(T.count(W))

W = input().lower()
T = []
while True:
    S = input()
    if S == "END_OF_TEXT":
        break
    T.extend([words.lower() for words in S.split()])
print(T.count(W))