import java.io.PrintWriter; import java.util.Scanner; public class string_lewin { public static int N, K; public static int off; public static char[] c; public static void main (String[] args) { Scanner in = new Scanner (System.in); PrintWriter out = new PrintWriter(System.out, true); c = in.next().toCharArray(); N = c.length; for (K = 1; K <= N; K++) { // O(N^3 * sum of divisors of N) = O(N^4) if (N % K != 0) continue; // K is the length of my string String best = null; for (off = 0; off + K <= N; off++) { // O(N^4/K) seen = new boolean[N][N/K+1][K+1]; dp = new boolean[N][N/K+1][K+1]; if (generatable(0, N/K, 0)) { // O(N^3/K) String cand = new String(c, off, K); if (best == null || cand.compareTo(best) < 0) best = cand; } } if (best != null) { out.println(best); out.close(); System.exit(0); } } // shouldn't ever reach here, since the entire string generates itself by default. throw new RuntimeException(); } public static boolean[][][] seen, dp; // O(N*(N/K)*K) = O(N^2) states, each of which takes O(N/K) time to compute, so runtime is O(N^3/K) public static boolean generatable(int s, int copies, int curletter) { if (copies == 0) return true; if (curletter == K) return generatable(s, copies - 1, 0); if (seen[s][copies][curletter]) return dp[s][copies][curletter]; seen[s][copies][curletter] = true; // I can match this character boolean ok = c[curletter + off] == c[s] && generatable(s+1, copies, curletter+1); // I can skip some generatable substrings in between for (int times = 1; !ok && times < copies; times++) { ok |= generatable(s, times, 0) && generatable(s + times * K, copies - times, curletter); } return dp[s][copies][curletter] = ok; } }