#include #include #include #include using namespace std; using ll = long long; #define rep(i, j, n) for (ll i = j; i < (n); ++i) #define rrep(i, j, n) for (ll i = (n) - 1; j <= i; --i) #define all(a) a.begin(), a.end() int main() { cin.tie(0)->sync_with_stdio(0); ll a, b; cin >> a >> b; string s; char c = 0; rep(i, 0, b * 10) { s += c + 'a'; c = (c + 1) % 26; } int n = (int)s.size(); vector hash(n + 1); rep(i, 0, n) { hash[i + 1] = (hash[i] * a + s[i]) % b; } vector mp(b); rep(i, 0, n) mp[hash[i]]++; ll mx = 0, mxi = 0; rep(i, 0, b) if (mx < mp[i]) mx = mp[i], mxi = i; vector ids; rep(i, 0, n) if (hash[i] == mxi) ids.push_back(i); string t = s; reverse(t.begin() + ids[0], t.begin() + ids[1]); cout << s << '\n' << t << '\n'; }