import java.util.Scanner; public class Talent { /* The input strings */ private static String s1, s2; /* Z[i] denotes the length of the longest string * that starts at position i of s1 and is also a * prefix of s1. * Similarly, Y[i] is the length of the longest * string that starts at position i of s2 (note, * not s1) and is also a prefix of s1 (note, not * s2). */ private static int[] Z, Y; /* Fills up the Y array */ private static void computeY() { Y = new int[s2.length()]; int r = 0, l = 0; for(int i = 0; i < Y.length; i++) { if (i >= r) { int j = 0; int k = i; while(j < s1.length() && k < s2.length() && s1.charAt(j) == s2.charAt(k)) { j++; k++; } l = i; r = k; Y[i] = r - l; } else { int t = i - l; if (Z[t] < r-i) { Y[i] = Z[t]; } else { int j = r - i; int k = r; while(j < s1.length() && k < s2.length() && s1.charAt(j) == s2.charAt(k)) { j++; k++; } l = i; r = k; Y[i] = r - l; } } } } /* Fills up the Z array */ private static void computeZ() { Z = new int[s1.length()]; int r = 0, l = 0; for(int i = 1; i < Z.length; i++) { if (i >= r) { int j = 0; int k = i; while(k < s1.length() && s1.charAt(j) == s1.charAt(k)) { j++; k++; } l = i; r = k; Z[i] = r - l; } else { int t = i - l; if (Z[t] < r-i) { Z[i] = Z[t]; } else { int j = r - i; int k = r; while(k < s1.length() && s1.charAt(j) == s1.charAt(k)) { j++; k++; } l = i; r = k; Z[i] = r - l; } } } } /* Finds the length of the longest string that * is a prefix of s1 and suffix of s2. */ private static int solve() { computeZ(); computeY(); for(int i = 0; i < Y.length; i++) { if (Y[i] == Y.length - i) { return Y[i]; } } return 0; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); s1 = sc.next(); s2 = sc.next(); int len = solve(); if (len > 0) System.out.print(s1.substring(0, len)+" "); System.out.println(len); } }