/** ____ ____ ____ ____ ____ ____ ||l |||e |||i |||n |||a |||d || ||__|||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\|/__\| **/ #include #define endl '\n' using namespace std; typedef long long ll; const ll base = 26; const int maxn = 1e5 + 10; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } char c[maxn]; void solve() { map < ll, int > mp; map < ll, int > to; map < ll, pair < int, int > > rev; string s; cin >> s; int n = s.size(); for (int i = 0; i < n; i ++) { ll h = 0; string p = ""; for (int j = i; j < min(n, i + 500000 / n); j ++) { h = (h * base) + s[j] - '1'; if (to[h] == 0 || to[h] < i) { mp[h] ++; rev[h] = {i, j}; to[h] = j; } } } int best = 0; ll hs; for (auto it : mp) { int sz = rev[it.first].second - rev[it.first].first + 1; int cnt = it.second; ///cout << k << " " << cnt << " " << (int)(k.size()) * cnt - ((int)(k.size()) + cnt) << endl; if (sz * cnt - (sz + cnt + 3) >= best) { hs = it.first; best = sz * cnt - (sz + cnt); } } string p = s.substr(rev[hs].first, rev[hs].second - rev[hs].first + 1); if (best == 0) { cout << s << endl; return; } int pos = 0, pl = 0; while(true) { //cout << pos << " " << pl << endl; if (pos == n) break; if (pos + p.size() > n) { c[pl ++] = s[pos ++]; continue; } if (s.substr(pos, p.size()) == p) c[pl ++] = '#', pos = pos + p.size(); else c[pl ++] = s[pos], pos ++; } if (pl + p.size() + 3 > n) { cout << s << endl; return; } cout << "#=" << p << "."; int i = 0; while(i < pl) { int j = i; while(j < n && c[j] == c[i] && c[j] != '#') j ++; if (j - i > 5) { cout << "[" << c[i] << "," << j - i << "]"; i = j; } else cout << c[i], i ++; } } int main() { freopen ("pattern.in ", "r", stdin); freopen ("pattern.out", "w", stdout); solve(); return 0; }