package main import . "fmt" import . "os" import bf "bufio" import . "sort" func main() { rd:=bf.NewReader(Stdin) var n,m int Fscan(rd,&n,&m) t:=map[string]int{} s:=[]string{} for i:=n+m;i>0;i--{ var a string var b int Fscan(rd,&a,&b) t[a]=b s=append(s,a) } Strings(s) for _,a:= range s{ if b,ok:=t[a];ok { Println(a,b) delete(t,a) } } }