#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
inline bool mina(A &x, B y) {
  return (x > y) ? (x = y, 1) : 0;
}
template <class A, class B>
inline bool maxa(A &x, B y) {
  return (x < y) ? (x = y, 1) : 0;
}
template <class T>
class Matrix {
 public:
  vector<vector<T> > mat;
  int N, M;
  Matrix(int n, int m) {
    N = n;
    M = m;
    mat = vector<vector<T> >(N);
    for (int i = 0; i < N; i++) mat[i] = vector<T>(M);
  }
  Matrix mult(const Matrix &a) {
    assert(M == a.N);
    Matrix ret = Matrix(N, a.M);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < a.M; j++) {
        ret.mat[i][j] = 0;
        for (int k = 0; k < M; k++) {
          if (mat[i][k] == 0 || a.mat[k][j] == 0) continue;
          maxa(ret.mat[i][j], mat[i][k] + a.mat[k][j]);
        }
      }
    }
    return ret;
  }
  Matrix power(long long ex) {
    assert(N == M);
    bool first = true;
    Matrix ret(1, 1), b = *this;
    while (ex) {
      if (ex & 1) {
        if (first) {
          ret = b;
          first = false;
        } else {
          ret = ret.mult(b);
        }
      }
      b = b.mult(b);
      ex >>= 1;
    }
    return ret;
  }
  Matrix identity(int n) {
    Matrix ret = Matrix(n, n);
    for (int i = 0; i < n; i++) ret.mat[i][i] = 1;
    return ret;
  }
  void print() {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        cout << mat[i][j] << " ";
      }
      cout << endl;
    }
  }
};
int N, T;
int in[(105) * 2];
int dp[(105) * 2];
int dp2[(105) * 2];
int A[(105)][(105) * 2];
int main() {
  scanf("%d %d", &N, &T);
  for (int(i) = 0; (i) < (N); ++(i)) {
    scanf("%d", &in[i]);
    in[i + N] = in[i];
  }
  for (int(i) = 0; (i) < (N); ++(i)) {
    dp2[i] = 1;
    for (int(j) = 0; (j) < (i); ++(j)) {
      if (in[i] >= in[j]) {
        maxa(dp2[i], dp2[j] + 1);
      }
    }
  }
  if (T == 1) {
    int ans = 1;
    for (int(i) = 0; (i) < (N); ++(i)) maxa(ans, dp2[i]);
    printf("%d\n", ans);
    return 0;
  }
  for (int(i) = 0; (i) < (N); ++(i)) {
    dp[i] = 1;
    A[i][i] = 1;
    for (int j = i + 1; j < 2 * N; j++) {
      dp[j] = 0;
      for (int k = j - 1; k >= i; k--) {
        if (in[j] >= in[k] && dp[k]) maxa(dp[j], dp[k] + 1);
      }
      if (dp[j]) {
        if (j >= N) {
          A[i][j - N] = dp[j] - 1;
        } else {
          A[i][j] = dp[j] - 1;
        }
      }
    }
  }
  Matrix<int> M(N, N);
  for (int(i) = 0; (i) < (N); ++(i)) {
    for (int(j) = 0; (j) < (N); ++(j)) {
      M.mat[i][j] = A[i][j];
    }
  }
  Matrix<int> temp(1, 1);
  M = M.power(T - 1);
  int ans = 0;
  for (int(i) = 0; (i) < (N); ++(i)) {
    for (int(j) = 0; (j) < (N); ++(j)) {
      if (M.mat[i][j]) {
        maxa(ans, M.mat[i][j] + dp2[i]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

### Prompt

Please provide a Cpp coded solution to the problem described below:

You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array.

Input

The first line contains two space-separated integers: n, T (1 ≤ n ≤ 100, 1 ≤ T ≤ 107). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 300).

Output

Print a single number — the length of a sought sequence.

Examples

Input

4 3
3 1 4 2


Output

5

Note

The array given in the sample looks like that: 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
inline bool mina(A &x, B y) {
  return (x > y) ? (x = y, 1) : 0;
}
template <class A, class B>
inline bool maxa(A &x, B y) {
  return (x < y) ? (x = y, 1) : 0;
}
template <class T>
class Matrix {
 public:
  vector<vector<T> > mat;
  int N, M;
  Matrix(int n, int m) {
    N = n;
    M = m;
    mat = vector<vector<T> >(N);
    for (int i = 0; i < N; i++) mat[i] = vector<T>(M);
  }
  Matrix mult(const Matrix &a) {
    assert(M == a.N);
    Matrix ret = Matrix(N, a.M);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < a.M; j++) {
        ret.mat[i][j] = 0;
        for (int k = 0; k < M; k++) {
          if (mat[i][k] == 0 || a.mat[k][j] == 0) continue;
          maxa(ret.mat[i][j], mat[i][k] + a.mat[k][j]);
        }
      }
    }
    return ret;
  }
  Matrix power(long long ex) {
    assert(N == M);
    bool first = true;
    Matrix ret(1, 1), b = *this;
    while (ex) {
      if (ex & 1) {
        if (first) {
          ret = b;
          first = false;
        } else {
          ret = ret.mult(b);
        }
      }
      b = b.mult(b);
      ex >>= 1;
    }
    return ret;
  }
  Matrix identity(int n) {
    Matrix ret = Matrix(n, n);
    for (int i = 0; i < n; i++) ret.mat[i][i] = 1;
    return ret;
  }
  void print() {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        cout << mat[i][j] << " ";
      }
      cout << endl;
    }
  }
};
int N, T;
int in[(105) * 2];
int dp[(105) * 2];
int dp2[(105) * 2];
int A[(105)][(105) * 2];
int main() {
  scanf("%d %d", &N, &T);
  for (int(i) = 0; (i) < (N); ++(i)) {
    scanf("%d", &in[i]);
    in[i + N] = in[i];
  }
  for (int(i) = 0; (i) < (N); ++(i)) {
    dp2[i] = 1;
    for (int(j) = 0; (j) < (i); ++(j)) {
      if (in[i] >= in[j]) {
        maxa(dp2[i], dp2[j] + 1);
      }
    }
  }
  if (T == 1) {
    int ans = 1;
    for (int(i) = 0; (i) < (N); ++(i)) maxa(ans, dp2[i]);
    printf("%d\n", ans);
    return 0;
  }
  for (int(i) = 0; (i) < (N); ++(i)) {
    dp[i] = 1;
    A[i][i] = 1;
    for (int j = i + 1; j < 2 * N; j++) {
      dp[j] = 0;
      for (int k = j - 1; k >= i; k--) {
        if (in[j] >= in[k] && dp[k]) maxa(dp[j], dp[k] + 1);
      }
      if (dp[j]) {
        if (j >= N) {
          A[i][j - N] = dp[j] - 1;
        } else {
          A[i][j] = dp[j] - 1;
        }
      }
    }
  }
  Matrix<int> M(N, N);
  for (int(i) = 0; (i) < (N); ++(i)) {
    for (int(j) = 0; (j) < (N); ++(j)) {
      M.mat[i][j] = A[i][j];
    }
  }
  Matrix<int> temp(1, 1);
  M = M.power(T - 1);
  int ans = 0;
  for (int(i) = 0; (i) < (N); ++(i)) {
    for (int(j) = 0; (j) < (N); ++(j)) {
      if (M.mat[i][j]) {
        maxa(ans, M.mat[i][j] + dp2[i]);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}

```