def _get_best_joint_indexes(max_span_length, logits, n_best_size):
  """Gets the n-best start and end indices from flat logits."""
  indices = sorted(range(len(logits)), key=logits.__getitem__, reverse=True)
  indices = indices[:n_best_size]
  starts = [x // max_span_length for x in indices]
  offsets = [x % max_span_length for x in indices]
  starts, ends = zip(*[(s, s + offs) for s, offs in zip(starts, offsets)])
  return starts, ends