https://sourceforge.net/projects/embarcadero-devcpp/
#include<bits/stdc++.h>
using namespace std;
using lld = long long;
const lld siz = 2e2+5;
const lld mod = 1e9+7;
using pll = pair<lld,lld>;
lld n;
string str;
lld dp[siz][siz];
lld splt[siz][siz];
lld rept[siz][siz];
string ans(lld l,lld r)
{
if(l == r) return string(str,l,1);
if(rept[l][r]!=0)
{
string m = ans(l,l+(r-l+1)/rept[l][r]);
return to_string(rept[l][r])+'('+m+')';
}
return ans(l,splt[l][r])+ans(splt[l][r]+1,r);
}
bool check(lld l,lld r,lld t)
{
lld len = (r-l+1)/t;
for(int i=l;i<=r-2*len;i+=len)
if(string(str,i,len)!=string(str,i+len,len))
return false;
return true;
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
cin>>str; n = str.size(); str = " "+str;
for(int i=1;i<=n;i++)
dp[i][i] = 1;
for(int len=2;len<=n;len++)
{
for(int l=1;l+len-1<=n;l++)
{
lld r = l+len-1;
dp[l][r] = 1e18;
for(int s=l;s<r;s++)
{
if(dp[l][r]>dp[l][s]+dp[s+1][r])
{
dp[l][r] = dp[l][s]+dp[s+1][r];
splt[l][r] = s; rept[l][r] = 0;
}
}
for(int t=2;t<10;t++)
{
if(len%t == 0&&check(l,r,t))
{
lld now = 3+dp[l][l+len/t-1];
if(now<dp[l][r])
{
dp[l][r] = now;
rept[l][r] = t;
}
}
}
}
}
cout<<ans(1,n);
return 0;
}https://www.luogu.com.cn/article/n5epgpxr