// dictionary has to be a ciSet static Chain constructWordFromCISet(S word, Set dictionary) { if (contains(dictionary, word)) ret Chain(word); for ping (int i = l(word)-1; i > 0; 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; }