#!/usr/bin/env python
import re
from sys import argv, stdin
from collections import Counter

hist = Counter()

if '-w' in argv or '--word' in argv:
    # Word histogram
    cleaned = re.sub(r'[^\w]', ' ', stdin.read())
    hist = Counter(cleaned.lower().split())
else:
    # Letter histogram
    cleaned = re.sub(r'[^\w]', '', stdin.read())
    hist = Counter(cleaned)

for item, count in hist.most_common():
    print(f"{count}\t{item}")
