[UVA1262] Password

Source: Internet
Author: User

Password

Description

Asterix, Obelix and their temporary buddies Suffix and Prefix have finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.

A little later they found a string s, carved on a rock below the temple ' s gates. Asterix supposed that's the password that opens the temple and the read the string aloud. However, nothing happened. Then Asterix supposed, a password is some substring t of the string s.

Prefix supposed the substring T is the beginning of the string s; Suffix supposed that the substring T should is the end of the string s; And Obelix supposed that T should was located somewhere inside the string s, that's, T is n Either its beginning, nor its end.

Asterix chose the substring T as to the "all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring t aloud, the temple doors opened.

You know the string s. Find the substring t or determine that such substring does isn't exist and all that's been written above is just a Nice legend.

Input

You is given the string s whose length can vary from 1 to 6 (inclusive), consisting of small Latin letters.

Output

Print the string t. If a suitable t string does not exist and then print "Just a legend" without the quotes.

Sample Input

Input
Fixprefixsuffix
Output
Fix
Input
Abcdabc
Output
Just a legend

Sample Output

Case 1:13case 2:6

Hint

Find out if there is a string in the string with the same prefix, the KMP pre array is applied

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <algorithm>5#include <iostream>6#include <cmath>7#include <queue>8#include <map>9#include <stack>Ten#include <list> One#include <vector> A  - using namespacestd; -  the Const intMAXN =1000010; - intnb; - CharB[MAXN]; - intPRE[MAXN]; + intVIS[MAXN]; -  + //B is the pattern string, a is the target string A voidGetpre (Char*b,int*pre) { at     intJ, K; -pre[0] = -1; -j =0; -K =-1; -      while(J <nb) { -         if(k = =-1|| B[J] = =B[k]) { inJ + +; -k++; toPRE[J] =K; +         } -         Else { theK =Pre[k]; *         } $     }Panax Notoginseng } -  the intMain () { +     //freopen ("in", "R", stdin); A      while(~SCANF ("%s", B)) { thememset (PRE,0,sizeof(pre)); +memset (Vis,0,sizeof(Vis)); -NB =strlen (b); $         if(NB <3) { $printf"Just a legend\n"); -             Continue; -         } the Getpre (b, pre); -          for(inti =0; I < NB; i++) {WuyiVis[pre[i]] =1; the         } -         intFlag =0; Wu          while(Pre[nb]) { -             if(VIS[PRE[NB]]) { Aboutprintf"%.*s\n", PRE[NB], b); $Flag =1; -                  Break; -             } -NB =PRE[NB]; A         } +         if(!flag) { theprintf"Just a legend\n"); -         } $     } the     return 0; the}

[UVA1262] Password

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.