Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var inning int

	fmt.Scanf("%d", &inning)

	score := make([]int, inning)

	for i := 0; i < inning; i++ {
		var outCount, runnerCount int

		for scanner.Scan() {
			event := scanner.Text()

			// HIT, HOMERUN, OUT
			switch event {
			case "HIT":
				runnerCount++
				if runnerCount > 3 {
					runnerCount--
					score[i]++
				}
			case "HOMERUN":
				score[i] += runnerCount + 1
				runnerCount = 0
			case "OUT":
				outCount++
			}

			if outCount == 3 {
				break
			}
		}
	}

	for _, v := range score {
		fmt.Println(v)
	}
}

Python: a = int(input().rstrip())
b = 0
while a > b:
	c = 0
	runner = 0
	point = 0
	while c < 3:
		x = input().rstrip()
		if x == HIT:
			if runner == 3:
				point += 1
			else:
				runner += 1
		elif x == HOMERUN:
			point = point + runner + 1
			runner = 0
		else:
			c += 1
	print(point)

Python: num=int(input())
for i in range(num):
    outcount=0
    HIT=0
    HOMWRUN=0
    COUNT=0
    while True:
        a=input()
        if a=='HIT':
            HIT+=1
            if HIT==4:
                COUNT+=1
                HIT=1
        if a=='HOMERUN':
            COUNT+=(HIT+1)
        if a=='OUT':
            outcount+=1    
        if outcount==3:
            break
    print(COUNT)

Python: SCORE=[]
n=int(input())
for i in range(n):
    BASE=[False]*3
    OUTcount=0
    preSCORE=0
    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)
for i in SCORE:
    print(i)

Python: n = int(input())

for _ in range(n):
  out_cnt = 0
  runner = 0
  point = 0
  while out_cnt < 3:
    event = input()
    if event == "HIT":
      runner += 1
      if runner >= 4:
        point += 1
        runner = 3

    elif event == "HOMERUN":
      point += (runner + 1)
      runner = 0

    else:
      out_cnt += 1

  print(point)

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)

Python: n = int(input())
hit = out = score = 0
while(n):
    d = input()
    if d == "HIT":
        hit += 1
        if hit == 4:
            hit = 3
            score += 1
    elif d == "OUT":
        out += 1
        if out == 3:
            n -= 1
            print(score)
            hit = score = out = 0
    else:
        score += hit + 1
        hit = 0

Python: # AOJ 0103: Baseball Simulation
# Python3 2018.6.17 bal4u

for i in range(int(input())):
	p1 = p2 = p3 = out = cnt = 0;
	while True:
		s = input()
		if s == 'HIT':
			if p3 > 0: cnt += 1
			p3, p2, p1 = p2, p1, 1
		elif s == 'HOMERUN':
			cnt += p1 + p2 + p3 + 1
			p1 = p2 = p3 = 0
		else:
			out += 1
			if out == 3: break
	print(cnt)

Python: if __name__ == '__main__':

	n = int(input())

	ocnt = 0
	hcnt = 0
	score = 0

	while n > 0:
		line = input()
		if line == "HOMERUN":
			score += hcnt
			score += 1
			hcnt = 0
		elif line == "HIT":
			hcnt += 1
			if hcnt == 4:
				score += 1
				hcnt = 3
		else:
			ocnt += 1
			if ocnt == 3:
				print(score)
				ocnt = 0
				hcnt = 0
				score = 0
				n -= 1

Python: for i in range(int(input())):
	b1 = b2 = b3 = out = score = 0
	while 1:
		n = input()
		if n == "HIT":
			if b3 > 0 : 
				score += 1;
			b3 = b2;
			b2 = b1;
			b1 = 1;
		elif n == "HOMERUN":
			score += b1 + b2 + b3 + 1;
			b1 = b2 = b3 = 0
		elif n == "OUT":
			out += 1;
			if out >=3: break
	print(score)

Python: n = int(input())
score = [0 for i in range(n)]
inning = 1
runner = [0 for i in range(3)]
outCount = 0
inningScore = 0
while inning <= n:
    str = input()
    if str == "OUT":
        outCount += 1
    elif str == "HIT":
        runner.insert(0, 1)
        inningScore += runner[3]
        runner.pop()
    elif str == "HOMERUN":
        inningScore += 1
        for i in range(len(runner)):
            inningScore += runner[i]
            runner[i] = 0
    if outCount == 3:
        for i in range(len(runner)):
            runner[i] = 0
        score[inning-1] = inningScore
        inningScore = 0
        outCount = 0
        inning += 1
for i in range(len(score)):
    print(score[i])

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

  def __init__(self, score, first, second, third, out_counter):
    self.score = score
    self.first = first
    self.second = second
    self.third = third
    self.out_counter = out_counter

  def hit(self):
    if self.third == 1:
      self.score += 1
    if self.second == 1 and self.third == 0:
      self.third = 1
    if self.first == 1 and self.second == 0:
      self.second = 1
    if self.first == 0:
      self.first = 1

  def homerun(self):
    self.score += self.first + self.second + self.third + 1
    self.first = 0
    self.second = 0
    self.third = 0

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


for i in range(int(input())):
  baseball = Baseball(0, 0, 0, 0, 0)
  while 1:
    event = input()
    if event == "HIT":
      baseball.hit()
    elif event == "HOMERUN":
      baseball.homerun()
    else:
      baseball.out()
      if baseball.out_counter == 3:
        print(baseball.score)
        del baseball
        break

Python: var1 = int(input())
for m in range(0, var1):
    OutCount = 0
    BaseCount = 0
    PointCount = 0
    for i in range(0, 100):
        try:
            str1 = input()
            if str1 == 'HIT':
                BaseCount = BaseCount + 1
                if BaseCount == 4:
                    PointCount = PointCount + 1
                    BaseCount = 3
            elif str1 == 'HOMERUN':
                PointCount = PointCount + BaseCount + 1
                BaseCount = 0
            elif str1 == 'OUT':
                OutCount = OutCount + 1
                if OutCount == 3:
                    print(PointCount)
                    break
        except:
            break

Python: a = int(input().rstrip())
b = 0
while a > b:
	c = 0
	runner = 0
	point = 0
	while c < 3:
		x = input().rstrip()
		if x == "HIT":
			if runner == 3:
				point += 1
			else:
				runner += 1
		elif x == "HOMERUN":
			point = point + runner + 1
			runner = 0
		else:
			c += 1
	print(point)

Python: #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    for _ in range(int(readline())):
        first = second = third = out = point = 0

        while out < 3:
            event = readline()[1]

            if event == 'I':
                point += third
                third = second
                second = first
                first = 1
            elif event == 'U':
                out += 1
            else:
                point += first + second + third + 1
                first = second = third = 0

        print(point)
    exit()


if __name__ == '__main__':
    main()

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
  if'O'==a:s+=r+1;r=0
  if'U'==a:
   if o<2:o+=1
   else:print(s);break