Language: C++

/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.4.0"
+/

import std.stdio, std.algorithm, std.conv;

// import dcomp.scanner;
// import dcomp.container.deque;

int main() {
    auto sc = new Scanner(stdin);
    int n, m, q;
    int[] a;
    sc.read(n, m, q, a);

    bool solve() {
        int[] co, idx = new int[m]; idx[] = -1;

        int l = 0;
        foreach_reverse (d; a) {
            d--;
            int u = idx[d];
            if (u == -1) {
                u = idx[d] = co.length.to!int;
                co ~= 0;
            }
            if (u && co[u-1] == co[u]) {
                return false;
            }
            co[u]++;
            if (co[u] == n) {
                l++;
                idx[d] = -1;
            }
        }
        foreach (i; 0..m) {
            if (idx[i] == -1) continue;
            if (idx[i]-l != i) return false;
        }
        return true;
    }

    if (solve()) {
        writeln("Yes");
    } else {
        writeln("No");
    }
    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/container/deque.d */
// module dcomp.container.deque;

struct Deque(T) {
    import core.exception : RangeError;
    import core.memory : GC;
    import std.range : ElementType, isInputRange;
    import std.traits : isImplicitlyConvertible;

    struct Payload {
        T *d;
        size_t st, length, cap;
        @property bool empty() const { return length == 0; }
        alias opDollar = length;
        ref inout(T) opIndex(size_t i) inout {
            version(assert) if (length <= i) throw new RangeError();
            return d[(st+i >= cap) ? (st+i-cap) : st+i];
        }
        private void expand() {
            import std.algorithm : max;
            assert(length == cap);
            auto nc = max(4L, 2*cap);
            T* nd = cast(T*)GC.malloc(nc * T.sizeof);
            foreach (i; 0..length) {
                nd[i] = this[i];
            }
            d = nd; st = 0; cap = nc;
        }
        void insertFront(T v) {
            if (length == cap) expand();
            if (st == 0) st += cap;
            st--; length++;
            this[0] = v; 
        }
        void insertBack(T v) {
            if (length == cap) expand();
            length++;
            this[length-1] = v; 
        }
        void removeFront() {
            assert(!empty, "Deque.removeFront: Deque is empty");        
            st++; length--;
            if (st == cap) st = 0;
        }
        void removeBack() {
            assert(!empty, "Deque.removeBack: Deque is empty");        
            length--;
        }        
    }
    struct RangeT(A) {
        alias T = typeof(*(A.p));
        alias E = typeof(A.p.d[0]);
        T *p;
        size_t a, b;
        @property bool empty() const { return b <= a; }
        @property size_t length() const { return b-a; }
        @property RangeT save() { return RangeT(p, a, b); }
        @property RangeT!(const A) save() const {
            return typeof(return)(p, a, b);
        }
        alias opDollar = length;
        @property ref inout(E) front() inout { return (*p)[a]; }
        @property ref inout(E) back() inout { return (*p)[b-1]; }
        void popFront() {
            version(assert) if (empty) throw new RangeError();
            a++;
        }
        void popBack() {
            version(assert) if (empty) throw new RangeError();
            b--;
        }
        ref inout(E) opIndex(size_t i) inout { return (*p)[i]; }
        RangeT opSlice() { return this.save; }
        RangeT opSlice(size_t i, size_t j) {
            version(assert) if (i > j || a + j > b) throw new RangeError();
            return typeof(return)(p, a+i, a+j);
        }
        RangeT!(const A) opSlice() const { return this.save; }
        RangeT!(const A) opSlice(size_t i, size_t j) const {
            version(assert) if (i > j || a + j > b) throw new RangeError();
            return typeof(return)(p, a+i, a+j);
        }
    }
    
    alias Range = RangeT!Deque;
    alias ConstRange = RangeT!(const Deque);
    alias ImmutableRange = RangeT!(immutable Deque);

    Payload *p;
    private void I() { if (!p) p = new Payload(); }
    private void C() const { assert(p, "this deque is not init"); }
    //some value
    this(U)(U[] values...) if (isImplicitlyConvertible!(U, T)) {I;
        p = new Payload();
        foreach (v; values) {
            insertBack(v);
        }
    }
    //range
    this(Range)(Range r)
    if (isInputRange!Range &&
    isImplicitlyConvertible!(ElementType!Range, T) &&
    !is(Range == T[])) {I;
        p = new Payload();
        foreach (v; r) {
            insertBack(v);
        }
    }
    
    @property bool empty() const { return (!p || p.empty); }
    @property size_t length() const { return (p ? p.length : 0); }
    alias opDollar = length;
    ref inout(T) opIndex(size_t i) inout {C; return (*p)[i]; }
    ref inout(T) front() inout {C; return (*p)[0]; }
    ref inout(T) back() inout {C; return (*p)[$-1]; }
    void insertFront(T v) {I; p.insertFront(v); }
    void insertBack(T v) {I; p.insertBack(v); }
    void removeFront() {C; p.removeFront(); }
    void removeBack() {C; p.removeBack(); }
    Range opSlice() {I; return Range(p, 0, length); }
}

unittest {
    import std.algorithm : equal;
    import std.range.primitives : isRandomAccessRange;
    import std.container.util : make;
    auto q = make!(Deque!int);
    assert(isRandomAccessRange!(typeof(q[])));

    //insert,remove
    assert(equal(q[], new int[](0)));
    q.insertBack(1);
    assert(equal(q[], [1]));
    q.insertBack(2);
    assert(equal(q[], [1, 2]));
    q.insertFront(3);
    assert(equal(q[], [3, 1, 2]) && q.front == 3);
    q.removeFront;
    assert(equal(q[], [1, 2]) && q.length == 2);
    q.insertBack(4);
    assert(equal(q[], [1, 2, 4]) && q.front == 1 && q.back == 4 && q[$-1] == 4);
    q.insertFront(5);
    assert(equal(q[], [5, 1, 2, 4]));

    //range
    assert(equal(q[][1..3], [1, 2]));
    assert(equal(q[][][][], q[]));
    //const range
    const auto rng = q[];
    assert(rng.front == 5 && rng.back == 4);
    
    //reference type
    auto q2 = q;
    q2.insertBack(6);
    q2.insertFront(7);
    assert(equal(q[], q2[]) && q.length == q2.length);

    //construct with make
    auto a = make!(Deque!int)(1, 2, 3);
    auto b = make!(Deque!int)([1, 2, 3]);
    assert(equal(a[], b[]));
}

unittest {
    Deque!int a;
    Deque!int b;
    a.insertFront(2);
    assert(b.length == 0);
}

unittest {
    import std.algorithm : equal;
    import std.range : iota;
    Deque!int a;
    foreach (i; 0..100) {
        a.insertBack(i);
    }
    assert(equal(a[], iota(100)));
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    string[] buf;
    private bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = f.readln.split;
        }
        return true;
    }
    private bool readSingle(T)(ref T x) {
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                //string or char[10] etc
                x = buf.front;
                buf.popFront;
            } else {
                static if (isStaticArray!T) {
                    //static
                    assert(buf.length == T.length);
                }
                x = buf.map!(to!E).array;
                buf.length = 0;                
            }
        } else {
            x = buf.front.to!T;
            buf.popFront;            
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

unittest {
    import std.path : buildPath;
    import std.file : tempDir;
    import std.algorithm : equal;
    import std.stdio : File;
    string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
    auto fout = File(fileName, "w");
    fout.writeln("1 2 3");
    fout.writeln("ab cde");
    fout.writeln("1.0 1.0 2.0");
    fout.close;
    Scanner sc = new Scanner(File(fileName, "r"));
    int a;
    int[2] b;
    char[2] c;
    string d;
    double e;
    double[] f;
    sc.read(a, b, c, d, e, f);
    assert(a == 1);
    assert(equal(b[], [2, 3]));
    assert(equal(c[], "ab"));
    assert(equal(d, "cde"));
    assert(e == 1.0);
    assert(equal(f, [1.0, 2.0]));
}


Compiler output:
a.cc:37:21: error: too many decimal points in number
   37 |         foreach (i; 0..m) {
      |                     ^~~~
a.cc:63:9: error: stray '@' in program
   63 |         @property bool empty() const { return length == 0; }
      |         ^
a.cc:74:25: error: too many decimal points in number
   74 |             foreach (i; 0..length) {
      |                         ^~~~~~~~~
a.cc:105:9: error: stray '@' in program
  105 |         @property bool empty() const { return b <= a; }
      |         ^
a.cc:106:9: error: stray '@' in program
  106 |         @property size_t length() const { return b-a; }
      |         ^
a.cc:107:9: error: stray '@' in program
  107 |         @property RangeT save() { return RangeT(p, a, b); }
      |         ^
a.cc:108:9: error: stray '@' in program
  108 |         @property RangeT!(const A) save() const {
      |         ^
a.cc:112:9: error: stray '@' in program
  112 |         @property ref inout(E) front() inout { return (*p)[a]; }
      |         ^
a.cc:113:9: error: stray '@' in program
  113 |         @property ref inout(E) back() inout { return (*p)[b-1]; }
      |         ^
a.cc:160:5: error: stray '@' in program
  160 |     @property bool empty() const { return (!p || p.empty); }
      |     ^
a.cc:161:5: error: stray '@' in program
  161 |     @property size_t length() const { return (p ? p.length : 0); }
      |     ^
a.cc:196:22: error: too many decimal points in number
  196 |     assert(equal(q[][1..3], [1, 2]));
      |                      ^~~~
a.cc:225:17: error: too many decimal points in number
  225 |     foreach (i; 0..100) {
      |                 ^~~~~~
a.cc:1:1: error: expected unqualified-id before '/' token
    1 | /+ dub.sdl:
      | ^
a.cc: In function 'int main()':
a.cc:12:19: error: expected type-specifier before 'Scanner'
   12 |     auto sc = new Scanner(stdin);
      |                   ^~~~~~~
a.cc:14:8: error: structured binding declaration cannot have type 'int'
   14 |     int[] a;
      |        ^~
a.cc:14:8: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
a.cc:14:8: error: empty structured binding declaration
a.cc:14:11: error: expected initializer before 'a'
   14 |     int[] a;
      |           ^
a.cc:15:22: error: 'a' was not declared in this scope
   15 |     sc.read(n, m, q, a);
      |                      ^
a.cc:17:15: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   17 |     bool solve() {
      |               ^~
a.cc:17:15: note: remove parentheses to default-initialize a variable
   17 |     bool solve() {
      |               ^~
      |               --
a.cc:17:15: note: or replace parentheses with braces to value-initialize a variable
a.cc:17:18: error: a function-definition is not allowed here before '{' token
   17 |     bool solve() {
      |                  ^
a.cc:44:9: error: 'solve' was not declared in this scope
   44 |     if (solve()) {
      |         ^~~~~
a.cc:45:9: error: 'writeln' was not declared in this scope
   45 |         writeln("Yes");
      |         ^~~~~~~
a.cc:47:9: error: 'writeln' was not declared in this scope
   47 |         writeln("No");
      |         ^~~~~~~
a.cc: At global scope:
a.cc:54:15: error: variable 'Deque T' has initializer but incomplete type
   54 | struct Deque(T) {
      |               ^
a.cc:55:5: error: 'import' was not declared in this scope
   55 |     import core.exception : RangeError;
      |     ^~~~~~
a.cc:55:12: error: expected '}' before 'core'
   55 |     import core.exception : RangeError;
      |            ^~~~
a.cc:54:17: note: to match this '{'
   54 | struct Deque(T) {
      |                 ^
a.cc:55:12: error: expected ',' or ';' before 'core'
   55 |     import core.exception : RangeError;
      |            ^~~~
a.cc:56:5: error: 'import' does not name a type
   56 |     import core.memory : GC;
      |     ^~~~~~
a.cc:56:5: note: C++20 'import' only available with '-fmodules-ts'
a.cc:57:5: error: 'import' does not name a type
   57 |     import std.range : ElementType, isInputRange;
      |     ^~~~~~
a.cc:57:5: note: C++20 'import' only available with '-fmodules-ts'
a.cc:58:5: error: 'import' does not name a type
   58 |     import std.traits : isImplicitlyConvertible;
      |     ^~~~~~
a.cc:58:5: note: C++20 'import' only available with '-fmodules-ts'
a.cc:61:9: error: 'T' does not name a type
   61 |         T *d;
      |         ^
a.cc:62:9: error: 'size_t' does not name a type
   62 |         size_t st, length, cap;
      |         ^~~~~~
a.cc:1:1: note: 'size_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>'
  +++ |+#include <cstddef>
    1 | /+ dub.sdl:
a.cc:63:10: error: 'property' does not name a type
   63 |         @property bool empty() const { return length == 0; }
      |          ^~~~~~~~
a.cc:64:9: error: 'alias' does not name a type
   64 |         alias opDollar = length;
      |         ^~~~~
a.cc:65:9: error: 'ref' does not name a type
   65 |         ref inout(T) opIndex(size_t i) inout {
      |         ^~~
a.cc:69:16: error: expected ':' before 'void'
   69 |         private void expand() {
      |                ^~~~~
      |                :
a.cc:79:26: error: 'T' is not a type
   79 |         void insertFront(T v) {
      |                          ^
a.cc:85:25: error: 'T' is not a type
   85 |         void insertBack(T v) {
      |                         ^
a.cc:99:6: error: expected ';' after struct definition
   99 |     }
      |      ^
      |      ;
a.cc: In member function 'void Payload::expand()':
a.cc:70:13: error: 'import' was not declared in this scope
   70 |             import std.algorithm : max;
      |             ^~~~~~
a.cc:71:20: error: 'length' was not declared in this scope
   71 |             assert(length == cap);
      |                    ^~~~~~
a.cc:71:30: error: 'cap' was not declared in this scope
   71 |             assert(length == cap);
      |                              ^~~
a.cc:71:13: error: 'assert' was not declared in this scope
   71 |             assert(length == cap);
      |             ^~~~~~
a.cc:1:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
  +++ |+#include <cassert>
    1 | /+ dub.sdl:
a.cc:72:23: error: 'max' was not declared in this scope
   72 |             auto nc = max(4L, 2*cap);
      |                       ^~~
a.cc:73:16: error: 'nd' was not declared in this scope
   73 |             T* nd = cast(T*)GC.malloc(nc * T.sizeof);
      |                ^~
a.cc:73:28: error: expected primary-expression before ')' token
   73 |             T* nd = cast(T*)GC.malloc(nc * T.sizeof);
      |                            ^
a.cc:73:21: error: 'cast' was not declared in this scope
   73 |             T* nd = cast(T*)GC.malloc(nc * T.sizeof);
      |                     ^~~~
a.cc:74:22: error: 'i' was not declared in this scope
   74 |             foreach (i; 0..length) {
      |                      ^
a.cc:77:13: error: 'd' was not declared in this scope
   77 |             d = nd; st = 0; cap = nc;
      |             ^
a.cc:77:21: error: 'st' was not declared in this scope; did you mean 'std'?
   77 |             d = nd; st = 0; cap = nc;
      |                     ^~
      |                     std
a.cc: In member function 'void Payload::insertFront(int)':
a.cc:80:17: error: 'length' was not declared in this scope
   80 |             if (length == cap) expand();
      |                 ^~~~~~
a.cc:80:27: error: 'cap' was not declared in this scope
   80 |             if (length == cap) expand();
      |                           ^~~
a.cc:81:17: error: 'st' was not declared in this scope; did you mean 'std'?
   81 |             if (st == 0) st += cap;
      |                 ^~
      |                 std
a.cc:81:32: error: 'cap' was not declared in this scope
   81 |             if (st == 0) st += cap;
      |                                ^~~
a.cc:82:13: error: 'st' was not declared in this scope; did you mean 'std'?
   82 |             st--; length++;
      |             ^~
      |             std
a.cc:82:19: error: 'length' was not declared in this scope
   82 |             st--; length++;
      |                   ^~~~~~
a.cc:83:23: error: no match for 'operator=' (operand types are 'Payload' and 'int')
   83 |             this[0] = v;
      |                       ^
a.cc:60:12: note: candidate: 'constexpr Payload& Payload::operator=(const Payload&)'
   60 |     struct Payload {
      |            ^~~~~~~
a.cc:60:12: note:   no known conversion for argument 1 from 'int' to 'const Payload&'
a.cc:60:12: note: candidate: 'constexpr Payload& Payload::operator=(Payload&&)'
a.cc:60:12: note:   no known conversion for argument 1 from 'int' to 'Payload&&'
a.cc: In member function 'void Payload::insertBack(int)':
a.cc:86:17: error: 'length' was not declared in this scope
   86 |             if (length == cap) expand();
      |                 ^~~~~~
a.cc:86:27: error: 'cap' was not declared in this scope
   86 |             if (length == cap) expand();
      |                           ^~~
a.cc:87:13: error: 'length' was not declared in this scope
   87 |             length++;
      |             ^~~~~~
a.cc: In member function 'void Payload::removeFront()':
a.cc:91:21: error: 'empty' was not declared in this scope
   91 |             assert(!empty, "Deque.removeFront: Deque is empty");
      |                     ^~~~~
a.cc:91:13: error: 'assert' was not declared in this scope
   91 |             assert(!empty, "Deque.removeFront: Deque is empty");
      |             ^~~~~~
a.cc:91:13: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
a.cc:92:13: error: 'st' was not declared in this scope; did you mean 'std'?
   92 |             st++; length--;
      |             ^~
      |             std
a.cc:92:19: error: 'length' was not declared in this scope
   92 |             st++; length--;
      |                   ^~~~~~
a.cc:93:23: error: 'cap' was not declared in this scope
   93 |             if (st == cap) st = 0;
      |                       ^~~
a.cc: In member function 'void Payload::r