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

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int main() {
    int n;
    cin >> n;
    int a = 0, b = 0, out = 0, ini = 0;
    int base[4] = {0};
    string s;
    while (cin >> s) {
        if (out == 3) {
            out = 0;
            ini++;
            REP(i,4) base[i] = 0;
        }
        if (s == "HIT") {
            for (int i = 2; i >= 0; i--) {
                if (base[i]) base[i+1] = 1, base[i] = 0;
            }
            base[0] = 1;
            if (base[3]) {
                if (ini % 2 + 1) a++;
                else b++;
                base[3] = 0;
            }
        }else if (s == "HOMERUN") {
            if (ini % 2 + 1) {
                REP(i,3) a += base[i];
                a++;
            }else {
                REP(i,3) b += base[i];
                b++;
            }
            REP(i,3) base[i] = 0;
        }else {
            out++;
        }
    }
    cout << a << endl << b << endl;
}

C++: #include <iostream>
#include <string>

using namespace std;

int main(){
	int n , i = 1;
	int base = 0 , sum[3] = {} , out_count = 0;
	string str;

	cin >> n;
		
	while(1){
	    
		if(i > n) break;
		cin >> str;
		
		if(out_count >= 3){
			base = 0;
			i++;
		}
		if(base >= 4){
		    sum[i]++;
		    base = base - 1;
		}
		if(str == "HIT"){base++;}
		else if(str == "OUT"){out_count++;}
		else if(str == "HOMERUN"){
		    sum[i] += base + 1;
		    base = 0;
		}
		
	}
	cout << sum[1] << " " << sum[2] << endl;

	return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>


using namespace std;

void Solution()
{
    int n;
    
    
    
    cin >> n;
    
    while(n--)
    {
        
        string str;
        
        int point = 0;
        
        int out = 0;
        
        int base[3] = {0, 0, 0};
        
        while(cin>>str)
        {
            
            if(str == "HIT")
            {
                if(base[2] == 1)
                {
                    ++point;
                    
                    base[2] = 0;
                }
                
                if(base[1] == 1)
                {
                    base[2] = 1;
                    base[1] = 0;
                }
                
                if(base[0] == 1)
                {
                    base[1] = 1;
                    base[0] = 0;
                }
                
                base[0] = 1; //point
            }
            else if(str == "HOMERUN")
            {
                for(int i=0; i < 3; ++i)
                {
                    point += base[i];
                }
                
                point++;
                
                base[0] = 0;
                base[1] = 0;
                base[2] = 0;
            }
            else
            {
                ++out;
                
                if(out >= 3)
                {
                    cout<<point<<endl;
                    
                    point = 0;
                    out = 0;
                    
                    base[0] = 0;
                    base[1] = 0;
                    base[2] = 0;
                    
                    continue;
                }
            }
        }
    }
    
}

int main()
{
    Solution();
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
    int inning;
    cin >> inning;
    for(int i=0;i<inning;i++){
        int point,runner,out;
        point=runner=out=0;
        while(out!=3){
            char c[8];
            cin >> c;
            if(c[0]=='O')
                out+=1;
            if(c[0]=='H' && c[1]=='I'){
                if(runner==3)
                    point+=1;
                else
                    runner+=1;
            }
            if(c[0]=='H' && c[1]=='O'){
                point +=runner+1;
                runner =0;
            }
        }
        cout << point << endl;
    }
}

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

int main(){
	string t1("HIT"), t2("OUT"), t3("HOMERUN");
	int n;
	cin >> n;
	string s;
	for(int i = 0; i < n; i++){
		int out = 0;
		int count = 0;
		int point = 0;
		while(out != 3){
			cin >> s;
			if(s == t2){
				out++;
			}else if(s == t3){
				point += count + 1;
				count = 0;
			}else if(s == t1){
				if(count == 3) point++;
				else count++;
			}
		}
		cout << point << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>

int base;

int hit(){
	if(base==3) return 1;
	else base++;
	return 0;
}

int homerun(){
	base++;
	return base;
}

int main(){
	int inning;
	std::cin >> inning;

	for(int i=0;i<inning;i++){
		int outCount=0;
		int point=0;
		string result;
		base=0;
		while(outCount<3){
			std::cin >> result;

			if(result == "HIT"){
				point += hit();
			} else if(result == "HOMERUN"){
				point += homerun();
				base=0;
			} else if(result == "OUT"){
				outCount++;
			}
		}
		std::cout << point << std::endl;
	}

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int n;
int out = 0,point = 0;
bool base[3];
string str;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	while(true){
		cin >> str;
		if(str[0] == 'O'){
			out++;
			if(out%3 == 0){
				cout << point << endl;
				point = 0;
				rep(i,3) base[i] = 0;
			}
			if(out == n*3) break;
		} else if(str[1] == 'O'){
			point++;
			rep(i,3) if(base[i]) point++;
			rep(i,3) base[i] = 0;
		} else{
			if(base[2]) point++;
			if(base[1]) base[2] = 1;
			if(base[0]) base[1] = 1;
			base[0] = 1;
		}
	}
}