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:
  __table =[[0,1,2,3,4,5],[0,2,4,1,4,5],[0,4,3,2,1,5],[0,3,1,4,2,5],
            [1,5,2,3,0,4],[1,2,0,5,3,4],[1,0,3,2,5,4],[1,3,5,0,2,4],
            [2,5,4,1,0,3],[2,4,0,5,1,3],[2,0,1,4,5,3],[2,1,5,0,4,3],
            [3,5,1,4,0,2],[3,1,0,5,4,2],[3,0,4,1,5,2],[3,4,5,0,1,2],
            [4,2,5,0,3,1],[4,5,3,2,0,1],[4,3,0,5,2,1],[4,0,2,3,5,1],
            [5,1,3,2,4,0],[5,3,4,1,2,0],[5,4,2,3,1,0],[5,2,1,4,3,0]]
  __another = []
  def __init__(self,dice):
    self.dice = dice
    for t in self.__table:
      a = []
      for k,v in enumerate(t):
        a.append(dice[v])      
      self.__another.append(a)
      
  def output(self):
    print(self.dice[0])
    
  def right_dise(self,a,b):
    for t in self.__another:
      if t[0] == a and t[1] == b:
        return t[2]

  def move(self,str):
    if str == 'N':
      temp = self.dice[0]
      self.dice[0] = self.dice[1]
      self.dice[1] = self.dice[5]
      self.dice[5] = self.dice[4]
      self.dice[4] = temp
    elif str == 'S':
      temp = self.dice[0]
      self.dice[0] = self.dice[4]
      self.dice[4] = self.dice[5]
      self.dice[5] = self.dice[1]
      self.dice[1] = temp

    elif str == 'E':
      temp = self.dice[0]
      self.dice[0] = self.dice[3]
      self.dice[3] = self.dice[5]
      self.dice[5] = self.dice[2]
      self.dice[2] = temp
      
    elif str == 'W':
      temp = self.dice[0]
      self.dice[0] = self.dice[2]
      self.dice[2] = self.dice[5]
      self.dice[5] = self.dice[3]
      self.dice[3] = temp      
  
      
di = list(map(int,input().split()))
di = Dice(di)
num = int(input())

while num > 0:
  v1,v2 = map(int,input().split())
  re = di.right_dise(v1,v2)
  print(re)
  num -= 1

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self,label):
        self.W = label[3]
        self.S = label[1]
        self.E = label[2]
        self.N = label[4]
        self.u = label[0]
        self.l = label[5]
    def rotate(self,direction):
        if direction =='S':
            dummy = self.S
            self.S = self.u
            self.u = self.N
            self.N = self.l
            self.l = dummy
        elif direction == 'N':
            dummy = self.S
            self.S = self.l
            self.l = self.N
            self.N = self.u
            self.u = dummy
        elif direction == 'W':
            dummy = self.W
            self.W = self.u
            self.u = self.E
            self.E = self.l
            self.l = dummy
        else:
            dummy = self.W
            self.W = self.l
            self.l = self.E
            self.E = self.u
            self.u = dummy
    def rot(self):
            dummy = self.W
            self.W = self.S
            self.S = self.E
            self.E = self.N
            self.N = dummy

l = input().split()
D = Dice(l)
n = int(input())
for i in range(n):
    a,b = input().split()
    if a == D.u:
        c = 1
    elif a == D.N:
        D.rotate('S')
    elif a == D.W:
        D.rotate('E')
    elif a == D.E:
        D.rotate('W')
    elif a == D.S:
        D.rotate('N')
    else:
        D.rotate('S')
        D.rotate('S')
    for i in range(4):
        D.rot()
        if (D.S == b)+(D.S == str(b)):
            break
    print(D.E)
    D = Dice(l)

Submission status: Accepted

Solution code:
import math
import itertools
import sys

class Dice:
  numbers = []
  faces = {
    'top': None,
    'back': None,    
    'right': None,    
    'left': None,    
    'front': None,    
    'bottom': None,
  }

  def __init__(self, int_array):
    self.numbers = int_array
    self.faces['top'] = self.numbers[0]
    self.faces['back'] = self.numbers[1]
    self.faces['right'] = self.numbers[2]
    self.faces['left'] = self.numbers[3]
    self.faces['front'] = self.numbers[4]
    self.faces['bottom'] = self.numbers[5]

  def getNum(self, n):
    return self.numbers[n-1]

  def getFace(self, f):
    return self.faces[f]

  def getRightFace(self, t, b):
    top = self.faces['top']
    back = self.faces['back']
    right = self.faces['right']
    left = self.faces['left']
    front = self.faces['front']
    bottom = self.faces['bottom']

    if t == self.getNum(2):
      self.rotate('N')

    elif t == self.getNum(4):
      self.rotate('E')

    elif t == self.getNum(5):
      self.rotate('S')

    elif t == self.getNum(3):
      self.rotate('W')

    elif t == self.getNum(6):
      for _ in range(2):
        self.rotate('N')

    while self.getFace('back') != b:
      self.rotate('R')

    result = self.getFace('right')
      
    self.faces['top'] = top
    self.faces['back'] = back
    self.faces['right'] = right
    self.faces['left'] = left
    self.faces['front'] = front
    self.faces['bottom'] = bottom

    return result

  def rotate(self, direction):
    if direction == 'N': # 前回り
      top = self.getFace('top') #一時保存

      self.faces['top'] = self.faces['back']
      self.faces['back'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['front']
      self.faces['front'] = top
      
    elif direction == 'E': # 右回り
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['left']
      self.faces['left'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['right']
      self.faces['right'] = top
      
    elif direction == 'S': # 後ろ回り
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['front']
      self.faces['front'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['back']
      self.faces['back'] = top
      
    elif direction == 'W': # 左回り
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['right']
      self.faces['right'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['left']
      self.faces['left'] = top
      
    elif direction == 'R': # その場右回り
      back = self.faces['back'] #一時保存

      self.faces['back'] = self.faces['left']
      self.faces['left'] = self.faces['front']
      self.faces['front'] = self.faces['right']
      self.faces['right'] = back
      
    else: # その場左回り
      back = self.faces['back'] #一時保存

      self.faces['back'] = self.faces['right']
      self.faces['right'] = self.faces['front']
      self.faces['front'] = self.faces['left']
      self.faces['left'] = back
      
def main():
  number = list(map(int, input().split()))
  q = int(input())

  dice = Dice(number)

  for _ in range(q):
    t, b = map(int, input().split())
    print(dice.getRightFace(t,b))

if __name__ == '__main__':
  main()

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:
S = [
    (1, 2, 4, 3), # 0
    (0, 3, 5, 2), # 1
    (0, 1, 5, 4), # 2
    (0, 4, 5, 1), # 3
    (0, 2, 5, 3), # 4
    (1, 3, 4, 2), # 5
]

*L, = map(int, input().split())
q = int(input())
for i in range(q):
    a, b = map(int, input().split())
    for i in range(6):
        if L[i] == a:
            for k in range(4):
                if L[S[i][k]] == b:
                    print(L[S[i][k-3]])

Submission status: Accepted

Solution code:
d = input().split()
n = int(input())
r_list = []
i = 0

while n > i:
    t, f = map(str, input().split())
    tf = str(d.index(t)) + str(d.index(f))

    if tf == "12" or tf == "24" or tf == "43" or tf == "31":
        r_list.append(1)
    elif tf == "20" or tf == "03" or tf == "35" or tf == "52":
        r_list.append(2)
    elif tf == "01" or tf == "15" or tf == "54" or tf == "40":
        r_list.append(3)
    elif tf == "10" or tf == "51" or tf == "45" or tf == "04":
        r_list.append(4)
    elif tf == "02" or tf == "30" or tf == "53" or tf == "25":
        r_list.append(5)
    elif tf == "21" or tf == "42" or tf == "34" or tf == "13":
        r_list.append(6)

    i += 1

for r in r_list:
    print(d[r-1])

Submission status: Accepted

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

def move(x):
    if x == "N":
        d[0],d[1],d[2],d[3],d[4],d[5] = d[1],d[5],d[2],d[3],d[0],d[4]

    elif x == "W":
        d[0],d[1],d[2],d[3],d[4],d[5] = d[2],d[1],d[5],d[0],d[4],d[3]

    elif x == "E":
        d[0],d[1],d[2],d[3],d[4],d[5] = d[3],d[1],d[0],d[5],d[4],d[2]

    elif x == "S":
        d[0],d[1],d[2],d[3],d[4],d[5] = d[4],d[0],d[2],d[3],d[5],d[1]

q = int(input())

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

    if a == dice[1]:
        move("N")
    if a == dice[2]:
        move("W")
    if a == dice[3]:
        move("E")
    if a == dice[4]:
        move("N")
    if a == dice[5]:
        move("S")
        move("S")

    if b == d[1]:
        print(d[2])
    if b ==  d[2]:
        print(d[4])
    if b ==  d[3]:
        print(d[1])
    if b ==  d[4]:
        print(d[3])

Submission status: Accepted

Solution code:
class Dice:
    # constructor
    def __init__(self, eye1, eye2, eye3, eye4, eye5, eye6):
        self.__eyes = {
            "top": eye1,
            "front": eye2,
            "right": eye3,
            "left": eye4,
            "back": eye5,
            "bottom": eye6
        }
    # setter
    def set_eyes(self, eye1, eye2, eye3, eye4, eye5, eye6):
        self.__eyes["top"] = eye1
        self.__eyes["front"] = eye2
        self.__eyes["right"] = eye3
        self.__eyes["left"] = eye4
        self.__eyes["back"] = eye5
        self.__eyes["bottom"] = eye6
    # getter
    def get_eyes(self, key):
        return self.__eyes[key]

    
    def N(self):
        self.set_eyes(
            self.get_eyes("front"),
            self.get_eyes("bottom"),
            self.get_eyes("right"),
            self.get_eyes("left"),
            self.get_eyes("top"),
            self.get_eyes("back")
            )
    def S(self):
        self.set_eyes(
            self.get_eyes("back"),
            self.get_eyes("top"),
            self.get_eyes("right"),
            self.get_eyes("left"),
            self.get_eyes("bottom"),
            self.get_eyes("front")
            )
        
    def E(self):
        self.set_eyes(
            self.get_eyes("left"),
            self.get_eyes("front"),
            self.get_eyes("top"),
            self.get_eyes("bottom"),
            self.get_eyes("back"),
            self.get_eyes("right")
            )
        
    def W(self):
        self.set_eyes(
            self.get_eyes("right"),
            self.get_eyes("front"),
            self.get_eyes("bottom"),
            self.get_eyes("top"),
            self.get_eyes("back"),
            self.get_eyes("left")
            )
    
    def print_top(self):
        print(self.get_eyes("top"))
    

    def guess_right_from_top_front(self, top, front):
        key_top = None
        key_front = None
        keys = [ 
        "top", 
        "front", 
        "right", 
        "left", 
        "back", 
        "bottom"
        ]
        for key in keys:
            if top == self.get_eyes(key):
                key_top = key
            if front == self.get_eyes(key):
                key_front = key
        keys_for_top = [
            ["front", "right", "back", "left"],
            ["bottom", "right", "top", "left"],
            ["bottom", "back", "top", "front"],
            ["bottom", "front", "top", "back"],
            ["bottom", "left", "top", "right"],
            ["front", "left", "back", "right"]
        ]
        
        for i in range(6):
            if key_top == keys[i]:
                for j in range(4):
                    if key_front == keys_for_top[i][j]:
                        return keys_for_top[i][(j + 1) % 4]

eye1, eye2, eye3, eye4, eye5, eye6 = map(int, input().split())
q = int(input())
dice = Dice(eye1, eye2, eye3, eye4, eye5, eye6)
for _ in range(q):
    top, front = map(int, input().split())
    print(dice.get_eyes(dice.guess_right_from_top_front(top, front)))

Submission status: Accepted

Solution code:
N = list(map(int,input().split()))
q = int(input())

for _ in range(q):
    problem = [int(x) for x in input().split()]
    
    
    if problem in [[N[0],N[1]],[N[1],N[5]],[N[5],N[4]],[N[4],N[0]]]:
        print(N[2])
    elif problem in [[N[3],N[1]],[N[1],N[2]],[N[2],N[4]],[N[4],N[3]]]:
        print(N[0])
    elif problem in [[N[3],N[5]],[N[5],N[2]],[N[2],N[0]],[N[0],N[3]]]:
        print(N[1])
    elif problem in [[N[4],N[5]],[N[5],N[1]],[N[1],N[0]],[N[0],N[4]]]:
        print(N[3])
    elif problem in [[N[2],N[5]],[N[5],N[3]],[N[3],N[0]],[N[0],N[2]]]:
        print(N[4])
    elif problem in [[N[1],N[3]],[N[3],N[4]],[N[4],N[2]],[N[2],N[1]]]:
        print(N[5])

Submission status: Accepted

Solution code:

class Dice:
    def __init__(self,a,b,c,d,e,f):
        self.face1 = a
        self.face2 = b
        self.face3 = c
        self.face4 = d
        self.face5 = e
        self.face6 = f

    def above_face(self):
        return self.face1

    def roll(self, order):
        if order == 0:
            tmp = self.face1
            self.face1 = self.face2
            self.face2 = self.face6
            self.face6 = self.face5
            self.face5 = tmp
        elif order == 1:
            tmp = self.face1
            self.face1 = self.face5
            self.face5 = self.face6
            self.face6 = self.face2
            self.face2 = tmp
        elif order == 2:
            tmp = self.face1
            self.face1 = self.face3
            self.face3 = self.face6
            self.face6 = self.face4
            self.face4 = tmp
        else:
            tmp = self.face1
            self.face1 = self.face4
            self.face4 = self.face6
            self.face6 = self.face3
            self.face3 = tmp

a,b,c,d,e,f = map(int,input().split())
dice1 = Dice(a,b,c,d,e,f)
q = int(input())
import random
for i in range(q):
    A,B = map(int,input().split())
    while True:
        dice1.roll(random.randint(0, 3))
        if dice1.face1 == A and dice1.face2 == B:
            break
    print(dice1.face3)

Submission status: Accepted

Solution code:
class Dice():
    
    state = [0 for _ in range(6)]

    def __init__(self, dice_list):
        self.state[0] = dice_list[0]
        self.state[1] = dice_list[1]
        self.state[2] = dice_list[2]
        self.state[3] = dice_list[3]
        self.state[4] = dice_list[4]
        self.state[5] = dice_list[5]

    def north(self):
        tmp = self.state[0]
        self.state[0] = self.state[1]
        self.state[1] = self.state[5]
        self.state[5] = self.state[4]
        self.state[4] = tmp

    def west(self):
        tmp = self.state[0]
        self.state[0] = self.state[2]
        self.state[2] = self.state[5]
        self.state[5] = self.state[3]
        self.state[3] = tmp

    def south(self):
        tmp = self.state[0]
        self.state[0] = self.state[4]
        self.state[4] = self.state[5]
        self.state[5] = self.state[1]
        self.state[1] = tmp


    def east(self):
        tmp = self.state[0]
        self.state[0] = self.state[3]
        self.state[3] = self.state[5]
        self.state[5] = self.state[2]
        self.state[2] = tmp

    
if __name__ == '__main__':
    L = list(map(int, input().split()))
    N = int(input())
    querys = [list(map(int, input().split())) for _ in range(N)]

    for query in querys:
        dice = Dice(L)

        for i in range(3):
            for j in range(4):
                if dice.state[1] == query[1]:
                    break
                dice.north()
                
            if dice.state[1] == query[1]:
                break

            dice.west()
            

        for i in range(4):
            if dice.state[0] == query[0]:
                break
            dice.west()

        print(dice.state[2])

Submission status: Accepted

Solution code:
def right_num(m,u):
    cube = [
        {2:3,3:5,4:2,5:4},
        {1:4,3:1,4:6,6:3},
        {1:2,2:6,5:1,6:5},
        {1:5,2:1,5:6,6:2},
        {1:3,3:6,4:1,6:4},
        {2:4,3:2,4:5,5:3},
    ]
    return cube[m][u]

d=input().split()
for i in range(int(input())):
    num = input().split()

    p = d.index(num[0])
    s = int(d.index(num[1])) + 1

    print("{}".format(d[(right_num(p, s)-1)]))

Submission status: Accepted

Solution code:
ptn=["23542","14631",
"12651","15621",
"13641","32453"]

def rNO(d):
  global ptn
  for i,e in enumerate(ptn):
    if d in e:
      return i
  return 0
      

dice = list(input().split(" "))
n = int(input())

for i in range(n):
  q = input().split()
  for i,e in enumerate(dice):
    if e == q[0] :
      q1 = i + 1
    if e == q[1]:
      q2 = i + 1
  
  qq=str(q1) + str(q2)
  ans = rNO(qq)
  print(dice[ans])

Submission status: Accepted

Solution code:

#0:上面　1:S 2:E 3:W 4:N 5:下
class Dice:
    def __init__(self):#クラス内で用いる変数の定義（クラス作成時に代入しなくてよい）
        self.number = [i for i in range(6)]
        self.work = [i for i in range(6)]
        self.order = 'NNNNWNNNWNNNENNNENNNWNNN'
    #サイコロの目の数を設定
    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):#loc:
    #初期位置
        for i in range(6):
            self.work[i] = self.number[i]
        if loc == 'E':
            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])
        elif loc == 'N':
            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])
        elif loc == 'S':
            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])
        else:
            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])
    
    def query(self, top_num, front_num):
        self.save_data = [i for i in range(6)]
        #元のデータの保存
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]
        
        ret = -1
        
        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break
        return ret;
    

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

q = int(input())
for loop in range(q):
    u, f = map(int, input().split())
    print(dice.query(u, f))

# for tmp_loc in loc_array:
    # dice.roll(tmp_loc)
# print(dice.get_Top())

Submission status: Accepted

Solution code:
import random

class Dice():
    def __init__(self, number):
        self.number = number

    def S(self):
        temp = self.number
        self.number = [temp[4], temp[0], temp[2], temp[3], temp[5], temp[1]]

    def N(self):
        temp = self.number
        self.number = [temp[1], temp[5], temp[2], temp[3], temp[0], temp[4]]

    def E(self):
        temp = self.number
        self.number = [temp[3], temp[1], temp[0], temp[5], temp[4], temp[2]]

    def W(self):
        temp = self.number
        self.number = [temp[2], temp[1], temp[5], temp[0], temp[4], temp[3]]

    def order(self, str):
        for ch in str:
            if ch == "S":
                self.S()
            elif ch == "N":
                self.N()
            elif ch == "E":
                self.E()
            else:
                self.W()

    def query(self, top, front):
        while True:
            drc = random.randint(0, 3)
            self.order("NEWS"[drc])
            if self.number[0] == top and self.number[1] == front:
                return self.number[2]
                break

number = list(map(int, input().split()))
q = int(input())
dice = Dice(number)

for i in range(q):
    t, f = map(int, input().split())
    print(dice.query(t, f))

Submission status: Accepted

Solution code:
from enum import Enum
import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

#0:中央 1:南 2:東 3:西 4:北 5:裏側
class Dice():

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

    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 query(self,top_num,front_num):

        self.save_data = [i for i in range(6)]
        #元の値の保存
        for i in range(len(self.number)):
            self.save_data[i] = self.number[i]

        ret = -1;

        for i in range(len(self.order)):
            self.roll(self.order[i])
            if self.number[0] == top_num and self.number[1] == front_num:
                ret = self.number[2]
                break

        #元の値の復元
        for i in range(len(self.number)):
            self.number[i] = self.save_data[i]

        return ret;




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

num_query = int(input())
for loop in range(num_query):
    top_num,front_num = map(int,input().split())
    print("%d"%(dice.query(top_num, front_num)))

Submission status: Accepted

Solution code:
import enum
class Direction(enum.Enum):
    N = "N"
    E = "E"
    W = "W"
    S = "S"

    @classmethod
    def value_of(cls, value):
        return [v for v in cls if v.value == value][0]


class Dice:
    def __init__(self, *value_list):
        self.__value_list = list(value_list)

    def rotate(self, direction):
        l = self.__value_list
        if  direction == Direction.N:
            l[0],l[1],l[5],l[4] = l[1],l[5],l[4],l[0]
        elif  direction == Direction.E:
            l[0],l[2],l[5],l[3] = l[3],l[0],l[2],l[5]
        elif  direction == Direction.W:
            l[0],l[2],l[5],l[3] = l[2],l[5],l[3],l[0]
        elif  direction == Direction.S:
            l[0],l[1],l[5],l[4] = l[4],l[0],l[1],l[5]

    def adjust_top_front(self, top_value, front_value):
        for _ in range(2):
            for _ in range(3):
                if self.front_value() == front_value:
                    break
                self.rotate(Direction.N)
            if self.front_value() == front_value:
                break
            self.rotate(Direction.E)
        
        for _ in range(3):
            if self.top_value() == top_value:
                break
            self.rotate(Direction.E)

    def top_value(self):
        return self.__value_list[0]

    def front_value(self):
        return self.__value_list[1]

    def right_value(self):
        return self.__value_list[2]


dice = Dice(*input().split())
for _ in range(int(input())):
    top,front = input().split()
    dice.adjust_top_front(top, front)
    print(dice.right_value())

Submission status: Accepted

Solution code:
class dice():
    top = 1
    flont = 2
    right = 3
    def do_N(self):
        temp = self.flont
        self.flont = 7-self.top
        self.top = temp

    def do_S(self):
        temp = 7-self.flont
        self.flont = self.top
        self.top = temp

    def do_E(self):
        temp = self.top
        self.top = 7-self.right
        self.right = temp

    def do_W(self):
        temp = 7-self.top
        self.top = self.right
        self.right = temp

num1 = list(map(int, input().split()))
q = int(input())
dice1 = dice()

for i in range(q):
    top, flont = map(int, input().split())
    if num1[dice1.flont-1] == flont and num1[dice1.top-1] == top:
        ans = num1[dice1.right-1]
    for j in range(4):
        for k in range(4):
            dice1.do_E()
            if num1[dice1.flont-1] == flont and num1[dice1.top-1] == top:
                ans = num1[dice1.right-1]
        dice1.do_N()
        if num1[dice1.flont-1] == flont and num1[dice1.top-1] == top:
            ans = num1[dice1.right-1]

    dice1.do_S()
    dice1.do_E()
    if num1[dice1.flont-1] == flont and num1[dice1.top-1] == top:
        ans = num1[dice1.right-1]
    for j in range(4):
        for k in range(4):
            dice1.do_E()
            if num1[dice1.flont-1] == flont and num1[dice1.top-1] == top:
                ans = num1[dice1.right-1]
        dice1.do_N()
        if num1[dice1.flont-1] == flont and num1[dice1.top-1] == top:
            ans = num1[dice1.right-1]


    print(str(ans))

Submission status: Accepted

Solution code:
# ['表面', '南面', '東面', '西面', '北面', '裏面']
dice1 = [int(d) for d in input().split()]
Q = int(input())

R1 = [
    [0, 1, 2, 3, 4, 5], # 移動なし
    [3, 1, 0, 5, 4, 2], # 東へ1
    [2, 1, 5, 0, 4, 3], # 西へ1
    [4, 0, 2, 3, 5, 1], # 南へ1
    [1, 5, 2, 3, 0, 4], # 北へ1
    [5, 4, 2, 3, 1, 0]  # 北へ2
]

R2 = [0, 3, 1, 4, 2, 5] # 水平回り1

for _ in range(Q):
    F, S = map(int, input().split())
    for r1 in R1:
        dice2 = [dice1[i] for i in r1]
        for _ in range(4):
            dice2 = [dice2[i] for i in R2]
            if dice2[0] == F and dice2[1] == S:
                print(dice2[2])

Submission status: Accepted

Solution code:
F = [int(n) for n in input().split()]
N = int(input())

class Dice():

    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,d):
        if d == "N":
            tmp = self.top
            self.top = self.south
            self.south = self.bottom
            self.bottom = self.north
            self.north = tmp

        elif d == "S":
            tmp = self.top
            self.top = self.north
            self.north = self.bottom
            self.bottom = self.south
            self.south = tmp

        elif d == "E":
            tmp = self.top
            self.top = self.west
            self.west = self.bottom
            self.bottom = self.east
            self.east = tmp

        elif d == "W":
            tmp = self.top
            self.top = self.east
            self.east = self.bottom
            self.bottom = self.west
            self.west = tmp



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

    def setFront(self,front):
        if self.south == front:
            return self.east
        elif self.east == front:
            return self.north
        elif self.west == front:
            return self.south
        elif self.north == front:
            return self.west

    def get_top_value(self):
        return self.top



D = Dice(F)
# for d in D:
#     N.rotate(d)


for _ in range(N):
    top,front = map(int,input().split())
    D.setTop(top)
    print(D.setFront(front))

Submission status: Accepted

Solution code:
class Dice:
    def __init__(self, num):
        self.num = num
    def roll(self, fn):
        if fn == "S":
            ue = self.num[4]
            self.num[4] = self.num[5]
            self.num[5] = self.num[1]
            self.num[1] = self.num[0]
            self.num[0] = ue
        elif fn == "W":
            ue = self.num[2]
            self.num[2] = self.num[5]
            self.num[5] = self.num[3]
            self.num[3] = self.num[0]
            self.num[0] = ue        
        elif fn == "N":
            ue = self.num[1]
            self.num[1] = self.num[5]
            self.num[5] = self.num[4]
            self.num[4] = self.num[0]
            self.num[0] = ue                
 
    def spin(self, fn):
        if fn == "migi":
            mae = self.num[3]
            self.num[3] = self.num[4]
            self.num[4] = self.num[2]
            self.num[2] = self.num[1]
            self.num[1] = mae
num = list(map(int, input().split(" ")))
dice1 = Dice(num)
n = int(input())
a = []
for i in range(n):
    u, f = map(int, input().split(" "))
    count = 0
    while num[0] != u and count<5:
        dice1.roll("S")
        count+=1
    count = 0
    while num[0] != u and count<5:
        dice1.roll("W")
        count+=1        
    while num[1] != f:
        dice1.spin("migi")
    a.append(num[2])
for i in range(n):
    print(a[i])

Submission status: Accepted

Solution code:
def Roll(c, lst) :
    if c == 'N' :
        lst[0], lst[1], lst[5], lst[4] = lst[1], lst[5], lst[4], lst[0]
    elif c == 'S' :
        lst[0], lst[1], lst[5], lst[4] = lst[4], lst[0], lst[1], lst[5]
    elif c == 'E' :
        lst[0], lst[2], lst[5], lst[3] = lst[3], lst[0], lst[2], lst[5]
    elif c == 'W' :
        lst[0], lst[2], lst[5], lst[3] = lst[2], lst[5], lst[3], lst[0]
    return lst
    
import copy
dice_pre = list(map(int, input().split()))
N = int(input())
for i in range(N) :
    final_top, final_front = map(int, input().split())
    dice = copy.copy(dice_pre)
    
    for i in range(4) :
        if dice[1] == final_front :
            break
        else :
            Roll('S', dice)
    if dice[1] != final_front :
        Roll('E', dice)
        for i in range(4) :
            if dice[1] == final_front :
                break
            else :
                Roll('S', dice)
    for i in range(4) :
        if dice[0] == final_top :
            break
        else :
            Roll('E', dice)
    
    print(dice[2])