#include<bits/stdc++.h>
using namespace std;
const int N=3e6+1;
char s[N];
int nxt[N],mx;
int main(){
cin>>s+1;
int len=strlen(s+1);
for(int i=2,j=0;i<=len;i++){
while(j&&s[i]!=s[j+1]){
j=nxt[j];
}
if(s[i]==s[j+1]){
j++;
}
nxt[i]=j;
if(i!=len){
mx=max(mx,nxt[i]);
}
}
int f=nxt[len];
if(!f){
cout<<"Just a legend"<<endl;
}
else{
while(f>mx){
f=nxt[f];
}
if(!f){
cout<<"Just a legend"<<endl;
}
else{
for(int i=2;i<len;i++){
if(f==nxt[i]){
for(int j=i-nxt[i]+1;j<=i;j++){
cout<<s[j];
}
cout<<endl;
exit(0);
}
}
}
}
return 0;
}
第六行有疑问。