Problem:
Score : 1200 points

Problem Statement

There are N arrays.
The length of each array is M and initially each array contains integers (1，2，...，M) in this order.

Mr. Takahashi has decided to perform Q operations on those N arrays.
For the i-th (1≤i≤Q) time, he performs the following operation.

Choose an arbitrary array from the N arrays and move the integer a_i (1≤a_i≤M) to the front of that array. For example, after performing the operation on a_i=2 and the array (5，4，3，2，1), this array becomes (2，5，4，3，1).

Mr. Takahashi wants to make N arrays exactly the same after performing the Q operations.
Determine if it is possible or not.

Constraints

2≤N≤10^5

2≤M≤10^5

1≤Q≤10^5

1≤a_i≤M

Input

The input is given from Standard Input in the following format:

N M
Q
a_1 a_2 ... a_Q

Output

Print Yes if it is possible to make N arrays exactly the same after performing the Q operations.
Otherwise, print No.

Sample Input 1

2 2
3
2 1 2

Sample Output 1

Yes

You can perform the operations as follows.

Sample Input 2

3 2
3
2 1 2

Sample Output 2

No

Sample Input 3

2 3
3
3 2 1

Sample Output 3

Yes

You can perform the operations as follows.

Sample Input 4

3 3
6
1 2 2 3 3 3

Sample Output 4

No

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class ELRU {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, m, q; cin >> n >> m >> q;
      vector<int> a(q);
      rep(i, q) {
        cin >> a[i];
      }
      reverse(all(a));
      // value, pos
      map<int, int> used;
      vector<int> cnt;
      vector<int> rev;
      rep(i, q) {
        if (used.find(a[i]) == used.end()) {
          used[a[i]] = cnt.size();
          cnt.push_back(1);
          rev.push_back(a[i]);
        } else {
          int pos = used[a[i]];
          if (pos == 0 || cnt[pos-1] > cnt[pos]) {
            cnt[pos]++;
          }
        }
      }

      bool flag = true;
      bool foundone = false;
      set<int> st;
      for(int i=1; i<=m; i++) {
        st.insert(i);
      }
      for(int i=0; i<cnt.size(); i++) {
        if (rev[i] == 1) foundone = true;
        if (!foundone) {
          if (cnt[i] < n) {
            flag = false;
            break;
          }
          st.erase(rev[i]);
        } else {
          if (rev[i] == *st.begin()) {
            st.erase(st.begin());
            continue;
          }
          flag = false;
          break;
        }
      }
      if (flag) {
        cout << "Yes" << endl;
        return;
      }

      flag = true;
      for(int i=0; i<cnt.size(); i++) {
        if (cnt[i] >= n) continue;
        flag = false;
        break;
      }
      cout << (flag ? "Yes" : "No") << endl;
    }
};

signed main() {
  ELRU solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}