class Solution(object):
def rearrangeBarcodes(self, barcodes):
"""
:type barcodes: List[int]
:rtype: List[int]
"""
cnt = collections.Counter(barcodes)
barcodes.sort(key=lambda x: (-cnt[x], x))
n = len(barcodes)
ans = [0] * n
ans[::2] = barcodes[:(n + 1) // 2]
ans[1::2] = barcodes[(n + 1) // 2:]
return ans