compute common substrings