P1341 Unordered Letter Pairs

Description

Given $n$ distinct unordered letter pairs (case-sensitive; unordered means the two letters in a pair can appear in either order), construct a string with $(n+1)$ letters such that each letter pair appears in this string.

Input Format

The first line contains a positive integer $n$. Each of the next $n$ lines contains two letters, indicating that these two letters must be adjacent.

Output Format

Output a string that satisfies the requirement. If no such string exists, output `No Solution`. If multiple solutions exist, output the lexicographically smallest one (i.e., the earlier letters should have smaller ASCII codes).

Explanation/Hint

The number of different unordered letter pairs is finite, and the scale of $n$ can be calculated. Translated by ChatGPT 5