#include "testlib.h"
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
    setName("Triplet Popcount Array checker");
    registerTestlibCmd(argc, argv);

    const int n = inf.readInt();
    const int m = inf.readInt();
    const long long k = inf.readLong();

    // Compatible with BOTH kinds of official answer files:
    // 1) marker only: -1 / 0
    // 2) a full standard construction: -1 / a_1 ... a_n
    // Since every legal a_i >= 0, the first token is -1 iff jury says impossible.
    const long long juryFirst = ans.readLong();
    const bool feasible = (juryFirst != -1);
    // Do NOT call ans.readEof(): a normal standard output may contain n integers.

    const long long first = ouf.readLong();

    if (!feasible) {
        if (first != -1)
            quitf(_wa, "jury says impossible, but contestant did not print -1");
        if (!ouf.seekEof())
            quitf(_wa, "extra tokens after -1");
        quitf(_ok, "correctly reported no solution");
    }

    if (first == -1)
        quitf(_wa, "a solution exists, but contestant printed -1");
    if (first < 0 || first > m)
        quitf(_wa, "a[1]=%lld is outside [0,%d]", first, m);

    const int B = 32 - __builtin_clz((unsigned)m);
    vector<long long> ones(B, 0);

    auto addValue = [&](long long x, int pos) {
        if (x < 0 || x > m)
            quitf(_wa, "a[%d]=%lld is outside [0,%d]", pos, x, m);
        for (int b = 0; b < B; ++b)
            if ((x >> b) & 1LL) ++ones[b];
    };

    addValue(first, 1);
    for (int i = 2; i <= n; ++i)
        addValue(ouf.readLong(), i);

    if (!ouf.seekEof())
        quitf(_wa, "extra tokens after %d array elements", n);

    const long long base = 6LL * n;
    if (k % base != 0)
        quitf(_fail, "jury says feasible although k is not divisible by 6n");

    const long long target = k / base;
    long long got = 0;
    for (int b = 0; b < B; ++b)
        got += ones[b] * (n - ones[b]);

    if (got != target)
        quitf(_wa, "wrong total value: reduced contribution is %lld, expected %lld", got, target);

    quitf(_ok, "valid construction");
}
