package main import ( "fmt" "sort" ) type student struct { id int name string bad bool } type sts []student func (s sts) Len() int { return len(s) } func (s sts) Less(i, j int) bool { return s[i].id < s[j].id } func (s sts) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func main() { var N int fmt.Scan(&N) students := make(map[string]student, 0) for i := 0; i < N; i++ { sta := new(student) stb := new(student) fmt.Scan(&sta.name, &stb.name) if v, ok := students[sta.name]; !ok { sta.id = i sta.bad = true students[sta.name] = *sta } else { v.bad = true students[sta.name] = v } if _, ok := students[stb.name]; !ok { stb.id = i students[stb.name] = *stb } } a := make([]student, 0) for _, v := range students { if !v.bad { a = append(a, v) } } sort.Sort(sts(a)) for i := range a { fmt.Println(a[i].name) } }