Problem:


Baseball Simulation

Ichiro likes baseball and has decided to write a program which simulates baseball.

The program reads events in an inning and prints score in that inning. There are only three events as follows:

Single hit

put a runner on the first base.

the runner in the first base advances to the second base and the runner in the second base advances to the third base.

the runner in the third base advances to the home base (and go out of base) and a point is added to the score.

Home run

all the runners on base advance to the home base.

points are added to the score by an amount equal to the number of the runners plus one.

Out

The number of outs is increased by 1.

The runners and the score remain stationary.

The inning ends with three-out.

Ichiro decided to represent these events using "HIT", "HOMERUN" and "OUT", respectively.

Write a program which reads events in an inning and prints score in that inning. You can assume that the number of events is less than or equal to 100.

Input

The input consists of several datasets. In the first line, the number of datasets n is given. Each dataset consists of a list of events (strings) in an inning.

Output

For each dataset, prints the score in the corresponding inning.

Sample Input

2
HIT
OUT
HOMERUN
HIT
HIT
HOMERUN
HIT
OUT
HIT
HIT
HIT
HIT
OUT
HIT
HIT
OUT
HIT
OUT
OUT

Output for the Sample Input

7
0



Sample input:
2
HIT
OUT
HOMERUN
HIT
HIT
HOMERUN
HIT
OUT
HIT
HIT
HIT
HIT
OUT
HIT
HIT
OUT
HIT
OUT
OUT


Sample output:
7
0

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
p = 0
b = [0,0,0]
o = 0
for i in range(N):
    e = raw_input()
    if e == 'HIT':
        if b[-1] == 1:
            p += 1
        b[0],b[1],b[2] = 1,b[0],b[1]
    elif e == 'HOMERUN':
        p += sum(b)+1
        b = [0,0,0]
    elif e == 'OUT':
        o += 1
        if o == 3:
            print p
            p = 0
            b = [0,0,0]
            o = 0

Submission status: Wrong Answer

Solution code:
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)
                break

Submission status: Wrong Answer

Solution code:
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

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
for i in range(n):
    out = 0
    base = [0] * 4
    while out != 3:
        s = raw_input()
        if s  == 'HIT':
            if base[2] == 1:
                 base[3] += 1
            base[2] = base[1]
            base[1] = base[0]
            base[0] = 1 
        elif s == 'HOMERUN':
            base[3] += base.count(1)+1
            base[0] = 0
            base[1] = 0
            base[2] = 0
        else:
            out += 1
    print base[3]

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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

Submission status: Wrong Answer

Solution code:
ining = int(input())
out_count = 0
score = 0
bases = []

while True:
    print(score)
    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:]
            score = score + 1
            continue
    elif n == 'HOMERUN':
        score = len(bases) + 1
        bases = []
        continue

print(score)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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()

Submission status: Wrong Answer

Solution code:
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]

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    r = int(raw_input())
    totalOuter = 0
    goal = 0
    bs = [0,0,0]#base situation
    while r > 0:
        event = raw_input()
#        print "get",event
        if event == "HIT":
 #           print "#HIT"
            if bs[2] == 1:
                bs[2] =0
                goal += 1
            if bs[1] == 1:
                bs[1] = 0
                bs[2] = 1
            if bs[0] == 1:
                bs[0] = 0
                bs[1] = 1
            else:
                bs[0] += 1
        elif event == "HOMERUN":
            for i in range(3):
                if bs[i] != 0:
                    goal += 1
                    bs[i] = 0
            goal += 2
        elif event == "OUT":
            totalOuter += 1
  #          print "#OUT"

        if totalOuter == 3:
            print goal
            goal = 0
            totalOuter = 0
            bs = [0,0,0]
            r -= 1
           


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
n = int(raw_input())
   
runner = 0
run = 0
out = 0
inning = 0
while inning < n:
    event = raw_input()
    if event == 'HIT':
        if runner == 3:
            run += 1
        else:
            runner += 1
    elif event == 'HOMERUN':
        run += (runner+1)
        runner = 0
    else:
        if out == 2:
            print run
            runner = 0
            run = 0
            out = 0
            inning += 1
        else:
            out += 1

Submission status: Accepted

Solution code:
n=input()
for _ in [0]*n:
  i=0
  B=[0]*3
  c=0
  while i<3:
    s=raw_input()[1]
    if s=='I':
      if B[2]==1:c+=1
      B=[1]+B[0:2]
    elif s=='O':
      c+=sum(B)+1
      B=[0]*3
    elif s=='U':i+=1
  print c

Submission status: Accepted

Solution code:
n=input()
for _ in [0]*n:
  i=0
  b=0
  c=0
  while i<3:
    s=raw_input()[1]
    if s=='I':
      if b==3:c+=1
      else: b+=1
    elif s=='O':
      c+=b+1
      b=0
    elif s=='U':i+=1
  print c

Submission status: Accepted

Solution code:
n=input()
for _ in [0]*n:
  i,b,c=0,0,0
  while i<3:
    s="IOU".index(raw_input()[1])
    if s==0:
      if b==3: c+=1
      else: b+=1
    elif s==1:
      c+=b+1
      b=0
    elif s==2: i+=1
  print c

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/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())

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

def main():
    # 入力
    N = int(raw_input())

    for i in range(N):
        data = {}
        b = Baseball()
        while(b.out < 3):
            event = raw_input()
            b.decisionScore(event)

        print(b.score)

class Baseball():
    def __init__(self):
        self.out = 0
        self.score = 0
        self.que = [0,0,0]  #Third, Second, First

    def decisionScore(self, event):
        if event == "OUT":
            self.out += 1
        elif event == "HIT":
            self.score += self.addRunner()
        elif event == "HOMERUN":
            self.score += self.clearRunnner() + 1
        else:
            print("Wrong data")

    def addRunner(self):
        self.que.append(1)
        point = self.que[0]
        self.que = self.que[1:]
        return point

    def clearRunnner(self):
        point = sum(self.que)
        self.que = [0,0,0]
        return point

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright  : @Huki_Hara
# Created    : 2015-03-16

for _ in range(int(input())):
    ans = 0
    out = 0
    hit = 0
    while True:
        w = input()
        if w == "OUT":
            out += 1
            if out == 3:
                break
        elif w == "HIT":
            if hit == 3:
                ans += 1
            else:
                hit += 1
        elif w == "HOMERUN":
            ans += hit + 1
            hit = 0
    print(ans)

Submission status: Accepted

Solution code:
n=int(raw_input())
game=0
while game<n:
    run=0
    score=0
    out=0
    while out<3:
        ev=raw_input()
        if ev=='OUT':
            out=out+1
        elif ev=='HIT':
            run=run+1
            if run>3:
                run=3
                score=score+1
        else:
            score=score+run+1
            run=0
    print score
    game=game+1

Submission status: Accepted

Solution code:
while True:
    try:
        n = int(raw_input())
    except EOFError:
        break

    for i in range(n):
        base = [False,False,False] # first, second, third
        point = 0
        out = 0
        while out <3:
            order = raw_input()
            if order =='HIT':
                base.insert(0,True)
                if base[-1]:
                    base.pop()
                    point += 1
                else:
                    base.pop()
            elif order == 'OUT':
                out += 1
            elif order == 'HOMERUN':
                point += sum(base) + 1
                base = [False,False,False]
        else:
            print point

Submission status: Accepted

Solution code:
n = input()
base, out, score = [0]*3, 0, 0
while True:
    if n == 0:
        break
    event = raw_input()
    if event == 'OUT':
        out += 1
        if out == 3:
            print score
            base, out, score = [0]*3, 0, 0
            n -= 1
    elif event == 'HIT':
            score += base.pop()
            base.insert(0, 1)
    else:
            score += sum(base)+1
            base = [0] * 3

Submission status: Accepted

Solution code:
from collections import deque

inning = 0
point = 0
out = 0
base = deque([0] * 3)

n = input()
while True:
    event = raw_input()
    if event == "HIT":
        point += base.pop()
        base.appendleft(1)
    elif event == "HOMERUN":
        point += base.count(1) + 1
        base = deque([0] * 3)
    else:
        out += 1
        if out == 3:
            print point
            point = 0
            out = 0
            base = deque([0] * 3)
            inning += 1
            if inning == n: break

Submission status: Accepted

Solution code:
N = int(raw_input())
p = 0
b = [0,0,0]
o = 0
while True:
    try:
        e = raw_input()
        if e == 'HIT':
            if b[-1] == 1:
                p += 1
            b[0],b[1],b[2] = 1,b[0],b[1]
        elif e == 'HOMERUN':
            p += sum(b)+1
            b = [0,0,0]
        elif e == 'OUT':
            o += 1
            if o == 3:
                print p
                p = 0
                b = [0,0,0]
                o = 0
    except EOFError:
        break

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
n = int(input())

for i in range(n):
    first = False
    second = False
    third = False
    out = 0
    points = 0
    
    while (out != 3):
        event = raw_input()
        if event == "HIT":
            if first == True:
                if second == True:
                    if third == True:
                        points += 1

                    else:
                        third = True
                else:
                    second = True
            else:
                first = True

        elif event == "HOMERUN":
            if third == True:
                points += 4
            elif second == True:
                points += 3
            elif first == True:
                points += 2
            else:
                points += 1

            first = second = third = False

        else:
            out += 1

    print points

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
  l = [1,0,0,0]
  c = 0
  o_c = 0
  while True:
    s = input()
    if s == 'HIT':
      if l[3] == 1:
        c += 1
      for i in range(4):
        if i == 3:
          l[3-i] == 1
        else:
          l[3-i] = l[2-i]
    elif s == 'HOMERUN':
      c += sum(l)
      l = [1,0,0,0]
    else:
      o_c += 1
      if o_c == 3:
        print(c)
        break

Submission status: Accepted

Solution code:
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)
            runner = [0, 0, 0]
        elif event == 'OUT':
            out += 1
            if out == 3:
                print(point)
                break

Submission status: Accepted

Solution code:
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] = 1
        elif event == 'HOMERUN':
            point += (sum(runner)+1)
            runner = [0, 0, 0]
        elif event == 'OUT':
            out += 1
            if out == 3:
                print(point)
                break

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
import sys

n = input()
events = []
for line in sys.stdin:
    events.append(line.strip())

out = 0
score = 0
runner = 0
for event in events:
    if event == 'OUT':
        out += 1
        if out == 3:
            print score
            out = 0
            score = 0
            runner = 0
    elif event == 'HIT':
        if runner == 3:
            score += 1
        else:
            runner += 1
    elif event == 'HOMERUN':
        score += runner+1
        runner = 0

Submission status: Accepted

Solution code:
def game():
    score=out=0
    runner=[0]*3
    while 1:
        t=raw_input()
        if t=='OUT':
            out+=1
            if out==3:
                return score
        elif t=='HOMERUN':
            score+=(1+runner.count(1))
            runner=[0]*3
        elif t=='HIT':
            if runner[2]==1:
                score+=1
                runner[2]=0
            runner=[1,runner[0],runner[1]]

n=int(raw_input())
for i in range(n):
    print game()

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
def init_state():
    return 0, 0, 0


def main():
    n = int(input())

    point, hit, out = init_state()

    while True:
        if n == 0:
            break

        event = input()

        if event == 'HIT':
            if hit >= 3:
                point += 1
            else:
                hit += 1
        elif event == 'OUT':
            out += 1
        elif event == 'HOMERUN':
            point += hit + 1
            hit = 0

        if out == 3:
            print(point)
            point, hit, out = init_state()
            n -= 1


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
score = 0
outcount = 0
first = 0
second = 0
third = 0
for i in range(n):
	while outcount < 3:
		event = input()
		if event == 'HIT':
			if third == 1:
				score += 1
			third = second
			second = first
			first = 1
		if event == 'HOMERUN':
			score = score + first + second + third + 1
			first = second = third = 0
		if event == 'OUT':
			outcount += 1
	print(score)
	score = 0
	outcount = 0
	first = 0
	second = 0
	third = 0

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    out_count = 0
    score = 0
    runner = []
    while True:
        if out_count == 3:
            print(score)
            break
            
        events = input()
        if events == "HIT":
            if len(runner) == 3:
                score += 1
            else:
                runner.append(1)

        elif events == "HOMERUN":
            score += len(runner) + 1
            runner = []

        elif events == "OUT":
            out_count += 1

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
for Panzerlied in range(0,int(input())):
  runners = 0
  outs = 0
  points = 0
  while outs<3:
    command=input()
    if command == "HIT":
      runners+=1
      if runners > 3:
        runners=3
        points+=1
    elif command == "HOMERUN":
      points+=(runners+1)
      runners=0
    else: # command == "OUT"
      outs+=1
  print(points)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    hit_cou = 0
    out_cou = 0
    poi = 0
    while True:     
        eve = input()
        if eve == "HIT":
            if hit_cou == 3:
                poi += 1
            else:
            
                hit_cou += 1
        elif eve == "OUT":
            if out_cou == 2:
                print(poi)
                break
            else:
                out_cou += 1
        elif eve == "HOMERUN":
            poi += hit_cou + 1
            hit_cou = 0

Submission status: Accepted

Solution code:
n=int(input())
b=[0]*3;s=o=0
while n:
    e=input()
    if len(e)>3:s+=sum(b)+1;b=[0]*3
    elif e[0]=='H':
        if b.pop():s+=1
        b=[1]+b
    else:
        o+=1
        if o==3:n-=1;b=[0]*3;print(s);o=s=0

Submission status: Accepted

Solution code:
n = int(input())

for _ in range(n):
    runners = []
    outs = 0
    score = 0
    while True:
        s = input()
        if s == "HIT":
            runners.append(0)
            for i in range(len(runners)):
                runners[i] += 1
                if runners[i] == 4:
                    score += 1
            if 4 in runners:
                runners.remove(4)
        elif s == "HOMERUN":
            score += len(runners) + 1
            runners = []
        elif s == "OUT":
            outs += 1
            if outs == 3:
                break
    print(score)

Submission status: Accepted

Solution code:
def main():
    kai, wo = 0, []
    kai = input()
    while(True):
        try:
            wo.append(raw_input())
        except EOFError:
            break
    R, S, O = 0, 0, 0
    for i in wo:
        if i == "HIT":
            if R < 3:
                R += 1
            else:
                S += 1

        elif i == "OUT":
            O += 1
            if O >= 3:
                print S
                R, S, O = 0, 0, 0
            else: pass
        elif i == "HOMERUN":
            R += 1
            S += R
            R = 0



if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
for i in range(N):
    out = 0
    hit = 0
    point = 0
    
    while out < 3 :
         a = input()
         if a == "HIT":
              if hit < 3:
                   hit = hit + 1
              else:
                  point = point + 1
         elif a == "HOMERUN":
            point += hit + 1
            hit = 0
         elif a == "OUT":
            out += 1
    print(point)

Submission status: Accepted

Solution code:
# -*- 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)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
score = [0] * n
for i in range(n):
    out_count = 0
    runner = 0
    while True:
        data = input()
        if data == "OUT":
            out_count += 1
            if out_count == 3:
                break
        elif data == "HIT":
            runner += 1
            if runner == 4:
                runner = 3
                score[i] += 1
        else:
            score[i] += runner + 1
            runner = 0
print(*score, sep="\n")

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# -*- 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:])

Submission status: Accepted

Solution code:
# Aizu Problem 0103: Baseball Simulation
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N = int(input())
for n in range(N):
    bases = [0, 0, 0]
    outs = 0
    score = 0
    while outs < 3:
        event = input().strip()
        if event == "OUT":
            outs += 1
        elif event == "HOMERUN":
            score += 1 + sum(bases)
            bases = [0, 0, 0]
        elif event == "HIT":
            score += bases[2]
            bases[1:] = bases[:2]
            bases[0] = 1
    print(score)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
	o_count = 0
	h_count = 0
	score = 0
	while True:
		site = input()
		if site == 'OUT':
			o_count += 1
			if o_count == 3:
				print(score)
				break
		elif site == 'HIT':
			if h_count == 3:
				score += 1
			else:
				h_count += 1
		else:
			score += h_count+1
			h_count = 0