TXR
The 'hist-sort' function call does most of the work here, creating an association list of (id . freq) pairs in decreasing order of frequency:
@(next "01-input")
@(collect)
@ ids
@(end)
@;;
@(bind freqs @(hist-sort [map int-str ids]))
@;;
@(output)
1: @[prod (take 3 freqs) car]
2: @[prod (last freqs 3) car]
@(end)



TXR
I didn’t solve part 2 programmatically. I simply used Emacs’
'count-matches'command to count occurrences of the 5 characters (not 6, as one of them never occurs!), and calculated the answer manually.