Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Dice II

Construct a dice from a given sequence of integers in the same way as Dice I.

  You are given integers on the top face and the front face after the dice was rolled in the same way as Dice I. Write a program to print an integer on the right side face.

Input

 In the first line, six integers assigned to faces are given in ascending order of their corresponding labels.
In the second line, the number of questions $q$ is given.

  In the following $q$ lines, $q$ questions are given. Each question consists of two integers on the top face and the front face respectively.

Output

  For each question, print the integer on the right side face.

Constraints

$0 \leq $ the integer assigned to a face $ \leq 100$

The integers are all different

$1 \leq q \leq 24$

Sample Input

1 2 3 4 5 6
3
6 5
1 3
3 2

Sample Output

3
5
6



Sample input:
1 2 3 4 5 6
3
6 5
1 3
3 2


Sample output:
3
5
6

Submission status: Accepted

Solution code:
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

    def rotate_horizon(self):
        self.south,self.east,self.north,self.west = self.west,self.south,self.east,self.north

    def get_east(self):
        return self.east
        
dice = Dice(list(map(int,input().split())))
q = int(input())

for i in range(q):
    rot = list(map(int,input().split()))
    if rot[0]==dice.top:
        for _ in range(4):
           dice.rotate_horizon()
           if dice.south==rot[1]:
               h=dice.get_east()
    elif rot[0]==dice.west:
        dice.rotate_east()
        for _ in range(4):
           dice.rotate_horizon()
           if dice.south==rot[1]:
               h=dice.get_east()
    elif rot[0]==dice.bottom:
        dice.rotate_east()
        dice.rotate_east()
        for _ in range(4):
           dice.rotate_horizon()
           if dice.south==rot[1]:
               h=dice.get_east()
    elif rot[0]==dice.east:
        dice.rotate_west()
        for _ in range(4):
           dice.rotate_horizon()
           if dice.south==rot[1]:
               h=dice.get_east()
    elif rot[0]==dice.north:
        dice.rotate_south()
        for _ in range(4):
           dice.rotate_horizon()
           if dice.south==rot[1]:
               h=dice.get_east()
    else:
        dice.rotate_north()
        for _ in range(4):
           dice.rotate_horizon()
           if dice.south==rot[1]:
               h=dice.get_east()
    print(h)

Submission status: Accepted

Solution code:
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[1]
    dice[1] = dice[2]
    dice[2] = dice[4]
    dice[4] = dice[3]
    dice[3] = 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

maxloop = 4
Ncnt = 0
Ecnt = 0
Wcnt = 0

Dice = input().split()
q = int(input())

CopyDice = Dice

for i1 in range(q):
    Nloop = True
    Eloop = True
    Wloop = True
    Ncnt = 0
    Ecnt = 0
    Wcnt = 0
    I = input().split()
    top = I[0]
    front = I[1]
    while Eloop:
        while Nloop:
            while Wloop:
                if Dice[0] == top and Dice[1] == front:
                    print(Dice[2])
                    Nloop = False
                    Eloop = False
                    Wloop = False
                    break
                Dice = West(Dice)
                Wcnt += 1
                if Wcnt == maxloop:
                    Wloop = False
            Dice = North(Dice)
            Wcnt = 0
            Wloop = True
            Ncnt += 1
            if Ncnt == maxloop:
                Nloop = False
        Dice = East(Dice)
        Ncnt = 0
        Nloop = True
        Ecnt += 1
        if Ecnt == maxloop:
            Eloop = False
    Dice = CopyDice

Submission status: Accepted

Solution code:
data = list(map(int, input().split()))
n = int(input())
dice = ['12431', '03520', '01540', '04510', '02530', '13421']
for i in range(n):
    up, front = map(int, input().split())
    u = data.index(up)
    f = data.index(front)
    a = dice[u].find(str(f))
    print(data[int(dice[u][a+1])])

Submission status: Accepted

Solution code:
class Converter:
    d = {
        1: { 2: 3, 3: 5, 4: 2, 5: 4, },
        2: { 1: 4, 3: 1, 4: 6, 6: 3, },
        3: { 1: 2, 2: 6, 5: 1, 6: 5, },
        4: { 1: 5, 2: 1, 5: 6, 6: 2, },
        5: { 1: 3, 3: 6, 4: 1, 6: 4, },
        6: { 2: 4, 3: 2, 4: 5, 5: 3, }
        }

    def __init__(self, s):
        l = s.split()
        self.tbl = dict(zip(l, range(1,7)))
        self.pip = dict(zip(range(1,7), l))

    def __call__(self, s):
        l, r = s.split()
        print(self.pip[self.d[self.tbl[l]][self.tbl[r]]])

cv = Converter(input())
n = int(input())
for _ in range(n):
    cv(input())

Submission status: Accepted

Solution code:
class Dice2():

    def __init__(self, v): # v [Top, Front, Right, Left, Back, Bottom ]
        self.view = v
        self.dTFR = {}
        for i, j, k in ((ii, (ii++2)%6, (ii+4)%6) for ii in  range(6)):
            self.dTFR[self.view[i]]=[self.view[v] for v in (j, k, 5-j, 5-k, j)]


d2, q = Dice2(list(map(int, input().split()))), int(input())
for i in range(q):
    t, f = map(int, input().split())
    print(d2.dTFR[t][d2.dTFR[t].index(f)+1] )

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self):
        self.dice=[1,2,3,4,5,6] # up,front,right,left,back,front
    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

import random
d=Dice()
d.set(list(map(int,input().split())))
for i in range(int(input())):
    u,f=map(int,input().split())
    while True:
        d.roll('NSEW'[random.randrange(4)])
        if d.get()[0]==u and d.get()[1]==f:
            print(d.get()[2])
            break

Submission status: Accepted

Solution code:
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 = [int(s) for s in 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 search(self, line):
        top, south = [int(s) for s in line.split()]
        for direction in 'NNNNWNNNN':
            self.move(direction)
            if self.convert[self.south - 1] == south:
                break
        for direction in 'WWWW':
            self.move(direction)
            if self.convert[self.top - 1] == top:
                break
        return self.result()
        
    def result(self):
        return self.convert[self.east - 1]
    
dice = Dice(input())
for i in range(int(input())):
    print(dice.search(input()))

Submission status: Accepted

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

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

rightSide = {'F':'L','R':'F','B':'R','L':'B'}

for i in range(q):
    top, front = list(map(int, input().split()))
    topIdx = str(faces.index(top) + 1)
    frontIdx = str(faces.index(front) + 1)
    for k,v in dice[topIdx].items():
        if v[0] == str(frontIdx):
            faceIdx = dice[topIdx][rightSide[k]]
            print(faces[int(faceIdx)-1])
            break

Submission status: Accepted

Solution code:
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

    def yaw(self, direction):
        newDice = {}
        if direction == 'E':
            newDice['N'] = self.dice['E']
            newDice['E'] = self.dice['S']
            newDice['S'] = self.dice['W']
            newDice['W'] = self.dice['N']
        if direction == 'W':
            newDice['N'] = self.dice['W']
            newDice['E'] = self.dice['N']
            newDice['S'] = self.dice['E']
            newDice['W'] = self.dice['S']
        self.dice = newDice

faces = list(map(int, input().split()))
q = int(input())
d = Dice()

for i in range(q):
    top, front = list(map(int, input().split()))
    topIdx = faces.index(top) + 1
    frontIdx = faces.index(front) + 1

    if d.top() != topIdx:
        # search topIdx and rotate to make topIdx top.
        key = [k for k,v in d.dice.items() if topIdx == v]
        if len(key) == 0:
            d.rot('N')
            key = [k for k,v in d.dice.items() if topIdx == v]
        d.rot(key[0])

    # rotate(yaw) to make frontIdx front.
    while True:
        if d.dice['N'] == frontIdx:
            break
        d.yaw('E')

    print(faces[d.dice['W']-1])

Submission status: Accepted

Solution code:
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

    def yaw(self, direction):
        newDice = {}
        if direction == 'E':
            newDice['N'] = self.dice['E']
            newDice['E'] = self.dice['S']
            newDice['S'] = self.dice['W']
            newDice['W'] = self.dice['N']
        if direction == 'W':
            newDice['N'] = self.dice['W']
            newDice['E'] = self.dice['N']
            newDice['S'] = self.dice['E']
            newDice['W'] = self.dice['S']
        self.dice = newDice

faces = list(map(int, input().split()))
q = int(input())
d = Dice()

for i in range(q):
    top, front = list(map(int, input().split()))
    topIdx = faces.index(top) + 1
    frontIdx = faces.index(front) + 1

    if d.top() != topIdx:
        # search topIdx and rotate to make topIdx top.
        key = [k for k,v in d.dice.items() if topIdx == v]
        if len(key) == 0:
            d.rot('N')
            key = [k for k,v in d.dice.items() if topIdx == v]
        d.rot(key[0])

    # rotate(yaw) to make frontIdx front.
    while True:
        if d.dice['N'] == frontIdx:
            break
        d.yaw('E')

    print(faces[d.dice['W']-1])

Submission status: Accepted

Solution code:
# -*-coding:utf-8

import random

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():

    orderList = ['N', 'E', 'W', 'S']
    inputDiceList = list(map(int, input().split()))
    inputNum = int(input())
    d = Dice(inputDiceList)

    for i in range(inputNum):
        x, y = map(int, input().split())
        while True:
            if(d.d1 == x and d.d2 == y):
                print(d.d3)
                break
            else:
                r = random.randint(0, 3)
                d.diceRoll(orderList[r])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main_1_11_A():
    values = list(map(int, input().split()))
    query = input()

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


def main_1_11_B():
    values = list(map(int, input().split()))
    n = int(input())

    for _ in range(n):
        t_value, s_value = map(int, input().split())

        print(_B(values, t_value, s_value))


def _B(values, t_value, s_value):
    """
    ????????¢?????????????????¨??????
    ??´??¢???????????¢?????????????????§???????????????????????¨?????????
    ??????????????????????????¢???????¢??????????
    """
    def rot_n(dice, n):
        for _ in range(n):
            dice.roll("N").roll("E").roll("S")
        return dice

    def make_dices():
        # ?????¢???TOP?????????
        return [
            Dice(values),
            Dice(values).roll("N"),
            Dice(values).roll("N").roll("N"),
            Dice(values).roll("N").roll("N").roll("N"),
            Dice(values).roll("E"),
            Dice(values).roll("W"),
        ]

    dices = (
        make_dices() +
        list(map(lambda dice: rot_n(dice, 1), make_dices())) +
        list(map(lambda dice: rot_n(dice, 2), make_dices())) +
        list(map(lambda dice: rot_n(dice, 3), make_dices()))
    )
    for dice in dices:
        # print(dice)
        for d in ("E" * 4 + "W" * 4 + "S" * 4 + "N" * 4):
            dice.roll(d)
            #print(d, (dice.top_value, dice.south_value), (t_value, s_value))
            if (dice.top_value, dice.south_value) == (t_value, s_value):
                return dice.east_value


class Dice:

    def __init__(self, values):
        self.values = values
        # top, bottom, direction 4
        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

        return self

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

    @property
    def south_value(self):
        return self.values[self.s - 1]

    @property
    def east_value(self):
        return self.values[self.e - 1]

if __name__ == "__main__":
    # main_1_11_A()
    main_1_11_B()

Submission status: Accepted

Solution code:
dice = {
	1: [2, 3, 5, 4],
	2: [6, 3, 1, 4],
	3: [2, 6, 5, 1],
	4: [2, 1, 5, 6],
	5: [1, 3, 6, 4],
	6: [2, 4, 5, 3]
}
tags = []

def GetRight(top, front):
	numList = dice[top]
	for i in range(4):
		if numList[i] == front:
			return numList[(i+1)%4]

def SetDice():
	global tags
	tags = input().split(" ")
	
def DoQuestion():
	nums = input().split(" ")
	top = tags.index(nums[0])+1
	front = tags.index(nums[1])+1
	right = GetRight(top, front)
	print(tags[right-1])
	
SetDice()
q = int(input())
for i in range(q):
	DoQuestion()

Submission status: Accepted

Solution code:
d=input().split()
for _ in range(int(input())):
 t,f=[d.index(s) for s in input().split()]
 n={0:(1,2,4,3,1),1:(0,3,5,2,0),2:(0,1,5,4,0),3:(1,0,4,5,1),4:(0,2,5,3,0),5:(1,3,4,2,1)}[int(t)]
 print(d[n[n.index(int(f))+1]])

Submission status: Accepted

Solution code:
import random

class Dice():
    
    def __init__(self, *n):
       self.rolls = n

    def spin(self, order):
        if order == "N":
            self.rolls = [
                self.rolls[1],
                self.rolls[5],
                self.rolls[2],
                self.rolls[3],
                self.rolls[0],
                self.rolls[4]
            ]
        if order == "E":
            self.rolls = [
                self.rolls[3],
                self.rolls[1],
                self.rolls[0],
                self.rolls[5],
                self.rolls[4],
                self.rolls[2]
            ]
        if order == "S":
            self.rolls = [
                self.rolls[4],
                self.rolls[0],
                self.rolls[2],
                self.rolls[3],
                self.rolls[5],
                self.rolls[1]
            ]
        if order == "W":
            self.rolls = [
                self.rolls[2],
                self.rolls[1],
                self.rolls[5],
                self.rolls[0],
                self.rolls[4],
                self.rolls[3]
            ]
        return self.rolls[0]

d = Dice(*[int(i) for i in input().split()])
directions = ['N','E','S','W']
for _ in range(int(input())):
    a,b = [int(i) for i in input().split()]
    while a != d.rolls[0] or d.rolls[1] != b:
        d.spin(directions[random.randint(0,3)])
    print(d.rolls[2])

Submission status: Accepted

Solution code:
dice = list(map(int, input().split()))
mask = {
    'N': (1, 5, 2, 3, 0, 4),
    'R': (0, 2, 4, 1, 3, 5)
    }


for i in range(int(input())):
    a, b = map(int, input().split())

    lim = 0
    while dice[0] != a:
        dice = [dice[x] for x in mask['N']]
        lim += 1
        if lim == 4:
            dice = [dice[x] for x in mask['R']]
            lim = 0
    while dice[1] != b:
        dice = [dice[x] for x in mask['R']]
    print(dice[2])

Submission status: Accepted

Solution code:
class dice:
    men = [0] * 7
    def __init__(self, li):
        self.men = [0] + li
    def move0(self, a, b, c, d):
        self.men[a], self.men[b], self.men[c], self.men[d] = self.men[b], self.men[c], self.men[d], self.men[a]
    def move(self, h):
        if h == "N":
            self.move0(1, 2, 6, 5)
        elif h == "S":
            self.move0(1, 5, 6, 2)
        elif h == "W":
            self.move0(1, 3, 6, 4)
        elif h == "E":
            self.move0(1, 4, 6, 3)
    def move2(self, a, b):
        if self.men[1] != a:
            for i, ss in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "NN")]:
                if self.men[i] == a:
                    for s in ss:
                        self.move(s)
                    break
        if self.men[2] != b:
            if b == self.men[3]:
                self.move0(2, 3, 5, 4)
            elif b == self.men[4]:
                self.move0(2, 4, 5, 3)
            else:
                self.men[2], self.men[5], self.men[3], self.men[4] = self.men[5], self.men[2], self.men[4], self.men[3]
saikoro = dice(list(map(int, input().split())))
for _ in range(int(input())):
    saikoro.move2(*map(int, input().split()))
    print(saikoro.men[3])

Submission status: Accepted

Solution code:
class dice:
    men = [0] * 7
    def __init__(self, li):
        self.men = [0] + li
    def move0(self, a, b, c, d):
        self.men[a], self.men[b], self.men[c], self.men[d] = self.men[b], self.men[c], self.men[d], self.men[a]
    def move(self, h):
        if h == "N":
            self.move0(1, 2, 6, 5)
        elif h == "S":
            self.move0(1, 5, 6, 2)
        elif h == "W":
            self.move0(1, 3, 6, 4)
        elif h == "E":
            self.move0(1, 4, 6, 3)
        elif h == "O":
            self.men[1], self.men[6], self.men[2], self.men[5] = self.men[6], self.men[1], self.men[5], self.men[2]
        elif h == "L":
            self.move0(2, 3, 5, 4)
        elif h == "R":
            self.move0(2, 4, 5, 3)
        elif h == "B":
            self.men[3], self.men[4], self.men[2], self.men[5] = self.men[4], self.men[3], self.men[5], self.men[2]
    def move2(self, a, b):
        if self.men[1] != a:
            for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]:
                if self.men[i] == a:
                    self.move(s)
                    break
        if self.men[2] != b:
            if b == self.men[3]:
                self.move("L")
            elif b == self.men[4]:
                self.move("R")
            else:
                self.move("B")
saikoro = dice(list(map(int, input().split())))
for _ in range(int(input())):
    saikoro.move2(*map(int, input().split()))
    print(saikoro.men[3])

Submission status: Accepted

Solution code:
class dice:
    def __init__(self, li):
        self.men = [0] + li
    def move0(self, a, b, c, d):
        self.men[a], self.men[b], self.men[c], self.men[d] = self.men[b], self.men[c], self.men[d], self.men[a]
    def move(self, h):
        if h == "N":
            self.move0(1, 2, 6, 5)
        elif h == "S":
            self.move0(1, 5, 6, 2)
        elif h == "W":
            self.move0(1, 3, 6, 4)
        elif h == "E":
            self.move0(1, 4, 6, 3)
        elif h == "O":
            self.men[1], self.men[6], self.men[2], self.men[5] = self.men[6], self.men[1], self.men[5], self.men[2]
        elif h == "L":
            self.move0(2, 3, 5, 4)
        elif h == "R":
            self.move0(2, 4, 5, 3)
        elif h == "B":
            self.men[3], self.men[4], self.men[2], self.men[5] = self.men[4], self.men[3], self.men[5], self.men[2]
    def move2(self, a, b):
        if self.men[1] != a:
            for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]:
                if self.men[i] == a:
                    self.move(s)
                    break
        if self.men[2] != b:
            if b == self.men[3]:
                self.move("L")
            elif b == self.men[4]:
                self.move("R")
            else:
                self.move("B")
saikoro = dice(list(map(int, input().split())))
for _ in range(int(input())):
    saikoro.move2(*map(int, input().split()))
    print(saikoro.men[3])

Submission status: Accepted

Solution code:
data = list(map(int, input().split()))
n = int(input())
dice = ['12431', '03520', '01540', '04510', '02530', '13421']
for i in range(n):
    up, front = map(int, input().split())
    u = data.index(up)
    f = data.index(front)
    a = dice[u].find(str(f))
    print(data[int(dice[u][a+1])])

Submission status: Accepted

Solution code:
d=input().split()
for _ in range(int(input())):
 t,f=[int(d.index(s))for s in input().split()]
 n={0:(1,2,4,3,1),1:(0,3,5,2,0),2:(0,1,5,4,0),3:(1,0,4,5,1),4:(0,2,5,3,0),5:(1,3,4,2,1)}[t]
 print(d[n[n.index(f)+1]])

Submission status: Accepted

Solution code:
d=input().split()
for _ in range(int(input())):
 t,f=[int(d.index(s))for s in input().split()]
 n=[(1,2,4,3,1),(0,3,5,2,0),(0,1,5,4,0),(1,0,4,5,1),(0,2,5,3,0),(1,3,4,2,1)][t]
 print(d[n[n.index(f)+1]])

Submission status: Accepted

Solution code:
d=input().split()
for _ in range(int(input())):
 t,f=[d.index(s)for s in input().split()]
 n=[(1,2,4,3,1),(0,3,5,2,0),(0,1,5,4,0),(1,0,4,5,1),(0,2,5,3,0),(1,3,4,2,1)][t]
 print(d[n[n.index(f)+1]])

Submission status: Accepted

Solution code:
class dice:

    def __init__(self, numlist):
        self._men = {"T": numlist[0],
                     "B": numlist[5],
                     "N": numlist[4],
                     "S": numlist[1],
                     "W": numlist[3],
                     "E": numlist[2]}

    def roll(self, direction):
        t = dict(self._men)

        if direction == "N":
            self._men["T"] = t["S"]
            self._men["B"] = t["N"]
            self._men["N"] = t["T"]
            self._men["S"] = t["B"]
        elif direction == "S":
            self._men["T"] = t["N"]
            self._men["B"] = t["S"]
            self._men["S"] = t["T"]
            self._men["N"] = t["B"]
        elif direction == "W":
            self._men["T"] = t["E"]
            self._men["B"] = t["W"]
            self._men["W"] = t["T"]
            self._men["E"] = t["B"]
        elif direction == "E":
            self._men["T"] = t["W"]
            self._men["B"] = t["E"]
            self._men["W"] = t["B"]
            self._men["E"] = t["T"]


    def settopsouth(self, top, south):
        if self._men["T"] == top:
            pass
        elif self._men["S"] == top:
            self.roll("N")
        elif self._men["N"] == top:
            self.roll("S")
        elif self._men["W"] == top:
            self.roll("E")
        elif self._men["E"] == top:
            self.roll("W")
        elif self._men["B"] == top:
            self.roll("N")
            self.roll("N")

        if self._men["S"] == south:
            return self._men["E"]
        elif self._men["E"] == south:
            return self._men["N"]
        elif self._men["N"] == south:
            return self._men["W"]
        elif self._men["W"] == south:
            return self._men["S"]


    def gettop(self):
        return self._men["T"]

def decode():
    numlist = [int(x) for x in input().split()]
    n = int(input())
    qs = []
    for _ in range(n):
        al = [int(x) for x in input().split()]
        qs.append(al)

    return numlist, n, qs


if __name__ == '__main__':

    numlist, n, qs = decode()
    d1 = dice(numlist)
    for q in qs:
        print(d1.settopsouth(*q))

Submission status: Accepted

Solution code:
import random

class Dice:
    def __init__(self, hoge):
        self.num = hoge
        self.face = {'U': 0, 'W': 3, 'E': 2, 'N': 4, 'S': 1, 'B': 5} 
    
    def move(self, direct):
        previouse = {k: v for k, v in self.face.items()}
        if direct == 'E':
            self.face['U'] = previouse['W']
            self.face['W'] = previouse['B']
            self.face['E'] = previouse['U']
            self.face['B'] = previouse['E']
        elif direct == 'W':
            self.face['U'] = previouse['E']
            self.face['W'] = previouse['U']
            self.face['E'] = previouse['B']
            self.face['B'] = previouse['W']
        elif direct == 'N':
            self.face['U'] = previouse['S']
            self.face['N'] = previouse['U']
            self.face['S'] = previouse['B']
            self.face['B'] = previouse['N']
        elif direct == 'S':
            self.face['U'] = previouse['N']
            self.face['N'] = previouse['B']
            self.face['S'] = previouse['U']
            self.face['B'] = previouse['S']
    
    def get_num(self, place):
        return self.num[self.face[place]]
    
        
if __name__ == '__main__':
    dice = Dice([int(x) for x in input().split()])
    num_q = int(input())
    d = ['E', 'W', 'N', 'S']
    for _ in range(num_q):
        x, y = [int(x) for x in input().split()]
        while True:
            rand_num = random.randint(0, 3)
            dice.move(d[rand_num])
            if dice.get_num('U') == x and dice.get_num('S') == y:
                break
        print(dice.get_num('E'))

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, top, dside):
        self.top = top
        self.dside = dside
        self.rside = None
        self.num = [self.top, self.dside, 7-self.top, 7-self.dside]
    def rside_num(self):
        if 2 in self.num and 3 in self.num:
            if(self.num.index(3)==self.num.index(2)+1 or 
                self.num==[3, 5, 4, 2]):
                self.rside = 1
            else:
                self.rside = 6
        elif 1 in self.num and 4 in self.num:
            if(self.num.index(4)==self.num.index(1)+1 or 
                self.num==[4, 6, 3, 1]):
                self.rside = 2
            else:
                self.rside = 5
        else:
            if(self.num.index(2)==self.num.index(1)+1 or
                self.num==[2, 6, 5, 1]):
                self.rside = 3
            else:
                self.rside = 4

num = list(map(int, input().split()))
n = int(input())
for i in range(n):
    value = list(map(int, input().split()))
    dice = Dice(num.index(value[0])+1, num.index(value[1])+1)
    dice.rside_num()
    print(num[dice.rside-1])

Submission status: Accepted

Solution code:
jisho= {0:
    [[1,2],[3,1],[4,3],[2,4]],
     1:
    [[0,3],[3,5],[5,2],[2,0]],
    2:
    [[0,1],[1,5],[5,4],[4,0]],
    3:
    [[0,4],[4,5],[5,1],[1,0]],
    4:
    [[0,2],[2,5],[5,3],[3,0]],
    5:
    [[2,1],[1,3],[3,4],[4,2]]
       }
i_number = [int(x) for x in input().split()]
n = int(input())
for _ in range(n):
    q1,q2 = [int(x) for x in input().split()]
    for i,n in enumerate(i_number):
        if q1 == n:
            qq1 = i
        if q2 == n:
            qq2 = i
    for k,v in jisho.items():
        if [qq1,qq2] in v:
            print(i_number[k])

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

face = sys.stdin.readline().split()

right = [[None for front in range(6)] for top in range(6)]

# Top:1 Face:2 -> Right:3, Top:2 Face:6 -> Right:3 ...
right[0][1] = right[1][5] = right[5][4] = right[4][0] = 3 - 1
right[1][0] = right[5][1] = right[4][5] = right[0][4] = 4 - 1
right[0][2] = right[2][5] = right[5][3] = right[3][0] = 5 - 1
right[2][0] = right[5][2] = right[3][5] = right[0][3] = 2 - 1
right[3][1] = right[1][2] = right[2][4] = right[4][3] = 1 - 1
right[1][3] = right[2][1] = right[4][2] = right[3][4] = 6 - 1

# print(right)

q = int(sys.stdin.readline())
for i in range(q):
    top, front = sys.stdin.readline().split()
    r_index = right[face.index(top)][face.index(front)]
    print(face[r_index])