title: String manipulation: calculate the "similarity of a string with its suffixes"
body: <p>For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings "abc" and "abd" is 2, while the similarity of strings "aaa" and "aaab" is 3.</p>
  
  <p>The problem is to give an algorithm to calculate the sum of similarities of a string S with each of it's suffixes. For example, let the string be : <code>ababaa</code>. Then, the suffixes of the string are <code>ababaa</code>, <code>babaa</code>, <code>abaa</code>, <code>baa</code>, <code>aa</code> and <code>a</code>. The similarities of each of these strings with the string <code>ababaa</code> are <code>6,0,3,0,1,1</code>, respectively. Thus the answer is <code>6 + 0 + 3 + 0 + 1 + 1 = 11</code>.</p>