private String generate(String word, int mask) {
        StringBuilder sb = new StringBuilder();
        int cnt = 0;
        for (int i = 0; i < word.length(); ++i) {
            if ((mask & (1 << i)) != 0) {
                if (cnt > 0) {
                    sb.append(cnt);
                    cnt = 0;
                }
                sb.append(word.charAt(i));
            } else {
                ++cnt;
            }
        }
        if (cnt > 0) sb.append(cnt);
        return sb.toString();
    }