using System.Linq; using System.Collections.Generic; using System; public class Hello { static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var c = new HashSet(); var ok = new HashSet(); var w = new List(); for (int i = 0; i < n; i++) { string[] line = Console.ReadLine().Trim().Split(' '); var a = line[0]; var b = line[1]; w.Add(b); c.Add(a); if (c.Add(b)) { ok.Add(b); c.Remove(b); } } var w2 = w.Distinct().ToList(); for (int i = 0; i < w2.Count(); i++) if (ok.Contains(w2[i])) Console.WriteLine(w2[i]); } }