Dice I

raw_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

input_output: {"inputs": ["1 2 4 8 16 32\nSE\n", "1 2 4 8 16 32\nEESWN\n", "1 2 3 4 5 6\nSWNN\n", "1 2 3 4 5 6\nSWNNEEES\n", "1 2 3 4 5 6\nSWNNEEESSEWWNNE\n", "6 5 4 3 2 1\nSSSSEEENNNWWSEWNNWNWESSE\n", "1 2 3 4 5 6\nS\n", "7 8 9 10 11 12\nW\n", "13 14 15 16 17 18\nN\n", "19 20 21 22 23 24\nE\n", "1 2 3 4 5 6\nSSSSSEEEWWWNNNSSSNEENNNWWWWEEEENNNNNNNSSNNSNSNSNSWEWEWENNN\n", "1 2 3 4 5 6\nNNSESSESSEEEWWEWNENNSEESSNEENENNWEEWWWEENNEENNWWENNNNNSSNNSNSNSNSWEWEWENNN\n", "32 59 68 1 2 12\nSESSWWNWNNSESSNWNWNNSESSWWNWWNSESSWWNWNNSESSEENWNNSESSWWNWNNSESSWWNWNNSESSSSNWNNSESSEWNWNNSESSWWNWSN\n", "32 59 68 1 2 12\nSSNWNNSESSNWNWNNSEWWSSWWNWWNSESSWNNWNNSESSSSNWNNSESSSSNWNNSESSWWNWNNSESSSSNWNNSESSEWNWSSSESSWWNWSNSE\n"], "outputs": ["8\n", "32\n", "4\n", "1\n", "5\n", "4\n", "5\n", "9\n", "14\n", "22\n", "6\n", "5\n", "2\n", "1\n"]}

solutions: ["from enum import Enum\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\n#0:\u4e2d\u592e 1:\u5357 2:\u6771 3:\u897f 4:\u5317 5:\u88cf\u5074\nclass Dice():\n\n    def __init__(self):\n        self.number = [i for i in range(6)]\n        self.work = [i for i in range(6)]\n\n\n    def setNumber(self,n0,n1,n2,n3,n4,n5):\n        self.number[0] = n0\n        self.number[1] = n1\n        self.number[2] = n2\n        self.number[3] = n3\n        self.number[4] = n4\n        self.number[5] = n5\n\n\n    def roll(self,loc):\n        for i in range(6):\n            self.work[i] = self.number[i]\n\n        if loc == 'E':\n            self.setNumber(self.work[3],self.work[1],self.work[0],self.work[5],self.work[4],self.work[2])\n        elif loc == 'N':\n            self.setNumber(self.work[1],self.work[5],self.work[2],self.work[3],self.work[0],self.work[4])\n        elif loc == 'S':\n            self.setNumber(self.work[4],self.work[0],self.work[2],self.work[3],self.work[5],self.work[1])\n        elif loc == 'W':\n            self.setNumber(self.work[2],self.work[1],self.work[5],self.work[0],self.work[4],self.work[3])\n\n\n    def get_Top(self):\n        return self.number[0]\n\n\ndice = Dice()\ntable = list(map(int,input().split()))\ndice.setNumber(table[0], table[1], table[2], table[3], table[4], table[5])\n\nloc_array = str(input())\nfor tmp_loc in loc_array:\n    dice.roll(tmp_loc)\n\nprint(\"%d\"%(dice.get_Top()))\n\n\n", "def roll_front(a):\n    b=[0]*6\n    b[0]=a[4]\n    b[1]=a[0]\n    b[2]=a[2]\n    b[3]=a[3]\n    b[4]=a[5]\n    b[5]=a[1]\n    return b\ndef roll_back(a):\n    b=[0]*6\n    b[0]=a[1]\n    b[1]=a[5]\n    b[2]=a[2]\n    b[3]=a[3]\n    b[4]=a[0]\n    b[5]=a[4]\n    return b\ndef roll_left(a):\n    b=[0]*6\n    b[0]=a[2]\n    b[1]=a[1]\n    b[2]=a[5]\n    b[3]=a[0]\n    b[4]=a[4]\n    b[5]=a[3]\n    return b\ndef roll_right(a):\n    b=[0]*6\n    b[0]=a[3]\n    b[1]=a[1]\n    b[2]=a[0]\n    b[3]=a[5]\n    b[4]=a[4]\n    b[5]=a[2]\n    return b\n\na=list(map(int,input().split()))\ns=input()\nfor si in s:\n    if si=='S':\n        a=roll_front(a)\n    elif si=='N':\n        a=roll_back(a)\n    elif si=='W':\n        a=roll_left(a)\n    else: a=roll_right(a)\nprint(a[0])\n", "class Dice:\n    def __init__(self):\n        self.u=1\n        self.w=2\n        self.s=3\n        self.e=4\n        self.n=5\n        self.d=6\n        self.dic={\"W\":0,\"S\":1,\"E\":2,\"N\":3}\n    \n    def __init__(self,u,w,s,e,n,d):\n        self.u=u\n        self.w=w\n        self.s=s\n        self.e=e\n        self.n=n\n        self.d=d\n        self.dic={\"W\":0,\"S\":1,\"E\":2,\"N\":3}\n\n    def rot(self,way):\n        if isinstance(way,str):\n            way=self.dic[way]\n\n        if(way==0):\n            c=self.u\n            self.u=self.e\n            self.e=self.d\n            self.d=self.w\n            self.w=c\n        elif way==1:\n            c=self.u\n            self.u=self.n\n            self.n=self.d\n            self.d=self.s\n            self.s=c\n        elif way==2:\n            c=self.u\n            self.u=self.w\n            self.w=self.d\n            self.d=self.e\n            self.e=c\n        else :\n            c=self.u\n            self.u=self.s\n            self.s=self.d\n            self.d=self.n\n            self.n=c\n\nu,s,e,w,n,d=map(int,input().split())\ndice=Dice(u,w,s,e,n,d)\nst=input()\nfor c in st:\n    dice.rot(c)\nprint(dice.u)\n", "D = [\n    (1, 5, 2, 3, 0, 4), # 'U'\n    (3, 1, 0, 5, 4, 2), # 'R'\n    (4, 0, 2, 3, 5, 1), # 'D'\n    (2, 1, 5, 0, 4, 3), # 'L'\n]\nC = 'NESW'\n\n*L, = map(int, input().split())\nfor c in input():\n    L[:] = (L[e] for e in D[C.index(c)])\nprint(L[0])\n", "A = list(map(int, input().split()))\nS = list(input())\n\nn = len(S)\nfor i in range(n):\n    preA0 = A[0]\n    if S[i] == 'S':\n        A[0] = A[4]\n        A[4] = A[5]\n        A[5] = A[1]\n        A[1] = preA0\n    elif S[i] == 'E':\n        A[0] = A[3]\n        A[3] = A[5]\n        A[5] = A[2]\n        A[2] = preA0\n    elif S[i] == 'N':\n        A[0] = A[1]\n        A[1] = A[5]\n        A[5] = A[4]\n        A[4] = preA0\n    elif S[i] == 'W':\n        A[0] = A[2]\n        A[2] = A[5]\n        A[5] = A[3]\n        A[3] = preA0\nprint(A[0])\n\n", "import sys\n\n# READ_FROM_FILE = True\nREAD_FROM_FILE = False\n\n\nclass Dice:\n    def __init__(self, faces):\n        self._faces = faces\n        return\n\n    def roll_north(self):\n        tmp = self._faces[0]\n        self._faces[0] = self._faces[1]\n        self._faces[1] = self._faces[5]\n        self._faces[5] = self._faces[4]\n        self._faces[4] = tmp\n        return\n\n    def roll_east(self):\n        tmp = self._faces[0]\n        self._faces[0] = self._faces[3]\n        self._faces[3] = self._faces[5]\n        self._faces[5] = self._faces[2]\n        self._faces[2] = tmp\n        return\n\n    def roll_west(self):\n        tmp = self._faces[0]\n        self._faces[0] = self._faces[2]\n        self._faces[2] = self._faces[5]\n        self._faces[5] = self._faces[3]\n        self._faces[3] = tmp\n        return\n\n    def roll_south(self):\n        tmp = self._faces[0]\n        self._faces[0] = self._faces[4]\n        self._faces[4] = self._faces[5]\n        self._faces[5] = self._faces[1]\n        self._faces[1] = tmp\n        return\n\n    def get_top(self):\n        return self._faces[0]\n\n\ndef main():\n    if READ_FROM_FILE:\n        f = open('test0.txt', 'r')\n    else:\n        f = sys.stdin\n\n    faces = list(map(int, f.readline().split()))\n    op_str = f.readline().rstrip('\\n')\n\n    d = Dice(faces)\n    for op in op_str:\n        if op == 'N':\n            d.roll_north()\n        elif op == 'E':\n            d.roll_east()\n        elif op == 'W':\n            d.roll_west()\n        else:\n            d.roll_south()\n    print(d.get_top())\n\n    if READ_FROM_FILE:\n        f.close()\n    return\n\n\nif __name__ == '__main__':\n    main()\n\n", "dice = list(map(int, input().split()))\ncmd = input()\nfor i in range(len(cmd)):\n  if cmd[i] == 'N':\n    dice[0], dice[1] = dice[1], dice[0]\n    dice[1], dice[5] = dice[5], dice[1]\n    dice[5], dice[4] = dice[4], dice[5]\n  elif cmd[i] == 'E':\n    dice[0], dice[3] = dice[3], dice[0]\n    dice[3], dice[5] = dice[5], dice[3]\n    dice[5], dice[2] = dice[2], dice[5]\n  elif cmd[i] == 'W':\n    dice[0], dice[2] = dice[2], dice[0]\n    dice[2], dice[5] = dice[5], dice[2]\n    dice[5], dice[3] = dice[3], dice[5]\n  else:\n    dice[0], dice[4] = dice[4], dice[0]\n    dice[4], dice[5] = dice[5], dice[4]\n    dice[5], dice[1] = dice[1], dice[5]\nprint(dice[0])\n", "class Dice:\n    def __init__(self, face_vals):\n        self.faces = dict(zip(['top', 'front', 'right',\n                               'left', 'back', 'bottom'], face_vals))\n\n    def roll(self, direction):\n        if direction == 'N':\n            self.faces['top'], self.faces['front'], self.faces['bottom'], \\\n            self.faces['back'] = self.faces['front'], self.faces['bottom'], \\\n            self.faces['back'], self.faces['top']\n        elif direction == 'S':\n            self.faces['top'], self.faces['front'], self.faces['bottom'], \\\n            self.faces['back'] = self.faces['back'], self.faces['top'], \\\n            self.faces['front'], self.faces['bottom']\n        elif direction == 'E':\n            self.faces['top'], self.faces['right'], self.faces['bottom'], \\\n            self.faces['left'] = self.faces['left'], self.faces['top'], \\\n            self.faces['right'], self.faces['bottom']\n        else:\n            self.faces['top'], self.faces['right'], self.faces['bottom'], \\\n            self.faces['left'] = self.faces['right'], self.faces['bottom'], \\\n            self.faces['left'], self.faces['top']\n\n\nface_vals = input().split()\n\ndice = Dice(face_vals)\n\nfor i in input():\n    dice.roll(i)\n\nprint(dice.faces['top'])\n", "class Dice:\n\n    __slots__ = [\"data\"]\n    state = [\"top\", \"front\", \"right\", \"left\", \"back\", \"bottom\"]\n    index = {c:i for i,c in enumerate(state)}\n \n    def __init__(self, data=list(range(1,7))):\n        self.data = data[:]\n    \n    def __getitem__(self, key):\n        if type(key) is int:\n            return self.data[key]\n        else:\n            return self.data[self.index[key]]\n    \n    def __str__(self):\n        return str(self.data)\n\n    def move_front(self):\n        self.data = [self.data[4], self.data[0], self.data[2], self.data[3], self.data[5], self.data[1]]\n        \n    def move_back(self):\n        self.data = [self.data[1], self.data[5], self.data[2], self.data[3], self.data[0], self.data[4]]\n\n    def move_left(self):\n        self.data = [self.data[2], self.data[1], self.data[5], self.data[0], self.data[4], self.data[3]]\n    \n    def move_right(self):\n        self.data = [self.data[3], self.data[1], self.data[0], self.data[5], self.data[4], self.data[2]]\n        \n    def turn_left(self):\n        self.data = [self.data[0], self.data[2], self.data[4], self.data[1], self.data[3], self.data[5]]\n\n    def turn_right(self):\n        self.data = [self.data[0], self.data[3], self.data[1], self.data[4], self.data[2], self.data[5]]\n\n    def all(self):\n        tmp = Dice(self.data)\n        for i in range(24):\n            yield tmp\n            tmp.turn_right()\n            if i&7 == 7:\n                tmp.move_back()\n            elif i&3 == 3:\n                tmp.move_right()\n\ndice = Dice(list(map(int, input().split())))\nfor s in input():\n    if s == \"S\":\n        dice.move_front()\n    elif s == \"N\":\n        dice.move_back()\n    elif s == \"W\":\n        dice.move_left()\n    else:\n        dice.move_right()\nprint(dice[\"top\"])\n", "d=input().split()\ns={'N':\"152304\",'W':\"215043\",'E':\"310542\",'S':\"402351\"}\nfor o in input():\n d=[d[int(i)]for i in s[o]]\nprint(d[0])\n", "class Dice:\n    def __init__(self, lst):\n        self.men = lst\n\n    def rotate1(self):\n        n = self.men[0]\n        self.men[0] = self.men[3]\n        self.men[3] = self.men[5]\n        self.men[5] = self.men[2]\n        self.men[2] = n\n\n    def rotate2(self):\n        n = self.men[0]\n        self.men[0] = self.men[1]\n        self.men[1] = self.men[5]\n        self.men[5] = self.men[4]\n        self.men[4] = n\n\n    def rotate(self, s):\n        if(s == \"N\"):\n            self.rotate2()\n        elif(s == \"S\"):\n            for _ in range(3):\n                self.rotate2()\n        elif(s == \"E\"):\n            self.rotate1()\n        elif(s == \"W\"):\n            for _ in range(3):\n                self.rotate1()\n\n    def ans(self):\n        return self.men[0]\n\n\nlst = list(map(int, input().split()))\nord = input()\ndice = Dice(lst)\nfor i in range(len(ord)):\n    dice.rotate(ord[i])\nprint(dice.ans())\n", "class Dice:\n    def __init__(self, num):\n        self.num = num\n        \n    def rot(self, S):\n        num = self.num.copy()\n        if S == \"E\":\n            num[0] = self.num[3]\n            num[2] = self.num[0]\n            num[3] = self.num[5]\n            num[5] = self.num[2]\n        elif S == \"W\":\n            num[0] = self.num[2]\n            num[2] = self.num[5]\n            num[3] = self.num[0]\n            num[5] = self.num[3]\n        elif S == \"S\":\n            num[0] = self.num[4]\n            num[1] = self.num[0]\n            num[5] = self.num[1]\n            num[4] = self.num[5]\n        else:\n            num[0] = self.num[1]\n            num[1] = self.num[5]\n            num[5] = self.num[4]\n            num[4] = self.num[0]\n        self.num = num\n        \ndice = Dice(list(map(int, input().split())))\nrot = input()\nfor s in rot:\n    dice.rot(s)\nprint(dice.num[0])\n", "f = list(map(int, input().split()))\nm = input()\np = [0, 1, 2]\nfor i in range(len(m)):\n\tt = p[0]\n\tif m[i] == \"N\":\n\t\tp[0] = p[1]\n\t\tp[1] = 5 - t\n\telif m[i] == \"W\":\n\t\tp[0] = p[2]\n\t\tp[2] = 5 - t\n\telif m[i] == \"S\":\n\t\tp[0] = 5 - p[1]\n\t\tp[1] = t\n\telif m[i] == \"E\":\n\t\tp[0] = 5 - p[2]\n\t\tp[2] = t\nprint(f[p[0]])\n", "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)}\nd=input().split()\nfor x in input():\n    d=[d[y]for y in r[x]]\nprint(d[0])\n", "class Dice(object):\n    def __init__(self, labels):\n        self.stat = labels\n\n    def roll_e(self):\n        self.stat[0], self.stat[2], self.stat[5], self.stat[3] = self.stat[3], self.stat[0], self.stat[2], self.stat[5]\n\n    def roll_w(self):\n        self.stat[0], self.stat[2], self.stat[5], self.stat[3] = self.stat[2], self.stat[5], self.stat[3], self.stat[0]\n\n    def roll_n(self):\n        self.stat[0], self.stat[1], self.stat[5], self.stat[4] = self.stat[1], self.stat[5], self.stat[4], self.stat[0]\n\n    def roll_s(self):\n        self.stat[0], self.stat[1], self.stat[5], self.stat[4] = self.stat[4], self.stat[0], self.stat[1], self.stat[5]\n\n    def get_top(self):\n        return self.stat[0]\n\n\ndice = Dice(input().split())\ncommands = input()\nfor command in commands:\n    if command == \"E\":\n        dice.roll_e()\n    elif command == \"W\":\n        dice.roll_w()\n    elif command == \"N\":\n        dice.roll_n()\n    elif command == \"S\":\n        dice.roll_s()\nprint(dice.get_top())\n\n", "l = list(map(int, input().split()))\norder = list(input())\nfor i in order:\n    if i == \"W\":\n        l = [l[2], l[1], l[5], l[0], l[4], l[3]]\n    elif i == \"S\":\n        l = [l[4], l[0], l[2], l[3], l[5], l[1]]\n    elif i == \"E\":\n        l = [l[3], l[1], l[0], l[5], l[4], l[2]]\n    else:\n        l = [l[1], l[5], l[2], l[3], l[0], l[4]]\nprint(l[0])\n", "import math\n\nclass Dice:\n    def __init__(self, top, south, east, west, north, bottom):\n        self.top = top\n        self.south = south\n        self.east = east\n        self.west = west\n        self.north = north\n        self.bottom = bottom\n\n    def roll_east(self):\n        tmp = self.top\n        self.top = self.west\n        self.west = self.bottom\n        self.bottom = self.east\n        self.east = tmp\n\n    def roll_north(self):\n        tmp = self.top\n        self.top = self.south\n        self.south = self.bottom\n        self.bottom = self.north\n        self.north = tmp\n\n    def roll_south(self):\n        tmp = self.top\n        self.top = self.north\n        self.north = self.bottom\n        self.bottom = self.south\n        self.south = tmp\n\n    def roll_west(self):\n        tmp = self.top\n        self.top = self.east\n        self.east = self.bottom\n        self.bottom = self.west\n        self.west = tmp\n\n\na, b, c, d, e, f = map(int, input().split())\ndice = Dice(a, b, c, d, e, f)\ncommand = input()\nfor c in command:\n    if c == 'E':\n        dice.roll_east()\n    elif c == 'N':\n        dice.roll_north()\n    elif c == 'S':\n        dice.roll_south()\n    elif c == 'W':\n        dice.roll_west()\nprint(dice.top)\n\n", "import sys\n#\u7acb\u65b9\u4f53\u3067\u6570\u5b57\u304c\u81ea\u7531\u306a\u3055\u3044\u3053\u308d\nclass Dice:\n    def __init__(self,top,bottom,front,rear,right,left):\n        self.top=top\n        self.front=front\n        self.right=right\n        self.bottom=bottom\n        self.rear=rear\n        self.left=left\n\n    def rotate_front(self):\n        t,b,f,r=self.top,self.bottom,self.front,self.rear\n        self.top=r\n        self.bottom=f\n        self.front=t\n        self.rear=b\n\n    def rotate_rear(self):\n        t,b,f,r=self.top,self.bottom,self.front,self.rear\n        self.top=f\n        self.bottom=r\n        self.front=b\n        self.rear=t\n\n    def rotate_right(self):\n        t,b,r,l=self.top,self.bottom,self.right,self.left\n        self.top=l\n        self.bottom=r\n        self.right=t\n        self.left=b\n\n    def rotate_left(self):\n        t,b,r,l=self.top,self.bottom,self.right,self.left\n        self.top=r\n        self.bottom=l\n        self.right=b\n        self.left=t\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef main():\n    top,front,right,left,rear,bottom=map(int, input().split())\n    d=Dice(top,bottom,front,rear,right,left)\n    s=input()\n    for c in s:\n        if c==\"N\":d.rotate_rear()\n        if c==\"S\":d.rotate_front()\n        if c==\"E\":d.rotate_right()\n        if c==\"W\":d.rotate_left()\n    print(d.top)\n\nmain()\n", "# -*- coding: utf-8 -*-\n\nimport sys\nimport os\nimport math\n\n\ndice = list(map(int, input().split()))\norders = input().strip()\nfor c in orders:\n    copy = dice[:]\n    if c == 'E':\n        dice[2] = copy[0]\n        dice[5] = copy[2]\n        dice[3] = copy[5]\n        dice[0] = copy[3]\n    elif c == 'N':\n        dice[0] = copy[1]\n        dice[4] = copy[0]\n        dice[5] = copy[4]\n        dice[1] = copy[5]\n        pass\n    elif c == 'S':\n        dice[1] = copy[0]\n        dice[0] = copy[4]\n        dice[4] = copy[5]\n        dice[5] = copy[1]\n    elif c == 'W':\n        dice[0] = copy[2]\n        dice[2] = copy[5]\n        dice[5] = copy[3]\n        dice[3] = copy[0]\nprint(dice[0])\n", "class Dice:\n    def __init__(self, a, b, c, d, e, f):\n        self.top = a\n        self.front = b\n        self.right = c\n        self.left = d\n        self.behind = e\n        self.bottom = f\n\n    def S(self):\n        self.top, self.front, self.behind, self.bottom = self.behind, self.top, self.bottom, self.front\n\n    def N(self):\n        self.behind, self.top, self.bottom, self.front = self.top, self.front, self.behind, self.bottom\n\n    def E(self):\n        self.top, self.bottom, self.left, self.right = self.left, self.right, self.bottom, self.top\n\n    def W(self):\n        self.left, self.right, self.bottom, self.top = self.top, self.bottom, self.left, self.right\n\n\ndice=Dice(*[int(i) for i in input().split(\" \")])\nfor s in input():\n    if s==\"S\":\n        dice.S()\n    if s==\"E\":\n        dice.E()\n    if s==\"N\":\n        dice.N()\n    if s==\"W\":\n        dice.W()\nprint(dice.top)\n\n", "\ndef Roll(c, lst) :\n    if c == 'N' :\n        lst[0], lst[1], lst[5], lst[4] = lst[1], lst[5], lst[4], lst[0]\n    elif c == 'S' :\n        lst[0], lst[1], lst[5], lst[4] = lst[4], lst[0], lst[1], lst[5]\n    elif c == 'E' :\n        lst[0], lst[2], lst[5], lst[3] = lst[3], lst[0], lst[2], lst[5]\n    elif c == 'W' :\n        lst[0], lst[2], lst[5], lst[3] = lst[2], lst[5], lst[3], lst[0]\n    return lst\n    \n\ndice = list(map(int, input().split()))\n\ndirection = list(input())\nfor i in range(len(direction)) :\n    D = direction.pop(0)\n    Roll(D, dice)\n\n\nprint(dice[0])\n", "class dice:\n    def roll(self,direction):\n        if direction==\"N\":\n            self.face=[self.face[1],self.face[5],self.face[2],self.face[3],self.face[0],self.face[4]]\n        if direction==\"E\":\n            self.face=[self.face[3],self.face[1],self.face[0],self.face[5],self.face[4],self.face[2]]\n        if direction==\"W\":\n            self.face=[self.face[2],self.face[1],self.face[5],self.face[0],self.face[4],self.face[3]]\n        if direction==\"S\":\n            self.face=[self.face[4],self.face[0],self.face[2],self.face[3],self.face[5],self.face[1]]\ndice1=dice()\ndice1.face=list(map(int,input().split()))\nfor i in input():\n    dice1.roll(i)\nprint(dice1.face[0])\n", "class Dice(object):\n    \"\"\"\n    6??\u00a2???????????????\n    ?????\u00a2???top, ?????\u00a2???bottom???????????\\??????4??\u00a2??????????????? north, south, east, west ??\u00a8?????\u00b6???\n    \"\"\"\n    def __init__(self, faces):\n        # faces???????????????????????\u00a8?????????????????????????????????\n        # ???????????? top, south, east, west, north, bottom ????????\u00a7????\u00b4????????????????????????\u00a8??????????????????????????\u00a7???top??????????????\u00a3????????????\n        self.top = faces[0]\n        self.south = faces[1]\n        self.east = faces[2]\n        self.west = faces[3]\n        self.north = faces[4]\n        self.bottom = faces[5]\n\n    def rotate(self, dir):\n        # ???????????????dir??????????????????????????\u00a2?????????\n        # ????????????N, S, E, W???????????????????????????(1??????)??\u00a7????????????\n        if dir == 'N':\n            temp = self.top\n            self.top = self.south\n            self.south = self.bottom\n            self.bottom = self.north\n            self.north = temp\n        elif dir == 'S':\n            temp = self.top\n            self.top = self.north\n            self.north = self.bottom\n            self.bottom = self.south\n            self.south = temp\n        elif dir == 'E':\n            temp = self.top\n            self.top = self.west\n            self.west = self.bottom\n            self.bottom = self.east\n            self.east = temp\n        elif dir == 'W':\n            temp = self.top\n            self.top = self.east\n            self.east = self.bottom\n            self.bottom = self.west\n            self.west = temp\n        # self.print()\n\n    def get_top_value(self):\n        return self.top\n\n    def print(self):\n        print('=' * 64)\n        print('top: {0}'.format(self.top))\n        print('south: {0}'.format(self.south))\n        print('bottom: {0}'.format(self.bottom))\n        print('north: {0}'.format(self.north))\n        print('east: {0}'.format(self.east))\n        print('west: {0}'.format(self.west))\n        print('=' * 64)\n\n\nif __name__ == '__main__':\n    # ??????????????\\???\n    dice_values = [int(x) for x in input().split(' ')]\n    rotations = input()\n\n    # ????????????????????????????????\u00a2?????????\n    d = Dice(dice_values)\n    for r in rotations:\n        d.rotate(r)\n\n    # ?????\u00a2??????????\u00a2????????????????\n    print('{0}'.format(d.get_top_value()))\n", "dice = list(map(int, input().split()))\nslist = input()\n\nfor s in slist:\n    if s == \"N\":\n        next = list(\"263415\")\n    elif s == \"E\":\n        next = list(\"421653\")\n    elif s == \"S\":\n        next = list(\"513462\")\n    else:\n        next = list(\"326154\")\n\n    tmp = [0] * 6\n    for i, n in enumerate(next):\n        tmp[i] = dice[int(n)-1]\n\n    dice = tmp\n\nprint(dice[0])\n\n", "class Dice:\n    def __init__(self,dice):\n        self.d = dice[:]\n    def move(self,s):\n        self.n = len(s)\n        for i in range(self.n):\n            if s[i] == 'S':\n                self.d[0],self.d[1],self.d[2],self.d[3],self.d[4],self.d[5] = self.d[4],self.d[0],self.d[2],self.d[3],self.d[5],self.d[1]\n            elif s[i] == 'N':\n                self.d[0],self.d[1],self.d[2],self.d[3],self.d[4],self.d[5] = self.d[1],self.d[5],self.d[2],self.d[3],self.d[0],self.d[4]\n            elif s[i] == 'W':\n                self.d[0],self.d[1],self.d[2],self.d[3],self.d[4],self.d[5] = self.d[2],self.d[1],self.d[5],self.d[0],self.d[4],self.d[3]\n            elif s[i] == 'E':\n                self.d[0],self.d[1],self.d[2],self.d[3],self.d[4],self.d[5] = self.d[3],self.d[1],self.d[0],self.d[5],self.d[4],self.d[2]\n        return self.d\n\nd = list(map(int,input().split()))\ns = input()\ndicer = Dice(d)\nans = dicer.move(s)\nprint(ans[0])\n", "def NRoll():\n    Dice[4], Dice[5], Dice[1], Dice[0] = Dice[0], Dice[4], Dice[5], Dice[1]\ndef ERoll():\n    Dice[2], Dice[0], Dice[3], Dice[5] = Dice[0], Dice[3], Dice[5], Dice[2]\ndef WRoll():\n    Dice[3], Dice[5], Dice[2], Dice[0] = Dice[0], Dice[3], Dice[5], Dice[2]\ndef SRoll():\n    Dice[1], Dice[0], Dice[4], Dice[5] = Dice[0], Dice[4], Dice[5], Dice[1]\n\n\nDice = list(map(int, input().split()))\nroll = input()\n\nfor i in range(len(roll)):\n    if roll[i] == \"N\":\n        NRoll()\n    elif roll[i] == \"E\":\n        ERoll()\n    elif roll[i] == \"W\":\n        WRoll()\n    elif roll[i] == \"S\":\n        SRoll()\n\nprint(Dice[0])\n", "dice = list(map(str, input().split()))\ndirection = input()\nfor i in range(len(direction)):\n    if direction[i] == \"N\":\n        dice[0], dice[1], dice[4], dice[5] = dice[1], dice[5], dice[0], dice[4]\n    elif direction[i] == \"S\":\n        dice[0], dice[1], dice[4], dice[5] = dice[4], dice[0], dice[5], dice[1]\n    elif direction[i] == \"W\":\n        dice[0], dice[2], dice[3], dice[5] = dice[2], dice[5], dice[0], dice[3]\n    else:\n        dice[0], dice[2], dice[3], dice[5] = dice[3], dice[0], dice[5], dice[2]\nprint(dice[0])\n", "class Dice:\n    def __init__(self, vs):\n        self.v1, self.v2, self.v3, self.v4, self.v5, self.v6 = vs\n\n    def roll(self, dir):\n        if dir == \"E\":\n            self.v1, self.v2, self.v3, self.v4, self.v5, self.v6 = self.v4, self.v2, self.v1, self.v6, self.v5, self.v3\n        elif dir == \"W\":\n            self.v1, self.v2, self.v3, self.v4, self.v5, self.v6 = self.v3, self.v2, self.v6, self.v1, self.v5, self.v4\n        elif dir == \"S\":\n            self.v1, self.v2, self.v3, self.v4, self.v5, self.v6 = self.v5, self.v1, self.v3, self.v4, self.v6, self.v2\n        elif dir == \"N\":\n            self.v1, self.v2, self.v3, self.v4, self.v5, self.v6 = self.v2, self.v6, self.v3, self.v4, self.v1, self.v5\n\n    def top(self):\n        return self.v1\n\nval = list(map(int, input().split()))\ns = input()\n\ndice = Dice(val)\nfor dir in list(s):\n    dice.roll(dir)\n\nprint(dice.top())\n", "mask = {'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)}\n\ndice = input().split()\n\nfor c in input():\n    dice = [dice[i] for i in mask[c]]\n\nprint(dice[0])\n", "s = list(map(int,input().split()))\n\ntop = 0\nunder = 5\nsides = [1,2,4,3]\n\nsig = list(input())\nfor i in sig:\n    if i == \"N\":\n        top,sides[0],under,sides[2] = sides[0],under,sides[2],top\n    elif i == \"S\":\n        top,sides[0],under,sides[2] = sides[2],top,sides[0],under\n    elif i == \"E\":\n        top,sides[1],under,sides[3] = sides[3],top,sides[1],under\n    else:\n        top,sides[1],under,sides[3] = sides[1],under,sides[3],top\n\nprint(s[top])\n", "class Dice:\n    def __init__(self, dice):\n        self.dice = dice\n    \n    def roll(self, i, j, k, l):\n        self.dice[i], self.dice[j], self.dice[k], self.dice[l] = self.dice[j], self.dice[k], self.dice[l], self.dice[i] \n        \n    def roll_x(self):\n        self.roll(0, 3, 5, 2)\n        \n    def roll_y(self):\n        self.roll(0, 1, 5, 4)\n        \n    def output(self):\n        print(self.dice[0])\n        \nd = list(map(int, input().split()))\ndice = Dice(d)\ncom = input()\nfor c in com:\n    if c == \"E\": dice.roll_x()\n    elif c == \"N\": dice.roll_y()\n    elif c == \"S\": \n        for i in range(3): dice.roll_y()\n    elif c == \"W\": \n        for i in range(3): dice.roll_x()\ndice.output()\n", "class dice:\n    def __init__(self, nums):\n        self.up, self.front, self.right, self.left, self.back, self.down = nums\n    \n    def East(self):\n        self.up, self.right, self.down, self.left = self.left, self.up, self.right, self.down\n    \n    def North(self):\n        self.up, self.front, self.down, self.back = self.front, self.down, self.back, self.up\n    \n    def South(self):\n        self.up, self.front, self.down, self.back = self.back, self.up, self.front, self.down\n    \n    def West(self):\n        self.up, self.right, self.down, self.left = self.right, self.down, self.left, self.up\n\nif __name__ == \"__main__\":\n    nums = list(map(int, input().split()))\n    D = dice(nums)\n    S = input()\n    \n    for s in S:\n        if s == \"E\":\n            D.East()\n        elif s == \"N\":\n            D.North()\n        elif s == \"S\":\n            D.South()\n        else:\n            D.West()\n    \n    print(D.up)\n", "# Aizu Problem ITP_1_11_A: Dice I\n#\nimport sys, math, os\n\n# read input:\nPYDEV = os.environ.get('PYDEV')\nif PYDEV==\"True\":\n    sys.stdin = open(\"sample-input.txt\", \"rt\")\n\n\ndef do_roll(dice, roll):\n    d1, d2, d3, d4, d5, d6 = dice\n    if roll == 'E':\n        return [d4, d2, d1, d6, d5, d3]\n    elif roll == 'W':\n        return [d3, d2, d6, d1, d5, d4]\n    elif roll == 'N':\n        return [d2, d6, d3, d4, d1, d5]\n    elif roll == 'S':\n        return [d5, d1, d3, d4, d6, d2]\n    else:\n        assert False, \"We should never reach this point!\"\n    \n\ndice = [int(_) for _ in input().split()]\nfor roll in input().strip():\n    dice = do_roll(dice, roll)\n\nprint(dice[0])\n", "class Dice:\n    [U, S, E, W, N, D] = range(6)\n    def __init__(self, a):\n        self.f = a\n\n    def rot(self, dir):\n        tmp = self.f[U]\n        if dir =='N':\n            self.f[U] = self.f[S]\n            self.f[S] = self.f[D]\n            self.f[D] = self.f[N]\n            self.f[N] = tmp\n\n        elif dir  == 'E':\n            self.f[U] = self.f[W]\n            self.f[W] = self.f[D]\n            self.f[D] = self.f[E]\n            self.f[E] = tmp\n\n        elif dir == 'S':\n            self.f[U] = self.f[N]\n            self.f[N] = self.f[D]\n            self.f[D] = self.f[S]\n            self.f[S] = tmp\n\n        elif dir == 'W':\n            self.f[U] = self.f[E]\n            self.f[E] = self.f[D]\n            self.f[D] = self.f[W]\n            self.f[W] = tmp\n\n        return\n\n[U, S, E, W, N, D] = range(6)\ndice = Dice(input().split())\nfor c in input():\n    dice.rot(c)\nprint (dice.f[U])\n\n", "dice = list(map(int,input().split()))\nx = list(input())\n\ndef move(x):\n    if x == \"N\":\n        dice[0],dice[1],dice[2],dice[3],dice[4],dice[5] = dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]\n\n    elif x == \"W\":\n        dice[0],dice[1],dice[2],dice[3],dice[4],dice[5] = dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]\n\n    elif x == \"E\":\n        dice[0],dice[1],dice[2],dice[3],dice[4],dice[5] = dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]\n\n    elif x == \"S\":\n        dice[0],dice[1],dice[2],dice[3],dice[4],dice[5] = dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]\n\nfor i in range(len(x)):\n    move(x[i])\nprint(dice[0])\n", "class Dice:\n\tdef __init__(self, init_val):\n\t\tself.top = init_val[0]\n\t\tself.south = init_val[1]\n\t\tself.east = init_val[2]\n\t\tself.west = init_val[3]\n\t\tself.north = init_val[4]\n\t\tself.bottom = init_val[5]\n\tdef roll_north(self):\n\t\tself.top, self.north, self.bottom, self.south = \\\n\t\tself.south, self.top, self.north, self.bottom\n\tdef roll_south(self):\n\t\tself.top, self.north, self.bottom, self.south = \\\n\t\tself.north, self.bottom, self.south, self.top\n\tdef roll_west(self):\n\t\tself.top, self.west, self.bottom, self.east = \\\n\t\tself.east, self.top, self.west, self.bottom\n\tdef roll_east(self):\n\t\tself.top, self.west, self.bottom, self.east = \\\n\t\tself.west, self.bottom, self.east, self.top\n\tdef print_top(self):\n\t\tprint(self.top)\n\t\t\ninit_val = list(map(int, input().split(\" \")))\ndice = Dice(init_val)\ns = input()\nfor c in s:\n\tif c == \"S\":\n\t\tdice.roll_south()\n\telif c == \"N\":\n\t\tdice.roll_north()\n\telif c == \"E\":\n\t\tdice.roll_east()\n\telif c == \"W\":\n\t\tdice.roll_west()\ndice.print_top()\n", "def solve():\n    TOP = 0\n    SOUTH = 1\n    EAST = 2\n    WEST = 3\n    NORTH = 4\n    BOTTOM = 5\n    class Dice():\n        def __init__(self, faces):\n            self.faces = faces\n        \n        def _replace(self, face_directions):\n            self.faces = [ self.faces[direction] for direction in face_directions ]\n\n        def roll(self, direction):\n            if direction == \"E\":\n                self._replace([WEST, SOUTH, TOP, BOTTOM, NORTH, EAST])\n            elif direction == \"W\":\n                self._replace([EAST, SOUTH, BOTTOM, TOP, NORTH, WEST])\n            elif direction == \"S\":\n                self._replace([NORTH, TOP, EAST, WEST, BOTTOM, SOUTH])\n            elif direction == \"N\":\n                self._replace([SOUTH, BOTTOM, EAST, WEST, TOP, NORTH])\n        def get_top(self):\n            return self.faces[TOP]\n    \n    faces = list(map(int, input().split()))\n    dice = Dice(faces)\n    commands = str(input())\n    for command in commands:\n        dice.roll(command)\n    print(dice.get_top())\n\nsolve()\n\n", "def north(list):\n    List = []\n    List.append(list[1])\n    List.append(list[5])\n    List.append(list[2])\n    List.append(list[3])\n    List.append(list[0])\n    List.append(list[4])\n    return List\n\ndef west(list):\n    List = []\n    List.append(list[2])\n    List.append(list[1])\n    List.append(list[5])\n    List.append(list[0])\n    List.append(list[4])\n    List.append(list[3])\n    return List\n    \ndef south(list):\n    List = []\n    List.append(list[4])\n    List.append(list[0])\n    List.append(list[2])\n    List.append(list[3])\n    List.append(list[5])\n    List.append(list[1])\n    return List\n\ndef east(list):\n    List = []\n    List.append(list[3])\n    List.append(list[1])\n    List.append(list[0])\n    List.append(list[5])\n    List.append(list[4])\n    List.append(list[2])\n    return List\n\ndice = list(map(int, input().split()))\nx = str(input())\ny = list(x)\nfor i in range(len(x)):\n    if y[i] == 'N':\n        dice[0:5] = north(dice)\n    elif y[i] == 'W':\n        dice[0:5] = west(dice)\n    elif y[i] == 'S':\n        dice[0:5] = south(dice)\n    elif y[i] == 'E':\n        dice[0:5] = east(dice)\nprint(dice[0])\n", "def north(d):\n    d[0], d[1], d[5], d[4] = d[1], d[5], d[4], d[0]\n\n\ndef west(d):\n    d[0], d[2], d[5], d[3] = d[2], d[5], d[3], d[0]\n\n\ndef east(d):\n    d[0], d[3], d[5], d[2] = d[3], d[5], d[2], d[0]\n\n\ndef south(d):\n    d[0], d[4], d[5], d[1] = d[4], d[5], d[1], d[0]\n\n\nF = {'N': north, 'W': west, 'E': east, 'S': south}\n\nd, os = list(map(int, input().split())), input()\n\nfor o in os:\n    F[o](d)\n\nprint(d[0])\n", "daise=list(map(int,input().split()))\na=input()\nA=list(a)\nn=len(A)\nfor m in range(n):\n\tif A[m]=='S':\n\t\tx=daise[0]\n\t\tdaise[0]=daise[4]\n\t\tdaise[4]=daise[5]\n\t\tdaise[5]=daise[1]\n\t\tdaise[1]=x\n\telif A[m]=='E':\n\t\tx=daise[0]\n\t\tdaise[0]=daise[3]\n\t\tdaise[3]=daise[5]\n\t\tdaise[5]=daise[2]\n\t\tdaise[2]=x\n\telif A[m]=='W':\n\t\tx=daise[0]\n\t\tdaise[0]=daise[2]\n\t\tdaise[2]=daise[5]\n\t\tdaise[5]=daise[3]\n\t\tdaise[3]=x\n\t\tpass\n\telif A[m]=='N':\n\t\tx=daise[0]\n\t\tdaise[0]=daise[1]\n\t\tdaise[1]=daise[5]\n\t\tdaise[5]=daise[4]\n\t\tdaise[4]=x\n\t\tpass\nprint(daise[0])\n", "from enum import IntEnum\n\n\nclass Direction(IntEnum):\n    NORTH = 0\n    EAST = 1\n    SOUTH = 2\n    WEST = 3\n\n\nclass Dice:\n    \"\"\"Dice class implements the structure of a dice\n    having six faces.\n    \"\"\"\n    def __init__(self, v1, v2, v3, v4, v5, v6):\n        self.top = 1\n        self.heading = Direction.NORTH\n        self.values = [v1, v2, v3, v4, v5, v6]\n\n    def to_dice_axis(self, d):\n        return (d - self.heading) % 4\n\n    def to_plain_axis(self, d):\n        return (self.heading + d) % 4\n\n    def roll(self, d):\n        faces = [[(2, Direction.NORTH), (6, Direction.NORTH),\n                  (6, Direction.WEST), (6, Direction.EAST),\n                  (6, Direction.SOUTH), (5, Direction.SOUTH)],\n                 [(4, Direction.EAST), (4, Direction.NORTH),\n                  (2, Direction.NORTH), (5, Direction.NORTH),\n                  (3, Direction.NORTH), (4, Direction.WEST)],\n                 [(5, Direction.SOUTH), (1, Direction.NORTH),\n                  (1, Direction.EAST), (1, Direction.WEST),\n                  (1, Direction.SOUTH), (2, Direction.NORTH)],\n                 [(3, Direction.WEST), (3, Direction.NORTH),\n                  (5, Direction.NORTH), (2, Direction.NORTH),\n                  (4, Direction.NORTH), (3, Direction.EAST)]]\n        f, nd = faces[self.to_dice_axis(d)][self.top-1]\n        self.top = f\n        self.heading = self.to_plain_axis(nd)\n\n    def value(self):\n        return self.values[self.top-1]\n\n\ndef run():\n    values = [int(v) for v in input().split()]\n    dice = Dice(*values)\n    for d in input():\n        if d == 'N':\n            dice.roll(Direction.NORTH)\n        if d == 'E':\n            dice.roll(Direction.EAST)\n        if d == 'S':\n            dice.roll(Direction.SOUTH)\n        if d == 'W':\n            dice.roll(Direction.WEST)\n\n    print(dice.value())\n\n\nif __name__ == '__main__':\n    run()\n\n", "def rn(a):\n\treturn [a[1], a[5], a[2], a[3], a[0], a[4]]\ndef rs(a):\n\treturn [a[4], a[0], a[2], a[3], a[5], a[1]]\ndef re(a):\n\treturn [a[3], a[1], a[0], a[5], a[4], a[2]]\ndef rw(a):\n\treturn [a[2], a[1], a[5], a[0], a[4], a[3]]\n\ndef main():\n\td = list(map(int, input().split()))\n\tq = input()\n\tfor c in q:\n\t\tif c == \"N\":\n\t\t\td = rn(d)\n\t\tif c == \"S\":\n\t\t\td = rs(d)\n\t\tif c == \"E\":\n\t\t\td = re(d)\n\t\tif c == \"W\":\n\t\t\td = rw(d)\n\tprint(d[0])\n\n\nmain()\n", "dice = list(map(int, input().split()))\norder = input()\nfor i in range(len(order)):\n  c = order[i]\n  if c == \"E\":\n    temp = dice[0]\n    dice[0] = dice[3]\n    dice[3] = dice[5]\n    dice[5] = dice[2]\n    dice[2] = temp\n  elif c == \"N\":\n    temp = dice[0]\n    dice[0] = dice[1]\n    dice[1] = dice[5]\n    dice[5] = dice[4]\n    dice[4] = temp\n  elif c == \"S\":\n    temp = dice[0]\n    dice[0] = dice[4]\n    dice[4] = dice[5]\n    dice[5] = dice[1]\n    dice[1] = temp\n  elif c == \"W\":\n    temp = dice[0]\n    dice[0] = dice[2]\n    dice[2] = dice[5]\n    dice[5] = dice[3]\n    dice[3] = temp\n  else:\n    pass\nprint(dice[0])\n", "class Dice:\n    def __init__(self,list):\n        self.list = []\n        for i in range(6):\n            self.list.append(list[i])\n\n    def rotate(self,dir):\n        if dir == \"N\":\n            self.list[0], self.list[1], self.list[5], self.list[4] = self.list[1], self.list[5], self.list[4], self.list[0]\n        elif dir == \"S\":\n            self.list[0], self.list[4], self.list[5], self.list[1] = self.list[4], self.list[5], self.list[1], self.list[0]\n        elif dir == \"W\":\n            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[2], self.list[0], self.list[3], self.list[5]\n        elif dir == \"E\":\n            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]\n        else:\n            pass\n\n    def show(self):\n        for i in self.list:\n            print(i)\n\n\nl = [ int(x) for x in input().split()]\ndice = Dice(l)\nstr = input()\nfor i in range(len(str)):\n    dice.rotate(str[i])\nprint(dice.list[0])\n\n", "def lotate(dic, dire):\n    if dire == 'N':\n        x,y,z,w = dic['up'], dic['back'], dic['bottom'], dic['front']\n        dic['back'], dic['bottom'], dic['front'], dic['up'] = x,y,z,w\n    elif dire == 'S':\n        x, y, z, w = dic['up'], dic['back'], dic['bottom'], dic['front']\n        dic['front'], dic['up'], dic['back'], dic['bottom'] = x, y, z, w\n    elif dire == 'W':\n        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']\n        dic['left'], dic['bottom'], dic['right'], dic['up'] = x, y, z, w\n    elif dire == 'E':\n        x, y, z, w = dic['up'], dic['left'], dic['bottom'], dic['right']\n        dic['right'], dic['up'], dic['left'], dic['bottom'] = x, y, z, w\n    return dic\n\n\na,b,c,d,e,f = map(int, input().split())\nd = {'up':a, 'front':b, 'right':c, 'left':d, 'back':e, 'bottom':f}\ns = input()\nfor i in s:\n    d = lotate(d, i)\nprint(d['up'])\n", "def E(dice):\n    dice[0],dice[1],dice[2],dice[3],dice[4],dice[5] = \\\n        dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]\n    return dice\ndef N(dice):\n    dice[0],dice[1],dice[2],dice[3],dice[4],dice[5] = \\\n        dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]\n    return dice\ndef S(dice):\n    dice[0],dice[1],dice[2],dice[3],dice[4],dice[5] = \\\n        dice[4],dice[0],dice[2],dice[3],dice[5],dice[1]\n    return dice\ndef W(dice):\n    dice[0],dice[1],dice[2],dice[3],dice[4],dice[5] = \\\n        dice[2],dice[1],dice[5],dice[0],dice[4],dice[3]\n    return dice\n\ndice = [int(item) for item in input().split()]\noperations = [item for item in input()]\nfor operation in operations:\n    if operation == \"E\":\n        dice = E(dice)\n    elif operation == \"N\":\n        dice = N(dice)\n    elif operation == \"S\":\n        dice = S(dice)\n    else:\n        dice = W(dice)\nprint(dice[0])\n", "# coding: utf-8\n\nclass dice():\n    __rot = {\n        'N' : [1, 5, 2, 3, 0, 4],\n        'E' : [3, 1, 0, 5, 4, 2],\n        'S' : [4, 0, 2, 3, 5, 1],\n        'W' : [2, 1, 5, 0, 4, 3],\n    }\n    \n    def __init__(self, input_d):\n        assert len(input_d) == 6\n        self.__d = [int(val) for val in input_d]\n    \n    def rotate(self, s):\n        a = self.__rot[s]\n        self.__d = [self.__d[i] for i in a]\n    \n    def get_num(self, i):\n        return self.__d[i]\n\n\ndice1 = dice(input().split())\nrot = input()\n\nfor s in rot:\n    dice1.rotate(s)\nprint(dice1.get_num(0))\n\n", "ns=list(map(int,input().split()))\nrs=input()\n\ndef rot(d, r):\n    if r == 'N':\n        return [d[1], d[5], d[2], d[3], d[0], d[4]]\n    if r == 'E':\n        return [d[3], d[1], d[0], d[5], d[4], d[2]]\n    if r == 'W':\n        return [d[2], d[1], d[5], d[0], d[4], d[3]]\n    if r == 'S':\n        return [d[4], d[0], d[2], d[3], d[5], d[1]]\n    return d\n\nfor r in rs:\n    ns = rot(ns, r)\n\nprint(ns[0])\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nPOSITIONS = [\"top\", \"south\", \"east\", \"west\", \"north\", \"bottom\"]\n\n\nclass Dice(object):\n\n    def __init__(self, initial_faces):\n        self.faces = {p: initial_faces[i] for i, p in enumerate(POSITIONS)}\n        self.store_previous_faces()\n\n    def store_previous_faces(self):\n        self.previous_faces = self.faces.copy()\n\n    def change_face(self, after, before):\n        self.faces[after] = self.previous_faces[before]\n\n    def change_faces(self, rotation):\n        self.change_face(rotation[0], rotation[1])\n        self.change_face(rotation[1], rotation[2])\n        self.change_face(rotation[2], rotation[3])\n        self.change_face(rotation[3], rotation[0])\n\n    def roll(self, direction):\n        self.store_previous_faces()\n        if direction == \"E\":\n            self.change_faces([\"top\", \"west\", \"bottom\", \"east\"])\n        elif direction == \"N\":\n            self.change_faces([\"top\", \"south\", \"bottom\", \"north\"])\n        elif direction == \"S\":\n            self.change_faces([\"top\", \"north\", \"bottom\", \"south\"])\n        elif direction == \"W\":\n            self.change_faces([\"top\", \"east\", \"bottom\", \"west\"])\n\n    def rolls(self, directions):\n        for d in directions:\n            self.roll(d)\n\n    def show_top(self):\n        return self.faces[\"top\"]\n\n\ndef main():\n    dice = Dice(input().split())\n    dice.rolls(input())\n    print(dice.show_top())\n\nif __name__ == \"__main__\":\n    main()\n", "class dice:\n    def __init__(self, pip):\n        self.pip = pip\n        \n    def move(self,dir):\n        if str(dir) == \"E\":\n            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[3],self.pip[0],self.pip[5],self.pip[2]\n        elif str(dir) == \"W\":\n            self.pip[0],self.pip[2],self.pip[3],self.pip[5] = self.pip[2],self.pip[5],self.pip[0],self.pip[3]\n        elif str(dir) == \"N\":\n            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[1],self.pip[5],self.pip[0],self.pip[4]\n        elif str(dir) == \"S\":\n            self.pip[0],self.pip[1],self.pip[4],self.pip[5] = self.pip[4],self.pip[0],self.pip[5],self.pip[1]\n\nd = dice(list(map(int,input().split())))\ninp = list(input())\n\nfor dir in inp:\n    d.move(dir)\n\nprint(d.pip[0])\n", "# 11_A\n# https://eromog.hatenablog.com/entry/2015/05/29/000529\n# https://tjkendev.github.io/procon-library/python/other/dice.html\n\n# Top, Bottom, Front, Back, Left, Right\nD={\"T\":1, \"Bo\":6, \"F\":2, \"Ba\":5, \"L\":4, \"R\":3}\n\n*A,=list(map(int,input().split()))\nS=input()\n\n# A=[1,2,4,8,16,32]\n# S=\"SE\"\n\nfor d in S:\n    if d==\"N\":\n        D[\"T\"],D[\"Bo\"],D[\"F\"],D[\"Ba\"] = D[\"F\"],D[\"Ba\"],D[\"Bo\"],D[\"T\"]\n    elif d==\"S\":\n        D[\"T\"],D[\"Bo\"],D[\"F\"],D[\"Ba\"] = D[\"Ba\"],D[\"F\"],D[\"T\"],D[\"Bo\"]\n    elif d==\"E\":\n        D[\"T\"],D[\"Bo\"],D[\"L\"],D[\"R\"] = D[\"L\"],D[\"R\"],D[\"Bo\"],D[\"T\"]\n    elif d==\"W\":\n        D[\"T\"],D[\"Bo\"],D[\"L\"],D[\"R\"] = D[\"R\"],D[\"L\"],D[\"T\"],D[\"Bo\"]\n    # print(d,\"-\",D[\"T\"],D)\nprint(A[D[\"T\"]-1])\n", "face = list(map(int, input().split()))\norder = input()\n\nfor j in range(len(order)) :\n  if(order[j] == \"S\") :\n    key = face[4]\n    face[4] = face[5]\n    face[5] = face[1]\n    face[1] = face[0]\n    face[0] = key\n  elif(order[j] == \"N\") :\n    key = face[1]\n    face[1] = face[5]\n    face[5] = face[4]\n    face[4] = face[0]\n    face[0] = key\n  elif(order[j] == \"E\") :\n    key = face[3]\n    face[3] = face[5]\n    face[5] = face[2]\n    face[2] = face[0]\n    face[0] = key\n  else :\n    key = face[2]\n    face[2] = face[5]\n    face[5] = face[3]\n    face[3] = face[0]\n    face[0] = key\n\nprint(face[0])\n", "class dice:\n    def __init__(self, first, second, third, fourth, fifth, sixth):\n        self.up = first\n        self.down = sixth\n        self.S = second\n        self.E = third\n        self.N = fifth\n        self.W = fourth\n    def move(self, direction):\n        if direction == \"S\":\n            temp = self.up\n            self.up = self.N\n            self.N = self.down\n            self.down = self.S\n            self.S = temp \n            return self\n        elif direction == \"E\":\n            temp = self.up\n            self.up = self.W\n            self.W = self.down\n            self.down = self.E\n            self.E = temp\n            return self\n        elif direction == \"N\":\n            temp = self.up\n            self.up = self.S\n            self.S = self.down\n            self.down = self.N\n            self.N = temp\n            return self\n        else:\n            temp = self.up\n            self.up = self.E\n            self.E = self.down\n            self.down = self.W\n            self.W = temp\n            return self\n\nnums = list(map(int,input().split()))\ndice1 = dice(nums[0], nums[1], nums[2], nums[3], nums[4], nums[5])\ncommand = input()\ncommandlen = len(command)\nfor i in range(commandlen):\n    dice1 = dice1.move(command[i])\nprint(str(dice1.up))\n", "class Dice:\n        def __init__(self, strLabel):\n                self.label = strLabel.split()\n                self.label[0] = int(self.label[0])\n                self.label[1] = int(self.label[1])\n                self.label[2] = int(self.label[2])\n                self.label[3] = int(self.label[3])\n                self.label[4] = int(self.label[4])\n                self.label[5] = int(self.label[5])\n        def roll(self, r):\n                if r == 'E':\n                        temp = self.label[3]\n                        self.label[3] = self.label[5]\n                        self.label[5] = self.label[2]\n                        self.label[2] = self.label[0]\n                        self.label[0] = temp\n                elif r == 'W':\n                        temp = self.label[0]\n                        self.label[0] = self.label[2]\n                        self.label[2] = self.label[5]\n                        self.label[5] = self.label[3]\n                        self.label[3] = temp\n                elif r == 'N':\n                        temp = self.label[0]\n                        self.label[0] = self.label[1]\n                        self.label[1] = self.label[5]\n                        self.label[5] = self.label[4]\n                        self.label[4] = temp\n                elif r == 'S':\n                        temp = self.label[4]\n                        self.label[4] = self.label[5]\n                        self.label[5] = self.label[1]\n                        self.label[1] = self.label[0]\n                        self.label[0] = temp\n\ndice = Dice(input())\nrollList = list(input())\n\nfor i in range(len(rollList)):\n        dice.roll(rollList[i])\n\nprint(dice.label[0])\n", "U, S, E, W, N, D = [int(x) for x in input().split()]\nlist = [\"\"]*6\ndef Val_To_List_transfer(list, U, S, E, W, N, D):\n    list[0] = U\n    list[1] = S\n    list[2] = E\n    list[3] = W\n    list[4] = N\n    list[5] = D\ndef South(list, U, S, E, W, N, D):\n    U = list[4]\n    S = list[0]\n    E = list[2]\n    W = list[3]\n    N = list[5]\n    D = list[1]\n    Val_To_List_transfer(list, U, S, E, W, N, D)\ndef North(list, U, S, E, W, N, D):\n    U = list[1]\n    S = list[5]\n    E = list[2]\n    W = list[3]\n    N = list[0]\n    D = list[4]\n    Val_To_List_transfer(list, U, S, E, W, N, D)\ndef West(list, U, S, E, W, N, D):\n    U = list[2]\n    S = list[1]\n    E = list[5]\n    W = list[0]\n    N = list[4]\n    D = list[3]\n    Val_To_List_transfer(list, U, S, E, W, N, D)\ndef East(list, U, S, E, W, N, D):\n    U = list[3]\n    S = list[1]\n    E = list[0]\n    W = list[5]\n    N = list[4]\n    D = list[2]\n    Val_To_List_transfer(list, U, S, E, W, N, D)\n\nVal_To_List_transfer(list, U, S, E, W, N, D)\nmove = []\nmove.extend(input())\nwhile len(move) != 0:\n    order = move.pop(0)\n    if order == \"S\":\n        South(list, U, S, E, W, N, D)\n    elif order == \"N\":\n        North(list, U, S, E, W, N, D)\n    elif order == \"W\":\n        West(list, U, S, E, W, N, D)\n    elif order == \"E\":\n        East(list, U, S, E, W, N, D)\n    #print(order, list)\nprint(list[0])\n\n", "class Dice:                                                                                \n    def __init__(self, ns):                                                                                \n        self.top = ns[0]                                                                                \n        self.bottom = ns[5]                                                                                \n        self.head = ns[4]                                                                                \n        self.tail = ns[1]                                                                                \n        self.right = ns[2]                                                                                \n        self.left = ns[3]                                                                                \n                                                                                \n    def go_north(self):                                                                                \n        tmp = self.top                                                                                \n        self.top = self.tail                                                                                \n        self.tail = self.bottom\n        self.bottom = self.head\n        self.head = tmp\n\n    def go_south(self):\n        tmp = self.top\n        self.top = self.head\n        self.head = self.bottom\n        self.bottom = self.tail\n        self.tail = tmp\n\n    def go_east(self):\n        tmp = self.top\n        self.top = self.left\n        self.left = self.bottom\n        self.bottom = self.right\n        self.right = tmp\n\n    def go_west(self):\n        tmp = self.top\n        self.top = self.right\n        self.right = self.bottom\n        self.bottom = self.left\n        self.left = tmp\n\nns = list(map(int, input().split()))\ndice = Dice(ns)\ndirs = input()\nfor dir_ in dirs:\n    if dir_ == 'N':\n        dice.go_north()\n    elif dir_ == 'S':\n        dice.go_south()\n    elif dir_ == 'E':\n        dice.go_east()\n    else:\n        dice.go_west()\nprint(dice.top)\n\n", "def swap(a, i, j):\n    x = a[i]\n    y = a[j]\n    a[i] = y\n    a[j] = x\n    return a\n    \ndef N(value):\n    value = swap(value,0,1)\n    value = swap(value,4,5)\n    value = swap(value,1,4)\n    return value\n\ndef E(value):\n    value = swap(value,0,3)\n    value = swap(value,2,5)\n    value = swap(value,2,3)\n    return value\n    \ndef S(value):\n    value = swap(value,0,1)\n    value = swap(value,4,5)\n    value = swap(value,0,5)\n    return value\n    \ndef W(value):\n    value = swap(value,0,2)\n    value = swap(value,3,5)\n    value = swap(value,2,3)\n    return value\n\nclass dice:\n    def __init__(self,a):\n        self.value = a\n    \n    value = []\n    \na = []\na = list(map(int, input().split()))\n\nd = dice(a)\n\ns = input()\nfor i in range(len(s)):\n    if s[i] == \"N\":\n        d.value = N(d.value)\n        \n    elif s[i] == \"E\":\n        d.value = E(d.value)\n        \n    elif s[i] == \"S\":\n        d.value = S(d.value)\n        \n    elif s[i] == \"W\":\n        d.value = W(d.value)\n        \nprint(d.value[0])\n\n\n\n\n    \n    \n", "dice = list(map(int, input().split()))\norder = input()\n\nfor ch in order:\n    if ch == \"N\":\n        dice = [dice[1], dice[5], dice[2], dice[3], dice[0], dice[4]]\n    elif ch == \"E\":\n        dice = [dice[3], dice[1], dice[0], dice[5], dice[4], dice[2]]\n    elif ch == \"W\":\n        dice = [dice[2], dice[1], dice[5], dice[0], dice[4], dice[3]]\n    else:\n        dice = [dice[4], dice[0], dice[2], dice[3], dice[5], dice[1]]\n\nprint(dice[0])\n", "sur={1:0,2:0,3:0,4:0,5:0,6:0}\ninputs=input().split()\nfor i in range(6):\n    sur[i+1]=int(inputs[i])\ndir_of_roll=input()\nfor i in range(len(dir_of_roll)):\n    copy_sur=sur.copy()\n    if dir_of_roll[i]=='N':\n        sur[1]=copy_sur[2]\n        sur[2]=copy_sur[6]\n        sur[6]=copy_sur[5]\n        sur[5]=copy_sur[1]\n    elif dir_of_roll[i]=='S':\n        sur[1]=copy_sur[5]\n        sur[5]=copy_sur[6]\n        sur[6]=copy_sur[2]\n        sur[2]=copy_sur[1]\n    elif dir_of_roll[i]=='W':\n        sur[1]=copy_sur[3]\n        sur[3]=copy_sur[6]\n        sur[6]=copy_sur[4]\n        sur[4]=copy_sur[1]\n    elif dir_of_roll[i]=='E':\n        sur[1]=copy_sur[4]\n        sur[4]=copy_sur[6]\n        sur[6]=copy_sur[3]\n        sur[3]=copy_sur[1]\n\nprint(sur[1])\n", "#ITP1_11_A\n\ndef west(d):\n\ttmp=d[4]\n\td[4]=d[1]\n\td[1]=d[3]\n\td[3]=d[6]\n\td[6]=tmp\n\ndef east(d):\n\ttmp=d[4]\n\td[4]=d[6]\n\td[6]=d[3]\n\td[3]=d[1]\n\td[1]=tmp\n\ndef north(d):\n\ttmp=d[1]\n\td[1]=d[2]\n\td[2]=d[6]\n\td[6]=d[5]\n\td[5]=tmp\n\ndef south(d):\n\ttmp=d[1]\n\td[1]=d[5]\n\td[5]=d[6]\n\td[6]=d[2]\n\td[2]=tmp\n\ndef kaiten(d, op):\n\tif   op == \"W\": west(d)\n\telif op == \"E\": east(d)\n\telif op == \"N\": north(d)\n\telif op == \"S\": south(d)\n\telse          : raise AssertionError()\n\ndef dump(d):\n\tprint(\" \".join(map(str,d)))\n\ndef inputDice():\n\treturn list(map(int,(\"-1 \"+input()).split()))\n\nd=inputDice()\nfor op in list(input()):\n\tkaiten(d,op)\nprint(d[1])\n", "dice_ = [int(i) for i in input().split()]\ncom = list(input())\ndice = {\n    't':dice_[0],\n    'd':dice_[1],\n    'r':dice_[2],\n    'l':dice_[3],\n    'u':dice_[4],\n    'b':dice_[5]\n}\nfor i in com:\n    # u\n    #ltr b\n    # d\n    if i == \"N\":\n        temp = dice['t']\n        dice['t'] = dice['d']\n        dice['d'] = dice['b']\n        dice['b'] = dice['u']\n        dice['u'] = temp\n    elif i == \"S\":\n        temp = dice['u']\n        dice['u'] = dice['b']\n        dice['b'] = dice['d']\n        dice['d'] = dice['t']\n        dice['t'] = temp\n    elif i == \"W\":\n        temp = dice['t']\n        dice['t'] = dice['r']\n        dice['r'] = dice['b']\n        dice['b'] = dice['l']\n        dice['l'] = temp\n    elif i == \"E\":\n        temp = dice['l']\n        dice['l'] = dice['b']\n        dice['b'] = dice['r']\n        dice['r'] = dice['t']\n        dice['t'] = temp\nprint(dice['t'])\n", "\nclass Dice:\n    def __init__(self, label):\n        self.d = label\n\n    def roll(self, direction):\n        if direction == \"N\":\n            self.d[0], self.d[1], self.d[5], self.d[4] = self.d[1], self.d[5], self.d[4], self.d[0]\n        elif direction == \"S\":\n            self.d[0], self.d[1], self.d[5], self.d[4] = self.d[4], self.d[0], self.d[1], self.d[5]\n        elif direction == \"E\":\n            self.d[0], self.d[2], self.d[5], self.d[3] = self.d[3], self.d[0], self.d[2], self.d[5]\n        else:\n            self.d[0], self.d[2], self.d[5], self.d[3] = self.d[2], self.d[5], self.d[3], self.d[0]\n\nlabel = [int(i) for i in input().split()]\ncmd = input()\n\ndice1 = Dice(label)\n\nfor i in cmd:\n    dice1.roll(i)\n\nprint(dice1.d[0])\n", "class Dice:\n  def __init__(self, nl):\n    self.n = nl[:]\n  def move(self, dir):\n    if dir==\"N\": self.n = [self.n[1], self.n[5], self.n[2], self.n[3], self.n[0], self.n[4]]\n    if dir==\"E\": self.n = [self.n[3], self.n[1], self.n[0], self.n[5], self.n[4], self.n[2]]\n    if dir==\"S\": self.n = [self.n[4], self.n[0], self.n[2], self.n[3], self.n[5], self.n[1]]\n    if dir==\"W\": self.n = [self.n[2], self.n[1], self.n[5], self.n[0], self.n[4], self.n[3]]\n\nnl = list(map(int, input().split()))\nd = Dice(nl)\nmovelist = input().rstrip()\nfor dir in movelist: d.move(dir)\nprint(d.n[0])\n\n", "class diceClass:\n\tdef __init__(self, valuelist):\n\t\tself.valuelist = valuelist\n\t\tself.t = valuelist[0]\n\t\tself.b = valuelist[5]\n\t\tself.n = valuelist[4]\n\t\tself.s = valuelist[1]\n\t\tself.e = valuelist[2]\n\t\tself.w = valuelist[3]\n\n\tdef throw(self, direction):\n\t\t# N,S,W,E\n\t\tif direction == 'N':\n\t\t\tself.t, self.s, self.b, self.n = self.s, self.b, self.n, self.t\n\t\telif direction == 'S':\n\t\t\tself.t, self.s, self.b, self.n = self.n, self.t, self.s, self.b\n\t\telif direction == 'W':\n\t\t\tself.t, self.e, self.b, self.w = self.e, self.b, self.w, self.t\n\t\telif direction == 'E':\n\t\t\tself.t, self.e, self.b, self.w = self.w, self.t, self.e, self.b\n\n\narrinput = list(map(int, input().split()))\ndirinput = input()\ndice = diceClass(arrinput)\nfor s in dirinput:\n\tdice.throw(s)\nprint(dice.t)\n\n", "class Dice:\n    def __init__(self, default = [1, 2, 3, 4, 5, 6]):\n        self.d = default\n\n    def e(self):\n        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[3], self.d[0], self.d[5], self.d[2]\n\n    def w(self):\n        self.d[0], self.d[2], self.d[3], self.d[5] = self.d[2], self.d[5], self.d[0], self.d[3]\n\n    def n(self):\n        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[1], self.d[5], self.d[0], self.d[4]\n\n    def s(self):\n        self.d[0], self.d[1], self.d[4], self.d[5] = self.d[4], self.d[0], self.d[5], self.d[1]\n\n    def top(self):\n        return self.d[0]\n\n\ndef main():\n    dice = Dice([int(i) for i in input().split()])\n    for o in input():\n        if o == 'E':\n            dice.e()\n        elif o == 'W':\n            dice.w()\n        elif o == 'S':\n            dice.s()\n        else:\n            dice.n()\n\n    print(dice.top())\n\n\nif __name__ == '__main__':\n    main()\n\n\n\n\n\n", "class Dice:\n\n    def __init__(self, num):\n        self.num = num\n    \n    def rot_s(self):\n        self.num = [self.num[i-1] for i in [5, 1, 3, 4, 6, 2]]\n\n    def rot_n(self):\n        self.num = [self.num[i-1] for i in [2, 6, 3, 4, 1, 5]]\n\n    def rot_e(self):\n        self.num = [self.num[i-1] for i in [4, 2, 1, 6, 5, 3]]\n\n    def rot_w(self):\n        self.num = [self.num[i-1] for i in [3, 2, 6, 1, 5, 4]]\n    \n    def rot_c(self):\n        self.num = [self.num[i-1] for i in [1, 3, 5, 2, 4, 6]]\n    \n    def rot_rc(self):\n        self.num = [self.num[i-1] for i in [1, 4, 2, 5, 3, 6]]\n\n\ndef main():\n    num = list(map(int, input().split()))\n    dice = Dice(num)\n    s = input()\n\n    for c in s:\n        if c == \"S\":\n            dice.rot_s()\n        elif c == \"N\":\n            dice.rot_n()\n        elif c == \"E\":\n            dice.rot_e()\n        elif c == \"W\":\n            dice.rot_w()\n    \n    print(dice.num[0])\n\nmain()\n", "# \u5165\u529b\ndice = list(map(int, input().split()))\ns = input()\n\n# \u30b7\u30df\u30e5\u30ec\u30fc\u30b7\u30e7\u30f3\nfor char in s:\n    if char == \"S\":\n        dice[0], dice[1], dice[4], dice[5] = dice[4], dice[0], dice[5], dice[1]\n    elif char == \"N\":\n        dice[0], dice[1], dice[4], dice[5] = dice[1], dice[5], dice[0], dice[4]\n    elif char == \"E\":\n        dice[0], dice[2], dice[3], dice[5] = dice[3], dice[0], dice[5], dice[2]\n    elif char == \"W\":\n        dice[0], dice[2], dice[3], dice[5] = dice[2], dice[5], dice[0], dice[3]\n\n# \u51fa\u529b\nprint(dice[0])\n", "# coding: utf-8\nclass Dice_cls:\n    def __init__(self, t, s, e, w, n, b):\n        self.t = t\n        self.s = s\n        self.e = e\n        self.w = w\n        self.n = n\n        self.b = b\n    def move(self, i):\n        if i == \"E\":\n            self.t, self.e, self.w, self.b = self.w, self.t, self.b, self.e\n        elif i == \"W\":\n            self.t, self.e, self.w, self.b = self.e, self.b, self.t, self.w\n        elif i == \"S\":\n            self.t, self.s, self.n, self.b = self.n, self.t, self.b, self.s\n        elif i == \"N\":\n            self.t, self.s, self.n, self.b = self.s, self.b, self.t, self.n\n\nt, s, e, w, n, b = map(int, input().split())\ndice = Dice_cls(t, s, e, w, n, b)\ns = input()\nfor i in s:\n    dice.move(i)\nprint(dice.t)\n", "c=[int(i) for i in input().split()]\nS=input()\nd=[(0,0,1),(-1,0,0),(0,1,0),(0,-1,0),(1,0,0),(0,0,-1)]\ndef north(r):\n    res=[]\n    for p in r:\n        res.append((p[2],p[1],-p[0]))\n    return res\ndef south(r):\n    res=[]\n    for p in r:\n        res.append((-p[2],p[1],p[0]))\n    return res\ndef east(r):\n    res=[]\n    for p in r:\n        res.append((p[0],p[2],-p[1]))\n    return res\ndef west(r):\n    res=[]\n    for p in r:\n        res.append((p[0],-p[2],p[1]))\n    return res\nD=[i for i in d]\nfor i in S:\n    if i==\"N\":\n        D=north(D)\n    elif i==\"S\":\n        D=south(D)\n    elif i==\"W\":\n        D=west(D)\n    else:\n        D=east(D)\nfor k in range(6):\n    if D[k]==(0,0,1):\n        print(c[k])\n", "def north(d):\n    return [d[1], d[5], d[2], d[3], d[0], d[4]]\n\ndef east(d):\n    return [d[3], d[1], d[0], d[5], d[4], d[2]]\n\ndef south(d):\n    return [d[4], d[0], d[2], d[3], d[5], d[1]]\n\ndef west(d):\n    return [d[2], d[1], d[5], d[0], d[4], d[3]]\n\nnumbers = list(map(int, input().split()))\ndirections = list(input())\n\nfor d in directions:\n    if d == \"N\":\n        numbers = north(numbers)\n    elif d == \"E\":\n        numbers = east(numbers)\n    elif d == \"S\":\n        numbers = south(numbers)\n    elif d == \"W\":\n        numbers = west(numbers)\n\nprint(numbers[0])\n"]

source: aizu

question:
Dice I

  Write a program to simulate rolling a dice, which can be constructed by the following net.

![image](1.png)
![image](2.png)

  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

image_tags:
3D Geometry
3D Geometry

data_split: test


solutions: ["import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, n // 2 - p // 2))\n", "n = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, (n - p) // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min((n - p) // 2, p // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nanswer = min(p // 2, (n - p) // 2)\nprint(answer)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, (n - p) // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, n // 2 - p // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\npage_in_book = p // 2\ntotal_pages = n // 2\nfrom_front = page_in_book\nfrom_back = total_pages - page_in_book\nprint(min(from_front, from_back))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nl = p // 2\nr = ((n | 1) - p) // 2\nprint(min(l, r))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nfront = p // 2\nn = n // 2 * 2\nback = max(0, (n - p + 1) // 2)\nprint(min(front, back))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nfront = p // 2\nif n % 2 == 0:\n\tback = (n - p + 1) // 2\nelse:\n\tback = (n - p) // 2\nprint(min(front, back))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, (n - p) // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nq = n - p\nnp = p // 2\nnq = None\nif n % 2 == 0:\n\tnq = (q + 1) // 2\nelse:\n\tnq = q // 2\nprint(min([np, nq]))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nleft = p // 2\nright = 0\nif n % 2 == 0:\n\timport math\n\tright = math.ceil((n - p + 0.0) / 2)\nelse:\n\tright = (n - p) // 2\nprint(min(left, right))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\ncount = int((p - 1) / 2)\nif p % 2 == 0:\n\tcount += 1\ncountEnd = int((n - p) / 2)\nif n % 2 == 0 and p % 2 != 0:\n\tcountEnd += 1\nprint(min(count, countEnd))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nfront = p // 2\nback = n // 2 - front\nif back >= front:\n\tprint(front)\nelse:\n\tprint(back)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\np1 = p\nif p % 2 > 0:\n\tp1 = p - 1\nn1 = n\nif n % 2 > 0:\n\tn1 = n - 1\nprint(min(p1 // 2, (n1 - p1) // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif n % 2 != 0:\n\tn = n - 1\nif p % 2 != 0:\n\tp = p - 1\nprint(int(min(p / 2, (n - p) / 2)))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif p == n and n % 2 == 0 or p == 1 or (p == n - 1 and n % 2 == 1):\n\tprint('0')\nelse:\n\tprint(min((n - p) // 2, p // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\n\ndef turn_from_front(p):\n\tcounter = 0\n\tif p % 2 == 0:\n\t\tp += 1\n\tfor i in range(1, p, 2):\n\t\tcounter += 1\n\treturn counter\n\ndef turn_from_back(n, p):\n\tcounter = 0\n\tif n % 2 == 0:\n\t\tif p % 2 == 0:\n\t\t\tfor i in range(n, p, -2):\n\t\t\t\tcounter += 1\n\t\telse:\n\t\t\tfor i in range(n + 1, p, -2):\n\t\t\t\tcounter += 1\n\telif p % 2 == 0:\n\t\tp += 1\n\t\tfor i in range(n, p, -2):\n\t\t\tcounter += 1\n\telse:\n\t\tfor i in range(n, p, -2):\n\t\t\tcounter += 1\n\treturn counter\narr = []\narr.append(turn_from_front(p))\narr.append(turn_from_back(n, p))\narr.sort()\nprint(arr[0])\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif n >= 1 and n <= 10 ** 5 and (p <= n) and (p >= 1):\n\tif p % 2 != 0:\n\t\tt1 = (p - 1) / 2\n\t\tif n % 2 == 0:\n\t\t\tt2 = (n - p + 1) / 2\n\t\telse:\n\t\t\tt2 = (n - p) / 2\n\telse:\n\t\tt1 = p / 2\n\t\tif n % 2 == 0:\n\t\t\tt2 = (n - p) / 2\n\t\telse:\n\t\t\tt2 = (n - p - 1) / 2\n\tif t1 > t2:\n\t\tprint(int(t2))\n\telif t2 >= t1:\n\t\tprint(int(t1))\n", "import sys\n\ndef solve(n, p):\n\tfrom_start = p // 2\n\tfrom_end = (n - p) // 2\n\treturn min(from_start, from_end)\n\ndef main(inp=sys.stdin):\n\tn = int(inp.readline().strip())\n\tp = int(inp.readline().strip())\n\tprint(solve(n, p))\nmain()\n", "import sys\nimport math\nn = float(input().strip())\np = float(input().strip())\ndistFromStart = 0\ndistFromEnd = 0\ndistFromStart = int(math.ceil((p - 1.0) / 2))\nif n % 2 == 0:\n\tdistFromEnd = int(math.ceil((n - p) / 2))\nelse:\n\tdistFromEnd = int(math.floor((n - p) / 2))\nprint(min(distFromStart, distFromEnd))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif p <= int(n / 2):\n\tprint(int(p / 2))\nelse:\n\tprint(int(n / 2) - int(p / 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif p == 1 or n == p:\n\tprint('0')\nelse:\n\tif p > int(n / 2):\n\t\tc = int((n - p) / 2)\n\telse:\n\t\tc = int(p / 2)\n\tprint(c)\n", "import sys\nimport unittest\nimport math\n\nclass DrawingBook:\n\n\tdef __init__(self, n, p):\n\t\tself.n = self._get_next_odd(n)\n\t\tself.p = self._get_next_odd(p)\n\n\tdef _get_next_odd(self, x):\n\t\tif x % 2:\n\t\t\treturn x\n\t\telse:\n\t\t\treturn x + 1\n\n\tdef calculate(self):\n\t\tfrom_left = self.p / 2\n\t\tfrom_right = (self.n - self.p) / 2\n\t\tif from_left < from_right:\n\t\t\treturn math.floor(from_left)\n\t\telse:\n\t\t\treturn math.floor(from_right)\n\nclass TestDrawingBook(unittest.TestCase):\n\n\tdef test1(self):\n\t\tdb = DrawingBook(6, 2)\n\t\tself.assertEquals(db.calculate(), 1)\n\n\tdef test2(self):\n\t\tdb = DrawingBook(5, 4)\n\t\tself.assertEquals(db.calculate(), 0)\nn = int(input().strip())\np = int(input().strip())\ndb = DrawingBook(n, p)\nprint(db.calculate())\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif p <= int(n / 2):\n\tprint(int(p / 2))\nelse:\n\tprint(int((n - p) / 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, n // 2 - p // 2))\n", "import sys\nimport math\nn = int(input().strip())\np = int(input().strip())\nprint(math.floor((n - p) / 2) if math.floor(p / 2) > math.floor((n - p) / 2) else math.floor(p / 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif n % 2 == 0:\n\tn += 1\nif p % 2 == 0:\n\tp += 1\nd1 = (n - p) / 2\nd2 = (p - 1) / 2\nif d1 < d2:\n\tprint(int(d1))\nelse:\n\tprint(int(d2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nk = int(p / 2)\nl = int((n - p) / 2)\nif k < l:\n\tprint(k)\nelse:\n\tprint(l)\n", "N = int(input().rstrip())\nP = int(input().rstrip())\nfrom_front = P // 2\nfrom_back = (N - P) // 2\nprint(min(from_back, from_front))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\na = p // 2\nb = (n - p) // 2\nif b < a:\n\tprint(b)\nelse:\n\tprint(a)\n", "import math\nn = int(input().strip())\np = int(input().strip())\nif p <= n / 2:\n\tprint(p // 2)\nelif n % 2 == 0:\n\tprint(math.ceil((n - p) / 2))\nelse:\n\tprint(math.floor((n - p) / 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif p <= n / 2:\n\tprint(p // 2)\nelse:\n\tif n % 2 == 0:\n\t\tn += 1\n\tprint((n - p) // 2)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif p / n > 0.5:\n\tturns = int(n / 2) - int(p / 2)\nelse:\n\tturns = int(p / 2)\nprint(turns)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\n\ndef do(n, p):\n\tif p == 1 or p == n:\n\t\treturn 0\n\tif n % 2 == 1:\n\t\tn -= 1\n\tfrom1 = p // 2\n\tfromN = (n + 1 - p) // 2\n\treturn min(from1, fromN)\nprint(do(n, p))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif n % 2 == 0:\n\tn = n + 1\nmid = (n + 1) / 2\nif mid % 2 == 0:\n\tif p < mid:\n\t\ts = p / 2\n\telse:\n\t\ts = n / 2 - p / 2\nelse:\n\tmid = mid - 1\n\tif p <= mid:\n\t\ts = p / 2\n\telse:\n\t\ts = n / 2 - p / 2\nprint(int(s))\n", "import sys\nimport math\nn = int(input().strip())\np = int(input().strip())\nmiddle = n / 2\nif p <= middle:\n\tprint(math.floor(p / 2))\nelse:\n\tprint(math.floor((n - p) / 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nfrom_start = p // 2\nfrom_end = (n // 2 * 2 + 1 - p) // 2\nprint(min(from_start, from_end))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, n // 2 - p // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\ntotal_number = 0\npage_number = 0\nif n % 2 == 1:\n\ttotal_number = n - 1\nelse:\n\ttotal_number = n\nif p % 2 == 1:\n\tpage_number = p - 1\nelse:\n\tpage_number = p\nfrom_front = page_number / 2\nfrom_back = (total_number - page_number) / 2\nprint(int(min(from_front, from_back)))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nforward = p // 2\nn = n + 1 if n % 2 == 0 else n\nbackward = (n - p) // 2\nprint(forward if forward < backward else backward)\n", "import sys\n\ndef solve(n, p):\n\txl = p // 2\n\txr = (n + (1 - n % 2) - p) // 2\n\treturn min(xl, xr)\nn = int(input().strip())\np = int(input().strip())\nprint(solve(n, p))\n", "import math\nn = int(input())\np = int(input())\nif n & 1:\n\tn -= 1\ndif1 = p - 1\ndif2 = n - p\nans1 = math.ceil(dif1 / 2)\nans2 = math.ceil(dif2 / 2)\nif ans1 >= ans2:\n\tprint(ans2)\nelse:\n\tprint(ans1)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nleft = 0\nright = 1\nnpages = 0\nnstart = 0\nwhile left != n and right != n:\n\tif left == p or right == p:\n\t\tnstart = npages\n\tleft = right + 1\n\tright = left + 1\n\tnpages = npages + 1\nnend = 0\nwhile left != p and right != p:\n\tright = left - 1\n\tleft = right - 1\n\tnend = nend + 1\nprint(min(nstart, nend))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nval = None\nif p == n:\n\tprint(0)\nelse:\n\tis_even = True if n % 2 == 0 else False\n\tarr = []\n\tarr.append(1)\n\tfor i in range(2, n, 2):\n\t\tarr.append((i, i + 1))\n\tif is_even:\n\t\tarr.append(n)\n\tc1 = 0\n\tc2 = 0\n\tfor i in range(len(arr)):\n\t\tif type(arr[i]) is tuple:\n\t\t\tif p not in arr[i]:\n\t\t\t\tc1 += 1\n\t\t\telse:\n\t\t\t\tval = c1\n\t\t\t\tprint(val)\n\t\t\t\tbreak\n\t\telif arr[i] == p:\n\t\t\tval = c1\n\t\t\tprint(val)\n\t\t\tbreak\n\t\telse:\n\t\t\tc1 += 1\n\t\tif type(arr[len(arr) - i - 1]) is tuple:\n\t\t\tif p not in arr[len(arr) - i - 1]:\n\t\t\t\tc2 += 1\n\t\t\telse:\n\t\t\t\tval = c2\n\t\t\t\tprint(val)\n\t\t\t\tbreak\n\t\telif arr[len(arr) - i - 1] == p:\n\t\t\tval = c2\n\t\t\tprint(val)\n\t\t\tbreak\n\t\telse:\n\t\t\tc2 += 1\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nk = min(int((n - p) / 2), int(p / 2))\nprint(k)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nfrom_first = p // 2\nfrom_last = (n - p) // 2\nprint(min(from_first, from_last))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif p <= n / 2:\n\tref = 1\nelse:\n\tref = -1\ni = 0\nif ref == -1:\n\tif p == n:\n\t\tprint(0)\n\t\texit()\n\tif n % 2 == 0:\n\t\tif p % 2 == 0:\n\t\t\tprint(int((n - p) / 2))\n\t\t\texit()\n\t\tif p % 2 != 0:\n\t\t\tprint(int((n - (p - 1)) / 2))\n\t\t\texit()\n\telse:\n\t\tprint(int((n - p) / 2))\n\t\texit()\nif ref == 1:\n\tif p == 1:\n\t\tprint(0)\n\t\texit()\n\telif p % 2 == 0:\n\t\tprint(int(p / 2))\n\t\texit()\n\telse:\n\t\tprint(int((p - 1) / 2))\n\t\texit()\n", "import sys\nimport math\nn = int(input().strip())\np = int(input().strip())\noutput = min(math.floor(p / 2), math.floor((n - p) / 2))\nprint(output)\n", "import sys\nimport math\nn = int(input().strip())\np = int(input().strip())\nif p == 1:\n\tprint(0)\nelif p <= n // 2:\n\tprint(int(math.ceil((p - 1) / 2)))\nelif n % 2 == 1:\n\tprint((n - p) // 2)\nelif n == p:\n\tprint(0)\nelse:\n\tprint((n - 1 - p) // 2 + 1)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\npages = []\nx = min(p // 2, abs(p // 2 - n // 2))\nprint(x)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nn = list((int(x) for x in range(n)))\nif p == 0:\n\tprint('0')\nelif p == n[-1]:\n\tprint('0')\nelse:\n\tmid = len(n) / 2\n\tif p % 2 == 0:\n\t\tif p == len(n) - 1:\n\t\t\tprint('0')\n\t\telif p <= mid:\n\t\t\tprint(int(p / 2))\n\t\telif p > mid:\n\t\t\tprint(int((len(n) - p) / 2))\n\telif p % 2 == 1:\n\t\tif p <= mid:\n\t\t\tprint(int((p - 1) / 2))\n\t\telif p > mid:\n\t\t\tprint(int((len(n) - (p - 1)) / 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nn = list((int(x) for x in range(n)))\nif p == 0:\n\tprint('0')\nelif p == n[-1]:\n\tprint('0')\nelse:\n\tmid = len(n) / 2\n\tif p % 2 == 0:\n\t\tif p == len(n) - 1:\n\t\t\tprint('0')\n\t\telif p <= mid:\n\t\t\tprint(int(p / 2))\n\t\telif p > mid:\n\t\t\tprint(int((len(n) - p) / 2))\n\telif p % 2 == 1:\n\t\tif p <= mid:\n\t\t\tprint(int((p - 1) / 2))\n\t\telif p > mid:\n\t\t\tprint(int((len(n) - (p - 1)) / 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nr = 0\nif p <= n / 2:\n\tif p % 2 == 0:\n\t\tr = p / 2\n\telse:\n\t\tr = (p - 1) / 2\nelif n % 2 == 0:\n\tif (n - p + 1) % 2 == 0:\n\t\tr = (n - p + 1) / 2\n\telse:\n\t\tr = (n - p) / 2\nelif (n - p) % 2 == 0:\n\tr = (n - p) / 2\nelse:\n\tr = (n - p - 1) / 2\nr = int(r)\nprint(r)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, (n - p + abs(n % 2 - 1)) // 2))\n", "n = int(input())\np = int(input())\nm = 1 + n // 2\nk = p // 2\nprint(min(k, m - k - 1))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nnormalize = lambda x: x if x % 2 == 0 else x - 1\nnormalized_n = normalize(n)\nnormalized_p = normalize(p)\nprint(min((normalized_p // 2, (normalized_n - normalized_p) // 2)))\n", "import sys\nfrom math import *\nn = int(input().strip())\np = int(input().strip())\nif n == p:\n\tprint(0)\nelse:\n\tl = 2\n\tc_l = 1\n\tc_l += (p - l) // 2\n\tr = n\n\tc_r = 0\n\tif n % 2 == 0:\n\t\tr = n - 1\n\t\tc_r += (r - p) // 2\n\t\tc_r += 1\n\telse:\n\t\tc_r += (r - p) // 2\n\tprint(min(c_l, c_r))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif n % 2 == 0:\n\tprint(min(int(p / 2), int((n - p + 1) / 2)))\nelse:\n\tprint(min(int(p / 2), int((n - p) / 2)))\n", "import sys\n\ndef fromFront(tot, dest):\n\treturn dest // 2\n\ndef fromBack(tot, dest):\n\tif tot % 2 == 0:\n\t\treturn (tot - dest + 1) // 2\n\telse:\n\t\treturn (tot - dest) // 2\nn = int(input().strip())\np = int(input().strip())\nfront = fromFront(n, p)\nback = fromBack(n, p)\nif front <= back:\n\tprint(front)\nelse:\n\tprint(back)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, (n - p) // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif p == 1 or p == n or p == n - 1:\n\tprint(0)\nelse:\n\tx = 2\n\tpageList = []\n\twhile x < n - 1:\n\t\tpageList.append([x, x + 1])\n\t\tx += 2\n\tforward = 1\n\tfor i in pageList:\n\t\tif p in i:\n\t\t\tbreak\n\t\tforward += 1\n\tif forward <= len(pageList) // 2:\n\t\tprint(forward)\n\telse:\n\t\tprint(len(pageList) - forward + 1)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif n % 2 == 1:\n\tn -= 1\nans = (p - 1 if p % 2 == 1 else p) // 2\nans = min(ans, (n - (p - 1 if p % 2 == 1 else p)) // 2)\nprint(ans)\n", "n = int(input())\np = int(input())\nif n % 2 == 0:\n\tn = n + 1\nif p % 2 != 0:\n\tp = p - 1\nr = (n - p - 1) // 2\nl = (p - 2) // 2 + 1\nif r < l:\n\tprint(r)\nelse:\n\tprint(l)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\ni = 0\nwhile i <= n // 2:\n\tif 2 * i + 1 >= p or 2 * (n // 2 - i) <= p:\n\t\tbreak\n\telse:\n\t\ti += 1\nprint(i)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, n // 2 - p // 2))\n", "import sys\n\ndef getNumOfPagesFrom(start, page):\n\tcount = 0\n\tif start == 1:\n\t\twhile page - start > 0:\n\t\t\tstart += 2\n\t\t\tcount += 1\n\telse:\n\t\twhile start - page > 1:\n\t\t\tstart -= 2\n\t\t\tcount += 1\n\treturn count\nn = int(input().strip())\np = int(input().strip())\nif p < float((n + 1) / 2):\n\tprint(getNumOfPagesFrom(1, p))\nelse:\n\tprint(getNumOfPagesFrom(n, p))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif n >= 1 and n <= 10 ** 5:\n\tif p >= 1 and p <= n:\n\t\tif p <= n / 2:\n\t\t\tprint(p // 2)\n\t\telse:\n\t\t\tprint((n - p) // 2)\n", "(n, m) = (int(input()), int(input()))\nprint(min(m // 2, n // 2 - m // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, (n - p) // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, n // 2 - p // 2))\n", "import sys\nimport math\nPRINT = False\nn = int(input().strip())\np = int(input().strip())\nif p == 1:\n\tprint(0)\nelse:\n\tn_middle = n - 1\n\tp_middle = p - 2\n\tturns_middle = p_middle // 2\n\tdouble_pages_middle = math.ceil(n_middle / 2)\n\treverse_turns_middle = double_pages_middle - 1 - turns_middle\n\tturns = turns_middle + 1\n\tif PRINT:\n\t\tprint('N middle: ' + str(n_middle))\n\t\tprint('P middle: ' + str(p_middle))\n\t\tprint('Double_pages_middle: ' + str(double_pages_middle))\n\t\tprint('Turns middle: ' + str(turns_middle))\n\t\tprint('Turns: ' + str(turns))\n\t\tprint('Reverse: ' + str(reverse_turns_middle))\n\tprint(min(turns, reverse_turns_middle))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, (n - p) // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nfront = int(p / 2)\nback = n - p + 1 if n % 2 == 0 else n - p\nback = int(back / 2)\nprint(min(front, back))\n", "import sys\nimport math\nn = int(input().strip())\np = int(input().strip())\nif n / 2 > p:\n\tt = math.ceil((p - 1) / 2)\nelse:\n\tt = math.floor((n - p) / 2)\nprint(t)\n", "import math\nimport sys\nn = int(input().strip())\np = int(input().strip())\nturns = int(n / 2)\nif int(turns / 2) >= int(p / 2):\n\tprint(int(p / 2))\nelse:\n\tprint(int((n - p) / 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nl = n // 2\nlp = p // 2\nprint(min(lp, l - lp))\n", "import sys\nimport math\nn = int(input().strip())\np = int(input().strip())\nprint(min((n - p) // 2, (p - 1) // 2 + ((p - 1) % 2 > 0)))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\na = p // 2\nb = n // 2\nprint('{}'.format(min(a, b - a)))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\n\ndef min_pages_num(n, p):\n\tif p % 2:\n\t\tk1 = (p - 1) / 2\n\t\tif n % 2:\n\t\t\tk2 = (n - p) / 2\n\t\telse:\n\t\t\tk2 = (n - p + 1) / 2\n\telse:\n\t\tk1 = p / 2\n\t\tif n % 2:\n\t\t\tk2 = (n - p - 1) / 2\n\t\telse:\n\t\t\tk2 = (n - p) / 2\n\treturn int(min(k1, k2))\nprint(min_pages_num(n, p))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif p > n // 2:\n\tc = (n - p) // 2\nelse:\n\tc = p // 2\nprint(c)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif n % 2 == 0:\n\tn = n + 1\nt1 = int(p / 2)\nt2 = int((n - p) / 2)\nif t1 < t2:\n\tprint(t1)\nelse:\n\tprint(t2)\n", "import sys\nimport math\nn = int(input().strip())\np = int(input().strip())\nturn_front = math.ceil((p - 1) / 2)\nturn_back = math.ceil((n - p) / 2) if n % 2 == 0 else math.floor((n - p) / 2)\nprint(min(turn_front, turn_back))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif n % 2 != 0:\n\tn = n - 1\nif p % 2 != 0:\n\tp = p - 1\nif p - 1 <= n - p:\n\tprint((p - 1) // 2 + 1)\nelse:\n\tprint((n - p) // 2)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nn2 = int(n / 2)\np2 = int(p / 2)\nif p2 > int(n2 / 2):\n\tprint(int(n2 - p2))\nelse:\n\tprint(p2)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nftob = int(p / 2)\nn += 1 - n % 2\nbtof = int((n - p) / 2)\nprint(min(ftob, btof))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\np = int(p / 2)\nn = int(n / 2)\nprint(int(min(p, n - p)))\n", "n = int(input().strip())\np = int(input().strip())\nif n % 2 == 0:\n\tif p % 2 == 0:\n\t\tprint(min(p // 2, (n - p) // 2))\n\telse:\n\t\tprint(min((p - 1) // 2, (n - p + 1) // 2))\nelif p % 2 == 0:\n\tprint(min(p // 2, (n - p) // 2))\nelse:\n\tprint(min((p - 1) // 2, (n - p) // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(int(min(int(p / 2), int((n - p) / 2))))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nturns = 0\nmax_page = 1\nif n % 2 == 1:\n\tmin_page = n - 1\nelse:\n\tmin_page = n\nwhile max_page < p and min_page > p:\n\tmax_page += 2\n\tmin_page -= 2\n\tturns += 1\nprint(turns)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(int(p / 2), int((n - p) / 2)))\n", "import sys\nimport math\nn = int(input().strip())\np = int(input().strip())\nif n % 2 == 0:\n\tturn_from_back = math.ceil((n - p) / 2)\nelse:\n\tturn_from_back = math.floor((n - p) / 2)\nturn_from_front = math.ceil((p - 1) / 2)\nif turn_from_front < turn_from_back:\n\tprint(turn_from_front)\nelse:\n\tprint(turn_from_back)\n", "import sys\nimport math\nn = int(input().strip())\np = int(input().strip())\nif n - p >= p:\n\tif p == 1:\n\t\tturns = 0\n\telse:\n\t\tturns = math.ceil((p - 1) / 2)\nelif p == n:\n\tturns = 0\nelif (n - p) % 2 == 0:\n\tturns = math.ceil((n - p) / 2)\nelse:\n\tturns = math.ceil((n - p - 1) / 2)\nprint(turns)\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nfront = p // 2\nback = ((n | 1) - p) // 2\nprint(min(front, back))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif p == 1 or (p == n and p % 2 == 0):\n\tprint(0)\nelse:\n\tprint(min(p // 2, n // 2 - p // 2))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nprint(min(p // 2, n // 2 - p // 2))\n", "import sys\nnop = int(input().strip())\npd = int(input().strip())\npage_fwd = 0\nif pd % 2 == 0:\n\tpage_fwd = pd / 2\nelse:\n\tpage_fwd = (pd - 1) / 2\npage_bwd = 0\nif nop % 2 != 0:\n\tnop = nop - 1\nif pd % 2 != 0:\n\tpd -= 1\npage_bwd = (nop - pd) / 2\nprint(int(min(page_fwd, page_bwd)))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif p in [1, n]:\n\tprint(0)\nelse:\n\tfront_flips = p // 2\n\tp = n - p\n\tif n % 2:\n\t\tback_flips = p // 2\n\telse:\n\t\tback_flips = (p + 1) // 2\n\tprint(min(front_flips, back_flips))\n", "import sys\nn = int(input().strip())\np = int(input().strip())\nif p > int(n / 2):\n\tprint(int((n - p) / 2))\nelse:\n\tprint(int(p / 2))\n"]

difficulty: EASY

source: hacker rank

question:
A teacher asks the class to open their books to a page number. A student can either start turning pages from the front of the book or from the back of the book. They always turn pages one at a time.  When they open the book, page $1$ is always on the right side:

![image](1.png)
When they flip page $1$, they see pages $2$ and $3$.  Each page except the last page will always be printed on both sides.  The last page may only be printed on the front, given the length of the book.  If the book is $n$ pages long, and a student wants to turn to page $\boldsymbol{p}$, what is the minimum number of pages to turn?  They can start at the beginning or the end of the book.

Given $n$ and $\boldsymbol{p}$, find and print the minimum number of pages that must be turned in order to arrive at page $\boldsymbol{p}$.

Example

$n=5$

$p=3$

![image](2.png)
Using the diagram above, if the student wants to get to page $3$, they open the book to page $1$, flip $1$ page and they are on the correct page.  If they open the book to the last page, page $5$, they turn $1$ page and are at the correct page.  Return $1$.

Function Description

Complete the pageCount function in the editor below.

pageCount has the following parameter(s):

int n: the number of pages in the book
int p: the page number to turn to

Returns

int: the minimum number of pages to turn

Input Format

The first line contains an integer $n$, the number of pages in the book.

The second line contains an integer, $\boldsymbol{p}$, the page to turn to.

Constraints

$1\leq n\leq10^5$
$1\leq p\leq n$

Sample Input 0
6
2

Sample Output 0
1

Explanation 0

If the student starts turning from page $1$, they only need to turn $1$ page:

![image](3.png)
If a student starts turning from page $\boldsymbol{6}$, they need to turn $2$ pages:

![image](4.png)

![image](6.png)
Return the minimum value, $1$.

Sample Input 1
5
4

Sample Output 1
0

Explanation 1

![image](6.png)
If the student starts turning from page $1$, they need to turn $2$ pages:

If they start turning from page $5$, they do not need to turn any pages:

Return the minimum value, $0$.

image_tags: Others Others Others Others Others Others

data_split: test