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)
	}
}

C++: #include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int xcomp(vector<LL>& a, vector<LL>& b) {
	return a[0] < b[0];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

int main() {
	int N;
	cin >> N;
	REP(i, N) {
		int a1 = 0;
		int a2 = 0;
		int a3 = 0;
		int out = 0;
		int pt = 0;
		while (true) {

			string s;
			cin >> s;
			if (s[1] == 'I') {
				if (a3 == 1) {
					a3 = 0;
					pt++;
				}
				if (a2 == 1) {
					a2 = 0;
					a3 = 1;
				}
				if (a1 == 1) {
					a1 = 0;
					a2 = 1;
				}
				a1 = 1;
			}
			else
				if (s[1] == 'U') {
					out++;
					if (out == 3) {
						break;
					}
				}
				else {
					if (a1 == 1) {
						a1 = 0;
						pt++;
					}
					if (a2 == 1) {
						a2 = 0;
						pt++;
					}
					if (a3 == 1) {
						a3 = 0;
						pt++;
					}
					pt++;
				}
		}
		cout << pt << endl;
	}
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ELEM(array) (sizeof (array)/sizeof *(array))
#define MAX_N 100
typedef long long ll;
 
int n;
int count_HIT=0, count_OUT=0;
int Point=0;
string S;
 
 
void solve()
{
    while (count_OUT <3)
    {
        cin >> S;
        if (S == "HIT")
        {
            count_HIT++;
            if (count_HIT == 4)
            {
                Point++;
                 
                count_HIT -- ;
            }
        }
        else if (S == "HOMERUN")
        {
            Point += count_HIT + 1;
             
            count_HIT = 0;
        }
        else count_OUT++;
    }
    cout << Point << endl;
    count_OUT = 0; count_HIT = 0;
    Point = 0;
     
    return;
}
 
int main()
{
    cin >> n;
    REP(j, n)
    {
        solve();
    }
 
     
 
    return 0;
}

C++: #include<iostream>
#include<vector>
int main(){
	int n,m=0;
	std::cin>>n;
	int o=0;
	std::vector<int> vec(3);
	std::vector<int> vec2(n);
	int d=0;
	while(n>m){
		std::string str;
		std::cin>>str;
		if(str=="HIT"){
			if(vec[2]==1)vec2[d]+=1,vec[2]=0;
			if(vec[1]==1)vec[2]=1,vec[1]=0;
			if(vec[0]==1)vec[1]=1,vec[0]=0;
			vec[0]=1;
		}
		if(str=="HOMERUN"){
			for(int i=0;i<3;i++){
				if(vec[i]==1)vec2[d]+=1;
				vec[i]=0;
			}
			vec2[d]+=1;
		}

		if(str=="OUT")o++;
		if(o==3){
			m++,o=0,d++;
			for(int i=0;i<3;i++){
				vec[i]=0;
			}
		}
	}
	for(int i=0;i<n;i++){
		std::cout<<vec2[i]<<std::endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)(テつエテ」ツδサテ渉嘉」ツδサ`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	REP(i, n) {
		int out = 0, score = 0;
		vi v(3, 0);
		while (out <3) {
			string s;
			cin >> s;
			if (s[0] == 'H') {
				RREP(i, 3) {
					if (v[i] == 1) {
						if (i == 2)score++;
						else v[i + 1]++;
						v[i]--;

					}
				}
				v[0]++;
			}
			else if (s[0] == 'O') {
				out++;
			}
			else {
				REP(i, 3) {
					if (v[i] == 1) {
						score++;
						v[i] = 0;
					}
				}
			}
		}
		cout << score << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include<iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

using namespace std;

int main(){
	int n;
	cin>>n;
	rep(I,n){
		int no=0, po=0;
		int base[3]={0,0,0};
		while(no<3){
			string cmd;
			cin>>cmd;
			if(cmd=="HIT"){
				if(base[2]) po++;
				for(int i=2;i>0;--i){
					base[i]=base[i-1];
				}
				base[0]=1;
			}else if(cmd=="OUT"){
				no++;
			}else if(cmd=="HOMERUN"){
				int co=0;
				rep(i,3){
					if(base[i]){
						co++;
						base[i]=0;
					}
				}
				po+=co+1;
			}
		}
		cout<<po<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;

int main(){
  int n,ansc[100]={},o=0,hr=0,h=0,o2=0;
  string event;
  cin>>n;
  int i=0;
  int j=0;
  while(1){
    cin>>event;
    if(event=="OUT"){
      o++;
      o2++;
    }
    if(event=="HIT")h++;
    if(event=="HOMERUN")hr++;

    if(o2==3*n)break;

    if(h==4){
      ansc[j]++;
      h--;
    }
    else if(o==3){
      o=0;
      h=0;
      j++;
    }
    else if(hr==1){
      ansc[j]+=h+1;
      h=0;
      hr=0;
    }
    i++;
  }
  for(int j=0;j<n;j++)
  cout<<ansc[j]<<endl;
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#define PI 3.141592653589793
using namespace std;
int main(){
	int n;
	string str;
	cin>>n;
	for(int i=0;i<n;i++){
		int cnt=0,num=0;
		int rui[5]={0};
		while(cin>>str){
			if(str=="HIT"){
				rui[4]=rui[3];
				rui[3]=rui[2];
				rui[2]=rui[1];
				rui[1]=1;
				if(rui[4]==1){
					rui[4]=0;
					cnt++;
				}
			}else if(str=="HOMERUN"){
				for(int j=1;j<=3;j++){
					if(rui[j]==1){
						rui[j]=0;
						cnt++;
					}
				}
				cnt++;
			}else{
				num++;
				if(num==3)break;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}