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: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0103&lang=jp
"""
import sys



class Baseball():
    def __init__(self):
        self.score = 0
        self.out_count = 0
        self.base = [0, 0, 0]

    def event(self, e):
        if e == 'HIT':
            self.base.insert(0, 1)
            home = self.base.pop()
            if home:
                self.score += 1
        elif e == 'HOMERUN':
            self.score += self.base.count(1)
            self.score += 1
            self.base = [0, 0, 0]
        elif e == 'OUT':
            self.out_count += 1


def main(args):
    num = int(input().strip())
    for _ in range(num):
        b = Baseball()
        while b.out_count < 3:
            b.event(input().strip())
        print(b.score)


if __name__ == '__main__':
    main(sys.argv[1:])

Python: n=int(input())
r=o=s=0
while n:
 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);n-=1;r=o=s=0

Python: import sys

import sys
N = int(input())
turn = 0
point = 0
out = 0
base = [0, 0, 0]

point_list = []
for idx, line in enumerate(sys.stdin):
    if line == 'HOMERUN\n':
        # print('homerun')
        cnt = 1
        if base[0] == 1:
            cnt += 1
        if base[1] == 1:
            cnt += 1
        if base[2] == 1:
            cnt += 1
        point += cnt
        # print('point: %s' % point)
        base = [0, 0, 0]

    if line == 'HIT\n':
        # print('hit')
        if base[2] == 1:
            base[2] = 0
            point += 1
            # print('point: %s' % point)
        if base[1] == 1:
            base[2] = 1
        if base[0] == 1:
            base[1] = 1
        if base[0] == 0:
            base[0] = 1
        # print(base)

    if line == 'OUT\n':
        # print('out')
        out += 1
        # print(out)
        if out == 3:
            # print('change')
            point_list.append(point)
            turn += 1
            point = 0
            base = [0, 0, 0]
            out = 0
            if turn == N:
                # print('gameset')
                break
            continue

for e in point_list:
    print(e)

Python: n=int(input())
g=1
while g<=n:
    out=0
    #0ランナーなし、1ランナーあり,4番目得点
    runner=[0,0,0,0]
    #3アウトまで
    while out<3:
        batter=str(input())
    #アウト
        if batter=="OUT":
            out+=1
    #ヒット
        if batter=="HIT":
            for i in range(3):
                if i==0:
                    runner[0]+=1

                if runner[i]==2:
                    runner[i]=1
                    runner[i+1]+=1
    #ホームラン
        if batter=="HOMERUN":
            for i in range(3):
                if runner[i]==1:
                    runner[i]=0
                    runner[3]+=1
            runner[3]+=1

    print(runner[3])
    g+=1

Python: num = int(input())
for _ in range(num):
    P = 0
    B = [0] * 3
    O = 0
    while True:
        s = input()
        if s == "OUT":
            O += 1
            if O > 2:
                break
        elif s == "HIT":
            P += B[2]
            B[2] = B[1]
            B[1] = B[0]
            B[0] = 1
        elif s == "HOMERUN":
            P += sum(B)
            P += 1
            B = [0] * 3
        else:
            pass

    if O > 2:
        print(P)
        continue

Python: SCORE=[]
preSCORE=0
OUTcount=0
BASE=[False]*3
n=int(input())
for i in range(n):
    while OUTcount<3:
        spam=input()
        if 'HIT' in spam:
            if BASE[2]==True:
                preSCORE+=1
            BASE[2]=BASE[1]
            BASE[1]=BASE[0]
            BASE[0]=True
        elif 'OUT' in spam:
            OUTcount+=1
        elif 'HOMERUN' in spam:
            preSCORE+=sum(x for x in BASE)+1
            BASE=[False]*3
    SCORE.append(preSCORE)
    BASE=[False]*3
    OUTcount=0
    preSCORE=0
for i in SCORE:
    print(i)

Python: # -*- coding: utf-8 -*-

import sys
import os

n = int(input())
for i in range(n):
    base = [0, 0, 0]
    score = 0
    out_count = 0
    while True:
        s = input().strip()
        if s == 'HIT':
            if base[2] == 1:
                score += 1
            base[2] = base[1]
            base[1] = base[0]
            base[0] = 1

        elif s == 'HOMERUN':
            score += sum(base) + 1
            base = [0, 0, 0]

        elif s == 'OUT':
            out_count += 1
            if out_count > 2:
                break
    print(score)

Python: #!/usr/bin/python3

n = int(input())

def solve():
    o = 0
    s = 0
    b = [False, False, False]
    while o < 3:
        inst = input()
        if inst == 'OUT':
            o += 1
        elif inst == 'HIT':
            if b[2]:
                s += 1
            b2 = [True]
            b2.extend(b[0:2])
            b = b2
        elif inst == 'HOMERUN':
            s += 1
            for k in range(3):
                if b[k]:
                    b[k] = False
                    s += 1
    return s

for _ in range(n):
    print(solve())

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: def hit(point, base, out_count):
    new_base = (base << 1) + 1
    return point + (new_base > 0b111), new_base & 0b111, out_count


def homerun(point, base, out_count):
    return point + (bin(base & 0b111).count('1') + 1), 0, out_count


def out(point, base, out_count):
    return point, base, out_count - 1


F = {'HIT': hit, 'HOMERUN': homerun, 'OUT': out}

i, point, base, out_count = int(input()), 0, 0, 3

while i:

    point, base, out_count = F[input().strip()](point, base, out_count)

    if not out_count:
        i -= 1
        print(point)
        point, base, out_count = 0, 0, 3

Python: for inning in range(int(input())):
    out=0
    runner=[0]*4
    while out<3:
        event=input()
        if event=="HIT":
            for i in range(3,0,-1):
                runner[i]+=runner[i-1]
                runner[i-1]=0
            runner[0]=1
        elif event=="HOMERUN":
            runner[3]+=1
            for i in range(3,0,-1):
                runner[3]+=runner[i-1]
                runner[i-1]=0
        elif event=="OUT":
            out+=1
        #print(runner)
    print(runner[3])

Python: N = int(input())

base = [0] * 3
out = 0
point = 0
inning = 0

while True:
    event = input()

    if event == "HIT":
        if base[2] == 1:
            point += 1
        base[2] = base[1]
        base[1] = base[0]
        base[0] = 1

    elif event == "HOMERUN":
        point += sum(base) + 1
        base = [0] * 3

    elif event == "OUT":
        out += 1
        if out == 3:
            print(point)
            inning += 1
            if inning == N:
                break
            base = [0] * 3
            out = 0
            point = 0