#include <stdio.h>          // putchar(), fgets()
#define NUL '\0'

typedef struct decode_node
{
	char c;
	int zero;
	int one;
} decode_n;

const char *encode[91] = 
{
	['A'] = "00000", ['B'] = "00001", ['C'] = "00010", ['D'] = "00011", ['E'] = "00100", ['F'] = "00101", ['G'] = "00110", ['H'] = "00111", ['I'] = "01000",
	['J'] = "01001", ['K'] = "01010", ['L'] = "01011", ['M'] = "01100", ['N'] = "01101", ['O'] = "01110", ['P'] = "01111", ['Q'] = "10000", ['R'] = "10001",
	['S'] = "10010", ['T'] = "10011", ['U'] = "10100", ['V'] = "10101", ['W'] = "10110", ['X'] = "10111", ['Y'] = "11000",
	['Z'] = "11001", [' '] = "11010", ['.'] = "11011", [','] = "11100", ['-'] = "11101", ['\''] = "11110", ['?'] = "11111"
};

decode_n decode[] =
{ /*0 x          1            2            3            4             5              6              7              8              9                      */
	{NUL, 1, 2}, {NUL, 3, 4}, {NUL, 5, 6}, {NUL, 7, 8}, {NUL, 9, 10}, {NUL, 11, 12}, {NUL, 13, 14}, {NUL, 15, 16}, {NUL, 17, 18}, {NUL, 19, 20},
  /*10 x           11             12             13             14             15             16             17             18             19            */  
	{NUL, 21, 22}, {NUL, 23, 24}, {' ', -1, -1}, {'E', -1, -1}, {'P', -1, -1}, {NUL, 25, 26}, {'D', -1, -1}, {NUL, 27, 28}, {NUL, 29, 30}, {NUL, 31, 32}, 
  /*20 x           21             22             23             24             25             26             27             28             29            */  
	{'C', -1, -1}, {'K', -1, -1}, {'I', -1, -1}, {'R', -1, -1}, {NUL, 33, 34}, {NUL, 35, 36}, {NUL, 37, 38}, {'L', -1, -1}, {'O', -1, -1}, {'S', -1, -1}, 
  /*30 x           31             32             33             34             35              36             37             38             39           */  
	{'T', -1, -1}, {NUL, 39, 40}, {'F', -1, -1}, {NUL, 41, 42}, {NUL, 43, 44}, {'\'', -1, -1}, {'?', -1, -1}, {'W', -1, -1}, {',', -1, -1}, {'H', -1, -1}, 
  /*40 x           41             42             43             44             45             46             47             48             49            */  
	{'.', -1, -1}, {NUL, 45, 46}, {'A', -1, -1}, {NUL, 47, 48}, {NUL, 49, 50}, {NUL, 51, 52}, {NUL, 53, 54}, {NUL, 55, 56}, {NUL, 57, 58}, {NUL, 59, 60}, 
  /*50 x           51             52             53             54             55             56             57             58             59            */  
	{NUL, 61, 62}, {'Z', -1, -1}, {'-', -1, -1}, {'X', -1, -1}, {'Y', -1, -1}, {'J', -1, -1}, {'M', -1, -1}, {'B', -1, -1}, {'G', -1, -1}, {'U', -1, -1}, 
  /*60 x           61             62                                                                                                                     */  
	{'V', -1, -1}, {'N', -1, -1}, {'Q', -1, -1}
};

int
main(int argc, char **argv)
{
	char line[200 + 2];
	char bina[200 * 5 + 1];
	const char *s, *t;
	char *u;
	int i;

	while (fgets(line, sizeof(line), stdin) != NULL)
	{
		u = bina;
		for (s = line; *s != '\n' && *s != NUL; ++s)
		{
			for (t = encode[(int)*s]; *t != NUL; ++t, ++u)
				*u = *t;
		}

		*u = NUL;
		s = bina;
		while (*s != NUL)
		{
			int p = 0;
			while (decode[p].zero != -1)
			{
				switch (*s++)
				{
				case '0':
					p = decode[p].zero;
					break;

				case '1':
					p = decode[p].one;
					break;
				}
			}

			putchar(decode[p].c);
			t = s;
			for (i = 0; *t != NUL && i <= 6; ++i, ++t)
			{
				if (*t == '1')
					break;
			}

			if (*t == NUL && i <= 5)
				break;
		}

		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 524