Problem:
Nested Repetition Compression
You have a number of strings of lowercase letters to be sent in e-mails, but some of them are so long that typing as they are would be tiresome. As you found repeated parts in them, you have decided to try out a simple compression method in which repeated sequences are enclosed in parentheses, prefixed with digits meaning the numbers of repetitions. For example, the string "
abababaaaaa
" can be represented as "
3(ab)5(a)
" or "
a3(ba)4(a)
". The syntax of compressed representations is given below in Backus-Naur form with the start symbol $S$.
<S> ::= <R> | <R> <S>
<R> ::= <L> | <D> ( <S> )
<D> ::= 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<L> ::= a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z
Note that numbers of repetitions are specified by a single digit, and thus at most nine, but more repetitions can be specified by nesting them. A string of thirty a's can be represented as  "
6(5(a))
" or "
3(5(2(a)))
", for example.
Find the shortest possible representation of the given string in this compression scheme.
Input
The input is a line containing a string of lowercase letters. The number of letters in the string is at least one and at most 200.
Output
Output a single line containing the shortest possible representation of the input string. If there exist two or more shortest representations, any of them is acceptable.
Sample Input 1
abababaaaaa
Sample Output 1
3(ab)5(a)
Sample Input 2
abababcaaaaaabababcaaaaa
Sample Output 2
2(3(ab)c5(a))
Sample Input 3
abcdefg
Sample Output 3
abcdefg

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
template <class T>
inline bool chmin(T& a, T b) {
  return ((a > b) ? (a = b, 1) : (0));
}
template <class T>
inline bool chmax(T& a, T b) {
  return ((a < b) ? (a = b, 1) : (0));
}
#define YesNo(f) cout << (f ? "Yes" : "No") << endl

void solve();
int main() {
  int T = 1;
  // cin >> T;
  while (T--) solve();
  return 0;
}

// nを9以下の整数の積であらわす
vector<vi> g9_table(201);
void g9_init() {
  auto mat = [&](vi v) -> int {
    int res = 1;
    for (auto x : v) res *= x;
    return res;
  };
  const int N = 201;
  queue<vi> q;
  vi seen(N);
  rep(i, 1, 10) q.push(vi(1, i));
  while (!q.empty()) {
    vi i = q.front();
    q.pop();
    int mi = mat(i);
    if (seen[mi]) continue;
    seen[mi] = 1;
    g9_table[mi] = i;
    rep(j, 2, 10) {
      if (mi * j >= N) continue;
      if (seen[mi * j]) continue;
      i.push_back(j);
      q.push(i);
      i.pop_back();
    }
  }
}
void solve() {  // solver
  g9_init();
  // for (auto v : g9_table) {
  //   for (auto x : v) cout << x << " ";
  //   cout << endl;
  // }
  string S;
  cin >> S;
  const int N = sz(S);
  vector dp(N, vector<string>(N + 1));
  vector com(N, vector<bool>(N + 1, false));

  auto f = [&](auto f, int l, int r) -> string {
    if (r - l == 1) return string(1, S[l]);
    if (com[l][r]) return dp[l][r];

    string res = S.substr(l, r - l);
    // 2分割
    rep(i, l + 1, r) {
      string tmp = f(f, l, i) + f(f, i, r);
      if (sz(res) > sz(tmp)) res = tmp;
    }
    // num(str) <- sz(str)==len
    rep(len, 1, r - l) {
      vi v = g9_table[(r - l) / len];
      if (v.empty()) continue;

      if ((r - l) % len != 0) continue;
      bool ok = true;
      string fir = S.substr(l, len);
      for (int i = l; i < r; i += len) {
        if (fir != S.substr(i, len)) {
          ok = false;
          break;
        }
      }
      if (ok) {
        string tmp;
        for (auto x : v) {
          tmp += x + '0';
          tmp += '(';
        }
        tmp += f(f, l, l + len);
        rep(stp, 0, sz(v)) tmp += ')';
        if (sz(res) > sz(tmp)) res = tmp;
      }
    }
    com[l][r] = 1;
    return dp[l][r] = res;
  };
  cout << f(f, 0, N) << endl;
  return;
}
/*
icpc-r-2023-d
区間dpしながら求める
*/
accuracy: 1
time_ms: 80
memory_kb: 6400
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
constexpr int N_MAX = 200;
string s, dp[N_MAX + 1][N_MAX + 1];
int n;
bool chmin(string& a, const string b) {
  if (a.size() <= b.size()) return 0;
  a = b;
  return 1;
}
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> s;
  n = s.size();
  rep(l, n + 1) rep(r, n + 1) dp[l][r] = s.substr(l, r - l);
  for (int len = 2; len <= n; ++len) {
    rep(l, n - len + 1) {
      int r = l + len;
      for (int d = 9; 2 <= d; --d) {
        if (len % d) continue;
        int seg = len / d;
        bool ok = 1;
        rep(i, seg) {
          for (int j = l + seg + i; j < r; j += seg) {
            if (s[l + i] != s[j]) {
              ok = 0;
              break;
            }
          }
          if (!ok) break;
        }
        if (!ok) continue;
        string cand = to_string(d) + "(" + dp[l][l + seg] + ")";
        chmin(dp[l][r], cand);
      }
      for (int k = l; k < r; ++k) chmin(dp[l][r], dp[l][k] + dp[k][r]);
    }
  }
  cout << dp[0][n] << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 7936
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
constexpr int N_MAX = 200;
string s, dp[N_MAX + 1][N_MAX + 1];
int n;
bool chmin(string& a, const string b) {
  if (a.size() <= b.size()) return 0;
  a = b;
  return 1;
}
signed main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> s;
  n = s.size();
  rep(l, n + 1) rep(r, n + 1) dp[l][r] = s.substr(l, r - l);
  for (int len = 2; len <= n; ++len) {
    rep(l, n - len + 1) {
      int r = l + len;
      for (int d = 9; 2 <= d; --d) {
        if (len % d) continue;
        int seg = len / d;
        bool ok = 1;
        rep(i, seg) {
          for (int j = l + seg + i; j < r; j += seg) {
            if (s[l + i] != s[j]) {
              ok = 0;
              break;
            }
          }
          if (!ok) break;
        }
        if (ok) {
          string cand = to_string(d) + "(" + dp[l][l + seg] + ")";
          chmin(dp[l][r], cand);
          break;
        }
      }
      for (int k = l; k < r; ++k) chmin(dp[l][r], dp[l][k] + dp[k][r]);
    }
  }
  cout << dp[0][n] << endl;
}
accuracy: 0.43023255813953487
time_ms: 30
memory_kb: 8064
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, a, b) for (ll i = a; i <= (ll)b; ++i)
#define vl vector<ll>
#define vvl vector<vl>
int dx[] = {1, 0, 0, -1};
int dy[] = {0, 1, -1, 0};

string mymin(string a,string b){
	if(a.size()<b.size())return a;
	if(a.size()>b.size())return b;
	return min(a,b);
}

int main(){
	string s;
	cin>>s;
	ll n=s.size();
	vector<vector<string>> dp(n+1,vector<string>(n+1,string(n+1,'.')));
	
	rep(j,n){
		dp[1][j]=s[j];
	}
	loop(i,1,n){
		rep(j,n-i+1){
			//マージフェーズ
			loop(k,1,i-1){
				dp[i][j]=mymin(dp[i][j],dp[k][j]+dp[i-k][j+k]);
			}

			//圧縮フェーズ
			loop(k,1,min(((n-j)/i)-1,8LL)){
				bool f=true;
				rep(l,i){
					if(s[j+l]!=s[j+l+k*i]){
						f=false;
						break;
					}
				}
				if(f){
					dp[i*(k+1)][j]=mymin(dp[i*(k+1)][j],to_string(k+1)+"("+dp[i][j]+")");
				}else{
					break;
				}
				
			}
		}
		
	}

	cout<<dp[n][0]<<endl;
	return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 13568
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  vector<vector<string>> D(n + 1, vector<string>(n + 1));
  for (int i = 0; i < n; i++) D[i][i + 1] = s.substr(i, 1);
  for (int k = 2; k <= n; k++) {
    for (int l = 0; l <= n - k; l++) {
      int r = l + k;
      auto& d = D[l][r];
      d = s.substr(l, k);
      for (int m = l + 1; m <= r - 1; m++) {
        if (d.size() > D[l][m].size() + D[m][r].size()) {
          d = D[l][m] + D[m][r];
        }
      }
      for (int c = 2; c <= 9; c++) {
        if (k % c == 0) {
          int cl = k / c;
          if (s.substr(l, k - cl) == s.substr(l + cl, k - cl) && 3 + D[l][l + cl].size() < d.size()) {
            stringstream ss;
            ss << c << '(' << D[l][l + cl] << ')', d = ss.str();
          }
        }
      }
    }
  }
  cout << D[0][n] << "\n";
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6224
final_rank: 2

code_snippet: // Yokohama 2023 D Nested Repetition Compression
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define SZ(x) int(x.size())
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  string S;
  cin >> S;
  int N = S.size();
  vector<vector<string>> dp(N + 1, vector<string>(N + 1));
  REP(i, 0, N - 1) dp[i][i + 1] = S.substr(i, 1);  // D[i,i+1): 单个字符重复一次
  REP(k, 2, N) REP(l, 0, N - k) {
    int r = l + k;
    auto& d = dp[l][r];  // D[l,r]: 字符串 S[l,r) 的最优压缩答案
    d = S.substr(l, k);  // 不压缩也是一种方案
    REP(m, l + 1, r - 1) if (SZ(d) > SZ(dp[l][m]) + SZ(dp[m][r])) {
      d = dp[l][m] + dp[m][r];  // 切成两部分[l,m) [m,r)，压缩之后拼起来
    }
    REP(c, 2, 9) if (k % c == 0) {  // 能否分成c(2≤c≤9)个相同的字符串
      int cl = k / c;               // 周期长度
      string tmp = S.substr(l, cl);
      if (S.substr(l, k - cl) == S.substr(l + cl, k - cl) and
          3 + SZ(dp[l][l + cl]) < SZ(d)) {
        stringstream ss;  // c(dp[l][l+cl])的形式
        ss << char(c + '0') << '(' << dp[l][l + cl] << ')', d = ss.str();
      }
    }
  }
  return cout << dp[0][N], 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6220
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;

string dp[209][209];

int main() {
    // Step 1. Input
    string S; cin >> S;
    int N = S.size();
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k <= N; k++) dp[i][j] += "a";
        }
    }

    // Step 2. Solve
    for (int l = N - 1; l >= 0; l--) {
        for (int r = l + 1; r <= N; r++) {
            tuple<int, int, int> minv = make_tuple(r - l, 1, 0);
            for (int m = l + 1; m <= r - 1; m++) {
                int cost = dp[l][m].size() + dp[m][r].size();
                minv = min(minv, make_tuple(cost, 2, m));
            }
            for (int m = 1; m <= r - l - 1; m++) {
                if ((r - l) % m != 0) continue;
                if ((r - l) / m >= 10) continue;
                bool flag = true;
                for (int i = l + m; i < r; i++) {
                    if (S[i] != S[i - m]) { flag = false; break; }
                }
                if (flag == false) continue;
                string str = to_string((r - l) / m);
                int cost = dp[l][l + m].size() + (int)str.size() + 2;
                minv = min(minv, make_tuple(cost, 3, m));
            }

            // Reconstruction
            if (get<1>(minv) == 1) {
                dp[l][r] = S.substr(l, r - l);
            }
            if (get<1>(minv) == 2) {
                int m = get<2>(minv);
                dp[l][r] = dp[l][m] + dp[m][r];
            }
            if (get<1>(minv) == 3) {
                int m = get<2>(minv);
                dp[l][r] = to_string((r - l) / m) + "(" + dp[l][l + m] + ")";
            }
        }
    }

    // Step 3. Output
    cout << dp[0][N] << endl;
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 14960
final_rank: 10

code_snippet: // AOJ #1447 Nested Repetition Compression
// 2025.2.25

#include <bits/stdc++.h>
using namespace std;
 
unordered_map<string, string> repMemo;

string repCompress(int k, const string &rep) {
    if(k == 1) return rep;
    string key = to_string(k) + "#" + rep;
    if(repMemo.find(key) != repMemo.end())
        return repMemo[key];
    
    string best = "";
    if(k >= 2 && k <= 9) {
        best = to_string(k) + "(" + rep + ")";
    }
    for (int d = 2; d <= 9; d++){
        if(k % d == 0 && k/d > 1) {
            string inner = repCompress(k/d, rep);
            string cand = to_string(d) + "(" + inner + ")";
            if(best == "" || cand.size() < best.size() ||
               (cand.size() == best.size() && cand < best)){
                best = cand;
            }
        }
    }
    if(best == ""){
        string repRepeated = "";
        for(int i = 0; i < k; i++) repRepeated += rep;
        best = repRepeated;
    }
    repMemo[key] = best;
    return best;
}
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    getline(cin, s);
    int n = s.size();
    vector<vector<string>> dp(n, vector<string>(n, ""));
    
    for (int i = 0; i < n; i++) dp[i][i] = string(1, s[i]);
    
    for (int len = 2; len <= n; len++){
        for (int i = 0; i + len - 1 < n; i++){
            int j = i + len - 1;
            string plain = s.substr(i, len);
            string best = plain;
            for (int k = i; k < j; k++){
                string candidate = dp[i][k] + dp[k+1][j];
                if(candidate.size() < best.size() ||
                   (candidate.size() == best.size() && candidate < best)){
                    best = candidate;
                }
            }
            int subLen = j - i + 1;
            for (int p = 1; p <= subLen / 2; p++){
                if(subLen % p != 0) continue;
                int times = subLen / p;
                bool match = true;
                for (int k = i; k <= j; k++){
                    if(s[k] != s[i + (k - i) % p]){
                        match = false;
                        break;
                    }
                }
                if(match){
                    string repCandidate = repCompress(times, dp[i][i+p-1]);
                    if(repCandidate.size() < best.size() ||
                       (repCandidate.size() == best.size() && repCandidate < best)){
                        best = repCandidate;
                    }
                }
            }
            dp[i][j] = best;
        }
    }
    cout << dp[0][n-1] << endl;
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 6280
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
string s;
int n;
map<pair<int,int>,string>mp;
string calc(int l,int r){
  if(mp.find({l,r})!=mp.end())return mp[{l,r}];
  int len=r-l;
  string re=s.substr(l,len);
  for(int k=1;k<r-l;++k){
    if(len%k!=0)continue;
    if(9<len/k)continue;
    bool ok=1;
    for(int i=l+k;i<r&&ok;i+=k){
      if(s.substr(l,k)!=s.substr(i,k))ok=0;
    }
    if(ok){
      string te;
      te+='0'+(len/k);
      te+='(';
      te+=calc(l,l+k);
      te+=')';
      if(te.size()<re.size())re=te;
    }
  }
  for(int k=l+1;k<r;++k){
    string te=calc(l,k)+calc(k,r);
    if(te.size()<re.size())re=te;
  }
  return mp[{l,r}]=re;
}
int main(){
  cin.tie(0)->sync_with_stdio(0);
  cin>>s;
  n=s.size();
  cout<<calc(0,n)<<endl;
}
accuracy: 1
time_ms: 350
memory_kb: 6412
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep2(i, n) for (ll i = 0; i < (n); i++)
#define rep3(i, a, b) for (ll i = a; i < (b); i++)
#define overload(a, b, c, d, ...) d
#define rep(...) overload(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(a) begin(a), end(a)
#define sz(a) ssize(a)
bool chmin(auto& a, auto b) {
    return a > b ? a = b, 1 : 0;
}
bool chmax(auto& a, auto b) {
    return a < b ? a = b, 1 : 0;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    string s;
    cin >> s;
    int n = s.size();

    vector table(n, vector<int>(n));
    rep(i, n) rep(j, n) {
        int d = 0;
        while (i + d < n && j + d < n && s[i + d] == s[j + d]) d++;
        table[i][j] = d;
    }

    vector memo(n, vector<string>(n + 1));
    auto dfs = [&](auto&& self, int l, int r) -> string {
        if (!memo[l][r].empty()) return memo[l][r];
        int n = r - l;
        string cur = s.substr(l, r - l);

        rep(k, 1, n) {
            if (n % k != 0) continue;
            if (n / k >= 10) continue;
            bool ok = true;
            for (int i = l; i < r; i += k) {
                if (table[l][i] < k) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                auto res = to_string(n / k) + "(" + self(self, l, l + k) + ")";
                if (cur.size() > res.size()) cur = res;
            }
        }

        rep(i, l + 1, r) {
            auto res = self(self, l, i) + self(self, i, r);
            if (cur.size() > res.size()) cur = res;
        }
        return memo[l][r] = cur;
    };

    cout << dfs(dfs, 0, n) << '\n';
}
accuracy: 1
time_ms: 60
memory_kb: 6656
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  string S;
  cin >> S;
  int n = S.size();

  vector dp(n + 1, vector<string>(n + 1, string(1000, '*')));
  for (int i = n; i >= 0; i--) {
    rep(j, i, n + 1) {
      dp[i][j] = S.substr(i, j - i);  // raw string
      rep(k, i, j) {
        if (dp[i][j].size() > dp[i][k].size() + dp[k][j].size()) {
          dp[i][j] = dp[i][k] + dp[k][j];
        }
      }
      rep(d, 2, 10) {
        if ((j - i) % d != 0) continue;
        bool ok = true;
        rep(x, 0, (j - i) / d) {
          rep(y, 0, d) {
            if (S[i + x] != S[i + x + y * (j - i) / d]) {
              ok = false;
              break;
            }
          }
        }
        if (!ok) continue;
        // dp[i][j] = min(dp[i][j], 3 + dp[i][i + (j - i) / d]);
        if (dp[i][j].size() > 3 + dp[i][i + (j - i) / d].size()) {
          dp[i][j] = to_string(d) + "(" + dp[i][i + (j - i) / d] + ")";
        }
      }
    }
  }

  cout << dp[0][n];
}
accuracy: 1
time_ms: 20
memory_kb: 45004
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    string s;cin>>s;
    int n=s.size();
    vector<vector<string>> memo(n+1,vector<string>(n+1));
    auto f=[&](auto self,int l,int r) -> string {
        if(memo[l][r].size()!=0)return memo[l][r];
        int len=r-l;
        if(len==1)return {s[l]};
        string res = s.substr(l,len);
        for (int i = l+1; i < r; i++) {
            string tmp=self(self,l,i)+self(self,i,r);
            if(res.size()>tmp.size()){
                res=tmp;
            }
        }
        for (int d = 1; d < len; d++) {
            if(len%d!=0)continue;
            // for (int st = l; st+d <= r; st++) {
            int mk = len / d;
            if(mk>=10)continue;
                string base=self(self,l,l+d);
                bool isok=true;
                for (int k = l; k < r; k+=d) {
                    if(base!=self(self,k,k+d)){ isok=false;break;}
                }
                if(!isok)continue;
                string ta;
                ta+='0'+mk;
                ta+='(';
                ta+=base;
                ta+=')';
                // cerr<<ta<<endl;
                // cerr<<res<<endl;
                if(res.size()>ta.size()){
                    res=ta;
                }
            // }
        }
        memo[l][r]=res;
        return res;
    };
    cout<<f(f,0,n)<<endl;
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 6412
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
int main(){
  string s;
  cin >> s;
  ll n = (ll)s.size();
  vector<vector<string>> dp(n+1,vector<string>(n+1));
  vector<vector<ll>> find(n+1,vector<ll>(n+1));
  auto dfs = [&](auto dfs,ll l,ll r) {
    if (find[l][r] == 1)return dp[l][r];
    find[l][r] = 1;
    if (r == l+1) {
      return dp[l][r] = s.substr(l,1);
    }
    //[l,r)
    //k分割できる
    dp[l][r] = s.substr(l,r);
    for (ll k = 2;k <= 9;k++)if ((r-l)%k== 0) {
      ll step = (r-l)/k;
      bool ok = true;
      string base = s.substr(l,(r-l)/k);
      for (ll i = 1;i < k;i++) {
        string tmp = s.substr(l+step*i,step);
        if (tmp != base) {
          ok = false;
          break;
        }
      }
      if (ok) {
        string inner = dfs(dfs,l,l+step);
        string now = to_string(k) + "(" + inner + ")";
        if (now.length() < dp[l][r].length()) {
          dp[l][r] = now;
        }
      }
    }
    //どっかで分割
    for (ll k = l+1;k < r;k++) {
      string now = dfs(dfs,l,k) + dfs(dfs,k,r);
      if (now.length() < dp[l][r].length()) {
        dp[l][r]  = now;
      }
    }
    return dp[l][r];
  };
  dfs(dfs,0,n);
  cout << dp[0][n] << endl;


}
accuracy: 1
time_ms: 60
memory_kb: 7552
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
	string S; cin >> S;
	int N = S.size();

	vector<vector<string>> dp(N+1, vector<string>(N+1, ""));
	for(int i = 0; i < N; i++) dp[i][i+1] += S[i];

	// i->j 長さk
	vector<vector<vector<int>>> repeat(N, vector<vector<int>>(N+1, vector<int>(N+1)));
	for(int i = 0; i < N; i++){
		for(int k = 1; k <= N; k++){
			string s = S.substr(i, k);
			int cnt = 1;

			while(cnt <= 9 && i+cnt*k <= N && s == S.substr(i+(cnt-1)*k, k)){
				repeat[i][i+cnt*k][k] = cnt;
				cnt++;
			}
		}
	}

	for(int len = 2; len <= N; len++){
		for(int l = 0; l < N; l++){
			int r = l+len;
			if(r > N) break;

			string s = S.substr(l, len);
			int mnlen = len;

			for(int m = l+1; m < r; m++){
				if(dp[l][m].size()+dp[m][r].size() < mnlen){
					s = dp[l][m] + dp[m][r];
					mnlen = s.size();
				}
			}

			for(int k = 1; k < r-l; k++){
				//cerr << l << ' ' << r << ' ' << k << ' ' << s << ' ' << repeat[l][r][k] << endl;
				if(repeat[l][r][k] > 0){
					string t = to_string(repeat[l][r][k])+"("+dp[l][l+k]+")";
					if(t.size() < mnlen){
						mnlen = t.size();
						s = t;
						//cerr << l << ' ' << r << ' ' << k << ' ' << s << endl;
					}
					//string t = to_string(repeat[l][r][k])+"("+dp[l][l+k]+")";
					//cerr << l << ' ' << r << ' ' << k << ' ' << t << endl;
				}
			}

			dp[l][r] = s;
			//cerr << l << ' ' << r << ' ' << s << endl;
		}
	}

	cout << dp[0][N] << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 39360
final_rank: 13

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

bool memo[300][300] = {};
string ANS[300][300] = {};

string Solve(string S, int X, int Y) {
    if (memo[X][Y]) return ANS[X][Y];
    int Len = S.size();
    string Ret = S;
    rep(i,2,10) {
        if ((int)(S.size()) % i == 0) {
            int k = (int)(S.size()) / i;
            string T = S.substr(0,k);
            bool check = true;
            rep(j,0,i) {
                if (T != S.substr(k*j,k)) check = false;
            }
            if (check) {
                string R = Solve(T,X,X+k);
                R = '(' + R +')';
                R = (char)(i + '0') + R;
                if (chmin(Len,(int)(R.size()))) Ret = R;
            }
        }
    }
    rep(i,1,(int)(S.size())) {
        string R = Solve(S.substr(0,i),X,X+i) + Solve(S.substr(i,(int)(S.size()) - i),X+i,Y);
        if (chmin(Len,(int)(R.size()))) Ret = R;
    }
    memo[X][Y] = true;
    ANS[X][Y] = Ret;
    return Ret;
}

int main() {
    rep(i,0,300) rep(j,0,300) memo[i][j] = false, ANS[i][j] = "";
    string S;
    cin >> S;
    cout << Solve(S,0,(int)(S.size())) << endl;
}
accuracy: 1
time_ms: 110
memory_kb: 7836
final_rank: 11

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

bool memo[300][300] = {};
string ANS[300][300] = {};

string Solve(string S, int X, int Y) {
    if (memo[X][Y]) return ANS[X][Y];
    int Len = S.size();
    string Ret = S;
    rep(i,2,10) {
        if ((int)(S.size()) % i == 0) {
            int k = (int)(S.size()) / i;
            string T = S.substr(0,k);
            bool check = true;
            rep(j,0,i) {
                if (T != S.substr(k*j,k)) check = false;
            }
            if (check) {
                string R = Solve(T,X,X+k);
                R = '(' + R +')';
                R = (char)(i + '0') + R;
                if (chmin(Len,(int)(R.size()))) Ret = R;
            }
        }
    }
    rep(i,1,(int)(S.size()) - 1) {
        string R = Solve(S.substr(0,i),X,X+i) + Solve(S.substr(i,(int)(S.size()) - i),X+i,Y);
        if (chmin(Len,(int)(R.size()))) Ret = R;
    }
    memo[X][Y] = true;
    ANS[X][Y] = Ret;
    return Ret;
}

int main() {
    rep(i,0,300) rep(j,0,300) memo[i][j] = false, ANS[i][j] = "";
    string S;
    cin >> S;
    cout << Solve(S,0,(int)(S.size())) << endl;
}
accuracy: 0.005813953488372093
time_ms: 90
memory_kb: 7344
final_rank: 20

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

bool memo[300][300] = {};
string ANS[300][300] = {};

string Solve(string S, int X, int Y) {
    if (memo[X][Y]) return ANS[X][Y];
    if (S == "") return "";
    int Len = S.size();
    string Ret = S;
    rep(i,2,10) {
        if ((int)(S.size()) % i == 0) {
            int k = (int)(S.size()) / i;
            string T = S.substr(0,k);
            bool check = true;
            rep(j,0,i) {
                if (T != S.substr(k*j,k)) check = false;
            }
            if (check) {
                string R = Solve(T,X,X+k);
                R = '(' + R +')';
                R = (char)(i + '0') + R;
                if (chmin(Len,(int)(R.size()))) Ret = R;
            }
        }
    }
    rep(i,1,(int)(S.size()) - 1) {
        string R = Solve(S.substr(0,i),X,X+i) + Solve(S.substr(i,(int)(S.size()) - i),X+i,Y);
        if (chmin(Len,(int)(R.size()))) Ret = R;
    }
    memo[X][Y] = true;
    ANS[X][Y] = Ret;
    return Ret;
}

int main() {
    string S;
    cin >> S;
    cout << Solve(S,0,(int)(S.size())) << endl;
}
accuracy: 0.005813953488372093
time_ms: 90
memory_kb: 7252
final_rank: 19

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

bool memo[202][202] = {};
string ANS[202][202] = {};

string Solve(string S, int X, int Y) {
    if (memo[X][Y]) return ANS[X][Y];
    if (S == "") return "";
    int Len = S.size();
    string Ret = S;
    rep(i,2,10) {
        if ((int)(S.size()) % i == 0) {
            int k = (int)(S.size()) / i;
            string T = S.substr(0,k);
            bool check = true;
            rep(j,0,i) {
                if (T != S.substr(k*j,k)) check = false;
            }
            if (check) {
                string R = Solve(T,X,X+k);
                R = '(' + R +')';
                R = (char)(i + '0') + R;
                if (chmin(Len,(int)(R.size()))) Ret = R;
            }
        }
    }
    rep(i,1,(int)(S.size()) - 1) {
        string R = Solve(S.substr(0,i),X,X+i) + Solve(S.substr(i,(int)(S.size()) - i),X+i,Y);
        if (chmin(Len,(int)(R.size()))) Ret = R;
    }
    memo[X][Y] = true;
    ANS[X][Y] = Ret;
    return Ret;
}

int main() {
    string S;
    cin >> S;
    cout << Solve(S,0,(int)(S.size())) << endl;
}
accuracy: 0.005813953488372093
time_ms: 90
memory_kb: 5636
final_rank: 17

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

bool memo[201][201] = {};
string ANS[201][201] = {};

string Solve(string S, int X, int Y) {
    if (memo[X][Y]) return ANS[X][Y];
    if (S == "") return "";
    int Len = S.size();
    string Ret = S;
    rep(i,2,10) {
        if ((int)(S.size()) % i == 0) {
            int k = (int)(S.size()) / i;
            string T = S.substr(0,k);
            bool check = true;
            rep(j,0,i) {
                if (T != S.substr(k*j,k)) check = false;
            }
            if (check) {
                string R = Solve(T,X,X+k);
                R = '(' + R +')';
                R = (char)(i + '0') + R;
                if (chmin(Len,(int)(R.size()))) Ret = R;
            }
        }
    }
    rep(i,1,(int)(S.size()) - 1) {
        string R = Solve(S.substr(0,i),X,X+i) + Solve(S.substr(i,(int)(S.size()) - i),X+i,Y);
        if (chmin(Len,(int)(R.size()))) Ret = R;
    }
    memo[X][Y] = true;
    ANS[X][Y] = Ret;
    return Ret;
}

int main() {
    string S;
    cin >> S;
    cout << Solve(S,0,(int)(S.size())) << endl;
}
accuracy: 0.005813953488372093
time_ms: 90
memory_kb: 5824
final_rank: 18

code_snippet: #include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001
string s;
string dp[205][205];
string smin(string x,string y){
	if(x.size()<y.size())return x;
	return y;
}

string get(int l,int r){
	if(r-l<=0)return "";
	if(dp[l][r]!="")return dp[l][r];
	
	string ret(s.begin()+l,s.begin()+r);
	
	for(int i=1;i<r-l;i++){
		ret = smin(ret,get(l,l+i) + get(l+i,r));
	}
	for(int i=1;i<r-l;i++){
		if((r-l)%i!=0)continue;
		if((r-l)/i>=10)continue;
		string ts = s.substr(l,i);
		bool f = true;
		rep(j,(r-l)/i){
			if(s.substr(l+i*j,i)!=ts){
				f = false;
				break;
			}
		}
		if(!f)continue;
		ret = smin(ret,to_string((r-l)/i) + "(" + get(l,l+i) + ")");
	}
	
	dp[l][r] = ret;
	return ret;
}

int main(){
	
	cin>>s;
	int n = s.size();
	cout<<get(0,n)<<endl;
	
	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 6364
final_rank: 9