gets
score = 0
base = [0, 0, 0]
out_count = 0
readlines.map(&:chomp).each{|cmd|
  case cmd
  when 'HIT'
    base.unshift(1)
    score += base.pop
  when 'OUT'
    out_count += 1

    if out_count == 3
      puts score
      score = 0
      base = [0, 0, 0]
      out_count = 0
    end
  when 'HOMERUN'
    score += base.inject(&:+) + 1
    base = [0, 0, 0]
  end
}