Олимпиадный тренинг

Задача 38220. good verses


Задача

Темы: Строки
Have you ever thought about how to distinguish good poetry from mediocre?

No? But the editor of a literary magazine does this every day, receiving tons of correspondence from young authors who want to become famous poets. Fortunately, recently most of the poems are sent by e-mail, so the editor had the idea to automate the process. He is firmly convinced that poetry is the better, the more accurate the rhyme in them. He considers two lines to be rhymed if they have the same last few letters. And the more letters match, the better the lines are rhymed. For example, the strings “stick” and “rope” only pairs of the last letters “ka” match, and the lines “olympiad” and “heaven and hell” four letters match (we skip spaces). Therefore, the second rhyme is better. The editor believes that in a quatrain (four lines) the first line should rhyme with the third, and the second – from the fourth. For each of these two pairs of strings, it counts the number of matching last characters and chooses the largest of these two numbers. He calls the resulting number the quality coefficient of the poem – the higher it is, the more likely the poem is to be published. Help the editor – write a program that determines the quality of a poem. And who knows, maybe thanks to your efforts, the world will get acquainted with brilliant poems (see the first example).

Input
The input is 4 non-empty lines, each of which consists of no more than 100 lowercase Latin letters (the poem has already been pre-processed: all spaces and punctuation marks have been removed from it, and capital letters have been made lowercase).

Imprint
Print one number – poem quality index.
 
# Input Output
1 yapomnyuchudnoemgnovenje
peredomnojyavilasty

kakgenijchistoykrasoty
4
2 eto
vovse

stihi
0
3 etootlichnyestihi
etootlichnyestihi
etootlichnyestihi
etootlichnyestihi
17