Problem: In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substring of ABCDEF.

You are given two strings s1, s2 and another string called virus. Your task is to find the longest common subsequence of s1 and s2, such that it doesn't contain virus as a substring.

Input

The input contains three strings in three separate lines: s1, s2 and virus (1 ≤ |s1|, |s2|, |virus| ≤ 100). Each string consists only of uppercase English letters.

Output

Output the longest common subsequence of s1 and s2 without virus as a substring. If there are multiple answers, any of them will be accepted. 

If there is no valid common subsequence, output 0.

Examples

Input

AJKEQSLOBSROFGZ
OVGURWZLWVLUXTH
OZ


Output

ORZ


Input

AA
A
A


Output

0

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
 
import static java.lang.Math.*;

public class Main implements Runnable {
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }
        
        public int read() {
            if (numChars==-1) 
                throw new InputMismatchException();
            
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }
                
                if(numChars <= 0)               
                    return -1;
            }
            return buf[curChar++];
        }
     
        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();
            
            while(isSpaceChar(c)) 
                c = read();
            
            int sgn = 1;
            
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            
            int res = 0;
            do {
                if(c<'0'||c>'9') 
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c)); 
            
            return res * sgn;
        }
        
        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }
        
        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }
        
        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } 
            while (!isSpaceChar(c));
            
            return res.toString();
        }
     
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
     
        public String next() {
            return readString();
        }
        
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Main(),"Main",1<<26).start();
    }
    public void run() {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        char[] virus = sc.next().toCharArray();

        int n = s.length;
        int m = t.length;
        int k = virus.length;

        int dp[][][] = new int[n + 1][m + 1][k + 1];
        // for(int i = 0; i <= n; ++i) {
        //     for(int j = 0; j <= m; ++j) {
        //         for(int l = 0; l <= k; ++l)
        //             dp[i][j][l] = -1;
        //     }
        // }

        int prevInd[][] = new int[k + 1][26];

        for(int i = 0; i <= k; ++i) {
            for(int j = 0; j < 26; ++j) {
                prevInd[i][j] = 0;
                for(int l = 0; l < i; ++l) {
                    if(virus[l] == (char)('A' + j)) {
                        int flag = 0;
                        int offset = i - l;
                        for(int p = l - 1; p >= 0; --p) {
                            if(virus[p] != virus[p + offset])
                                flag = 1;
                        }
                        if(flag == 0)
                            prevInd[i][j] = l + 1;
                    }
                }
            }
        }

        Pair par[][][] = new Pair[n + 1][m + 1][k + 1];

        for(int i = 1; i <= n; ++i) {
            for(int j = 1; j <= m; ++j) {
                for(int l = 0; l <= k; ++l) {
                    if(dp[i - 1][j][l] > dp[i][j][l]) {
                        dp[i][j][l] = dp[i - 1][j][l];
                        par[i][j][l] = new Pair(i - 1, j, l);
                    }
                    if(dp[i][j - 1][l] > dp[i][j][l]) {
                        dp[i][j][l] = dp[i][j - 1][l];
                        par[i][j][l] = new Pair(i, j - 1, l);
                    }
                }

                if(s[i - 1] == t[j - 1]) {
                    for(int l = 0; l < k; ++l) {
                        //if(dp[i - 1][j - 1][l] != -1) {
                        if(s[i - 1] == virus[l]) {
                            if(dp[i][j][l + 1] < dp[i - 1][j - 1][l] + 1) {
                                dp[i][j][l + 1] = dp[i - 1][j - 1][l] + 1;
                                par[i][j][l + 1] = new Pair(i - 1, j - 1, l, true);
                            }
                        }
                        else {
                            int curInd = prevInd[l][s[i - 1] - 'A'];
                            if(dp[i][j][curInd] < dp[i - 1][j - 1][l] + 1) {
                                dp[i][j][curInd] = dp[i - 1][j - 1][l] + 1;
                                par[i][j][curInd] = new Pair(i - 1, j - 1, l, true);
                            }       
                        }       
                        //}
                    }
                }
            }
        }

        int cur_i = n, cur_j = m, cur_l = 0; 
        for(int i = 1; i < k; ++i) {
            if(dp[n][m][i] > dp[n][m][cur_l]) {
                cur_l = i;
            }
        }

        if(dp[n][m][cur_l] == 0)
            w.print("0");
        else {
            ArrayList<Character> ans = new ArrayList<>();
            while(par[cur_i][cur_j][cur_l] != null) {
                if(par[cur_i][cur_j][cur_l].print)
                    ans.add(s[cur_i - 1]);
                Pair cur = par[cur_i][cur_j][cur_l];
                cur_i = cur.i;
                cur_j = cur.j;
                cur_l = cur.k;
            }
            for(int i = ans.size() - 1; i >= 0; --i)
                w.print(ans.get(i));
        }

        w.close();   
    }
}
class Pair {
    int i, j, k;
    boolean print;
    Pair(int a, int b, int c, boolean d) {
        i = a;
        j = b;
        k = c;
        print = d;
    }
    Pair(int a, int b, int c) {
        i = a;
        j = b;
        k = c;
        print = false;
    }
}