#C2055. Concatenated Palindrome Check

    ID: 45329 Type: Default 1000ms 256MiB

Concatenated Palindrome Check

Concatenated Palindrome Check

Problem Statement:

You are given a list of words. Your task is to determine whether there exist two distinct words such that, when concatenated (one appended after the other), they form a palindrome. A string is considered a palindrome if it reads the same forward and backward. Note that the two words must be different, though they can be identical in content if they appear in different positions in the list.

For example, if the list is ["abat", "tab", "abc", "xyx"], then combining "abat" and "tab" gives "abattab", which is a palindrome. Hence, the answer would be YES. Conversely, if no such pair exists, output NO.

inputFormat

Input is read from standard input (stdin). The first line contains a single integer n (n ≥ 2) representing the number of words. This is followed by n lines, each containing one word consisting of lowercase English letters.

outputFormat

Output a single line to standard output (stdout): print 'YES' if there exist two distinct words in the list whose concatenation forms a palindrome; otherwise, print 'NO'.## sample

4
abat
tab
abc
xyx
YES