Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

Ring

Write a program which finds a pattern $p$ in a ring shaped text $s$.

Input

In the first line, the text $s$ is given.

In the second line, the pattern $p$ is given.

Output

If $p$ is in $s$, print Yes in a line, otherwise No.

Constraints

$1 \leq $ length of $p \leq $ length of $s \leq 100$

$s$ and $p$ consists of lower-case letters

Sample Input 1

vanceknowledgetoad
advance

Sample Output 1

Yes

Sample Input 2

vanceknowledgetoad
advanced

Sample Output 2

No

Solution in JAVA (judge verdict: Accepted)

import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String s = "";
		String p = "";
		String searched_line = "";
		boolean judge = false;
		int count = 0; // 一致している文字数をカウントするための変数

		s = sc.nextLine();
		p = sc.nextLine();

		if (p.length() >= 1 && s.length() >= p.length() && s.length() <= 100) {

			searched_line = s + s.substring(0, p.length() - 1);

			out: for (int i = 0; i < s.length(); i++) {
				count = 0;
				if (("" + searched_line.charAt(i)).equals("" + p.charAt(0))) { // if1
					count++;
					in: for (int j = 1; j < p.length(); j++) {
						if (("" + searched_line.charAt(i + j)).equals("" // if2
								+ p.charAt(j)) == false) {
							break in;
						}// if2ここまで
						count++;
					}// in: for文ここまで

					if (count == p.length()) { // if3
						judge = true;
						break out;
					}// if3ここまで

				} // if1ここまで

			}// out:for文ここまで

			if (judge == true) {
				System.out.println("Yes");

			} else {
				System.out.println("No");
			}

		}

	}

}