$stdin = DATA if $stdin.eof?

target = gets.chomp.upcase

words = []

ARGF.each_line do |line|
  break if line =~ /^END_OF_TEXT$/
  words += line.split.map(&:upcase)
end

p words
puts words.select{|e| e =~ %r/#{target}/ }.size