#include <bits/stdc++.h> using namespace std; const int maxn = 2e6 + 10;
int n; string a, b;
int get_min(string t) { int i = 0, j = 1; while (i <= n && j <= n) { int k = 0; while (k < n && t[i + k] == t[j + k]) { //当前位相等 k++; } if (k == n) { //到最后一直都相等 说明字符串是由同一字母构成的 break; } if (t[i + k] > t[j + k]) { // i指向的字符串大 舍弃i i += k + 1; } else { j += k + 1; } if (i == j) i++; // j++ } int res = min(i, j); //一定有一个跑出界了 return res; }
int main() { cin >> a >> b; n = a.length(); a = a + a; b = b + b; int ap = get_min(a), bp = get_min(b); string na = a.substr(ap) + a.substr(0, ap - 1); string nb = b.substr(bp) + b.substr(0, bp - 1); if (na == nb) { cout << "Yes" << endl; cout << na << endl; } else { cout << "No" << endl; } return 0; }