Adrian likes rhymes. He decides that two words rhyme if and only if the length of their longest common suffix equals the length of the longer word, or falls exactly 1 short of it. In other words, words A and B rhyme if and only if
LCS(A,B)≥max(∣A∣,∣B∣)−1
Here LCS(A,B) is the length of the longest common suffix of A and B, and ∣A∣ is the length of A.
One day, while reading a collection of short stories, Adrian decided to lay out the longest possible sequence of words in which every two consecutive words rhyme. The words come from the given list, and no word may be used twice.
Adrian got tired of the task and went back to reading. Given N words, write a program that computes the maximum length of such a sequence.