#!/usr/bin/perl -w
# /System/Volumes/Data/opt/local/bin/perl5.30 -w

# More shell, less egg
# 
#  tr -cs A-Za-z '\n' |
#  tr A-Z a-z |
#  sort |
#  uniq -c |
#  sort -rn |
#  sed ${1}q

use strict;
my %words;
my $out=$ENV{COUNT};

while ( <> ) {
  for my $key ( split /[^a-z]/, lc($_) ) {
    $words{$key}++ unless $key eq ''
  }
}

for my $key ( sort { $words{$b} <=> $words{$a} } keys %words ) {
  if ( $out-- > 0 ) {
    printf "%4d %s\n", $words{$key}, $key
  } else {
    exit
  }
}