eolymp
bolt
Try our new interface for solving problems
Məsələlər

Insidious Branding

Insidious Branding

A brand designer came up with a strategy that you think will be the key to the success of your company, and therefore, you. The strategy is to use a brand name that has two possible decompositions into a pair of frequently used everyday words, and then expose the consumer to the four words repeatedly in brief episodes of sensory bombardment. The feeble mind of the consumer will jar, and the brand will then ease its way into the victim's long-term memory. Your task is to write a program that sifts through a dictionary for combinations of four words (not necessarily distinct), say \textbf{A},\textbf{B}, \textbf{C} and \textbf{D}, which satisfy the equation \textbf{A+B=C+D} where '\textbf{+}' denotes concatenation, '\textbf{=}' denotes an exact string match, the length of the word \textbf{A} is strictly less than the length of the word \textbf{C}, and all four strings are not empty. \InputFile The input consists of multiple cases where one dictionary is used for each case. A case starts with an integer \textbf{W} (\textbf{1}≤ \textbf{W} < \textbf{100000}) that indicates the number of words in the dictionary on a line by itself. Each of the following \textbf{W} lines contains a single word. The words are in no particular order, and they are all distinct within a test case. Each word is a string that consists of \textbf{L} lowercase letters and contains no spaces. \textbf{1} ≤ \textbf{L} ≤ \textbf{30}. The input is terminated by a zero on a line by itself. \OutputFile The output consists of a single integer, on a line by itself, that represents the number of equations that can be formed.
Zaman məhdudiyyəti 3 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
4
catchment
ally
catch
mentally
0
Çıxış verilənləri #1
1
Mənbə The 2011 South Pacific Programming Contest