#K51567. Substring of Rotated String

    ID: 29116 Type: Default 1000ms 256MiB

Substring of Rotated String

Substring of Rotated String

You are given two strings ( s_1 ) and ( s_2 ). Your task is to determine whether ( s_2 ) can appear as a contiguous substring in some rotation of ( s_1 ). A rotation of a string involves taking a prefix of the string and moving it to the end. For instance, if ( s_1 = ) "abcdefg", one valid rotation is "cdefgab". Output “YES” if there exists a rotation of ( s_1 ) that contains ( s_2 ) as a substring, otherwise output “NO".

inputFormat

The input consists of four lines:

  1. An integer ( n ) representing the length of string ( s_1 ).
  2. A string ( s_1 ).
  3. An integer ( m ) representing the length of string ( s_2 ).
  4. A string ( s_2 ).

All input is provided via standard input (stdin).

outputFormat

Output a single line containing either "YES" if ( s_2 ) can be found as a substring in some rotation of ( s_1 ), or "NO" otherwise. The answer should be printed on standard output (stdout).## sample

7
abcdefg
3
cde
YES

</p>