Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		base := [3]bool{}
		score, out := 0, 0
		for stdin.Scan() {
			switch stdin.Text() {
			case "HIT":
				if base[2] { // 3塁
					score++
				}
				if base[1] { // 2塁
					base[2] = true
					base[1] = false
				}
				if base[0] { // 1塁
					base[1] = true
				}
				base[0] = true
			case "HOMERUN":
				for i := 0; i < 3; i++ {
					if base[i] {
						score++
						base[i] = false
					}
				}
				score++
			case "OUT":
				out++
			}
			if out >= 3 {
				fmt.Println(score)
				break
			}
		}
	}
}

Python: n = int(input())

cnt = 0
while 1:
    if cnt == n:
        break

    runner = [0] * 3
    score = 0
    outcount = 0
    while outcount != 3:
        event = input()
        if event == "HIT":
            if runner[2]:
                score += 1
                runner[2] = 0
            if runner[1]:
                runner[2] = 1
                runner[1] = 0
            if runner[0]:
                runner[1] = 1
            runner[0] = 1

        elif event == "HOMERUN":
            runners = runner.count(1)
            score += runners + 1
            runner = [0] * 3

        else:
            outcount += 1

        if outcount == 3:
            break

    print(score)
    cnt += 1

Python: for i in range(int(input())):
    point = 0
    out = 0
    runner = [0, 0, 0]
    while True:
        event = input()
        if event == 'HIT':
            if runner[2] == 1:
                point += 1
                runner[2] = 0
            if runner[1] == 1:
                runner[2] = 1
                runner[1] = 0
            if runner[0] == 1:
                runner[1] = 1
            runner[0] = 1
        elif event == 'HOMERUN':
            point += (sum(runner)+1)
            runner = [0, 0, 0]
        elif event == 'OUT':
            out += 1
            if out == 3:
                print(point)
                break

Python: n = int(input())
for i in range(n):
    p = 0
    out = 0
    x = i % 2
    state = [0,0,0]
    while True:
        s = str(input())

        if s == "HIT":
            if state[0] == 1:
                p += 1
            state[0],state[1],state[2] = state[1],state[2],1
        elif s == "HOMERUN":
            point = state.count(1)
            p = p + point + 1
            state = [0,0,0]
        elif s == "OUT":
            out = out + 1
        if out == 3:
            break

    print(p)

Python: n = int(input())
inning = 0

while inning != n:
    score = 0
    info = [0, 0, 0]
    out_count = 0
    while True:
        event = input()
        if event == "OUT":
            out_count += 1
        if out_count == 3:
            inning += 1
            print(score)
            break

        if event == "HIT":
            score += info[-1]
            info = [1] + info[:2]
        elif event == "HOMERUN":
            score += sum(info) + 1
            info = [0, 0, 0]

Python: class Point():
      def __init__(self,base,score,out):
            self.base=base
            self.score=score
            self.out=out

      def hit(self):
            if self.base < 3:
                  self.base = self.base + 1
            else:
                  self.score = self.score + 1

      def home(self):
            self.score = self.score + self.base + 1
            self.base = 0

      def out1(self):
            self.out = self.out + 1

n = int(input())
for i in range(n):
      game = Point(0,0,0)
      while 1:
            eve = input()
            if eve == "HIT":
                  game.hit()             
            if eve == "HOMERUN":
                  game.home()
            if eve == "OUT":
                  game.out1()
                  if game.out == 3:
                        print(game.score)
                        del game
                        break

Python: for _ in[0]*int(input()):
 r=o=s=0
 while 1:
  a=input()[1]
  if'I'==a:
   if r<3:r+=1
   else:s+=1
  elif'O'==a:s+=r+1;r=0
  else:
   if r<3:o+=1
   else:print(s);break

Python: for i in range(int(input())):
    point = 0
    out = 0
    runner = [0, 0, 0]
    while True:
        event = input()
        if event == 'HIT':
            if runner[2] == 1:
                point += 1
                runner[2] = 0
            if runner[1] == 1:
                runner[2] = 1
                runner[1] = 0
            if runner[0] == 1:
                runner[1] = 1
                runner[0] = 0
            runner[0] = 1
        elif event == 'HOMERUN':
            point += (sum(runner)+1)
            runner = [0, 0, 0]
        elif event == 'OUT':
            out += 1
            if out == 3:
                print(point)
                break

Python: # coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

# def printA(A):
#     for i, n in enumerate(A):
#         print(n, end='')
#         if i != N-1:
#             print(' ', end='')
#     print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

data = get_input()
data = data[1:]

rui = 0
out = 0

ans = 0

for s in data:
    if s == 'HIT':
        if rui != 3:
            rui += 1
        else:
            ans += 1
    elif s == 'OUT':
        if out != 2:
            out += 1
        else:
            print(ans)
            out = 0
            rui = 0
            ans = 0
    elif s == 'HOMERUN':
        ans += (rui+1)
        rui = 0