# BZOJ 5128([Lydsy12月赛]寻找母串-区间dp)

1. T =hello。
2. T =hhelloello。
3. T =hhelloelhellolo。
4. T =hhehellolloelhellolo。

|T|<=200

fi,j$f{i,j}$表示子串T[i,j]$T[i,j]$能否合法由t产生。

#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (998244353)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MAXN (210)
int n,len;
char s[MAXN],t[MAXN],ans[MAXN];
int f[MAXN][MAXN];
bool check(int i,int j) {
if (i>j) return 1;
if (f[i][j]!=-1) return f[i][j];
f[i][j]=0;
for(int k=j-len;k>=i;k-=len) {
if (check(i,k) && check(k+1,j)) return f[i][j]=1;
}
if (s[j]==t[(j-i)%len]) {
return f[i][j]=check(i,j-1);
}
return f[i][j]=0;
}
int main()
{
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
scanf("%s",s+1);
n=strlen(s+1);
bool flag=0;
for(len=1;len<=n;len++) if (n%len==0){
for(int i=1;i<=n-len+1;i++) {
int j=i+len-1;
memcpy(t,s+i,sizeof(char)*len);
t[len]=0;
memset(f,-1,sizeof(f));
if (check(1,n)) {
if (!flag || strcmp(t,ans)<0) flag=1,memcpy(ans,t,sizeof(char)*(len+1));
}
}
if (flag) {
cout<<ans<<endl; return 0;
}
}
return 0;
}