using System;
using System.Linq;

namespace _02.Command_Interpreter
{
    public class StartUp
    {
        public static void Main()
        {
            var collection = Console.ReadLine().Split(new[] {' ', '\t'}, StringSplitOptions.RemoveEmptyEntries)
                .ToList();
            string input = Console.ReadLine();
            while (!input.Equals("end"))
            {
                string[] commands = input.Split().ToArray();
                if (commands[0] == "reverse")
                {
                    try
                    {
                        collection.Reverse(int.Parse(commands[2]), int.Parse(commands[4]));
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Invalid input parameters.");
                    }
                }
                else if (commands[0] == "sort")
                {
                    try
                    {
                        collection.Sort(int.Parse(commands[2]), int.Parse(commands[4]), null);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Invalid input parameters.");
                    }
                }
                else if (commands[0] == "rollleft")
                {
                    try
                    {
                        for (int i = 0; i < int.Parse(commands[1]); i++)
                        {
                            string first = collection[0];
                            collection.RemoveAt(0);
                            collection.Add(first);
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Invalid input parameters.");
                    }
                }
                else if (commands[0] == "rollright")
                {
                    try
                    {
                        for (int i = 0; i < int.Parse(commands[1]); i++)
                        {
                            string last = collection.Last();
                            collection.RemoveAt(collection.Count-1);
                            collection.Insert(0,last);
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Invalid input parameters.");
                    }
                }
                input = Console.ReadLine();
            }
            Console.WriteLine("["+string.Join(", ",collection)+"]");
        }
    }
}