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: Wrong Answer

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 = 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: Wrong Answer

Solution code:
while True:
    n=input()
    if n==0:break
    S=range(1,7)
    s=1
    for i in range(n):
        c=raw_input()
        if c=="North":
            S=[S[1],S[5],S[2],S[3],S[0],S[4]]
        elif c=="South":
            S=[S[4],S[0],S[2],S[3],S[5],S[1]]
        elif c=="East":
            S=[S[3],S[1],S[0],S[5],S[4],S[2]]
        elif c=="West":
            S=[S[2],S[1],S[5],S[0],S[4],S[3]]
        elif c=="Right":
            S=[S[0],S[2],S[4],S[1],S[3],S[5]]
        elif c=="Left":
            S=[S[0],S[3],S[1],S[4],S[2],S[5]]
        s+=S[0]
    print s

Submission status: Wrong Answer

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: Wrong Answer

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 1:
    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: Wrong Answer

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 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: Wrong Answer

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 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: Wrong Answer

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 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)
        sum += dice[0]
    print(sum)

Submission status: Wrong Answer

Solution code:
ans = []
while True:
    place = range(1,7)
    n = input()
    if n == 0:
        break
    p = 0
    sig = 1
    while p != n:
        direct = raw_input()
        if direct == "North":
            temp = place[1]
            place[1] = place[5]
            place[5] = place[4]
            place[4] = place[0]
            place[0] = temp
            sig += temp
        elif direct == "East":
            temp = place[3]
            place[3] = place[5]
            place[5] = place[2]
            place[2] = place[0]
            place[0] = temp
            sig += temp
        elif direct == "West":
            temp = place[2]
            place[2] = place[5]
            place[5] = place[3]
            place[3] = place[0]
            place[0] = temp
            sig += temp
        elif direct == "South":
            temp = place[4]
            place[4] = place[5]
            place[5] = place[1]
            place[1] = place[0]
            place[0] = temp
            sig += temp
        elif direct == "Right":
            temp = place[1]
            place[1] = place[2]
            place[2] = place[4]
            place[4] = place[3]
            place[3] = temp
            sig += place[0]
        elif direct == "Left":
            temp = place[1]
            place[1] = place[3]
            place[3] = place[4]
            place[4] = place[2]
            place[2] = temp
            sig += place[0]
        p += 1
    ans.append(sig)
 
for i in ans:
    print i

Submission status: Wrong Answer

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: Wrong Answer

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)
print("")

Submission status: Wrong Answer

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: Wrong Answer

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]
	dice = 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]
	dice = 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
	dice = 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
	dice = 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
	dice = 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
	dice = 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":
			North(dice)
		elif instruct == "East":
			East(dice)
		elif instruct == "South":
			South(dice)
		elif instruct == "West":
			West(dice)
		elif instruct == "Right":
			Right(dice)
		elif instruct == "Left":
			Left(dice)
		#print("** {:} **".format(dice[0]))
		sum += dice[0]
	print(sum)

Submission status: Wrong Answer

Solution code:
def main():
  while True:
    n = int(input())
    if not n:
      break
  
    D = [1, 2, 3, 4, 5, 6]
    ans = 1
  
    for i in range(n):
      s = input()[0]
  
      if s == "N":
        temp = D[0]
        D[0] = D[1]
        D[1] = D[5]
        D[4] = temp
        D[5] = D[4]
  
      elif s == "S":
        temp = D[0]
        D[0] = D[4]
        D[4] = D[5]
        D[5] = D[1]
        D[1] = temp
  
      elif s == "E":
        temp = D[0]
        D[0] = D[3]
        D[3] = D[5]
        D[5] = D[2]
        D[2] = temp
  
      elif s == "W":
        temp = D[0]
        D[0] = D[2]
        D[2] = D[5]
        D[5] = D[3]
        D[3] = temp
  
      elif s == "L":
        temp = D[1]
        D[1] = D[3]
        D[3] = D[4]
        D[4] = D[2]
        D[2] = temp
  
      elif s == "R":
        temp = D[1]
        D[1] = D[2]
        D[2] = D[4]
        D[4] = D[3]
        D[3] = temp
  
      ans += D[0]
  
    print(ans)

main()

Submission status: Wrong Answer

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

import sys
while True:
	n = int(input())
	if n == 0: break
	dice = [[j for j in range(7)] for i in range(2)]
	ans = 1
	for i in range(n):
		x = input()
		if x not in d: sys.exit()
		j = d[x]
		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: Wrong Answer

Solution code:
cmdic = {'North':0,'East':1,'West':3,'South':2,'Right':4,'Left':5}
roll = int(raw_input())
valis = []
while roll > 0:
    val = 1
    num = 1
    adj = [None,[2,4,5,3],[6,4,1,3],[2,1,5,6],[2,6,5,1],[1,4,6,3],[5,4,2,3]]
    for i in range(roll):
        cmd = cmdic[raw_input()]
        if cmd < 4:
            r1 = adj[num][(cmd+3)%4]
            r2 = adj[num][(cmd+1)%4]
            r3 = adj[num][(cmd+2)%4]
            if cmd == 1 or cmd == 3:
                adj[7-num] = adj[7-num][2:]+adj[7-num][:-2] 
                adj[r3] = adj[r3][2:]+adj[r3][:-2]
            num = adj[num][cmd]
            adj[r1] = adj[r1][-1:]+adj[r1][:-1]
            adj[r2] = adj[r2][1:]+adj[r2][:1]
        else:
            if cmd == 4:
                adj[num] = adj[num][-1:]+adj[num][:-1]
                for n in adj[num]:
                    adj[n] = adj[n][-1:]+adj[n][:-1]
                adj[7-num] = adj[7-num][1:]+adj[7-num][:1]
            if cmd == 5:
                adj[num] = adj[num][1:]+adj[num][:1]
                for n in adj[num]:
                    adj[n] = adj[n][1:]+adj[n][:1]
                adj[7-num] = adj[7-num][-1:]+adj[7-num][:-1]
        val += num
        print num
        print adj
    valis.append(val)
    roll = int(raw_input())
for v in valis: print v

Submission status: Wrong Answer

Solution code:
while 1:
	n = input()
	if n == 0: break
	D = range(1,7)
	ans = 1
	for i in range(n):
		c = raw_input()[0]
		if c == "N":
			D = [D[1],D[5],D[2],D[3],D[0],D[4]]
		elif c == "S":
			D = [D[4],D[0],D[2],D[3],D[5],D[1]]
		elif c == "E":
			D = [D[3],D[1],D[0],D[5],D[4],D[2]]
		elif c == "W":
			D = [D[2],D[1],D[5],D[0],D[4],D[3]]
		elif c == "R":
			D = [D[0],D[2],D[4],D[1],D[3],D[5]]
		elif c == "L":
			D = [D[0],D[3],D[1],D[4],D[2],D[5]]
			ans += D[0]
	print ans

Submission status: Accepted

Solution code:
n = int(input())
while (n!=0):
    wlist = []
    for i in range(n):
        wlist.append(str(input()))
    ufr = {"u":1 ,"f":2, "r":3}
    up = 1
    for w in wlist:
        tmp = 0
        if (w == "North"):
            tmp = ufr["u"]
            ufr["u"] = ufr["f"]
            ufr["f"] = 7-tmp
        elif (w == "East"):
            tmp = ufr["r"]
            ufr["r"] = ufr["u"]
            ufr["u"] = 7-tmp
        elif (w == "West"):
            tmp = ufr["u"]
            ufr["u"] = ufr["r"]
            ufr["r"] = 7-tmp
        elif (w=="South"):
            tmp = ufr["f"]
            ufr["f"] = ufr["u"]
            ufr["u"] = 7-tmp
        elif (w=="Right"):
            tmp = ufr["f"]
            ufr["f"] = ufr["r"]
            ufr["r"] = 7-tmp
        else:
            tmp = ufr["r"]
            ufr["r"] = ufr["f"]
            ufr["f"] = 7-tmp
        up += ufr["u"]  
    print(up)   
    n=int(input())

Submission status: Accepted

Solution code:
dic = {'North' : 0, 'East' : 1, 'South' : -2, 'West' : -1}

vv = []
while True:
    n = int( raw_input() )
    if n == 0: break
    cur = 1
    adj = [2, 4, 5, 3]
    ans = 1
    for i in range(n):
        cmd = raw_input()
        if cmd in ['North', 'East', 'South', 'West']:
            cur, adj[ dic[cmd] ], adj[ dic[cmd] + 2 ] = adj[ dic[cmd] ] , 7-cur, cur
        elif cmd == 'Left':
            adj = adj[1:] + adj[:1]
        elif cmd == 'Right':
            adj = adj[-1:] + adj[:-1]
        ans += cur
    vv.append(ans)
for v in vv:
    print v

Submission status: Accepted

Solution code:
import sys

input=sys.stdin.read().split()
a=1
b=2
c=3
d=5
e=4
f=6
x=1





for command in input[1:]:


  if command=='North':
    a,b,d,f,c,e=b,f,a,d,c,e
    x=x+a
  elif command=='South':
    a,d,f,b,c,e=d,f,b,a,c,e
    x=x+a
  elif command=='West':
    a,e,c,f,d,b=c,a,f,e,d,b
    x=x+a
  elif command=='East':
    a,e,c,f,b,d=e,f,a,c,b,d
    x=x+a
  elif command=='Right':
    c,d,e,b,a,f=d,e,b,c,a,f
    x=x+a
  elif command=='Left':
    c,b,e,d,a,f=b,e,d,c,a,f
    x=x+a
  else:
      print x
      a=1
      b=2
      c=3
      d=5
      e=4
      f=6
      x=1

Submission status: Accepted

Solution code:
a,b,c,d,e,f = 1,2,3,4,5,6

def North():
    global a,b,c,d,e,f
    a,b,c,d,e,f =b,f,c,d,a,e
def South():
    global a,b,c,d,e,f
    a,b,c,d,e,f =e,a,c,d,f,b
def East():
    global a,b,c,d,e,f
    a,b,c,d,e,f =d,b,a,f,e,c
def West():
    global a,b,c,d,e,f
    a,b,c,d,e,f =c,b,f,a,e,d
def Right():
    global a,b,c,d,e,f
    a,b,c,d,e,f =a,c,e,b,d,f
def Left():
    global a,b,c,d,e,f
    a,b,c,d,e,f =a,d,b,e,c,f


x = int(raw_input())
while x > 0:
    y = range(x)
    z =1
    a,b,c,d,e,f =1,2,3,4,5,6
    for i in y :
        In = raw_input()
        if In == "North":
            North()
            z +=a
        elif In == "South":
            South()
            z +=a
        elif In == "East":
            East()
            z +=a
        elif In == "West":
            West()
            z +=a
        elif In == "Right":
            Right()
            z +=a
        elif In == "Left":
            Left()
            z +=a
    print z
    x = int(raw_input())

Submission status: Accepted

Solution code:
def input_n(infile,outfile):
	while True:
		n = int(infile.readline())
		if n == 0:
			break
		dice(infile,outfile,n)

def dice(infile,outfile,n):
	point = 1
	top = 1
	east = 3
	south = 2
	for i in range(n):
		buff = top
		command = infile.readline().split()[0]
		if command == "North":
			point += south
			top = south
			south = (7 - buff)
		elif command == "South":
			point += (7 - south)
			top = (7 - south)
			south = buff
		elif command == "East":
			point += (7 - east)
			top = (7 - east)
			east = buff
		elif command == "West":
			point += east
			top = east
			east = (7 - buff)
		elif command == "Right":
			point += top
			remember = south
			south = east
			east = (7 - remember)
		elif command == "Left":
			point += top
			remember = east
			east = south
			south = (7 - remember)
		else:
			break
	print >> outfile,point

if __name__ == "__main__":
	import sys
	input_n(sys.stdin, sys.stdout)

Submission status: Accepted

Solution code:
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect

while(True):
    dice = [1, 2, 3, 4, 5, 6]
    score = 1
    n = int(input())
    if n == 0:
        break

    for i in range(n):
        action = input().rstrip()
        if action == "North":
            tmp = dice[0]
            dice[0] = dice[1]
            dice[1] = dice[5]
            dice[5] = dice[4]
            dice[4] = tmp
        elif action == "East":
            tmp = dice[0]
            dice[0] = dice[3]
            dice[3] = dice[5]
            dice[5] = dice[2]
            dice[2] = tmp
        elif action == "West":
            tmp = dice[0]
            dice[0] = dice[2]
            dice[2] = dice[5]
            dice[5] = dice[3]
            dice[3] = tmp
        elif action == "South":
            tmp = dice[0]
            dice[0] = dice[4]
            dice[4] = dice[5]
            dice[5] = dice[1]
            dice[1] = tmp
        elif action == "Right":
            tmp = dice[1]
            dice[1] = dice[2]
            dice[2] = dice[4]
            dice[4] = dice[3]
            dice[3] = tmp
        elif action == "Left":
            tmp = dice[1]
            dice[1] = dice[3]
            dice[3] = dice[4]
            dice[4] = dice[2]
            dice[2] = tmp
        score += dice[0]
    print(score)