static void Main(string[] args) { var word = Console.ReadLine(); var text = Console.ReadLine(); var result = 0l; var wordLen = word.Length; var searcher = new StringSearcher(text.ToCharArray()); for (var i = 1; i <= wordLen; i++) { var left = word.Substring(0, i).ToCharArray(); var right = word.Substring(i, wordLen - i).ToCharArray(); var leftCounter = 0; if (left.Length > 1) { var index = searcher.Search(left); while (index < text.Length && index > -1) { leftCounter++; index++; index = searcher.Search(left, index); } } else { var index = text.IndexOf(left[0]); while (index > -1) { leftCounter++; index = text.IndexOf(left[0], index + 1); } } var rightCounter = 0; if (right.Length > 1) { var index = searcher.Search(right); while (index < text.Length && index > -1) { rightCounter++; index++; index = searcher.Search(right, index); } } else if (right.Length == 1) { var index = text.IndexOf(right[0]); while (index > -1) { rightCounter++; index = text.IndexOf(right[0], index + 1); } } if (i == wordLen) { rightCounter = 1; } result += leftCounter * rightCounter; } Console.WriteLine(result); }