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: import sys
n = int(sys.stdin.readline().rstrip())
for i in range(n):
    out = score = 0
    runner = [0] * 3
    while out < 3:
        st = sys.stdin.readline().rstrip()
        if st == 'HIT':
            score += runner[2]
            runner = [1] + runner[:-1]
        elif st == 'HOMERUN':
            score += sum(runner) + 1
            runner = [0] * 3
        else:
            out += 1
    print(score)

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:
            print(score)
            score = 0
            out_count = 0
            runners = [0, 0, 0]

Python: class Baseball():
    def __init__(self, runner, score, out):
        self.runner = runner
        self.score = score
        self.out = out


for i in range(int(input())):
    inning = Baseball(0,0,0)
    while True:
        event = input()
        if event == 'HIT':
            if inning.runner == 3:
                inning.score += 1
            else:
                inning.runner += 1
        elif event == 'HOMERUN':
            inning.score += inning.runner +1
            inning.runner = 0
        elif event == 'OUT':
            inning.out += 1
            if 2 < inning.out:
                break
        else:
            pass
    print(str(inning.score))

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)
        elif event == 'OUT':
            out += 1
            if out == 3:
                print(point)
                break

Python: n = int(input())
for i in range(n):
    r = 0
    p = 0
    o = 0
    while o < 3:
        e = input()
        if e == "OUT":
            o += 1
        elif e == "HIT":
            if r == 3:
                p += 1
            else:
                r += 1
        else:
            p += r + 1
            r = 0
    print(p)

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 o<2:o+=1
   else:print(s);break

Python: import sys
n = int(sys.stdin.readline().rstrip())
for i in range(n):
    out = score = 0
    runner = [0] * 3
    while out < 3:
        st = sys.stdin.readline().rstrip()
        if st == 'HIT':
            score += runner[2]
            runner = [1] + runner[:-1]
        elif st == 'HOMERUN':
            score += sum(runner) + 1
            runner = [0] * 3
        else:
            out += 1
    print(score)

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,1]
      
  elif b == "HOMERUN":
    ba.append(1)
    sc+=len(ba)
    ba=[]
[print(i) for i in s]

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 
            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: event = []
inning = int(input())


NONE   = 0b000
FIRST  = 0b001
SECOND = 0b010
THIRD  = 0b100

runner = NONE
currentInning = 0
score = 0
outCount = 0
inningScore = []

while currentInning < inning:
    data = input()
    if data == "HIT":
        if (runner & THIRD) == THIRD:
            score += 1
            runner &= ~THIRD
        runner = runner << 1
        runner |= FIRST
    elif data == "OUT":
        outCount += 1

    elif data == "HOMERUN":
        if (runner & THIRD) == THIRD:
            score += 1
        if (runner & SECOND) == SECOND:
            score += 1
        if (runner & FIRST) == FIRST:
            score += 1
        score += 1
        runner = NONE
    
    if outCount == 3:
        inningScore.append(score)
        currentInning += 1
        outCount = 0
        score = 0
        runner = NONE

for i in range(inning):
    print(inningScore[i])

Python: #import random
#basball
ineng = int(input())
#ivent_list = [random.randint(0,3) for _ in range(ineng)]
for _ in range(ineng):
    out_count = 0
    runner =0
    score = 0
    while out_count <3:
        event = input()
        if event == "HIT":
            runner +=1
            if runner >=4:
                score +=1
                runner = 3
                
        elif event == "HOMERUN":
            score += (runner + 1)
            runner = 0
        else:
            out_count +=1

    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)