namespace day_1 { internal class Program { static void Main(string[] args) { string[] flines = File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data.txt")); List la = new List(), lb = new List(); Dictionary similarity = new Dictionary(); int diff = 0; int similar = 0; for (int i = 0; i < flines.Length; i++) { string a, b; a = flines[i].Split(" ")[0]; b = flines[i].Split(" ")[1]; la.Add(Convert.ToInt32(a)); lb.Add(Convert.ToInt32(b)); } la.Sort(); lb.Sort(); for (int i = 0; i < la.Count; i++) { int d = la[i] - lb[i]; if (d < 0) d = -d; diff += d; } for (int x = 0; x < la.Count; x++) { int v = la[x]; int r = 0; for (int y = 0; y < lb.Count && lb[y] <= v; y++) { if (v == lb[y]) r++; } similarity[v] = r; } foreach (KeyValuePair sim in similarity) { similar += sim.Key * sim.Value; } Console.WriteLine($"distance: {diff}\nsimilarity: {similar}"); } } }