All problems

Problem 218

Check String Rotation

Easy · 10 pts · String

Problem

A rotation of a string A is obtained by moving some prefix of A to its end; for example, the rotations of abc are abc, bca and cab. Moving an empty prefix leaves A unchanged, so A counts as a rotation of itself. Given strings A and B, decide whether B is a rotation of A. Strings of different lengths can never be rotations of each other. A neat trick: when the lengths are equal, B is a rotation of A exactly when B appears as a substring of A + A, because A + A contains every rotation of A.

Input

Two lines: strings A and B of lowercase letters.

Output

Print YES or NO.

Constraints

1 <= |A|, |B| <= 100000

Example input

abcde
cdeab

Example output

YES

Explanation

Moving the prefix ab of abcde to its end gives cdeab, which is B. So the answer is YES. Indeed, cdeab appears inside abcdeabcde.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Capitalize Each Word Next: Longest Word in a Sentence