input: 
  def lcs(X, Y): 
      # find the length of the strings 
      m = len(X) 
      n = len(Y) 
  
      # declaring the array for storing the dp values 
      L = [[None]*(n+1) for i in range(m+1)] 
  
      # Following steps to build L[m+1][n+1] in bottom up manner 
      for i in range(m+1): 
          for j in range(n+1): 
              if i == 0 or j == 0 : 
                  L[i][j] = 0
              elif X[i-1] == Y[j-1]: 
                  L[i][j] = L[i-1][j-1]+1
              else: 
                  L[i][j] = max(L[i-1][j] , L[i][j-1]) 
  
      # L[m][n] contains the length of LCS of X[0..n-1] & Y[0..m-1] 
      return L[m][n] 
  
  # Driver program 
  X = "ABACEDF"
  Y = "ABDCF"
  
  print("Length of LCS is ", lcs(X, Y))
  
  Example:
  
  lcs("ABACEDF", "ABDCF") == 4
  
output:     
      # To find the LCS string, we need to backtrack from L[m][n]
      lcs_str = ""
      i, j = m, n
      while i > 0 and j > 0:
          if X[i-1] == Y[j-1]:
              lcs_str = X[i-1] + lcs_str
              i -= 1
              j -= 1
          elif L[i-1][j] > L[i][j-1]:
              i -= 1
          else:
              j -= 1
  
      return lcs_str
  
  # Driver program 
  X = "ABACEDF"
  Y = "ABDCF"
  
  print("Length of LCS is ", lcs(X, Y))
  print("LCS is ", lcs(X, Y))
  