#!/usr/bin/env python2.7
import sys
import copy
import string

def needs_expand(bits):
    for i in bits:
        if i not in "01":
            return True
    return False

def bit_to_int(bits):
    out = ""
    for i in bits: out += i
    return int(out, 2)

r_table = (
    ("111", "A"),
    ("000", "B"),
    ("001", "C"),
    ("010", "D"),
    ("011", "E"),
    ("100", "H"),
    ("101", "L"))

d_table = (
    ("00", "BC"),
    ("01", "DE"),
    ("10", "HL"),
    ("11", "SP"))

q_table = (
    ("00", "BC"),
    ("01", "DE"),
    ("10", "HL"),
    ("11", "AF"))

s_table = (
    ("00", "BC"),