#include <vector>
#include <iostream>
#include <algorithm>
#include <cstring>

#define ENABLE_LCS
#define ENABLE_LIS
#define ENABLE_MAIN

#ifdef ENABLE_LCS
namespace lcs {
  constexpr auto N = 50, M = 50;
  int dp[N + 1][M + 1];

  template <typename Iterable> int lcs(Iterable a, Iterable b) {
    memset(dp, sizeof(dp), 0);
    auto n = a.size();
    auto m = b.size();
    for (auto i = 0; i < n; ++i) for (auto j = 0; j < m; ++j) {
        dp[i + 1][j + 1] = a[i] == b[j] ? dp[i][j] + 1 : std::max(dp[i][j + 1], dp[i + 1][j]);
    }
    return dp[n][m];
  }
}
#endif

#ifdef ENABLE_LIS
namespace lis {
  constexpr auto N = 50;
  int INF = 2000000001;
  int dp[N];

  int lis(std::vector<int> a) {
    auto n = a.size();
    for (auto &i: dp) i = INF;
    for (auto i = 0; i < n; ++i) {
      *std::lower_bound(dp, dp + N, a[i]) = a[i];
    }
    return std::lower_bound(dp, dp + N, INF) - dp;
  }
}
#endif

#ifdef ENABLE_MAIN
int main() {
  std::string x = "XMJYAUZ", y = "MZJAWXU";
  std::cout << lcs::lcs(x, y) << " should be 4" << std::endl;

  std::vector<int> a = {0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15};
  std::cout << lis::lis(a) << " should be 6" << std::endl;
  return 0;
}
#endif