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):
from copy import deepcopy

class Dice():

    def num_input(self):
        self.number = list(map(int,input().split()))
        self.E = [4,2,1,6,5,3]
        self.N = [2,6,3,4,1,5]
        self.S = [5,1,3,4,6,2]
        self.W = [3,2,6,1,5,4]
    
    def rotate(self,order):
        tmp = deepcopy(self.number)
        if order == "E":
            for i in range(6):
                self.number[i] = tmp[self.E[i]-1]
        elif order == "N":
            for i in range(6):
                self.number[i] = tmp[self.N[i]-1]
        elif order == "S":
            for i in range(6):
                self.number[i] = tmp[self.S[i]-1]
        elif order == "W":
            for i in range(6):
                self.number[i] = tmp[self.W[i]-1]
    
    def output(self):
        print(self.number[0])
    

if __name__ == "__main__":
    dice = Dice()
    dice.num_input()
    order = input()
    for i in order:
        dice.rotate(i)
    dice.output()

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

    def roll_n(self):
        d = self.dice
        self.dice = [d[1],d[5],d[2],d[3],d[0],d[4]]

    def roll_e(self):
        d = self.dice
        self.dice = [d[3],d[1],d[0],d[5],d[4],d[2]]

    def roll_s(self):
        d = self.dice
        self.dice = [d[4],d[0],d[2],d[3],d[5],d[1]]
    
    def roll_w(self):
        d = self.dice
        self.dice = [d[2],d[1],d[5],d[0],d[4],d[3]]

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

def main():
    d = dice(list(map(int,input().split())))
    com = input()
    for c in com:
        if c == 'N':d.roll_n()
        if c == 'E':d.roll_e()
        if c == 'S':d.roll_s()
        if c == 'W':d.roll_w()
    print(d.top())

if __name__ == '__main__':
    main()

Solution (Python):
class dice:
    state={"now":6,"N":5,"S":2,"W":4,"E":3,"behind":1}
    writtenval={}
    def __init__(self):
        self.writtenval=[-1]+[int(item) for item in input().split()]

    def chState(self):
        state=self.state
        for order in input():
            if order == "N":
                newstate = {"now": state["N"],
                            "N": state["behind"],
                            "S": state["now"],
                            "W": state["W"],
                            "E":state["E"],
                            "behind":state["S"]
                            }
                state=newstate
            elif order == "S":
                newstate = {"now": state["S"],
                            "N": state["now"],
                            "S": state["behind"],
                            "W": state["W"],
                            "E":state["E"],
                            "behind":state["N"]
                            }
                state=newstate
            elif order == "W":
                newstate = {"now": state["W"],
                            "N": state["N"],
                            "S": state["S"],
                            "W": state["behind"],
                            "E":state["now"],
                            "behind":state["E"]
                            }
                state=newstate
            elif order == "E":
                newstate = {"now": state["E"],
                            "N": state["N"],
                            "S": state["S"],
                            "W": state["now"],
                            "E":state["behind"],
                            "behind":state["W"]
                            }
                state = newstate
        self.state=state

dice_ = dice()
dice_.chState()
print(dice_.writtenval[dice_.state["behind"]])

Solution (Python):
d = input().split() 

s = {"N":"152304", "W":"215043", "E":"310542", "S":"402351"} 

for o in input(): 

  d = [d[int(i)] for i in s[o]] 

print (d[0])

Solution (Python):
def str_to_num(list_input, str_input):
    if str_input == 'S' and list_input[1] % 2 == 0:
        list_input[0] += 1
    if str_input == 'N' and list_input[1] % 2 == 0:
        list_input[0] -= 1
    if str_input == 'E' and list_input[0] % 2 == 0:
        list_input[1] += 1
    if str_input == 'W' and list_input[0] % 2 == 0:
        list_input[1] -= 1

dies = [[0, 0], [1, 0], [0, 1], [0, -1], [-1, 0], [2, 0]]
num = list(map(int, input().split()))
order = input()

for c in order:
    for i in dies:
        str_to_num(i, c)
        
[print(num[j]) for j in range(6) if (dies[j][0]+dies[j][1])%4 == 0]

Solution (Python):
class Dice():

    def __init__(self, nums):
        self.__indexTop__ = 1
        self.__indexFront__ = 2
        self.__indexRight__ = 3
        self.__indexLeft__ = 4
        self.__indexBack__ = 5
        self.__indexBottom__ = 6
        self.__sides__ = {1:nums[0], 2:nums[1], 3:nums[2], 4:nums[3], 5:nums[4], 6:nums[5]}
    
    def getTopSideNum(self):
        return self.__sides__[self.__indexTop__]
    
    def getTopsideIndex(self):
        return self.__indexTop__
    
    def roll(self, direction):
        initTop = self.__indexTop__
        initFront = self.__indexFront__
        initRight = self.__indexRight__
        initLeft = self.__indexLeft__
        initBack = self.__indexBack__
        initBottom = self.__indexBottom__
        if direction == 'N':
            self.__indexTop__ = initFront
            self.__indexFront__ = initBottom
            self.__indexRight__ = initRight
            self.__indexLeft__ = initLeft
            self.__indexBack__ = initTop
            self.__indexBottom__ = initBack
        elif direction == 'E':
            self.__indexTop__ = initLeft
            self.__indexFront__ = initFront
            self.__indexRight__ = initTop
            self.__indexLeft__ = initBottom
            self.__indexBack__ = initBack
            self.__indexBottom__ = initRight
        elif direction == 'S':
            self.__indexTop__ = initBack
            self.__indexFront__ = initTop
            self.__indexRight__ = initRight
            self.__indexLeft__ = initLeft
            self.__indexBack__ = initBottom
            self.__indexBottom__ = initFront
        elif direction == 'W':
            self.__indexTop__ = initRight
            self.__indexFront__ = initFront
            self.__indexRight__ = initBottom
            self.__indexLeft__ = initTop
            self.__indexBack__ = initBack
            self.__indexBottom__ = initLeft

die = Dice([int(i) for i in input().split()])
for direction in input():
    die.roll(direction)
print(die.getTopSideNum())

Solution (Python):
class Dice():
    
    def __init__(self,d1,d2,d3,d4,d5,d6):
        self.d1=d1
        self.d2=d2
        self.d3=d3
        self.d4=d4
        self.d5=d5
        self.d6=d6
    
    def roll(self,c):
        if c=='N':
            self.d1,self.d5,self.d6,self.d2=self.d2,self.d1,self.d5,self.d6
        elif c=='S':
            self.d1,self.d5,self.d6,self.d2=self.d5,self.d6,self.d2,self.d1
        elif c=='E':
            self.d1,self.d3,self.d6,self.d4=self.d4,self.d1,self.d3,self.d6
        else:
            self.d1,self.d3,self.d6,self.d4=self.d3,self.d6,self.d4,self.d1
    
a,b,c,d,e,f=map(int,input().split())
D=Dice(a,b,c,d,e,f)
order=input()
for c in order:
    D.roll(c)
print(D.d1)

Solution (Python):
class dice():
    
    
    
    

    
    
    
    
    
    def __init__(self, nums):
        self.pos = [0]
        self.pos.extend(nums)
    
    def rot_E(self):
        m = self.pos
                  
        self.pos = [m[0], m[4], m[2], m[1], m[6], m[5], m[3]]

    def rot_W(self):
        m = self.pos
                  
        self.pos = [m[0], m[3], m[2], m[6], m[1], m[5], m[4]]

    def rot_S(self):
        m = self.pos
                  
        self.pos = [m[0], m[5], m[1], m[3], m[4], m[6], m[2]]

    def rot_N(self):
        m = self.pos
                  
        self.pos = [m[0], m[2], m[6], m[3], m[4], m[1], m[5]]
        
    def top(self):
        print(self.pos[1])

nums = [int(x) for x in input().split()]
d = dice(nums)
seq = [x for x in list(input())]

for op in seq:
    if op == 'S':
        d.rot_S()
    elif op == 'E':
        d.rot_E()
    elif op == 'N':
        d.rot_N()
    elif op == 'W':
        d.rot_W()

d.top()

Solution (Python):
u,s,e,w,n,d=map(int,input().split())
a=[i for i in input()]
for i in a:
    if i=='N':
        n,d,s,u=u,n,d,s
    elif i=='S':
        s,d,n,u=u,s,d,n
    elif i=='E':
        e,d,w,u=u,e,d,w
    elif i=='W':
        w,d,e,u=u,w,d,e
print(u)

Solution (Python):
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]


    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def get_Top(self):
        return self.number[0]


dice = Dice()
table = list(map(int,input().split()))
dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

loc_array = str(input())
for tmp_loc in loc_array:
    dice.roll(tmp_loc)

print("%d"%(dice.get_Top()))

Solution (Python):

class Dice():
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]

    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5

    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == "E":
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == "N":
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == "S":
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == "W":
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])

    def get_Top(self):
        return self.number[0]

dice = Dice()
table = list(map(int,input().split()))
dice.setNumber(table[0],table[1],table[2],table[3],table[4],table[5])

loc_array = input()
 
for tmp_loc in loc_array:
    dice.roll(tmp_loc)

print(dice.get_Top())

Solution (Python):
n1,n2,n3,n4,n5,n6=map(int,input().split())
char=input()
up=n1
bottom=n6
front=n2
back=n5
left=n4
right=n3
for i in range(len(char)):
	if char[i]=="S":
		t=up
		up=back
		back=bottom
		bottom=front
		front=t
	if char[i]=="E":
		t=up
		up=left
		left=bottom
		bottom=right
		right=t
	if char[i]=="W":
		t=up
		up=right
		right=bottom
		bottom=left
		left=t
	if char[i]=="N":
		t=up
		up=front
		front=bottom
		bottom=back
		back=t
print(up)

Solution (Python):

def rot_func_list(rot, dice):

    if rot == "N":
        keys=['T','S','B','N']
        items=dice['S'],dice['B'],dice['N'],dice['T']
        new_dice=dict(zip(keys,items))
        dice.update(new_dice)

    if rot == "S":
        keys=['T','S','B','N']
        items=dice['N'],dice['T'],dice['S'],dice['B']
        new_dice=dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "E":
        keys=['T','E','B','W']
        items=dice['W'],dice['T'],dice['E'],dice['B']
        new_dice=dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "W":
        keys=['T','E','B','W']
        items=dice['E'],dice['B'],dice['W'],dice['T']
        new_dice=dict(zip(keys, items))
        dice.update(new_dice)


input_data=input().split(" ")
items=[int(cont)  for cont in input_data]
keys=['T', 'S', 'E', 'W', 'N', 'B']

controls=list(input())
dice=dict(zip(keys, items))

for i in controls:
    rot_func_list(i, dice)

print(dice["T"])

Solution (Python):
class Dice(object):
    def __init__(self, name=None, *args):
        self.name = name
        self.args = args
        self.dic = {i + 1 : self.args[i] for i in range(6)}

    def roll(self,s):
        if s == 'N':
            (self.dic[1], self.dic[2], self.dic[5], self.dic[6]) = \
                (self.dic[2], self.dic[6], self.dic[1], self.dic[5])
        elif s == 'E':
            (self.dic[3], self.dic[6], self.dic[1], self.dic[4]) = \
                (self.dic[1], self.dic[3], self.dic[4], self.dic[6])
        elif s == 'W':
            (self.dic[4], self.dic[1], self.dic[3], self.dic[6]) = \
                (self.dic[1], self.dic[3], self.dic[6], self.dic[4])
        else: 
            (self.dic[2], self.dic[1], self.dic[5], self.dic[6]) = \
                (self.dic[1], self.dic[5], self.dic[6], self.dic[2])

    def ans(self):
            print(self.dic[1])

L = list(map(int, input().split()))
string = input()

dice = Dice('dice1',*L)

for i in range(len(string)):
    dice.roll(string[i])

dice.ans()

Solution (Python):
class Dice:
    def __init__(self):
        self.d = list(map(int, input().split()))

    def setNum(self, n0, n1, n2, n3, n4, n5):
        self.d[0], self.d[1], self.d[2], self.d[3], self.d[4], self.d[5] = (
            n0,
            n1,
            n2,
            n3,
            n4,
            n5,
        )

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

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


dice = Dice()
o = list(map(str, input()))

for i in o:
    dice.roll(i)
print(dice.top())

Solution (Python):
class Dice():
    def __init__(self, l):
        self.value = l
    def roll(self,s):
        new_list = [0]*6
        if s == "W":
            new_list[0] = self.value[2]
            new_list[1] = self.value[1]
            new_list[2] = self.value[5]
            new_list[3] = self.value[0]
            new_list[4] = self.value[4]
            new_list[5] = self.value[3]
        if s == "E":
            new_list[0] = self.value[3]
            new_list[1] = self.value[1]
            new_list[2] = self.value[0]
            new_list[3] = self.value[5]
            new_list[4] = self.value[4]
            new_list[5] = self.value[2]
        if s == "N":
            new_list[0] = self.value[1]
            new_list[1] = self.value[5]
            new_list[2] = self.value[2]
            new_list[3] = self.value[3]
            new_list[4] = self.value[0]
            new_list[5] = self.value[4]
        if s == "S":
            new_list[0] = self.value[4]
            new_list[1] = self.value[0]
            new_list[2] = self.value[2]
            new_list[3] = self.value[3]
            new_list[4] = self.value[5]
            new_list[5] = self.value[1]
        self.value = new_list

l = list(map(int,input().split()))
Dice1 = Dice(l)
quary = input()

for q in quary:
    Dice1.roll(q)
print(Dice1.value[0])

Solution (Python):
import sys
input = sys.stdin.readline

class Dice:
    def __init__(self, u, d, w, e, n, s):
        self.nums = {
            "u": u,
            "d": d,
            "w": w,
            "e": e,
            "n": n,
            "s": s
        }
    
    def roll_w(self):
        dic = {}
        dic["s"] = self.nums["s"]
        dic["n"] = self.nums["n"]
        dic["w"] = self.nums["u"]
        dic["u"] = self.nums["e"]
        dic["e"] = self.nums["d"]
        dic["d"] = self.nums["w"]
        self.nums = dic
    
    def roll_e(self):
        dic = {}
        dic["s"] = self.nums["s"]
        dic["n"] = self.nums["n"]
        dic["w"] = self.nums["d"]
        dic["d"] = self.nums["e"]
        dic["e"] = self.nums["u"]
        dic["u"] = self.nums["w"]
        self.nums = dic
    
    def roll_s(self):
        dic = {}
        dic["w"] = self.nums["w"]
        dic["e"] = self.nums["e"]
        dic["s"] = self.nums["u"]
        dic["u"] = self.nums["n"]
        dic["n"] = self.nums["d"]
        dic["d"] = self.nums["s"]
        self.nums = dic
    
    def roll_n(self):
        dic = {}
        dic["w"] = self.nums["w"]
        dic["e"] = self.nums["e"]
        dic["n"] = self.nums["u"]
        dic["u"] = self.nums["s"]
        dic["s"] = self.nums["d"]
        dic["d"] = self.nums["n"]
        self.nums = dic
    

def main():
    a = list(map(int, input().split()))
    s = input().strip()

    dice = Dice(a[0], a[5], a[3], a[2], a[4], a[1])

    for c in s:
        if c == "S":
            dice.roll_s()
        elif c == "W":
            dice.roll_w()
        elif c == "N":
            dice.roll_n()
        elif c == "E":
            dice.roll_e()
    
    print(dice.nums["u"])



if __name__ == "__main__":
    main()

Solution (Python):
import math

class Dice:
    s = [0] * 6
    def __init__(self, s):
        self.s = s
    
    def move(self, s):
        if s == 'E':
            self.s[0], self.s[3], self.s[5], self.s[2] = self.s[3], self.s[5], self.s[2], self.s[0]
        if s == 'N':
            self.s[0], self.s[1], self.s[5], self.s[4] = self.s[1], self.s[5], self.s[4] ,self.s[0]
        if s == 'S':
            self.s[0], self.s[4], self.s[5], self.s[1] = self.s[4], self.s[5], self.s[1], self.s[0]
        if s == 'W':
            self.s[0], self.s[2], self.s[5], self.s[3] = self.s[2], self.s[5], self.s[3], self.s[0]

s = list(map(int, input().split()))
x = Dice(s)
m = input()

for i in m:
    x.move(i)
print(x.s[0])

Solution (Python):
class Dice:
    def __init__(self, default = [0, 1, 2, 3, 4, 5]):
        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())

main()

Solution (Python):
def move(lon, lat, com):
    target, other, pop_index, insert_index = lon, lat, 0, 3
    if com == "E" or com == "W":
        target, other = lat, lon
    if com == "S" or com == "W":
        pop_index, insert_index = 3, 0
    target.insert(insert_index, target.pop(pop_index))
    other[0], other[2] = target[0], target[2]


longitude = [1, 2, 6, 5]
latitude = [1, 4, 6, 3]
values = list(input().split())
command = input()
for c in command:
    move(longitude, latitude, c)
print("{}".format(values[longitude[0] - 1]))

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 turn(self,order):
        if order=="N":
            self.top,self.front,self.bottom,self.back=self.front,self.bottom,self.back,self.top
        if order=="S":
            self.top,self.front,self.bottom,self.back=self.back,self.top,self.front,self.bottom
        if order=="E":
            self.top,self.right,self.bottom,self.left=self.left,self.top,self.right,self.bottom
        if order=="W":
            self.top,self.right,self.bottom,self.left=self.right,self.bottom,self.left,self.top

num=map(int,raw_input().split())
dice=Dice(num[0],num[1],num[2],num[3],num[4],num[5])
order=raw_input()
for i in order:
    dice.turn(i)
print dice.top

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

for i in rotation:
    top = nums[0]
    if i == "S":
        top = nums[4]
        nums = [top, nums[0], nums[2], nums[3], nums[5], nums[1]]
    elif i == "E":
        top = nums[3]
        nums = [top, nums[1], nums[0], nums[5], nums[4], nums[2]]
    elif i == "N":
        top = nums[1]
        nums = [top, nums[5], nums[2], nums[3], nums[0], nums[4]]
    elif i == "W":
        top = nums[2]
        nums = [top, nums[1], nums[5], nums[0], nums[4], nums[3]]

print(top)

Solution (Python):
class Dice:
    
    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        
    def setNumber(self, n0, n1, n2, n3, n4, n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5

    def roll(self, dir):
        for i in range(6):
            self.work[i] = self.number[i]
        if dir == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif dir == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif dir == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif dir == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])

    def top(self):
        return self.number[0]
        
dice = Dice()
table = list(map(int, input().split()))
dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

dirction = input()
for d in dirction:
    dice.roll(d)
print("%d" %dice.top())

Solution (Python):
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


class Dice():

    def __init__(self):
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]


    def setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5


    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]

        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        elif loc == 'W':
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])


    def get_Top(self):
        return self.number[0]


dice = Dice()
table = list(map(int,input().split()))
dice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])

loc_array = str(input())
for tmp_loc in loc_array:
    dice.roll(tmp_loc)

print("%d"%(dice.get_Top()))

Solution (Python):
faces = input().split()

move = input()

for i in range(len(move)):
    m = move[i]
    
    if m == "N":
        
        
        
        
        
        tmp = faces[4]
        faces[4] = faces[0]
        faces[0] = faces[1]
        faces[1] = faces[5]
        faces[5] = tmp
        
        
    elif m == "S":
        
        
        
        
        
        tmp = faces[1]
        faces[1] = faces[0]
        faces[0] = faces[4]
        faces[4] = faces[5]
        faces[5] = tmp
        
    elif m == "E":
        
        
        
        
        
        tmp = faces[2]
        faces[2] = faces[0]
        faces[0] = faces[3]
        faces[3] = faces[5]
        faces[5] = tmp
        
    elif m == "W":
        
        
        
        
        
        tmp = faces[3]
        faces[3] = faces[0]
        faces[0] = faces[2]
        faces[2] = faces[5]
        faces[5] = tmp

print(faces[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 setNumber(self,n0,n1,n2,n3,n4,n5):
        self.number[0] = n0
        self.number[1] = n1
        self.number[2] = n2
        self.number[3] = n3
        self.number[4] = n4
        self.number[5] = n5
        
    def roll(self,loc):
        for i in range(6):
            self.work[i] = self.number[i]
            
        if loc == "E":
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
            
        elif loc == "N":
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        
        elif loc == "S":
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        else:
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
            
    def get_Top(self):
        return self.number[0]
        
dice = Dice()
table = list(map(int,input().split()))
dice.setNumber(table[0],table[1],table[2],table[3],table[4],table[5])

loc_array = str(input())
for tmp_loc in loc_array:
    dice.roll(tmp_loc)
print("%d"%(dice.get_Top()))

Solution (Python):
class Dice(object):
    def __init__(self, labels):
        self.stat = labels
    def roll_e(self):
        self.stat[0], self.stat[2], self.stat[5], self.stat[3] = self.stat[3], self.stat[0], self.stat[2], self.stat[5]
    def roll_w(self):
        self.stat[0], self.stat[2], self.stat[5], self.stat[3] = self.stat[2], self.stat[5], self.stat[3], self.stat[0]
    def roll_n(self):
        self.stat[0], self.stat[1], self.stat[5], self.stat[4] = self.stat[1], self.stat[5], self.stat[4], self.stat[0]
    def roll_s(self):
        self.stat[0], self.stat[1], self.stat[5], self.stat[4] = self.stat[4], self.stat[0], self.stat[1], self.stat[5]
    def get_top(self):
        return self.stat[0]
dice = Dice(input().split())
commands = input()
for command in commands:
    if command == "E":
        dice.roll_e()
    elif command == "W":
        dice.roll_w()
    elif command == "N":
        dice.roll_n()
    elif command == "S":
        dice.roll_s()
print(dice.get_top())

Solution (Python):
dice = [int(e) for e in input().split()]
roll = input()
for roll1 in roll: 
    if roll1 == "N":
        dice = [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]]
    elif roll1 == "W":
        dice = [dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]]
    elif roll1 == "E":
        dice = [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]]
    elif roll1 == "S":
        dice = [dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]]
print(dice[0])

Solution (Python):
f1, f2, f3, f4, f5, f6 = map(int, input().split())

dice = {'f_top':f1, 'f_front':f2,'f_back':f5,'f_left':f4,'f_right':f3,'f_bottom':f6}

def roll(command, d):
    if command=='E':
        tmp = d['f_right']
        d['f_right'] = d['f_top']
        d['f_top'] = d['f_left']
        d['f_left'] = d['f_bottom']
        d['f_bottom'] = tmp
    elif command=='W':
        tmp = d['f_left']
        d['f_left'] = d['f_top']
        d['f_top'] = d['f_right']
        d['f_right'] = d['f_bottom']
        d['f_bottom'] = tmp
    elif command=='N':
        tmp = d['f_back']
        d['f_back'] = d['f_top']
        d['f_top'] = d['f_front']
        d['f_front'] = d['f_bottom']
        d['f_bottom'] = tmp
    elif command=='S':
        tmp = d['f_front']
        d['f_front'] = d['f_top']
        d['f_top'] = d['f_back']
        d['f_back'] = d['f_bottom']
        d['f_bottom'] = tmp
    return d
    
commands = input()
for s in commands:
    dice = roll(s, dice)

print(dice['f_top'])

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

  def vertical(self, direction):
    s = self.state
    state = [s[1], s[5], s[0], s[4]]
    if direction < 0:
      s[0], s[1], s[4], s[5] = state
    elif 0 < direction:
      s[0], s[1], s[4], s[5] = reversed(state)
    return self
  
  def lateral(self, direction):
    s = self.state
    state = [s[2], s[5], s[0], s[3]]
    if direction < 0:
      s[0], s[2], s[3], s[5] = state
    elif 0 < direction:
      s[0], s[2], s[3], s[5] = reversed(state)
    return self

  def north(self):
    self.vertical(-1)
    return self

  def south(self):
    self.vertical(1)
    return self
  
  def east(self):
    self.lateral(1)
    return self

  def west(self):
    self.lateral(-1)
    return self

dice = Dice(input().split())

for direction in list(input()):
  if direction == 'N':
    dice.north()
  elif direction == 'S':
    dice.south()
  elif direction == 'W':
    dice.west()
  elif direction == 'E':
    dice.east()

print(dice.state[0])

Solution (Python):
class Dise():
    def __init__(self, aLabelList):
        self.LabelList = aLabelList
        self.NEWS = {"N": [0,4,5,1], 
                     "E": [0,2,5,3], 
                     "W": [0,3,5,2], 
                     "S": [0,1,5,4]} 
        
    def move(self,aNEWS):
        idx = self.NEWS[aNEWS]
        
        tmp = self.LabelList[idx[0]]
        self.LabelList[idx[0]] = self.LabelList[idx[3]]
        self.LabelList[idx[3]] = self.LabelList[idx[2]]
        self.LabelList[idx[2]] = self.LabelList[idx[1]]
        self.LabelList[idx[1]] = tmp

    def DisePrint(self):
        print(self.LabelList[0])

myInstance = Dise(input().split())
 
x = input()
for i in range(len(x)):
    myInstance.move(x[i:i+1])

myInstance.DisePrint()