import java.io.*;
import java.util.*;

public class given_gk {
    static Scanner in;
    static PrintWriter out;

    public void run() {
        char[] t = in.nextLine().toCharArray();
        String z = in.nextLine();
        char[] s = (z + z + z).toCharArray();

        int n = t.length;

        int[] p = new int[n];
        p[0] = -1;
        int q = -1;
        for (int i = 1; i < n; i++) {
            while (q != -1 && t[q + 1] != t[i]) q = p[q];
            if (t[q + 1] == t[i]) {
                q++;
            }
            p[i] = q;
        }

        int[][] table = new int[n][2];
        for (int i = 0; i < n; i++) {
            for (q = i - 1; q != -1 && t[q + 1] != '0'; q = p[q]);
            if (t[q + 1] == '0') q++;
            table[i][0] = q;
            for (q = i - 1; q != -1 && t[q + 1] != '1'; q = p[q]);
            if (t[q + 1] == '1') q++;
            table[i][1] = q;
        }

        boolean ok = false;
        for (int i = 0; i < n; i++) {
            q = -1;
            for (int j = 0; j < 2 * n; j++) {
                q = table[q + 1][s[j] ^ s[i + j]];
                if (q == n - 1) {
                    ok = true;
                    q = p[q];
                }
            }
        }

        out.println(ok ? "Yes" : "No");
    }

    public static void main(String[] args) throws IOException {
        in = new Scanner(new File("given.in"));
        out = new PrintWriter("given.out");

        new given_gk().run();

        in.close();
        out.close();
    }
}
