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 __init__(s, i):
        s.d1,s.d2,s.d3,s.d4,s.d5,s.d6 = map(int, i)
    
    def W(s):
        tmp = s.d1
        s.d1 = s.d3
        s.d3 = s.d6
        s.d6 = s.d4
        s.d4 = tmp
        
    def E(s):
        tmp = s.d1
        s.d1 = s.d4
        s.d4 = s.d6
        s.d6 = s.d3
        s.d3 = tmp
        
    def N(s):
        tmp = s.d1
        s.d1 = s.d2
        s.d2 = s.d6
        s.d6 = s.d5
        s.d5 = tmp
        
    def S(s):
        tmp = s.d1
        s.d1 = s.d5
        s.d5 = s.d6
        s.d6 = s.d2
        s.d2 = tmp
        
dice1 = dice(input().split())
lst = list(input())
for s in lst:
    eval("dice1." + s)()
print(dice1.d1)

Solution (Python):
class  Dise:
    def __init__(self,top,flont,right,left,back,bottom):
        self.top,self.flont,self.right,self.left,self.back,self.bottom=top,flont,right,left,back,bottom
        
    def rot(self,d):
        if d=='N':
            self.top,self.flont,self.bottom,self.back=self.flont,self.bottom,self.back,self.top
        elif d=='E':
            self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom
        elif d=='S':
                self.top,self.flont,self.bottom,self.back=self.back,self.top,self.flont,self.bottom
        elif d=='W':
            self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top
    
    def gettop(self):
        return self.top

n=list(map(int,input().split()))
dise=Dise(n[0],n[1],n[2],n[3],n[4],n[5])
str=input()
for s in str:
    dise.rot(s)
print(dise.gettop())

Solution (Python):

class Dice():
 East = [ [0,3,5,2,4,0]
		 ,[4,0,1,6,0,3]
		 ,[2,6,0,0,1,5]
		 ,[5,1,0,0,6,2]
		 ,[3,0,6,1,0,4]
		 ,[0,4,2,5,3,0]
		 ]
 def __init__(self,N):
  self.label = N
  self.top = 1
  self.north = 5
 def move(self,ori):
  if ori=='S':
   t = self.top
   self.top = self.north
   self.north = 7-t
  elif ori=='N':
   t = self.top
   self.top = 7-self.north
   self.north = t
  elif ori=='E':
   east = self.East[self.north-1][self.top-1]
   self.top = 7-east
  elif ori=='W':
   east = self.East[self.north-1][self.top-1]
   self.top = east
 def gettop(self):
  return( self.label[self.top-1] )

label = list(map(int, input().split() ))
D = Dice(label)
command = input()
for ci in range(len(command)):
 D.move(command[ci])
 
print(D.gettop())

Solution (Python):

def dice_rotation(list, direction):
    if direction == "S":
        list[0],list[1],list[4],list[5] = list[4],list[0],list[5],list[1]
    elif direction == "E":
        list[0],list[2],list[3],list[5] = list[3],list[0],list[5],list[2]
    elif direction == "N":
        list[0],list[1],list[4],list[5] = list[1],list[5],list[0],list[4]
    elif direction == "W":
        list[0],list[2],list[3],list[5] = list[2],list[5],list[0],list[3]
    return list


input_number = list(map(int, input().split()))
input_order = input()


for order in input_order:
    input_number = dice_rotation(input_number, order)


print(input_number[0])

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

    def N(self):
        self.top, self.front, self.bottom, self.back = self.front, self.bottom, self.back, self.top

    def E(self):
        self.top, self.right, self.bottom, self.left = self.left, self.top, self.right, self.bottom

    def S(self):
        self.top, self.front, self.bottom, self.back = self.back, self.top, self.front, self.bottom

    def W(self):
        self.top, self.right, self.bottom, self.left = self.right, self.bottom, self.left, self.top

*x,=map(int,input().split())
dice=Dice(x)
A=input()
for a in A:
    if a=='N':
        dice.N()
    if a=='E':
        dice.E()
    if a=='S':
        dice.S()
    if a=='W':
        dice.W()
print(dice.top)

Solution (Python):
import math

class Dice():
    top   = 0 
    left  = 0 
    right = 0 
    front = 0 
    back  = 0 
    below = 0 

    DEBUG_MODE = False
    def __init__(self,lst,dbg = False):
        if len(lst) == 6:
            self.top   = lst[0]
            self.front = lst[1]
            self.right = lst[2]
            self.left  = lst[3]
            self.back  = lst[4]
            self.below = lst[5]

        if dbg == True:
            self.DEBUG_MODE = True
        else:
            self.DEBUG_MODE = False
    
    def rotate(self,string):
        
        for ch in string:
            if   ch == 'W':
                self.left,self.top,self.right,self.below = self.top,self.right,self.below,self.left

            elif ch == 'E':
                self.left,self.top,self.right,self.below = self.below,self.left,self.top,self.right

            elif ch == 'S':
                self.top,self.back,self.below,self.front = self.back,self.below,self.front,self.top

            elif ch == 'N':
                self.top,self.back,self.below,self.front = self.front,self.top,self.back,self.below
            
            
            if self.DEBUG_MODE:
                self.dbg_PRINT_ALL_VALUE()

        
    def get_topvalue(self):
        return self.top
    
    def dbg_PRINT_ALL_VALUE(self):
        print(f"        bk:{self.back:04} ")
        print(f"le:{self.left:04} tp:{self.top:04} ri:{self.right:04} be:{self.below:04}")
        print(f"        fr:{self.front:04} ")

lst = list(map(int,input().split()))

dice = Dice(lst)
dice.rotate(input())
print(dice.get_topvalue())

Solution (Python):
label = list(map(int,input().split()))
direction = list(str(input()))
D=list(range(6))
Dtemp=[0,0,0,0,0,0]
for i in range(len(direction)):
    if direction[i] == 'N':
        Dtemp[0] = D[1]
        Dtemp[1] = D[5]
        Dtemp[2] = D[2]
        Dtemp[3] = D[3]
        Dtemp[4] = D[0]
        Dtemp[5] = D[4]
    elif direction[i] == 'E':
        Dtemp[0] = D[3]
        Dtemp[1] = D[1]
        Dtemp[2] = D[0]
        Dtemp[3] = D[5]
        Dtemp[4] = D[4]
        Dtemp[5] = D[2]
    elif direction[i] =='S':
        Dtemp[0] = D[4]
        Dtemp[1] = D[0]
        Dtemp[2] = D[2]
        Dtemp[3] = D[3]
        Dtemp[4] = D[5]
        Dtemp[5] = D[1]
    elif direction[i] =='W':
        Dtemp[0] = D[2]
        Dtemp[1] = D[1]
        Dtemp[2] = D[5]
        Dtemp[3] = D[0]
        Dtemp[4] = D[4]
        Dtemp[5] = D[3]
    D=Dtemp
    Dtemp=[0,0,0,0,0,0]
print(label[D[0]])

Solution (Python):
class Dice_roll:
    face_num = []
    def move(self,way):
        if way == "N":
            self.face_num = [self.face_num[1],self.face_num[5],self.face_num[2],self.face_num[3],self.face_num[0],self.face_num[4]]
            
        elif way == "S":
            self.face_num = [self.face_num[4],self.face_num[0],self.face_num[2],self.face_num[3],self.face_num[5],self.face_num[1]]
            
        elif way == "W":
            self.face_num = [self.face_num[2],self.face_num[1],self.face_num[5],self.face_num[0],self.face_num[4],self.face_num[3]]
            
        elif way == "E":
            self.face_num = [self.face_num[3],self.face_num[1],self.face_num[0],self.face_num[5],self.face_num[4],self.face_num[2]]        

dice = Dice_roll()
               
dice.face_num = list(map(int,input().split()))

direction = str(input())
  
for i in direction:
    dice.move(i)

print(dice.face_num[0])

Solution (Python):
class Dice:
    def __init__(self, dice):
        self.dice = dice
        self.rule={'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)}
    def output(self):
        return self.dice
    def move(self, direction):
        self.dice = [self.dice[y] for y in self.rule[_]]
        return self.dice

dice = Dice([int(x) for x in input().split()])
for _ in input(): dice.move(_)
print(dice.output()[0])

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

l1 = [1, 4, 6, 3]
l2 = [l1[0], 2, l1[2], 5]

for char in s:
    if char == "W":
        l1 = [l1[3], l1[0], l1[1], l1[2]]
        l2[0] = l1[0]
        l2[2] = l1[2]
    elif char == "E":
        l1 = [l1[1], l1[2], l1[3], l1[0]]
        l2[0] = l1[0]
        l2[2] = l1[2]
    elif char == "N":
        l2 = [l2[1], l2[2], l2[3], l2[0]]
        l1[0] = l2[0]
        l1[2] = l2[2]
    elif char == "S":
        l2 = [l2[3], l2[0], l2[1], l2[2]]
        l1[0] = l2[0]
        l1[2] = l2[2]

print(nums[l1[0] - 1])

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

lis = [1,2,3,4,5,6]

def dicing(lis, inst):
    if inst == 'N':
        ans_lis = [lis[1],lis[5],lis[2],lis[3],lis[0],lis[4]]
    if inst == 'W':
        ans_lis = [lis[2],lis[1],lis[5],lis[0],lis[4],lis[3]]
    if inst == 'S':
        ans_lis = [lis[4],lis[0],lis[2],lis[3],lis[5],lis[1]]
    if inst == 'E':
        ans_lis = [lis[3],lis[1],lis[0],lis[5],lis[4],lis[2]]
    
    return(ans_lis)

inst = list(input())
N = len(inst)

for i in range(N):
    lis = dicing(lis, inst[i])

print(dice[(lis[0]-1)])

Solution (Python):

class Dice:
    def __init__(self, default_surface):
        self.dice = default_surface  
        self.rotation_count = 0

    def move(self, new_face: int) -> None:
        for i, face in enumerate(self.dice):  
            if face != new_face:
                continue
            elif i == 1:
                self.roll_up(), self.roll_up()
            elif i == 2:
                self.roll_left()
            elif i == 3:
                self.roll_right()
            elif i == 4:
                self.roll_up()
            elif i == 5:
                self.roll_down()

    def roll_left(self) -> None:
        self.dice[0], self.dice[3], self.dice[1], self.dice[2] = self.dice[2], self.dice[0], self.dice[3], self.dice[1]
        self.rotation_count += 1

    def roll_right(self) -> None:
        self.dice[0], self.dice[2], self.dice[1], self.dice[3] = self.dice[3], self.dice[0], self.dice[2], self.dice[1]
        self.rotation_count += 1

    def roll_up(self) -> None:
        self.dice[0], self.dice[5], self.dice[1], self.dice[4] = self.dice[4], self.dice[0], self.dice[5], self.dice[1]
        self.rotation_count += 1

    def roll_down(self) -> None:
        self.dice[0], self.dice[4], self.dice[1], self.dice[5] = self.dice[5], self.dice[0], self.dice[4], self.dice[1]
        self.rotation_count += 1

    def roll_clockwise(self) -> None:
        self.dice[2], self.dice[4], self.dice[3], self.dice[5] = self.dice[5], self.dice[2], self.dice[4], self.dice[3]
        self.rotation_count += 1

    def roll_counterclockwise(self) -> None:
        self.dice[2], self.dice[5], self.dice[3], self.dice[4] = self.dice[4], self.dice[2], self.dice[5], self.dice[3]
        self.rotation_count += 1


def main():
    T, L, U, D, R, B = map(int, input().split())
    order = input().rstrip()
    dice = Dice([T, B, U, D, L, R])
    for c in order:
        if c == "E":
            dice.roll_right()
        if c == "W":
            dice.roll_left()
        if c == "N":
            dice.roll_up()
        if c == "S":
            dice.roll_down()
    print(dice.dice[0])


if __name__ == "__main__":
    main()

Solution (Python):

class Dice:
    
    def __init__(self, dice_surface_str):
        dice_surface_list = [int(i) for i in dice_surface_str.split()]
        self.dice_surface = dice_surface_list

    
    def return_surface(self, return_surface_index=""):
        if return_surface_index == "":
            return self.dice_surface
        else:
            return self.dice_surface[return_surface_index]

    
    def print_surface(self, print_surface_index=""):
        print(self.return_surface(print_surface_index))

    
    def dice_roll_transition(self, direction):
        roll_dict = {"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]}
        if direction == "N" or direction == "E" or direction == "W" or direction == "S":
            roll_list = roll_dict[direction]
        
        
        
        
        
        
        
        
        else:
            print("命令が不正です")
            print(f"不正な入力データ : {direction}")
        return roll_list

    
    def dice_roll(self, order):
        for o in order:
            surface_tmp = self.return_surface()
            surface_after_roll = []
            surface_after_roll = [surface_tmp[d] for d in self.dice_roll_transition(o)]
            self.dice_surface = surface_after_roll



dc = input()

hoge = Dice(dc)

inp_order = input()

hoge.dice_roll(inp_order)

hoge.print_surface(0)

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

Solution (Python):
class Dice:
    def __init__(self, e1, e2, e3, e4, e5, e6):
        self.eye1 = e1
        self.eye2 = e2
        self.eye3 = e3
        self.eye4 = e4
        self.eye5 = e5
        self.eye6 = e6
    
    def roll_e(self):
        tmp_eye   = self.eye3
        self.eye3 = self.eye1
        self.eye1 = self.eye4
        self.eye4 = self.eye6
        self.eye6 = tmp_eye
    
    def roll_n(self):
        tmp_eye   = self.eye5
        self.eye5 = self.eye1
        self.eye1 = self.eye2
        self.eye2 = self.eye6
        self.eye6 = tmp_eye
    
    def roll_s(self):
        tmp_eye   = self.eye2
        self.eye2 = self.eye1
        self.eye1 = self.eye5
        self.eye5 = self.eye6
        self.eye6 = tmp_eye
    
    def roll_w(self):
        tmp_eye   = self.eye4
        self.eye4 = self.eye1
        self.eye1 = self.eye3
        self.eye3 = self.eye6
        self.eye6 = tmp_eye
    
    def get_eye1(self):
        return self.eye1

e1, e2, e3, e4 ,e5, e6 = map(int,input().split())
dice1 = Dice(e1, e2, e3, e4 ,e5, e6)
roll = input()
for i in range(len(roll)):
    if roll[i] == 'E':
        dice1.roll_e()
    if roll[i] == 'N':
        dice1.roll_n()
    if roll[i] == 'S':
        dice1.roll_s()
    if roll[i] == 'W':
        dice1.roll_w()
print(dice1.get_eye1())

Solution (Python):
from collections import deque

class Dice():
    def __init__(self, sequence):
        self.v = deque([seq[5], seq[4], seq[0], seq[1]])
        self.h = deque([seq[3], seq[0], seq[2], seq[5]])

    def lotate(self, direction):

        if   direction == "E":
            self.h.rotate()
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "W":
            self.h.rotate(-1)
            self.v[2] = self.h[1]
            self.v[0] = self.h[3]

        elif direction == "N":
            self.v.rotate(-1)
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        elif direction == "S":
            self.v.rotate()
            self.h[1] = self.v[2]
            self.h[3] = self.v[0]

        else:
            pass

    def disp_top_face(self):
        return self.v[2]

    def disp_front_face(self):
        return self.v[3]

    def disp_back_face(self):
        return self.v[1]

    def disp_right_face(self):
        return self.h[2]

    def disp_left_face(self):
        return self.h[0]

    def disp_bottom_face(self):
        return self.h[3]

if __name__ == "__main__":

    param = input().split(" ")
    seq = [int(a) for a in param]

    com = input()

    d = Dice(seq)
    for dir in com:
        d.lotate(dir)

    print(d.disp_top_face())

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

    def roll(self, str_direction):
        if str_direction == 'E':
            self.__rot_to_east()
        elif str_direction == 'W':
            self.__rot_to_west()
        elif str_direction == 'S':
            self.__rot_to_south()
        elif str_direction == 'N':
            self.__rot_to_north()

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

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

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

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

dice_labels = input().split(' ')
rot_operations = list(input())
dice = Dice(dice_labels)

for roll_direction in rot_operations:
    dice.roll(roll_direction)

print(dice.top)

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):
def lotate(dic, dire):
    if dire == 'N':
        x,y,z,w = dic['up'], dic['back'], dic['bottom'], dic['front']
        dic['back'], dic['bottom'], dic['front'], dic['up'] = x,y,z,w
    elif dire == 'S':
        x, y, z, w = dic['up'], dic['back'], dic['bottom'], dic['front']
        dic['front'], dic['up'], dic['back'], dic['bottom'] = x, y, z, w
    elif dire == 'W':
        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
        dic['left'], dic['bottom'], dic['right'], dic['up'] = x, y, z, w
    elif dire == 'E':
        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']
        dic['right'], dic['up'], dic['left'], dic['bottom'] = x, y, z, w
    return dic


a,b,c,d,e,f = map(int, input().split())
d = {'up':a, 'front':b, 'right':c, 'left':d, 'back':e, 'bottom':f}
s = input()
for i in s:
    d = lotate(d, i)
print(d['up'])

Solution (Python):
class Dice(object):

    def __init__(self, *args):
        self.faces = [None]
        self.faces.extend(args)
        self.top = self.faces[1]
        self.up = self.faces[5]
        self.down = self.faces[2]
        self.left = self.faces[4]
        self.right = self.faces[3]

    def roll(self, direction):
        if direction == "N":
            self.top, self.up, self.down = self.down, self.top, self.faces[7 - self.faces.index(self.top)]
        elif direction == "S":
            self.top, self.up, self.down = self.up, self.faces[7 - self.faces.index(self.top)], self.top
        elif direction == "W":
            self.top, self.left, self.right = self.right, self.top, self.faces[7 - self.faces.index(self.top)]
        elif direction == "E":
            self.top, self.left, self.right = self.left, self.faces[7 - self.faces.index(self.top)], self.top
        else:
            raise ValueError("{} is not valid direction.".format(direction))

    def get_top(self):
        return self.top


f = [int(i) for i in input().split()]
dice = Dice(*f)
for d in input():
    dice.roll(d)

print(dice.get_top())

Solution (Python):
class Dice():
    def __init__(self, up, back, right, left, front, down):
        self.up = up
        self.down = down
        self.right = right
        self.left = left
        self.front = front
        self.back = back
    
    def north(self):
        temp = self.up
        self.up = self.back
        self.back = self.down
        self.down = self.front
        self.front = temp
    
    def south(self):
        temp = self.up
        self.up = self.front
        self.front = self.down
        self.down = self.back
        self.back = temp
        
    def east(self):
        temp = self.up
        self.up = self.left
        self.left = self.down
        self.down = self.right
        self.right = temp
    
    def west(self):
        temp = self.up
        self.up = self.right
        self.right = self.down
        self.down = self.left
        self.left = temp
        
    def operate(self, op):
        if op == "N":
            self.north()
        elif op == "S":
            self.south()
        elif op == "E":
            self.east()
        elif op == "W":
            self.west()
        
        
up, back, right, left, front, down = map(int, input().split())
dice = Dice(up, back, right, left, front, down)

op_str = input()

for op in op_str:
    dice.operate(op)

print(dice.up)

Solution (Python):
from collections import deque


class Dice:
    def __init__(self, *surface):
        self._surface = surface

        self._mapping_sn = deque([0, 1, 5, 4], maxlen=4)
        self._mapping_we = deque([0, 3, 5, 2], maxlen=4)

    @property
    def top(self):
        return self._surface[self._mapping_sn[0]]

    def roll_s(self):
        self._mapping_sn.rotate(1)
        self._mapping_we[0] = self._mapping_sn[0]
        self._mapping_we[2] = self._mapping_sn[2]

    def roll_n(self):
        self._mapping_sn.rotate(-1)
        self._mapping_we[0] = self._mapping_sn[0]
        self._mapping_we[2] = self._mapping_sn[2]

    def roll_w(self):
        self._mapping_we.rotate(1)
        self._mapping_sn[0] = self._mapping_we[0]
        self._mapping_sn[2] = self._mapping_we[2]

    def roll_e(self):
        self._mapping_we.rotate(-1)
        self._mapping_sn[0] = self._mapping_we[0]
        self._mapping_sn[2] = self._mapping_we[2]


if __name__ == '__main__':
    surface = map(int, input().split())
    d = Dice(*surface)
    commands = list(input().lower())
    for c in commands:
        getattr(d, 'roll_' + c)()
    print(d.top)

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

def East(a,b,c,d,e,f):
    return [d, b, a, f, e, c]

def West(a,b,c,d,e,f):
    return [c, b, f, a, e, d]

def South(a,b,c,d,e,f):
    return [e, a, c, d, f, b]

def North(a,b,c,d,e,f):
    return [b, f, c, d, a, e]



a=input()

for idx in range(0, len(a)):
    if a[idx]=="E":
        change=East(*change)
    elif a[idx]=="W":
        change=West(*change)
    elif a[idx]=="S":
        change=South(*change)
    elif a[idx]=="N":
        change=North(*change)
print(change[0])

Solution (Python):
class Dice():
    top=1
    n=2
    e=4
    w=3
    s=5
    dice=[1,2,3,4,5,6]
    def __init__(self,num):
        self.dice=num

    def roll(self,direction):
        if(direction=="N"):
            self.top,self.n,self.s = self.n,7-self.top,self.top
        elif(direction=="E"):
            self.top,self.e,self.w = self.e,7-self.top,self.top
        elif(direction=="W"):
            self.top,self.e,self.w = self.w,self.top,7-self.top
        elif(direction=="S"):
            self.top,self.n,self.s = self.s,self.top,7-self.top


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

print(dice.dice[dice.top-1])

Solution (Python):
a=[]
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]


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



n = input()
b=[0]*6
for i in range(len(n)):
    for j in range(6):b[j] = a[j]
    
    if n[i] == "N":
        for j in range(6):
            a[j] = b[N[j]]    
        
    elif n[i] == "S":
        for j in range(6):
            a[j] = b[S[j]]
        
    elif n[i] == "W":
        for j in range(6):
            a[j] = b[W[j]]
        
    elif n[i] == "E":
        for j in range(6):
            a[j] = b[E[j]]

print(a[0])

Solution (Python):
class Dice:
    def __init__(self,u,s,e,w,n,d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d
        self.dir = {'W':0,'S':1,'E':2,'N':3}
    
    def rot(self,way):
        if isinstance(way,str):
            way = self.dir[way]
        
        if way == 0:
            c = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = c
        elif way == 1:
            c = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = c
        elif way == 2:
            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,s,e,w,n,d)
direct = input()

for d in direct:
    dice.rot(d)

print(dice.u)

Solution (Python):
s = list(map(int, input().split()))
dl = input()
stmp = [0] * 6

dr = {"N": [1, 5, 2, 3, 0, 4],
      "W": [2, 1, 5, 0, 4, 3],
      "S": [4, 0, 2, 3, 5, 1],
      "E": [3, 1, 0, 5, 4, 2]}
for d in dl:
    drs = dr[d]
    for i in range(6):
        stmp[i] = s[drs[i]]
    s = list(stmp)
    
print(s[0])

Solution (Python):
face = [0]*6
class Dice():

    def __init__(self):
        self.one = inp[0]
        self.two = inp[1]
        self.three = inp[2]
        self.four = inp[3]
        self.five = inp[4]
        self.six = inp[5]

    def setnumbers(self, n0, n1, n2, n3, n4, n5):
        self.one = n0
        self.two = n1
        self.three = n2
        self.four = n3
        self.five = n4
        self.six = n5


    def spin(self, command):
        face[0] = self.one
        face[1] = self.two
        face[2] = self.three
        face[3] = self.four
        face[4] = self.five
        face[5] = self.six
        if command == 'S':
            self.setnumbers(face[4], face[0], face[2], face[3], face[5], face[1])
            
        elif command == 'N':
            self.setnumbers(face[1], face[5], face[2], face[3], face[0], face[4])
            
        elif command == 'E':
            self.setnumbers(face[3], face[1], face[0], face[5], face[4], face[2])
            
        elif command == 'W':
            self.setnumbers(face[2], face[1], face[5], face[0], face[4], face[3])
            

inp = list(map(int, input().split()))
command = list(input())

dice = Dice()

dice.setnumbers(inp[0], inp[1], inp[2], inp[3], inp[4], inp[5])
face = inp
for i in range(len(command)):
    dice.spin(command[i])
print(dice.one)

Solution (Python):
f6=list(map(int,input().split()))
t=[0]*6
cmd=input()
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)}
for c in cmd:
    for i in range(6):
        t[i]=f6[r[c][i]]
    f6,t=t,f6
print(f6[0])

Solution (Python):
dice = input().split()
cmd = input()
for i in range(len(cmd)):
    if cmd[i] == 'E':
        dice[0], dice[3], dice[5], dice[2] = dice[3], dice[5], dice[2], dice[0]
    elif cmd[i] == 'W':
        dice[0], dice[2], dice[5], dice[3] = dice[2], dice[5], dice[3], dice[0]
    elif cmd[i] == 'S':
        dice[0], dice[4], dice[5], dice[1] = dice[4], dice[5], dice[1], dice[0]
    elif cmd[i] == 'N':
        dice[0], dice[1], dice[5], dice[4] = dice[1], dice[5], dice[4], dice[0]

print(dice[0])

Solution (Python):
class Dice():
    def __init__(self):
        self.face = [i for i in range(6)]
        self.memo = [i for i in range(6)]

    def setface(self,initface):
        for i in range(6):
            self.face[i] = initface[i]

    def roll(self,direction):
        for i in range(6):
            self.memo[i] = self.face[i]
        index = {'E':(3,1,0,5,4,2),'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'W':(2,1,5,0,4,3)}
        for i in range(6):
            self.face[i] = self.memo[index[direction][i]]

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

dice = Dice()
initface = list(map(int,input().split()))
dice.setface(initface)
route = input()
for direction in route:
    dice.roll(direction)
print(dice.top())

Solution (Python):
class Dice():
	def __init__(self,li):
		self.directionList = li
		self.top   = 1
		self.south = 2
		self.east  = 3
		self.west  = 4
		self.norse = 5
		self.low   = 6

	def get_top(self):
		return self.directionList[self.top-1]

	def advance_dice(self,direction):
		if direction == "E":
			tmp = self.top
			self.top = self.west
			self.west = self.low
			self.low = self.east
			self.east = tmp
		elif direction == "S":
			tmp = self.top
			self.top = self.norse
			self.norse = self.low
			self.low = self.south
			self.south = tmp
		elif direction == "W":
			self.advance_dice("E")
			self.advance_dice("E")
			self.advance_dice("E")
		elif direction == "N":
			self.advance_dice("S")
			self.advance_dice("S")
			self.advance_dice("S")

if __name__ == '__main__':
	li = list(map(int,input().split()))
	direction = list(input())
	dice  = Dice(li=li)
	for i in range(len(direction)):
		dice.advance_dice(direction[i])

	print(dice.get_top())

Solution (Python):
class Dise():
    def __init__(self, d1,d2,d3,d4,d5,d6):
        self.s1 = d1
        self.s2 = d2
        self.s3 = d3
        self.s4 = d4
        self.s5 = d5
        self.s6 = d6

    def roll_N(self):
        sub = self.s1
        self.s1 = self.s2
        self.s2 = self.s6
        self.s6 = self.s5
        self.s5 = sub

    def roll_S(self):
        sub = self.s1
        self.s1 = self.s5
        self.s5 = self.s6
        self.s6 = self.s2
        self.s2 = sub

    def roll_E(self):
        sub = self.s1
        self.s1 = self.s4
        self.s4 = self.s6
        self.s6 = self.s3
        self.s3 = sub

    def roll_W(self):
        sub = self.s1
        self.s1 = self.s3
        self.s3 = self.s6
        self.s6 = self.s4
        self.s4 = sub

    def top(self):
        print(self.s1)



inline = input().split()
d1, d2, d3, d4, d5, d6 = (int(xi) for xi in inline)
roll1 = input()
dise1 = Dise(d1, d2, d3, d4, d5, d6)

length = len(roll1)
for xi in range(length):
    if roll1[xi]=="N":
        dise1.roll_N()
    if roll1[xi]=="E":
        dise1.roll_E()
    if roll1[xi]=="W":
        dise1.roll_W()
    if roll1[xi]=="S":
        dise1.roll_S()

dise1.top()

Solution (Python):
class dice:
    def __init__(self, f):
        assert(len(f) == 6)
        self.face = f
        self.N = [1, 5, 2, 3, 0, 4]
        self.S = [4, 0, 2, 3, 5, 1]
        self.E = [3, 1, 0, 5, 4, 2]
        self.W = [2, 1, 5, 0, 4, 3]

    def rotate(self, dir):
        rot = self.__getattribute__(dir)
        old = self.face
        new = [-1 for _ in range(6)]
        for i in range(6):
            new[i] = old[rot[i]]
        self.face = new

d = list(map(int, input().split()))
D = dice(d)
Q = input()
for c in Q:
    D.rotate(c)
print(D.face[0])