spoj DISUBSTR: counting number of distinct substrings of a string