#!/usr/bin/python3
#
#
# Usage: du -hcs * | du_sort
#        du_sort du_hcs.txt
#
# Sort "du -hcs" results taking the following suffixes into account:
#
#      b K M G  T  P  E  Z  Y = 
# 10 * 0 3 6 9 12 15 18 21 24   
#

import fileinput
import re

SUFFIX = "bKMGTPEZY"

#
# Sort Key
#
def num_bytes(line):
	s = re.sub('\s.*', '', line)		# Strip whitespace and fname
	num = re.sub('[bKMGTPEZY]', '', s)
	suffix = re.sub('[\d\.]+', '', s)

	nbytes = float(num) * int(10**(3 * SUFFIX.find(suffix)))

	return nbytes

#
# Main Script
#
lines=[] # give lines variable a type of list

for line in fileinput.input():
	lines.append(line.rstrip())		# remove trailing whitespace

lines.sort(key=num_bytes)

for line in lines:
	print(line)

