#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {
  map<char, string> enc, dec;
  enc['A'] = "00000";
  enc['B'] = "00001";
  enc['C'] = "00010";
  enc['D'] = "00011";
  enc['E'] = "00100";
  enc['F'] = "00101";
  enc['G'] = "00110";
  enc['H'] = "00111";
  enc['I'] = "01000";
  enc['J'] = "01001";
  enc['K'] = "01010";
  enc['L'] = "01011";
  enc['M'] = "01100";
  enc['N'] = "01101";
  enc['O'] = "01110";
  enc['P'] = "01111";
  enc['Q'] = "10000";
  enc['R'] = "10001";
  enc['S'] = "10010";
  enc['T'] = "10011";
  enc['U'] = "10100";
  enc['V'] = "10101";
  enc['W'] = "10110";
  enc['X'] = "10111";
  enc['Y'] = "11000";
  enc['Z'] = "11001";
  enc[' '] = "11010";
  enc['.'] = "11011";
  enc[','] = "11100";
  enc['-'] = "11101";
  enc['\''] = "11110";
  enc['?'] = "11111";
  dec['A'] = "100101";
  dec['B'] = "10011010";
  dec['C'] = "0101";
  dec['D'] = "0001";
  dec['E'] = "110";
  dec['F'] = "01001";
  dec['G'] = "10011011";
  dec['H'] = "010000";
  dec['I'] = "0111";
  dec['J'] = "10011000";
  dec['K'] = "0110";
  dec['L'] = "00100";
  dec['M'] = "10011001";
  dec['N'] = "10011110";
  dec['O'] = "00101";
  dec['P'] = "111";
  dec['Q'] = "10011111";
  dec['R'] = "1000";
  dec['S'] = "00110";
  dec['T'] = "00111";
  dec['U'] = "10011100";
  dec['V'] = "10011101";
  dec['W'] = "000010";
  dec['X'] = "10010010";
  dec['Y'] = "10010011";
  dec['Z'] = "10010000";
  dec[' '] = "101";
  dec['.'] = "010001";
  dec[','] = "000011";
  dec['-'] = "10010001";
  dec['\''] = "000000";
  dec['?'] = "000001";
  for (;;) {
    string s, b, r;
    getline(cin, s);
    if (!s.length())
      break;
    for (int i = 0; i < s.length(); i++)
      b += enc[s[i]];
    for (int i = 0; i < b.length();) {
      bool f(false);
      for (map<char, string>::iterator it = dec.begin(); it != dec.end(); ++it)
        if (b.substr(i, it->second.length()) == it->second) {
          f = true;
          i += it->second.length();
          r.push_back(it->first);
          break;
        }
      if (!f) break;
    }
    cout << r << endl;
  }
  return 0;
}