import java.io.*; import java.util.*; public class subseq { public static final Scanner cin = new Scanner(System.in); public static void main(String[] args) { while(true) { String s = cin.nextLine(); if(s.equals("#END")) { break; } System.out.println(Solver.solve(s)); } } private static class Solver { private String str; private static final int DIR_H = 1; private static final int DIR_V = 2; private static final int DIR_D = 3; // diagonal private Solver(String str) { this.str = str; } private static String lcs(String s, String t) { int m = s.length(); int n = t.length(); int[][] num = new int[m+1][n+1]; int[][] dir = new int[m+1][n+1]; for(int i = 1; i <= m; i++) { for(int j = 1; j <= n; j++) { num[i][j] = -1; dir[i][j] = 0; if(num[i][j] < num[i-1][j]) { num[i][j] = num[i-1][j]; dir[i][j] = DIR_H; } if(num[i][j] < num[i][j-1]) { num[i][j] = num[i][j-1]; dir[i][j] = DIR_V; } if(s.charAt(i-1) == t.charAt(j-1)) { if(num[i][j] < num[i-1][j-1] + 1) { num[i][j] = num[i-1][j-1] + 1; dir[i][j] = DIR_D; } } } } StringBuilder sb = new StringBuilder(); { int i = m; int j = n; while(i > 0 && j > 0) { switch(dir[i][j]) { case DIR_H: i--; break; case DIR_V: j--; break; case DIR_D: i--; j--; sb.append(s.charAt(i)); break; } } } sb.reverse(); return sb.toString(); } private String solve() { String ans = ""; for(int i = 1; i < str.length(); i++) { String tmp = lcs(str.substring(0, i), str.substring(i)); if(ans.length() < tmp.length()) { ans = tmp; } } return ans; } public static String solve(String str) { return new Solver(str).solve(); } } }