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(object):
    def __init__(self, listnum):
        self.a = listnum[0]
        self.b = listnum[1]
        self.c = listnum[2]
        self.d = listnum[3]
        self.e = listnum[4]
        self.f = listnum[5]

    def moveS(self):
        listnew =[]
        listnew.append(self.e)
        listnew.append(self.a)
        listnew.append(self.c)
        listnew.append(self.d)
        listnew.append(self.f)
        listnew.append(self.b)
        return Dice(listnew)

    def moveN(self):
        listnew =[]
        listnew.append(self.b)
        listnew.append(self.f)
        listnew.append(self.c)
        listnew.append(self.d)
        listnew.append(self.a)
        listnew.append(self.e)
        return Dice(listnew)

    def moveE(self):
        listnew =[]
        listnew.append(self.d)
        listnew.append(self.b)
        listnew.append(self.a)
        listnew.append(self.f)
        listnew.append(self.e)
        listnew.append(self.c)
        return Dice(listnew)

    def moveW(self):
        listnew =[]
        listnew.append(self.c)
        listnew.append(self.b)
        listnew.append(self.f)
        listnew.append(self.a)
        listnew.append(self.e)
        listnew.append(self.d)
        return Dice(listnew)


No1 = Dice(input().split())
listmove = list(input())
for i in range(len(listmove)):
    if listmove[i] == "S":
        No1 = No1.moveS()
    elif listmove[i] == "N":
        No1 = No1.moveN()
    elif listmove[i] == "E":
        No1 = No1.moveE()
    elif listmove[i] == "W":
        No1 = No1.moveW()

print(No1.a)

Solution (Python):
class Dice():

    def __init__(self, d):
        self.d = d
        self.north = [2, 6, 3, 4, 1, 5]
        self.south = [5, 1, 3, 4, 6, 2]
        self.east = [4, 2, 1, 6, 5, 3]
        self.west = [3, 2, 6, 1, 5, 4]

    def roll(self, direction):
        if direction == 'S':
            self.d = [ self.d[self.south[i]-1] for i in range(6) ]
        elif direction == 'N':
            self.d = [ self.d[self.north[i]-1] for i in range(6) ]
        elif direction == 'E':
            self.d = [ self.d[self.east[i]-1] for i in range(6) ]
        elif direction == 'W':
            self.d = [ self.d[self.west[i]-1] for i in range(6) ]

    def getDice(self):
        return self.d


s = [ int(s) for s in input().split() ]
command = input().strip()

dice = Dice(s)
for c in command:
    dice.roll(c)

r = dice.getDice()
print(r[0])

Solution (Python):
dice = list(map(int, input().split()))

s = str(input())
n = len(s)

dicel = [[0 for i in range(6)] for j in range(n+1)]

for i in range(6):
  dicel[0][i] = dice[i]

for j in range(n):
  if s[j] == "N":
    dicel[j+1][0] = dicel[j][1]
    dicel[j+1][1] = dicel[j][5]
    dicel[j+1][5] = dicel[j][4]
    dicel[j+1][4] = dicel[j][0]
    dicel[j+1][2] = dicel[j][2]
    dicel[j+1][3] = dicel[j][3]
  elif s[j] == "E":
    dicel[j+1][0] = dicel[j][3]
    dicel[j+1][3] = dicel[j][5]
    dicel[j+1][5] = dicel[j][2]
    dicel[j+1][2] = dicel[j][0]
    dicel[j+1][1] = dicel[j][1]
    dicel[j+1][4] = dicel[j][4]
  elif s[j] == "S":
    dicel[j+1][0] = dicel[j][4]
    dicel[j+1][4] = dicel[j][5]
    dicel[j+1][5] = dicel[j][1]
    dicel[j+1][1] = dicel[j][0]
    dicel[j+1][2] = dicel[j][2]
    dicel[j+1][3] = dicel[j][3]
  else:
    dicel[j+1][0] = dicel[j][2]
    dicel[j+1][2] = dicel[j][5]
    dicel[j+1][5] = dicel[j][3]
    dicel[j+1][3] = dicel[j][0]
    dicel[j+1][1] = dicel[j][1]
    dicel[j+1][4] = dicel[j][4]

print(dicel[n][0])

Solution (Python):
import sys

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

    def rotate_front(self):
        t,b,f,r=self.top,self.bottom,self.front,self.rear
        self.top=r
        self.bottom=f
        self.front=t
        self.rear=b

    def rotate_rear(self):
        t,b,f,r=self.top,self.bottom,self.front,self.rear
        self.top=f
        self.bottom=r
        self.front=b
        self.rear=t

    def rotate_right(self):
        t,b,r,l=self.top,self.bottom,self.right,self.left
        self.top=l
        self.bottom=r
        self.right=t
        self.left=b

    def rotate_left(self):
        t,b,r,l=self.top,self.bottom,self.right,self.left
        self.top=r
        self.bottom=l
        self.right=b
        self.left=t

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    top,front,right,left,rear,bottom=map(int, input().split())
    d=Dice(top,bottom,front,rear,right,left)
    s=input()
    for c in s:
        if c=="N":d.rotate_rear()
        if c=="S":d.rotate_front()
        if c=="E":d.rotate_right()
        if c=="W":d.rotate_left()
    print(d.top)

main()

Solution (Python):
n = list(map(int,input().split()))
j = list(input())

for i in range(len(j)):
    if j[i] == 'E':
        n[0], n[3], n[5], n[2] = n[3], n[5], n[2], n[0]

    elif j[i] == 'W':
        n[0], n[2], n[5], n[3] = n[2], n[5], n[3], n[0]

    elif j[i] == 'S':
        n[0], n[4], n[5], n[1] = n[4], n[5], n[1], n[0]

    else:
        n[0], n[1], n[5], n[4]  = n[1], n[5], n[4], n[0]

print(n[0])

Solution (Python):
class Dice():
    def __init__(self, arr):
        self.top = arr[0]
        self.front = arr[1]
        self.right = arr[2]
        self.left = arr[3]
        self.back = arr[4]
        self.bottom = arr[5]
        
    def rotate(self, direction):
        if direction == "N":
            self.back, self.top, self.front, self.bottom = \
            self.top, self.front, self.bottom, self.back
        elif direction == "S":
            self.front, self.bottom, self.back, self.top = \
            self.top, self.front, self.bottom, self.back
        elif direction == "E":
            self.right, self.bottom, self.left, self.top = \
            self.top, self.right, self.bottom, self.left
        elif direction == "W":
            self.left, self.bottom, self.right, self.top = \
            self.top, self.left, self.bottom, self.right
        
            
dice = Dice(input().split())

direction_list = list(input())

for direction in direction_list:
    dice.rotate(direction)

print(dice.top)

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

Solution (Python):
arr=input().split()
x=input()
for i in x:
    if i=='W':
        arr=[arr[k-1] for k in [3,2,6,1,5,4]]
    if i=='E':
        arr=[arr[k-1] for k in [4,2,1,6,5,3]]
    if i=='N':
        arr=[arr[k-1] for k in [2,6,3,4,1,5]]
    if i=='S':
        arr=[arr[k-1] for k in [5,1,3,4,6,2]]
print(arr[0])

Solution (Python):
class Dice:
    def __init__(self, U, S, E, W, N, D):
        self.u, self.d = U, D
        self.e, self.w = E, W
        self.s, self.n = S, N
    
    def roll(self, commmand):
        if command == 'E':
            self.e, self.u, self.w, self.d = self.u, self.w, self.d, self.e
        elif command == 'W':
            self.e, self.u, self.w, self.d = self.d, self.e, self.u, self.w
        elif command == 'S':
            self.s, self.u, self.n, self.d = self.u, self.n, self.d, self.s
        else:
            self.s, self.u, self.n, self.d = self.d, self.s, self.u, self.n

U, S, E, W, N, D = [int(i) for i in input().split()]
commands = input()
dice1 = Dice(U, S, E, W, N, D)
for command in commands:
    dice1.roll(command)
print(dice1.u)

Solution (Python):
class Dice:
    def __init__(self, label):
        self.label = label
    
    def rotateS(self):
        """[1, 2, 6, 5] -> [5, 1, 2, 6]"""
        t = self.label[1]
        self.label[1] = self.label[5]
        self.label[5] = self.label[6]
        self.label[6] = self.label[2]
        self.label[2] = t

    def rotateN(self):
        t = self.label[1]
        self.label[1] = self.label[2]
        self.label[2] = self.label[6]
        self.label[6] = self.label[5]
        self.label[5] = t
    
    def rotateW(self):
        t = self.label[1]
        self.label[1] = self.label[3]
        self.label[3] = self.label[6]
        self.label[6] = self.label[4]
        self.label[4] = t
    
    def rotateE(self):
        t = self.label[1]
        self.label[1] = self.label[4]
        self.label[4] = self.label[6]
        self.label[6] = self.label[3]
        self.label[3] = t

label = []
label.append(None)
label[1:] = map(int,input().split())
dice = Dice(label)


cmd = input()
for _ in cmd:
    if (_ == 'S'):
        dice.rotateS()
    elif (_ == 'N'):
        dice.rotateN()
    elif (_ == 'W'):
        dice.rotateW()
    elif (_ == 'E'):
        dice.rotateE()
print(dice.label[1])

Solution (Python):
D = [
    (1, 5, 2, 3, 0, 4), 
    (3, 1, 0, 5, 4, 2), 
    (4, 0, 2, 3, 5, 1), 
    (2, 1, 5, 0, 4, 3), 
]
C = 'NESW'

*L, = map(int, input().split())
for c in input():
    L[:] = (L[e] for e in D[C.index(c)])
print(L[0])

Solution (Python):
class Dice:
    def __init__(self, top, front, right, left, back, bottom):
        self.TOP = top
        self.BOTTOM = bottom
        self.FRONT = front
        self.BACK = back
        self.LEFT = left
        self.RIGHT = right
    
    def move_N(self):
        tmp = self.TOP
        self.TOP = self.FRONT
        self.FRONT = self.BOTTOM
        self.BOTTOM = self.BACK
        self.BACK = tmp

    def move_S(self):
        tmp = self.TOP
        self.TOP = self.BACK
        self.BACK = self.BOTTOM
        self.BOTTOM = self.FRONT
        self.FRONT = tmp
        
    def move_W(self):
        tmp = self.TOP
        self.TOP = self.RIGHT
        self.RIGHT = self.BOTTOM
        self.BOTTOM = self.LEFT
        self.LEFT = tmp

    def move_E(self):
        tmp = self.TOP
        self.TOP = self.LEFT
        self.LEFT = self.BOTTOM
        self.BOTTOM = self.RIGHT
        self.RIGHT = tmp
    
    @property
    def top(self):
        return self.TOP
        
top, front, right, left, back, bottom = map(int,input().split())
dice = Dice(top, front, right, left, back, bottom)
m = input()
for i in range(len(m)):
    if m[i] == "N":
        dice.move_N()
    elif m[i] == "E":
        dice.move_E()
    elif m[i] == "S":
        dice.move_S()
    elif m[i] == "W":
        dice.move_W()
    else:
        raise Exception
print(dice.TOP)

Solution (Python):
class Dice:
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d

    def rot(self,way):

        if way=="W":
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way=="S":
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way=="E":
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c
        else:
            c=self.u
            self.u=self.s
            self.s=self.d
            self.d=self.n
            self.n=c

u,s,e,w,n,d=map(int,input().split())
dice=Dice(u,w,s,e,n,d)
st=input()
for c in st:
    dice.rot(c)
print(dice.u)

Solution (Python):
dice = list(map(int, input().split()))
com = input()
for i in range(len(com)):
    if com[i] == 'E':
        temp = dice[0]
        dice[0] = dice[3]
        dice[3] = dice[5]
        dice[5] = dice[2]
        dice[2] = temp
    elif com[i] == 'N':
        temp = dice[0]
        dice[0] = dice[1]
        dice[1] = dice[5]
        dice[5] = dice[4]
        dice[4] = temp
    elif com[i] == 'S':
        temp = dice[0]
        dice[0] = dice[4]
        dice[4] = dice[5]
        dice[5] = dice[1]
        dice[1] = temp
    else:
        temp = dice[0]
        dice[0] = dice[2]
        dice[2] = dice[5]
        dice[5] = dice[3]
        dice[3] = temp
print(dice[0])

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

    def south_direction(self):
        front = self.top
        bottom = self.front
        back = self.bottom
        top = self.back
        right = self.right
        left = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left

    def north_direction(self):
        back = self.top
        top = self.front
        front = self.bottom
        bottom = self.back
        right = self.right
        left = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left

    def east_direction(self):
        right = self.top
        front = self.front
        left = self.bottom
        back = self.back
        bottom = self.right
        top = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left
        
    def west_direction(self):
        left = self.top
        front = self.front
        right = self.bottom
        back = self.back
        top = self.right
        bottom = self.left
        
        self.top = top
        self.front = front
        self.bottom = bottom
        self.back = back
        self.right = right
        self.left = left
    
    def print_top(self):
        print(self.top)

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

d = Dice(num)
for i in directions:
    if i == "N":
        d.north_direction()
    elif i == "S":
        d.south_direction()
    elif i == "E":
        d.east_direction()
    elif i == "W":
        d.west_direction()

d.print_top()

Solution (Python):
l=list(map(int,input().split()))
s=input()
for i in s:
    if i=="W":
        l[0],l[2],l[5],l[3]=l[2],l[5],l[3],l[0]
    elif i=="E":
        l[0],l[2],l[5],l[3]=l[3],l[0],l[2],l[5]
    elif i=="N":
        l[0],l[1],l[5],l[4]=l[1],l[5],l[4],l[0]
    else:
        l[0],l[1],l[5],l[4]=l[4],l[0],l[1],l[5]
print(l[0])

Solution (Python):
class dice():
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
    
    def setnum(self,s):
        self.number = s

    def kai(self,h):
        tmp = self.number
        if h == 'E':
            self.number = [tmp[3],tmp[1],tmp[0],tmp[5],tmp[4],tmp[2]]
        elif h == 'S':
            self.number = [tmp[4],tmp[0],tmp[2],tmp[3],tmp[5],tmp[1]]
        elif h == 'W':
            self.number = [tmp[2],tmp[1],tmp[5],tmp[0],tmp[4],tmp[3]]
        elif h == 'N':
            self.number = [tmp[1],tmp[5],tmp[2],tmp[3],tmp[0],tmp[4]]

num = list(map(int,input().split()))
kaitenn = input()
dice = dice()
dice.setnum(num)
for i in range(len(kaitenn)):
    dice.kai(kaitenn[i])
print(dice.number[0])

Solution (Python):
N=list(map(int,input().split()))
D=input()
for d in D:
  if d=="E":
    N=[N[3],N[1],N[0],N[5],N[4],N[2]]
  if d=="W":
    N=[N[2],N[1],N[5],N[0],N[4],N[3]]
  if d=="N":
    N=[N[1],N[5],N[2],N[3],N[0],N[4]]
  if d=="S":
    N=[N[4],N[0],N[2],N[3],N[5],N[1]]
print(N[0])

Solution (Python):
class Dice:
    def __init__(self, labels):
        self.surface = {x: labels[x-1] for x in range(1, 6+1)}
    def move_towards(self, direction):
        if direction == 'N':
            self._move(1, 2, 6, 5)
        elif direction == 'S':
            self._move(1, 5, 6, 2)
        elif direction == 'E':
            self._move(1, 4, 6, 3)
        elif direction == 'W':
            self._move(1, 3, 6, 4)
    def get_upper(self):
        return self.surface[1]
    def _move(self, i, j, k, l):
        temp_label = self.surface[i]
        self.surface[i] = self.surface[j]
        self.surface[j] = self.surface[k]
        self.surface[k] = self.surface[l]
        self.surface[l] = temp_label

labels = list(map(int, input().split()))
dice = Dice(labels)
moves = input()
for move in moves:
    dice.move_towards(move)
print(dice.get_upper())

Solution (Python):
dice = list(map(int, input().split()))
directions = input()


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

    def get_top(self):
        for direction in self.directions:
            NS = [0, 1, 5, 4]
            WE = [0, 2, 5, 3]
            copy_dice = self.dice[:]

            if direction == 'N':
                for j in range(4):
                    self.dice[NS[j]] = copy_dice[NS[j-3]]
            elif direction == 'S':
                for j in range(4):
                    self.dice[NS[j]] = copy_dice[NS[j-1]]
            elif direction == 'W':
                for j in range(4):
                    self.dice[WE[j]] = copy_dice[WE[j-3]]
            else:
                for j in range(4):
                    self.dice[WE[j]] = copy_dice[WE[j-1]]

        return self.dice[0]

dice_roll = Dice(dice, directions)

print(dice_roll.get_top())

Solution (Python):
top, back, right, left, front, bottom = [int(i) for i in input().split()]
for i in input():
    if i == "N":
        top, front, bottom, back = back, top, front, bottom
    elif i == "S":
        top, front, bottom, back = front, bottom, back, top
    elif i == "E":
        top, left, bottom, right = left, bottom, right, top
    else:
        top, left, bottom, right = right, top, left, bottom
print(top)

Solution (Python):


nesw = {'N':0, 'E':1, 'S':2, 'W':3}
dirc = ((4, 0, 2, 3, 5, 1), (2, 1, 5, 0, 4, 3),
(1, 5, 2, 3, 0, 4), (3, 1, 0, 5, 4, 2))
dice = [0, 1, 2, 3, 4, 5]
temp = [0 for i in range(6)]

label = list(map(int, input().split()))
order = input()

for i in order:
    for j in range(6):
        temp[dirc[nesw[i]][j]] = dice[j]
    dice = temp[:]
print(label[dice[0]])

Solution (Python):
class Dice:
    def __init__(self, default = [1, 2, 3, 4, 5, 6]):
        self.d = default

    def e(self):
        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[3], self.d[0], self.d[5], self.d[2]

    def w(self):
        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[2], self.d[5], self.d[0], self.d[3]

    def n(self):
        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[1], self.d[5], self.d[0], self.d[4]

    def s(self):
        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[4], self.d[0], self.d[5], self.d[1]

    def top(self):
        return self.d[0]


def main():
    dice = Dice([int(i) for i in input().split()])
    for o in input():
        if o == 'E':
            dice.e()
        elif o == 'W':
            dice.w()
        elif o == 'S':
            dice.s()
        else:
            dice.n()

    print(dice.top())


if __name__ == '__main__':
    main()

Solution (Python):
class Dice:
    
    def __init__(self,l):
        self.f=l
        
    def __str__(self):
        l=self.f
        s=f'[U:{l[0]},S:{l[1]},E:{l[2]},W:{l[3]},N:{l[4]},D:{l[5]}]'
        return(s)
       
    def roll(self,c):
        if c=='N':
            ni=[1,5,2,3,0,4]
        elif c=='S':
            ni=[4,0,2,3,5,1]
        elif c=='E':
            ni=[3,1,0,5,4,2]
        elif c=='W':
            ni=[2,1,5,0,4,3]
        self.f=[self.f[j] for j in ni]
    
    def rotate(self,r):
        if r==+1: 
            ni=[0,3,1,4,2,5]
        elif r==-1: 
            ni=[0,2,4,1,3,5]
        self.f=[self.f[j] for j in ni]

d=Dice(list(map(int,input().split())))
for c in input():
    d.roll(c)
print(d.f[0])

Solution (Python):
class Dice:
    def __init__(self,list):
        self.list = []
        for i in range(6):
            self.list.append(list[i])

    def rotate(self,dir):
        if dir == "N":
            self.list[0], self.list[1], self.list[5], self.list[4] = self.list[1], self.list[5], self.list[4], self.list[0]
        elif dir == "S":
            self.list[0], self.list[4], self.list[5], self.list[1] = self.list[4], self.list[5], self.list[1], self.list[0]
        elif dir == "W":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[2], self.list[0], self.list[3], self.list[5]
        elif dir == "E":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]
        else:
            pass

    def show(self):
        for i in self.list:
            print(i)


l = [ int(x) for x in input().split()]
dice = Dice(l)
str = input()
for i in range(len(str)):
    dice.rotate(str[i])
print(dice.list[0])

Solution (Python):
class Sai():
    def __init__(self, m1, m2, m3, m4, m5, m6):
        self.t = m1
        self.s = m2
        self.e = m3
        self.w = m4
        self.n = m5
        self.b = m6
    def furu(self, arg):
        if arg == 'N':
            tmp = self.s
            self.s = self.b
            self.b = self.n
            self.n = self.t
            self.t = tmp
        elif arg == 'S':
            tmp = self.n
            self.n = self.b
            self.b = self.s
            self.s = self.t
            self.t = tmp
        elif arg == 'W':
            tmp = self.e
            self.e = self.b
            self.b = self.w
            self.w = self.t
            self.t = tmp
        else:
            tmp = self.w
            self.w = self.b
            self.b = self.e
            self.e = self.t
            self.t = tmp

s = list(map(int, input().split()))
c = input()
sai = Sai(s[0], s[1], s[2], s[3], s[4], s[5])
for i in c:
    sai.furu(i)
    
print(sai.t)

Solution (Python):
def dice(u,f,o):
	if u == 1 :
		if f == 2:
			if o == "E":
				u = 4
			if o == "N":
				u = 2
				f = 6
			if o == "S":
				u = 5
				f = 1
			if o == "W":
				u = 3
		elif f == 3:
			if o == "E":
				u = 2
			if o == "N":
				u = 3
				f = 6
			if o == "S":
				u = 4
				f = 1
			if o == "W":
				u = 5
		elif f == 5:
			if o == "E":
				u = 3
			if o == "N":
				u = 5
				f = 6
			if o == "S":
				u = 2
				f = 1
			if o == "W":
				u = 4
		elif f == 4:
			if o == "E":
				u = 5
			if o == "N":
				u = 4
				f = 6
			if o == "S":
				u = 3
				f = 1
			if o == "W":
				u = 2
	elif u == 2 :
		if f == 1:
			if o == "E":
				u = 3
			if o == "N":
				u = 1
				f = 5
			if o == "S":
				u = 6
				f = 2
			if o == "W":
				u = 4
		elif f == 3:
			if o == "E":
				u = 6
			if o == "N":
				u = 3
				f = 5
			if o == "S":
				u = 4
				f = 2
			if o == "W":
				u = 1
		elif f == 4:
			if o == "E":
				u = 1
			if o == "N":
				u = 4
				f = 5
			if o == "S":
				u = 3
				f = 2
			if o == "W":
				u = 6
		elif f == 6:
			if o == "E":
				u = 4
			if o == "N":
				u = 6
				f = 5
			if o == "S":
				u = 1
				f = 2
			if o == "W":
				u = 3
	elif u == 3 :
		if f == 2:
			if o == "E":
				u = 1
			if o == "N":
				u = 2
				f = 4
			if o == "S":
				u = 5
				f = 3
			if o == "W":
				u = 6
		elif f == 1:
			if o == "E":
				u = 5
			if o == "N":
				u = 1
				f = 4
			if o == "S":
				u = 6
				f = 3
			if o == "W":
				u = 2
		elif f == 5:
			if o == "E":
				u = 6
			if o == "N":
				u = 5
				f = 4
			if o == "S":
				u = 2
				f = 3
			if o == "W":
				u = 1
		elif f == 6:
			if o == "E":
				u = 2
			if o == "N":
				u = 6
				f = 4
			if o == "S":
				u = 1
				f = 3
			if o == "W":
				u = 5
	elif u == 4 :
		if f == 1:
			if o == "E":
				u = 2
			if o == "N":
				u = 1
				f = 3
			if o == "S":
				u = 6
				f = 4
			if o == "W":
				u = 5
		elif f == 2:
			if o == "E":
				u = 6
			if o == "N":
				u = 2
				f = 3
			if o == "S":
				u = 5
				f = 4
			if o == "W":
				u = 1
		elif f == 5:
			if o == "E":
				u = 1
			if o == "N":
				u = 5
				f = 3
			if o == "S":
				u = 2
				f = 4
			if o == "W":
				u = 6
		elif f == 6:
			if o == "E":
				u = 5
			if o == "N":
				u = 6
				f = 3
			if o == "S":
				u = 1
				f = 4
			if o == "W":
				u = 2
	elif u == 5 :
		if f == 1:
			if o == "E":
				u = 4
			if o == "N":
				u = 1
				f = 2
			if o == "S":
				u = 6
				f = 5
			if o == "W":
				u = 3
		elif f == 3:
			if o == "E":
				u = 1
			if o == "N":
				u = 3
				f = 2
			if o == "S":
				u = 4
				f = 5
			if o == "W":
				u = 6
		elif f == 4:
			if o == "E":
				u = 6
			if o == "N":
				u = 4
				f = 2
			if o == "S":
				u = 3
				f = 5
			if o == "W":
				u = 1
		elif f == 6:
			if o == "E":
				u = 3
			if o == "N":
				u = 6
				f = 2
			if o == "S":
				u = 1
				f = 5
			if o == "W":
				u = 4
	elif u == 6 :
		if f == 2:
			if o == "E":
				u = 3
			if o == "N":
				u = 2
				f = 1
			if o == "S":
				u = 5
				f = 6
			if o == "W":
				u = 4
		elif f == 3:
			if o == "E":
				u = 5
			if o == "N":
				u = 3
				f = 1
			if o == "S":
				u = 4
				f = 6
			if o == "W":
				u = 2
		elif f == 4:
			if o == "E":
				u = 2
			if o == "N":
				u = 4
				f = 1
			if o == "S":
				u = 3
				f = 6
			if o == "W":
				u = 5
		elif f == 5:
			if o == "E":
				u = 4
			if o == "N":
				u = 5
				f = 1
			if o == "S":
				u = 2
				f = 6
			if o == "W":
				u = 3
	return [u,f]
n = list(map(int,input().split()))
o_list = list(input())
o_length = len(o_list)
u = 1 
f = 2
for i in range(o_length):
	a = dice(u,f,o_list[i])
	u = a[0]
	f = a[1]

print(n[u-1])

Solution (Python):
class Dice:
    val=[]
    def __init__(self, lst):
        self.val.append(lst[0])
        self.val.append(lst[1])
        self.val.append(lst[2])
        self.val.append(lst[3])
        self.val.append(lst[4])
        self.val.append(lst[5])

    def rotate(self,dir):
        if dir=="N":
            tmp=self.val[0]
            self.val[0]=self.val[1]
            self.val[1]=self.val[5]
            self.val[5]=self.val[4]
            self.val[4]=tmp
        if dir=="E":
            tmp=self.val[0]
            self.val[0]=self.val[3]
            self.val[3]=self.val[5]
            self.val[5]=self.val[2]
            self.val[2]=tmp
        if dir=="S":
            tmp=self.val[0]
            self.val[0]=self.val[4]
            self.val[4]=self.val[5]
            self.val[5]=self.val[1]
            self.val[1]=tmp
        if dir=="W":
            tmp=self.val[0]
            self.val[0]=self.val[2]
            self.val[2]=self.val[5]
            self.val[5]=self.val[3]
            self.val[3]=tmp


x = list(map(int,input().split()))
char = list(input())


D = Dice(x)

for word in char:
    D.rotate(word)

print(D.val[0])

Solution (Python):
def test():

	faces = list(map(int,input().split()))
	command_stream = list(input())

	for command in command_stream:

		tmp_face = []
		for face in faces:
			tmp_face.append(face)

		
		if command == 'S':
			faces[0] = tmp_face[4]
			faces[4] = tmp_face[5]
			faces[5] = tmp_face[1]
			faces[1] = tmp_face[0]
		
		elif command == 'N':
			faces[0] = tmp_face[1]
			faces[1] = tmp_face[5]
			faces[5] = tmp_face[4]
			faces[4] = tmp_face[0]
		
		elif command == 'W':
			faces[0] = tmp_face[2]
			faces[2] = tmp_face[5]
			faces[5] = tmp_face[3]
			faces[3] = tmp_face[0]
		
		elif command == 'E':
			faces[0] = tmp_face[3]
			faces[3] = tmp_face[5]
			faces[5] = tmp_face[2]
			faces[2] = tmp_face[0]

	print(faces[0])

if __name__ == "__main__":
	test()

Solution (Python):
class dice:
    def __init__(self, lable):
        self.top, self.front, self.right, self.left, self.rear, self.bottom = label
    
    def roll(self, odr):
        if odr == 'N': self.top, self.front, self.bottom, self.rear = \
            self.front, self.bottom, self.rear, self.top
        elif odr == 'E': self.top, self.left, self.bottom, self.right = \
            self.left, self.bottom, self.right, self.top
        elif odr == 'W': self.top, self.right, self.bottom, self.left = \
            self.right, self.bottom, self.left, self.top
        elif odr == 'S': self.top, self.rear, self.bottom, self.front = \
            self.rear, self.bottom, self.front, self.top
    def print_top(self): print(self.top)
label = list(map(int, input().split()))
odr_list = list(input())
d = dice(label)
for odr in odr_list:
    d.roll(odr)
d.print_top()

Solution (Python):


def west(d):
	tmp=d[4]
	d[4]=d[1]
	d[1]=d[3]
	d[3]=d[6]
	d[6]=tmp

def east(d):
	tmp=d[4]
	d[4]=d[6]
	d[6]=d[3]
	d[3]=d[1]
	d[1]=tmp

def north(d):
	tmp=d[1]
	d[1]=d[2]
	d[2]=d[6]
	d[6]=d[5]
	d[5]=tmp

def south(d):
	tmp=d[1]
	d[1]=d[5]
	d[5]=d[6]
	d[6]=d[2]
	d[2]=tmp

def kaiten(d, op):
	if   op == "W": west(d)
	elif op == "E": east(d)
	elif op == "N": north(d)
	elif op == "S": south(d)
	else          : raise AssertionError()

def dump(d):
	print(" ".join(map(str,d)))

def inputDice():
	return list(map(int,("-1 "+input()).split()))

d=inputDice()
for op in list(input()):
	kaiten(d,op)
print(d[1])

Solution (Python):

import sys
import copy
line = sys.stdin.readline() 
line = line.rstrip('\r\n')
face = line.split()

line = sys.stdin.readline() 
line = line.rstrip('\r\n')

for i in line:
    face_old = copy.deepcopy(face)
    if i == "E":
        face[0] = face_old[3]
        face[1] = face_old[1]
        face[2] = face_old[0]
        face[3] = face_old[5]
        face[4] = face_old[4]
        face[5] = face_old[2]
    elif i == "N":
        face[0] = face_old[1]
        face[1] = face_old[5]
        face[2] = face_old[2]
        face[3] = face_old[3]
        face[4] = face_old[0]
        face[5] = face_old[4]
    elif i == "S":
        face[0] = face_old[4]
        face[1] = face_old[0]
        face[2] = face_old[2]
        face[3] = face_old[3]
        face[4] = face_old[5]
        face[5] = face_old[1]
    else:
        face[0] = face_old[2]
        face[1] = face_old[1]
        face[2] = face_old[5]
        face[3] = face_old[0]
        face[4] = face_old[4]
        face[5] = face_old[3]

print(face[0])

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