using System; using System.Collections.Generic; using System.Linq; namespace apps { class Program { static void Main() { //list operations List integers = Get().Split(' ').Select(int.Parse).ToList(); for (int i = 0; i < integers.Count - 1; i++) { string[] command = Get().Split(' '); if (command[0] == "End") { break; } else { if (command[0] == "Add") { integers.Add(Convert.ToInt32(command[1])); continue; } if (command[0] == "Insert") { int index = Convert.ToInt32(command[2]); if (index > integers.Count ||index<0 ) { Console.WriteLine("Invalid index"); continue; } int number = Convert.ToInt32(command[1]); integers.Insert(index, number); continue; } if (command[0] == "Remove") { int index = Convert.ToInt32(command[1]); if (index > integers.Count || index<0) { Console.WriteLine("Invalid index"); continue; } integers.RemoveAt(index); continue; } if (command[1] == "left") { int times = Convert.ToInt32(command[2]); for (int x =1; x<=times; x++) { int firstElement = integers[0]; integers.Add(firstElement); integers.RemoveAt(0); } continue; } if (command[1] == "right") { int times = Convert.ToInt32(command[2]); for (int x =1; x <= times; x++) { int lastlement = integers[integers.Count-1]; integers.Insert(0, lastlement); integers.RemoveAt(integers.Count - 1); } continue; } } } Console.WriteLine(string.Join(" ", integers)); static string Get() { return Console.ReadLine(); } } } }