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:
class Dice():
    def __init__(self,top,fw,ras,las,back,btm):
        self.top=top
        self.btm=btm
        self.ras=ras
        self.las=las
        self.fw=fw
        self.back=back

    def query(self,q):
        if q=="North":
            tmp=self.top
            self.top=self.fw
            self.fw=self.btm
            self.btm=self.back
            self.back=tmp
        elif q=="South":
            tmp=self.top
            self.top=self.back
            self.back=self.btm
            self.btm=self.fw
            self.fw=tmp
        elif q=="East":
            tmp=self.top
            self.top=self.las
            self.las=self.btm
            self.btm=self.ras
            self.ras=tmp
        elif q=="West":
            tmp=self.top
            self.top=self.ras
            self.ras=self.btm
            self.btm=self.las
            self.las=tmp
        elif q=="Right":
            tmp=self.fw
            self.fw=self.ras
            self.ras=self.back
            self.back=self.las
            self.las=tmp
        elif q=="Left":
            tmp=self.fw
            self.fw=self.las
            self.las=self.back
            self.back=self.ras
            self.ras=tmp
        return

while True:
    dice=Dice(1,2,3,4,5,6)
    n=int(raw_input())
    if n==0:break
    ans=1
    for i in xrange(n):
        q=raw_input()
        dice.query(q)
        ans+=dice.top
    print(ans)

Submission status: Wrong Answer

Solution code:
class Dice():
    def __init__(self,top,fw,ras,las,back,btm):
        self.top=top
        self.btm=btm
        self.ras=ras
        self.las=las
        self.fw=fw
        self.back=back

    def query(self,q):
        if q=="North":
            tmp=self.top
            self.top=self.fw
            self.fw=self.btm
            self.btm=self.back
            self.back=tmp
        elif q=="South":
            tmp=self.top
            self.top=self.back
            self.back=self.btm
            self.btm=self.fw
            self.fw=tmp
        elif q=="East":
            tmp=self.top
            self.top=self.las
            self.las=self.btm
            self.btm=self.ras
            self.ras=tmp
        elif q=="West":
            tmp=self.top
            self.top=self.ras
            self.ras=self.btm
            self.btm=self.las
            self.las=tmp
        elif q=="Right":
            tmp=self.fw
            self.fw=self.ras
            self.ras=self.back
            self.back=self.las
            self.las=tmp
        elif q=="Left":
            tmp=self.fw
            self.fw=self.las
            self.las=self.back
            self.back=self.ras
            self.ras=tmp
        return

while True:
    dice=Dice(1,2,3,4,5,6)
    n=int(raw_input())
    if n==0:break
    ans=1
    for i in xrange(n):
        q=raw_input()
        dice.query(q)
        ans+=dice.top
    print ans

Submission status: Wrong Answer

Solution code:
dice = {'north': 5, 'south': 2, 'west': 4, 'east': 3, 'top': 1, 'bottom': 6}

class Dice(object):
    """docstring for Dice"""
    def __init__(self):
        self.top = 1
        self.south = 2
        self.east = 3
        self.update()
    def manipulate(self, arg):
        if arg == 'North':
            self.top = self.south
            self.south = self.bottom
            self.east = self.east
            self.update()
        elif arg == 'South':
            self.south = self.top
            self.top = self.north
            self.east = self.east
            self.update()
        elif arg == 'East':
            self.east = self.top
            self.top = self.west
            self.south = self.south
            self.update()
        elif arg == 'West':
            self.top = self.east
            self.east = self.bottom
            self.south = self.south
            self.update()
        elif arg == 'Left':
            self.top = self.top
            self.east = self.south
            self.south = self.west
            self.update()
        elif arg == 'Right':
            self.top = self.top
            self.south = self.east
            self.east = self.north
            self.update()
        else:
            print("not implemented.")

    def update(self):
        self.bottom = 7 - self.top
        self.west = 7 - self.east
        self.north = 7 - self.south

if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            break
        dice = Dice()
        s = dice.top
        for i in range(n):
            man = input()
            dice.manipulate(man)
            s += dice.top
        else:
            print(s)

Submission status: Wrong Answer

Solution code:
class Dice(object):
    """docstring for Dice"""
    def __init__(self):
        self.top = 1
        self.south = 2
        self.east = 3
        self.update()
    def manipulate(self, arg):
        if arg == 'North':
            self.top = self.south
            self.south = self.bottom
            self.east = self.east
            self.update()
        elif arg == 'South':
            self.south = self.top
            self.top = self.north
            self.east = self.east
            self.update()
        elif arg == 'East':
            self.east = self.top
            self.top = self.west
            self.south = self.south
            self.update()
        elif arg == 'West':
            self.top = self.east
            self.east = self.bottom
            self.south = self.south
            self.update()
        elif arg == 'Left':
            self.top = self.top
            self.east = self.south
            self.south = self.west
            self.update()
        elif arg == 'Right':
            self.top = self.top
            self.south = self.east
            self.east = self.north
            self.update()
        else:
            print("not implemented.")

    def update(self):
        self.bottom = 7 - self.top
        self.west = 7 - self.east
        self.north = 7 - self.south

if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            exit(0)
        dice = Dice()
        s = dice.top
        for i in range(n):
            man = input()
            dice.manipulate(man)
            s += dice.top
        else:
            print(s)

Submission status: Wrong Answer

Solution code:
class Dice(object):
    """docstring for Dice"""
    def __init__(self):
        self.top = 1
        self.south = 2
        self.east = 3
        self.update()
    def manipulate(self, arg):
        if arg == 'North':
            self.top = self.south
            self.south = self.bottom
            self.east = self.east
        elif arg == 'South':
            self.south = self.top
            self.top = self.north
            self.east = self.east
        elif arg == 'East':
            self.east = self.top
            self.top = self.west
            self.south = self.south
        elif arg == 'West':
            self.top = self.east
            self.east = self.bottom
            self.south = self.south
        elif arg == 'Left':
            self.top = self.top
            self.east = self.south
            self.south = self.west
        elif arg == 'Right':
            self.top = self.top
            self.south = self.east
            self.east = self.north
        # print("not implemented.")
        self.update()

    def update(self):
        self.bottom = 7 - self.top
        self.west = 7 - self.east
        self.north = 7 - self.south

if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            exit(0)
        dice = Dice()
        s = dice.top
        for i in range(n):
            man = input()
            dice.manipulate(man)
            s += dice.top
        else:
            print(s)

Submission status: Wrong Answer

Solution code:
class Dice(object):
    """docstring for Dice"""
    def __init__(self):
        self.top = 1
        self.south = 2
        self.east = 3
        self.update()
    def manipulate(self, arg):
        if arg == 'North':
            self.top = self.south
            self.south = self.bottom
        elif arg == 'South':
            self.south = self.top
            self.top = self.north
        elif arg == 'East':
            self.east = self.top
            self.top = self.west
        elif arg == 'West':
            self.top = self.east
            self.east = self.bottom
        elif arg == 'Left':
            self.east = self.south
            self.south = self.west
        elif arg == 'Right':
            self.south = self.east
            self.east = self.north
        # print("not implemented.")
        self.update()

    def update(self):
        self.bottom = 7 - self.top
        self.west = 7 - self.east
        self.north = 7 - self.south

if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            exit(0)
        dice = Dice()
        s = dice.top
        for i in range(n):
            man = input()
            dice.manipulate(man)
            s += dice.top
        else:
            print(s)

Submission status: Wrong Answer

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
    return top

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

Solution code:
def North(d):
    d = [d[1]] + [7 -d[0]] + [d[2]]
    return d
       
def East(d):
    d = [7-d[2]] + [d[1]] + [d[0]]
    return d
       
def South(d):
    d = [7-d[1]] + [d[0]] + [d[2]]
    return d
   
def West(d):
    d = [d[2]] + [d[1]] + [7-d[0]]
    return d
   
def Right(d):
    d = [d[0]] + [d[2]] + [7-d[1]]
    return d
   
def Left(d):
    d = [d[0]] + [7-d[2]] + [d[1]]
    return d
    
while True:
    n = int(input())
    if n == 0:
        break
    dice = [1,2,3]
    result = 1
    for _ in range(n):
        direction = input()
        if direction == 'North':
            dice = North(dice)
        if direction == 'East':
            dice = East(dice)
        if direction == 'South':
            dice = South(dice)
        if direction == 'West':
            dice = West(dice)
        if direction == 'Right':
            dice = Right(dice)
        if direction == 'Left':
            dice = Left(dice)
        result += dice[0]
    print(result)

Submission status: Wrong Answer

Solution code:
def North(d):
    d = [d[1]] + [7 -d[0]] + [d[2]]
    return d
       
def East(d):
    d = [7-d[2]] + [d[1]] + [d[0]]
    return d
       
def South(d):
    d = [7-d[1]] + [d[0]] + [d[2]]
    return d
   
def West(d):
    d = [d[2]] + [d[1]] + [7-d[0]]
    return d
   
def Right(d):
    d = [d[0]] + [d[2]] + [7-d[1]]
    return d
   
def Left(d):
    d = [d[0]] + [7-d[2]] + [d[1]]
    return d
    
while True:
    n = int(input())
    if n == 0: break
    dice = [1,2,3]
    result = 1
    for _ in range(n):
        direction = input()
        if direction == 'North':
            dice = North(dice)
        if direction == 'East':
            dice = East(dice)
        if direction == 'South':
            dice = South(dice)
        if direction == 'West':
            dice = West(dice)
        if direction == 'Right':
            dice = Right(dice)
        if direction == 'Left':
            dice = Left(dice)
        result += dice[0]
    print(result)

Submission status: Wrong Answer

Solution code:
def North(d):
    d = [d[1]] + [7 -d[0]] + [d[2]]
    return d
       
def East(d):
    d = [7-d[2]] + [d[1]] + [d[0]]
    return d
       
def South(d):
    d = [7-d[1]] + [d[0]] + [d[2]]
    return d
   
def West(d):
    d = [d[2]] + [d[1]] + [7-d[0]]
    return d
   
def Right(d):
    d = [d[0]] + [d[2]] + [7-d[1]]
    return d
   
def Left(d):
    d = [d[0]] + [7-d[2]] + [d[1]]
    return d
    
while True:
    n = int(input())
    if n == 0: break
    dice = [1,2,3]
    result = 1
    for _ in range(n):
        direction = input()
        if direction == 'North':
            dice = North(dice)
        if direction == 'East':
            dice = East(dice)
        if direction == 'South':
            dice = South(dice)
        if direction == 'West':
            dice = West(dice)
        if direction == 'Right':
            dice = Right(dice)
        if direction == 'Left':
            dice = Left(dice)
        result += dice[0]
    print (result)

Submission status: Wrong Answer

Solution code:
def North(d):
    d = [d[1]] + [7 -d[0]] + [d[2]]
    return d
       
def East(d):
    d = [7-d[2]] + [d[1]] + [d[0]]
    return d
       
def South(d):
    d = [7-d[1]] + [d[0]] + [d[2]]
    return d
   
def West(d):
    d = [d[2]] + [d[1]] + [7-d[0]]
    return d
   
def Right(d):
    d = [d[0]] + [d[2]] + [7-d[1]]
    return d
   
def Left(d):
    d = [d[0]] + [7-d[2]] + [d[1]]
    return d
    
while True:
    n = int(input())
    if n == 0: break
    dice = [1,2,3]
    result = 1
    for _ in range(n):
        direction = input()
        if direction == 'North':
            dice = North(dice)
        if direction == 'East':
            dice = East(dice)
        if direction == 'South':
            dice = South(dice)
        if direction == 'West':
            dice = West(dice)
        if direction == 'Right':
            dice = Right(dice)
        if direction == 'Left':
            dice = Left(dice)
        result += dice[0]
    print (result)
print()

Submission status: Wrong Answer

Solution code:
import sys
def main():
    for line in sys.stdin:
        n = int(line)
        if n == 0:
            break
        else:
            act = []
            for _ in range(n):
                act.append(input())

            total = 1
            dice = [0, 1, 2, 3, 4, 5, 6]
            #Top, South, East, West, North, Bottom

            for x in range(n):
                hoge = act[x]
                if hoge == "North":
                    tmp = dice[6]
                    dice[6] = dice[5]
                    dice[5] = dice[1]
                    dice[1] = dice[2]
                    dice[2] = tmp
                elif hoge == "East":
                    tmp = dice[6]
                    dice[6] = dice[3]
                    dice[3] = dice[1]
                    dice[1] = dice[4]
                    dice[4] = tmp
                elif hoge == "West":
                    tmp = dice[6]
                    dice[6] = dice[4]
                    dice[4] = dice[1]
                    dice[1] = dice[3]
                    dice[3] = tmp
                elif hoge == "South":
                    tmp = dice[6]
                    dice[6] = dice[2]
                    dice[2] = dice[1]
                    dice[1] = dice[5]
                    dice[5] = tmp
                elif hoge == "Right":
                    tmp = dice[5]
                    dice[5] = dice[4]
                    dice[4] = dice[2]
                    dice[2] = dice[3]
                    dice[3] = tmp
                elif hoge == "Left":
                    tmp = dice[5]
                    dice[5] = dice[3]
                    dice[3] = dice[2]
                    dice[2] = dice[4]
                    dice[4] = tmp
                total += dice[1]
            print(total)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
def main():
    while 1:
        n = int(input())
        if n == 0:
            break
        else:
            act = []
            for _ in range(n):
                act.append(input())

            total = 1
            dice = [0, 1, 2, 3, 4, 5, 6]
            #Top, South, East, West, North, Bottom

            for x in range(n):
                hoge = act[x]
                if hoge == "North":
                    tmp = dice[6]
                    dice[6] = dice[5]
                    dice[5] = dice[1]
                    dice[1] = dice[2]
                    dice[2] = tmp
                elif hoge == "East":
                    tmp = dice[6]
                    dice[6] = dice[3]
                    dice[3] = dice[1]
                    dice[1] = dice[4]
                    dice[4] = tmp
                elif hoge == "West":
                    tmp = dice[6]
                    dice[6] = dice[4]
                    dice[4] = dice[1]
                    dice[1] = dice[3]
                    dice[3] = tmp
                elif hoge == "South":
                    tmp = dice[6]
                    dice[6] = dice[2]
                    dice[2] = dice[1]
                    dice[1] = dice[5]
                    dice[5] = tmp
                elif hoge == "Right":
                    tmp = dice[5]
                    dice[5] = dice[4]
                    dice[4] = dice[2]
                    dice[2] = dice[3]
                    dice[3] = tmp
                elif hoge == "Left":
                    tmp = dice[5]
                    dice[5] = dice[3]
                    dice[3] = dice[2]
                    dice[2] = dice[4]
                    dice[4] = tmp
                total += dice[1]
            print(total)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
while True:
    top = 1
    front = 5
    back = 2
    left = 4
    right = 3
    bottom = 6
    total = 1
    n = input()
    if(n == 0):
        break
    for i in xrange(n):
        s = raw_input()
        if(s == "North"):
            top,front,bottom,back = back,top,front,bottom
        elif(s == "East"):
            top,left,bottom,right = left,bottom,right,top
        elif(s == "South"):
            top, front, bottom, back = front,bottom,back,top
        elif(s == "West"):
            top, left, bottom, right = right, top, left, bottom
        elif(s == "Left"):
            front,back,left,right = right,left,front,back
        elif(s == "Right"):
            front, back, left, right = left,right,back,front
        total += top
    print total

Submission status: Wrong Answer

Solution code:
while True:
    top = 1
    front = 5
    back = 2
    left = 4
    right = 3
    bottom = 6
    total = 1
    n = input()
    if(n == 0):
        break
    for i in xrange(n):
        s = raw_input()
        if(s == "North"):
            top,front,bottom,back = back,top,front,bottom
        elif(s == "East"):
            top,left,bottom,right = left,bottom,right,top
        elif(s == "South"):
            top, front, bottom, back = front,bottom,back,top
        elif(s == "West"):
            top, left, bottom, right = right, top, left, bottom
        elif(s == "Left"):
            front,back,left,right = right,left,front,back
        elif(s == "Right"):
            front, back, left, right = left,right,back,front
        total += top
print total

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