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.Text.RegularExpressions;

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            var oneLine = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var dice = new Dice(oneLine);
            var rotateList = Console.ReadLine().Select(x => Enum.Parse(typeof(Direction), x.ToString())).ToList();
            foreach (Direction direction in rotateList)
            {
                dice.Rotate(direction);
            }

            Console.WriteLine(dice.Top);
        }
    }

    public class Dice
    {
        public int Top { get; private set; }
        public int Right { get; private set; }
        public int Front { get; private set; }
        public int Left { get; private set; }
        public int Bottom { get; private set; }
        public int Back { get; private set; }


        public Dice(IList<int> numbers)
        {
            //this.Number = numbers.ToArray();
            this.Top = numbers[0];
            this.Back = numbers[1];
            this.Right = numbers[2];
            this.Left = numbers[3];
            this.Front = numbers[4];
            this.Bottom = numbers[5];
        }


        public void Rotate(Direction direction)
        {
            var tmp = this.Top;
            switch (direction)
            {
                case Direction.N:
                    this.Top = this.Back;
                    this.Back = this.Bottom;
                    this.Bottom = this.Front;
                    this.Front = tmp;
                    break;
                case Direction.E:
                    this.Top = this.Left;
                    this.Left = this.Bottom;
                    this.Bottom = this.Right;
                    this.Right = tmp;
                    break;
                case Direction.W:
                    this.Top = this.Right;
                    this.Right = this.Bottom;
                    this.Bottom = this.Left;
                    this.Left = tmp;
                    break;
                case Direction.S:
                    this.Top = this.Front;
                    this.Front = this.Bottom;
                    this.Bottom = this.Back;
                    this.Back = tmp;
                    break;
                default:
                    break;
            }
        }
    }

    /// <summary>
    /// ダイスを転がす方向
    /// </summary>
    public enum Direction
    {
        N,
        E,
        W,
        S
    }

}