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

Dice I

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

As shown in the figures, each face is identified by a different label from 1 to 6.

Write a program which reads integers assigned to each face identified by the label and a sequence of commands to roll the dice, and prints the integer on the top face. At the initial state, the dice is located as shown in the above figures.

Input

In the first line, six integers assigned to faces are given in ascending order of their corresponding labels.

In the second line, a string which represents a sequence of commands, is given. The command is one of 'E', 'N', 'S' and 'W' representing four directions shown in the above figures.

Output

Print the integer which appears on the top face after the simulation.

Constraints

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

$0 \leq $ the length of the command $\leq 100$

Sample Input 1

1 2 4 8 16 32
SE

Sample Output 1

8

You are given a dice where 1, 2, 4, 8, 16 are 32 are assigned to a face labeled by 1, 2, ..., 6 respectively. After you roll the dice to the direction S and then to the direction E, you can see 8 on the top face.

Sample Input 2

1 2 4 8 16 32
EESWN

Sample Output 2

32

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var numList = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var directList = Console.ReadLine();

            var dice = new Dice(numList);

            foreach (char direction in directList)
            {
                switch (direction)
                {
                    case 'N':
                        dice.Roll(Direction.North);
                        break;

                    case 'E':
                        dice.Roll(Direction.East);
                        break;

                    case 'S':
                        dice.Roll(Direction.South);
                        break;

                    case 'W':
                        dice.Roll(Direction.West);
                        break;
                }
            }

            Console.WriteLine(dice.Top);
        }
    }

    /// <summary>
    /// 方角を示します。
    /// </summary>
    public enum Direction
    {
        North,
        East,
        South,
        West
    }

    class Dice
    {
        private int[,] diceList;

        /// <summary>
        /// 縦方向の末尾のインデックスを取得します。
        /// </summary>
        private int LastIndexY => diceList.GetLength(0) - 1;

        /// <summary>
        /// 横方向の末尾のインデックスを取得します。
        /// </summary>
        private int LastIndexX => diceList.GetLength(1) - 1;

        /// <summary>
        /// サイコロの上面の要素を取得します。
        /// </summary>
        public int Top => diceList[0, 0];

        /// <summary>
        /// サイコロの右面の要素を取得します。
        /// </summary>
        public int Right => diceList[0, 1];

        public Dice(int[] face)
        {
            diceList = new int[4, 4];

            diceList[0, 0] = face[0];
            diceList[1, 0] = face[1];
            diceList[2, 0] = face[5]; //
            diceList[3, 0] = face[4];

            diceList[0, 1] = face[2];
            diceList[0, 2] = face[5]; //
            diceList[0, 3] = face[3];
        }

        /// <summary>
        /// 方角を指定してサイコロを転がします、
        /// </summary>
        public void Roll(Direction direction)
        {
            switch (direction)
            {
                case Direction.North:
                    RollNorth();
                    break;

                case Direction.East:
                    RollEast();
                    break;

                case Direction.South:
                    RollSouth();
                    break;

                case Direction.West:
                    RollWest();
                    break;
            }
        }

        #region Private Method

        private void UpdateXtoY() => diceList[2, 0] = diceList[0, 2];
        private void UpdateYtoX() => diceList[0, 2] = diceList[2, 0];

        /// <summary>
        /// 北方向へ転がします。
        /// </summary>
        private void RollNorth()
        {
            var tmp = diceList[0, 0];

            for (int i = 0; i < LastIndexY; i++)
            {
                diceList[i, 0] = diceList[i + 1, 0];
            }

            diceList[LastIndexY, 0] = tmp;
            UpdateYtoX();
        }

        /// <summary>
        /// 南方向へ転がします。
        /// </summary>
        private void RollSouth()
        {
            var tmp = diceList[LastIndexY, 0];

            for (int i = LastIndexY; i > 0; i--)
            {
                diceList[i, 0] = diceList[i - 1, 0];
            }

            diceList[0, 0] = tmp;
            UpdateYtoX();
        }

        /// <summary>
        /// 東方向へ転がします。
        /// </summary>
        private void RollEast()
        {
            var tmp = diceList[0, LastIndexX];

            for (int i = LastIndexX; i > 0; i--)
            {
                diceList[0, i] = diceList[0, i - 1];
            }

            diceList[0, 0] = tmp;
            UpdateXtoY();
        }

        /// <summary>
        /// 西方向へ転がします。
        /// </summary>
        private void RollWest()
        {
            var tmp = diceList[0, 0];

            for (int i = 0; i < LastIndexX; i++)
            {
                diceList[0, i] = diceList[0, i + 1];
            }

            diceList[0, LastIndexX] = tmp;
            UpdateXtoY();
        }

        #endregion
    }
}