Problem:


サイコロが以下の図のような向きで置かれている．

ここで使用するサイコロは，この図のように，上側に 1，南側に 2 があるときは，東側に 3 があるものとする．サイコロの向かいあう面の和は必ず 7 なので，見えない面はそれぞれ北側 5，西側 4，下側 6 になっている．

　この初期配置の状態から指示に従ってサイコロを動かしていく．ただし，指示は以下の 6 通りの操作を何回か行うものである． 

North，East，South，West の各操作は指示された方向へサイコロを 90 度回転させる．
　Right，Left の 2 つの操作は上下の面はそのままで水平方向に 90 度回転させる．（回転させる向きに要注意．）

　初期配置で上の面に出ている目 1 を初期値とし， 1 回の操作が終わるたびに，上の面に出ている目の数を加算していき，指示にしたがってすべての操作を終えたときの合計値を出力するプログラムを作成しなさい.

　入力ファイルの 1 行目には総指示回数 n が書かれていて，続く n 行の各行には「North，East，South，West，Right，Left」のいずれか 1 つの指示が書かれているものとする．ただし， n ≦ 10000 とする． 

 

  入力例１入力例２

 

58

NorthWest

NorthNorth

EastLeft

SouthSouth

WestRight

North

Left

East

  　

  出力例１  出力例２

2134

入力

入力は複数のデータセットからなる．n が 0 のとき入力が終了する．データセットの数は 5 を超えない．

出力

データセットごとに、合計値を１行に出力する．

入力例

5
North
North
East
South
West
8
West
North
Left
South
Right
North
Left
East
0

出力例

21
34

各データセットの出力（合計値）の後に改行を入れること。

上記問題文と自動審判に使われるデータは、情報オリンピック日本委員会が作成し公開している問題文と採点用テストデータです。



Sample input:
5
North
North
East
South
West
8
West
North
Left
South
Right
North
Left
East
0


Sample output:
21
34

Submission status: Runtime Error

Solution code:
class Dice:
    def __init__(self):
        self.omote=1
        self.sita=2
        self.migi=3
        self.ue=4
        self.hidari=5
        self.ura=6

    def North(self):
        self.omote,self.ue,self.ura,self.sita=self.sita,self.omote,self.ue,self.ura

    def East(self):
        self.omote,self.hidari,self.ura,self.migi=self.hidari,self.ura,self.migi,self.omote

    def West(self):
        self.omote,self.migi,self.ura,self.hidari=self.migi,self.ura,self.hidari,self.omote

    def South(self):
        self.omote,self.ue,self.ura,self.sita=self.ue,self.ura,self.sita,self.omote

    def Right(self):
        self.sita,self.migi,self.ue,self.hidari=self.migi,self.ue,self.hidari,self.sita

    def Left(self):
        self.sita,self.hidari,self.ue,self.migi=self.hidari,self.ue,self.migi,self.sita


while(True):
    n=int(input())
    if n==0:
        break
    sum=0
    dice=Dice()
    dice_def={"North":dice.North,"East":dice.East,"South":dice.South,"West":dice.West,"Right":dice.Right,"Left":dice.Left}
    for i in range(n):
        dice_def[input()]()
        sum+=dice.omote
    print(sum)

Submission status: Runtime Error

Solution code:
class Dice:
    def __init__(self):
        self.omote=1
        self.sita=2
        self.migi=3
        self.ue=5
        self.hidari=4
        self.ura=6

    def North(self):
        self.omote,self.ue,self.ura,self.sita=self.sita,self.omote,self.ue,self.ura

    def East(self):
        self.omote,self.hidari,self.ura,self.migi=self.hidari,self.ura,self.migi,self.omote

    def West(self):
        self.omote,self.migi,self.ura,self.hidari=self.migi,self.ura,self.hidari,self.omote

    def South(self):
        self.omote,self.ue,self.ura,self.sita=self.ue,self.ura,self.sita,self.omote

    def Right(self):
        self.sita,self.migi,self.ue,self.hidari=self.migi,self.ue,self.hidari,self.sita

    def Left(self):
        self.sita,self.hidari,self.ue,self.migi=self.hidari,self.ue,self.migi,self.sita


while(True):
    n=int(input())
    if n==0:
        break
    sum=1
    dice=Dice()
    dice_def={"North":dice.North,"East":dice.East,"South":dice.South,"West":dice.West,"Right":dice.Right,"Left":dice.Left}
    for i in range(n):
        dice_def[input()]()
        sum+=dice.omote
    print(sum)

Submission status: Runtime Error

Solution code:
import sys
class Dice:
    def __init__(self):
        self.omote=1
        self.sita=2
        self.migi=3
        self.ue=5
        self.hidari=4
        self.ura=6

    def North(self):
        self.omote,self.ue,self.ura,self.sita=self.sita,self.omote,self.ue,self.ura

    def East(self):
        self.omote,self.hidari,self.ura,self.migi=self.hidari,self.ura,self.migi,self.omote

    def West(self):
        self.omote,self.migi,self.ura,self.hidari=self.migi,self.ura,self.hidari,self.omote

    def South(self):
        self.omote,self.ue,self.ura,self.sita=self.ue,self.ura,self.sita,self.omote

    def Right(self):
        self.sita,self.migi,self.ue,self.hidari=self.migi,self.ue,self.hidari,self.sita

    def Left(self):
        self.sita,self.hidari,self.ue,self.migi=self.hidari,self.ue,self.migi,self.sita


while(True):
    n=int(input())
    if n==0:
        sys.exit()
    sum=1
    dice=Dice()
    dice_def={"North":dice.North,"East":dice.East,"South":dice.South,"West":dice.West,"Right":dice.Right,"Left":dice.Left}
    for i in range(n):
        dice_def[input()]()
        sum+=dice.omote
    print(sum)

Submission status: Runtime Error

Solution code:
class Dice:
    def __init__(self):
        self.omote=1
        self.sita=2
        self.migi=3
        self.ue=5
        self.hidari=4
        self.ura=6

    def North(self):
        self.omote,self.ue,self.ura,self.sita=self.sita,self.omote,self.ue,self.ura

    def East(self):
        self.omote,self.hidari,self.ura,self.migi=self.hidari,self.ura,self.migi,self.omote

    def West(self):
        self.omote,self.migi,self.ura,self.hidari=self.migi,self.ura,self.hidari,self.omote

    def South(self):
        self.omote,self.ue,self.ura,self.sita=self.ue,self.ura,self.sita,self.omote

    def Right(self):
        self.sita,self.migi,self.ue,self.hidari=self.migi,self.ue,self.hidari,self.sita

    def Left(self):
        self.sita,self.hidari,self.ue,self.migi=self.hidari,self.ue,self.migi,self.sita

n=int(input())
while(n!=0):
    sum=1
    dice=Dice()
    dice_def={"North":dice.North,"East":dice.East,"South":dice.South,"West":dice.West,"Right":dice.Right,"Left":dice.Left}
    for i in range(n):
        dice_def[input()]()
        sum+=dice.omote
    print(sum)
    n=int(input())

Submission status: Runtime Error

Solution code:
import sys
top = 1
north = 5
south = 2
west = 4
east = 3
back = 6
score = 1

def to_right():
    global top, north, south, west, east, back
    tmp = north
    north = west
    west = south
    south = east
    east = tmp
    return top

def to_left():
    global top, north, south, west, east, back
    tmp = north
    north = east
    east = south
    south = west
    west = tmp
    return top

def to_north():
    global top, north, south, west, east, back
    tmp = top
    top = south
    south = back
    back = north

def to_south():
    global top, north, south, west, east, back
    tmp = top
    top = north
    north = back
    back = south
    south = tmp
    return top

def to_west():
    global top, north, south, west, east, back
    tmp = top
    top = east
    east = back
    back = west
    west = tmp
    return top

def to_east():
    global top, north, south, west, east, back
    tmp = top
    top = west
    west = back
    back = east
    east = tmp
    return top

scores = []
while True:
    n = int(raw_input().strip())
    if n == 0:
        break
    top = 1
    north = 5
    south = 2
    west = 4
    east = 3
    back = 6
    for _ in range(0, n):
        flag = raw_input().strip()
        if flag == "North":
            score += to_north()
            # print top, north, south, west, east, back
        elif flag == "South":
            score += to_south()
        elif flag == "West":
            score += to_west()
        elif flag == "East":
            score += to_east()
        elif flag == "Left":
            score += to_left()
        elif flag == "Right":
            score += to_right()
    scores.append(score)

for i in scores:
    print i

Submission status: Runtime Error

Solution code:
def North(dice):
	new_dice = [0,0,0,0,0,0]
	new_dice[0] = dice[3]
	new_dice[1] = dice[0]
	new_dice[2] = dice[2]
	new_dice[3] = dice[5]
	new_dice[4] = dice[4]
	new_dice[5] = dice[1]
	return new_dice

def East(dice):
	new_dice = [0,0,0,0,0,0]
	new_dice[0] = dice[4]
	new_dice[1] = dice[1]
	new_dice[2] = dice[0]
	new_dice[3] = dice[3]
	new_dice[4] = dice[5]
	new_dice[5] = dice[2]
	return new_dice

def West(dice):
	new_dice = [0,0,0,0,0,0]
	new_dice[0] = dice[2] #3
	new_dice[1] = dice[1] #5
	new_dice[2] = dice[5] #6
	new_dice[3] = dice[3] #2
	new_dice[4] = dice[0] #1
	new_dice[5] = dice[4] #4
	return new_dice

def South(dice):
	new_dice = [0,0,0,0,0,0]
	new_dice[0] = dice[1] #5
	new_dice[1] = dice[5] #6
	new_dice[2] = dice[2] #3
	new_dice[3] = dice[0] #1
	new_dice[4] = dice[4] #4
	new_dice[5] = dice[3] #2
	return new_dice

def Right(dice):
	new_dice = [0,0,0,0,0,0]
	new_dice[0] = dice[0] #1
	new_dice[1] = dice[4] #4
	new_dice[2] = dice[1] #5
	new_dice[3] = dice[2] #3
	new_dice[4] = dice[3] #2
	new_dice[5] = dice[5] #6
	return new_dice

def Left(dice):
	new_dice = [0,0,0,0,0,0]
	new_dice[0] = dice[0] #1
	new_dice[1] = dice[2] #3
	new_dice[2] = dice[3] #2
	new_dice[3] = dice[4] #4
	new_dice[4] = dice[1] #5
	new_dice[5] = dice[5] #6
	return new_dice

while True:
	n = int(raw_input())
	if n == 0:
		print()
		break
	dice = [1,5,3,2,4,6] # ??? ??? ??± ??? ?\? ??? ??????
	sum = 1
	for i in range(n):
		instruct = raw_input()
		if instruct == "North":
			dice = North(dice)
		elif instruct == "East":
			dice = East(dice)
		elif instruct == "South":
			dice = South(dice)
		elif instruct == "West":
			dice = West(dice)
		elif instruct == "Right":
			dice = Right(dice)
		elif instruct == "Left":
			dice = Left(dice)
		#print("** {:} **".format(dice[0]))
		sum += dice[0]
	print(sum)

Submission status: Runtime Error

Solution code:
# coding: utf-8

def North(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[3]
    new_dice[1] = dice[0]
    new_dice[2] = dice[2]
    new_dice[3] = dice[5]
    new_dice[4] = dice[4]
    new_dice[5] = dice[1]
    return new_dice

def East(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[4]
    new_dice[1] = dice[1]
    new_dice[2] = dice[0]
    new_dice[3] = dice[3]
    new_dice[4] = dice[5]
    new_dice[5] = dice[2]
    return new_dice

def West(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[2] #3
    new_dice[1] = dice[1] #5
    new_dice[2] = dice[5] #6
    new_dice[3] = dice[3] #2
    new_dice[4] = dice[0] #1
    new_dice[5] = dice[4] #4
    return new_dice

def South(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[1] #5
    new_dice[1] = dice[5] #6
    new_dice[2] = dice[2] #3
    new_dice[3] = dice[0] #1
    new_dice[4] = dice[4] #4
    new_dice[5] = dice[3] #2
    return new_dice

def Right(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[0] #1
    new_dice[1] = dice[4] #4
    new_dice[2] = dice[1] #5
    new_dice[3] = dice[2] #3
    new_dice[4] = dice[3] #2
    new_dice[5] = dice[5] #6
    return new_dice

def Left(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[0] #1
    new_dice[1] = dice[2] #3
    new_dice[2] = dice[3] #2
    new_dice[3] = dice[4] #4
    new_dice[4] = dice[1] #5
    new_dice[5] = dice[5] #6
    return new_dice

while True:
    n = int(raw_input())
    if n == 0:
        break
        dice = [1,5,3,2,4,6] # ??? ??? ??± ??? ?\? ??? ??????
        sum = 1
        for i in range(n):
            instruct = raw_input()
            if instruct == "North":
                dice = North(dice)
                elif instruct == "East":
                    dice = East(dice)
                elif instruct == "South":
                    dice = South(dice)
                elif instruct == "West":
                    dice = West(dice)
                elif instruct == "Right":
                    dice = Right(dice)
                elif instruct == "Left":
                    dice = Left(dice)
                #print("** {:} **".format(dice[0]))
                        sum += dice[0]
        print(sum)

Submission status: Runtime Error

Solution code:
# coding: utf-8

def North(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[3]
    new_dice[1] = dice[0]
    new_dice[2] = dice[2]
    new_dice[3] = dice[5]
    new_dice[4] = dice[4]
    new_dice[5] = dice[1]
    return new_dice

def East(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[4]
    new_dice[1] = dice[1]
    new_dice[2] = dice[0]
    new_dice[3] = dice[3]
    new_dice[4] = dice[5]
    new_dice[5] = dice[2]
    return new_dice

def West(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[2] #3
    new_dice[1] = dice[1] #5
    new_dice[2] = dice[5] #6
    new_dice[3] = dice[3] #2
    new_dice[4] = dice[0] #1
    new_dice[5] = dice[4] #4
    return new_dice

def South(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[1] #5
    new_dice[1] = dice[5] #6
    new_dice[2] = dice[2] #3
    new_dice[3] = dice[0] #1
    new_dice[4] = dice[4] #4
    new_dice[5] = dice[3] #2
    return new_dice

def Right(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[0] #1
    new_dice[1] = dice[4] #4
    new_dice[2] = dice[1] #5
    new_dice[3] = dice[2] #3
    new_dice[4] = dice[3] #2
    new_dice[5] = dice[5] #6
    return new_dice

def Left(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[0] #1
    new_dice[1] = dice[2] #3
    new_dice[2] = dice[3] #2
    new_dice[3] = dice[4] #4
    new_dice[4] = dice[1] #5
    new_dice[5] = dice[5] #6
    return new_dice

while True:
    n = int(raw_input())
    if n == 0:
        break
        dice = [1,5,3,2,4,6] # ??? ??? ??± ??? ?\? ??? ??????
        sum = 1
        for i in range(n):
            instruct = raw_input()
            if instruct == "North":
                dice = North(dice)
            elif instruct == "East":
                dice = East(dice)
            elif instruct == "South":
                dice = South(dice)
            elif instruct == "West":
                dice = West(dice)
            elif instruct == "Right":
                dice = Right(dice)
            elif instruct == "Left":
                dice = Left(dice)
            #print("** {:} **".format(dice[0]))
            sum += dice[0]
        print(sum)

Submission status: Runtime Error

Solution code:
import sys

# coding: utf-8

def North(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[3]
    new_dice[1] = dice[0]
    new_dice[2] = dice[2]
    new_dice[3] = dice[5]
    new_dice[4] = dice[4]
    new_dice[5] = dice[1]
    return new_dice

def East(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[4]
    new_dice[1] = dice[1]
    new_dice[2] = dice[0]
    new_dice[3] = dice[3]
    new_dice[4] = dice[5]
    new_dice[5] = dice[2]
    return new_dice

def West(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[2] #3
    new_dice[1] = dice[1] #5
    new_dice[2] = dice[5] #6
    new_dice[3] = dice[3] #2
    new_dice[4] = dice[0] #1
    new_dice[5] = dice[4] #4
    return new_dice

def South(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[1] #5
    new_dice[1] = dice[5] #6
    new_dice[2] = dice[2] #3
    new_dice[3] = dice[0] #1
    new_dice[4] = dice[4] #4
    new_dice[5] = dice[3] #2
    return new_dice

def Right(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[0] #1
    new_dice[1] = dice[4] #4
    new_dice[2] = dice[1] #5
    new_dice[3] = dice[2] #3
    new_dice[4] = dice[3] #2
    new_dice[5] = dice[5] #6
    return new_dice

def Left(dice):
    new_dice = [0,0,0,0,0,0]
    new_dice[0] = dice[0] #1
    new_dice[1] = dice[2] #3
    new_dice[2] = dice[3] #2
    new_dice[3] = dice[4] #4
    new_dice[4] = dice[1] #5
    new_dice[5] = dice[5] #6
    return new_dice

while 1:
    n = input()
    if n == 0:
        break
    dice = [1,5,3,2,4,6] # ??? ??? ??± ??? ?\? ??? ??????
    sum = 1
    for i in range(n):
        instruct = raw_input()
        if instruct == "North":
            dice = North(dice)
        elif instruct == "East":
            dice = East(dice)
        elif instruct == "South":
            dice = South(dice)
        elif instruct == "West":
            dice = West(dice)
        elif instruct == "Right":
            dice = Right(dice)
        elif instruct == "Left":
            dice = Left(dice)
        #print("** {:} **".format(dice[0]))
        sum += dice[0]
    print(sum)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python

while 1:
    T,U,N,E,W,S=1,6,5,3,4,2
    n=int(raw_input())
    if n==0: break
    ans=T
    for i in range(n):
        di=raw_input()
        if di=="North":
            N,T,S,U=T,S,U,N
        elif di=="East":
            E,U,W,T=T,E,U,W
        elif di=="South":
            T,S,U,N=N,T,S,U
        elif di=="West":
            T,E,U,W=E,U,W,T
        elif di=="Left":
            E,S,W,N=S,W,N,E
        elif di=="Right":
            S,W,N,E=E,S,W,N
        else:
            print '[*] Error ->',di
            raise IOError
        ans+=T
    print ans

Submission status: Runtime Error

Solution code:
def North(dice):
	new_dice = [0,0,0,0,0,0]
	new_dice[0] = dice[3]
	new_dice[1] = dice[0]
	new_dice[2] = dice[2]
	new_dice[3] = dice[5]
	new_dice[4] = dice[4]
	new_dice[5] = dice[1]
	return new_dice

def East(dice):
	new_dice = [0,0,0,0,0,0]
	new_dice[0] = dice[4]
	new_dice[1] = dice[1]
	new_dice[2] = dice[0]
	new_dice[3] = dice[3]
	new_dice[4] = dice[5]
	new_dice[5] = dice[2]
	return new_dice

def West(dice):
	new_dice = [0,0,0,0,0,0]
	new_dice[0] = dice[2] #3
	new_dice[1] = dice[1] #5
	new_dice[2] = dice[5] #6
	new_dice[3] = dice[3] #2
	new_dice[4] = dice[0] #1
	new_dice[5] = dice[4] #4
	return new_dice

def South(dice):
	new_dice = [0,0,0,0,0,0]
	new_dice[0] = dice[1] #5
	new_dice[1] = dice[5] #6
	new_dice[2] = dice[2] #3
	new_dice[3] = dice[0] #1
	new_dice[4] = dice[4] #4
	new_dice[5] = dice[3] #2
	return new_dice

def Right(dice):
	new_dice = [0,0,0,0,0,0]
	new_dice[0] = dice[0] #1
	new_dice[1] = dice[4] #4
	new_dice[2] = dice[1] #5
	new_dice[3] = dice[2] #3
	new_dice[4] = dice[3] #2
	new_dice[5] = dice[5] #6
	return new_dice

def Left(dice):
	new_dice = [0,0,0,0,0,0]
	new_dice[0] = dice[0] #1
	new_dice[1] = dice[2] #3
	new_dice[2] = dice[3] #2
	new_dice[3] = dice[4] #4
	new_dice[4] = dice[1] #5
	new_dice[5] = dice[5] #6
	return new_dice

while True:
	n = int(raw_input())
	if n == 0:
		break
	dice = [1,5,3,2,4,6] # ??? ??? ??± ??? ?\? ??? ??????
	sum = 1
	for i in range(n):
		instruct = raw_input()
		if instruct == "North":
			dice = North(dice)
		elif instruct == "East":
			dice = East(dice)
		elif instruct == "South":
			dice = South(dice)
		elif instruct == "West":
			dice = West(dice)
		elif instruct == "Right":
			dice = Right(dice)
		elif instruct == "Left":
			dice = Left(dice)
		#print("** {:} **".format(dice[0]))
		sum += dice[0]
	print(sum)

Submission status: Runtime Error

Solution code:
while 1:
????????T,U,N,E,W,S=1,6,5,3,4,2
????????n=int(raw_input())
????????if n==0: break
????????ans=T
????????for i in range(n):
????????????????di=raw_input()
????????????????if di=="North":
????????????????????????N,T,S,U=T,S,U,N
????????????????elif di=="East":
????????????????????????E,U,W,T=T,E,U,W
????????????????elif di=="South":
????????????????????????T,S,U,N=N,T,S,U
????????????????elif di=="West":
????????????????????????T,E,U,W=E,U,W,T
????????????????elif di=="Left":
????????????????????????E,S,W,N=S,W,N,E
????????????????elif di=="Right":
????????????????????????S,W,N,E=E,S,W,N
????????????????else:
????????????????????????print '[*] Error ->',di
????????????????????????raise IOError
????????????????ans+=T
????????print ans

Submission status: Runtime Error

Solution code:
while 1:
????????T,U,N,E,W,S=1,6,5,3,4,2
????????n=int(raw_input())
????????if n==0: break
????????ans=T
????????for i in range(n):
????????????????di=raw_input()
????????????????if di=="North":
????????????????????????N,T,S,U=T,S,U,N
????????????????elif di=="East":
????????????????????????E,U,W,T=T,E,U,W
????????????????elif di=="South":
????????????????????????T,S,U,N=N,T,S,U
????????????????elif di=="West":
????????????????????????T,E,U,W=E,U,W,T
????????????????elif di=="Left":
????????????????????????E,S,W,N=S,W,N,E
????????????????elif di=="Right":
????????????????????????S,W,N,E=E,S,W,N
????????????????ans+=T
????????print ans

Submission status: Runtime Error

Solution code:
while 1:
????????T,U,N,E,W,S=1,6,5,3,4,2
????????n=input()
????????if n==0: break
????????ans=T
????????for i in range(n):
????????????????di=raw_input()
????????????????if di=="North":
????????????????????????N,T,S,U=T,S,U,N
????????????????elif di=="East":
????????????????????????E,U,W,T=T,E,U,W
????????????????elif di=="South":
????????????????????????T,S,U,N=N,T,S,U
????????????????elif di=="West":
????????????????????????T,E,U,W=E,U,W,T
????????????????elif di=="Left":
????????????????????????E,S,W,N=S,W,N,E
????????????????elif di=="Right":
????????????????????????S,W,N,E=E,S,W,N
????????????????ans+=T
????????print ans

Submission status: Runtime Error

Solution code:
while 1:
????????T,U,N,E,W,S=1,6,5,3,4,2
????????n=input()
????????if n==0:
        break
????????ans=T
????????for i in range(n):
????????????????di=raw_input()
????????????????if di=="North":
????????????????????????N,T,S,U=T,S,U,N
????????????????elif di=="East":
????????????????????????E,U,W,T=T,E,U,W
????????????????elif di=="South":
????????????????????????T,S,U,N=N,T,S,U
????????????????elif di=="West":
????????????????????????T,E,U,W=E,U,W,T
????????????????elif di=="Left":
????????????????????????E,S,W,N=S,W,N,E
????????????????elif di=="Right":
????????????????????????S,W,N,E=E,S,W,N
????????????????ans+=T
????????print ans

Submission status: Runtime Error

Solution code:
while 1:
????????T,U,N,E,W,S=1,6,5,3,4,2
????????n=input()
????????if n==0:
        break
????????ans=T
????????for i in range(n):
????????????????di=raw_input()
????????????????if di=="North":
????????????????????????N,T,S,U=T,S,U,N
????????????????elif di=="East":
????????????????????????E,U,W,T=T,E,U,W
????????????????elif di=="South":
????????????????????????T,S,U,N=N,T,S,U
????????????????elif di=="West":
????????????????????????T,E,U,W=E,U,W,T
????????????????elif di=="Left":a
????????????????????????E,S,W,N=S,W,N,E
????????????????elif di=="Right":
????????????????????????S,W,N,E=E,S,W,N
????????????????ans+=T
????????print ans

Submission status: Runtime Error

Solution code:
operation = {"North": (1, 5, 2, 3, 0, 4),
             "East": (3, 1, 0, 5, 4, 2),
             "West": (2, 1, 5, 0, 4, 3),
             "South": (4, 0, 2, 3, 5, 1),
             "Right": (0, 2, 4, 1, 3, 5),
             "Left": (0, 3, 1, 4, 2, 5)}

while True:
    n = int(input())
    if n == 0:
        break
    dice = [i+1 for i in range(6)]
    ans = 1
    for _ in range(n):
        indices = operation[input()]
        dice = [dice[i] for i in indices]
        ans += dice[0]
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
s=sys.stdin
while 1:
 n=int(s.readline())
 if n==0:break
 a=1;s='123456'
 for _ in[0]*n:
  s=[s[int(e)]for e in{'N':"152304",'E':"310542",'W':"215043",'S':"402351",'R':"024135",'L':"031425"}[s.readline()[0]]]
  a+=int(s[0])
 print(a)

Submission status: Runtime Error

Solution code:
# AOJ 0502: Dice
# Python3 2018.6.29 bal4u

dir = { "North":1, "East":2, "West":3, "South":4, "Right":5, "Left":6 }

rot = ((0,1,2,3,4,5,6),(0,2,6,3,4,1,5),(0,4,2,1,6,5,3),(0,3,2,6,1,5,4), \
       (0,5,1,3,4,6,2),(0,1,3,5,2,4,6),(0,1,4,2,5,3,6))

while True:
	n = int(input())
	if n == 0: break
	dice = [[i for i in range(7)] for j in range(2)]
	ans = 1
	for i in range(n):
		j = dir[input()]
		for k in range(1, 7): dice[1-(i&1)][k] = dice[i&1][rot[j][k]];
		ans += dice[1-(i&1)][1]
	print(ans)

Submission status: Runtime Error

Solution code:
# AOJ 0502: Dice
# Python3 2018.6.29 bal4u

d = { "North":1, "East":2, "West":3, "South":4, "Right":5, "Left":6 }

rot = ((0,1,2,3,4,5,6),(0,2,6,3,4,1,5),(0,4,2,1,6,5,3),(0,3,2,6,1,5,4), \
       (0,5,1,3,4,6,2),(0,1,3,5,2,4,6),(0,1,4,2,5,3,6))

while True:
	n = int(input())
	if n == 0: break
	dice = [[i for i in range(7)] for j in range(2)]
	ans = 1
	for i in range(n):
		j = d[input()]
		for k in range(1, 7): dice[1-(i&1)][k] = dice[i&1][rot[j][k]];
		ans += dice[1-(i&1)][1]
	print(ans)