Problem:
Dice I Write a program to simulate rolling a dice, which can be constructed by the following net.    As shown in the figures, each face is identified by a different label from 1 to 6. Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures. Input In the first line, six integers assigned to faces are given in ascending order of their corresponding labels. In the second line, a string which represents a sequence of commands, is given. The command is one of ' E ', ' N ', ' S ' and ' W ' representing four directions shown in the above figures. Output Print the integer which appears on the top face after the simulation. Constraints  $0 \leq $ the integer assigned to a face $ \leq 100$  $0 \leq $ the length of the command $\leq 100$  Sample Input 1 1 2 4 8 16 32
SE Sample Output 1 8 You are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face labeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction S and then to the direction E , you can see 8 on the top face. Sample Input 2 1 2 4 8 16 32
EESWN Sample Output 2 32

Solution (Python):
class dice:
    def roll(self,direction):
        if direction=="N":
            self.face=[self.face[1],self.face[5],self.face[2],self.face[3],self.face[0],self.face[4]]
        if direction=="E":
            self.face=[self.face[3],self.face[1],self.face[0],self.face[5],self.face[4],self.face[2]]
        if direction=="W":
            self.face=[self.face[2],self.face[1],self.face[5],self.face[0],self.face[4],self.face[3]]
        if direction=="S":
            self.face=[self.face[4],self.face[0],self.face[2],self.face[3],self.face[5],self.face[1]]
dice1=dice()
dice1.face=list(map(int,input().split()))
for i in input():
    dice1.roll(i)
print(dice1.face[0])

Solution (Python):
class dice:
    def __init__(self, pip):
        self.pip = pip
        
    def move(self,dir):
        if str(dir) == "E":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[3],self.pip[0],self.pip[5],self.pip[2]
        elif str(dir) == "W":
            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[2],self.pip[5],self.pip[0],self.pip[3]
        elif str(dir) == "N":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[1],self.pip[5],self.pip[0],self.pip[4]
        elif str(dir) == "S":
            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[4],self.pip[0],self.pip[5],self.pip[1]

d = dice(list(map(int,input().split())))
inp = list(input())

for dir in inp:
    d.move(dir)

print(d.pip[0])

Solution (Python):
houkou={'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
saikoro=input().split()
for i in input():
  saikoro=[saikoro[j]for j in houkou[i]]
  
print(saikoro[0])

Solution (Python):
class Dice(object):
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom
    def rollN(self):
        prevN = self.north
        prevB = self.bottom
        prevS = self.south
        self.north = self.top
        self.bottom = prevN
        self.south = prevB
        self.top = prevS
    def rollS(self):
        prevS = self.south
        prevB = self.bottom
        prevN = self.north
        self.south = self.top
        self.bottom = prevS
        self.north = prevB
        self.top = prevN
    def rollE(self):
        prevE = self.east
        prevB = self.bottom
        prevW = self.west
        self.east = self.top
        self.bottom = prevE
        self.west = prevB
        self.top = prevW
    def rollW(self):
        prevW = self.west
        prevB = self.bottom
        prevE = self.east
        self.west = self.top
        self.bottom = prevW
        self.east = prevB
        self.top = prevE

diceInit = [int(n) for n in raw_input().split()][:6:]
instruction = raw_input()

diceI = Dice(diceInit[0], diceInit[1], diceInit[2], diceInit[3], diceInit[4], diceInit[5])

for item in instruction:
    if item == 'N':
        diceI.rollN()
    elif item == 'E':
        diceI.rollE()
    elif item == 'W':
        diceI.rollW()
    elif item == 'S':
        diceI.rollS()

print diceI.top

Solution (Python):
class Dice(object):
    def __init__(self, s1, s2, s3, s4, s5, s6):
        self.s1 = s1
        self.s2 = s2
        self.s3 = s3
        self.s4 = s4
        self.s5 = s5
        self.s6 = s6
    def east(self):
        prev_s6 = self.s6
        self.s6 = self.s3
        self.s3 = self.s1
        self.s1 = self.s4
        self.s4 = prev_s6
    def west(self):
        prev_s6 = self.s6
        self.s6 = self.s4
        self.s4 = self.s1
        self.s1 = self.s3
        self.s3 = prev_s6
    def north(self):
        prev_s6 = self.s6
        self.s6 = self.s5
        self.s5 = self.s1
        self.s1 = self.s2
        self.s2 = prev_s6
    def south(self):
        prev_s6 = self.s6
        self.s6 = self.s2
        self.s2 = self.s1
        self.s1 = self.s5
        self.s5 = prev_s6
    def top(self):
        return self.s1

s1, s2, s3, s4, s5, s6 = map(int, input().split())
dice = Dice(s1, s2, s3, s4, s5, s6)
order = input()
for c in order:
    if c == 'N':
        dice.north()
    elif c == 'W':
        dice.west()
    elif c == 'E':
        dice.east()
    elif c == 'S':
        dice.south()
print(dice.top())

Solution (Python):
def north(d):
    return [d[1], d[5], d[2], d[3], d[0], d[4]]

def east(d):
    return [d[3], d[1], d[0], d[5], d[4], d[2]]

def south(d):
    return [d[4], d[0], d[2], d[3], d[5], d[1]]

def west(d):
    return [d[2], d[1], d[5], d[0], d[4], d[3]]

numbers = list(map(int, input().split()))
directions = list(input())

for d in directions:
    if d == "N":
        numbers = north(numbers)
    elif d == "E":
        numbers = east(numbers)
    elif d == "S":
        numbers = south(numbers)
    elif d == "W":
        numbers = west(numbers)

print(numbers[0])

Solution (Python):
def rot(dice, I):
  
  
  a = dice[:]
  if I=='N': x=[0,4,5,1,0]
  elif I=='E': x=[0,2,5,3,0]
  elif I=='W': x=[0,3,5,2,0]
  elif I=='S': x=[0,1,5,4,0]
  for i in [0,1,2,3]: a[x[i+1]]=dice[x[i]]
  return a

dice = map(int,raw_input().split())
for c in raw_input(): dice = rot(dice,c)
print dice[0]

Solution (Python):
def get_dice(pips):
    return [[0, pips[4], 0, 0], 
                   [pips[3], pips[0], pips[2], pips[5]], 
                   [0, pips[1], 0, 0]]

def move_e(dice):
    dice[1] = dice[1][3:] + dice[1][:3]
    return dice

def move_n(dice):
    return [[0,          dice[1][1], 0, 0],
            [dice[1][0], dice[2][1], dice[1][2], dice[0][1]],
            [0,                 dice[1][3], 0, 0]]

def move_s(dice):
    return [[0,          dice[1][3], 0, 0],
            [dice[1][0], dice[0][1], dice[1][2], dice[2][1]],
            [0,                 dice[1][1], 0, 0]]

def move_w(dice):
    dice[1] = dice[1][1:] + dice[1][:1]
    return dice

func = {'E':move_e,'N':move_n,'S':move_s,'W':move_w}

dice = get_dice(list(map(int, input().split())))

for c in input():
    dice = func[c](dice)

print(dice[1][1])

Solution (Python):
mask = {'N':(1, 5, 2, 3, 0, 4), 'E':(3, 1, 0, 5, 4, 2), 'S':(4, 0, 2, 3, 5, 1), 'W':(2, 1, 5, 0, 4,3)}

dice = input().split()

for c in input():
    dice = [dice[i] for i in mask[c]]

print(dice[0])

Solution (Python):
class Dice:
    def __init__(self, data):
        self.data = data
    
    def move(self, direction):
        if direction == 'E':
            self.data[0], self.data[3], self.data[5], self.data[2] = \
                self.data[3], self.data[5], self.data[2], self.data[0]
        elif direction == 'N':
            self.data[0], self.data[4], self.data[5], self.data[1] = \
                self.data[1], self.data[0], self.data[4], self.data[5]
        elif direction == 'S':
            self.data[0], self.data[1], self.data[5], self.data[4] = \
                self.data[4], self.data[0], self.data[1], self.data[5]
        elif direction == 'W':
            self.data[0], self.data[2], self.data[5], self.data[3] = \
                self.data[2], self.data[5], self.data[3], self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
print(dice.getTop())

Solution (Python):
class Dice:
    def __init__(self, data):
        self.data = data

    def move(self, direction):
        if direction == 'E':
            self.data[0],self.data[3], self.data[5], self.data[2] = \
                self.data[3],self.data[5], self.data[2], self.data[0] 
        elif direction == 'N':
            self.data[0],self.data[1], self.data[5], self.data[4] = \
                self.data[1],self.data[5], self.data[4], self.data[0]
        elif direction == 'S':
            self.data[0],self.data[1], self.data[5], self.data[4] = \
                self.data[4],self.data[0], self.data[1], self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2], self.data[5], self.data[3] = \
                self.data[2],self.data[5], self.data[3], self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
print(dice.getTop())

Solution (Python):
class Dice:
    def __init__(self, data):
        self.data = data

    def move(self, direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3],self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[1],self.data[0],self.data[4],self.data[5]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4],self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
             self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2],self.data[5],self.data[3],self.data[0]


    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])

print(dice.getTop())

Solution (Python):
class Dice:
    def __init__ (self,data):
        self.data = data

    def move(self,direction):
        if direction == 'E':
            self.data[0],self.data[3],self.data[5],self.data[2] = \
                    self.data[3],self.data[5],self.data[2],self.data[0]
        elif direction == 'N':
            self.data[0],self.data[4],self.data[5],self.data[1] = \
                    self.data[1],self.data[0],self.data[4],self.data[5]
        elif direction == 'S':
            self.data[0],self.data[1],self.data[5],self.data[4] = \
                    self.data[4],self.data[0],self.data[1],self.data[5]
        elif direction == 'W':
            self.data[0],self.data[2],self.data[5],self.data[3] = \
                    self.data[2],self.data[5],self.data[3],self.data[0]

    def getTop(self):
        return self.data[0]

dice = Dice(input().split())
cmd = input()
for i in range(len(cmd)):
    dice.move(cmd[i])
print(dice.getTop())

Solution (Python):
import sys

dice = [int(i) for i in sys.stdin.readline().split()]
command = sys.stdin.readline().strip()
for c in command:
    if c == "N":
        dice = (dice[1], dice[5], dice[2], dice[3], dice[0], dice[4])
    elif c == "S":
        dice = (dice[4], dice[0], dice[2], dice[3], dice[5], dice[1])
    elif c == "W":
        dice = (dice[2], dice[1], dice[5], dice[0], dice[4], dice[3])
    elif c == "E":
        dice = (dice[3], dice[1], dice[0], dice[5], dice[4], dice[2])
print(dice[0])

Solution (Python):
import sys

class Dice(object):
    def __init__(self, dice):
        self.__dice = dice

    def roll_north(self):
        self.__dice = (self.__dice[1], self.__dice[5], self.__dice[2],
                       self.__dice[3], self.__dice[0], self.__dice[4])

    def roll_south(self):
        self.__dice = (self.__dice[4], self.__dice[0], self.__dice[2],
                       self.__dice[3], self.__dice[5], self.__dice[1])

    def roll_west(self):
        self.__dice = (self.__dice[2], self.__dice[1], self.__dice[5],
                       self.__dice[0], self.__dice[4], self.__dice[3])

    def roll_east(self):
        self.__dice = (self.__dice[3], self.__dice[1], self.__dice[0],
                       self.__dice[5], self.__dice[4], self.__dice[2])

    def number(self, face_id):
        return self.__dice[face_id - 1]


dice = Dice([int(i) for i in sys.stdin.readline().split()])
command = sys.stdin.readline().strip()
for c in command:
    if c == "N":
        dice.roll_north()
    elif c == "S":
        dice.roll_south()
    elif c == "W":
        dice.roll_west()
    elif c == "E":
        dice.roll_east()
print(dice.number(1))

Solution (Python):
class Dice:
    def __init__(self,ls):
        self.a = ls[0]
        self.b = ls[1]
        self.c = ls[2]
        self.d = ls[3]
        self.e = ls[4]
        self.f = ls[5]
    
    def E(self):
        self.a, self.c, self.f, self.d = self.d, self.a, self.c, self.f
    def W(self):
        self.a, self.c, self.f, self.d = self.c, self.f, self.d, self.a
    def S(self):
        self.a, self.b, self.f, self.e = self.e, self.a, self.b, self.f
    def N(self):
        self.a, self.b, self.f, self.e = self.b, self.f, self.e, self.a
    
ls = map(int,raw_input().split())
orders = raw_input()
dice = Dice(ls)
for w in orders:
    if w == 'E': dice.E()
    elif w == 'W': dice.W()
    elif w == 'S': dice.S()
    elif w == 'N': dice.N()
print dice.a

Solution (Python):



class Dice:
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, direction):
        if direction == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if direction == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if direction == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if direction == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

    def get_top(self):
        return self.top

if __name__ == '__main__':
    nums = [int(i) for i in input().split()]
    directions = input()

    d = Dice(nums)
    for ch in directions:
        d.roll(ch)

    print(d.get_top())

Solution (Python):



class Dice:
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, direction):
        if direction == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if direction == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if direction == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if direction == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

    def get_top(self):
        return self.top

if __name__ == '__main__':
    nums = [int(i) for i in input().split()]
    directions = input()

    d = Dice(nums)
    for i in range(len(directions)):
        d.roll(directions[i])

    print(d.get_top())

Solution (Python):


class Dice:
    def __init__(self,ary):
        self.top = ary[0]
        self.south = ary[1]
        self.east = ary[2]
        self.west = ary[3]
        self.north = ary[4]
        self.bottom = ary[5]

    def get_top(self):
        return self.top

    def roll_n(self):
        self.top , self.south , self.bottom , self.north = self.south , self.bottom , self.north , self.top

    def roll_s(self):
        self.top , self.north , self.bottom , self.south = self.north , self.bottom , self.south , self.top

    def roll_e(self):
        self.top , self.west , self.bottom , self.east = self.west , self.bottom , self.east , self.top

    def roll_w(self):
        self.top , self.east , self.bottom , self.west = self.east , self.bottom , self.west , self.top

dice = Dice(input().split())
cmds = input()
for cmd in cmds:
    if cmd == 'N':
        dice.roll_n()
    elif cmd == 'S':
        dice.roll_s()
    elif cmd == 'E':
        dice.roll_e()
    elif cmd == 'W':
        dice.roll_w()

print(dice.get_top())

Solution (Python):
import sys
data=list(map(int,input().split()))
order=sys.stdin.readline()
char_list=list(order)
for i in char_list:
	
	if i=='N':
		k=data[0]
		m=data[4]
		data[0]=data[1]
		data[1]=data[5]
		data[4]=k
		data[5]=m
	elif i=='E':
		k=data[0]
		m=data[2]
		data[0]=data[3]
		data[2]=k
		data[3]=data[5]	
		data[5]=m
	elif i=='S':
		k=data[0]
		m=data[1]
		data[0]=data[4]
		data[1]=k
		data[4]=data[5]
		data[5]=m
	elif i=='W':
		k=data[0]
		m=data[3]
		data[0]=data[2]
		data[2]=data[5]
		data[3]=k
		data[5]=m
print(data[0])

Solution (Python):
import sys

class Dice(object):
	def __init__(self, data):
		self.dice=data
	def roll_n(self):
		self.dice=(self.dice[1],self.dice[5],self.dice[2],
					self.dice[3],self.dice[0],self.dice[4])
	def roll_e(self):
		self.dice=(self.dice[3],self.dice[1],self.dice[0],
					self.dice[5],self.dice[4],self.dice[2])
	def roll_w(self):
		self.dice=(self.dice[2],self.dice[1],self.dice[5],
					self.dice[0],self.dice[4],self.dice[3])				
	def roll_s(self):
		self.dice=(self.dice[4],self.dice[0],self.dice[2],
					self.dice[3],self.dice[5],self.dice[1])
	def get_top(self, id):
 		return self.dice[id-1]

data=Dice([int(i) for i in sys.stdin.readline().split()])
order=sys.stdin.readline().strip()
for i in order:
	if i=='N':
		data.roll_n()
	elif i=='E':
		data.roll_e()
	elif i=='S':
		data.roll_s()
	elif i=='W':
		data.roll_w()
print(data.get_top(1))

Solution (Python):
l=map(int,raw_input().split())
n=raw_input()
ans=chk=0


def rolling(word,dice):
    if word=='S':
        dice[0],dice[1],dice[5],dice[4]=dice[4],dice[0],dice[1],dice[5]
    elif word=='N':
        dice[0],dice[1],dice[5],dice[4]=dice[1],dice[5],dice[4],dice[0]
    elif word=='W':
        dice[0],dice[2],dice[5],dice[3]=dice[2],dice[5],dice[3],dice[0]
    else:
        dice[0],dice[2],dice[5],dice[3]=dice[3],dice[0],dice[2],dice[5]
    return dice

for i in n:
    l=rolling(i,l)
print l[0]

Solution (Python):
diceface = { "TOP":0,"FRONT":1,"RIGHT":2,"LEFT":3,"BACK":4,"BOTTOM":5 }

dice = [ int( i ) for i in raw_input( ).split( " " ) ]
roll = raw_input( )
for i in range( len(  roll ) ):
	if "E" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = t
	elif "N" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = t
	elif "S" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = t
	elif "W" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = t	

print( dice[ diceface["TOP"] ] )

Solution (Python):
diceface = { "TOP":0,"FRONT":1,"RIGHT":2,"LEFT":3,"BACK":4,"BOTTOM":5 }

dice = [ int( i ) for i in input( ).split( " " ) ]
roll = input( )
for i in range( len(  roll ) ):
	if "E" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = t
	elif "N" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = t
	elif "S" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = t
	elif "W" == roll[i]:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = t	

print( dice[ diceface["TOP"] ] )

Solution (Python):
diceface = { "TOP":0,"FRONT":1,"RIGHT":2,"LEFT":3,"BACK":4,"BOTTOM":5 }

dice = [ int( i ) for i in raw_input( ).split( " " ) ]
roll = raw_input( )
for i in roll:
	if "E" == i:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = t
	elif "N" == i:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = t
	elif "S" == i:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["BACK"] ]
		dice[ diceface["BACK"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["FRONT"] ]
		dice[ diceface["FRONT"] ] = t
	elif "W" == i:
		t = dice[ diceface["TOP"] ]
		dice[ diceface["TOP"] ] = dice[ diceface["RIGHT"] ]
		dice[ diceface["RIGHT"] ] = dice[ diceface["BOTTOM"] ]
		dice[ diceface["BOTTOM"] ] = dice[ diceface["LEFT"] ]
		dice[ diceface["LEFT"] ] = t	

print( dice[ diceface["TOP"] ] )

Solution (Python):
class Dice:
    def __init__(self, top, front, right, left, back, bottom):
        self.top,   self.bottom = top, bottom
        self.right, self.left   = right, left
        self.front, self.back   = front, back

    def rot(self, d):
        if   d == "N":
            self.top, self.back, self.bottom, self.front = self.front, self.top, self.back, self.bottom
        elif d == "S":
            self.top, self.back, self.bottom, self.front = self.back, self.bottom, self.front, self.top
        elif d == "E":
            self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom
        elif d == "W":
            self.top, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.top

ls = map(int, raw_input().split())
dice = Dice(ls[0], ls[1], ls[2], ls[3], ls[4], ls[5])
for d in raw_input():
    dice.rot(d)
print dice.top

Solution (Python):



class Dice(object):

    def __init__(self, label):
        self.label = label

    def rotateS(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s5, s1, s3, s4, s6, s2]

    def rotateN(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s2, s6, s3, s4, s1, s5]

    def rotateE(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s4, s2, s1, s6, s5, s3]

    def rotateW(self):
        s1, s2, s3, s4, s5, s6 = self.label
        self.label = [s3, s2, s6, s1, s5, s4]

    def rotate(self, r):
        if r == 'S':
            self.rotateS()
        elif r == 'N':
            self.rotateN()
        elif r == 'E':
            self.rotateE()
        elif r == 'W':
            self.rotateW()
        else:
            print 'Cannot rotate into ' + r + 'direction.'

    def getTopLabel(self):
        return self.label[0]


if __name__ == '__main__':
    d = Dice(map(int, raw_input().split()))
    rotations = raw_input()
    for r in rotations:
        d.rotate(r)
    print d.getTopLabel()

Solution (Python):
class Dice:

    def __init__(self, faces):
        self.faces = tuple(faces)

    def roll_north(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])

    def roll_south(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])

    def roll_west(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])

    def roll_east(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])

    def number(self, face_id):
        return self.faces[face_id - 1]


dice = Dice(list(map(int, input().split())))
commands = input()

for c in commands:
    if c == "N":
        dice.roll_north()
    elif c == "S":
        dice.roll_south()
    elif c == "W":
        dice.roll_west()
    elif c == "E":
        dice.roll_east()
print(dice.number(1))

Solution (Python):
a = list(map(int, input().split()))
commands = input()
for command in commands:
    if command == 'N':
        a[0], a[1], a[5], a[4] = a[1], a[5], a[4], a[0]
    elif command == 'S':
        a[0], a[1], a[5], a[4] = a[4], a[0], a[1], a[5]
    elif command == 'W':
        a[0], a[3], a[5], a[2] = a[2], a[0], a[3], a[5]
    elif command == 'E':
        a[0], a[3], a[5], a[2] = a[3], a[5], a[2], a[0]
print(a[0])

Solution (Python):
m={"E":[3,1,0,5,4,2], "N":[1,5,2,3,0,4], "W":[2,1,5,0,4,3], "S":[4,0,2,3,5,1]}
d=map(int, raw_input().split())
nd=[0]*6
dir=raw_input()
for i in range(len(dir)):
    x=dir[i]
    for j in range(6):
        nd[j]=d[m[x][j]]
    d=list(nd)
print d[0]

Solution (Python):
m={"E":[3,1,0,5,4,2], "N":[1,5,2,3,0,4], "W":[2,1,5,0,4,3], "S":[4,0,2,3,5,1]}
d=map(int, raw_input().split())
nd=[0]*6
for x in raw_input():
    for j in range(6): nd[j]=d[m[x][j]]
    d=list(nd)
print d[0]

Solution (Python):
class Dice:
  def __init__(self, list = map(str, range(1, 7))):
    self.top = list[0]
    self.front = list[1]
    self.right = list[2]
    self.left = list[3]
    self.back = list[4]
    self.bottom = list[5]

  def print_all(self):
    print "top = " + self.top
    print "front = " + self.front
    print "right = " + self.right
    print "left = " + self.left
    print "back = " + self.back
    print "bottom = " + self.bottom

  def roll_N(self):
    temp = self.top
    self.top = self.front
    self.front = self.bottom
    self.bottom = self.back
    self.back = temp

  def roll_S(self):
    temp = self.top
    self.top = self.back
    self.back = self.bottom
    self.bottom = self.front
    self.front = temp

  def roll_W(self):
    temp = self.top
    self.top = self.right
    self.right = self.bottom
    self.bottom = self.left
    self.left = temp

  def roll_E(self):
    temp = self.top
    self.top = self.left
    self.left = self.bottom
    self.bottom = self.right
    self.right = temp

my_dice = Dice(raw_input().split(" "))
order = raw_input()
for i in xrange(len(order)):
  if order[i] == "E":
    my_dice.roll_E()
  elif order[i] == "N":
    my_dice.roll_N()
  elif order[i] == "S":
    my_dice.roll_S()
  elif order[i] == "W":
    my_dice.roll_W()
  else:
    continue

print my_dice.top

Solution (Python):



POSITIONS = ["top", "south", "east", "west", "north", "bottom"]


class Dice(object):

    def __init__(self, initial_faces):
        self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)}
        self.store_previous_faces()

    def store_previous_faces(self):
        self.previous_faces = self.faces.copy()

    def change_face(self, after, before):
        self.faces[after] = self.previous_faces[before]

    def change_faces(self, rotation):
        self.change_face(rotation[0], rotation[1])
        self.change_face(rotation[1], rotation[2])
        self.change_face(rotation[2], rotation[3])
        self.change_face(rotation[3], rotation[0])

    def roll(self, direction):
        self.store_previous_faces()
        if direction == "E":
            self.change_faces(["top", "west", "bottom", "east"])
        elif direction == "N":
            self.change_faces(["top", "south", "bottom", "north"])
        elif direction == "S":
            self.change_faces(["top", "north", "bottom", "south"])
        elif direction == "W":
            self.change_faces(["top", "east", "bottom", "west"])

    def rolls(self, directions):
        for d in directions:
            self.roll(d)

    def show_top(self):
        return self.faces["top"]


def main():
    dice = Dice(input().split())
    dice.rolls(input())
    print(dice.show_top())

if __name__ == "__main__":
    main()

Solution (Python):
import sys
 
class Dice(object):
    def __init__(self, dice):
        self.__dice = dice
 
    def roll_north(self):
        self.__dice = (self.__dice[1], self.__dice[5], self.__dice[2],
                       self.__dice[3], self.__dice[0], self.__dice[4])
 
    def roll_south(self):
        self.__dice = (self.__dice[4], self.__dice[0], self.__dice[2],
                       self.__dice[3], self.__dice[5], self.__dice[1])
 
    def roll_west(self):
        self.__dice = (self.__dice[2], self.__dice[1], self.__dice[5],
                       self.__dice[0], self.__dice[4], self.__dice[3])
 
    def roll_east(self):
        self.__dice = (self.__dice[3], self.__dice[1], self.__dice[0],
                       self.__dice[5], self.__dice[4], self.__dice[2])
 
    def number(self, face_id):
        return self.__dice[face_id - 1]
 
 
dice = Dice([int(i) for i in sys.stdin.readline().split()])
command = sys.stdin.readline().strip()
for c in command:
    if c == "N":
        dice.roll_north()
    elif c == "S":
        dice.roll_south()
    elif c == "W":
        dice.roll_west()
    elif c == "E":
        dice.roll_east()
print(dice.number(1))

Solution (Python):
class Dice(object):

    def __init__(self, num):
        self.num = num

    def rotate_S(self):
        self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]]

    def rotate_N(self):
        self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]]

    def rotate_W(self):
        self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]]

    def rotate_E(self):
        self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]]


dice = Dice(map(int, raw_input().split()))
order = raw_input()
for i in range(len(order)):
    if order[i] == 'S':
        dice.rotate_S()
    elif order[i] == 'N':
        dice.rotate_N()
    elif order[i] == 'W':
        dice.rotate_W()
    elif order[i] == 'E':
        dice.rotate_E()

print dice.num[0]