// dictionary has to be a ciSet static Chain constructWordFromCISet(S word, Set dictionary) { if (contains(dictionary, word)) ret Chain(word); for (int i = 1; i < l(word); i++) { S prefix = takeFirst(i, word); if (contains(dictionary, prefix)) { Chain chain = constructWordFromCISet(substring(word, i), dictionary); if (chain != null) ret Chain(prefix, chain); } null; }