#include #define all(x) begin(x),end(x) #define rall(x) (x).rbegin(),(x).rend() #define REP(i,b,n) for(int i=(int)(b);i<(int)(n);++i) #define rep(i,n) REP(i,0,n) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define repsz(i,v) rep(i,(v).size()) using namespace std; templateint size(const C &c){ return c.size(); } templatebool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;} templatebool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;} using Int = long long; Int mulMod(Int a, Int b, Int mod){//{{{ if(a > b) swap(a, b); Int res = 0; for(; a;){ if(a&1){ res += b; if(res >= mod) res -= mod; } a >>= 1; b <<= 1; if(b >= mod) b -= mod; } return res; }//}}} unsigned int xor128(){ //static unsigned int x=123456789,y=362436069,z=521288629,w=88675123; static unsigned int x=129042, y=38923212, z=3829312, w=3893189; unsigned int t=x^(x<<11); x=y;y=z;z=w; return w=(w^(w>>19))^(t^(t>>8)); } int rnd(int m){ return xor128() % m; } bool solve(){ constexpr int max_e = 10000; Int P, B; // cin >> P >> B; P = 1000000000000000003LL; B = 123456789987654321LL; vector> powB(max_e+1); { powB[0].first = 1; rep(i, max_e) powB[i+1].first = mulMod(powB[i].first, B, P); rep(i, max_e+1) powB[i].second = max_e - i; sort(powB.begin(), powB.end()); auto tmp = powB; powB.clear(); rep(i, max_e) if(rnd(i+1) == 0) powB.emplace_back(tmp[i]); sort(powB.rbegin(), powB.rend()); } unordered_map memo; while(true){ string s(max_e, 'a'); Int hash = 0; for(auto &pi : powB) if(rnd(2)){ ++s[pi.second]; hash = (hash + pi.first) % P; } for(auto &pi : powB){ vector> tmp; tmp.emplace_back(hash, 0); rep(i, 20) tmp.emplace_back((tmp.back().first + pi.first) % P, i+1); int e; tie(hash, e) = *max_element(all(tmp)); } if(memo.count(hash)){ if(memo[hash] == s) continue; cout << memo[hash] << endl << s << endl; return true; } if((memo.size() & -memo.size()) == memo.size()){ cout << memo.size() << endl; cout << hash << endl; } memo[hash] = s; } return true; } signed main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << std::fixed << std::setprecision(10); solve(); return 0; } // vim:set foldmethod=marker commentstring=//%s: