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):
import sys
import math

def str_input():
    S = raw_input()
    if S[len(S)-1] == "\r":
        return S[:len(S)-1]
    return S

def float_to_str(num):
    return str("{:.10f}".format(num))

def list_input(tp):
    return map(tp, str_input().split())



class Dice:
    pip = [0 for i in xrange(6)]

    def __init__(self, arg):
        self.pip = arg

    def rollDir(self, dr):
        nextPip = [0 for i in xrange(6)]
        if dr == "N":
            nextPip[0] = self.pip[1]
            nextPip[1] = self.pip[5]
            nextPip[2] = self.pip[2]
            nextPip[3] = self.pip[3]
            nextPip[4] = self.pip[0]
            nextPip[5] = self.pip[4]
        elif dr == "E":
            nextPip[0] = self.pip[3]
            nextPip[1] = self.pip[1]
            nextPip[2] = self.pip[0]
            nextPip[3] = self.pip[5]
            nextPip[4] = self.pip[4]
            nextPip[5] = self.pip[2]
        self.pip = nextPip

    def roll(self, dr):
        if dr == "N" or dr == "E":
            self.rollDir(dr)
        elif dr == "S":
            self.rollDir("N")
            self.rollDir("N")
            self.rollDir("N")
        elif dr == "W":
            self.rollDir("E")
            self.rollDir("E")
            self.rollDir("E")

dice = Dice(list_input(int))
command = str_input()

for x in command:
    dice.roll(x)

print dice.pip[0]

Solution (Python):
def rotate(dice,d):
    if d == "N":
        temp = dice[0]
        dice[0] = dice[1]
        dice[1] = dice[5]
        dice[5] = dice[4]
        dice[4] = temp
    elif d == "E":
        temp = dice[0]
        dice[0] = dice[3]
        dice[3] = dice[5]
        dice[5] = dice[2]
        dice[2] = temp
    elif d == "W":
        temp = dice[0]
        dice[0] = dice[2]
        dice[2] = dice[5]
        dice[5] = dice[3]
        dice[3] = temp
    elif d == "S":
        temp = dice[0]
        dice[0] = dice[4]
        dice[4] = dice[5]
        dice[5] = dice[1]
        dice[1] = temp
    return dice

dice = input().split()
dArr = list(input())
for i in range(len(dArr)):
    dice = rotate(dice,dArr[i])
print(dice[0])

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

    def move_E(self):
        self.copy = self.num.copy() 
        for i,j in zip([0,2,5,3],[3,0,2,5]):
            self.num[i] = self.copy[j]

    def move_W(self):
        self.copy = self.num.copy()
        for i,j in zip([0,3,5,2],[2,0,3,5]):
            self.num[i] = self.copy[j]

    def move_N(self):
        self.copy = self.num.copy()
        for i,j in zip([0,1,5,4],[1,5,4,0]):
            self.num[i] = self.copy[j]

    def move_S(self):
        self.copy = self.num.copy()
        for i,j in zip([0,1,5,4],[4,0,1,5]):
            self.num[i] = self.copy[j]



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



dice = Dice(number)

for order in input():
    if order == 'S':
        dice.move_S()
    elif order == 'N':
        dice.move_N()
    elif order == 'W':
        dice.move_W()
    else:
        dice.move_E()




print(dice.num[0])

Solution (Python):
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='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()))
op_list = list(input())
d = dice(label)
for op in op_list:
    d.roll(op)
d.print_top()

Solution (Python):
class Dice:
    def __init__(self):
        self.numbers = map(int, raw_input().split())
        
    def roll(self, direction):
        if direction == "N":
            before_inds = [0, 1, 5, 4]
            after_inds  = [1, 5, 4, 0]
        elif direction == "S":
            before_inds = [0, 1, 5, 4]
            after_inds  = [4, 0, 1, 5]
        elif direction == "E":
            before_inds = [0, 2, 5, 3]
            after_inds  = [3, 0, 2, 5]
        elif direction == "W":
            before_inds = [0, 2, 5, 3]
            after_inds  = [2, 5, 3, 0]
        else:
            return False
        changed = [self.numbers[i] for i in after_inds]
        for c_i, n_i in enumerate(before_inds):
            self.numbers[n_i] = changed[c_i]
        return True
        
dice = Dice()
for d in raw_input():
    dice.roll(d)
    
print dice.numbers[0]

Solution (Python):
class Dice:
    def __init__(self):
        
        self.numbers = map(int, raw_input().split())
    
    @property
    def top(self):
        return self.numbers[0]
    
    @property
    def front(self):
        return self.numbers[1]
        
    @property
    def right(self):
        return self.numbers[2]
        
    @property
    def left(self):
        return self.numbers[3]
    
    @property
    def back(self):
        return self.numbers[4]
        
    @property
    def bottom(self):
        return self.numbers[5]

    def roll(self, direction):
        if direction == "N":
            before_inds = [0, 1, 5, 4]
            after_inds  = [1, 5, 4, 0]
        elif direction == "S":
            before_inds = [0, 1, 5, 4]
            after_inds  = [4, 0, 1, 5]
        elif direction == "E":
            before_inds = [0, 2, 5, 3]
            after_inds  = [3, 0, 2, 5]
        elif direction == "W":
            before_inds = [0, 2, 5, 3]
            after_inds  = [2, 5, 3, 0]
        else:
            return False
        changed = [self.numbers[i] for i in after_inds]
        for c_i, n_i in enumerate(before_inds):
            self.numbers[n_i] = changed[c_i]
        return True
        
dice = Dice()
for d in raw_input():
    dice.roll(d)
    
print dice.top

Solution (Python):
class Dice:
    def __init__(self,pips):
        self.top = pips[0]
        self.south = pips[1]
        self.east = pips[2]
        self.west = pips[3]
        self.north =pips[4]
        self.bottom=pips[5]
    def show_top(self):
        print(self.top)
    def n(self):
        tmp = self.top
        self.top = self.south
        self.south = self.bottom
        self.bottom = self.north
        self.north = tmp
    def s(self):
        tmp = self.top
        self.top = self.north
        self.north = self.bottom
        self.bottom = self.south
        self.south = tmp
    def e(self):
        tmp = self.top
        self.top = self.west
        self.west = self.bottom
        self.bottom = self.east
        self.east = tmp
    def w(self):
        tmp = self.top
        self.top = self.east
        self.east = self.bottom
        self.bottom = self.west
        self.west = tmp

pips = [int(x) for x in input().split()]
dice = Dice(pips)
move = input()
for m in move:
    if m == "N":
        dice.n()
    if m == "S":
        dice.s()
    if m == "E":
        dice.e()
    if m == "W":
        dice.w()

dice.show_top()

Solution (Python):
def north(d):
	d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]
	
def south(d):
	d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0]
	
def east(d):
	d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0]
	
def west(d):
	d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]

F = {'N': north, 'S': south, 'W': west, 'E': east}

d, os = list(map(int, input().split())), input()

for o in os:
	F[o](d)

print(d[0])

Solution (Python):
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='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=[int(x) for x in input().split()]
oplist=list(input())
d=dice(label)
for op in oplist:
    d.roll(op)
d.print_top()

Solution (Python):
class Dice():

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

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def change(self, convert):
        num = []
        for i in range(6):
            num.append(self.label[convert[i] - 1])
        self.label = num


def main():
    dice = Dice([int(x) for x in input().split()])
    cmd = list(input())
    for c in cmd:
        if c == 'N':
            dice.north()
        elif c == 'W':
            dice.west()
        elif c == 'E':
            dice.east()
        elif c == 'S':
            dice.south()
    print(dice.label[0])


if __name__ == '__main__':
    main()

Solution (Python):
class Dice():

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

    def north(self):
        self.change([2, 6, 3, 4, 1, 5])

    def west(self):
        self.change([3, 2, 6, 1, 5, 4])

    def east(self):
        self.change([4, 2, 1, 6, 5, 3])

    def south(self):
        self.change([5, 1, 3, 4, 6, 2])

    def change(self, convert):
        num = []
        for i in range(6):
            num.append(self.label[convert[i] - 1])
        self.label = num


def main():
    dice = Dice([int(x) for x in input().split()])
    for c in input():
        if c == 'N':
            dice.north()
        elif c == 'W':
            dice.west()
        elif c == 'E':
            dice.east()
        elif c == 'S':
            dice.south()
    print(dice.label[0])


if __name__ == '__main__':
    main()

Solution (Python):
class Dice:
    def __init__(self, labels):
        self.up = labels[0]
        self.front = labels[1]
        self.right = labels[2]
        self.left = labels[3]
        self.back = labels[4]
        self.down = labels[5]
    def east(self):
        self.up, self.right, self.down, self.left = self.left, self.up, self.right, self.down
    def north(self):
        self.up, self.back, self.down, self.front = self.front, self.up, self.back, self.down
    def south(self):
        self.up, self.front, self.down, self.back = self.back, self.up, self.front, self.down
    def west(self):
        self.up, self.left, self.down, self.right = self.right, self.up, self.left, self.down

dice = Dice(list(map(int, input().split())))
for cmd in list(input()):
    if cmd == 'E':
        dice.east()
    if cmd == 'N':
        dice.north()
    if cmd == 'S':
        dice.south()
    if cmd == 'W':
        dice.west()
print(dice.up)

Solution (Python):


class Dice(object):
	def __init__(self):
		
		
		self.x = [2, 5]
		self.y = [3, 4]
		self.z = [1, 6]
		SN = {'S': 0, 'N': 1}
		WE = {'W': 0, 'E': 1}
		pass

	def rotate(self, _dir):
		def rot(_k, _r):
			return list(reversed(_r)), _k

		if _dir=='N':
			self.x, self.z = rot(self.x, self.z)
		elif _dir=='S':
			self.z, self.x = rot(self.z, self.x)
		elif _dir=='E':
			self.z, self.y = rot(self.z, self.y)
		elif _dir=='W':
			self.y, self.z = rot(self.y, self.z)
		else:
			pass

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


if __name__=="__main__":
	dice = Dice()
	val = list(map(int, input().split()))
	dr = input()
	for d in dr:
		dice.rotate(d)
	print(val[dice.top()-1])

Solution (Python):
class Dice(object):
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def get_top(self):
        return self.top
    
    def rotate(self, directions):
        for direction in directions:
            if direction == 'S':
                self.prev_top = self.top
                self.top = self.north
                self.north = self.bottom
                self.bottom = self.south
                self.south = self.prev_top
            elif direction == 'E':
                self.prev_top = self.top
                self.top = self.west
                self.west = self.bottom
                self.bottom = self.east
                self.east = self.prev_top
            elif direction == 'W':
                self.prev_top = self.top
                self.top = self.east
                self.east = self.bottom
                self.bottom = self.west
                self.west = self.prev_top
            elif direction == 'N':
                self.prev_top = self.top
                self.top = self.south
                self.south = self.bottom
                self.bottom = self.north
                self.north = self.prev_top
 
dice = Dice(*map(int,input().split()))
dice.rotate(input())
print(dice.get_top())

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

Solution (Python):
class Dice:
    def __init__(self, n1, n2, n3, n4, n5, n6):
        self.elements = [n1, n2, n3, n4, n5, n6]

    def rotateW(self):
        n5 = self.elements[0]
        n1 = self.elements[2]
        n3 = self.elements[5]
        n6 = self.elements[4]
        self.elements[4] = n5
        self.elements[0] = n1
        self.elements[2] = n3
        self.elements[5] = n6

    def rotateN(self):
        n2 = self.elements[0]
        n1 = self.elements[3]
        n4 = self.elements[5]
        n6 = self.elements[1]
        self.elements[1] = n2
        self.elements[0] = n1
        self.elements[3] = n4
        self.elements[5] = n6


    def rotateS(self):
        n4 = self.elements[0]
        n1 = self.elements[1]
        n2 = self.elements[5]
        n6 = self.elements[3]
        self.elements[3] = n4
        self.elements[0] = n1
        self.elements[1] = n2
        self.elements[5] = n6

    def rotateE(self):
        n3 = self.elements[0]
        n1 = self.elements[4]
        n5 = self.elements[5]
        n6 = self.elements[2]
        self.elements[2] = n3
        self.elements[0] = n1
        self.elements[4] = n5
        self.elements[5] = n6

elements = map(int, raw_input().split(" "))
dice = Dice(elements[0], elements[4], elements[2], elements[1], elements[3], elements[5])
rule = raw_input()

for i in rule:
    if i == "S": dice.rotateS()
    elif i == "W": dice.rotateW()
    elif i == "N": dice.rotateN()
    elif i == "E": dice.rotateE()

print(str(dice.elements[0]))

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

    def roll(self, s):
        for f in s:
            n = self.f[:]
            if f == 'E':
                t = n[0]
                n[0] = n[3]
                n[3] = n[5]
                n[5] = n[2]
                n[2] = t
            elif f == 'W':
                t = n[0]
                n[0] = n[2]
                n[2] = n[5]
                n[5] = n[3]
                n[3] = t
            elif f == 'N':
                t = n[0]
                n[0] = n[1]
                n[1] = n[5]
                n[5] = n[4]
                n[4] = t
            else:
                t = n[0]
                n[0] = n[4]
                n[4] = n[5]
                n[5] = n[1]
                n[1] = t
            self.f = n

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

d = Dice(list(map(int, input().split())))
r = input()
d.roll(r)
print(d.top())

Solution (Python):
class Dice(object):
    def __init__(self):
        self.upside = 1
        self.frontside = 2
        self.rightside = 3
        self.backside = 5
        self.leftside = 4
        self.downside = 6
		
    def throwDice(self,dir):
        up = self.upside
        front = self.frontside
        left = self.leftside
        if dir == "S":
            self.frontside = up
            self.backside = 7-up
            self.downside = front
            self.upside = 7-front
			
        elif dir == "N":
            self.frontside = 7-up
            self.backside = up
            self.downside = 7-front
            self.upside = front
 		
        elif dir == "E":
            self.rightside = up
            self.leftside = 7-up
            self.upside = left
            self.downside = 7-left
		
        elif dir == "W":
            self.rightside = 7-up
            self.leftside = up
            self.upside = 7-left
            self.downside = left
	
    def getUpside(self):
        return self.upside
		
n = list(map(int,input().split()))
com = list(input())

dice = Dice()
for i in range(len(com)):
    dice.throwDice(com[i])

print(n[dice.getUpside()-1])

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

for i in range(len(inst)):
    if inst[i] == 'E':
        temp = dice[5]
        dice[5] = dice[2]
        dice[2] = dice[0]
        dice[0] = dice[3]
        dice[3] = temp
    elif inst[i] == 'W':
        temp = dice[5]
        dice[5] = dice[3]
        dice[3] = dice[0]
        dice[0] = dice[2]
        dice[2] = temp
    elif inst[i] == 'N':
        temp = dice[5]
        dice[5] = dice[4]
        dice[4] = dice[0]
        dice[0] = dice[1]
        dice[1] = temp
    elif inst[i] == 'S':
        temp = dice[5]
        dice[5] = dice[1]
        dice[1] = dice[0]
        dice[0] = dice[4]
        dice[4] = temp

print dice[0]

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

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

 def InsSN(self, one, two, five, six):
  self.dice[0] = one
  self.dice[1] = two
  self.dice[4] = five
  self.dice[5] = six

 def S(self):
  one = self.dice[4]
  two = self.dice[0]
  five = self.dice[5]
  six = self.dice[1]
  self.InsSN(one, two, five, six)

 def N(self):
  one = self.dice[1]
  two = self.dice[5]
  five = self.dice[0]
  six = self.dice[4]
  self.InsSN(one, two, five, six)
  
 def InsWE(self, one, three, four, six):
  self.dice[0] = one
  self.dice[2] = three
  self.dice[3] = four
  self.dice[5] = six
 
 def W(self):
  one = self.dice[2]
  three = self.dice[5]
  four = self.dice[0]
  six = self.dice[3]
  self.InsWE(one, three, four, six)

 def E(self):
  one = self.dice[3]
  three = self.dice[0]
  four = self.dice[5]
  six = self.dice[2]
  self.InsWE(one, three, four, six)

d = Dice(d)

for i in range(len(O)):
 if O[i] == 'S':
  d.S()
 elif O[i] == 'N':
  d.N()
 elif O[i] == 'E':
  d.E()
 elif O[i] == 'W':
  d.W()

print(d.dice[0])

Solution (Python):
dice = map(int, raw_input().split())
inst = raw_input()
 
def rolling(inst, dice):
    if inst == 'E':
        dice[5], dice[2], dice[0], dice[3] = dice[2], dice[0], dice[3], dice[5]
    elif inst == 'W':
        dice[5], dice[3], dice[0], dice[2] = dice[3], dice[0], dice[2], dice[5]
    elif inst == 'N':
        dice[5], dice[4], dice[0], dice[1] = dice[4], dice[0], dice[1], dice[5]
    elif inst == 'S':
        dice[5], dice[1], dice[0], dice[4] = dice[1], dice[0], dice[4], dice[5]
 
for i in range(len(inst)):
    rolling(inst[i], dice)
print dice[0]

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

    def InsSN(self, one, two, five, six):
        self.dice[0] = one
        self.dice[1] = two
        self.dice[4] = five
        self.dice[5] = six
        
    def InsWE(self, one, three, four, six):
        self.dice[0] = one
        self.dice[2] = three
        self.dice[3] = four
        self.dice[5] = six

    def S(self):
        one = self.dice[4]
        two = self.dice[0]
        five = self.dice[5]
        six = self.dice[1]
        self.InsSN(one, two, five, six)

    def N(self):
        one = self.dice[1]
        two = self.dice[5]
        five = self.dice[0]
        six = self.dice[4]
        self.InsSN(one, two, five, six)
 
    def W(self):
        one = self.dice[2]
        three = self.dice[5]
        four = self.dice[0]
        six = self.dice[3]
        self.InsWE(one, three, four, six)
        
    def E(self):
        one = self.dice[3]
        three = self.dice[0]
        four = self.dice[5]
        six = self.dice[2]
        self.InsWE(one, three, four, six)
        
    def roll(self, order):
        if order == 'S':
            self.S()
        elif order == 'N':
            self.N()
        elif order == 'E':
            self.E()
        elif order == 'W':
            self.W()
d = Dice(d)
for o in order:
    d.roll(o)
print(d.dice[0])

Solution (Python):
class Dice(object):
    """Dice Class

    """

    def __init__(self, numbers):
        """

        Args:
            numbers:
        """
        self.numbers = {1: numbers[0], 2: numbers[1], 3: numbers[2], 4: numbers[3], 5: numbers[4], 6: numbers[5]}

        self.vertical = [self.numbers[1], self.numbers[2], self.numbers[6], self.numbers[5]]
        self.horizontal = [self.numbers[4], self.numbers[1], self.numbers[3], self.numbers[6]]

    def move_dice(self, s):
        """

        Args:
            s: move direction

        Returns:

        """
        if s == 'N':
            self.move_north()
        elif s == 'S':
            self.move_south()
        elif s == 'W':
            self.move_west()
        elif s == 'E':
            self.move_east()

    def move_south(self):
        """move this dice towered north
        """
        self.vertical = (self.vertical * 2)[3:7]
        self.horizontal[1] = self.vertical[0]
        self.horizontal[3] = self.vertical[2]

    def move_north(self):
        """move this dice towered south
        """
        self.vertical = (self.vertical * 2)[1:5]
        self.horizontal[1] = self.vertical[0]
        self.horizontal[3] = self.vertical[2]

    def move_east(self):
        """move this dice towered east
        """
        self.horizontal = (self.horizontal * 2)[3:7]
        self.vertical[0] = self.horizontal[1]
        self.vertical[2] = self.horizontal[3]

    def move_west(self):
        """move this dice towered west
        """
        self.horizontal = (self.horizontal * 2)[1:5]
        self.vertical[0] = self.horizontal[1]
        self.vertical[2] = self.horizontal[3]

    def get_top(self):
        return self.vertical[0]


numbers = [int(x) for x in raw_input().split()]
dice1 = Dice(numbers=numbers)
for s in raw_input():
    dice1.move_dice(s)

print(dice1.get_top())

Solution (Python):
class Dice(object):
    """
    6??¢???????????????
    ?????¢???top, ?????¢???bottom???????????\??????4??¢??????????????? north, south, east, west ??¨?????¶???
    """
    def __init__(self, faces):
        
        
        self.top = faces[0]
        self.south = faces[1]
        self.east = faces[2]
        self.west = faces[3]
        self.north = faces[4]
        self.bottom = faces[5]

    def rotate(self, dir):
        
        
        if dir == 'N':
            temp = self.top
            self.top = self.south
            self.south = self.bottom
            self.bottom = self.north
            self.north = temp
        elif dir == 'S':
            temp = self.top
            self.top = self.north
            self.north = self.bottom
            self.bottom = self.south
            self.south = temp
        elif dir == 'E':
            temp = self.top
            self.top = self.west
            self.west = self.bottom
            self.bottom = self.east
            self.east = temp
        elif dir == 'W':
            temp = self.top
            self.top = self.east
            self.east = self.bottom
            self.bottom = self.west
            self.west = temp
        

    def get_top_value(self):
        return self.top

    def print(self):
        print('=' * 64)
        print('top: {0}'.format(self.top))
        print('south: {0}'.format(self.south))
        print('bottom: {0}'.format(self.bottom))
        print('north: {0}'.format(self.north))
        print('east: {0}'.format(self.east))
        print('west: {0}'.format(self.west))
        print('=' * 64)


if __name__ == '__main__':
    
    dice_values = [int(x) for x in input().split(' ')]
    rotations = input()

    
    d = Dice(dice_values)
    for r in rotations:
        d.rotate(r)

    
    print('{0}'.format(d.get_top_value()))

Solution (Python):
class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
    
    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
        self.dic={"W":0,"S":1,"E":2,"N":3}

    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[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,w,s,e,n,d)
st=input()
for c in st:
    dice.rot(c)
print(dice.u)

Solution (Python):
dice = list(map(str, input().split()))
direction = input()
for i in range(len(direction)):
    if direction[i] == "N":
        dice[0], dice[1], dice[4], dice[5] = dice[1], dice[5], dice[0], dice[4]
    elif direction[i] == "S":
        dice[0], dice[1], dice[4], dice[5] = dice[4], dice[0], dice[5], dice[1]
    elif direction[i] == "W":
        dice[0], dice[2], dice[3], dice[5] = dice[2], dice[5], dice[0], dice[3]
    else:
        dice[0], dice[2], dice[3], dice[5] = dice[3], dice[0], dice[5], dice[2]
print(dice[0])

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

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

	def roll(self,com):
		a1,a2,a3,a4,a5,a6=self.d
		if com=="E":
			self.d = [a4,a2,a1,a6,a5,a3]
		elif com=="W":
			self.d = [a3,a2,a6,a1,a5,a4]
		elif com=="S":
			self.d = [a5,a1,a3,a4,a6,a2]
		elif com=="N":
			self.d = [a2,a6,a3,a4,a1,a5]

dice1=dice(d)	
for com in c:
	dice1.roll(com)
print(dice1.d[0])

Solution (Python):
class Dice(object):
    def __init__(self,num):
        self.f=num[0]
        self.s=num[1]
        self.e=num[2]
        self.w=num[3]
        self.n=num[4]
        self.b=num[5]
    def create(self,order):
        if order=='N':
            return [self.s,self.b,self.e,self.w,self.f,self.n]
        elif order=='S':
            return [self.n,self.f,self.e,self.w,self.b,self.s]

        elif order=='E':
            return [self.w,self.s,self.f,self.b,self.n,self.e]
        else:
            return [self.e,self.s,self.b,self.f,self.n,self.w]
    @classmethod
    def Dice_create(cls,num):
            return cls(num)


num=list(map(int,input().split()))
command=input()
dice=Dice(num)
for i in range(len(command)):
    temp=dice.create(command[i])
    dice=Dice.Dice_create(temp)
print(dice.f)

Solution (Python):
d = [_ for _ in input().split()]

commands = input()

for c in commands:
  if c == 'E':
    d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
  elif c == 'W':
    d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]
  elif c == 'N':
    d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
  elif c == 'S':
    d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]

print(d[0])

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

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

d = dice([_ for _ in input().split()])

commands = input()
for c in commands:
  d.roll(c)
d.print()

Solution (Python):
label = input().split()
rot = input()

dice = {
        "top":1,
        "front":2,
        "right":3,
        "left":4,
        "back":5,
        "bottom":6
        }

for r in rot:
    if r == 'E':
        t = dice["top"]
        dice["top"] = dice["left"]
        dice["left"] = dice["bottom"]
        dice["bottom"] = dice["right"]
        dice["right"] = t
    elif r == 'N':
        t = dice["top"]
        dice["top"] = dice["front"]
        dice["front"] = dice["bottom"]
        dice["bottom"] = dice["back"]
        dice["back"] = t
    elif r == 'S':
        t = dice["top"]
        dice["top"] = dice["back"]
        dice["back"] = dice["bottom"]
        dice["bottom"] = dice["front"]
        dice["front"] = t
    elif r == 'W':
        t = dice["top"]
        dice["top"] = dice["right"]
        dice["right"] = dice["bottom"]
        dice["bottom"] = dice["left"]
        dice["left"] = t
print(label[dice["top"]-1])