def Group(array):
  """Groups duplicate elements, e.g. [2, 1, 2, 2, 3] => [1, 2, 3], [1, 3, 1]."""
  array.sort()
  uniq, cnts = [], []
  for i in array:
    if len(uniq) == 0 or i != uniq[-1]:
      uniq.append(i)
      cnts.append(1)
    else:
      cnts[-1] += 1
  return uniq, cnts