using System; using System.IO; using System.Text.RegularExpressions; namespace D07._2 { class Program { static void Main(string[] args) { if (args.Length < 1) throw new ArgumentException(); if (File.Exists(args[0]) == false) throw new FileNotFoundException(); var r = new Regex(@"(\w)(?!\1)(\w)\1(?:(?!\w*\]).*\2\1\2(?=\w*\])|(?=\w*\]).*\2\1\2(?!\w*\]))", RegexOptions.Multiline) .Matches(File.ReadAllText(args[0])); Console.WriteLine($"The answer is : {r.Count}"); } } }