Substring and Subsequence

CodeForces - 1989B