using System; using System.Collections.Generic; using System.IO; namespace D1._2 { class Program { static void Main(string[] args) { if (args.Length < 1) return; if (File.Exists(args[0]) == false) return; var frequencies = new Dictionary() { { 0, true } }; int frequency = 0; bool foundTwice = false; do { var file = File.OpenText(args[0]); foundTwice = ApplySequence(frequencies, ref frequency, ref foundTwice, file); file.Close(); } while (foundTwice == false); if (foundTwice) Console.WriteLine($"Result : {frequency}"); } private static bool ApplySequence(Dictionary frequencies, ref int frequency, ref bool foundTwice, StreamReader file) { do { var line = file.ReadLine(); if (line == null) break; frequency += int.Parse(line); if (frequencies.ContainsKey(frequency)) foundTwice = true; else frequencies.Add(frequency, true); } while (foundTwice == false); return foundTwice; } } }