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())
for i in range(n):
    runner=0
    out=0
    score=0
    while 1:
        state=input()
        if state=="HIT":
            if runner<3:
                runner+=1
            else:
                score+=1
        elif state=="HOMERUN":
            score+=runner+1
            runner=0
        else:
            out+=1
            if out==3:break
    print(score)

Python: ining = int(input())
out_count = 0
score = 0
bases = []

while True:
    print(score)
    n = input()
    if n == 'OUT':
        out_count = out_count + 1

    if out_count >= 3 * ining: break

    if out_count % 3 == 0 and out_count != 0:
        bases = []
        continue

    if n == 'HIT':
        bases.append(1)
        if len(bases) >= 3:
            bases = bases[1:]
            score = score + 1
            continue
    elif n == 'HOMERUN':
        score = len(bases) + 1
        bases = []
        continue

print(score)

Python: N = int(input())
bc = [0, 1, 1, 2, 1, 2, 2, 3]
for i in range(N):
    ans = 0
    b = 0
    rest = 3
    while rest:
        s = input()
        if s == "OUT":
            rest -= 1
            continue

        if s == "HIT":
            b = (b << 1) | 1
            if b & 8:
                ans += 1
                b ^= 8
        else:
            ans += bc[b] + 1
            b = 0
    print(ans)

Python: N=int(input())
count = 0
point = 0
runner = 0
out = 0
while 1:
    n = input()
    if n=="HIT":
        runner +=1
        if runner==4:
            point +=1
            runner -=1
    elif n=="OUT":
        out +=1
        if out==3:
            count +=1
            print(point)
            point = runner = out = 0
            if count == N:break
    elif n=="HOMERUN":
        runner +=1
        point +=runner
        runner = 0

Python: #!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright  : @Huki_Hara
# Created    : 2015-03-16

for _ in range(int(input())):
    ans = 0
    out = 0
    hit = 0
    while True:
        w = input()
        if w == "OUT":
            out += 1
            if out == 3:
                break
        elif w == "HIT":
            if hit == 3:
                ans += 1
            else:
                hit += 1
        elif w == "HOMERUN":
            ans += hit + 1
            hit = 0
    print(ans)

Python: #!/usr/bin/python
# -*- coding: utf-8 -*-

def main():
    # 入力
    N = int(raw_input())

    for i in range(N):
        data = {}
        b = Baseball()
        while(b.out < 3):
            event = raw_input()
            b.decisionScore(event)

        print(b.score)

class Baseball():
    def __init__(self):
        self.out = 0
        self.score = 0
        self.que = [0,0,0]  #Third, Second, First

    def decisionScore(self, event):
        if event == "OUT":
            self.out += 1
        elif event == "HIT":
            self.score += self.addRunner()
        elif event == "HOMERUN":
            self.score += self.clearRunnner() + 1
        else:
            print("Wrong data")

    def addRunner(self):
        self.que.append(1)
        point = self.que[0]
        self.que = self.que[1:]
        return point

    def clearRunnner(self):
        point = sum(self.que)
        self.que = [0,0,0]
        return point

if __name__=='__main__':
    main()

Python: for Panzerlied in range(0,int(input())):
  runners = 0
  outs = 0
  points = 0
  while outs<3:
    command=input()
    if command == "HIT":
      runners+=1
      if runners > 3:
        runners=3
        points+=1
    elif command == "HOMERUN":
      points+=(runners+1)
      runners=0
    else: # command == "OUT"
      outs+=1
  print(points)

Python: A = ['HIT','HOMERUN','OUT']
n = int(input())
for i in range(n):
    r = []
    o = 3
    s = 0
    while o > 0:
        a = input()
        if a == A[0]:
            r = [1]+r
            if len(r) >= 4:
                S,r[3:] = r[3:],[]
                for i in S:
                    s += i
        elif a == A[1]:
            for i in r:
                s += i
            s += 1
            r = []
        else:
            o -= 1
    print (s)

Python: inn=int(input())
o=0
i=0
s=[]
sc=0
ba=[]

while i<inn:
  b=input()
  if b == "OUT":
    o+=1
    if o%3 == 0 and o>0:
      s.append(sc)
      sc=0
      i+=1
      o=0
      ba=[]
  elif b == "HIT":
    ba.append(1)
    if len(ba)>=4:
      sc+=1
      ba=[1,1,1]      
  elif b == "HOMERUN":
    ba.append(1)
    sc+=len(ba)
    ba=[]
[print(i) for i in s]

Python: def init_state():
    return 0, 0, 0


def main():
    n = int(input())

    point, hit, out = init_state()

    while True:
        if n == 0:
            break

        event = input()

        if event == 'HIT':
            if hit >= 3:
                point += 1
            else:
                hit += 1
        elif event == 'OUT':
            out += 1
        elif event == 'HOMERUN':
            point += hit + 1
            hit = 0

        if out == 3:
            print(point)
            point, hit, out = init_state()
            n -= 1


if __name__ == '__main__':
    main()

Python: n = int(input())

for _ in range(n):
    runners = []
    outs = 0
    score = 0
    while True:
        s = input()
        if s == "HIT":
            runners.append(0)
            for i in range(len(runners)):
                runners[i] += 1
                if runners[i] == 4:
                    score += 1
            if 4 in runners:
                runners.remove(4)
        elif s == "HOMERUN":
            score += len(runners) + 1
            runners = []
        elif s == "OUT":
            outs += 1
            if outs == 3:
                break
    print(score)

Python: for i in range(int(input())):
    f, s, t, count, point = 0, 0, 0, 0, 0
    while count != 3:
        data = input()
        if data == 'HIT':
            if t == 1:
                point += 1
                t = 0
            if s == 1:
                t = 1
                s = 0
            if f == 1:
                s = 1
            f = 1
        elif data == 'OUT':
            count += 1
        elif data == 'HO' \
                   '' :
            point += f + s + t + 1
            f, s, t = 0, 0, 0
    print(point)

Python: N = int(input())

for l in range(N):
    outCount = 0
    score = 0
    bases = 0
    while True:
        action = input()
        if action == "HIT":
            if bases == 3:
                score += 1
            else:
                bases += 1
        elif action == "HOMERUN":
            score += bases + 1
            bases = 0
        elif action == "OUT":
            outCount += 1

        if outCount == 3:
            print(score)
            break

Python: for i in range(int(input())):
    f, s, t, count, point = 0, 0, 0, 0, 0
    while count != 3:
        data = input()
        if data == 'HIT':
            if t == 1:
                point += 1
                t = 0
            if s == 1:
                t = 1
                s = 0
            if f == 1:
                s = 1
            f = 1
        elif data == 'OUT':
            count += 1
        elif data == 'HO' \
                   '' :
            point += f + s + t + 1
            f, s, t = 0, 0, 0
    print(point)