        tmp = flag | (x << (8 * (ofs - 1)))
        l.append(N - pol(tmp))
    s, r = min(l), max(l)
    if s <= N - r:
        flag |= (l.index(s) << (8 * (ofs - 1)))
        result += chr(l.index(s))