P10476 Necklace

Description

One day, student Yuan borrowed a priceless gemstone necklace. However, a serious problem was that he actually forgot who the owner of the necklace was. After this became known, many people sent him emails, claiming that the necklace was theirs and asking him to return it (obviously, at most one of them is telling the truth). Student Yuan asked everyone to write a description of their necklace: The gemstones on the necklace are represented by digits from $0$ to $9$. One way to represent a necklace is to start from some gemstone on the necklace, go one full circle clockwise, and record the gemstones you pass. For example, for the following necklace: ![](https://cdn.luogu.com.cn/upload/image_hosting/57501u19.png) Its four possible representations are $0123$, $1230$, $2301$, $3012$. Student Yuan is now extremely anxious, so he came to you and hopes you can write a program to determine whether two given descriptions represent the same necklace (note that the necklace cannot be flipped).

Input Format

The input file contains only two lines. Each line is a string consisting of digits from $0$ to $9$, describing a representation of a necklace (it is guaranteed that the two necklaces have the same length).

Output Format

If the two necklaces cannot be isomorphic, output `No`. Otherwise, output `Yes` on the first line, and output the lexicographically smallest representation of the necklace on the second line.

Explanation/Hint

Let $L =$ the necklace length, then $1\leq L \leq 1000000$. Translated by ChatGPT 5