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):
label = input().split()
rot = input()
 
dice = {
        "top":1,
        "front":2,
        "right":3,
        "left":4,
        "back":5,
        "bottom":6
        }
 
for r in rot:
    if r == 'E':
        dice["top"], dice["left"], dice["bottom"], dice["right"] = \
        dice["left"], dice["bottom"], dice["right"], dice["top"]
    elif r == 'N':
        dice["top"], dice["front"], dice["bottom"], dice["back"] = \
        dice["front"], dice["bottom"], dice["back"], dice["top"]
    elif r == 'S':
        dice["top"], dice["back"], dice["bottom"], dice["front"] = \
        dice["back"], dice["bottom"], dice["front"], dice["top"]
    elif r == 'W':
        dice["top"], dice["right"], dice["bottom"], dice["left"] = \
        dice["right"], dice["bottom"], dice["left"], dice["top"]
print(label[dice["top"]-1])

Solution (Python):

class Dice:
    def __init__(self, label):
        self.d = label

    def roll(self, direction):
        if direction == "N":
            self.d[0], self.d[1], self.d[5], self.d[4] = self.d[1], self.d[5], self.d[4], self.d[0]
        elif direction == "S":
            self.d[0], self.d[1], self.d[5], self.d[4] = self.d[4], self.d[0], self.d[1], self.d[5]
        elif direction == "E":
            self.d[0], self.d[2], self.d[5], self.d[3] = self.d[3], self.d[0], self.d[2], self.d[5]
        else:
            self.d[0], self.d[2], self.d[5], self.d[3] = self.d[2], self.d[5], self.d[3], self.d[0]

label = [int(i) for i in input().split()]
cmd = input()

dice1 = Dice(label)

for i in cmd:
    dice1.roll(i)

print(dice1.d[0])

Solution (Python):
op = {'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)}
f = input().split()
for i in input():
    f = [f[j] for j in op[i]]
print(f[0])

Solution (Python):
n = [int(i) for i in input().split()]
s = input()


class Dice(object):
    def __init__(self,num):
        self.n = num[4]
        self.e = num[2]
        self.w = num[3]
        self.s = num[1]
        self.center = num[0]
        self.back = num[5]

    def move(self,str):
        if str == 'N':
            x = self.n
            self.n = self.center
            self.center = self.s
            self.s = self.back
            self.back = x
            return self.center
        elif str == 'S':
            x = self.s
            self.s = self.center
            self.center = self.n
            self.n = self.back
            self.back = x
            return self.center
        elif str== 'E':
            x = self.e
            self.e = self.center
            self.center = self.w
            self.w = self.back
            self.back = x
            return self.center
        elif str == 'W':
            x = self.w
            self.w = self.center
            self.center = self.e
            self.e = self.back
            self.back = x
            return self.center

dice = Dice(n)
status = 0

for i in range(len(s)):
    status = dice.move(s[i])

print(status)

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

    def throw(self, direction):
        if direction == "E":
            pmen = men[:]
            men[0] = pmen[3]
            men[1] = pmen[1]
            men[2] = pmen[0]
            men[3] = pmen[5]
            men[4] = pmen[4]
            men[5] = pmen[2]
        elif direction == "W":
            pmen = men[:]
            men[0] = pmen[2]
            men[1] = pmen[1]
            men[2] = pmen[5]
            men[3] = pmen[0]
            men[4] = pmen[4]
            men[5] = pmen[3]
        elif direction == "S":
            pmen = men[:]
            men[0] = pmen[4]
            men[1] = pmen[0]
            men[2] = pmen[2]
            men[3] = pmen[3]
            men[4] = pmen[5]
            men[5] = pmen[1]
        elif direction == "N":
            pmen = men[:]
            men[0] = pmen[1]
            men[1] = pmen[5]
            men[2] = pmen[2]
            men[3] = pmen[3]
            men[4] = pmen[0]
            men[5] = pmen[4]


    def printUe(self):
        print (self.men)[0]

    def printMen(self):
        print self.men

men = map(int, (raw_input()).split(" "))
d = Dice(men)

S = raw_input()
for s in S:
    d.throw(s)
d.printUe()

Solution (Python):
class Dice:

    __top = 0
    __front = 1
    __right = 2
    __left = 3
    __back = 4
    __bottom = 5

    def __init__(self, a, b, c, d, e, f):
        self.__dice = [a,b,c,d,e,f]

    def S(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__back]
        self.__dice[Dice.__front]  = dice_before[Dice.__top]
        self.__dice[Dice.__right]  = dice_before[Dice.__right]
        self.__dice[Dice.__left]   = dice_before[Dice.__left]
        self.__dice[Dice.__back]   = dice_before[Dice.__bottom]
        self.__dice[Dice.__bottom] = dice_before[Dice.__front]

    def E(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__left]
        self.__dice[Dice.__front]  = dice_before[Dice.__front]
        self.__dice[Dice.__right]  = dice_before[Dice.__top]
        self.__dice[Dice.__left]   = dice_before[Dice.__bottom]
        self.__dice[Dice.__back]   = dice_before[Dice.__back]
        self.__dice[Dice.__bottom] = dice_before[Dice.__right]

    def W(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__right]
        self.__dice[Dice.__front]  = dice_before[Dice.__front]
        self.__dice[Dice.__right]  = dice_before[Dice.__bottom]
        self.__dice[Dice.__left]   = dice_before[Dice.__top]
        self.__dice[Dice.__back]   = dice_before[Dice.__back]
        self.__dice[Dice.__bottom] = dice_before[Dice.__left]

    def N(self):
        dice_before = self.__dice[:]
        self.__dice[Dice.__top]    = dice_before[Dice.__front]
        self.__dice[Dice.__front]  = dice_before[Dice.__bottom]
        self.__dice[Dice.__right]  = dice_before[Dice.__right]
        self.__dice[Dice.__left]   = dice_before[Dice.__left]
        self.__dice[Dice.__back]   = dice_before[Dice.__top]
        self.__dice[Dice.__bottom] = dice_before[Dice.__back]

    def top(self):
        return(self.__dice[Dice.__top])

a,b,c,d,e,f = input().split()
dice = Dice(a,b,c,d,e,f)
com = input()
for i in com:
    if i == 'S':
        dice.S()

    elif i == 'E':
        dice.E()

    elif i == 'W':
        dice.W()

    elif i == 'N':
        dice.N()

print(dice.top())

Solution (Python):
def north(d):
    d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]


def west(d):
    d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]


def east(d):
    d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0]


def south(d):
    d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0]


F = {'N': north, 'W': west, 'E': east, 'S': south}
d, os = list(map(int, input().split())), input()
for o in os:
    F[o](d)
print(d[0])

Solution (Python):
class Dice:
    def __init__(self,l1,l2,l3,l4,l5,l6):
        self.l1 = l1
        self.l2 = l2
        self.l3 = l3
        self.l4 = l4
        self.l5 = l5
        self.l6 = l6
        self.top = 1
        self.front = 2
        self.right = 3

    def get_top(self):
        return eval("self." + 'l' + str(self.top))

    def move(self, order):
        if order == 'S':
            pretop = self.top
            self.top = 7 - self.front
            self.front = pretop
        elif order == 'E':
            pretop = self.top
            self.top = 7 - self.right
            self.right = pretop
        elif order == 'N':
            pretop = self.top
            self.top = self.front
            self.front = 7 - pretop
        elif order == 'W':
            pretop = self.top
            self.top = self.right
            self.right = 7 - pretop

l = list(map(int,input().split()))
orders = input()
d = Dice(l[0],l[1],l[2],l[3],l[4],l[5])
for order in orders:
    d.move(order)
print(d.get_top())

Solution (Python):


u,s,e,w,n,b = map(int,input().split())
roll = input()
for i in roll:
	if i == "E":
		tmp = e
		e = u
		u = w
		w = b
		b = tmp
	elif i == "S":
		tmp = s
		s = u
		u = n
		n = b
		b = tmp
	elif i == "W":
		tmp = w
		w = u
		u = e
		e = b
		b = tmp
	elif i == "N":
		tmp = n
		n = u
		u = s
		s = b
		b = tmp

print(u)

Solution (Python):
def move(up,bottom,right,left,front,back,direction):
    if direction == "N":
        return (front,back,right,left,bottom,up)
    elif direction == "S":
        return (back,front,right,left,up,bottom)
    elif direction == "E":
        return (left,right,up,bottom,front,back)
    elif direction == "W":
        return (right,left,bottom,up,front,back)
    
up,front,right,left,back,bottom = input().split()
direction = list(input())

for i in range(len(direction)):
    up,bottom,right,left,front,back = move(up,bottom,right,left,front,back,direction[i])
    
print(up)

Solution (Python):


u, s, e, w, n, b = map(int, input().split())
roll = input()
for i in roll:
    if i == "E":
        e,u,w,b = u,w,b,e
    elif i == "S":
        s,u,n,b = u,n,b,s
    elif i == "W":
        w,u,e,b = u,e,b,w
    elif i == "N":
        n,u,s,b = u,s,b,n
print(u)

Solution (Python):
class Dice:
    u, s, e, w, n, b = map(int, input().split())
    roll = input()
    for i in roll:
        if i == "E":
            e,u,w,b = u,w,b,e
        elif i == "S":
            s,u,n,b = u,n,b,s
        elif i == "W":
            w,u,e,b = u,e,b,w
        elif i == "N":
            n,u,s,b = u,s,b,n
    print(u)

dice = Dice()

Solution (Python):
r={'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)}
d=input().split()
for x in input():
    d=[d[y]for y in r[x]]
print(d[0])

Solution (Python):


import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        tmp = int()
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp

    def print_upside(self):
        print(self.pips[0])


def main():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    die.print_upside()


if __name__ == '__main__':
    main()

Solution (Python):


import sys


class Die:
    def __init__(self, pips):
        self.pips = pips

    def move_die(self, direction):
        tmp = int()
        if direction == 'N':
            tmp = self.pips[0]
            self.pips[0] = self.pips[1]
            self.pips[1] = self.pips[5]
            self.pips[5] = self.pips[4]
            self.pips[4] = tmp
        elif direction == 'S':
            tmp = self.pips[0]
            self.pips[0] = self.pips[4]
            self.pips[4] = self.pips[5]
            self.pips[5] = self.pips[1]
            self.pips[1] = tmp
        elif direction == 'E':
            tmp = self.pips[0]
            self.pips[0] = self.pips[3]
            self.pips[3] = self.pips[5]
            self.pips[5] = self.pips[2]
            self.pips[2] = tmp
        elif direction == 'W':
            tmp = self.pips[0]
            self.pips[0] = self.pips[2]
            self.pips[2] = self.pips[5]
            self.pips[5] = self.pips[3]
            self.pips[3] = tmp

    def get_upside(self):
        return self.pips[0]


def init_die():
    pips = [int(pip) for pip in sys.stdin.readline().strip('\n').split()]
    die = Die(pips)
    return die


def roll_die(die):
    directions = list(sys.stdin.readline().strip('\n'))

    for direction in directions:
        die.move_die(direction)

    return die


def main():
    die = init_die()
    die = roll_die(die)
    print(die.get_upside())


if __name__ == '__main__':
    main()

Solution (Python):
class Dice():
	def __init__(self, label):
		self.d = label
	
	def roll(self, drt):
		if drt == 'N':
			self.d[1], self.d[2], self.d[6], self.d[5] = self.d[2], self.d[6], self.d[5], self.d[1]
		elif drt == 'E':
			self.d[1], self.d[3], self.d[6], self.d[4] = self.d[4], self.d[1], self.d[3], self.d[6]
		elif drt == 'S':
			self.d[2], self.d[6], self.d[5], self.d[1] = self.d[1], self.d[2], self.d[6], self.d[5]
		elif drt == 'W':
			self.d[4], self.d[1], self.d[3], self.d[6] = self.d[1], self.d[3], self.d[6], self.d[4]
	def printl(self, lct):
		print(self.d[lct])
		
label = [0]	
label.extend(list(map(int, input().split())))
dice1 = Dice(label)
direction = input()
leng = len(direction)

for i in range(leng):
	dice1.roll(direction[i])

dice1.printl(1)

Solution (Python):
A,B,C,D,E,F = map(int, input().split())
f = list(input())
for i in range(len(f)):
    if f[i] == "E":
        A,B,C,D,E,F = D,B,A,F,E,C
    elif f[i] == "N":
        A,B,C,D,E,F = B,F,C,D,A,E
    elif f[i] == "S":
        A,B,C,D,E,F = E,A,C,D,F,B
    elif f[i] == "W":
        A,B,C,D,E,F = C,B,F,A,E,D

print(A)

Solution (Python):
d = map(int,raw_input().split())

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]}

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:
    """Dice class"""

    def __init__(self):                  
        self.eyeIndex = 1        
        self.eyeIndex_E = 3      
        self.eyeIndex_W = 4      
        self.eyeIndex_N = 5      
        self.eyeIndex_S = 2      
        self.eye = 0
        
    def shakeDice(self, in_command):

        pre_eyeIndex = self.eyeIndex
        if in_command == "E":
            self.eyeIndex = self.eyeIndex_W 
            self.eyeIndex_E = pre_eyeIndex 
            self.eyeIndex_W = 7 - self.eyeIndex_E
            
        elif in_command == "W":
            self.eyeIndex = self.eyeIndex_E 
            self.eyeIndex_W = pre_eyeIndex
            self.eyeIndex_E = 7 - self.eyeIndex_W
            
        elif in_command == "N":
            self.eyeIndex = self.eyeIndex_S 
            self.eyeIndex_N = pre_eyeIndex 
            self.eyeIndex_S = 7 - self.eyeIndex_N

        elif in_command == "S":
            self.eyeIndex = self.eyeIndex_N         
            self.eyeIndex_S = pre_eyeIndex 
            self.eyeIndex_N = 7 - self.eyeIndex_S 
            
        self.eye = self.eyes[self.eyeIndex]

    def getEye(self):
        return self.eye

    def setEyes(self, eyes):             
        
        
        eyes = "0 " + eyes
        self.eyes = list(map(int, eyes.split(" ")))


dice_1 = Dice()
dice_1.setEyes(input().rstrip())

input_commands = input().rstrip()

for i in range(len(input_commands)):
    
    dice_1.shakeDice(input_commands[i])

print(dice_1.getEye())

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):
number = [int(x) for x in input().split()]







order = input()

for i in range(len(order)):
    number_2 = [number[i] for i in range(len(number))]
    if order[i] == 'S':
        number[0] = number_2[4]
        number[1] = number_2[0]
        number[4] = number_2[5]
        number[5] = number_2[1]
    if order[i] == 'W':
        number[0] = number_2[2]
        number[2] = number_2[5]
        number[3] = number_2[0]
        number[5] = number_2[3]
    if order[i] == 'E':
        number[0] = number_2[3]
        number[2] = number_2[0]
        number[3] = number_2[5]
        number[5] = number_2[2]
    if order[i] == 'N':
        number[0] = number_2[1]
        number[1] = number_2[5]
        number[4] = number_2[0]
        number[5] = number_2[4]
    

print(number[0])

Solution (Python):
class Dice:
    def __init__(self):
        self.faces=[]

    def rotate(self, direction):
        tmp = self.faces.copy()

        if direction =="N":
            self.faces[5-1] = tmp[1-1]
            self.faces[1-1] = tmp[2-1]
            self.faces[2-1] = tmp[6-1]
            self.faces[6-1] = tmp[5-1]
        if direction =="S":
            self.faces[5-1] = tmp[6-1]
            self.faces[1-1] = tmp[5-1]
            self.faces[2-1] = tmp[1-1]
            self.faces[6-1] = tmp[2-1]
        if direction =="W":
            self.faces[4-1] = tmp[1-1]
            self.faces[1-1] = tmp[3-1]
            self.faces[3-1] = tmp[6-1]
            self.faces[6-1] = tmp[4-1]
        if direction =="E":
            self.faces[3-1] = tmp[1-1]
            self.faces[1-1] = tmp[4-1]
            self.faces[4-1] = tmp[6-1]
            self.faces[6-1] = tmp[3-1]
        return 0



d1 = Dice()
d1.faces=[int(x) for x in input().split(" ")]
directions=list(input())
for d in directions:
    d1.rotate(d)
print(d1.faces[0])

Solution (Python):
inp = [i for i in input().split()]
com = input()
for i in range(len(com)):
    if com[i] == "N":
        a = []
        a.append(inp[1])
        a.append(inp[5])
        a.append(inp[2])
        a.append(inp[3])
        a.append(inp[0])
        a.append(inp[4])
        inp = a
    elif com[i] == "S":
        a = []
        a.append(inp[4])
        a.append(inp[0])
        a.append(inp[2])
        a.append(inp[3])
        a.append(inp[5])
        a.append(inp[1])
        inp = a
    elif com[i] == "E":
        a = []
        a.append(inp[3])
        a.append(inp[1])
        a.append(inp[0])
        a.append(inp[5])
        a.append(inp[4])
        a.append(inp[2])
        inp = a
    elif com[i] == "W":
        a = []
        a.append(inp[2])
        a.append(inp[1])
        a.append(inp[5])
        a.append(inp[0])
        a.append(inp[4])
        a.append(inp[3])
        inp = a
print(inp[0])

Solution (Python):

"""
DiceFaces : ?????????????????¢?????°???
    ?????????????????¢?????¶??? : [top, front, right, left, back, bottom]

Rotates : ?????¢????????????
"""


EAST = "E"
WEST = "W"
SOUTH = "S"
NORTH = "N"

TOP = 0
FRONT = 1
RIGHT = 2
LEFT = 3
BACK = 4
BOTTOM = 5

def rotated_dice(DiceFaces, Rotate):
    """
    ????????????????????¢
    """
    if Rotate == EAST:
        
        DiceFaces[TOP], DiceFaces[RIGHT], DiceFaces[LEFT], DiceFaces[BOTTOM] = DiceFaces[LEFT], DiceFaces[TOP], DiceFaces[BOTTOM], DiceFaces[RIGHT]
    elif Rotate == WEST:
        
        DiceFaces[TOP], DiceFaces[RIGHT], DiceFaces[LEFT], DiceFaces[BOTTOM] = DiceFaces[RIGHT], DiceFaces[BOTTOM], DiceFaces[TOP], DiceFaces[LEFT]
    elif Rotate == SOUTH:
        
        DiceFaces[TOP], DiceFaces[FRONT], DiceFaces[BACK], DiceFaces[BOTTOM] = DiceFaces[BACK], DiceFaces[TOP], DiceFaces[BOTTOM], DiceFaces[FRONT]
    elif Rotate == NORTH:
        
        DiceFaces[TOP], DiceFaces[FRONT], DiceFaces[BACK], DiceFaces[BOTTOM] = DiceFaces[FRONT], DiceFaces[BOTTOM], DiceFaces[TOP], DiceFaces[BACK]

    return DiceFaces

if __name__ == "__main__":
    
    DiceFaces = [int(x) for x in input().split(" ")]
    RotatesStirng = input()
    Rotates = [x for x in RotatesStirng]
    for Rotate in Rotates:
        DiceFaces = rotated_dice(DiceFaces, Rotate)

    print(DiceFaces[0])

Solution (Python):
class Dice:
    def __init__(self, usr_input, command):
        self.eyes = list(map(int, usr_input.split()))
        self.pos = {label:eye for label, eye in zip(range(1, 7), self.eyes)}
        self.com = list(command)

    def roll(self):
        for c in self.com:
            self.eyes = [n for n in self.pos.values()]
            if c == 'E':
                self.pos[1] = self.eyes[3]
                self.pos[3] = self.eyes[0]
                self.pos[4] = self.eyes[5]
                self.pos[6] = self.eyes[2]
            elif c == 'N':
                self.pos[1] = self.eyes[1]
                self.pos[2] = self.eyes[5]
                self.pos[5] = self.eyes[0]
                self.pos[6] = self.eyes[4]
            elif c == 'S':
                self.pos[1] = self.eyes[4]
                self.pos[2] = self.eyes[0]
                self.pos[5] = self.eyes[5]
                self.pos[6] = self.eyes[1]
            elif c == 'W':
                self.pos[1] = self.eyes[2]
                self.pos[3] = self.eyes[5]
                self.pos[4] = self.eyes[0]
                self.pos[6] = self.eyes[3]

    def top_print(self):
        print(self.pos.get(1))

if __name__ == '__main__':
    dice1 = Dice(input(), input())
    dice1.roll()
    dice1.top_print()

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

    def upper_num(self):
        return self.nums[0]

dice = Dice(list(map(int, input().split())))
dirs = list(input())
for i in range(len(dirs)):
    dice.rotate(dirs[i])

print(dice.upper_num())

Solution (Python):


import sys
import os
import math


dice = list(map(int, input().split()))
orders = input().strip()
for c in orders:
    copy = dice[:]
    if c == 'E':
        dice[2] = copy[0]
        dice[5] = copy[2]
        dice[3] = copy[5]
        dice[0] = copy[3]
    elif c == 'N':
        dice[0] = copy[1]
        dice[4] = copy[0]
        dice[5] = copy[4]
        dice[1] = copy[5]
        pass
    elif c == 'S':
        dice[1] = copy[0]
        dice[0] = copy[4]
        dice[4] = copy[5]
        dice[5] = copy[1]
    elif c == 'W':
        dice[0] = copy[2]
        dice[2] = copy[5]
        dice[5] = copy[3]
        dice[3] = copy[0]
print(dice[0])

Solution (Python):
dice = [1,2,3,4,5,6]
number = list(map(int,input().split()))
direction = str(input())

rotate_n =[2,6,3,4,1,5]
rotate_s =[5,1,3,4,6,2]
rotate_e =[4,2,1,6,5,3]
rotate_w =[3,2,6,1,5,4]

for i in direction:
    result = []
    if i == "N":
        for j in range(6):
            dice[j] = rotate_n[j]
    elif i == "S":
        for j in range(6):
            dice[j] = rotate_s[j]
    elif i == "E":
        for j in range(6):
            dice[j] = rotate_e[j]
    else:
        for j in range(6):
            dice[j] = rotate_w[j]
    for k in dice:
        result.append(number[k-1])
    number = result

print(number[0])

Solution (Python):
u,s,e,w,n,b = list(map(int, input().split()))
rolls = input()

for roll in rolls:
    if roll == 'N':
        n,u,e,w,b,s = u,s,e,w,n,b
    elif roll == 'S':
        s,b,e,w,u,n = u,s,e,w,n,b
    elif roll == 'E':
        e,s,b,u,n,w = u,s,e,w,n,b
    elif roll == 'W':
        w,s,u,b,n,e = u,s,e,w,n,b
    else:
        print('Error')
        raise(-1)

print(u)

Solution (Python):
class Dice:
    """????????????????????????"""
    def __init__(self, s):
        self.s1 = s[0]
        self.s2 = s[1]
        self.s3 = s[2]
        self.s4 = s[3]
        self.s5 = s[4]
        self.s6 = s[5]

    def roll(self, direction):          
        temp = self.s1
        if direction == "E":
            self.s1 = self.s4
            self.s4 = self.s6
            self.s6 = self.s3
            self.s3 = temp
        elif direction == "N":
            self.s1 = self.s2
            self.s2 = self.s6
            self.s6 = self.s5
            self.s5 = temp
        elif direction == "S":
            self.s1 = self.s5
            self.s5 = self.s6
            self.s6 = self.s2
            self.s2 = temp
        elif direction == "W":
            self.s1 = self.s3
            self.s3 = self.s6
            self.s6 = self.s4
            self.s4 = temp

s = list(map(int, input().split()))
dice1 = Dice(s)
command = input()

for i in range(len(command)):
    dice1.roll(command[i])

print(dice1.s1)

Solution (Python):
''' This is AOJ Practice. '''


class Dice:
    ''' Dice
    6??¢????????????????????¨??????????????§??????
    NWSE?????????????????????????????¨????????\?????????
    ?????????Top??????????????????????????¢??????????????????????????¨????????\?????????
    '''

    def __init__(self):
        ''' ????????????????????? '''
        self.axis1 = list()
        self.axis2 = list()
        self.init()

    def control_n(self):
        ''' ????????¢?????? '''
        bottom_value = self.axis2[3]
        top_value = self.axis2[1]
        self.axis2 = [bottom_value, self.axis2[0], top_value, self.axis2[2], bottom_value]
        self.axis1 = [bottom_value, self.axis1[1], top_value, self.axis1[3], bottom_value]

    def control_w(self):
        ''' ????????¢?????? '''
        bottom_value = self.axis1[1]
        top_value = self.axis1[3]
        self.axis2 = [bottom_value, self.axis2[1], top_value, self.axis2[3], bottom_value]
        self.axis1 = [bottom_value, self.axis1[2], top_value, self.axis1[4], bottom_value]

    def control_s(self):
        ''' ????????¢?????? '''
        bottom_value = self.axis2[1]
        top_value = self.axis2[3]
        self.axis2 = [bottom_value, self.axis2[2], top_value, self.axis2[4], bottom_value]
        self.axis1 = [bottom_value, self.axis1[1], top_value, self.axis1[3], bottom_value]

    def control_e(self):
        ''' ????????¢?????? '''
        bottom_value = self.axis1[3]
        top_value = self.axis1[1]
        self.axis2 = [bottom_value, self.axis2[1], top_value, self.axis2[3], bottom_value]
        self.axis1 = [bottom_value, self.axis1[0], top_value, self.axis1[2], bottom_value]

    def top(self):
        ''' ????????¢??????????????? '''
        return self.axis1[2]

    def control(self, word):
        ''' ?????????????????????
        Args
            word    ????????????
                N   ????????¢??????
                W   ????????¢??????
                S   ????????¢??????
                E   ????????¢??????
        '''
        if word == 'N':
            self.control_n()
        elif word == 'W':
            self.control_w()
        elif word == 'S':
            self.control_s()
        elif word == 'E':
            self.control_e()
        else:
            Exception()

    def show(self):
        ''' ?????¨?????±????¨???????????????? '''
        print(self.axis1)
        print(self.axis2)

    def init(self):
        ''' ??????????????? '''
        self.axis1 = [6, 4, 1, 3, 6]
        self.axis2 = [6, 2, 1, 5, 6]

if __name__ == '__main__':
    input_value = input()
    control_value = input()
    dice = Dice()

    for word in list(control_value):
        dice.control(word)

    print(input_value.split(" ")[dice.top()-1])