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: Accepted

Solution code:
while(1):
    num=int(raw_input())
    if num==0:
        break
    else:
        d=[0,1,2,3,4,5,6]
        sum=1
        for i in range(num):
            dir=num=raw_input()
            if dir=="North":
                d=[0,d[2],d[6],d[3],d[4],d[1],d[5]]
            elif dir=="East":
                d=[0,d[4],d[2],d[1],d[6],d[5],d[3]]
            elif dir=="West":
                d=[0,d[3],d[2],d[6],d[1],d[5],d[4]]
            elif dir=="South":
                d=[0,d[5],d[1],d[3],d[4],d[6],d[2]]
            elif dir=="Right":
                d=[0,d[1],d[3],d[5],d[2],d[4],d[6]]
            else:
                d=[0,d[1],d[4],d[2],d[5],d[3],d[6]]
            sum=sum+d[1]
        print sum

Submission status: Accepted

Solution code:
def North(ls):
    ls[1-1],ls[2-1],ls[5-1],ls[6-1] = ls[2-1],ls[6-1],ls[1-1],ls[5-1]
def East(ls):
    ls[1-1],ls[3-1],ls[4-1],ls[6-1] = ls[4-1],ls[1-1],ls[6-1],ls[3-1]
def West(ls):
    ls[1-1],ls[3-1],ls[4-1],ls[6-1] = ls[3-1],ls[6-1],ls[1-1],ls[4-1]
def South(ls):
    ls[1-1],ls[2-1],ls[5-1],ls[6-1] = ls[5-1],ls[1-1],ls[6-1],ls[2-1]
def Right(ls):
    ls[2-1],ls[3-1],ls[4-1],ls[5-1] = ls[3-1],ls[5-1],ls[2-1],ls[4-1]
def Left(ls):
    ls[2-1],ls[3-1],ls[4-1],ls[5-1] = ls[4-1],ls[2-1],ls[5-1],ls[3-1]

while True:
    try:
        n = int(raw_input())
        if n==0:
            break
        dice = [1,2,3,4,5,6] 
        # top, south, east, west, north, bottom
        direction = ""
        total = 1
        for k in range(n):
            direction = str(raw_input())
            if direction=="North":
                North(dice)
            elif direction=="East":
                East(dice)
            elif direction=="West":
                West(dice)
            elif direction=="South":
                South(dice)
            elif direction=="Right":
                Right(dice)
            elif direction=="Left":
                Left(dice)
            total += dice[0]
        print total
    except EOFError:
        break

Submission status: Accepted

Solution code:
import sys
f = sys.stdin

ope = {'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(f.readline())
    if n == 0:
        break
    xi = [1,2,3,4,5,6]
    ret = 1
    for _ in range(n):
        xi = [xi[i] for i in ope[f.readline().strip()]]
        ret += xi[0]
    
    print(ret)

Submission status: Accepted

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

import copy

x = ['Front', 'Right', 'Back', 'Left']
y = ['Top', 'Front', 'Bottom', 'Back']
z = ['Top', 'Left', 'Bottom', 'Right']


def turn(dice, direction):
    turned_dice = copy.deepcopy(dice)
    # x?????????
    if direction == 'Right':
        for i in range(4):
            turned_dice[x[i]] = dice[x[(i+1)%4]]
    if direction == 'Left':
        for i in range(4):
            turned_dice[x[i]] = dice[x[(i-1)%4]]

    # y?????????
    if direction == 'North':
        for i in range(4):
            turned_dice[y[i]] = dice[y[(i+1)%4]]
    if direction == 'South':
        for i in range(4):
            turned_dice[y[i]] = dice[y[(i-1)%4]]

    # z?????????
    if direction == 'East':
        for i in range(4):
            turned_dice[z[i]] = dice[z[(i+1)%4]]
    if direction == 'West':
        for i in range(4):
            turned_dice[z[i]] = dice[z[(i-1)%4]]

    return turned_dice

if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            break
        dice = {'Top': 1, 'Front': 2, 'Right': 3,
                'Left': 4, 'Back': 5, 'Bottom': 6}

        ret = 1
        for i in range(n):
            dice = turn(dice, input())
            ret += dice['Top']

        print(ret)

Submission status: Accepted

Solution code:
while True:
    d = (1, 3, 6, 4, 5, 2)

    n = int(raw_input())
    if n == 0: break

    ans = d[0]
    for i in xrange(n):
        dire = raw_input()
        if dire == "North":
            d = d[5], d[1], d[4], d[3], d[0], d[2]
        elif dire == "East":
            d = d[3], d[0], d[1], d[2], d[4], d[5]
        elif dire == "West":
            d = d[1], d[2], d[3], d[0], d[4], d[5]
        elif dire == "South":
            d = d[4], d[1], d[5], d[3], d[2], d[0]
        elif dire == "Right":
            d = d[0], d[4], d[2], d[5], d[3], d[1]
        elif dire == "Left":
            d = d[0], d[5], d[2], d[4], d[1], d[3]
        ans += d[0]
    print ans

Submission status: Accepted

Solution code:
# -*- coding:shift-jis -*-

class Dice:

	def __init__(self):
		self.top = 1
		self.south = 2
		self.north = 5
		self.east = 3
		self.west = 4
		self.bottom = 6

	def rotate(self,operation):
		if operation == "North":
			self.top,self.north,self.bottom,self.south = self.south,self.top,self.north,self.bottom
		elif operation == "East":
			self.top,self.east,self.bottom,self.west = self.west,self.top,self.east,self.bottom
		elif operation == "West":
			self.top,self.east,self.bottom,self.west = self.east,self.bottom,self.west,self.top
		elif operation == "South":
			self.top,self.north,self.bottom,self.south = self.north,self.bottom,self.south,self.top
		elif operation == "Right":
			self.north,self.east,self.south,self.west = self.west,self.north,self.east,self.south
		elif operation == "Left":
			self.north,self.east,self.south,self.west = self.east,self.south,self.west,self.north,

n = int(input())

while n!=0:
	inputs = [input() for _ in range(n)]
	value = 1
	d = Dice()
	for i in inputs:
		d.rotate(i)
		value += d.top
	print(value)
	n = int(input())

Submission status: Accepted

Solution code:
rot = {
    "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 1:
    n = input()
    if not n:
        break
    dice = [1,2,3,4,5,6]
    nxt = [0]*6
    ans = 0
    for i in xrange(n):
        r = rot[raw_input()]
        for i in xrange(6):
            nxt[i] = dice[r[i]]
        dice, nxt = nxt, dice
        ans += dice[0]
    print ans+1

Submission status: Accepted

Solution code:
rot = {
    "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 1:
    n = input()
    if not n:
        break
    dice = [1,2,3,4,5,6]
    nxt = [0]*6
    ans = 0
    for i in xrange(n):
        r = rot[raw_input()]
        dice = [dice[r[i]] for i in xrange(6)]
        ans += dice[0]
    print ans+1

Submission status: Accepted

Solution code:
rot = {
    "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 1:
    n = int(raw_input())
    if not n:
        break
    dice = [1,2,3,4,5,6]
    ans = 0
    for i in xrange(n):
        r = rot[raw_input()]
        dice = [dice[r[i]] for i in xrange(6)]
        ans += dice[0]
    print ans+1

Submission status: Accepted

Solution code:
import sys

operator = sys.stdin.read().split()
	
top = 1
bottom = 6
south = 2
north = 5
east = 3
west = 4
sum = 1

for var in operator[1:]:
	if var == "North":
		north,top,south,bottom = top,south,bottom,north
		sum += top
	elif var == "South":
		south,top,north,bottom = top,north,bottom,south
		sum += top
	elif var == "West":
		west,top,east,bottom = top,east,bottom,west
		sum += top
	elif var == "East":
		east,top,west,bottom = top,west,bottom,east
		sum += top
	elif var == "Right":
		south,east,north,west = east,north,west,south
		sum += top
	elif var == "Left":
		south,west,north,east = west,north,east,south
		sum += top
	else:
		print sum
		top = 1
		bottom = 6
		south = 2
		north = 5
		east = 3
		west = 4
		sum = 1

Submission status: Accepted

Solution code:
while True:
  dice = [1,2,3,5,4,6]
  n = int(input())
  if n == 0:
    break
  a = 1
  while n>0:
    s = input()
    if s == 'North':
      dice[0],dice[1],dice[3],dice[5] = dice[1],dice[5],dice[0],dice[3]
    elif s == 'South':
      dice[1],dice[5],dice[0],dice[3] = dice[0],dice[1],dice[3],dice[5]
    elif s == 'East':
      dice[0],dice[2],dice[4],dice[5] = dice[4],dice[0],dice[5],dice[2]
    elif s == 'West':
      dice[4],dice[0],dice[5],dice[2] = dice[0],dice[2],dice[4],dice[5]
    elif s == 'Right':
      dice[1],dice[2],dice[3],dice[4] = dice[2],dice[3],dice[4],dice[1]
    else:
      dice[2],dice[3],dice[4],dice[1] = dice[1],dice[2],dice[3],dice[4]
    a += dice[0]
    n -= 1
  print(a)

Submission status: Accepted

Solution code:
import sys
 
operator = sys.stdin.read().split()
     
top = 1
bottom = 6
south = 2
north = 5
east = 3
west = 4
sum = 1
 
for var in operator[1:]:
    if var == "North":
        north,top,south,bottom = top,south,bottom,north
        sum += top
    elif var == "South":
        south,top,north,bottom = top,north,bottom,south
        sum += top
    elif var == "West":
        west,top,east,bottom = top,east,bottom,west
        sum += top
    elif var == "East":
        east,top,west,bottom = top,west,bottom,east
        sum += top
    elif var == "Right":
        south,east,north,west = east,north,west,south
        sum += top
    elif var == "Left":
        south,west,north,east = west,north,east,south
        sum += top
    else:
        print sum
        top = 1
        bottom = 6
        south = 2
        north = 5
        east = 3
        west = 4
        sum = 1

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
import sys
f = sys.stdin

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(f.readline())
    if n == 0:
        break
      
    dice = [1,2,3]
    result = 1
      
    for _ in range(n):
        direction = f.readline().rstrip()
        #print(direction)
        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)
        #dice = eval(direction+"(dice)")
        #print(dice)
          
        result += dice[0]
      
    print(result)

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
import sys
f = sys.stdin

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(f.readline())
    if n == 0:
        break
      
    dice = [1,2,3]
    result = 1
      
    for _ in range(n):
        direction = f.readline().rstrip()
   
        dice = eval(direction+"(dice)")
     
          
        result += dice[0]
      
    print(result)

Submission status: Accepted

Solution code:
orders = {
    'North': (2, 6, 3, 4, 1, 5),
    'East': (4, 2, 1, 6, 5, 3),
    'West': (3, 2, 6, 1, 5, 4),
    'South': (5, 1, 3, 4, 6, 2),
    'Right': (1, 3, 5, 2, 4, 6),
    'Left': (1, 4, 2, 5, 3, 6)
}

while True:
    n = int(input())
    if not n:
        break
    dice = list(range(1, 7))
    top = 1

    while n:
        dice = [dice[s - 1] for s in orders[input().strip()]]
        top += dice[0]
        n -= 1
    print(top)

Submission status: Accepted

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': S = [1,5,2,3,0,4]
    elif c == "S": S = [4,0,2,3,5,1]
    elif c == "E": S = [3,1,0,5,4,2]
    elif c == "W": S = [2,1,5,0,4,3]
    elif c == "R": S = [0,2,4,1,3,5]
    elif c == "L": S = [0,3,1,4,2,5]
    d = [d[s] for s in S]
    ans += d[0]
  print ans

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.total = 1
        self.up = 1
        self.s = 2
        self.e = 3

    def north(self):
        self.up, self.s = self.s, 7 - self.up
        self.total += self.up

    def south(self):
        self.up, self.s = 7 - self.s, self.up
        self.total += self.up

    def east(self):
        self.up, self.e = 7 - self.e, self.up
        self.total += self.up

    def west(self):
        self.up, self.e = self.e, 7 - self.up
        self.total += self.up

    def right(self):
        self.s, self.e = self.e, 7 - self.s
        self.total += self.up

    def left(self):
        self.s, self.e = 7 - self.e, self.s
        self.total += self.up

    def exe(self, cmd):
        if 'N' in cmd:
            self.north()
        elif 'S' in cmd:
            self.south()
        elif 'E' in cmd:
            self.east()
        elif 'W' in cmd:
            self.west()
        elif 'R' in cmd:
            self.right()
        elif 'L' in cmd:
            self.left()

def solve(N):
    dice = Dice()
    for i in range(N):
        cmd = input()
        dice.exe(cmd)

    print(dice.total)

while True:
    N = int(input())
    if N == 0:
        break
    solve(N)

Submission status: Accepted

Solution code:
def North(d):
    d[0], d[1], d[3], d[5] = d[1], d[5], d[0], d[3]
    return int(d[0])

def West(d):
    d[0], d[2], d[4], d[5] = d[2], d[5], d[0], d[4]
    return int(d[0])

def East(d):
    d[0], d[2], d[4], d[5] = d[4], d[0], d[5], d[2]
    return int(d[0])

def South(d):
    d[0], d[1], d[3], d[5] = d[3], d[0], d[5], d[1]
    return int(d[0])

def Right(d):
    d[1], d[2], d[3], d[4] = d[2], d[3], d[4], d[1]
    return int(d[0])

def Left(d):
    d[1], d[2], d[3], d[4] = d[4], d[1], d[2], d[3]
    return int(d[0])

while True:
    n = int(input())
    if n == 0:
        break

    dice = ['1','2','3','5','4','6']
    total = 1
    for i in range(n):
        ss = str(input().split()[0])
        if ss == "North":
            total += North(dice)

        elif ss == "West":
            total += West(dice)

        elif ss == "East":
            total += East(dice)

        elif ss == "South":
            total += South(dice)

        elif ss == "Right":
            total += Right(dice)

        elif ss == "Left":
            total += Left(dice)
    print(total)

Submission status: Accepted

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().strip()]()
        sum+=dice.omote
    print(sum)
    n=int(input())

Submission status: Accepted

Solution code:
class Dice(object):
    """
    6??¢???????????????
    ?????¢???top, ?????¢???bottom???????????\??????4??¢??????????????? north, south, east, west ??¨?????¶???
    """
    def __init__(self, faces):
        # faces???????????????????????¨?????????????????????????????????
        # ???????????? top, south, east, west, north, bottom ????????§????´????????????????????????¨??????????????????????????§???top??????????????£????????????
        self.top = faces[0]
        self.south = faces[1]
        self.east = faces[2]
        self.west = faces[3]
        self.north = faces[4]
        self.bottom = faces[5]
        self.values = (self.top, self.south, self.east, self.west, self.north, self.bottom)

    def rotate(self, dir):
        # ???????????????dir??????????????????????????¢?????????
        # ????????????N, S, E, W???????????????????????????(1??????)??§????????????
        if dir == 'N':
            temp = self.top
            self.top = self.south
            self.south = self.bottom
            self.bottom = self.north
            self.north = temp
        elif dir == 'S':
            temp = self.top
            self.top = self.north
            self.north = self.bottom
            self.bottom = self.south
            self.south = temp
        elif dir == 'E':
            temp = self.top
            self.top = self.west
            self.west = self.bottom
            self.bottom = self.east
            self.east = temp
        elif dir == 'W':
            temp = self.top
            self.top = self.east
            self.east = self.bottom
            self.bottom = self.west
            self.west = temp
        elif dir == 'R':
            self.spin()
        elif dir == 'L':
            self.spin(count=3)
        return self.top

    def get_top_value(self):
        return self.top

    def get_bottom_value(self):
        return self.bottom

    def get_east_value(self):
        return self.east

    def get_west_value(self):
        return self.west

    def get_north_value(self):
        return self.north

    def get_south_value(self):
        return self.south

    def spin(self, count=1):
        """???????????????top??¨bottom?????????????????????????????????????????????????????????????¨??????????90????????¢?????????
        ?????????????????§???1?????????????????????????????§?????§?????°??????????????????
        """
        for i in range(count):
            temp = self.south
            self.south = self.east
            self.east = self.north
            self.north = self.west
            self.west = temp

    def place(self, upper, front):
        """ ?????¢(top)??¨??¨??¢(south)?????????????????????upper, front??¨???????????????????????????????????¢?????????
        ??????????????????????????¨??????????????????????????????????????¢?????????????????????????????????????????????????????´???????????????(ValueError)?????????????????????
        """
        # ????????? top == upper??¨????????????????????¢?????????
        if upper not in self.values or front not in self.values:
            raise ValueError
        if upper == self.top:
            pass
        elif upper == self.east:
            self.rotate('W')
        elif upper == self.west:
            self.rotate('E')
        elif upper == self.north:
            self.rotate('S')
        elif upper == self.south:
            self.rotate('N')
        else:
            self.rotate('N')
            self.rotate('N')
        # ????????????south == front ??¨????????????????????¢?????????
        #if front == self.bottom:  # ?????°??¢??§????????????????????????????????§????????????????????§?????????????????¢??????????????????????????????????????°???????????????
        #    raise ValueError
        count = 0
        while front != self.south:
            self.spin()
            count += 1
            if count > 3:
                raise ValueError

    def is_identical(self, dice):
        """ ????????¨???????????????????????????????§????????????£?????????????¢?????????? (?????¢???????????°??????????????????????????????)
        :param dice: ?????????????????????????????????
        :return: ???????§????????????????(True/False)
        """
        # 6??¢????????????????§????????????£?????????????¢????
        my_v = sorted(list(self.values))
        d_v = sorted(list(dice.values))
        if my_v != d_v:
            return False

        # ?????¢????§????????¢????
        try:
            dice.place(self.get_top_value(), self.get_south_value())
        except ValueError:
            return False
        if self.get_east_value() != dice.get_east_value():
            return False
        self.spin()
        try:
            dice.place(self.get_top_value(), self.get_south_value())
        except ValueError:
            return False
        if self.get_east_value() != dice.get_east_value():
            return False
        self.spin()
        try:
            dice.place(self.get_top_value(), self.get_south_value())
        except ValueError:
            return False
        if self.get_east_value() != dice.get_east_value():
            return False
        self.spin()
        try:
            dice.place(self.get_top_value(), self.get_south_value())
        except ValueError:
            return False
        if self.get_east_value() != dice.get_east_value():
            return False

        return True


def process_commands(d, cmds):
    total = d.get_top_value()
    for cmd in cmds:
        total += d.rotate(cmd[0])
    return total


if __name__ == '__main__':
    while True:
        # ??????????????\???
        num = int(input())
        if num == 0:
            break
        commands = [input().strip() for _ in range(num)]

        # ?????????????????????
        d = Dice([1, 2, 3, 4, 5, 6])
        result = process_commands(d, commands)

        # ???????????¨???
        print(result)

Submission status: Accepted

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().rstrip()
        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: Accepted

Solution code:
def roll(die, d):
    if d == "E":
        return [die[3], die[1], die[0], die[5], die[4], die[2]]
    if d == "N":
        return [die[1], die[5], die[2], die[3], die[0], die[4]]
    if d == "S":
        return [die[4], die[0], die[2], die[3], die[5], die[1]]
    if d == "W":
        return [die[2], die[1], die[5], die[0], die[4], die[3]]
    if d == "L":
        return [die[0], die[3], die[1], die[4], die[2], die[5]]
    if d == "R":
        return [die[0], die[2], die[4], die[1], die[3], die[5]]

while True:
    die = [1, 2, 3, 4, 5, 6]
    ans = 1
    n = int(input())
    if n == 0:
        break
    for _ in range(n):
        die = roll(die, input()[0])
        ans += die[0]
    print(ans)

Submission status: Accepted

Solution code:
import sys
  
operator = sys.stdin.read().split()
      
top = 1
bottom = 6
south = 2
north = 5
east = 3
west = 4
sum = 1
  
for var in operator[1:]:
    if var == "North":
        north,top,south,bottom = top,south,bottom,north
        sum += top
    elif var == "South":
        south,top,north,bottom = top,north,bottom,south
        sum += top
    elif var == "West":
        west,top,east,bottom = top,east,bottom,west
        sum += top
    elif var == "East":
        east,top,west,bottom = top,west,bottom,east
        sum += top
    elif var == "Right":
        south,east,north,west = east,north,west,south
        sum += top
    elif var == "Left":
        south,west,north,east = west,north,east,south
        sum += top
    else:
        print sum
        top = 1
        bottom = 6
        south = 2
        north = 5
        east = 3
        west = 4
        sum = 1

Submission status: Accepted

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

Submission status: Accepted

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().strip()]
        dice = [dice[i] for i in indices]
        ans += dice[0]
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while 1:
 n=int(input())
 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"}[input()[0]]]
  a+=int(s[0])
 print(a)

Submission status: Accepted

Solution code:
import sys
d=sys.stdin
while 1:
 n=int(d.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"}[d.readline()[0]]]
  a+=int(s[0])
 print(a)

Submission status: Accepted

Solution code:
dice = [0,1,2,3,4,5,6]


def north():
    ret = [0]
    global dice
    ret.append(dice[2])
    ret.append(dice[6])
    ret.append(dice[3])
    ret.append(dice[4])
    ret.append(dice[1])
    ret.append(dice[5])

    dice = ret.copy()


def east():
    ret = [0]
    global dice
    ret.append(dice[4])
    ret.append(dice[2])
    ret.append(dice[1])
    ret.append(dice[6])
    ret.append(dice[5])
    ret.append(dice[3])

    dice = ret.copy()


def west():
    ret = [0]
    global dice
    ret.append(dice[3])
    ret.append(dice[2])
    ret.append(dice[6])
    ret.append(dice[1])
    ret.append(dice[5])
    ret.append(dice[4])

    dice = ret.copy()


def south():
    ret = [0]
    global dice
    ret.append(dice[5])
    ret.append(dice[1])
    ret.append(dice[3])
    ret.append(dice[4])
    ret.append(dice[6])
    ret.append(dice[2])

    dice = ret.copy()


def right():
    ret = [0]
    global dice
    ret.append(dice[1])
    ret.append(dice[3])
    ret.append(dice[5])
    ret.append(dice[2])
    ret.append(dice[4])
    ret.append(dice[6])

    dice = ret.copy()

def left():
    ret = [0]
    global dice
    ret.append(dice[1])
    ret.append(dice[4])
    ret.append(dice[2])
    ret.append(dice[5])
    ret.append(dice[3])
    ret.append(dice[6])

    dice = ret.copy()

total_score = 1

while True:
    n = int(input())
    if n == 0:
        break

    for i in range(n):
        input_str = input()

        if input_str == 'North':
            north()
        elif input_str == 'East':
            east()
        elif input_str == 'West':
            west()
        elif input_str == 'South':
            south()
        elif input_str == 'Right':
            right()
        else:
            left()
        total_score += dice[1]

    print(total_score)
    total_score = 1
    dice = [i for i in range(0, 7)]

Submission status: Accepted

Solution code:
import sys
d=sys.stdin.readline
p={'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),
   'S':(4,0,2,3,5,1),'R':(0,2,4,1,3,5),'L':(0,3,1,4,2,5)}
while 1:
 n=int(d())
 if n==0:break
 a=1;s='123456'
 for _ in[0]*n:
  s=[s[e]for e in p[d()[0]]]
  a+=int(s[0])
 print(a)

Submission status: Accepted

Solution code:
import sys
d=sys.stdin.readline
p={'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),
   'S':(4,0,2,3,5,1),'R':(0,2,4,1,3,5),'L':(0,3,1,4,2,5)}
while 1:
 n=int(d())
 if n==0:break
 a=[1];s='123456'
 for _ in[0]*n:
  s=[s[e]for e in p[d()[0]]]
  a+=[s[0]]
 print(sum(map(int,a)))

Submission status: Accepted

Solution code:
import sys
d=sys.stdin.readline
p={'N':(1,5,2,3,0,4),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3),
   'S':(4,0,2,3,5,1),'R':(0,2,4,1,3,5),'L':(0,3,1,4,2,5)}
for n in iter(d,'0\n'):
 a=[1];s='123456'
 for _ in[0]*int(n):
  s=[s[e]for e in p[d()[0]]]
  a+=[s[0]]
 print(sum(map(int,a)))