using System.Collections.Generic;
namespace _02_Command_Interpreter
public class CommandInterpreter
public static void Main()
var nums = Console.ReadLine().Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
string line = Console.ReadLine();
var tokens = line.Split().ToArray();
string command = tokens[0];
if (command == "reverse")
ReverseNums(nums, tokens);
else if (command == "sort")
else if (command == "rollLeft")
else if (command == "rollRight")
line = Console.ReadLine();
Console.WriteLine($"[{string.Join(", ", nums)}]");
static void RollRight(List<string> nums, string[] tokens)
long count = long.Parse(tokens[1]);
var isCountInvalid = count < 0;
Console.WriteLine($"Invalid input parameters.");
for (int i = 0; i < count % nums.Count; i++)
var lastElement = nums.Last();
nums.RemoveAt(nums.Count - 1);
nums.Insert(0, lastElement);
static void RollLeft(List<string> nums, string[] tokens)
long count = long.Parse(tokens[1]);
var isCountInvalid = count < 0;
Console.WriteLine($"Invalid input parameters.");
for (int i = 0; i < count % nums.Count; i++)
var firstElement = nums[0];
static void SortNums(List<string> nums, string[] tokens)
int startIndex = int.Parse(tokens[2]);
int count = int.Parse(tokens.Last());
var isIndexInvalid = startIndex < 0 || startIndex > nums.Count - 1;
var isCountInvalid = count < 0 || count + startIndex > nums.Count;
if (isIndexInvalid || isCountInvalid)
Console.WriteLine($"Invalid input parameters.");
var sortedNums = nums.Skip(startIndex).Take(count).ToList();
nums.RemoveRange(startIndex, count);
nums.InsertRange(startIndex, sortedNums);
static void ReverseNums(List<string> nums, string[] tokens)
int startIndex = int.Parse(tokens[2]);
int count = int.Parse(tokens.Last());
var isIndexInvalid = startIndex < 0 || startIndex > nums.Count - 1;
var isCountInvalid = count < 0 || count + startIndex > nums.Count;
if (isIndexInvalid || isCountInvalid)
Console.WriteLine($"Invalid input parameters.");
var reversedNums = nums.Skip(startIndex).Take(count).Reverse().ToList();
nums.RemoveRange(startIndex, count);
nums.InsertRange(startIndex, reversedNums);