using System; using System.Collections.Generic; class Program { static string InputPattern = "Input4"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("ABC"); //5 } else if (InputPattern == "Input2") { WillReturn.Add("DDDDDD"); //0 } else if (InputPattern == "Input3") { WillReturn.Add("XYZYX"); //29 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); string S = InputList[0]; var stk = new Stack(); stk.Push(S); var VisitedSet = new HashSet() { S }; while (stk.Count > 0) { string Popped = stk.Pop(); for (int I = 0; I <= S.Length - 2; I++) { char[] NewCharArr = Popped.ToCharArray(); NewCharArr[I] = Popped[I + 1]; NewCharArr[I + 1] = Popped[I]; string NewStr = new string(NewCharArr); if (VisitedSet.Add(NewStr)) stk.Push(NewStr); } } Console.WriteLine(VisitedSet.Count - 1); } }