12304 - Huffman Compression   

Description

Given

  • 1 word
  • N lines of text

Task

  • Calculate character distribution in the text, do a stable sort
  • Build a Huffman tree
  • Encode the word given at the first line based on the Huffman tree

Input

  • The first line of input contains a single positive integer n (number of lines of the text) and a word, separated by a comma, followed by newline
  • The next n lines contains zero or more characters(with whitespace), they all end in newlines. This will be the text.

 

 

 

 

Output

Sample Input  Download

Sample Output  Download

Tags




Discuss