MediumStringsNot started

Check a label rotation

A circular label printer may begin reading at a different position but must preserve the same character cycle. Read the original and printed labels. Print YES if the printed label is a cyclic rotation of the original, otherwise print NO.

Input

Two lines, each containing a non-empty lowercase label.

Output

One line: YES or NO.

Example 1

Input

warehouse
houseware

Output

YES

Moving the first four characters of warehouse to the end gives houseware.

Constraints

  • Each label has 1 to 200 lowercase letters

Hints

Hint 1 of 3

Rotations must have the same length.

Hint 2 of 3

Write the original label twice in a row.

Hint 3 of 3

Every rotation appears as a same-length substring of original + original.

Solution

Show a reference solution and explanation
 Python · reference solution
original = input().strip()
printed = input().strip()
is_rotation = len(original) == len(printed) and printed in (original + original)
print("YES" if is_rotation else "NO")

Approach

Doubling the original contains every possible cut-and-wrap arrangement as a contiguous substring. The explicit length check prevents a shorter repeated pattern from being accepted accidentally.

Your program
original = input().strip()
printed = input().strip()
# print YES or NO

Tests: 4 cases including the examples. Available in Python, JavaScript.

How this page was checked. Every reference solution, in every language listed, was run against every test case by the publishing checks. Languages marked “no run” have no in-browser runtime here yet; download your file and run it locally.