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__(self,t,f,r,l,ba,bo):
        self.t = t
        self.f = f
        self.r = r
        self.l = l
        self.ba = ba
        self.bo = bo

s = input().split(" ")
dice = Dice(s[0],s[1],s[2],s[3],s[4],s[5])
s = input()
for i in range(len(s)):
    if s[i] == "E":
        a = dice.t
        b = dice.r
        c = dice.bo
        d = dice.l
        dice.r = a
        dice.bo = b
        dice.l = c
        dice.t = d
    elif s[i] == "N":
        a = dice.t
        b = dice.f
        c = dice.bo
        d = dice.ba
        dice.ba = a
        dice.t = b
        dice.f = c
        dice.bo = d
    elif s[i] == "S":
        a = dice.t
        b = dice.f
        c = dice.bo
        d = dice.ba
        dice.f = a
        dice.bo = b
        dice.ba = c
        dice.t = d
    else:
        a = dice.t
        b = dice.r
        c = dice.bo
        d = dice.l
        dice.l = a
        dice.t = b
        dice.r = c
        dice.bo = d
print(dice.t)

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

Solution (Python):
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 = [dice for dice in input().split()]
dice_t = ["" for dice_t in range(6)]
direction = input()
for d in direction:
    if d == "N":
        for i in range(6):
            dice_t[i] = dice[N[i]]
    elif d == "S":
        for i in range(6):
            dice_t[i] = dice[S[i]]
    elif d == "E":
        for i in range(6):
            dice_t[i] = dice[E[i]]
    else:
        for i in range(6):
            dice_t[i] = dice[W[i]]
    for i in range(6):
        dice[i] = dice_t[i]

print(dice[0])

Solution (Python):
class Dice:
    def __init__(self):
        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 roll(self, dice, dice_t, direction):
        for d in direction:
            if d == "N":
                for i in range(6):
                    dice_t[i] = dice[self.N[i]]
            elif d == "S":
                for i in range(6):
                    dice_t[i] = dice[self.S[i]]
            elif d == "E":
                for i in range(6):
                    dice_t[i] = dice[self.E[i]]
            else:
                for i in range(6):
                    dice_t[i] = dice[self.W[i]]
            for i in range(6):
                dice[i] = dice_t[i]

d = Dice()
dice = [dice for dice in input().split()]
dice_t = ["" for dice_t in range(6)]
direction = input()
d.roll(dice, dice_t, direction)
print(dice[0])

Solution (Python):
u, s, e, w, n, d = input().split()
insts = input()
for inst in insts:
    if inst == 'N':
        u, s, n, d = s, d, u, n
    elif inst == 'E':
        u, e, w, d = w, u, d, e
    elif inst == 'S':
        u, s, n, d = n, u, d, s
    elif inst == 'W':
        u, e, w, d = e, d, u, w
print(u)

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

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

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

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

Solution (Python):


"""
???????????? I

?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????
   +--+
 ???|???|
+--+--+--+--+
|???|???|???|???|
+--+--+--+--+
 ???|???|
   +--+

"""
class Dice:
    """ ????????????????????? """
    def __init__(self):                  
        self.side = [1, 2, 3, 4, 5, 6]

    def setDice(self, arr):  
        self.side = arr[0:6]

    def Turn(self, dir):
        s = self.side

        if dir == "N":     
            t = [s[1],s[5],s[2],s[3],s[0],s[4]]
        elif dir == "S": 
            t = [s[4],s[0],s[2],s[3],s[5],s[1]]
        elif dir == "E": 
            t = [s[3],s[1],s[0],s[5],s[4],s[2]]
        elif dir == "W": 
            t = [s[2],s[1],s[5],s[0],s[4],s[3]]

        self.side = t




num = list(map(int,input().strip().split()))
cmd = input().strip()
d = Dice()
d.setDice(num)
for c in cmd:
    d.Turn(c)

print(d.side[0])

Solution (Python):


"""
???????????? I

?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°????????????????????????????????????
   +--+
 ???|???|
+--+--+--+--+
|???|???|???|???|
+--+--+--+--+
 ???|???|
   +--+

"""

class Dice:
    T = 0
    S = 1
    E = 2
    W = 3
    N = 4
    B = 5

    """ ????????????????????? """
    def __init__(self): 
        self.side = [1, 2, 3, 4, 5, 6]
        self.top = 0

    def setDice(self, arr):  
        self.side = arr[0:6]

    def Turn(self, dir): 
        s = self.side

        if dir == "N":     
            
            t = [s[Dice.S],s[Dice.B],s[Dice.E],s[Dice.W],s[Dice.T],s[Dice.N]]
        elif dir == "S": 
            t = [s[Dice.N],s[Dice.T],s[Dice.E],s[Dice.W],s[Dice.B],s[Dice.S]]
        elif dir == "E": 
            t = [s[Dice.W],s[Dice.S],s[Dice.T],s[Dice.B],s[Dice.N],s[Dice.E]]
        elif dir == "W": 
            t = [s[Dice.E],s[Dice.S],s[Dice.B],s[Dice.T],s[Dice.N],s[Dice.W]]

        self.side = t


num = list(map(int,input().strip().split()))
cmd = input().strip()
d = Dice()
d.setDice(num)
for c in cmd:
    d.Turn(c)
print(d.side[0])

Solution (Python):
def CP(a,b):
	x = a[1]*b[2]-a[2]*b[1]
	y = a[2]*b[0]-a[0]*b[2]
	z = a[0]*b[1]-a[1]*b[0]
	return (x,y,z)

minus = lambda d:tuple(-i for i in d)

class dice:
	def __init__(self,data):
		names = [(1,0,0),(0,0,1),(0,1,0),(0,-1,0),(0,0,-1),(-1,0,0)]
		self.faces = {n:d for n,d in zip(names,data)}
		self.top = (1,0,0)
		self.north = (0,0,-1)
	
	def turn(self,direction):
		if direction == 'N':
			self.top,self.north = minus(self.north),self.top
		elif direction == 'S':
			[self.turn('N') for i in range(3)]
		elif direction == 'W':
			self.top = CP(self.top,self.north)
		elif direction == 'E':
			[self.turn('W') for i in range(3)]

if __name__ == '__main__':
	data = [int(i) for i in input().split()]
	operations = input()
	d = dice(data)
	[d.turn(o) for o in operations]
	print(d.faces[d.top])

Solution (Python):
x1,x2,x3,x4,x5,x6 = map(int,(input().split()))
t = input()
x=x1


L=[x1,x2,x3,x4,x5,x6]
n= len(t)
T=[]
M=[]
for i in range(n):
    T.append(t[:1])
    t=t[1:]



for i in T:
    if i is "S":
        L = [L[4],L[0],L[2],L[3],L[5],L[1]]
    elif i is "E":
        L = [L[3], L[1], L[0], L[5], L[4], L[2]]
    elif i is "N":
        L = [L[1], L[5], L[2], L[3], L[0], L[4]]
    else:
        L = [L[2], L[1], L[5], L[0], L[4], L[3]]



print(L[0])

Solution (Python):
class dice():
    def __init__(self,men1,men2,men3,men4,men5,men6):
        self.men=[men1,men2,men3,men4,men5,men6]
        self.current_men=1
        self.men_udlr=[5,2,4,3]
        self.move_d=0
        
    def move_dice(self,direction): 
        if direction=="E":
            s=self.men_udlr[2]
            self.men_udlr=[self.men_udlr[0],self.men_udlr[1],
                          7-self.current_men,self.current_men]
            self.current_men=s
        if direction=="N":
            s=self.men_udlr[1]
            self.men_udlr=[self.current_men,7-self.current_men
                           ,self.men_udlr[2],self.men_udlr[3]]
            self.current_men=s
        if direction=="S":
            s=self.men_udlr[0]
            self.men_udlr=[7-self.current_men,self.current_men
                           ,self.men_udlr[2],self.men_udlr[3]]
            self.current_men=s
        if direction=="W":
            s=self.men_udlr[3]
            self.men_udlr=[self.men_udlr[0],self.men_udlr[1]
                           ,self.current_men
                           ,7-self.current_men]
            self.current_men=s
        
    def show_num(self):

        return self.men[self.current_men-1]

m_n=list(map(int,input().split()))
cmd=input()
d=dice(*m_n)
for c in cmd:
    d.move_dice(c)
print(d.show_num())

Solution (Python):
class Dice:
    __slots__ = ['n1', 'n2', 'n3', 'n4', 'n5', 'n6']

    def __init__(self, n_tup):

        self.n1 = n_tup[0]
        self.n2 = n_tup[1]
        self.n3 = n_tup[2]
        self.n4 = n_tup[3]
        self.n5 = n_tup[4]
        self.n6 = n_tup[5]

    def roll(self, direction):
        if direction == "N":
            self.n1, self.n2, self.n6, self.n5 \
                = self.n2, self.n6, self.n5, self.n1
        elif direction == "E":
            self.n1, self.n3, self.n6, self.n4 \
                = self.n4, self.n1, self.n3, self.n6
        if direction == "S":
            self.n1, self.n2, self.n6, self.n5 \
                = self.n5, self.n1, self.n2, self.n6
        if direction == "W":
            self.n1, self.n3, self.n6, self.n4 \
                = self.n3, self.n6, self.n4, self.n1

dice = Dice([int(x) for x in input().split()])

cmd = input()
for i in range(len(cmd)):
    dice.roll(cmd[i])

print(dice.n1)

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

die = list(map(int, input().split()))
queue = input()
for i in range(len(queue)):
    die = roll(die, queue[i])
print(die[0])

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

    def roll(self, op):
        d = self.d
        if op == 'N':
            self.d = [d[1], d[5], d[2], d[3], d[0], d[4]]
        elif op == 'E':
            self.d = [d[3], d[1], d[0], d[5], d[4], d[2]]
        elif op == 'W':
            self.d = [d[2], d[1], d[5], d[0], d[4], d[3]]
        elif op == 'S':
            self.d = [d[4], d[0], d[2], d[3], d[5], d[1]]
label=list(map(int,input().split()))
oplist=list(input())
do=dice(label)
for op in oplist :
        do.roll(op)
print(do.d[0])

Solution (Python):

D=[int(i) for i in input().split()]
Os=input()
for i in range(len(Os)):
    if Os[i]=="N":
        t=D[0]
        D[0]=D[1]
        D[1]=D[5]
        D[5]=D[4]
        D[4]=t
    elif Os[i]=="S":
        t=D[0]
        D[0]=D[4]
        D[4]=D[5]
        D[5]=D[1]
        D[1]=t        
    elif Os[i]=="E":
        t=D[0]
        D[0]=D[3]
        D[3]=D[5]
        D[5]=D[2]
        D[2]=t        
    elif Os[i]=="W":
        t=D[0]
        D[0]=D[2]
        D[2]=D[5]
        D[5]=D[3]
        D[3]=t        
print(D[0])

Solution (Python):


import sys, math, os


PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def do_roll(dice, roll):
    d1, d2, d3, d4, d5, d6 = dice
    if roll == 'E':
        return [d4, d2, d1, d6, d5, d3]
    elif roll == 'W':
        return [d3, d2, d6, d1, d5, d4]
    elif roll == 'N':
        return [d2, d6, d3, d4, d1, d5]
    elif roll == 'S':
        return [d5, d1, d3, d4, d6, d2]
    else:
        assert False, "We should never reach this point!"
    

dice = [int(_) for _ in input().split()]
for roll in input().strip():
    dice = do_roll(dice, roll)

print(dice[0])

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

    def get_top(self):
        return self.top

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

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

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

dice = Dice(list(map(int,input().split())))
for i in input():
    if i == "N":
        dice.rotate_north()
    elif i == "E":
        dice.rotate_east()
    elif i == "W":
        dice.rotate_west()
    elif i == "S":
        dice.rotate_south()

top=dice.get_top()
print(top)

Solution (Python):
def North(dice):
    w = dice[0]
    dice[0] = dice[1]
    dice[1] = dice[5]
    dice[5] = dice[4]
    dice[4] = w
    return dice
def East(dice):
    w = Dice[0]
    dice[0] = dice[3]
    dice[3] = dice[5]
    dice[5] = dice[2]
    dice[2] = w
    return dice
def South(dice):
    w = dice[0]
    dice[0] = dice[4]
    dice[4] = dice[5]
    dice[5] = dice[1]
    dice[1] = w
    return dice
def West(dice):
    w = dice[0]
    dice[0] = dice[2]
    dice[2] = dice[5]
    dice[5] = dice[3]
    dice[3] = w
    return dice

Dice = input().split()
Roll = list(input())

for roll in Roll:
    if roll == 'N':
        Dice = North(Dice)
        continue
    if roll == 'E':
        Dice = East(Dice)
        continue
    if roll == 'S':
        Dice = South(Dice)
        continue
    if roll == 'W':
        Dice = West(Dice)
        continue

print(Dice[0])

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

up = 1
front = 2
right = 3

move = "NSEW"

for m in order:
    i = move.index(m)
    if i == 0:
        up, front = front, 7 - up
    elif i == 1:
        up, front = 7 - front, up
    elif i == 2:
        up, right = 7 - right, up
    else:
        up, right = right, 7 - up

print(data[up - 1])

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

up = 1
front = 2
right = 3

move = "NSEW"

for m in order:
    i = move.index(m)
    if i == 0:
        up, front = front, 7 - up
    elif i == 1:
        up, front = 7 - front, up
    elif i == 2:
        up, right = 7 - right, up
    else:
        up, right = right, 7 - up

print(data[up - 1])

Solution (Python):
class State:
    d = {
        "E": lambda l: zip((0, 2, 3, 5), (l[3], l[0], l[5], l[2])),
        "N": lambda l: zip((0, 1, 4, 5), (l[1], l[5], l[0], l[4])),
        "S": lambda l: zip((0, 1, 4, 5), (l[4], l[0], l[5], l[1])),
        "W": lambda l: zip((0, 2, 3, 5), (l[2], l[5], l[0], l[3]))
        }

    def __init__(self, s, t):
        self.pos = list(range(1, 7))
        self.pip = s.split()
        self.log = t

    def __call__(self):
        for c in self.log:
            for i, v in self.d[c](self.pos):
                self.pos[i] = v

    def __str__(self):
        return self.pip[self.pos[0]-1]

state = State(input(), input())
state()
print(state)

Solution (Python):
sur={1:0,2:0,3:0,4:0,5:0,6:0}
inputs=input().split()
for i in range(6):
    sur[i+1]=int(inputs[i])
dir_of_roll=input()
for i in range(len(dir_of_roll)):
    copy_sur=sur.copy()
    if dir_of_roll[i]=='N':
        sur[1]=copy_sur[2]
        sur[2]=copy_sur[6]
        sur[6]=copy_sur[5]
        sur[5]=copy_sur[1]
    elif dir_of_roll[i]=='S':
        sur[1]=copy_sur[5]
        sur[5]=copy_sur[6]
        sur[6]=copy_sur[2]
        sur[2]=copy_sur[1]
    elif dir_of_roll[i]=='W':
        sur[1]=copy_sur[3]
        sur[3]=copy_sur[6]
        sur[6]=copy_sur[4]
        sur[4]=copy_sur[1]
    elif dir_of_roll[i]=='E':
        sur[1]=copy_sur[4]
        sur[4]=copy_sur[6]
        sur[6]=copy_sur[3]
        sur[3]=copy_sur[1]

print(sur[1])

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

Solution (Python):
class Dice:

    __dSNWE ={'S': (4, 0, 2, 3, 5, 1) , 'N': (1, 5, 2, 3, 0, 4),
             'W': (2, 1, 5, 0, 4, 3), 'E': (3, 1, 0, 5, 4, 2)}

    def __init__(self, v): 
        self.view = v


    def rotateDice(self, direction):
        self.view = [self.view[i] for i in Dice.__dSNWE[direction]]

d1 = Dice(list(map(int, input().split())))
for d in input():
    d1.rotateDice(d)
print(d1.view[0])

Solution (Python):

def move_func(dice_list, dir):
	new_dice = []
	if dir=="N":
		new_dice.append(dice_list[1])
		new_dice.append(dice_list[5])
		new_dice.append(dice_list[2])
		new_dice.append(dice_list[3])
		new_dice.append(dice_list[0])
		new_dice.append(dice_list[4])
	elif dir=="E":
		new_dice.append(dice_list[3])
		new_dice.append(dice_list[1])
		new_dice.append(dice_list[0])
		new_dice.append(dice_list[5])
		new_dice.append(dice_list[4])
		new_dice.append(dice_list[2])
	elif dir=="S":
		new_dice.append(dice_list[4])
		new_dice.append(dice_list[0])
		new_dice.append(dice_list[2])
		new_dice.append(dice_list[3])
		new_dice.append(dice_list[5])
		new_dice.append(dice_list[1])
	elif dir=="W":
		new_dice.append(dice_list[2])
		new_dice.append(dice_list[1])
		new_dice.append(dice_list[5])
		new_dice.append(dice_list[0])
		new_dice.append(dice_list[4])
		new_dice.append(dice_list[3])
	return new_dice

try:
	while True:
		dice_list = input().split(" ")
		move_cmd = input()
		for cmd in  move_cmd:
			dice_list = move_func(dice_list, cmd)
			
		print(dice_list[0])
except EOFError:
	pass

Solution (Python):
class Dice:
    def __init__(self):
        self.dice=[1,2,3,4,5,6] 
    def set(self,l):
        self.dice=l
    def roll(self, s):
        import copy
        mat=((1,4,3,2),(5,0,1,1),(2,2,0,5),(3,3,5,0),(0,5,4,4),(4,1,2,3))
        l=copy.deepcopy(self.dice)
        if s == 'N': c = 0
        if s == 'S': c = 1
        if s == 'E': c = 2
        if s == 'W': c = 3
        for i in range(6):
            self.dice[i]=l[mat[i][c]]
    def get(self):
        return self.dice

d=Dice()
d.set(list(map(int,input().split())))
s=input()
for i in range(len(s)):
    d.roll(s[i])
print(d.get()[0])

Solution (Python):
class Dice(object):
    
    def __init__(self, line):
        self.top = 1
        self.bottom = 6
        self.south = 2
        self.east = 3
        self.west = 4
        self.north = 5
        self.convert = line.split()
    
    def move(self, direction):
        if 'N' == direction:
            self.top, self.north, self.bottom, self.south = self.south, self.top, self.north, self.bottom
        elif 'S' == direction:
            self.top, self.north, self.bottom, self.south = self.north, self.bottom, self.south, self.top
        elif 'W' == direction:
            self.top, self.east, self.bottom, self.west = self.east, self.bottom, self.west, self.top
        elif 'E' == direction:
            self.top, self.east, self.bottom, self.west = self.west, self.top, self.east, self.bottom
    
    def result(self):
        return self.convert[self.top - 1]
    
dice = Dice(input())
for direction in input():
    dice.move(direction)

print(dice.result())

Solution (Python):
currAndRot2FBLR = {
    'N':{'N':'F','E':'R','S':'B','W':'L'},
    'E':{'E':'F','S':'R','W':'B','N':'L'},
    'S':{'S':'F','W':'R','N':'B','E':'L'},
    'W':{'W':'F','N':'R','E':'B','S':'L'}
}

dice = {
    '1': {'F':'2F', 'R':'4R', 'B':'5B', 'L':'3L'},
    '2': {'F':'6F', 'R':'4F', 'B':'1F', 'L':'3F'},
    '3': {'F':'6L', 'R':'2F', 'B':'1R', 'L':'5F'},
    '4': {'F':'6R', 'R':'5F', 'B':'1L', 'L':'2F'},
    '5': {'F':'6B', 'R':'3F', 'B':'1B', 'L':'4F'},
    '6': {'F':'5B', 'R':'4L', 'B':'2F', 'L':'3R'}
}

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


currNum = '1'
currDir = 'N'

for c in cmd:
    numDir = dice[currNum][currAndRot2FBLR[currDir][c]]
    currNum = numDir[0]
    currFBLR = numDir[1]
    currDir = {v:k for k,v in currAndRot2FBLR[currDir].items()}[currFBLR]

print(faces[int(currNum) - 1])

Solution (Python):
class Dice:
    dice = {'N':2, 'E':4, 'S':5, 'W':3}
    currTop = 1

    def top(self):
        return self.currTop

    def rot(self, direction):
        newTop = self.dice[direction]
        currTop = self.currTop
        self.currTop = newTop
        if direction == 'N':
            self.dice['N'] = 7 - currTop
            self.dice['S'] = currTop
        elif direction == 'S':
            self.dice['N'] = currTop
            self.dice['S'] = 7 - currTop
        elif direction == 'E':
            self.dice['E'] = 7 - currTop
            self.dice['W'] = currTop
        elif direction == 'W':
            self.dice['E'] = currTop
            self.dice['W'] = 7 - currTop


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

d = Dice()
for c in cmd:
    d.rot(c)

print(faces[d.top()-1])

Solution (Python):
class Dice:
    def __init__(self):
        self.dice = {'N':2, 'E':4, 'S':5, 'W':3}
        self.currTop = 1

    def top(self):
        return self.currTop

    def rot(self, direction):
        newTop = self.dice[direction]
        currTop = self.currTop
        self.currTop = newTop
        if direction == 'N':
            self.dice['N'] = 7 - currTop
            self.dice['S'] = currTop
        elif direction == 'S':
            self.dice['N'] = currTop
            self.dice['S'] = 7 - currTop
        elif direction == 'E':
            self.dice['E'] = 7 - currTop
            self.dice['W'] = currTop
        elif direction == 'W':
            self.dice['E'] = currTop
            self.dice['W'] = 7 - currTop


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

d = Dice()
for c in cmd:
    d.rot(c)

print(faces[d.top()-1])

Solution (Python):


class Dice:

    def __init__(self, diceList):
        self.d1, self.d2, self.d3, self.d4, self.d5, self.d6 = diceList

    def diceRoll(self, r):
        if(r == 'N'):
            self.d1, self.d2, self.d5, self.d6 = self.d2, self.d6, self.d1, self.d5

        elif(r == 'E'):
            self.d1, self.d3, self.d4, self.d6 = self.d4, self.d1, self.d6, self.d3

        elif(r == 'W'):
            self.d1, self.d3, self.d4, self.d6 = self.d3, self.d6, self.d1, self.d4

        elif(r == 'S'):
            self.d1, self.d2, self.d5, self.d6 = self.d5, self.d1, self.d6, self.d2


def main():

    inputDiceList = list(map(int, input().split()))
    rollList = list(input())

    d = Dice(inputDiceList)

    for i in rollList:
        d.diceRoll(i)

    print(d.d1)

if __name__ == '__main__':
    main()

Solution (Python):
def east(dice):
    buff = [d for d in dice]
    dice[0] = buff[3]
    dice[2] = buff[0]
    dice[5] = buff[2]
    dice[3] = buff[5]


def west(dice):
    buff = [d for d in dice]
    dice[0] = buff[2]
    dice[2] = buff[5]
    dice[5] = buff[3]
    dice[3] = buff[0]


def north(dice):
    buff = [d for d in dice]
    dice[0] = buff[1]
    dice[1] = buff[5]
    dice[5] = buff[4]
    dice[4] = buff[0]


def south(dice):
    buff = [d for d in dice]
    dice[0] = buff[4]
    dice[1] = buff[0]
    dice[5] = buff[1]
    dice[4] = buff[5]


dice = list(map(int, input().split()))
commands = input()

for c in commands:
    if c == "E":
        east(dice)
    elif c == "W":
        west(dice)
    elif c == "N":
        north(dice)
    elif c == "S":
        south(dice)
    else:
        break

print(dice[0])

Solution (Python):
def main():
    values = list(map(int, input().split()))
    query = input()

    dice = Dice(values)
    for d in query:
        dice.roll(d)

    print(dice.top_value)


class Dice:

    def __init__(self, values):
        self.values = values
        
        self.t = 1
        self.b = 6
        self.w = 4
        self.e = 3
        self.n = 5
        self.s = 2

    def __repr__(self):
        labels = {
            "t": self.t,
            "b": self.b,
            "w": self.w,
            "e": self.e,
            "n": self.n,
            "s": self.s,
        }
        return "<%s (%s, %s)>" % (self.__class__, self.values, labels)

    def roll(self, direction):
        if direction == "E":
            after_lables = self.t, self.b, self.e, self.w
            self.e, self.w, self.b, self.t = after_lables
        elif direction == "W":
            after_lables = self.t, self.b, self.e, self.w
            self.w, self.e, self.t, self.b = after_lables
        elif direction == "S":
            after_lables = self.t, self.b, self.n, self.s
            self.s, self.n, self.t, self.b = after_lables
        elif direction == "N":
            after_lables = self.t, self.b, self.n, self.s
            self.n, self.s, self.b, self.t = after_lables

    @property
    def top_value(self):
        return self.values[self.t - 1]

if __name__ == "__main__":
    main()

Solution (Python):
class Dice:
    def __init__(self,faces):
        self.faces = tuple(faces)
    def N(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])
    def S(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])
    def W(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])
    def E(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])
    def number(self, face_id):
        return self.faces[face_id - 1]
dice = Dice(list(map(int, input().split())))
x=input()
 
for i in x:
    if i == "N":
        dice.N()
    elif i == "S":
        dice.S()
    elif i == "W":
        dice.W()
    elif i == "E":
        dice.E()
print(dice.number(1))

Solution (Python):
class Dice:
    def __init__(self,faces):
        self.faces = tuple(faces)
    def N(self):
        self.faces = (self.faces[1], self.faces[5], self.faces[2],
                      self.faces[3], self.faces[0], self.faces[4])
    def S(self):
        self.faces = (self.faces[4], self.faces[0], self.faces[2],
                      self.faces[3], self.faces[5], self.faces[1])
    def W(self):
        self.faces = (self.faces[2], self.faces[1], self.faces[5],
                      self.faces[0], self.faces[4], self.faces[3])
    def E(self):
        self.faces = (self.faces[3], self.faces[1], self.faces[0],
                      self.faces[5], self.faces[4], self.faces[2])
    def number(self, face_id):
        return self.faces[face_id - 1]
dice = Dice(list(map(int, input().split())))
x=input()
 
for i in x:
    if i == "N":dice.N()
    elif i == "S":dice.S()
    elif i == "W":dice.W()
    elif i == "E":dice.E()
print(dice.number(1))

Solution (Python):
class dice:
    directions = ['S', 'E', 'N', 'W']
    def __init__(self, strlabels):
        label = strlabels.split()
        self.top = label[0]
        self.side = label[1:5]
        self.side[2], self.side[3] = self.side[3], self.side[2]
        self.down = label[5]
        

    def roll(self, direction):
        tmp = self.top
        self.top = self.side[(self.directions.index(direction)+2)%4]
        self.side[(self.directions.index(direction)+2)%4] = self.down
        self.down = self.side[self.directions.index(direction)]
        self.side[self.directions.index(direction)] = tmp
        

    def pFace(self, initial):
        if initial == 'u':
            print(self.top)
        elif initial == 'd':
            print(self.down)
        else:
            print(self.side[directions.index(direction)])

dice1 = dice(input())
for direction in input():
    dice1.roll(direction)

dice1.pFace('u')