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

INVERSE_ROTATIONS = {
    'N': [
        [1, 0, 0],
        [0, 0, -1],
        [0, 1, 0]
    ],
    'S': [
        [1, 0, 0],
        [0, 0, 1],
        [0, -1, 0]
    ],
    'E': [
        [0, 0, -1],
        [0, 1, 0],
        [1, 0, 0]
    ],
    'W': [
        [0, 0, 1],
        [0, 1, 0],
        [-1, 0, 0]
    ]
}


def mul(mat1, mat2):
    return [
        [
            sum(mat1[i][k] * mat2[k][j] for k in range(3))
            for j in range(3)
        ]
        for i in range(3)
    ]


faces = [int(n) for n in sys.stdin.readline().strip().split()]
commands = sys.stdin.readline().strip()

rotation = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
for c in commands:
    rotation = mul(rotation, INVERSE_ROTATIONS[c])
location = [rotation[i][2] for i in range(3)]

number = {
    (1, 0, 0): 3,
    (-1, 0, 0): 4,
    (0, 1, 0): 5,
    (0, -1, 0): 2,
    (0, 0, 1): 1,
    (0, 0, -1): 6
}[tuple(location)]

print(faces[number - 1])

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

Solution (Python):
class Dice:
    def __init__(self, face_val=None):
        self.top = 1
        self.front = 2
        self.left = 4
        self.FaceValue = {}
        if face_val is None or len(face_val) != 6:
            face_val = [1, 2, 3, 4, 5, 6]

        for i, val in enumerate(face_val):
            self.FaceValue[i+1] = val

    def dice_move(self, direction):
        if direction == 'S':
            tmp = self.top
            self.top = 7 - self.front
            self.front = tmp
        elif direction == 'W':
            tmp = self.top
            self.top = 7 - self.left
            self.left = tmp
        elif direction == 'E':
            tmp = self.top
            self.top = self.left
            self.left = 7 - tmp
        elif direction == 'N':
            tmp = self.top
            self.top = self.front
            self.front = 7 - tmp

    def top_value(self):
        return self.FaceValue[self.top]

    def __repr__(self):
        return f'({self.top},{self.front},{self.left})'


faces = input().split()
directions = input()

dice = Dice(faces)
for direction in directions:
    
    dice.dice_move(direction)
    

print(dice.top_value())

Solution (Python):
import math
def main():
    dice = Dice([int(a) for a in input().split()])
    commands = input()
    for d in range(len(commands)):
        dice.move(commands[d])
    dice.show()

class Dice():
    def __init__(self, surface):
        self.l = surface
 
    def move(self, dir):
        if(dir == 'N'):
            self.l = [self.l[1], self.l[5], self.l[2], self.l[3], self.l[0], self.l[4]]
        elif(dir == 'W'):
            self.l = [self.l[2], self.l[1], self.l[5], self.l[0], self.l[4], self.l[3]]
        elif(dir == 'E'):
            self.l = [self.l[3], self.l[1], self.l[0], self.l[5], self.l[4], self.l[2]]
        elif(dir == 'S'):
            self.l = [self.l[4], self.l[0], self.l[2], self.l[3], self.l[5], self.l[1]]

    def show(self):
        print(self.l[0])


main()

Solution (Python):



class Dice(object):
    def __init__(self, top, front, right, left, back, bottom):
        self.t = top
        self.f = front
        self.r = right
        self.l = left
        self.bc = back
        self.bt = bottom

    def roll(self, direction):
        if direction == 'N':
            self.t, self.f, self.bt, self.bc = self.f, self.bt, self.bc, self.t
        elif direction == 'S':
            self.t, self.f, self.bt, self.bc = self.bc, self.t, self.f, self.bt
        elif direction == 'E':
            self.t, self.l, self.bt, self.r = self.l, self.bt, self.r, self.t
        elif direction == 'W':
            self.t, self.l, self.bt, self.r = self.r, self.t, self.l, self.bt

    def show_top(self):
        print(self.t)

    def __str__(self):
        
        return f'{self.t}, {self.f}, {self.r}, {self.l}, {self.bc}, {self.bt}'


def solve():
    dice = Dice(*input().split())

    for direction in input():
        dice.roll(direction)
    dice.show_top()


if __name__ == '__main__':
    solve()

Solution (Python):



class Dice:
    def __init__(self, *num):
        if len(num) != 6:
            raise ValueError("6!")
        self.numbers = num

    def east(self):
        index = (3, 1, 0, 5, 4, 2)
        self.numbers = tuple((self.numbers[i] for i in index))

    def west(self):
        index = (2, 1, 5, 0, 4, 3)
        self.numbers = tuple((self.numbers[i] for i in index))

    def south(self):
        index = (4, 0, 2, 3, 5, 1)
        self.numbers = tuple((self.numbers[i] for i in index))

    def north(self):
        index = (1, 5, 2, 3, 0, 4)
        self.numbers = tuple((self.numbers[i] for i in index))

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

    def __repr__(self):
        return "Dice(" + ", ".join([str(i) for i in self.numbers]) + ")"


def main():
    num = [int(i) for i in input().rstrip().split()]
    dice = Dice(*num)
    for i in input().rstrip():
        if i == "E":
            dice.east()
        elif i == "W":
            dice.west()
        elif i == "S":
            dice.south()
        elif i == "N":
            dice.north()
    print(dice.top)

if __name__ == "__main__":
    main()

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:
    diceNum = []
    pos = 0
    def setNum(self,i):
        self.pos = i[0]
        self.diceNum.append(i[0])
        self.diceNum.append(i[2])
        self.diceNum.append(i[5])
        self.diceNum.append(i[3])
        self.diceNum.append(i[4])
        self.diceNum.append(i[1])
    def showPos(self):
        print (self.pos)
    def move(self,d):
        if (d == "E"):
            i0=self.diceNum[3]
            i1=self.diceNum[0] 
            i2=self.diceNum[1] 
            i3=self.diceNum[2]
            i4=self.diceNum[4]
            i5=self.diceNum[5]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
            self.pos = self.diceNum[0]
        if (d == "W"):
            i0=self.diceNum[1]
            i1=self.diceNum[2] 
            i2=self.diceNum[3] 
            i3=self.diceNum[0]
            i4=self.diceNum[4]
            i5=self.diceNum[5]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
            self.pos = self.diceNum[0]
        if (d == "S"):
            i0=self.diceNum[4]
            i1=self.diceNum[1] 
            i2=self.diceNum[5] 
            i3=self.diceNum[3]
            i4=self.diceNum[2]
            i5=self.diceNum[0]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
            self.pos = self.diceNum[0]
        if (d == "N"):
            i0=self.diceNum[5]
            i1=self.diceNum[1] 
            i2=self.diceNum[4] 
            i3=self.diceNum[3]
            i4=self.diceNum[0]
            i5=self.diceNum[2]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
            self.pos= self.diceNum[0]

l = list(map(int,input().split()))
dice = Dice()
dice.setNum(l)
for i in str(input()):
    dice.move(i)
dice.showPos()

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

def roll(Dice,Vector):
    if Vector == "N":
        c=Dice[0]
        Dice[0]=Dice[1]
        Dice[1]=Dice[5]
        Dice[5]=Dice[4]
        Dice[4]=c
    elif Vector == "W":
        c=Dice[0]
        Dice[0]=Dice[2]
        Dice[2]=Dice[5]
        Dice[5]=Dice[3]
        Dice[3]=c
    elif Vector == "E":
        c=Dice[0]
        Dice[0]=Dice[3]
        Dice[3]=Dice[5]
        Dice[5]=Dice[2]
        Dice[2]=c
    elif Vector == "S":
        c=Dice[0]
        Dice[0]=Dice[4]
        Dice[4]=Dice[5]
        Dice[5]=Dice[1]
        Dice[1]=c

for item in v:
    roll(d,item)
print(d[0])

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

for s in slist:
    if s == "N":
        next = list("263415")
    elif s == "E":
        next = list("421653")
    elif s == "S":
        next = list("513462")
    else:
        next = list("326154")

    tmp = [0] * 6
    for i, n in enumerate(next):
        tmp[i] = dice[int(n)-1]

    dice = tmp

print(dice[0])

Solution (Python):
r={'N':(1,5,2,3,0,4),'S':(4,0,2,3,5,1),'E':(3,1,0,5,4,2),'W':(2,1,5,0,4,3)}
d=input().split()
for x in input():
    d=[d[y]for y in r[x]]
print(d[0])

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

Solution (Python):
def swap(dice,i,j,k,l):
    x=dice[l]
    dice[l]=dice[k]
    dice[k]=dice[j]
    dice[j]=dice[i]
    dice[i]=x
    return dice


dice=list(map(int,input().split()))
Dice=[0]
dice=Dice +dice
roll=list(input())
for i in range(0,len(roll)):
    if(roll[i]=="S"):
        dice=swap(dice,1,2,6,5)
    elif(roll[i]=="E"):
        dice=swap(dice,1,3,6,4)
    elif(roll[i]=="W"):
        dice=swap(dice,1,4,6,3)
    elif(roll[i]=="N"):
        dice=swap(dice,1,5,6,2)
print(dice[1])

Solution (Python):
from collections import OrderedDict
d = list(map(int, input().split()))
command = input()
p = OrderedDict()
for k, v in zip(["T", "N", "S", "E", "W", "B"], [d[0], d[4], d[1], d[2], d[3], d[5]]):
    p[k] = v

for c in command:
    t, n, s, e, w, b = p["T"], p["N"], p["S"], p["E"], p["W"], p["B"]
    if c == "N":
        p["N"], p["T"], p["S"], p["B"]= t, s, b, n
    if c == "S":
        p["N"], p["T"], p["S"], p["B"]= b, n, t, s
    if c == "E":
        p["E"], p["T"], p["W"], p["B"]= t, w, b, e
    if c == "W":
        p["E"], p["T"], p["W"], p["B"]= b, e, t, w
    
print(p["T"])

Solution (Python):
a,b,c,d,e,f=list(map(int,input().split()))
for g in input():
 if g=='N':a,e,f,b=b,a,e,f
 if g=='E':a,c,f,d=d,a,c,f
 if g=='W':a,c,f,d=c,f,d,a
 if g=='S':a,e,f,b=e,f,b,a
print(a)

Solution (Python):
num = input().split()
r = input()

for i in r:
    temp = num[0]
    if (i == 'W'): 
        num[0] = num[2]
        num[2] = num[5]
        num[5] = num[3]
        num[3] = temp
    elif (i == 'E'):
        num[0] = num[3]
        num[3] = num[5]
        num[5] = num[2]
        num[2] = temp
    elif (i == 'S'):
        num[0] = num[4]
        num[4] = num[5]
        num[5] = num[1]
        num[1] = temp
    else :
        num[0] = num[1]
        num[1] = num[5]
        num[5] = num[4]
        num[4] = temp

print(num[0])

Solution (Python):
dice = list(map(int, input().split()))
dir = list(input())
newdice = [0]*6

for i in dir:
    if i == 'N':
        newdice[0] = dice[1]
        newdice[1] = dice[5]
        newdice[5] = dice[4]
        newdice[4] = dice[0]
        newdice[2] = dice[2]
        newdice[3] = dice[3]

    elif i == 'E':
        newdice[0] = dice[3]
        newdice[3] = dice[5]
        newdice[5] = dice[2]
        newdice[2] = dice[0]
        newdice[1] = dice[1]
        newdice[4] = dice[4]
    elif i == 'S':
        newdice[0] = dice[4]
        newdice[4] = dice[5]
        newdice[5] = dice[1]
        newdice[1] = dice[0]
        newdice[2] = dice[2]
        newdice[3] = dice[3]
    else:
        newdice[0] = dice[2]
        newdice[2] = dice[5]
        newdice[5] = dice[3]
        newdice[3] = dice[0]
        newdice[1] = dice[1]
        newdice[4] = dice[4]

    dice = newdice[:]

print(dice[0])

Solution (Python):
class Dice:
    def __init__(self,dice):
        self.dice = dice
    def n_roll(self):
        self.dice = [self.dice[1],self.dice[5],self.dice[2],self.dice[3],self.dice[0],self.dice[4]]
    def s_roll(self):
        self.dice = [self.dice[4],self.dice[0],self.dice[2],self.dice[3],self.dice[5],self.dice[1]]
    def e_roll(self):
        self.dice = [self.dice[3],self.dice[1],self.dice[0],self.dice[5],self.dice[4],self.dice[2]]
    def w_roll(self):
        self.dice = [self.dice[2],self.dice[1],self.dice[5],self.dice[0],self.dice[4],self.dice[3]]
dice = list(map(int, input().split()))
dice1 = Dice(dice)
s = input()
for i in s:
    if i == "N":
        dice1.n_roll()
    elif i == "S":
        dice1.s_roll()
    elif i == "E":
        dice1.e_roll()
    elif i == "W":
        dice1.w_roll()
print(dice1.dice[0])

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 = {'N': (1, 5, 2, 3, 0, 4),
        'E': (3, 1, 0, 5, 4, 2),
        'S': (4, 0, 2, 3, 5, 1),
        'W': (2, 1, 5, 0, 4, 3)
        }
dice = list(map(int, input().split()))
face = input()
for f in face:
    dice = [dice[i] for i in faces[f]]
print(dice[0])

Solution (Python):
lab = list(map(int,input().split()))
dir = str(input())

for i in range(len(dir)):
    dcopy = lab.copy()
    if dir[i] == 'E':
        lab[0]=dcopy[3]
        lab[2]=dcopy[0]
        lab[3]=dcopy[5]
        lab[5]=dcopy[2]
    elif dir[i] == 'N':
        lab[0]=dcopy[1]
        lab[1]=dcopy[5]
        lab[4]=dcopy[0]
        lab[5]=dcopy[4]
    elif dir[i] == 'S':
        lab[0]=dcopy[4]
        lab[1]=dcopy[0]
        lab[4]=dcopy[5]
        lab[5]=dcopy[1]
    else:
        lab[0]=dcopy[2]
        lab[2]=dcopy[5]
        lab[3]=dcopy[0]
        lab[5]=dcopy[3]
print(lab[0])

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


s=input()
for i in range(len(s)):
    if s[i]=="E":
        E=[D[3],D[1],D[0],D[5],D[4],D[2]]
        D=E
    elif s[i]=="W":
        W=[D[2],D[1],D[5],D[0],D[4],D[3]]
        D=W
    elif s[i]=="S":
        S=[D[4],D[0],D[2],D[3],D[5],D[1]]
        D=S
    elif s[i]=="N":
        N=[D[1],D[5],D[2],D[3],D[0],D[4]]
        D=N
print(D[0])

Solution (Python):
result = 0

dice = input().split()

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

shaked = input()

for s in shaked:
    temp = dice[:]
    for f, t in moves[s]:
        temp[t - 1] = dice[f - 1]
    dice = temp[:]

print(dice[0])

Solution (Python):
class MIGI_HIDARI():

    def __init__(self,up,down,ue,shita,migi,hidari,value):
        self.up = up
        self.down = down
        self.ue = ue
        self.shita = shita
        self.migi = migi
        self.hidari = hidari
        self.value = value

    def MIGI(self):
        self.value = self.up
        self.up = self.hidari
        self.hidari = self.down
        self.down = self.migi
        self.migi = self.value


    def SHITA(self):
        self.value = self.up
        self.up = self.ue
        self.ue = self.down
        self.down = self.shita
        self.shita = self.value

    def HIDARI(self):
        self.value = self.up
        self.up = self.migi
        self.migi = self.down
        self.down = self.hidari
        self.hidari = self.value

    def UE(self):
        self.value = self.up
        self.up = self.shita
        self.shita = self.down
        self.down = self.ue
        self.ue = self.value

nums = input().rstrip().split(' ')

up = int(nums[0])
shita = int(nums[1])
migi = int(nums[2])
hidari = int(nums[3])
ue = int(nums[4])
down = int(nums[5])
value = ue

EWSN = list(input())

migi_hidari = MIGI_HIDARI(up,down,ue,shita,migi,hidari,value)

for i in EWSN:
    if i =="E":
        migi_hidari.MIGI()
    elif i =="W":
        migi_hidari.HIDARI()
    elif i =="S":
        migi_hidari.SHITA()
    else:
        migi_hidari.UE()
print(migi_hidari.up)

Solution (Python):
class Dice:
  def __init__(self, top=1, front=2, left=4, right=3, back=5, bottom=6):
    self.d = {"TOP":top, "FRONT":front, "LEFT":left, "RIGHT":right, "BACK":back, "BOTTOM":bottom}

  def roll_x(self):
    self._roll("TOP", "FRONT", "BOTTOM", "BACK")
  
  def roll_y(self):
    self._roll("FRONT", "LEFT", "BACK", "RIGHT")
  
  def roll_z(self):
    self._roll("TOP", "LEFT", "BOTTOM", "RIGHT")
  
  def _roll(self, a, b, c, d):
    self.d[a], self.d[b], self.d[c], self.d[d] = \
    self.d[b], self.d[c], self.d[d], self.d[a]

n = list(map(int, input().split()))
q = input()
d = Dice(n[0], n[1], n[3], n[2], n[4], n[5])
for ele in q:
  if ele=="N":
    d.roll_x()
  elif ele=="S":
    for _ in range(3):
      d.roll_x()
  elif ele=="E":
    d.roll_z()
  elif ele=="W":
    for _ in range(3):
      d.roll_z()
print(d.d["TOP"])

Solution (Python):
class Dice:
	def __init__(self, nums):
		self.cU = nums[0]
		self.cS = nums[1]
		self.cE = nums[2]
		self.cW = nums[3]
		self.cN = nums[4]
		self.cD = nums[5]
	def goN(self):
		pU,pS,pN,pD = self.cU,self.cS,self.cN,self.cD
		self.cU,self.cS,self.cN,self.cD = pS,pD,pU,pN
	def goE(self):
		pU,pE,pW,pD = self.cU,self.cE,self.cW,self.cD
		self.cU,self.cE,self.cW,self.cD = pW,pU,pD,pE
	def goW(self):
		pU,pE,pW,pD = self.cU,self.cE,self.cW,self.cD
		self.cU,self.cE,self.cW,self.cD = pE,pD,pU,pW
	def goS(self):
		pU,pS,pN,pD = self.cU,self.cS,self.cN,self.cD
		self.cU,self.cS,self.cN,self.cD = pN,pU,pD,pS
nums = [int(i) for i in input().split(' ')]
di = Dice(nums)
for op in input():
	if op == 'N': di.goN()
	elif op == 'E': di.goE()
	elif op == 'W': di.goW()
	elif op == 'S': di.goS()
print(di.cU)