private void addPair(String word, int l, int r, Map<String, List<Integer>> leftIndices, 
            Map<String, List<Integer>> rightIndices, int idx) {
            StringBuilder builder = new StringBuilder();
            while (l >= 0 && r < word.length()) {
                if (word.charAt(l) != word.charAt(r))
                    break;
                l--;
                r++;
            }
            if (l < 0 && r == word.length()) {
                add(leftIndices, "", idx);
                add(rightIndices, "", idx);
            } else if (l < 0) {
                while (r < word.length())
                    builder.insert(0, word.charAt(r++));
                add(leftIndices, builder.toString(), idx);
            } else if (r == word.length()) {
                while (l >= 0)
                    builder.append(word.charAt(l--));
                add(rightIndices, builder.toString(), idx);
            }
        }