Problem:
You and your grandma are playing with graph automata, which is generalization of cell automata.
A graph automaton is expressed by a graph. The vertices of the graph have a time-dependent value, which can be either 0 or 1.
There is no more than one edge between any of two vertices, but self-loops might exist.
The values of vertices change regularly according to the following rule:
At time
t+1
, the value of vertex
i
will be 1 if and only if there are an odd number of edges from the vertex
i
to a vertex which has the value 1 at time
t
; otherwise 0.
Now, your forgetful grandma forgot the past states of the automaton. Your task is to write a program which recovers the past states from the current time and states --- time machines are way too expensive.
There may be multiple candidates or no consistent states.
For such cases, you must print an appropriate error message.
Input
The input is formatted as follows:
N
a_{11}
...
a_{1N}
:
:
a_{N1}
...
a_{NN}
v_1
:
:
v_N
T
The first line contains one integer
N
(
2 \leq N \leq 300
).
N
indicates the number of vertices.
The following
N
lines indicate the adjacent matrix of the graph.
When
(i,j)
-element is 1, there is an edge from vertex
i
to vertex
j
.
Otherwise, there is no edge.
The following
N
lines indicate the value vector of the vertices.
The
i
-th element indicates the value of vertex
i
at time 0.
Each element of the matrix and the vector can be 0 or 1.
The last line contains one integer
T
(
1 \leq T \leq 100,000,000
).
-T
is the time your grandma wants to know the status at.
Output
Print the value vector at time
-T
separated one white space in one line as follows:
v_1
...
v_N
Each value must be separated with one white space.
If there is no consistent value vectors, you should print
none
in one line.
Or if there are multiple candidates and the solution is not unique  (i.e. the solution is not unique), you should print
ambiguous
in one line.
Sample Input 1
2
1 1
0 1
1
1
1
Output for the Sample Input 1
0 1
Sample Input 2
2
0 1
0 0
1
0
1
Output for the Sample Input 2
ambiguous
Sample Input 3
2
0 1
0 0
1
0
2
Output for the Sample Input 3
none

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto&& e : v)
using ll = long long;
const ll mod = 1000000009;

vector<vector<int>> mul(vector<vector<int>> &a, vector<vector<int>> &b) {
    int n = a.size();
    vector ret(n, vector(n, 0));
    rep(i, n) rep(j, n) {
        rep(k, n) {
            ret[i][j] ^= a[i][k] & b[k][j];
        }
    }
    return ret;
}
vector<vector<int>> matpow(vector<vector<int>> a, ll m) {
    int n = a.size();
    vector ret(n, vector(n, 0));
    rep(i, n) ret[i][i] = 1;
    while(m) {
        if(m & 1) {
            ret = mul(ret, a);
        }
        a = mul(a, a);
        m >>= 1;
    }
    return ret;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // とりあえずT乗してよい
    // v = a * ans

    int n; cin >> n;
    vector a(n, vector(n, 0));
    rep(i, n) {
        rep(j, n) cin >> a[i][j];
    }
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    int T; cin >> T;
    auto mat = matpow(a, T);
    rep(i, n) mat[i].pb(v[i]);
    
    int idx = 0;
    for(int i = 0; i < n; i ++) {
        int id = -1;
        for(int j = idx; j < n; j ++) if(mat[j][i]) {
            id = j;
            break;
        }
        if(id == -1) continue;
        swap(mat[id], mat[idx]);
        for(int j = idx + 1; j < n; j ++) if(mat[j][i]) {
            rep(k, n + 1) mat[j][k] ^= mat[idx][k];
        }
        idx ++;
    }
    while(!mat.empty() and count(all(mat.back()), 1) == 0) mat.pop_back();
    int sz = mat.size();
    if(!mat.empty() and mat.back()[n] == 1 and count(all(mat.back()), 1) == 1) {
        cout << "none\n";
        return 0;
    }
    if(sz != n) {
        cout << "ambiguous\n";
        return 0;
    }
    vector<int> ans(n, 0);
    for(int i = n - 1; i >= 0; i --) {
        assert(mat[i][i]);
        ans[i] = mat[i][n];
        for(int j = 0; j < i; j ++) if(mat[j][i]) {
            rep(k, n + 1) mat[j][k] ^= mat[i][k];
        }
    }
    rep(i, n) cout << ans[i] << (i == n - 1 ? '\n' : ' ') ;
    
    return 0;
}
accuracy: 1
time_ms: 550
memory_kb: 4656
final_rank: 7

code_snippet: // AOJ #2624 Graph Automata Player
// 2025.3.26

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

#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int Cin() {
	int n = 0; int c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void Cout(int n) {
	char b[30];
	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		int i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
}

void Couts(const string &s) {
    for (char c : s) pc(c);
    pc('\n');
}

const int NMAX = 305;

int main(){
    int n = Cin();
    vector<vector<bitset<NMAX>>> tapi(30, vector<bitset<NMAX>>(n));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            int a = Cin();
            if (a) tapi[0][i].flip(j);
        }
    }

    vector<int> wt(n);
    for (int i = 0; i < n; i++) wt[i] = gc() & 1, gc();

    int T = Cin();
    for (int i = 1; i < 30; i++)
        for (int j = 0; j < n; j++)
            for (int k = 0; k < n; k++)
                if (tapi[i - 1][j].test(k)) tapi[i][j] ^= tapi[i - 1][k];

    vector<bitset<NMAX>> box(n);
    for (int i = 0; i < n; i++) box[i].flip(i);

    for (int i = 0; i < 30; i++){
        if ((T >> i) & 1LL) {
            for (int j = 0; j < n; j++){
                bitset<NMAX> bs;
                for (int k = 0; k < n; k++)
                    if (box[j].test(k)) bs ^= tapi[i][k];
                box[j] = bs;
            }
        }
    }

    for (int i = 0; i < n; i++){
        if (wt[i]) box[i].flip(NMAX - 1);
    }

    vector<int> used(n, 0);
    for (int col = 0; col < n; col++){
        for (int row = 0; row < n; row++){
            if (used[row]) continue;
            if (box[row].test(col)) {
                used[row] = 1;
                swap(box[col], box[row]);
                swap(used[col], used[row]);
                for (int r = 0; r < n; r++){
                    if (r == col) continue;
                    if (box[r].test(col))
                        box[r] ^= box[col];
                }
                break;
            }
        }
    }

    bool freeVar = false;
    bool inconsistent = false;
    for (int i = 0; i < n; i++){
        if (!box[i].test(i)) {
            freeVar = true;
            if (box[i].test(NMAX - 1)) inconsistent = true;
        }
    }

    if (inconsistent) {
        Couts("none");
        return 0;
    }
    if (freeVar) {
        Couts("ambiguous");
        return 0;
    }

    for (int i = 0; i < n; i++){
        if (i) pc(' ');
        Cout(box[i].test(NMAX - 1));
    }
    pc('\n');
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3580
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

// =============================================================================================
// === Matrix Part 1
// =============================================================================================
struct Matrix {
    short dat[309][309];
};

Matrix Zero() {
    Matrix C; 
    for (int i = 0; i < 309; i++) {
        for (int j = 0; j < 309; j++) C.dat[i][j] = 0;
    }
    return C;
}

Matrix One() {
    Matrix C; 
    for (int i = 0; i < 309; i++) {
        for (int j = 0; j < 309; j++) C.dat[i][j] = (i == j ? 1 : 0);
    }
    return C;
}

Matrix Mult(int N, Matrix A, Matrix B) {
    Matrix C = Zero();
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                C.dat[i][j] += A.dat[i][k] * B.dat[k][j];
                C.dat[i][j] &= 1;
            }
        }
    }
    return C;
}

Matrix Pow(int N, Matrix A, long long K) {
    Matrix current = One();
    Matrix doubles = A;
    for (int i = 0; i < 27; i++) {
        if ((K >> i) & 1) current = Mult(N, current, doubles);
        doubles = Mult(N, doubles, doubles);
    }
    return current;
}


// =============================================================================================
// === Matrix Part 2
// =============================================================================================
pair<string, Matrix> GetRank(int N, vector<vector<int>> R, vector<int> V) {
    vector<vector<int>> mat(N, vector<int>(2 * N + 1, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) mat[i][j] = R[i][j];
    }
    for (int i = 0; i < N; i++) mat[i][i + N] = 1;
    for (int i = 0; i < N; i++) mat[i][2 * N] = V[i];

    // Operations
    for (int piv = 0; piv < N; piv++) {
        int Index = -1;
        for (int i = piv; i < N; i++) {
            if (mat[i][piv] == 1) { Index = i; break; }
        }
        if (Index == -1) continue;

        // Swap & Operate
        swap(mat[piv], mat[Index]);
        for (int i = 0; i < N; i++) {
            if (mat[i][piv] == 0 || i == piv) continue;
            for (int j = 0; j < 2 * N + 1; j++) mat[i][j] ^= mat[piv][j];
        }
    }

    // Check Ambiguous or None
    string str = "success";
    for (int i = 0; i < N; i++) {
        int cnt = 0;
        for (int j = 0; j < N; j++) cnt += mat[i][j];
        if (cnt >= 1) continue;
        if (str == "success") str = "ambiguous";
        if (str == "ambiguous" && mat[i][2 * N] == 1) str = "none";
    }
    if (str != "success") return make_pair(str, Zero());

    // Get Matrix
    Matrix E = Zero();
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) E.dat[i][j] = mat[i][j + N];
    }
    return make_pair(str, E);
}


// =============================================================================================
// === Main Part
// =============================================================================================
int main() {
    // Step 1. Input
    int N; cin >> N;
    Matrix A;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) cin >> A.dat[i][j];
    }
    vector<int> V(N, 0); for (int i = 0; i < N; i++) cin >> V[i];
    int T; cin >> T;
    A = Pow(N, A, T);

    // Prepare
    vector<vector<int>> R(N, vector<int>(N, 0));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) R[i][j] = A.dat[i][j];
    }

    // Step 2. Solve 1
    pair<string, Matrix> ret = GetRank(N, R, V);
    /*for (int i = 0; i < N; i++) {
        for (int j = 0; j < 2 * N + 1; j++) cout << " " << ret.second.dat[i][j];
        cout << endl;
    }*/
    if (ret.first != "success") {
        cout << ret.first << endl;
        return 0;
    }

    // Step 3. Solve 2
    for (int i = 0; i < N; i++) {
        if (i >= 1) cout << " ";
        int cnt = 0;
        for (int j = 0; j < N; j++) cnt ^= (V[j] * ret.second.dat[i][j]);
        cout << cnt;
    }
    cout << endl;
    return 0;
}
accuracy: 1
time_ms: 570
memory_kb: 6512
final_rank: 15

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rrep(i, a, b) for (ll i = (ll)(b)-1; i >= (ll)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

template <unsigned mod = 1000000007> struct fp {
    unsigned v;
    static constexpr int get_mod() {
        return mod;
    }
    constexpr unsigned inv() const {
        assert(v != 0);
        int x = v, y = mod, p = 1, q = 0, t = 0, tmp = 0;
        while (y > 0) {
            t = x / y;
            x -= t * y, p -= t * q;
            tmp = x, x = y, y = tmp;
            tmp = p, p = q, q = tmp;
        }
        if (p < 0)
            p += mod;
        return p;
    }
    constexpr fp(ll x = 0) : v(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    fp operator-() const {
        return fp() - *this;
    }
    fp pow(ull t) {
        fp res = 1, b = *this;
        while (t) {
            if (t & 1)
                res *= b;
            b *= b;
            t >>= 1;
        }
        return res;
    }
    fp &operator+=(const fp &x) {
        if ((v += x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator-=(const fp &x) {
        if ((v += mod - x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator*=(const fp &x) {
        v = ull(v) * x.v % mod;
        return *this;
    }
    fp &operator/=(const fp &x) {
        v = ull(v) * x.inv() % mod;
        return *this;
    }
    fp operator+(const fp &x) const {
        return fp(*this) += x;
    }
    fp operator-(const fp &x) const {
        return fp(*this) -= x;
    }
    fp operator*(const fp &x) const {
        return fp(*this) *= x;
    }
    fp operator/(const fp &x) const {
        return fp(*this) /= x;
    }
    bool operator==(const fp &x) const {
        return v == x.v;
    }
    bool operator!=(const fp &x) const {
        return v != x.v;
    }
    friend istream &operator>>(istream &is, fp &x) {
        return is >> x.v;
    }
    friend ostream &operator<<(ostream &os, const fp &x) {
        return os << x.v;
    }
};

template <typename T> T Inv(ll n) {
    static const int md = T::get_mod();
    static vector<T> buf({0, 1});
    assert(n > 0);
    n %= md;
    while (SZ(buf) <= n) {
        int k = SZ(buf), q = (md + k - 1) / k;
        buf.push_back(buf[k * q - md] * q);
    }
    return buf[n];
}

template <typename T> T Fact(ll n, bool inv = 0) {
    static const int md = T::get_mod();
    static vector<T> buf({1, 1}), ibuf({1, 1});
    assert(n >= 0 and n < md);
    while (SZ(buf) <= n) {
        buf.push_back(buf.back() * SZ(buf));
        ibuf.push_back(ibuf.back() * Inv<T>(SZ(ibuf)));
    }
    return inv ? ibuf[n] : buf[n];
}

template <typename T> T nPr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nCr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(r, inv ^ 1) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nHr(int n, int r, bool inv = 0) {
    return nCr<T>(n + r - 1, r, inv);
}

/**
 * @brief Modint
 */

template <class T> struct Matrix {
    int h, w;
    vector<vector<T>> val;
    T det;
    Matrix() {}
    Matrix(int n) : h(n), w(n), val(vector<vector<T>>(n, vector<T>(n))) {}
    Matrix(int n, int m)
        : h(n), w(m), val(vector<vector<T>>(n, vector<T>(m))) {}
    vector<T> &operator[](const int i) {
        return val[i];
    }
    Matrix &operator+=(const Matrix &m) {
        assert(h == m.h and w == m.w);
        rep(i, 0, h) rep(j, 0, w) val[i][j] += m.val[i][j];
        return *this;
    }
    Matrix &operator-=(const Matrix &m) {
        assert(h == m.h and w == m.w);
        rep(i, 0, h) rep(j, 0, w) val[i][j] -= m.val[i][j];
        return *this;
    }
    Matrix &operator*=(const Matrix &m) {
        assert(w == m.h);
        Matrix<T> res(h, m.w);
        rep(i, 0, h) rep(j, 0, m.w) rep(k, 0, w) res.val[i][j] +=
            val[i][k] * m.val[k][j];
        *this = res;
        return *this;
    }
    Matrix operator+(const Matrix &m) const {
        return Matrix(*this) += m;
    }
    Matrix operator-(const Matrix &m) const {
        return Matrix(*this) -= m;
    }
    Matrix operator*(const Matrix &m) const {
        return Matrix(*this) *= m;
    }
    Matrix pow(ll k) {
        Matrix<T> res(h, h), c = *this;
        rep(i, 0, h) res.val[i][i] = 1;
        while (k) {
            if (k & 1)
                res *= c;
            c *= c;
            k >>= 1;
        }
        return res;
    }
    vector<int> gauss(int c = -1) {
        det = 1;
        if (val.empty())
            return {};
        if (c == -1)
            c = w;
        int cur = 0;
        vector<int> res;
        rep(i, 0, c) {
            if (cur == h)
                break;
            rep(j, cur, h) if (val[j][i] != 0) {
                swap(val[cur], val[j]);
                if (cur != j)
                    det *= -1;
                break;
            }
            det *= val[cur][i];
            if (val[cur][i] == 0)
                continue;
            rep(j, 0, h) if (j != cur) {
                T z = val[j][i] / val[cur][i];
                rep(k, i, w) val[j][k] -= val[cur][k] * z;
            }
            res.push_back(i);
            cur++;
        }
        return res;
    }
    Matrix inv() {
        assert(h == w);
        Matrix base(h, h * 2), res(h, h);
        rep(i, 0, h) rep(j, 0, h) base[i][j] = val[i][j];
        rep(i, 0, h) base[i][h + i] = 1;
        base.gauss(h);
        det = base.det;
        rep(i, 0, h) rep(j, 0, h) res[i][j] = base[i][h + j] / base[i][i];
        return res;
    }
    bool operator==(const Matrix &m) {
        assert(h == m.h and w == m.w);
        rep(i, 0, h) rep(j, 0, w) if (val[i][j] != m.val[i][j]) return false;
        return true;
    }
    bool operator!=(const Matrix &m) {
        assert(h == m.h and w == m.w);
        rep(i, 0, h) rep(j, 0, w) if (val[i][j] == m.val[i][j]) return false;
        return true;
    }
    friend istream &operator>>(istream &is, Matrix &m) {
        rep(i, 0, m.h) rep(j, 0, m.w) is >> m[i][j];
        return is;
    }
    friend ostream &operator<<(ostream &os, Matrix &m) {
        rep(i, 0, m.h) {
            rep(j, 0, m.w) os << m[i][j]
                              << (j == m.w - 1 and i != m.h - 1 ? '\n' : ' ');
        }
        return os;
    }
};

/**
 * @brief Matrix
 */

template<typename T>pair<vector<T>,Matrix<T>> LinearEquation(Matrix<T> a,vector<T> b){
   int h=a.h,w=a.w;
   rep(i,0,h)a[i].push_back(b[i]);
   a.w++;
   vector<int> idx=a.gauss(w);
   rep(i,idx.size(),h)if(a[i][w]!=0)return {{},{}};
   vector<T> res(w);
   rep(i,0,idx.size())res[idx[i]]=a[i][w]/a[i][idx[i]];
   Matrix<T> d(w,h+w);
   rep(i,0,h)rep(j,0,w)d[j][i]=a[i][j];
   rep(i,0,w)d[i][h+i]=1;
   int r=d.gauss(h).size();
   Matrix<T> basis(w-r,w);
   rep(i,r,w)basis[i-r]={d[i].begin()+h,d[i].end()};
   return {res,basis};
}

/**
 * @brief Linear Equation
 */

using Fp = fp<2>;

int main() {
    int N;
    cin >> N;
    Matrix<Fp> A(N);
    rep(i,0,N) rep(j,0,N) cin >> A[i][j];
    vector<Fp> B(N);
    rep(i,0,N) cin >> B[i];
    ll T;
    cin >> T;
    A = A.pow(T);
    auto [ret,basis] = LinearEquation<Fp>(A,B);
    if (ret.empty()) cout << "none" << endl;
    else if (basis.h >= 1) cout << "ambiguous" << endl;
    else {
        rep(i,0,N) cout << ret[i] << (i == N-1 ? '\n' : ' ');
    }
}
accuracy: 1
time_ms: 1660
memory_kb: 4900
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using namespace std;
vector<vector<int> > pr(vector<vector<int> > &a, vector<vector<int> > &b) {
    int n = a.size();
    int k = a[0].size();
    int m = b[0].size();
    vector<vector<int> > res(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int f = 0; f < k; f++) {
            for (int j = 0; j < m; j++) {
                res[i][j] ^= a[i][f] * b[f][j];
            }
        }
    }
    return res;
}
vector<vector<int> > binpow(vector<vector<int> > &a, int pw) {
    if (pw == 1) {
        return a;
    }
    vector<vector<int> > res = binpow(a, pw / 2);
    res = pr(res, res);
    if (pw % 2) {
        res = pr(res, a);
    }
    return res;
}
vector<int> xr(vector<int> &a, vector<int> &b) {
    vector<int> res(a.size());
    for (int i = 0; i < a.size(); i++) {
        res[i] = a[i] ^ b[i];
    }
    return res;
}
void gauss(vector<vector<int> > mat) {

    int n = mat.size();
    for (int i = 0; i < n; i++) {
        int pos = -1;
        for (int j = i; j < n; j++) {
            if (mat[j][i]) {
                pos = j;
                break;
            }
        }
        if (pos == -1) {
            continue;
        }
        if (i != pos) {
            mat[i] = xr(mat[i], mat[pos]);
        }
        for (int j = i + 1; j < n; j++) {
            if (mat[j][i]) {
                mat[j] = xr(mat[j], mat[i]);
            }
        }
    }
    for (int i = n - 1; i >= 0; i--) {
        int pos = -1;
        for (int k = 0; k < n; k++) {
            if (mat[i][k]) {
                pos = k;
                break;
            }
        }
        if (pos != -1) {
            for (int j = i - 1; j >= 0; j--) {
                if (mat[j][pos]) {
                    mat[j] = xr(mat[j], mat[i]);
                }
            }
        }
    }
    bool bad = 0;
    bool ambig = 0;
    vector<int> res(n);
    for (int i = 0; i < n; i++) {
        int pos = -1;
        for (int j = 0; j < n; j++) {
            if (mat[i][j]) {
                pos = j;
            }
        }
        if (pos == -1 && mat[i][n]) {
            bad = 1;
        } else if (pos == -1) {
            ambig = 1;
        } else {
            res[pos] = mat[i][n];
        }
    }
    if (bad) {
        cout << "none\n";
        return;
    }
    if (ambig) {
        cout << "ambiguous\n";
        return;
    }
    for (int i = 0; i < n; i++) {
        cout << res[i];
        if (i + 1 != n) {
            cout << " ";
        }
    }
    cout << '\n';
}
int main() {
    int n;
    cin >> n;
    vector<vector<int> > mat(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> mat[i][j];
        }
    }
    vector<int> val(n);
    for (int i = 0; i < n; i++) {
        cin >> val[i];
    }
    int t;
    cin >> t;
    mat = binpow(mat, t);
    for (int i = 0; i < n; i++) {
        mat[i].push_back(val[i]);
    }
    gauss(mat);
}
accuracy: 1
time_ms: 590
memory_kb: 4068
final_rank: 6

code_snippet: #include <bitset>
#include <cassert>
#include <cstddef>
#include <tuple>
#include <utility>
#include <vector>

// Gauss-Jordan elimination of n * m matrix M
// Complexity: O(nm + nm rank(M) / 64)
// Verified: abc276_h (2000 x 8000)
template <std::size_t Wmax>
std::vector<std::bitset<Wmax>> f2_gauss_jordan(int W, std::vector<std::bitset<Wmax>> M) {
    assert(W <= Wmax);
    int H = M.size(), c = 0;
    for (int h = 0; h < H and c < W; ++h, ++c) {
        int piv = -1;
        for (int j = h; j < H; ++j) {
            if (M[j][c]) {
                piv = j;
                break;
            }
        }
        if (piv == -1) {
            --h;
            continue;
        }
        std::swap(M[piv], M[h]);
        for (int hh = 0; hh < H; ++hh) {
            if (hh != h and M[hh][c]) M[hh] ^= M[h];
        }
    }
    return M;
}

// Rank of Gauss-Jordan eliminated matrix
template <std::size_t Wmax> int f2_rank_gauss_jordan(int W, const std::vector<std::bitset<Wmax>> &M) {
    assert(W <= Wmax);
    for (int h = (int)M.size() - 1; h >= 0; h--) {
        int j = 0;
        while (j < W and !M[h][j]) ++j;
        if (j < W) return h + 1;
    }
    return 0;
}

// determinant of F2 matrix.
// Return 0 if the matrix is singular, otherwise return 1.
// Complexity: O(W^3 / 64)
template <std::size_t Wmax> int f2_determinant(const std::vector<std::bitset<Wmax>> &M) {
    const int H = M.size();
    if (H > Wmax) return 0;

    auto tmp = M;
    for (int h = 0; h < H; ++h) {
        int piv = -1;
        for (int j = h; j < H; ++j) {
            if (tmp.at(j).test(h)) {
                piv = j;
                break;
            }
        }
        if (piv == -1) return 0; // singular

        if (piv != h) std::swap(tmp.at(piv), tmp.at(h));
        for (int hh = h + 1; hh < H; ++hh) {
            if (tmp.at(hh).test(h)) tmp.at(hh) ^= tmp.at(h);
        }
    }

    return 1; // nonsingular
}

template <std::size_t W1, std::size_t W2>
std::vector<std::bitset<W2>>
f2_matmul(const std::vector<std::bitset<W1>> &A, const std::vector<std::bitset<W2>> &B) {
    int H = A.size(), K = B.size();
    std::vector<std::bitset<W2>> C(H);
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < K; j++) {
            if (A.at(i).test(j)) C.at(i) ^= B.at(j);
        }
    }
    return C;
}

template <std::size_t Wmax>
std::vector<std::bitset<Wmax>> f2_matpower(std::vector<std::bitset<Wmax>> X, long long n) {
    int D = X.size();
    std::vector<std::bitset<Wmax>> ret(D);
    for (int i = 0; i < D; i++) ret[i][i] = 1;
    while (n) {
        if (n & 1) ret = f2_matmul<Wmax, Wmax>(ret, X);
        X = f2_matmul<Wmax, Wmax>(X, X), n >>= 1;
    }
    return ret;
}

// Solve Ax = b on F_2
// - retval: {true, one of the solutions, {freedoms}} (if solution exists)
//           {false, {}, {}} (otherwise)
// Complexity: O(HW + HW rank(A) / 64 + W^2 len(freedoms))
template <std::size_t Wmax, class Vec>
std::tuple<bool, std::bitset<Wmax>, std::vector<std::bitset<Wmax>>>
f2_system_of_linear_equations(std::vector<std::bitset<Wmax>> A, Vec b, int W) {
    int H = A.size();
    assert(W <= Wmax);
    assert(A.size() == b.size());

    std::vector<std::bitset<Wmax + 1>> M(H);
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) M[i][j] = A[i][j];
        M[i][W] = b[i];
    }
    M = f2_gauss_jordan<Wmax + 1>(W + 1, M);
    std::vector<int> ss(W, -1);
    std::vector<int> ss_nonneg_js;
    for (int i = 0; i < H; i++) {
        int j = 0;
        while (j <= W and !M[i][j]) ++j;
        if (j == W) return {false, 0, {}};
        if (j < W) {
            ss_nonneg_js.push_back(j);
            ss[j] = i;
        }
    }
    std::bitset<Wmax> x;
    std::vector<std::bitset<Wmax>> D;
    for (int j = 0; j < W; ++j) {
        if (ss[j] == -1) {
            // This part may require W^2 space complexity in output
            std::bitset<Wmax> d;
            d[j] = 1;
            for (int jj : ss_nonneg_js) d[jj] = M[ss[jj]][j];
            D.emplace_back(d);
        } else {
            x[j] = M[ss[j]][W];
        }
    }
    return std::make_tuple(true, x, D);
}

#include <iostream>
#include <numeric>
using namespace std;

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);

    constexpr int Wmax = 320;
    int N, T;
    cin >> N;
    vector<bitset<Wmax>> A(N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            int t;
            cin >> t;
            A[i][j] = t;
        }
    }
    bitset<Wmax> v(N);
    for (int i = 0; i < N; i++) {
        int t;
        cin >> t;
        v[i] = t;
    }

    cin >> T;
    A = f2_matpower(A, T);
    for (int i = 0; i < N; i++) A[i][N] = v[i];
    A = f2_gauss_jordan(N + 1, A);

    for (int i = 0; i < N; i++) {
        if (A[i].count() == 1 and A[i][N]) {
            cout << "none\n";
            return 0;
        }
    }
    if (!A[N - 1][N - 1]) {
        cout << "ambiguous\n";
        return 0;
    }
    bitset<Wmax> ret;
    for (int i = N - 1; i >= 0; i--) {
        int a = 0;
        for (int j = i + 1; j < N; j++) a ^= ret[j] * A[i][j];
        ret[i] = (a != A[i][N]);
    }
    for (int i = 0; i < N; i++) cout << ret[i] << (i == N - 1 ? '\n' : ' ');
}
accuracy: 1
time_ms: 20
memory_kb: 3520
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
using ll = long long;
#define all(p) p.begin(),p.end()


int main(){
	int N;
	cin>>N;
	const int M=310;
	vector<bitset<M>> A(N);
	rep(i,0,N) rep(j,0,N){
		char c;
		cin>>c;
		if(c=='1') A[i][j]=1;
	}
	vector<int> v(N);
	rep(i,0,N) cin>>v[i];
	int T;
	cin>>T;
	auto f=[&](vector<bitset<M>> l,vector<bitset<M>> r)->vector<bitset<M>>{
		vector<bitset<M>> res(N);
		rep(i,0,N) rep(j,0,N){
			if(l[i][j]){
				res[i]^=r[j];
			}
		}
		return res;
	};
	vector<bitset<M>> tmp(N);
	rep(i,0,N) tmp[i][i]=1;
	while(T){
		if(T&1) tmp=f(tmp,A);
		A=f(A,A);
		T>>=1;
	}
	rep(i,0,N) tmp[i][N]=v[i];
	int ind=0;
	rep(i,0,N){
		for(int j=ind;j<N;j++){
			if(tmp[j][i]){
				swap(tmp[j],tmp[ind]);
				break;
			}
		}
		if(!tmp[ind][i]) continue;
		rep(j,0,N){
			if(j==ind) continue;
			if(tmp[j][i]) tmp[j]^=tmp[ind];
		}
		ind++;
	}
	if(ind<N){
		rep(i,ind,N){
			if(tmp[i][N]){
				cout<<"none\n";
				return 0;
			}
		}
		cout<<"ambiguous\n";
		return 0;
	}
	rep(i,0,N){
		if(i) cout<<" ";
		cout<<(int)(tmp[i][N]);
	}
	cout<<"\n";
}
accuracy: 1
time_ms: 20
memory_kb: 3488
final_rank: 1

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

// mod2
const int N = 301;
struct Mat{
    array<array<bool, N>, N> a;
    int n;
    Mat(int _n, int x) : n(_n){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i == j){
                    if(x) a[i][j] = 1;
                    else a[i][j] = 0;
                }
                else{
                    a[i][j] = 0;
                }
            }
        }
    }
};
Mat mul(Mat A, Mat B){
    int n = A.n;
    Mat res(n,0);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                res.a[i][j] ^= (A.a[i][k]&B.a[k][j]);
            }
        }
    }
    return res;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    Mat E(n,1), A(N,0);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int x; cin >> x;
            if(x) A.a[i][j] = 1;
        }
    }
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    int T; cin >> T;
    while(T){
        if(T & 1) E = mul(E, A);
        A = mul(A, A);
        T >>= 1;
    }
    bool am = false;
    bool ng = false;
    vector<bool> used(n);
    vector<vector<int>> a(n,vector<int>(n));
    vector<int> res(n);
    for(int i=0;i<n;i++){
        bool ok = false;
        int w = v[i];
        for(int j=0;j<n;j++){
            if(E.a[i][j] and a[j][j]){
                for(int k=0;k<n;k++){
                    E.a[i][k] ^= a[j][k];
                }
                w ^= res[j];
            }
            if(E.a[i][j]){
                for(int k=0;k<n;k++){
                    a[j][k] = E.a[i][k];
                }
                res[j] = w;
                ok = true;
                break;
            }
        }
        if(!ok){
            am = true;
            if(w) ng = true;
        }
    }
    if(ng){
        cout << "none" << endl;  
    }
    else if(am){
        cout << "ambiguous" << endl;
    }
    else{
        for(int i=n-1;i>=0;i--){
            for(int j=i+1;j<n;j++){
                res[i] ^= (res[j]&a[i][j]);
            }
        }
        for(int i=0;i<n;i++){
            if(i) cout << " ";
            cout << res[i];
        }
        cout << endl;
    }
}
accuracy: 1
time_ms: 50
memory_kb: 4076
final_rank: 5

code_snippet: #line 1 "/Users/nok0/Documents/Programming/nok0/cftemp.hpp"
#include <bits/stdc++.h>
using namespace std;

#pragma region Macros
// rep macro
#define foa(v, a) for(auto &v : a)
#define REPname(a, b, c, d, e, ...) e
#define REP(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define REP0(x) for(int i = 0; i < (x); ++i)
#define REP1(i, x) for(int i = 0; i < (x); ++i)
#define REP2(i, l, r) for(int i = (l); i < (r); ++i)
#define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c))
#define REPSname(a, b, c, ...) c
#define REPS(...) REPSname(__VA_ARGS__, REPS1, REPS0)(__VA_ARGS__)
#define REPS0(x) for(int i = 1; i <= (x); ++i)
#define REPS1(i, x) for(int i = 1; i <= (x); ++i)
#define RREPname(a, b, c, d, e, ...) e
#define RREP(...) RREPname(__VA_ARGS__, RREP3, RREP2, RREP1, RREP0)(__VA_ARGS__)
#define RREP0(x) for(int i = (x)-1; i >= 0; --i)
#define RREP1(i, x) for(int i = (x)-1; i >= 0; --i)
#define RREP2(i, r, l) for(int i = (r)-1; i >= (l); --i)
#define RREP3(i, r, l, c) for(int i = (r)-1; i >= (l); i -= (c))
#define RREPSname(a, b, c, ...) c
#define RREPS(...) RREPSname(__VA_ARGS__, RREPS1, RREPS0)(__VA_ARGS__)
#define RREPS0(x) for(int i = (x); i >= 1; --i)
#define RREPS1(i, x) for(int i = (x); i >= 1; --i)

// name macro
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define popcnt(x) __builtin_popcountll(x)
template <class T = int>
using V = std::vector<T>;
template <class T = int>
using VV = std::vector<std::vector<T>>;
template <class T>
using pqup = std::priority_queue<T, std::vector<T>, std::greater<T>>;
using ll = long long;
using ld = long double;
using int128 = __int128_t;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

// input macro
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
	for(T &i : v) is >> i;
	return is;
}
std::istream &operator>>(std::istream &is, __int128_t &a) {
	std::string s;
	is >> s;
	__int128_t ret = 0;
	for(int i = 0; i < s.length(); i++)
		if('0' <= s[i] and s[i] <= '9')
			ret = 10 * ret + s[i] - '0';
	a = ret * (s[0] == '-' ? -1 : 1);
	return is;
}
namespace scanner {
void scan(int &a) { std::cin >> a; }
void scan(long long &a) { std::cin >> a; }
void scan(std::string &a) { std::cin >> a; }
void scan(char &a) { std::cin >> a; }
void scan(char a[]) { std::scanf("%s", a); }
void scan(double &a) { std::cin >> a; }
void scan(long double &a) { std::cin >> a; }
template <class T, class U>
void scan(std::pair<T, U> &p) { std::cin >> p; }
template <class T>
void scan(std::vector<T> &a) { std::cin >> a; }
void INPUT() {}
template <class Head, class... Tail>
void INPUT(Head &head, Tail &...tail) {
	scan(head);
	INPUT(tail...);
}
}  // namespace scanner
#define VEC(type, name, size)     \
	std::vector<type> name(size); \
	scanner::INPUT(name)
#define VVEC(type, name, h, w)                                    \
	std::vector<std::vector<type>> name(h, std::vector<type>(w)); \
	scanner::INPUT(name)
#define INT(...)     \
	int __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LL(...)            \
	long long __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define STR(...)             \
	std::string __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define CHAR(...)     \
	char __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define DOUBLE(...)     \
	double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)
#define LD(...)              \
	long double __VA_ARGS__; \
	scanner::INPUT(__VA_ARGS__)

// output-macro
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << p.first << " " << p.second;
	return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &a) {
	for(int i = 0; i < int(a.size()); ++i) {
		if(i) os << " ";
		os << a[i];
	}
	return os;
}
std::ostream &operator<<(std::ostream &dest, __int128_t &value) {
	std::ostream::sentry s(dest);
	if(s) {
		__uint128_t tmp = value < 0 ? -value : value;
		char buffer[128];
		char *d = std::end(buffer);
		do {
			--d;
			*d = "0123456789"[tmp % 10];
			tmp /= 10;
		} while(tmp != 0);
		if(value < 0) {
			--d;
			*d = '-';
		}
		int len = std::end(buffer) - d;
		if(dest.rdbuf()->sputn(d, len) != len) {
			dest.setstate(std::ios_base::badbit);
		}
	}
	return dest;
}
template <class T>
void print(const T a) { std::cout << a << '\n'; }
template <class Head, class... Tail>
void print(Head H, Tail... T) {
	std::cout << H << ' ';
	print(T...);
}
template <class T>
void printel(const T a) { std::cout << a << '\n'; }
template <class T>
void printel(const std::vector<T> &a) {
	for(const auto &v : a)
		std::cout << v << '\n';
}
template <class Head, class... Tail>
void printel(Head H, Tail... T) {
	std::cout << H << '\n';
	printel(T...);
}
void Yes(const bool b = true) { std::cout << (b ? "Yes\n" : "No\n"); }
void No() { std::cout << "No\n"; }
void YES(const bool b = true) { std::cout << (b ? "YES\n" : "NO\n"); }
void NO() { std::cout << "NO\n"; }
void err(const bool b = true) {
	if(b) {
		std::cout << "-1\n", exit(0);
	}
}

//debug macro
namespace debugger {
template <class T>
void view(const std::vector<T> &a) {
	std::cerr << "{ ";
	for(const auto &v : a) {
		std::cerr << v << ", ";
	}
	std::cerr << "\b\b }";
}
template <class T>
void view(const std::vector<std::vector<T>> &a) {
	std::cerr << "{\n";
	for(const auto &v : a) {
		std::cerr << "\t";
		view(v);
		std::cerr << "\n";
	}
	std::cerr << "}";
}
template <class T, class U>
void view(const std::vector<std::pair<T, U>> &a) {
	std::cerr << "{\n";
	for(const auto &p : a) std::cerr << "\t(" << p.first << ", " << p.second << ")\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::map<T, U> &m) {
	std::cerr << "{\n";
	for(const auto &p : m) std::cerr << "\t[" << p.first << "] : " << p.second << "\n";
	std::cerr << "}";
}
template <class T, class U>
void view(const std::pair<T, U> &p) { std::cerr << "(" << p.first << ", " << p.second << ")"; }
template <class T>
void view(const std::set<T> &s) {
	std::cerr << "{ ";
	for(auto &v : s) {
		view(v);
		std::cerr << ", ";
	}
	std::cerr << "\b\b }";
}

template <class T>
void view(const T &e) { std::cerr << e; }
}  // namespace debugger
#ifdef LOCAL
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	debugger::view(H);
	std::cerr << ", ";
	debug_out(T...);
}
#define debug(...)                                                \
	do {                                                          \
		std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \
		debug_out(__VA_ARGS__);                                   \
		std::cerr << "\b\b]\n";                                   \
	} while(false)
#else
#define debug(...) (void(0))
#endif

// vector macro
template <class T>
int lb(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::lower_bound((a).begin(), (a).end(), (x))); }
template <class T>
int ub(const std::vector<T> &a, const T x) { return std::distance((a).begin(), std::upper_bound((a).begin(), (a).end(), (x))); }
template <class T>
void UNIQUE(std::vector<T> &a) {
	std::sort(a.begin(), a.end());
	a.erase(std::unique(a.begin(), a.end()), a.end());
}
template <class T>
std::vector<T> press(std::vector<T> &a) {
	auto res = a;
	UNIQUE(res);
	for(auto &v : a)
		v = lb(res, v);
	return res;
}
#define SORTname(a, b, c, ...) c
#define SORT(...) SORTname(__VA_ARGS__, SORT1, SORT0, ...)(__VA_ARGS__)
#define SORT0(a) std::sort((a).begin(), (a).end())
#define SORT1(a, c) std::sort((a).begin(), (a).end(), [](const auto x, const auto y) { return x c y; })
template <class T>
void ADD(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v += x;
}
template <class T>
void SUB(std::vector<T> &a, const T x = 1) {
	for(auto &v : a) v -= x;
}
std::vector<std::pair<char, int>> rle(const string &s) {
	int n = s.size();
	std::vector<std::pair<char, int>> ret;
	for(int l = 0; l < n;) {
		int r = l + 1;
		for(; r < n and s[l] == s[r]; r++) {}
		ret.emplace_back(s[l], r - l);
		l = r;
	}
	return ret;
}
template <class T>
std::vector<std::pair<T, int>> rle(const std::vector<T> &v) {
	int n = v.size();
	std::vector<std::pair<T, int>> ret;
	for(int l = 0; l < n;) {
		int r = l + 1;
		for(; r < n and v[l] == v[r]; r++) {}
		ret.emplace_back(v[l], r - l);
		l = r;
	}
	return ret;
}
std::vector<int> iota(int n) {
	std::vector<int> p(n);
	std::iota(p.begin(), p.end(), 0);
	return p;
}
template <class T>
struct cum_vector {
public:
	cum_vector() = default;
	template <class U>
	cum_vector(const std::vector<U> &vec) : cum((int)vec.size() + 1) {
		for(int i = 0; i < (int)vec.size(); i++)
			cum[i + 1] = cum[i] + vec[i];
	}
	T prod(int l, int r) {
		return cum[r] - cum[l];
	}

private:
	std::vector<T> cum;
};

// math macro
template <class T, class U>
inline bool chmin(T &a, const U &b) { return a > b ? a = b, true : false; }
template <class T, class U>
inline bool chmax(T &a, const U &b) { return a < b ? a = b, true : false; }
template <class T>
T divup(T x, T y) { return (x + y - 1) / y; }
template <class T>
T POW(T a, long long n) {
	T ret = 1;
	while(n) {
		if(n & 1) ret *= a;
		a *= a;
		n >>= 1;
	}
	return ret;
}
// modpow
long long POW(long long a, long long n, const int mod) {
	long long ret = 1;
	a = (a % mod + mod) % mod;
	while(n) {
		if(n & 1) (ret *= a) %= mod;
		(a *= a) %= mod;
		n >>= 1;
	}
	return ret;
}
template <class T, class F>
T bin_search(T ok, T ng, const F &f) {
	while(abs(ok - ng) > 1) {
		T mid = (ok + ng) >> 1;
		(f(mid) ? ok : ng) = mid;
	}
	return ok;
}
template <class T, class F>
T bin_search(T ok, T ng, const F &f, int loop) {
	for(int i = 0; i < loop; i++) {
		T mid = (ok + ng) / 2;
		(f(mid) ? ok : ng) = mid;
	}
	return ok;
}

// others
struct fast_io {
	fast_io() {
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		cout << fixed << setprecision(15);
	}
} fast_io_;
const int inf = 1e9;
const ll INF = 1e18;
#pragma endregion

void main_();

int main() {
	main_();
	return 0;
}
#line 5 "/Users/nok0/Documents/Programming/nok0/math/matrix.hpp"

template <class T>
struct matrix {
private:
	std::vector<std::vector<T>> A;

	static matrix I(size_t n) {
		matrix mat(n);
		for(int i = 0; i < n; i++) mat[i][i] = 1;
		return mat;
	}

public:
	matrix() = default;

	matrix(std::vector<std::vector<T>> &vvec) { A = vvec; }

	matrix(size_t n, size_t m) : A(n, std::vector<T>(m, 0)) {}

	matrix(size_t n, size_t m, T init) : A(n, std::vector<T>(m, init)) {}

	matrix(size_t n, std::vector<T> &vec) : A(n, vec) {}

	matrix(size_t n) : A(n, std::vector<T>(n, 0)) {}

	size_t height() const { return A.size(); }

	size_t width() const { return A[0].size(); }

	inline const std::vector<T> &operator[](int k) const {
		return A[k];
	}

	inline std::vector<T> &operator[](int k) {
		return A[k];
	}

	matrix &operator+=(const matrix &B) {
		size_t n = height(), m = width();
		assert(n == B.height() and m == B.width());
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				(*this)[i][j] += B[i][j];
		return *this;
	}

	matrix &operator-=(const matrix &B) {
		size_t n = height(), m = width();
		assert(n == B.height() and m == B.width());
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				(*this)[i][j] -= B[i][j];
		return *this;
	}

	matrix &operator*=(const matrix &B) {
		size_t n = height(), m = B.width(), p = width();
		assert(p == B.height());
		std::vector<std::vector<T>> C(n, std::vector<T>(m, 0));
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				for(int k = 0; k < p; k++)
					C[i][j] += (*this)[i][k] * B[k][j];
		A.swap(C);
		return *this;
	}

	matrix &operator^=(long long k) {
		matrix B = matrix::I(height());
		while(k > 0) {
			if(k & 1) B *= (*this);
			*this *= *this;
			k >>= 1ll;
		}
		A.swap(B.A);
		return *this;
	}

	bool operator==(const matrix &B) {
		size_t n = height(), m = width();
		if(n != B.height() or m != B.width()) return false;
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				if((*this)[i][j] != B[i][j]) return false;
		return true;
	}

	matrix operator+(const matrix &B) const {
		return (matrix(*this) += B);
	}

	matrix operator-(const matrix &B) const {
		return (matrix(*this) -= B);
	}

	matrix operator*(const matrix &B) const {
		return (matrix(*this) *= B);
	}

	matrix operator^(const long long &k) const {
		return (matrix(*this) ^= k);
	}

	matrix &operator+=(const T &t) {
		int n = height(), m = width();
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				(*this)[i][j] += t;
		return *this;
	}

	matrix &operator-=(const T &t) {
		int n = height(), m = width();
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				(*this)[i][j] -= t;
		return *this;
	}

	matrix &operator*=(const T &t) {
		int n = height(), m = width();
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				(*this)[i][j] *= t;
		return *this;
	}

	matrix &operator/=(const T &t) {
		int n = height(), m = width();
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++)
				(*this)[i][j] /= t;
		return *this;
	}

	matrix operator+(const T &t) const {
		return (matrix(*this) += t);
	}

	matrix operator-(const T &t) const {
		return (matrix(*this) -= t);
	}

	matrix operator*(const T &t) const {
		return (matrix(*this) *= t);
	}

	matrix operator/(const T &t) const {
		return (matrix(*this) /= t);
	}

	friend std::ostream &operator<<(std::ostream &os, matrix &p) {
		size_t n = p.height(), m = p.width();
		for(int i = 0; i < n; i++) {
			os << '[';
			for(int j = 0; j < m; j++)
				os << p[i][j] << (j == m - 1 ? "]\n" : ",");
		}
		return (os);
	}


};
#line 3 "/Users/nok0/Documents/Programming/nok0/math/gauss_jordan.hpp"

template <class T>
int gauss_elimination_mint(matrix<T> &mat, bool is_extended = false) {
	const int h = mat.height(), w = mat.width();
	int rank = 0;
	for(int j = 0; j < w; j++) {
		if(is_extended and j == w - 1) break;
		int pivot = -1;
		for(int i = rank; i < h; i++) {
			if(mat[i][j] != T(0)) {
				pivot = i;
				break;
			}
		}
		if(pivot == -1) continue;
		swap(mat[rank], mat[pivot]);

		const auto cur = T(1) / mat[rank][j];

		for(int j2 = 0; j2 < w; j2++) mat[rank][j2] *= cur;

		for(int i = 0; i < h; i++) {
			if(i != rank and mat[i][j] != T(0)) {
				auto fac = mat[i][j];
				for(int j2 = 0; j2 < w; j2++)
					mat[i][j2] -= mat[rank][j2] * fac;
			}
		}
		rank++;
	}
	return rank;
}

//return {x, rank} s.t. ax = b
//if no solution, return empty x
template <class T>
std::pair<std::vector<T>, int> linear_equation_mint(const matrix<T> &a, const std::vector<T> &b) {
	int h = a.height(), w = a.width();
	matrix<T> eq(h, w + 1);
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) eq[i][j] = a[i][j];
		eq[i][w] = b[i];
	}
	int rank = gauss_elimination_mint(eq, true);

	for(int i = rank; i < h; i++)
		if(eq[i].back() != T(0)) return std::pair(vector<T>{}, rank);

	std::vector<T> res(h);
	for(int i = 0; i < h; i++) res[i] = eq[i].back();

	return std::pair(res, rank);
}
#line 1 "/Users/nok0/Documents/Programming/nok0/atcoder/modint.hpp"



#line 6 "/Users/nok0/Documents/Programming/nok0/atcoder/modint.hpp"
#include <type_traits>

#ifdef _MSC_VER
#include <intrin.h>
#endif



#ifdef _MSC_VER
#include <intrin.h>
#endif

namespace atcoder {

namespace internal {

// @param m `1 <= m`
// @return x mod m
constexpr long long safe_mod(long long x, long long m) {
    x %= m;
    if (x < 0) x += m;
    return x;
}

// Fast modular multiplication by barrett reduction
// Reference: https://en.wikipedia.org/wiki/Barrett_reduction
// NOTE: reconsider after Ice Lake
struct barrett {
    unsigned int _m;
    unsigned long long im;

    // @param m `1 <= m < 2^31`
    explicit barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {}

    // @return m
    unsigned int umod() const { return _m; }

    unsigned int mul(unsigned int a, unsigned int b) const {
        unsigned long long z = a;
        z *= b;
#ifdef _MSC_VER
        unsigned long long x;
        _umul128(z, im, &x);
#else
        unsigned long long x =
            (unsigned long long)(((unsigned __int128)(z)*im) >> 64);
#endif
        unsigned int v = (unsigned int)(z - x * _m);
        if (_m <= v) v += _m;
        return v;
    }
};

constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
    if (m == 1) return 0;
    unsigned int _m = (unsigned int)(m);
    unsigned long long r = 1;
    unsigned long long y = safe_mod(x, m);
    while (n) {
        if (n & 1) r = (r * y) % _m;
        y = (y * y) % _m;
        n >>= 1;
    }
    return r;
}

// Reference:
// M. Forisek and J. Jancina,
// Fast Primality Testing for Integers That Fit into a Machine Word
// @param n `0 <= n`
constexpr bool is_prime_constexpr(int n) {
    if (n <= 1) return false;
    if (n == 2 || n == 7 || n == 61) return true;
    if (n % 2 == 0) return false;
    long long d = n - 1;
    while (d % 2 == 0) d /= 2;
    constexpr long long bases[3] = {2, 7, 61};
    for (long long a : bases) {
        long long t = d;
        long long y = pow_mod_constexpr(a, t, n);
        while (t != n - 1 && y != 1 && y != n - 1) {
            y = y * y % n;
            t <<= 1;
        }
        if (y != n - 1 && t % 2 == 0) {
            return false;
        }
    }
    return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);

constexpr std::pair<long long, long long> inv_gcd(long long a, long long b) {
    a = safe_mod(a, b);
    if (a == 0) return {b, 0};

    long long s = b, t = a;
    long long m0 = 0, m1 = 1;

    while (t) {
        long long u = s / t;
        s -= t * u;
        m0 -= m1 * u;  // |m1 * u| <= |m1| * s <= b


        auto tmp = s;
        s = t;
        t = tmp;
        tmp = m0;
        m0 = m1;
        m1 = tmp;
    }
    // by [3]: |m0| <= b/g
    // by g != b: |m0| < b/g
    if (m0 < 0) m0 += b / s;
    return {s, m0};
}

constexpr int primitive_root_constexpr(int m) {
    if (m == 2) return 1;
    if (m == 167772161) return 3;
    if (m == 469762049) return 3;
    if (m == 754974721) return 11;
    if (m == 998244353) return 3;
    int divs[20] = {};
    divs[0] = 2;
    int cnt = 1;
    int x = (m - 1) / 2;
    while (x % 2 == 0) x /= 2;
    for (int i = 3; (long long)(i)*i <= x; i += 2) {
        if (x % i == 0) {
            divs[cnt++] = i;
            while (x % i == 0) {
                x /= i;
            }
        }
    }
    if (x > 1) {
        divs[cnt++] = x;
    }
    for (int g = 2;; g++) {
        bool ok = true;
        for (int i = 0; i < cnt; i++) {
            if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) {
                ok = false;
                break;
            }
        }
        if (ok) return g;
    }
}
template <int m> constexpr int primitive_root = primitive_root_constexpr(m);

// @param n `n < 2^32`
// @param m `1 <= m < 2^32`
// @return sum_{i=0}^{n-1} floor((ai + b) / m) (mod 2^64)
unsigned long long floor_sum_unsigned(unsigned long long n,
                                      unsigned long long m,
                                      unsigned long long a,
                                      unsigned long long b) {
    unsigned long long ans = 0;
    while (true) {
        if (a >= m) {
            ans += n * (n - 1) / 2 * (a / m);
            a %= m;
        }
        if (b >= m) {
            ans += n * (b / m);
            b %= m;
        }

        unsigned long long y_max = a * n + b;
        if (y_max < m) break;
        // y_max < m * (n + 1)
        // floor(y_max / m) <= n
        n = (unsigned long long)(y_max / m);
        b = (unsigned long long)(y_max % m);
        std::swap(m, a);
    }
    return ans;
}

}  // namespace internal

}  // namespace atcoder



namespace atcoder {

namespace internal {

#ifndef _MSC_VER
template <class T>
using is_signed_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value ||
                                  std::is_same<T, __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int128 =
    typename std::conditional<std::is_same<T, __uint128_t>::value ||
                                  std::is_same<T, unsigned __int128>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using make_unsigned_int128 =
    typename std::conditional<std::is_same<T, __int128_t>::value,
                              __uint128_t,
                              unsigned __int128>;

template <class T>
using is_integral = typename std::conditional<std::is_integral<T>::value ||
                                                  is_signed_int128<T>::value ||
                                                  is_unsigned_int128<T>::value,
                                              std::true_type,
                                              std::false_type>::type;

template <class T>
using is_signed_int = typename std::conditional<(is_integral<T>::value &&
                                                 std::is_signed<T>::value) ||
                                                    is_signed_int128<T>::value,
                                                std::true_type,
                                                std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<(is_integral<T>::value &&
                               std::is_unsigned<T>::value) ||
                                  is_unsigned_int128<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<
    is_signed_int128<T>::value,
    make_unsigned_int128<T>,
    typename std::conditional<std::is_signed<T>::value,
                              std::make_unsigned<T>,
                              std::common_type<T>>::type>::type;

#else

template <class T> using is_integral = typename std::is_integral<T>;

template <class T>
using is_signed_int =
    typename std::conditional<is_integral<T>::value && std::is_signed<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using is_unsigned_int =
    typename std::conditional<is_integral<T>::value &&
                                  std::is_unsigned<T>::value,
                              std::true_type,
                              std::false_type>::type;

template <class T>
using to_unsigned = typename std::conditional<is_signed_int<T>::value,
                                              std::make_unsigned<T>,
                                              std::common_type<T>>::type;

#endif

template <class T>
using is_signed_int_t = std::enable_if_t<is_signed_int<T>::value>;

template <class T>
using is_unsigned_int_t = std::enable_if_t<is_unsigned_int<T>::value>;

template <class T> using to_unsigned_t = typename to_unsigned<T>::type;

}  // namespace internal

}  // namespace atcoder


#line 14 "/Users/nok0/Documents/Programming/nok0/atcoder/modint.hpp"

namespace atcoder {

namespace internal {

struct modint_base {};
struct static_modint_base : modint_base {};

template <class T> using is_modint = std::is_base_of<modint_base, T>;
template <class T> using is_modint_t = std::enable_if_t<is_modint<T>::value>;

}  // namespace internal

template <int m, std::enable_if_t<(1 <= m)>* = nullptr>
struct static_modint : internal::static_modint_base {
    using mint = static_modint;

  public:
    static constexpr int mod() { return m; }
    static mint raw(int v) {
        mint x;
        x._v = v;
        return x;
    }

    static_modint() : _v(0) {}
    template <class T, internal::is_signed_int_t<T>* = nullptr>
    static_modint(T v) {
        long long x = (long long)(v % (long long)(umod()));
        if (x < 0) x += umod();
        _v = (unsigned int)(x);
    }
    template <class T, internal::is_unsigned_int_t<T>* = nullptr>
    static_modint(T v) {
        _v = (unsigned int)(v % umod());
    }

    unsigned int val() const { return _v; }

    mint& operator++() {
        _v++;
        if (_v == umod()) _v = 0;
        return *this;
    }
    mint& operator--() {
        if (_v == 0) _v = umod();
        _v--;
        return *this;
    }
    mint operator++(int) {
        mint result = *this;
        ++*this;
        return result;
    }
    mint operator--(int) {
        mint result = *this;
        --*this;
        return result;
    }

    mint& operator+=(const mint& rhs) {
        _v += rhs._v;
        if (_v >= umod()) _v -= umod();
        return *this;
    }
    mint& operator-=(const mint& rhs) {
        _v -= rhs._v;
        if (_v >= umod()) _v += umod();
        return *this;
    }
    mint& operator*=(const mint& rhs) {
        unsigned long long z = _v;
        z *= rhs._v;
        _v = (unsigned int)(z % umod());
        return *this;
    }
    mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); }

    mint operator+() const { return *this; }
    mint operator-() const { return mint() - *this; }

    mint pow(long long n) const {
        assert(0 <= n);
        mint x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    mint inv() const {
        if (prime) {
            assert(_v);
            return pow(umod() - 2);
        } else {
            auto eg = internal::inv_gcd(_v, m);
            assert(eg.first == 1);
            return eg.second;
        }
    }

    friend mint operator+(const mint& lhs, const mint& rhs) {
        return mint(lhs) += rhs;
    }
    friend mint operator-(const mint& lhs, const mint& rhs) {
        return mint(lhs) -= rhs;
    }
    friend mint operator*(const mint& lhs, const mint& rhs) {
        return mint(lhs) *= rhs;
    }
    friend mint operator/(const mint& lhs, const mint& rhs) {
        return mint(lhs) /= rhs;
    }
    friend bool operator==(const mint& lhs, const mint& rhs) {
        return lhs._v == rhs._v;
    }
    friend bool operator!=(const mint& lhs, const mint& rhs) {
        return lhs._v != rhs._v;
    }

  private:
    unsigned int _v;
    static constexpr unsigned int umod() { return m; }
    static constexpr bool prime = internal::is_prime<m>;
};



using modint998244353 = static_modint<998244353>;
using modint1000000007 = static_modint<1000000007>;

namespace internal {

template <class T>
using is_static_modint = std::is_base_of<internal::static_modint_base, T>;

template <class T>
using is_static_modint_t = std::enable_if_t<is_static_modint<T>::value>;



}  // namespace internal

}  // namespace atcoder


#line 4 "/Users/nok0/Documents/Programming/nok0/math/factorial.hpp"

#line 6 "/Users/nok0/Documents/Programming/nok0/math/factorial.hpp"


#line 3 "/Users/nok0/Documents/Programming/nok0/math/modint_iostream.hpp"

#line 5 "/Users/nok0/Documents/Programming/nok0/math/modint_iostream.hpp"
template <int m>
std::istream &std::operator>>(std::istream &is, atcoder::static_modint<m> &a) {
	long long v;
	is >> v;
	a = v;
	return is;
}
template <int m>
std::ostream &std::operator<<(std::ostream &os, const atcoder::static_modint<m> &a) { return os << a.val(); }
#line 5 "a.cpp"

using mint = atcoder::static_modint<2>;

void main_() {
	INT(n);
	matrix<mint> mat(n);
	REP(i, n) {
		VEC(int, a, n);
		REP(j, n) { mat[i][j] = a[j]; }
	}
	VEC(mint, vec, n);
	INT(t);
	mat ^= t;

	auto p = linear_equation_mint(mat, vec);

	if(p.first.empty()) {
		print("none");
		return;
	}

	if(p.second != n) {
		print("ambiguous");
		return;
	}

	print(p.first);
}
accuracy: 1
time_ms: 1610
memory_kb: 4168
final_rank: 13

code_snippet: #pragma GCC ta g("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//#include <atcoder/maxflow>
//using namespace atcoder;
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-9;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const int MAX_ROW = 510; // to be set appropriately
const int MAX_COL = 510; // to be set appropriately
struct BitMatrix {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
    inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
};

int GaussJordan(BitMatrix &A, bool is_extended = false) {
    int rank = 0;
    for (int col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        int pivot = -1;
        for (int row = rank; row < A.H; ++row) {
            if (A[row][col]) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rank]);
        for (int row = 0; row < A.H; ++row) {
            if (row != rank && A[row][col]) A[row] ^= A[rank];
        }
        ++rank;
    }
    return rank;
}

int linear_equation(BitMatrix A, vector<int> b, vector<int> &res) {
    int m = A.H, n = A.W;
    BitMatrix M(m, n + 1);
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) M[i][j] = A[i][j];
        M[i][n] = b[i];
    }
    int rank = GaussJordan(M, true);

    // check if it has no solution
    for (int row = rank; row < m; ++row) if (M[row][n]) return -1;

    // answer
    res.assign(n, 0);
    for (int i = 0; i < rank; ++i) res[i] = M[i][n];
    return rank;
}

vvl matmul(vvl &a, vvl &b){
	vvl c(a.size(), vl(b[0].size()));
	for(int i=0; i<a.size(); i++){
		for(int k=0; k<b.size(); k++){
			for(int j=0; j<b[0].size(); j++){
				c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % 2;
			}
		}
	}
	return c;
}

vvl matpow(vvl a, ll n){
	vvl b(a.size(), vl(a.size()));
	for(int i=0; i<a.size(); i++) b[i][i] = 1;
	while(n > 0){
		if(n & 1) b = matmul(b,a);
		a = matmul(a,a);
		n >>= 1;
	}
	return b;
}

int main(){
	int n; cin >> n;
	BitMatrix A(n,n);
	vvl a(n,vl(n));
	rep(i,n) rep(j,n) cin >> a[i][j];
	vector<int> b(n);
	rep(i,n) cin >> b[i];
	int t; cin >> t;
	a = matpow(a,t);
	vector<int> res;
	rep(i,n) rep(j,n) A[i][j] = a[i][j]; 
	int ran = linear_equation(A,b,res);
	if(ran == -1){
		cout << "none\n";
		return 0;
	}
	if(ran == n){
		rep(i,n) cout << res[i] << " \n"[i==n-1];
	}else{
		cout << "ambiguous\n";
	}
}
accuracy: 1
time_ms: 750
memory_kb: 6088
final_rank: 14

code_snippet: #pragma GCC ta g("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//#include <atcoder/maxflow>
//using namespace atcoder;
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-9;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const int MAX_ROW = 510; // to be set appropriately
const int MAX_COL = 510; // to be set appropriately
struct BitMatrix {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
    inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
};

int GaussJordan(BitMatrix &A, bool is_extended = false) {
    int rank = 0;
    for (int col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        int pivot = -1;
        for (int row = rank; row < A.H; ++row) {
            if (A[row][col]) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rank]);
        for (int row = 0; row < A.H; ++row) {
            if (row != rank && A[row][col]) A[row] ^= A[rank];
        }
        ++rank;
    }
    return rank;
}

int linear_equation(BitMatrix A, vector<int> b, vector<int> &res) {
    int m = A.H, n = A.W;
    BitMatrix M(m, n + 1);
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) M[i][j] = A[i][j];
        M[i][n] = b[i];
    }
    int rank = GaussJordan(M, true);

    // check if it has no solution
    for (int row = rank; row < m; ++row) if (M[row][n]) return -1;

    // answer
    res.assign(n, 0);
    for (int i = 0; i < rank; ++i) res[i] = M[i][n];
    return rank;
}

vvl matmul(vvl &a, vvl &b){
	vvl c(a.size(), vl(b[0].size()));
	for(int i=0; i<a.size(); i++){
		for(int k=0; k<b.size(); k++){
			for(int j=0; j<b[0].size(); j++){
				c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod;
			}
		}
	}
	return c;
}

vvl matpow(vvl a, ll n){
	vvl b(a.size(), vl(a.size()));
	for(int i=0; i<a.size(); i++) b[i][i] = 1;
	while(n > 0){
		if(n & 1) b = matmul(b,a);
		a = matmul(a,a);
		n >>= 1;
	}
	return b;
}

int main(){
	int n; cin >> n;
	BitMatrix A(n,n);
	vvl a(n,vl(n));
	rep(i,n) rep(j,n) cin >> a[i][j];
	vector<int> b(n);
	rep(i,n) cin >> b[i];
	int t; cin >> t;
	a = matpow(a,t);
	vector<int> res;
	rep(i,n) rep(j,n) A[i][j] = a[i][j]; 
	int ran = linear_equation(A,b,res);
	if(ran == -1){
		cout << "none\n";
		return 0;
	}
	if(ran == n){
		rep(i,n) cout << res[i] << " \n"[i==n-1];
	}else{
		cout << "ambiguous\n";
	}
}
accuracy: 0.32727272727272727
time_ms: 450
memory_kb: 4812
final_rank: 19

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long MOD = 1000000007;
constexpr long long MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

constexpr int sz = 301;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	vector<vector<bitset<sz>>>tapi(30, vector<bitset<sz>>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> K;
			if (K) {
				tapi[0][i].flip(j);
			}
		}
	}
	vector<int>w(N);
	for (int i = 0; i < N; i++)cin >> w[i];
	cin >> T;
	vector<bitset<sz>>box(N);
	for (int i = 1; i < 30; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				if (tapi[i - 1][j][k]) {
					tapi[i][j] ^= tapi[i - 1][k];
				}
			}
		}
	}
	for (int i = 0; i < N; i++) {
		box[i].flip(i);
	}
	for (int i = 0; i < 30; i++) {
		if (T >> i & 1) {
			for (int j = 0; j < N; j++) {
				bitset<sz>bs;
				for (int k = 0; k < N; k++) {
					if (box[j][k]) {
						bs ^= tapi[i][k];
					}
				}
				box[j] = bs;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (w[i])box[i].flip(sz - 1);
	}
	vector<int>used(N);
	//for (auto i : box)cout << i << endl;
	bool no = false;
	bool ng = false;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (used[j])continue;
			if (box[j].test(i)) {
				used[j] = 1;
				swap(box[i], box[j]);
				swap(used[i], used[j]);
				for (int k = 0; k < N; k++) {
					if (i == k)continue;
					if (box[k].test(i)) {
						box[k] ^= box[i];
					}
				}
				break;
			}
		}
	}
	//for (auto i : box)cout << i << endl;
	for (int i = 0; i < N; i++) {
		if (box[i].test(i))continue;
		no = true;
		if (box[i].test(sz - 1))ng = true;
	}
	if (ng) {
		cout << "none\n";
		return 0;
	}
	if (no) {
		cout << "ambiguous\n";
		return 0;
	}
	for (int i = 0; i < N; i++) {
		if (i)cout << " ";
		cout << box[i][sz - 1];
	}
	cout << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3608
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
vector<vector<int>> matrix_multiplication(vector<vector<int>> A, vector<vector<int>> B){
  int N = A.size();
  vector<vector<int>> C(N, vector<int>(N, 0));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      for (int k = 0; k < N; k++){
        C[i][k] ^= A[i][j] & B[j][k];
      }
    }
  }
  return C;
}
vector<vector<int>> matrix_exponentiation(vector<vector<int>> A, int b){
  int N = A.size();
  vector<vector<int>> ans(N, vector<int>(N, 0));
  for (int i = 0; i < N; i++){
    ans[i][i] = 1;
  }
  while (b > 0){
    if (b % 2 == 1){
      ans = matrix_multiplication(ans, A);
    }
    A = matrix_multiplication(A, A);
    b /= 2;
  }
  return ans;
}
int main(){
  int N;
  cin >> N;
  vector<vector<int>> a(N, vector<int>(N));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      cin >> a[i][j];
    }
  }
  vector<int> v(N);
  for (int i = 0; i < N; i++){
    cin >> v[i];
  }
  int T;
  cin >> T;
  a = matrix_exponentiation(a, T);
  for (int i = 0; i < N; i++){
    a[i].push_back(v[i]);
  }
  for (int i = 0; i < N; i++){
    int p = -1;
    for (int j = i; j < N; j++){
      if (a[j][i] == 1){
        p = j;
      }
    }
    if (p != -1){
      swap(a[i], a[p]);
      for (int j = 0; j < N; j++){
        if (j != i && a[j][i] == 1){
          for (int k = i; k <= N; k++){
            if (a[i][k] == 1){
              a[j][k] ^= 1;
            }
          }
        }
      }
    }
  }
  bool ok1 = true, ok2 = true;
  for (int i = 0; i < N; i++){
    bool zero = true;
    for (int j = 0; j < N; j++){
      if (a[i][j] == 1){
        zero = false;
      }
    }
    if (zero){
      ok2 = false;
      if (a[i][N] == 1){
        ok1 = false;
      }
    }
  }
  if (!ok1){
    cout << "none" << endl;
  } else if (!ok2){
    cout << "ambiguous" << endl;
  } else {
    for (int i = 0; i < N; i++){
      cout << a[i][N];
      if (i < N - 1){
        cout << ' ';
      }
    }
    cout << endl;
  }
}
accuracy: 1
time_ms: 660
memory_kb: 5048
final_rank: 8

code_snippet: #include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;

struct Matrix{
	int h, w;
	vector<llint> mat;
	Matrix(){
		h = w = 0;
	}
	Matrix(int h, int w){
		this->h = h, this->w = w;
		mat.resize(h*w);
	}
	llint& at(int i, int j){
		return mat[w*(i-1)+(j-1)];
	}
	static Matrix ident(int size){
		Matrix ret(size, size);
		for(int i = 1; i <= size; i++) ret.at(i, i) = 1;
		return ret;
	}
	Matrix operator*(Matrix& ope){
		Matrix ret(h, ope.w);
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= ope.w; j++){
				for(int k = 1; k <= w; k++){
					ret.at(i, j) ^= at(i, k) & ope.at(k, j);
				}
			}
		}
		return ret;
	}
	Matrix pow(llint n){
		if(n == 0) return ident(h);
		if(n % 2){
			return pow(n-1) * (*this);
		}
		else{
			Matrix tmp = pow(n/2);
			return tmp * tmp;
		}
	}
	void print(){
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= w; j++){
				cout << at(i, j) << " ";
			}
			cout << endl;
		}
	}
};

void swapRows(int mat[305][305], int i, int j, int w)
{
	for(int k = 1; k <= w+1; k++) swap(mat[i][k], mat[j][k]);
}
void GaussianElimination(int mat[305][305], int w, int h)
{
	int r = 1;
	for(int i = 1; i <= w && r <= h; i++){
		if(mat[i][r] == 0){
			int max_val = 0, max_j;
			for(int j = r+1; j <= h; j++){
				if(mat[j][i] > max_val){
					max_val = mat[j][i];
					max_j = j;
				}
			}
			if(max_val == 0) goto end;
			swapRows(mat, r, max_j, w);
		}
		
		for(int j = 1; j <= h; j++){
			if(j == r) continue;
			if(mat[j][i] == 0) continue;
			for(int k = 1; k <= w+1; k++){
				mat[j][k] ^= mat[r][k];
			}
		}
		r++;
		end:;
	}
}


ll n, T;
ll v[305];
int a[305][305];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	Matrix mat(n, n);
	rep(i, 1, n) rep(j, 1, n) cin >> mat.at(i, j);
	rep(i, 1, n) cin >> v[i];
	cin >> T;
	
	Matrix pmat = mat.pow(T);
	
	rep(i, 1, n){
		rep(j, 1, n){
			a[i][j] = pmat.at(i, j);
		}
		a[i][n+1] = v[i];
	}
	GaussianElimination(a, n, n);
	
	if(a[n][n] == 0){
		rep(i, 1, n){
			ll x = 0;
			rep(j, 1, n) x |= a[i][j];
			if(x == 0 && a[i][n+1]){
				cout << "none" << endl;
				return 0;
			}
		}
		cout << "ambiguous" << endl;
		return 0;
	}
	
	rep(i, 1, n){
		cout << a[i][n+1];
		if(i < n) cout << " ";
	}
	cout << endl;
	
	return 0;
}
accuracy: 1
time_ms: 730
memory_kb: 5464
final_rank: 11

code_snippet: #include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;

struct Matrix{
	int h, w;
	vector<llint> mat;
	Matrix(){
		h = w = 0;
	}
	Matrix(int h, int w){
		this->h = h, this->w = w;
		mat.resize(h*w);
	}
	llint& at(int i, int j){
		return mat[w*(i-1)+(j-1)];
	}
	static Matrix ident(int size){
		Matrix ret(size, size);
		for(int i = 1; i <= size; i++) ret.at(i, i) = 1;
		return ret;
	}
	Matrix operator*(Matrix& ope){
		Matrix ret(h, ope.w);
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= ope.w; j++){
				for(int k = 1; k <= w; k++){
					ret.at(i, j) ^= at(i, k) & ope.at(k, j);
				}
			}
		}
		return ret;
	}
	Matrix pow(llint n){
		if(n == 0) return ident(h);
		if(n % 2){
			return pow(n-1) * (*this);
		}
		else{
			Matrix tmp = pow(n/2);
			return tmp * tmp;
		}
	}
	void print(){
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= w; j++){
				cout << at(i, j) << " ";
			}
			cout << endl;
		}
	}
};

void swapRows(int mat[305][305], int i, int j, int w)
{
	for(int k = 0; k <= w; k++) swap(mat[i][k], mat[j][k]);
}
void GaussianElimination(int mat[305][305], int w, int h)
{
	int r = 0;
	for(int i = 0; i < w && r < h; i++){
		if(mat[i][r] == 0){
			int max_val = 0, max_j;
			for(int j = r+1; j < h; j++){
				if(mat[j][i] > max_val){
					max_val = mat[j][i];
					max_j = j;
				}
			}
			if(max_val == 0) goto end;
			swapRows(mat, r, max_j, w);
		}
		
		for(int j = 0; j < h; j++){
			if(j == r) continue;
			if(mat[j][i] == 0) continue;
			for(int k = 0; k <= w; k++){
				mat[j][k] ^= mat[r][k];
			}
		}
		r++;
		end:;
	}
}


ll n, T;
ll v[305];
int a[305][305];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	Matrix mat(n, n);
	rep(i, 1, n) rep(j, 1, n) cin >> mat.at(i, j);
	rep(i, 1, n) cin >> v[i];
	cin >> T;
	
	Matrix pmat = mat.pow(T);
	
	rep(i, 1, n){
		rep(j, 1, n){
			a[i-1][j-1] = pmat.at(i, j);
		}
		a[i-1][n] = v[i];
	}
	GaussianElimination(a, n, n);
	
	if(a[n-1][n-1] == 0){
		rep(i, 0, n-1){
			ll x = 0;
			rep(j, 0, n-1) x |= a[i][j];
			if(x == 0 && a[i][n]){
				cout << "none" << endl;
				return 0;
			}
		}
		cout << "ambiguous" << endl;
		return 0;
	}
	
	/*rep(i, 0, n-1){
		rep(j, 0, n){
			cout << a[i][j];
		}
		cout << endl;
	}*/
	
	rep(i, 0, n-1){
		cout << a[i][n];
		if(i < n-1) cout << " ";
	}
	cout << endl;
	
	return 0;
}
accuracy: 1
time_ms: 730
memory_kb: 5468
final_rank: 12

code_snippet: #include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;

struct Matrix{
	int h, w;
	vector<llint> mat;
	Matrix(){
		h = w = 0;
	}
	Matrix(int h, int w){
		this->h = h, this->w = w;
		mat.resize(h*w);
	}
	llint& at(int i, int j){
		return mat[w*(i-1)+(j-1)];
	}
	static Matrix ident(int size){
		Matrix ret(size, size);
		for(int i = 1; i <= size; i++) ret.at(i, i) = 1;
		return ret;
	}
	Matrix operator*(Matrix& ope){
		Matrix ret(h, ope.w);
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= ope.w; j++){
				for(int k = 1; k <= w; k++){
					ret.at(i, j) ^= at(i, k) & ope.at(k, j);
				}
			}
		}
		return ret;
	}
	Matrix pow(llint n){
		if(n == 0) return ident(h);
		if(n % 2){
			return pow(n-1) * (*this);
		}
		else{
			Matrix tmp = pow(n/2);
			return tmp * tmp;
		}
	}
	void print(){
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= w; j++){
				cout << at(i, j) << " ";
			}
			cout << endl;
		}
	}
};

void swapRows(int mat[305][305], int i, int j, int w)
{
	for(int k = 0; k < w; k++) swap(mat[i][k], mat[j][k]);
}
void GaussianElimination(int mat[305][305], int w, int h)
{
	int r = 0;
	for(int i = 0; i < w && r < h; i++){
		if(mat[i][r] == 0){
			int max_val = 0, max_j;
			for(int j = r+1; j < h; j++){
				if(mat[j][i] > max_val){
					max_val = mat[j][i];
					max_j = j;
				}
			}
			if(max_val == 0) goto end;
			swapRows(mat, r, max_j, w);
		}
		
		for(int j = 0; j < h; j++){
			if(j == r) continue;
			if(mat[j][i] == 0) continue;
			for(int k = 0; k < w; k++){
				mat[j][k] ^= mat[r][k];
			}
		}
		r++;
		end:;
	}
}


ll n, T;
ll v[305];
int a[305][305];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	Matrix mat(n, n);
	rep(i, 1, n) rep(j, 1, n) cin >> mat.at(i, j);
	rep(i, 1, n) cin >> v[i];
	cin >> T;
	
	Matrix pmat = mat.pow(T);
	
	rep(i, 1, n){
		rep(j, 1, n){
			a[i-1][j-1] = pmat.at(i, j);
		}
		a[i-1][n] = v[i];
	}
	GaussianElimination(a, n+1, n);
	
	if(a[n-1][n-1] == 0){
		rep(i, 0, n-1){
			ll x = 0;
			rep(j, 0, n-1) x |= a[i][j];
			if(x == 0 && a[i][n]){
				cout << "none" << endl;
				return 0;
			}
		}
		cout << "ambiguous" << endl;
		return 0;
	}
	
	rep(i, 0, n-1){
		cout << a[i][n];
		if(i < n-1) cout << " ";
	}
	cout << endl;
	
	return 0;
}
accuracy: 0.9818181818181818
time_ms: 730
memory_kb: 5448
final_rank: 17

code_snippet: #include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#include <complex>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18

using namespace std;

typedef long long llint;
typedef long long ll;
typedef pair<llint, llint> P;

struct Matrix{
	int h, w;
	vector<llint> mat;
	Matrix(){
		h = w = 0;
	}
	Matrix(int h, int w){
		this->h = h, this->w = w;
		mat.resize(h*w);
	}
	llint& at(int i, int j){
		return mat[w*(i-1)+(j-1)];
	}
	static Matrix ident(int size){
		Matrix ret(size, size);
		for(int i = 1; i <= size; i++) ret.at(i, i) = 1;
		return ret;
	}
	Matrix operator*(Matrix& ope){
		Matrix ret(h, ope.w);
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= ope.w; j++){
				for(int k = 1; k <= w; k++){
					ret.at(i, j) ^= at(i, k) & ope.at(k, j);
				}
			}
		}
		return ret;
	}
	Matrix pow(llint n){
		if(n == 0) return ident(h);
		if(n % 2){
			return pow(n-1) * (*this);
		}
		else{
			Matrix tmp = pow(n/2);
			return tmp * tmp;
		}
	}
	void print(){
		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= w; j++){
				cout << at(i, j) << " ";
			}
			cout << endl;
		}
	}
};

void swapRows(int mat[305][305], int i, int j, int w)
{
	for(int k = 0; k < w; k++) swap(mat[i][k], mat[j][k]);
}
void GaussianElimination(int mat[305][305], int w, int h)
{
	int r = 0;
	for(int i = 0; i < w && r < h; i++){
		if(mat[i][r] == 0){
			int max_val = 0, max_j;
			for(int j = r+1; j < h; j++){
				if(mat[j][i] > max_val){
					max_val = mat[j][i];
					max_j = j;
				}
			}
			if(max_val == 0) goto end;
			swapRows(mat, r, max_j, w);
		}
		
		for(int j = 0; j < h; j++){
			if(j == r) continue;
			if(mat[j][i] == 0) continue;
			for(int k = 0; k <= w; k++){
				mat[j][k] ^= mat[r][k];
			}
		}
		r++;
		end:;
	}
}


ll n, T;
ll v[305];
int a[305][305];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	Matrix mat(n, n);
	rep(i, 1, n) rep(j, 1, n) cin >> mat.at(i, j);
	rep(i, 1, n) cin >> v[i];
	cin >> T;
	
	Matrix pmat = mat.pow(T);
	
	rep(i, 1, n){
		rep(j, 1, n){
			a[i-1][j-1] = pmat.at(i, j);
		}
		a[i-1][n] = v[i];
	}
	GaussianElimination(a, n+1, n);
	
	if(a[n-1][n-1] == 0){
		rep(i, 0, n-1){
			ll x = 0;
			rep(j, 0, n-1) x |= a[i][j];
			if(x == 0 && a[i][n]){
				cout << "none" << endl;
				return 0;
			}
		}
		cout << "ambiguous" << endl;
		return 0;
	}
	
	rep(i, 0, n-1){
		cout << a[i][n];
		if(i < n-1) cout << " ";
	}
	cout << endl;
	
	return 0;
}
accuracy: 0.9818181818181818
time_ms: 730
memory_kb: 5456
final_rank: 18

code_snippet: #include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

template <unsigned int mod>
class ModInt {
private:
    unsigned int v;
    static unsigned int norm(const unsigned int& x){ return x < mod ? x : x - mod; }
    static ModInt make(const unsigned int& x){ ModInt m; return m.v = x, m; }
    static ModInt inv(const ModInt& x){ return make(inverse(x.v, mod)); }
    static unsigned int inverse(int a, int m){
        int u[] = {a, 1, 0}, v[] = {m, 0, 1}, t;
        while(*v){
            t = *u / *v;
            swap(u[0] -= t * v[0], v[0]), swap(u[1] -= t * v[1], v[1]), swap(u[2] -= t * v[2], v[2]);
        }
        return (u[1] % m + m) % m;
    }

public:
    ModInt() : v{0}{}
    ModInt(const long long val) : v{norm(val % mod + mod)} {}
    ModInt(const ModInt<mod>& n) : v{n()} {}
    explicit operator bool() const noexcept { return v != 0; }
    bool operator!() const noexcept { return !static_cast<bool>(*this); }
    ModInt& operator=(const ModInt& n){ return v = n(), (*this); }
    ModInt& operator=(const long long val){ return v = norm(val % mod + mod), (*this); }
    ModInt operator+() const { return *this; }
    ModInt operator-() const { return v == 0 ? make(0) : make(mod - v); }
    ModInt operator+(const ModInt& val) const { return make(norm(v + val())); }
    ModInt operator-(const ModInt& val) const { return make(norm(v + mod - val())); }
    ModInt operator*(const ModInt& val) const { return make((long long)v * val() % mod); }
    ModInt operator/(const ModInt& val) const { return *this * inv(val); }
    ModInt& operator+=(const ModInt& val){ return *this = *this + val; }
    ModInt& operator-=(const ModInt& val){ return *this = *this - val; }
    ModInt& operator*=(const ModInt& val){ return *this = *this * val; }
    ModInt& operator/=(const ModInt& val){ return *this = *this / val; }
    ModInt operator+(const long long val) const { return ModInt{v + val}; }
    ModInt operator-(const long long val) const { return ModInt{v - val}; }
    ModInt operator*(const long long val) const { return ModInt{(long long)(v * (val % mod))}; }
    ModInt operator/(const long long val) const { return ModInt{(long long)v * inv(val)}; }
    ModInt& operator+=(const long long val){ return *this = *this + val; }
    ModInt& operator-=(const long long val){ return *this = *this - val; }
    ModInt& operator*=(const long long val){ return *this = *this * val; }
    ModInt& operator/=(const long long val){ return *this = *this / val; }
    bool operator==(const ModInt& val) const { return v == val.v; }
    bool operator!=(const ModInt& val) const { return !(*this == val); }
    bool operator==(const long long val) const { return v == norm(val % mod + mod); }
    bool operator!=(const long long val) const { return !(*this == val); }
    unsigned int operator()() const { return v; }
    friend ModInt operator+(const long long val, const ModInt& n) { return n + val; }
    friend ModInt operator-(const long long val, const ModInt& n) { return ModInt{val - n()}; }
    friend ModInt operator*(const long long val, const ModInt& n) { return n * val; }
    friend ModInt operator/(const long long val, const ModInt& n) { return ModInt{val} / n; }
    friend bool operator==(const long long val, const ModInt& n) { return n == val; }
    friend bool operator!=(const long long val, const ModInt& n) { return !(val == n); }
    friend istream& operator>>(istream& is, ModInt& n){
        unsigned int v;
        return is >> v, n = v, is;
    }
    friend ostream& operator<<(ostream& os, const ModInt& n){ return (os << n()); }
    friend ModInt mod_pow(ModInt x, long long n){
        ModInt ans = ((mod == 1) ? 0 : 1);
        while(n){
            if(n & 1) ans *= x;
            x *= x, n >>= 1;
        }
        return ans;
    }
};

using mod = ModInt<MOD>;

template<typename T> class mat : public vector<vector<T> > {
private:
    int r, c;    //行,列
public:
    inline int row() const {
        return r;
    }
    inline int column() const {
        return c;
    }
    mat(int n, int m, T val = 0){
        r = n, c = m;
        for(int i = 0; i < n; i++){
            this->push_back(vector<T>(m, val));
        }
    }
    mat operator+(const mat& another) const {
        if(r != another.r && c != another.c){
            cout << "足し算失敗(サイズ不一致)" << endl;
            exit(1);
        }
        mat<T> X(r, c);
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                X[i][j] = (*this)[i][j] + another[i][j];
            }
        }
        return X;
    }
    mat operator+(const T val) const {
        mat<T> X(r, c);
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                X[i][j] = (*this)[i][j] + val;
            }
        }
        return X;
    }
    mat operator-(const mat& another) const {
        if(r != another.r && c != another.c){
            cout << "引き算失敗(サイズ不一致)" << endl;
            exit(1);
        }
        mat<T> X(r, c);
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                X[i][j] = (*this)[i][j] - another[i][j];
            }
        }
        return X;
    }
    mat operator-(const T val) const {
        mat<T> X(r, c);
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                X[i][j] = (*this)[i][j] - val;
            }
        }
        return X;
    }
    vector<T> operator*(const vector<T>& another) const {
        if(c != (int)another.size()){
            cout << "掛け算失敗(サイズ不一致)" << endl;
            exit(1);
        }
        vector<T> vec(r,0);
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                vec[i] += (*this)[i][j] * another[j];
            }
        }
        return vec;
    }
    mat operator*(const mat& another) const {
        if(c != another.r){
            cout << "掛け算失敗(サイズ不一致)" << endl;
            exit(1);
        }
        mat<T> X(r, another.c);
        for(int i = 0; i < r; i++){
            for(int k = 0; k < c; k++){
                for(int j = 0; j < (another.c); j++){
                    X[i][j] += (*this)[i][k] * another[k][j];
                }
            }
        }
        return X;
    }
    mat operator-() const {
        mat<T> X(r, c);
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                X[i][j] = -(*this)[i][j];
            }
        }
        return X;
    }
    int rank() const {
        int res = 0;
        mat B(r, c);
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                B[i][j] = (*this)[i][j];
            }
        }
        for(int i = 0; i < c; i++){
            if(res == r) return res;
            int pivot = res;
            for(int j = res; j < r; j++){
                if(B[j][i]){
                    pivot = j;
                    break;
                }
            }
            if(!B[pivot][i]) continue;
            swap(B[pivot], B[res]);
            const T d = (T)1 / B[res][i];
            for(int j = i + 1; j < c; j++){
                B[res][j] *= d;
            }
            for(int j = res + 1; j < r; j++){
                for(int k = i + 1; k < c; k++){
                    B[j][k] -= B[res][k] * B[j][i];
                }
            }
            ++res;
        }
        return res;
    }
    T det() const {
        if(r != c){
            cout << "正方行列でない(行列式定義不可)" << endl;
            exit(1);
        }
        T ans = 1;
        mat B(r, r);
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                B[i][j] = (*this)[i][j];
            }
        }
        for(int i = 0; i < c; i++){
            int pivot = i;
            for(int j = i; j < r; j++){
                if(B[j][i]){
                    pivot = j;
                    break;
                }
            }
            if(!B[pivot][i]) return (T)0;
            if(pivot != i) swap(B[i], B[pivot]), ans = -ans;
            ans *= B[i][i];
            const T d = (T)1 / B[i][i];
            for(int j = i + 1; j < c; j++){
                B[i][j] *= d;
            }
            for(int j = i + 1; j < r; j++){
                for(int k = i + 1; k < c; k++){
                    B[j][k] -= B[i][k] * B[j][i];
                }
            }
        }
        return ans;
    }
    mat inverse() const {
        if(r != c){
            cout << "正方行列でない(逆行列定義不可)" << endl;
            exit(1);
        }
        mat B(r, 2*r);
        for(int i = 0; i < r; i++){
            for(int j = 0; j < r; j++){
                B[i][j] = (*this)[i][j];
            }
        }
        for(int i = 0; i < r; i++){
            B[i][r+i] = 1;
        }
        for(int i = 0; i < r; i++){
            int pivot = i;
            for(int j = i; j < r; j++){
                if(B[j][i]){
                    pivot = j;
                    break;
                }
            }
            if(!B[pivot][i]){
                cout << "正則でない" << endl;
                exit(1);
            }
            swap(B[i], B[pivot]);
            const T d = (T)1 / B[i][i];
            for(int j = i + 1; j < 2*r; j++){
                B[i][j] *= d;
            }
            for(int j = 0; j < r; j++){
                if(i != j){
                    for(int k = i + 1; k < 2*r; k++){
                        B[j][k] -= B[i][k] * B[j][i];
                    }
                }
            }
        }
        mat res(r, r);
        for(int i = 0; i < r; i++){
            for(int j = 0; j < r; j++){
                res[i][j] = B[i][r+j];
            }
        }
        return res;
    }
    inline void print() const {
        for(int i = 0; i < r; i++){
            for(int j = 0; j < (c-1); j++){
                cout << (*this)[i][j] << ",";
            }
            cout << (*this)[i][c-1] << endl;
        }
    }
};

template<typename T> vector<T> eq_solve(const mat<T>& A, const vector<T>& b){
    if(A.row() != A.column()){
        cout << "正方行列でない(解なしor不定)" << endl;
        exit(1);
    }
    int n = A.row();
    mat<T> B(n, n+1);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            B[i][j] = A[i][j];
        }
    }
    for(int i = 0; i < n; i++){
        B[i][n] = b[i];
    }
    for(int i = 0; i < n; i++){
        int pivot = i;
        for(int j = i; j < n; j++){
            if(B[j][i]){
                pivot = j;
                break;
            }
        }
        if(!B[pivot][i]){
            cout << "解なしor不定" << endl;
            exit(1);
        }
        swap(B[i], B[pivot]);
        const T d = (T)1 / B[i][i];
        for(int j = i + 1; j <= n; j++){
            B[i][j] *= d;
        }
        for(int j = 0; j < n; j++){
            if(i != j){
                for(int k = i + 1; k <= n; k++){
                    B[j][k] -= B[i][k] * B[j][i];
                }
            }
        }
    }
    vector<T> res(n);
    for(int i = 0; i < n; i++){
        res[i] = B[i][n];
    }
    return res;
}

template<typename T> mat<T> pow(mat<T> A, long long cnt)
{
    if(A.row() != A.column()){
        cout << "累乗不可" << endl;
    }
    int n = A.row();
    mat<T> B(n, n);
    for(int i = 0; i < n; i++){
        B[i][i] = 1;
    }
    while(cnt > 0){
		if(cnt & 1) B = B * A;
        A = A * A;
        cnt >>= 1;
    }
    return B;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    mat<mod> A(n, n), B(n, n+1);
    vector<mod> v(n);
    rep(i,n){
        rep(j,n){
            cin >> A[i][j];
        }
    }
    rep(i,n){
        cin >> v[i];
        B[i][n] = v[i];
    }
    int T;
    cin >> T;
    mat<mod> AA = pow(A, T);
    rep(i,n){
        rep(j,n){
            B[i][j] = AA[i][j];
        }
    }
    int ar = AA.rank(), br = B.rank();
    // cout << ar << " " << br << "\n";
    if(ar == br){
        if(ar < n){
            cout << "ambiguous\n";
        }else{
            vector<mod> ans = AA.inverse() * v;
            rep(i,n-1){
                cout << ans[i] << " ";
            }
            cout << ans[n-1] << "\n";
        }
    }else{
        cout << "none\n";
    }
    return 0;
}
accuracy: 0.2727272727272727
time_ms: 30
memory_kb: 3568
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=15;
const int INF=1<<30;
//const ll INF=1LL<<60;

typedef vector<vector<int>> mat;
typedef vector<int> vec;

bool flag=false;

vec gauss_jordan(const mat& A,const vec &b){
    int n=A.size();
    mat B(n,vec(n+1));
    
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) B[i][j]=A[i][j];
    
    for(int i=0;i<n;i++) B[i][n]=b[i];
    
    int rank=0;
    
    for(int j=0;j<n;j++){
        int pivot=-1;
        
        for(int i=rank;i<n;i++){
            if(B[i][j]){
                pivot=i;
                break;
            }
        }
        
        if(pivot==-1) continue;
        
        swap(B[pivot],B[rank]);
        
        for(int i=0;i<n;i++){
            if(i!=rank){
                if(B[i][j]){
                    for(int k=0;k<=n;k++) B[i][k]^=B[rank][k];
                }
            }
        }
        
        rank++;
    }
    
    bool ok=true;
    
    for(int i=rank;i<n;i++){
        if(B[i][n]) ok=false;
    }
    
    if(!ok) return vec();
    
    //cout<<rank<<endl;
    
    if(rank!=n) flag=true;
    
    vec x(n);
    
    for(int i=0;i<rank;i++) x[i]=B[i][n];
    return x;
}


mat mul(mat &A, mat&B){
    mat C(A.size(),vector<int>(B[0].size()));
    for(int i=0;i<A.size();i++){
        for(int k=0;k<B.size();k++){
            for(int j=0;j<B[0].size();j++){
                C[i][j]=(C[i][j]^(A[i][k]&B[k][j]))%mod;
            }
        }
    }
    return C;
}

mat pow(mat A,ll n){
    mat B(A.size(),vector<int>(A.size()));
    for(int i=0;i<A.size();i++){
        B[i][i]=1;
    }
    
    while(n>0){
        if(n&1) B=mul(B,A);
        A=mul(A,A);
        n/=2;
    }
    return B;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<vector<int>> A(N,vector<int>(N));
    for(int i=0;i<N;i++) for(int j=0;j<N;j++) cin>>A[i][j];
    vector<int> v(N);
    for(int i=0;i<N;i++) cin>>v[i];
    ll T;cin>>T;
    A=pow(A,T);
    
    vector<int> ans=gauss_jordan(A,v);
    
    if(si(ans)==0) cout<<"none"<<endl;
    else if(flag) cout<<"ambiguous"<<endl;
    else{
        for(int i=0;i<si(ans);i++){
            if(i) cout<<" ";
            cout<<ans[i];
        }
        cout<<endl;
    }
}
accuracy: 1
time_ms: 1040
memory_kb: 4672
final_rank: 10

code_snippet: #include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 303

int mat[N][N], vs[N], xs[N];
int res[N][N], tmp[N][N], mat_t[N][N];
int t;

void matmul(int n, int mat_a[N][N], int mat_b[N][N], int mat_c[N][N]) {
  for(int i=0; i<n; ++i) {
    for(int j=0; j<n; ++j) {
      mat_c[i][j] = 0;
      for(int k=0; k<n; ++k) mat_c[i][j] ^= (mat_a[i][k] & mat_b[k][j]);
    }
  }
}

int el_mat[N][N+1];
int gaussian_elimination(int n, int mat[N][N], int bs[N], int xs[N]) {
  for(int i=0; i<n; ++i) {
    for(int j=0; j<n; ++j) el_mat[i][j] = mat[i][j];
    el_mat[i][n] = bs[i];
  }
  int cur = 0;
  for(int i=0; i<n; ++i) {
    if(el_mat[cur][i] == 0) {
      int k = cur+1;
      while(k < n && el_mat[k][i] == 0) k++;
      if(k == n) continue;
      for(int j=0; j<n+1; ++j) swap(el_mat[cur][j], el_mat[k][j]);
    }
    for(int j=cur+1; j<n; ++j) {
      if(el_mat[j][i]) {
        for(int k=i; k<n+1; ++k) el_mat[j][k] ^= el_mat[cur][k];
      }
    }
    ++cur;
  }
  if(cur == n) {
    for(int i=n-1; i>=0; --i) {
      xs[i] = el_mat[i][n];
      for(int j=i+1; j<n; ++j) {
        xs[i] ^= (el_mat[i][j] & xs[j]);
      }
    }
    return 1;
  }
  bool ok = true;
  for(int i=cur; i<n; ++i) {
    if(el_mat[i][n] != 0) {
      return 0;
    }
  }
  return 2;
}

int main() {
  int n;
  cin >> n;
  rep(i, n) rep(j, n) cin >> mat[i][j];
  rep(i, n) cin >> vs[i];
  cin >> t;

  rep(i, n) rep(j, n) res[i][j] = (i == j);
  while(t) {
    if(t & 1) {
      matmul(n, res, mat, tmp);
      rep(i, n) rep(j, n) res[i][j] = tmp[i][j];
    }
    matmul(n, mat, mat, mat_t);
    rep(i, n) rep(j, n) mat[i][j] = mat_t[i][j];
    t >>= 1;
  }
  int st = gaussian_elimination(n, res, vs, xs);
  if(st == 1) {
    rep(i, n) {
      if(i) cout << " ";
      cout << xs[i];
    }
    cout << endl;
  } else if(st == 2) {
    cout << "ambiguous" << endl;
  } else {
    cout << "none" << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 760
memory_kb: 4896
final_rank: 9