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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class B {    
    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

    int UNDEF = -1;
    public void solve() throws IOException {                
      char[] s1 = reader.readLine().toCharArray();
      char[] s2 = reader.readLine().toCharArray();
      char[] vi = reader.readLine().toCharArray();
      
      int[][] A = build_automaton(vi);
      int[][][] dp = new int[s1.length+1][s2.length+1][vi.length+1];
      for(int i = 0; i <= s1.length; i++)
        for(int j = 0; j <= s2.length; j++)
          Arrays.fill(dp[i][j], UNDEF);
      
      int[][][] trace = new int[s1.length+1][s2.length+1][vi.length+1];
      int[][][] trace_k = new int[s1.length+1][s2.length+1][vi.length+1];
      dp[0][0][0] = 0;
      for(int i = 0; i < s1.length; i++){
        for(int j = 0; j < s2.length; j++){
          for(int k = 0; k < vi.length; k++){
            if(dp[i][j][k] == UNDEF) continue;
            if (s1[i] == s2[j]){
              if( dp[i+1][j+1][ A[k][s1[i]-'A'] ] < dp[i][j][k] + 1){
                dp[i+1][j+1][ A[k][s1[i]-'A'] ] = dp[i][j][k] + 1;
                trace[i+1][j+1][ A[k][s1[i]-'A'] ] = 1;
                trace_k[i+1][j+1][ A[k][s1[i]-'A'] ] = k;
              }              
            }
            
            if( dp[i+1][j][k] < dp[i][j][k]){
              dp[i+1][j][k] = dp[i][j][k];
              trace[i+1][j][k] = 2;
            }
            
            if( dp[i][j+1][k] < dp[i][j][k]){
              dp[i][j+1][k] = dp[i][j][k];
              trace[i][j+1][k] = 3;
            }
            
          }
        }
      }      
      
      int ans = 0;
      int ans_i = -1;
      int ans_j = -1;
      int ans_k = -1;
      for(int i = 0; i <= s1.length; i++){
        for(int j = 0; j <= s2.length; j++){
          for(int k = 0; k < vi.length; k++){
            if( dp[i][j][k] > ans){
              ans = dp[i][j][k];
              ans_i = i;
              ans_j = j;
              ans_k = k;
            }        
          }
        }
      }     
      if(ans == 0){
        out.println(0); return;
      }
      Stack<Character> aa = new Stack<Character>();
      while(true){
        if(trace[ans_i][ans_j][ans_k] == 1){
          aa.add(s1[ans_i-1]);
          ans_k = trace_k[ans_i][ans_j][ans_k];
          ans_i--;
          ans_j--;          
        }
        else if(trace[ans_i][ans_j][ans_k] == 2){
          ans_i--;          
        }
        else if(trace[ans_i][ans_j][ans_k] == 3){
          ans_j--;
        }
        if(ans_i == 0 && ans_j == 0 && ans_k == 0) break;
      }
      
      while(!aa.isEmpty()){
        out.print(aa.pop());
      }      
      out.println();
    }
    
    
    /*
     *  A[i][j]:  0-index, at position i, the character j will move to position A[i][j]
     *  e.g.  pattern = ABAB  
     *  A[0][A] = 1;
     *  A[0][B] = 0;
     *  ...
     *  
     *  A[1][A] = 1;
     *  A[1][B] = 2;
     *  ...
     */
    public int[][] build_automaton(char[] pattern){
      int[][] A = new int[pattern.length][26];
      int[] F = build_failure(pattern);
      
      for(int i = 0; i < pattern.length; i++){
        for(int j = 0; j < 26; j++){
          if( pattern[i]-'A' == j){
            A[i][j] = i+1;
          }
          else{
            if( i > 0)
              A[i][j] = A[F[i]][j]; // F has an extra 0 for (empty)
            else
              A[i][j] = 0;
          }
        }
      }
      
      return A;
    }
    
    /*
     * e.g. pattern = ABABC
     * F[0]: (empty) = 0 
     * F[1]: A = 0
     * F[2]: AB = 0
     * F[3]: ABA = 1  
     * F[4]: ABAB = 2
     * F[5]: ABABC = 0
     */
    public int[] build_failure(char[] pattern){
      int[] F = new int[pattern.length+1];
      F[0] = 0;
      F[1] = 0;
      for(int i = 2; i <= pattern.length; i++){
        int j = F[i-1];
        while(true){
          if(pattern[j] == pattern[i-1]){
            F[i] = j+1; break;
          }
          if(j == 0){
            F[i] = 0; break;
          }
          j = F[j];          
        }
      }      
//      for(int i = 0 ; i <= pattern.length; i++){
//        out.println( i + ": " + F[i]);
//      }      
      return F;
    }
            
    /**
     * @param args
     */
    public static void main(String[] args) {
        new B().run();
    }
    
    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            out = new PrintWriter(System.out);
            solve();
            reader.close();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}