words. Say that a word a **frames** a word b if b both starts and ends with a. For example, "aba" frames "ababa", while "abc" does not frame "abcd". Every word frames itself.
Count the index pairs (i, j) with i < j such that words[i] frames words[j].words=['ab', 'abab', 'b', 'ab'] → 2
"ab" both starts and ends "abab" (pair (0, 1)), and the second "ab" matches the first one entirely (pair (0, 3)). "b" does not start any later word.
words=['xyx', 'x', 'xyxyx'] → 2
Both "xyx" and "x" frame "xyxyx" on both sides. The pair (0, 1) does not count because the longer word comes first.
words=['ab', 'abab', 'b', 'ab']
2
Run checks the first 3 tests in your browser. Submit checks all 71 tests on the server, hidden ones included.