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())
score = 0
outcount = 0
first = 0
second = 0
third = 0
for i in range(n):
	while outcount < 3:
		event = input()
		if event == 'HIT':
			if third == 1:
				score += 1
			third = second
			second = first
			first = 1
		if event == 'HOMERUN':
			score = score + first + second + third + 1
			first = second = third = 0
		if event == 'OUT':
			outcount += 1
	print(score)
	score = 0
	outcount = 0
	first = 0
	second = 0
	third = 0

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

while True:
    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:]
            continue
    elif n == 'HOMERUN':
        score = len(bases) + 1
        bases = []
        continue

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 i in range(n) :
    
    first = "OFF"
    second = "OFF"
    third = "OFF"
    score = 0
    out = 0
    
    while True :
        event = input()
        if event == "HIT" :
            if first == "OFF" :
                first = "ON"
            else :
                if second == "OFF" :
                    second = "ON"
                else :
                    if third == "OFF" :
                        third = "ON"
                    else :
                        score += 1
        elif event == "HOMERUN" :
            if first == "ON" :
                score += 1
                first = "OFF"
            if second == "ON" :
                score += 1
                second = "OFF"
            if third == "ON" :
                score += 1
                third = "OFF"
            score += 1
        else :
            out += 1
            if out == 3 :
                print(score)
                break

Python: n = int(input())
for _ in range(n):
    n_out, n_run, score = 0, 0, 0
    while n_out < 3:
        evt = input()
        if evt == 'HIT':
            if n_run < 3:
                n_run += 1
            else:
                score += 1
        elif evt == 'HOMERUN':
            score += n_run + 1
            n_run = 0
        elif evt == 'OUT':
            n_out += 1
    print(score)

Python: n = int(input())
for i in range(n):
    hit_cou = 0
    out_cou = 0
    poi = 0
    while True:     
        eve = input()
        if eve == "HIT":
            if hit_cou == 3:
                poi += 1
            else:
            
                hit_cou += 1
        elif eve == "OUT":
            if out_cou == 2:
                print(poi)
                break
            else:
                out_cou += 1
        elif eve == "HOMERUN":
            poi += hit_cou + 1
            hit_cou = 0

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
            if runner[1] == 1:
                runner[2] = 1
            if runner[0] == 1:
                runner[1] = 1
            runner[0] = 1
        elif event == 'HOMERUN':
            point += (sum(runner)+1)
        elif event == 'OUT':
            out += 1
            if out == 3:
                print(point)
                break

Python: ininng = int(input())
for i in range(ininng):
  base=[0,0,0]
  out=0
  score=0
  while out<3:
    event=input()
    if event=="HIT":
      if base[2]==1:
          base[2]=0
          score+=1
      if base[1]==1:
          base[2]=1
          base[1]=0
      
      if base[0] ==1:
          base[0]=0
          base[1]=1
        
      base[0]=1
    elif event=="HOMERUN":
      score=score+sum(base)+1
      base=[0,0,0]
    else:
      out+=1
  print(score)

Python: import sys
#from me.io import dup_file_stdin

#@dup_file_stdin
def solve():
    n = int(sys.stdin.readline())*3
    s = 0
    p = 0
    while n>0:
        log = sys.stdin.readline()
        if "HIT" in log:
            if p >= 3:
                s += 1 
            else:
                p += 1
        elif "OUT" in log:
            n -= 1
            if n % 3 == 0:
                print(s)
                s = 0
                p = 0
                if n == 0:
                    break
        else:
            s += p + 1
            p = 0  
solve()

Python: n = int(input())
score = [0] * n
for i in range(n):
    out_count = 0
    runner = 0
    while True:
        data = input()
        if data == "OUT":
            out_count += 1
            if out_count == 3:
                break
        elif data == "HIT":
            runner += 1
            if runner == 4:
                runner = 3
                score[i] += 1
        else:
            score[i] += runner + 1
            runner = 0
print(*score, sep="\n")

Python: from collections import deque
n=int(input())
for i in range(n):
    out,res=0,0
    q=deque([])
    while out<3:
        s=input()
        if s=='OUT':
            out+=1
        elif s=='HIT':
            if len(q)==3:
                res+=1
            else:
                q.append(0)
        else:
            res+=len(q)+1
            q.clear()
    print(res)

Python: n = int(input())
cnt, hit, out = 0, 0, 0
while n != 0:
    s = input()
    if s == 'HIT':
        hit += 1
        if hit == 4:
            cnt += 1
            hit -= 1
    elif s == 'HOMERUN':
        cnt += hit + 1
        hit = 0
    else:
        out += 1
    if out == 3:
        print(cnt)
        cnt, hit, out = 0, 0, 0
        n -= 1

Python: A = B = 0
team = "A"
n = int(input())
for i in range(n):
    cnt =  b1 = b2 = b3 = out = 0
    while out != 3:
        s = input()
        if s == "HIT":
            if b3 == 1:
                cnt+=1
            b1,b2,b3 = 1,b1,b2
        elif s == "HOMERUN":
            cnt+=b1+b2+b3+1
            b1 = b2 = b3 = 0
        elif s == "OUT":
            out+=1
            if out == 3 and team == "A":
                A+=cnt
                team="B"
                print(cnt)
            elif out == 3 and team == "B":
                B+=cnt
                team="A"
                print(cnt)

Python: n = int(input())
out_count = 0
score = 0
runners = [0, 0, 0]

while n:
    event = input()
    if event == "HIT":
        if runners.pop():
            score+=1
        runners = [1] + runners
    if event == "HOMERUN":
        score += 1 + sum(runners)
        runners = [0, 0, 0]
                
    if event == "OUT":
        out_count += 1
        if out_count > 2:
            n-=1
            print(score)
            score = 0
            out_count = 0
            runners = [0, 0, 0]