code for reordering, takes as input the n-best tra