func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 5;   const int inf = 1e9 + 5;   const double pi = acos(-1);   const int dx[] = {1, -1, 0, 0};   const int dy[] = {0, 0, 1, -1};   const int mod = 1e9 + 7;   int p[N], cnt[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     string s;     cin >> s;     int n = (int)(s).size();     memset(p, 0, sizeof p);     for (int i = 1; i < n; i++) {       int prev = p[i - 1];       while (prev > 0 && s[prev] != s[i]) prev = p[prev - 1];       if (s[prev] == s[i]) prev++;       p[i] = prev;     }     if (p[n - 1] == 0) {       if (p[p[n - 1] - 1] == 0) {         cout <<  Just a legend ;       } else {         cout << s.substr(0, p[p[n - 1] - 1]);       }     } else {       int cnt = 0;       for (int i = 0; i < n; i++) {         if (p[i] == p[n - 1]) {           ++cnt;         }       }       if (cnt >= 2) {         cout << s.substr(0, p[n - 1]);       } else {         if (p[p[n - 1] - 1] == 0) {           cout <<  Just a legend ;         } else {           cout << s.substr(0, p[p[n - 1] - 1]);         }       }     }     return 0;   }   