Problem:
D: xor Paradise
問題
非負整数を要素とする $K$ 個の配列があり、$i$ 番目の配列 $A_i$ の要素数は $N_i$ である。
いちごくんはこの中から一つの配列を選択し、その配列から $0$ 個以上 $N_i$ 個以下の要素を取り出し、それらの
xor
をとって一つ整数を作ることができる。ただし、$0$ 個の要素の xor は $0$ と定義する。
いちごくんが作ることができる整数の種類数を求めよ。
入力形式
$K$
$N_1$ $\ldots$ $N_K$
$A_{1, 1}$ $\ldots$ $A_{1, N_1}$
$\vdots$
$A_{K, 1}$ $\ldots$ $A_{K, N_K}$
制約
$1 \leq K \leq 14$
$1 \leq N_i \leq 10{,}000$
$1 \leq A_{i, j} \lt 10^{18}$
入力は全て整数で与えられる。
出力形式
答えを一行に出力し、最後に改行を入れてください。
入力例 1
2
2 3
2 8
4 16 32
出力例 1
11
一つ目の配列では $0,2,8,10$ を作ることができ、二つ目の配列では $0,4,16,20,32,36,48,52$ を作ることができます。
したがって、合計 $11$ 種類の整数を作ることができます。
入力例 2
2
5 6
91 5 35 74 85
73 96 47 82 32 29
出力例 2
56

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmin(T& a, T b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool chmax(T& a, T b) {
  return a < b ? a = b, true : false;
}
template <typename T>
concept Iterable = requires(T t) {
  std::begin(t);
  std::end(t);
};
template <typename T>
  requires Iterable<T> && (!is_same_v<T, string>)
ostream& operator<<(ostream& os, const T& container) {
  for (auto& element : container) os << element << ' ';
  return os;
}
template <typename R>
  requires ranges::range<R> && (!is_same_v<decay_t<R>, string>) &&
           (!is_same_v<decay_t<R>, const char*>)
ostream& operator<<(ostream& os, R&& range) {
  for (auto& element : range) os << element << ' ';
  return os;
}
template <typename T>
  requires Iterable<T> && (!is_same_v<T, string>)
istream& operator>>(std::istream& is, T& container) {
  for (auto& e : container) is >> e;
  return is;
}
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
template <class T = ll>
struct Edge {
  int to;
  T weight;
  bool operator==(Edge e) {
    return this->to == e.to and this->weight == e.weight;
  }
  bool operator<(Edge e) {
    return this->to == e.to ? this->weight < e.weight : this->to < e.to;
  }
};
#ifdef _DEBUG
#define SHOW(n)                         \
  {                                     \
    const auto& _ret = n;               \
    cerr << #n << ": " << _ret << endl; \
  }
#define MSG(x) cerr << x << endl;
#else
#define SHOW(n)
#define MSG(x)
#endif

////AtCoder Library
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint998244353;
////using mint = modint1000000007;
////using mint1 = dynamic_modint<0>;
////using mint = modint;
////mint::set_mod();
// istream& operator>>(istream& is, mint& x) { ll r; is >> r; x = r; return is;
// } ostream& operator<<(ostream& os, mint& x) { os << x.val(); return os; }

// boost
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using l3 = int128_t;

constexpr int m = 63;

vector<ll> base(const vector<ll>& a) {
  vector<ll> basis;
  for (auto e : a) {
    for (auto b : basis) chmin(e, e ^ b);
    for(auto& b : basis)chmin(b, e ^ b);
    if (e) basis.push_back(e);
  }
  return basis;
}

ull dot(ull v, ull w) { return popcount(v & w) % 2; }

vector<ll> f(const vector<ll>& a) {
  auto basis = base(a);
  ll s = 0;
  vector<ll> top;
  for (ll x : basis) {
    if (popcount(ull(x)) != 1) x = (bit_ceil(ull(x)) >> 1);
    s |= x;
    top.push_back(countr_zero(ull(x)));
  }

  vector<ll> res;
  for (int i = 0; i < m; ++i) {
    if ((1ll << i) & s) continue;
    ll w = (1ll << i);
    for (int j = 0; j < basis.size(); ++j) {
      ll e = basis[j];
      w ^= (dot(e, w) << top[j]);  
    }
    res.push_back(w);
  }

  return res;
}

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

  int k;
  cin >> k;
  vector<int> n(k);
  cin >> n;
  vector<vector<ll>> a(k);
  for (int i = 0; i < k; ++i) {
    a[i].resize(n[i]);
    cin >> a[i];
  }

  vector<vector<ll>> v(k);
  vector<ll> r(1 << k);
  for (uint bit = 1; bit < (1 << k); ++bit) {
    int p = popcount(bit);
    if (p == 1) {
      int i = countr_zero(bit);
      v[i] = f(a[i]);
    }

    vector<ll> basis;

    for (int i = 0; i < k; ++i) {
      if ((bit & (1 << i)) == 0) continue;
      basis.insert(basis.end(), v[i].begin(), v[i].end());
    }

    basis = base(basis);

    const int dimx = m;
    int dimk = basis.size();

    int dim = dimx - dimk;
    r[bit] = (1ll << dim);
  }

  ll res = 0;
  for (uint bit = 1; bit < (1 << k); ++bit) {
    int p = popcount(bit);
    if (p & 1)
      res += r[bit];
    else
      res -= r[bit];
  }

  cout << res << endl;

  return 0;
}
accuracy: 1
time_ms: 420
memory_kb: 4864
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmin(T& a, T b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool chmax(T& a, T b) {
  return a < b ? a = b, true : false;
}
template <typename T>
concept Iterable = requires(T t) {
  std::begin(t);
  std::end(t);
};
template <typename T>
  requires Iterable<T> && (!is_same_v<T, string>)
ostream& operator<<(ostream& os, const T& container) {
  for (auto& element : container) os << element << ' ';
  return os;
}
template <typename R>
  requires ranges::range<R> && (!is_same_v<decay_t<R>, string>) &&
           (!is_same_v<decay_t<R>, const char*>)
ostream& operator<<(ostream& os, R&& range) {
  for (auto& element : range) os << element << ' ';
  return os;
}
template <typename T>
  requires Iterable<T> && (!is_same_v<T, string>)
istream& operator>>(std::istream& is, T& container) {
  for (auto& e : container) is >> e;
  return is;
}
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
template <class T = ll>
struct Edge {
  int to;
  T weight;
  bool operator==(Edge e) {
    return this->to == e.to and this->weight == e.weight;
  }
  bool operator<(Edge e) {
    return this->to == e.to ? this->weight < e.weight : this->to < e.to;
  }
};
#ifdef _DEBUG
#define SHOW(n)                         \
  {                                     \
    const auto& _ret = n;               \
    cerr << #n << ": " << _ret << endl; \
  }
#define MSG(x) cerr << x << endl;
#else
#define SHOW(n)
#define MSG(x)
#endif

////AtCoder Library
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint998244353;
////using mint = modint1000000007;
////using mint1 = dynamic_modint<0>;
////using mint = modint;
////mint::set_mod();
// istream& operator>>(istream& is, mint& x) { ll r; is >> r; x = r; return is;
// } ostream& operator<<(ostream& os, mint& x) { os << x.val(); return os; }

// boost
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using l3 = int128_t;

constexpr int m = 63;

vector<ll> base(const vector<ll>& a) {
  vector<ll> basis;
  for (auto e : a) {
    for (auto b : basis) chmin(e, e ^ b);
    for(auto& b : basis)chmin(b, e ^ b);
    if (e) basis.push_back(e);
  }
  ranges::sort(basis, ranges::greater());
  return basis;
}

ull dot(ull v, ull w) { return popcount(v & w) % 2; }

vector<ll> f(const vector<ll>& a) {
  auto basis = base(a);
  ll s = 0;
  vector<ll> top;
  for (ll x : basis) {
    if (popcount(ull(x)) != 1) x = (bit_ceil(ull(x)) >> 1);
    s |= x;
    top.push_back(countr_zero(ull(x)));
  }

  vector<ll> res;
  for (int i = 0; i < m; ++i) {
    if ((1ll << i) & s) continue;
    ll w = (1ll << i);
    for (int j = 0; j < basis.size(); ++j) {
      ll e = basis[j];
      w ^= (dot(e, w) << top[j]);  //?
    }
    res.push_back(w);
  }

  return res;
}

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

  int k;
  cin >> k;
  vector<int> n(k);
  cin >> n;
  vector<vector<ll>> a(k);
  for (int i = 0; i < k; ++i) {
    a[i].resize(n[i]);
    cin >> a[i];
  }

  vector<vector<ll>> v(k);
  vector<ll> r(1 << k);
  for (uint bit = 1; bit < (1 << k); ++bit) {
    int p = popcount(bit);
    if (p == 1) {
      int i = countr_zero(bit);
      v[i] = f(a[i]);
    }

    vector<ll> basis;

    for (int i = 0; i < k; ++i) {
      if ((bit & (1 << i)) == 0) continue;
      basis.insert(basis.end(), v[i].begin(), v[i].end());
    }

    basis = base(basis);

    const int dimx = m;
    int dimk = basis.size();

    int dim = dimx - dimk;
    r[bit] = (1ll << dim);
  }

  ll res = 0;
  for (uint bit = 1; bit < (1 << k); ++bit) {
    int p = popcount(bit);
    if (p & 1)
      res += r[bit];
    else
      res -= r[bit];
  }

  cout << res << endl;

  return 0;
}
accuracy: 1
time_ms: 430
memory_kb: 4864
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
template<class T> bool chmin(T& a, T b) { return a > b ? a = b, true : false; }
template<class T> bool chmax(T& a, T b) { return a < b ? a = b, true : false; }
template<typename T>
concept Iterable = requires(T t) { std::begin(t); std::end(t); };
template<typename T>
	requires Iterable<T> && (!is_same_v<T, string>)
ostream& operator<<(ostream& os, const T& container) { for (auto& element : container) os << element << ' '; return os; }
template<typename R>
	requires ranges::range<R> && (!is_same_v<decay_t<R>, string>) && (!is_same_v<decay_t<R>, const char*>)
ostream& operator<<(ostream& os, R&& range) { for (auto& element : range)os << element << ' '; return os; }
template<typename T>
	requires Iterable<T> && (!is_same_v<T, string>)
istream& operator>>(std::istream& is, T& container) { for (auto& e : container)is >> e; return is; }
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
template<class T = ll> struct Edge {
	int to;
	T weight;
	bool operator==(Edge e) { return this->to == e.to and this->weight == e.weight; }
	bool operator<(Edge e) { return this->to == e.to ? this->weight < e.weight : this->to < e.to; }
};
#ifdef _DEBUG
#define SHOW(n) {const auto& _ret = n; cerr << #n << ": " << _ret << endl;}
#define MSG(x) cerr << x << endl;
#else
#define SHOW(n)
#define MSG(x)
#endif

////AtCoder Library 
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint998244353;
////using mint = modint1000000007;
////using mint1 = dynamic_modint<0>;
////using mint = modint;
////mint::set_mod();
//istream& operator>>(istream& is, mint& x) { ll r; is >> r; x = r; return is; }
//ostream& operator<<(ostream& os, mint& x) { os << x.val(); return os; }

//boost
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//using l3 = int128_t;

vector<ll> base(const vector<ll>& a) {
	vector<ll> basis;
	for (auto e : a) {
		for (auto b : basis)chmin(e, e ^ b);
		if (e)basis.push_back(e);
	}
	return basis;
}

vector<ll> merge(const vector<ll>& a, const vector<ll>& b) {
	vector<ll> basis = a;
	vector<ll> res;
	for (int i = 0; i < b.size(); ++i) {
		auto e = b[i];
		for (auto x : basis)chmin(e, e ^ x);
		if (e)basis.push_back(e);
		else res.push_back(b[i]);
	}
	return res;
}


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

	int k;
	cin >> k;
	vector<int> n(k);
	cin >> n;
	vector<vector<ll>> a(k);
	for (int i = 0; i < k; ++i) {
		a[i].resize(n[i]);
		cin >> a[i];
	}

	vector<ll> r(1 << k);
	vector<vector<ll>> basis(1 << k);
	for (int bit = 1; bit < (1 << k); ++bit) {
		int p = popcount(ull(bit));
		if (p == 1) {
			int i = countr_zero(ull(bit));
			basis[bit] = base(a[i]);
		}
		else {
			int q = bit_ceil(ull(bit)) >> 1;
			int i = countr_zero(ull(q));
			basis[bit] = merge(basis[q], basis[bit ^ q]);
		}
		r[bit] = 1ll << basis[bit].size();
	}

	ll res = 0;
	for (int i = 0; i < (1 << k); ++i) {
		int p = popcount(ull(i));
		if (p & 1)res += r[i];
		else res -= r[i];
	}
	cout << res << endl;


	return 0;
}
accuracy: 0.723404255319149
time_ms: 90
memory_kb: 12928
final_rank: 20

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

#line 2 "/Users/Shared/po167_library/modint/mint61.hpp"

// https://qiita.com/keymoon/items/11fac5627672a6d6a9f6
namespace po167{
struct mint61{
    using u64 = unsigned long long;
    static constexpr u64 MOD = (1ULL << 61) - 1;
    static constexpr u64 MASK30 = (1ULL << 30) - 1;
    static constexpr u64 MASK31 = (1ULL << 31) - 1;
    u64  x;
    u64 calcmod(u64 a){
        u64 au = (a >> 61);
        u64 ad = (a & MOD);
        u64 res = au + ad;
        if (res >= MOD) res -= MOD;
        return res;
    }
    mint61(){ x = 0;}
    mint61(long long x_){
        while (x_ < 0) x_ += MOD;
        x = calcmod(x_);
    }
    mint61 &operator+=(mint61 b){
        if ((x += b.x) >= MOD) x -= MOD;
        return *this;
    }
    mint61 &operator-=(mint61 b){
        if (x >= b.x) x -= b.x;
        else{
            x += MOD;
            x -= b.x;
        }
        return *this;
    }
    mint61 &operator*=(mint61 b){
        u64 au = (x >> 31);
        u64 ad = (x & MASK31);
        u64 bu = (b.x >> 31);
        u64 bd = (b.x & MASK31);
        u64 mid = ad * bu + au * bd;
        u64 midu = (mid >> 30);
        u64 midd = (mid & MASK30);
        x = calcmod(au * bu * 2 + midu + (midd << 31) + ad * bd);
        return *this;
    }
    friend mint61 operator+(mint61 a, mint61 b){return a += b;}
    friend mint61 operator-(mint61 a, mint61 b){return a -= b;}
    friend mint61 operator*(mint61 a, mint61 b){return a *= b;}
    friend bool operator==(mint61 a, mint61 b){return a.x == b.x;}
    friend bool operator!=(mint61 a, mint61 b){return a.x != b.x;}
    mint61 pow(long long e) const {
        mint61 r = 1,b =*this;
        if (e < 0) e = MOD - 1 + e % (MOD - 1);
        while (e){
            if (e & 1) r *= b;
            b *= b;
            e >>= 1;
        }
        return r;
    }
};
}
#line 8 "b.cpp"

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

    int t = 1;
    // cin >> t;
    rep(i, 0, t) solve();
}

void solve(){
    auto f = [&](vector<ll> p, vector<ll> q) -> vector<ll> {
        int n = p.size();
        vector<ll> res;
        vector<pair<ll, ll>> B;
        rep(i, 0, n) B.push_back({p[i], p[i]});
        for (auto a : q){
            ll b = 0;
            rep(i, 0, B.size()){
                if (a > (a ^ B[i].first)){
                    b ^= B[i].second;
                    a ^= B[i].first;
                }
            }
            if (a) B.push_back({a, b});
            else res.push_back(b);
        }
        rep(i, 0, res.size()){
            rep(j, 0, i){
                res[i] = min(res[i], res[i] ^ res[j]);
            }
        }
        return res;
    };
    int K;
    cin >> K;
    vector<int> N(K);
    rep(i, 0, K) cin >> N[i];
    vector<vector<ll>> A(K);

    auto g = [&](vector<int> id, int debug = 0) -> int {
        set<ll> s;
        rep(a, 0, id.size()){
            set<ll> n_s;
            rep(i, 0, 1 << (int)A[id[a]].size()){
                ll tmp = 0;
                rep(k, 0, A[id[a]].size()) if (i & (1 << k)){
                    tmp ^= A[id[a]][k];
                }
                if (a == 0 || s.count(tmp)){
                    n_s.insert(tmp);
                }
            }
            swap(n_s, s);
        }
        if (debug) for (auto x : s) cout << x << " ";
        if (debug) cout << "\n";
        return s.size();
    };

    rep(i, 0, K){
        rep(rp, 0, N[i]){
            ll a;
            cin >> a;
            for (auto x : A[i]) a = min(a, x ^ a);
            if (a) A[i].push_back(a);
        }
    }
    po167::mint61 ans = 0;
    rep(s, 0, K){
        rep(j, 0, 1 << (K - s - 1)){
            auto v = A[s];
            vector<int> q = {s};
            po167::mint61 c = 1;
            rep(t, s + 1, K) if (j & (1 << (t - s - 1))){
                v = f(v, A[t]);
                c *= -1;
                q.push_back(t);
            }
            ans += (1ll << (int)(v.size())) * c;
        }
    }
    cout << ans.x << "\n";
}
/*
4
8 8 8 9
670386 214412 707012 284602 744903 632852 620870 581179
375722 230792 228387 707539 751264 587927 552022 17784
43814 281358 747872 199800 483897 89996 500597 799779
182120 81421 47835 741181 978775 198507 779903 622645 3636

 */
accuracy: 1
time_ms: 950
memory_kb: 3500
final_rank: 18

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep3(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep2(i, a, b) rep3(i, a, b, 1)
#define rep1(i, n) rep2(i, 0, n)
#define rep0(n) rep1(aaaaa, n)
#define ov4(a, b, c, d, name, ...) name
#define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define per(i, a, b) for (ll i = (a) - 1; i >= (b); i--)
#define fore(e, v) for (auto&& e : v)
#define all(a) begin(a), end(a)
#define sz(a) (int)(size(a))
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define eb emplace_back

template <typename T, typename S>
bool chmin(T& a, const S& b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
bool chmax(T& a, const S& b) {
  return a < b ? a = b, 1 : 0;
}
const int INF = 1e9 + 100;
const ll INFL = 3e18 + 100;
#define i128 __int128_t
struct _ {
  _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }
} __;

struct f2_vector_space {
  vector<i128> basis;

  f2_vector_space() = default;

  i128 add(i128 x) {
    for (const i128& b : basis) x = min(x, x ^ b);

    if (x) {
      basis.push_back(x);
      return x;
    } else {
      return i128(0);
    }
  }
};

vl f2_intersection(const vl& A,
                             const vl& B) {
  f2_vector_space tmp;
  for (ll a : A) tmp.add(((i128)a << 64) + a);

  vl ret;

  for (ll b : B) {
    i128 v = (i128)b << 64;

    auto u = tmp.add(v);
    if (u < ((i128)1 << 64)) ret.push_back(u);
  }

  return ret;
}

int main() {
  int K;
  cin >> K;
  vi N(K);
  fore(i, N) cin >> i;
  vector<vl> B(K);
  rep(i, K) {
    rep(j, N[i]) {
      ll b;
      cin >> b;
      fore(bs, B[i]) { chmin(b, b^bs); }
      if (b != 0) B[i].eb(b);
    }
  }
  // fore(i,B){
  //   fore(j,i)cerr<<j<<' ';
  //   cerr<<endl;
  // }
  ll ans=0;
  rep(s, 1,1 << K) {
    vl b;
    bool f=1;
    rep(i,K){
      if(s>>i&1){
        if(f)b=B[i],f=0;
        else b=f2_intersection(b,B[i]);
      }
    }
    // cerr<<s<<' '<<b.size()<<'\n';
    if(__builtin_popcount(s)%2){
      ans+=(1ll<<sz(b));
    }else{
      ans-=(1ll<<sz(b));
    }
  }
  cout<<ans<<'\n';
}
accuracy: 1
time_ms: 720
memory_kb: 3584
final_rank: 16

code_snippet: /**
	author:  shobonvip
	created: 2025.05.08 18:25:43
**/

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}


vector<ll> merge_base(const vector<ll> &a, const vector<ll> &b) {
	vector<__int128> base;
	for (ll z: a) {
		__int128 x = z;
		x |= x << 60;
		for (__int128 y: base) {
			x = min(x, y^x);
		}		
		if (x > 0) base.push_back(x);
	}
	for (ll z: b) {
		__int128 x = z;
		x <<= 60;
		for (__int128 y: base) {
			x = min(x, y^x);
		}
		if (x > 0) base.push_back(x);
	}
	vector<ll> ret;
	rep(i,0,(int)base.size()) {
		if (base[i] < (1LL<<60)) {
			ret.push_back(
				static_cast<ll>(base[i])
			);
		}
	}
	return ret;
	

}

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

	int k; cin >> k;
	vector<int> ns(k);
	rep(i,0,k) cin >> ns[i];
	vector bases(k,vector<ll>(0));
	rep(i,0,k) {
		rep(j,0,ns[i]){
			ll x;cin >>x;
			for(ll y:bases[i]){
				x=min(x,y^x);
			}
			if(x>0)bases[i].push_back(x);
		}
	}

	__int128 ans = 0;
	rep(i,1,1<<k) {
		bool first = true;
		ll tmp=-1;
		vector<ll> base;
		rep(j,0,k){
			if(i>>j&1) {
				tmp*=-1;
				if (first){
					base = bases[j];
					first = false;
				}else {
					base = merge_base(base, bases[j]);
				}
			}
		}
		ans += (1LL<<(int)base.size()) * tmp;
	}

	cout << static_cast<ll>(ans) << endl;
}
accuracy: 1
time_ms: 710
memory_kb: 3584
final_rank: 15

code_snippet: // AOJ #3277 xor Paradise
// 2025.2.23

#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;

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

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

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

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

vector<ull> makeBasis(const vector<ull>& arr) {
    vector<ull> basis;
    for(auto x : arr) {
        for(auto b : basis) x = min(x, x ^ b);
        if(x) basis.push_back(x);
    }
    sort(basis.begin(), basis.end(), greater<ull>());
    return basis;
}

ull reduceWithBasis(ull x, const vector<ull>& basis) {
    for(auto b : basis) x = min(x, x ^ b);
    return x;
}

vector<ull> intersectBasis(const vector<ull>& B, const vector<ull>& Y) {
    int r = B.size();
    vector<ull> R(r);
    for (int i = 0; i < r; i++) R[i] = reduceWithBasis(B[i], Y);

    vector<ull> basisR;
    for (int i = 0; i < r; i++) {
        ull cur = R[i];
        for (auto b : basisR) cur = min(cur, cur ^ b);
        if(cur) basisR.push_back(cur);
    }
    int rankR = basisR.size();
    int newDim = r - rankR;

    vector<ull> rvec = R;
    vector<ull> cmask(r);
    for (int i = 0; i < r; i++) cmask[i] = 1ULL << i;

    int pivot = 0;
    for (int bit = 63; bit >= 0 && pivot < r; bit--) {
        int pivotRow = -1;
        for (int i = pivot; i < r; i++) {
            if ( (rvec[i] >> bit) & 1ULL ) { pivotRow = i; break; }
        }
        if(pivotRow == -1) continue;
        swap(rvec[pivot], rvec[pivotRow]);
        swap(cmask[pivot], cmask[pivotRow]);
        for (int i = 0; i < r; i++) {
            if(i != pivot && ((rvec[i] >> bit) & 1ULL)) {
                rvec[i] ^= rvec[pivot];
                cmask[i] ^= cmask[pivot];
            }
        }
        pivot++;
    }
    vector<ull> solMasks;
    for (int i = 0; i < r; i++) {
        if(rvec[i] == 0) solMasks.push_back(cmask[i]);
    }
    vector<ull> interCandidates;
    for (auto mask : solMasks) {
        ull vec = 0;
        for (int j = 0; j < r; j++) {
            if((mask >> j) & 1ULL) vec ^= B[j];
        }
        interCandidates.push_back(vec);
    }
    vector<ull> newBasis = makeBasis(interCandidates);
    return newBasis;
}

int main(){
    int K = Cin();
    vector<int> N(K);
    for (int i = 0; i < K; i++) N[i] = Cin();
    vector<vector<ull>> bases(K);
    for (int i = 0; i < K; i++){
        vector<ull> arr(N[i]);
        for (int j = 0; j < N[i]; j++) arr[j] = Cinl();
        bases[i] = makeBasis(arr);
    }

    __int128 ans = 0;
    int total = 1 << K;
    for (int mask = 1; mask < total; mask++){
        vector<ull> curBasis;
        bool first = true;
        int bits = 0;
        for (int i = 0; i < K; i++){
            if(mask & (1 << i)){
                bits++;
                if(first){
                    curBasis = bases[i];
                    first = false;
                } else curBasis = intersectBasis(curBasis, bases[i]);
            }
        }
        int d = curBasis.size();
        ull sizeIntersection = 1ULL << d;
        if(bits & 1) ans += sizeIntersection;
        else         ans -= sizeIntersection;
    }

    string res;
    while(ans > 0) {
        int digit = (int)(ans % 10);
        res.push_back('0' + digit);
        ans /= 10;
    }
    if(res.empty()) res = "0";
    reverse(res.begin(), res.end());
    Couts(res);
    return 0;
}
accuracy: 1
time_ms: 930
memory_kb: 3512
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

vl noshi(vl a){
  vl base;
  for(auto p:a){
    for(auto b:base){
      chmin(p,b^p);
    }
    if(p)base.emplace_back(p);
  }
  return base;
}

//baseとbの共通空間をとり、その基底を返す
//https://onlinejudge.u-aizu.ac.jp/beta/room.html#HUPC2021Day1/problems/D
vl noshimerge(vl base,vl b){
  vl res;
  vpl base_p;
  for(auto v:base){
    base_p.emplace_back(v,0);
  }
  for(auto v:b){
    ll x=v;
    for(auto [u,t]:base_p){
      if(chmin(v,v^u)){
        x^=t;
      }
    }
    if(v)base_p.emplace_back(v,x);
    else {
        for(auto p:res)chmin(x,x^p);
        assert(x!=0);
        res.emplace_back(x);
    }
  }
  return res;
}

typedef __int128 lll;
  istream& operator>>(istream& i, lll& x) {
    x = 0;
    string s;
    i >> s;
    int N = s.size(), it = 0;
    if (s[0] == '-') it++;
    for (; it < N; it++) x = (x * 10 + s[it] - '0');
    if (s[0] == '-') x = -x;
    return i;
  }
  ostream& operator<<(ostream& o, const lll& x) {
    ll tmp = x;
    if (tmp == 0) return o << 0;
    if (tmp < 0) o << '-', tmp = -tmp;
    vector<int> ds;
    while (tmp) ds.push_back(tmp % 10), tmp /= 10;
    reverse(ds.begin(), ds.end());
    for (int d : ds) o << d;
    return o;
  }
int main(){
  ll n;cin >> n;
  vl m(n);rep(i,n)cin >> m[i];
  vvl dp(1<<n);
  rep(i,n){
    vl a;
    rep(_,m[i]){
      ll b;cin >> b;
      a.emplace_back(b);
    }
    dp[1<<i]=noshi(a);
  }
  lll ans=0;
  repl(bit,1,1<<n){
    if(__builtin_popcount(bit)==1){
      ans+=1LL<<(dp[bit].size());
      continue;
    }
    ll x=bit & -bit;
    ll y=bit^x;
    dp[bit]=noshimerge(dp[y],dp[x]);
    ans+=(1LL<<(dp[bit].size()))*(__builtin_popcount(bit)%2? 1:-1);
    /*if(dp[bit].size()>60){
      vl mle(INF);
    }*/
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 11816
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

vl noshi(vl a){
  vl base;
  for(auto p:a){
    for(auto b:base){
      chmin(p,b^p);
    }
    if(p)base.emplace_back(p);
  }
  return base;
}
vl noshimerge(vl base,vl b){//baseとbの共通空間をとる
  vl res;
  vpl base_p;
  for(auto v:base){
    base_p.emplace_back(v,0);
  }
  for(auto v:b){
    ll x=v;
    for(auto [u,t]:base_p){
      if(chmin(v,v^u)){
        x^=t;
      }
    }
    if(v)base_p.emplace_back(v,x);
    else {
        for(auto p:res)chmin(x,x^p);
        if(x)res.emplace_back(x);
    }
  }
  return res;
}
typedef __int128 lll;
  istream& operator>>(istream& i, lll& x) {
    x = 0;
    string s;
    i >> s;
    int N = s.size(), it = 0;
    if (s[0] == '-') it++;
    for (; it < N; it++) x = (x * 10 + s[it] - '0');
    if (s[0] == '-') x = -x;
    return i;
  }
  ostream& operator<<(ostream& o, const lll& x) {
    ll tmp = x;
    if (tmp == 0) return o << 0;
    if (tmp < 0) o << '-', tmp = -tmp;
    vector<int> ds;
    while (tmp) ds.push_back(tmp % 10), tmp /= 10;
    reverse(ds.begin(), ds.end());
    for (int d : ds) o << d;
    return o;
  }
int main(){
  ll n;cin >> n;
  vl m(n);rep(i,n)cin >> m[i];
  vvl dp(1<<n);
  rep(i,n){
    vl a;
    rep(_,m[i]){
      ll b;cin >> b;
      a.emplace_back(b);
    }
    dp[1<<i]=noshi(a);
  }
  lll ans=0;
  repl(bit,1,1<<n){
    if(__builtin_popcount(bit)==1){
      ans+=1LL<<(dp[bit].size());
      continue;
    }
    ll x=bit & -bit;
    ll y=bit^x;
    dp[bit]=noshimerge(dp[x],dp[y]);
    ans+=(1LL<<(dp[bit].size()))*(__builtin_popcount(bit)%2? 1:-1);
    /*if(dp[bit].size()>60){
      vl mle(INF);
    }*/
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 170
memory_kb: 11952
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

vl noshi(vl a){
  vl base;
  for(auto p:a){
    for(auto b:base){
      chmin(p,b^p);
    }
    if(p)base.emplace_back(p);
  }
  return base;
}
vl noshimerge(vl base,vl b){//baseとbの共通空間をとる
  vl res;
  vpl base_p;
  for(auto v:base){
    base_p.emplace_back(v,0);
  }
  for(auto v:b){
    ll x=v;
    for(auto [u,t]:base_p){
      if(chmin(v,v^u)){
        x^=t;
      }
    }
    if(v)base_p.emplace_back(v,x);
    else {
        for(auto p:res)chmin(x,x^p);
        if(x)res.emplace_back(x);
    }
  }
  return res;
}
typedef __int128 lll;
  istream& operator>>(istream& i, lll& x) {
    x = 0;
    string s;
    i >> s;
    int N = s.size(), it = 0;
    if (s[0] == '-') it++;
    for (; it < N; it++) x = (x * 10 + s[it] - '0');
    if (s[0] == '-') x = -x;
    return i;
  }
  ostream& operator<<(ostream& o, const lll& x) {
    ll tmp = x;
    if (tmp == 0) return o << 0;
    if (tmp < 0) o << '-', tmp = -tmp;
    vector<int> ds;
    while (tmp) ds.push_back(tmp % 10), tmp /= 10;
    reverse(ds.begin(), ds.end());
    for (int d : ds) o << d;
    return o;
  }
int main(){
  ll n;cin >> n;
  vl m(n);rep(i,n)cin >> m[i];
  vvl dp(1<<n);
  rep(i,n){
    vl a;
    rep(_,m[i]){
      ll b;cin >> b;
      a.emplace_back(b);
    }
    dp[1<<i]=noshi(a);
  }
  lll ans=0;
  repl(bit,1,1<<n){
    if(__builtin_popcount(bit)==1){
      ans+=1LL<<(dp[bit].size());
      continue;
    }
    ll x=bit & -bit;
    ll y=bit^x;
    dp[bit]=noshimerge(dp[y],dp[x]);
    ans+=(1LL<<(dp[bit].size()))*(__builtin_popcount(bit)%2? 1:-1);
    /*if(dp[bit].size()>60){
      vl mle(INF);
    }*/
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 180
memory_kb: 11952
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

vl noshi(vl a){
  vl base;
  for(auto p:a){
    for(auto b:base){
      chmin(p,b^p);
    }
    if(p)base.emplace_back(p);
  }
  return base;
}
vl noshimerge(vl base,vl b){//baseとbの共通空間をとる
  vl res;
  vpl base_p;
  for(auto v:base){
    base_p.emplace_back(v,0);
  }
  for(auto v:b){
    ll x=v;
    for(auto [u,t]:base_p){
      if(chmin(v,v^u)){
        x^=t;
      }
    }
    if(v)base_p.emplace_back(v,x);
    else res.emplace_back(x);
  }
  return res;
}
typedef __int128 lll;
  istream& operator>>(istream& i, lll& x) {
    x = 0;
    string s;
    i >> s;
    int N = s.size(), it = 0;
    if (s[0] == '-') it++;
    for (; it < N; it++) x = (x * 10 + s[it] - '0');
    if (s[0] == '-') x = -x;
    return i;
  }
  ostream& operator<<(ostream& o, const lll& x) {
    ll tmp = x;
    if (tmp == 0) return o << 0;
    if (tmp < 0) o << '-', tmp = -tmp;
    vector<int> ds;
    while (tmp) ds.push_back(tmp % 10), tmp /= 10;
    reverse(ds.begin(), ds.end());
    for (int d : ds) o << d;
    return o;
  }
int main(){
  ll n;cin >> n;
  vl m(n);rep(i,n)cin >> m[i];
  vvl dp(1<<n);
  rep(i,n){
    vl a;
    rep(_,m[i]){
      ll b;cin >> b;
      a.emplace_back(b);
    }
    dp[1<<i]=noshi(a);
  }
  lll ans=0;
  repl(bit,1,1<<n){
    if(__builtin_popcount(bit)==1){
      ans+=1LL<<(dp[bit].size());
      continue;
    }
    int x=bit & -bit;
    int y=bit^x;
    dp[bit]=noshimerge(dp[x],dp[y]);
    ans+=(1LL<<(dp[bit].size()))*(__builtin_popcount(bit)%2? 1:-1);
    /*if(dp[bit].size()>60){
      vl mle(INF);
    }*/
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 160
memory_kb: 11948
final_rank: 10

code_snippet: /**
 * date   : 2023-05-26 23:23:52
 * author : Nyaan
 */

#define NDEBUG

using namespace std;

// intrinstic
#include <immintrin.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

// utility

namespace Nyaan {
using ll = long long;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;

template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<vector<T>>;
using vi = vector<int>;
using vl = vector<long long>;
using vd = V<double>;
using vs = V<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;

template <typename T, typename U>
struct P : pair<T, U> {
  template <typename... Args>
  P(Args... args) : pair<T, U>(args...) {}

  using pair<T, U>::first;
  using pair<T, U>::second;

  P &operator+=(const P &r) {
    first += r.first;
    second += r.second;
    return *this;
  }
  P &operator-=(const P &r) {
    first -= r.first;
    second -= r.second;
    return *this;
  }
  P &operator*=(const P &r) {
    first *= r.first;
    second *= r.second;
    return *this;
  }
  template <typename S>
  P &operator*=(const S &r) {
    first *= r, second *= r;
    return *this;
  }
  P operator+(const P &r) const { return P(*this) += r; }
  P operator-(const P &r) const { return P(*this) -= r; }
  P operator*(const P &r) const { return P(*this) *= r; }
  template <typename S>
  P operator*(const S &r) const {
    return P(*this) *= r;
  }
  P operator-() const { return P{-first, -second}; }
};

using pl = P<ll, ll>;
using pi = P<int, int>;
using vp = V<pl>;

constexpr int inf = 1001001001;
constexpr long long infLL = 4004004004004004004LL;

template <typename T>
int sz(const T &t) {
  return t.size();
}

template <typename T, typename U>
inline bool amin(T &x, U y) {
  return (y < x) ? (x = y, true) : false;
}
template <typename T, typename U>
inline bool amax(T &x, U y) {
  return (x < y) ? (x = y, true) : false;
}

template <typename T>
inline T Max(const vector<T> &v) {
  return *max_element(begin(v), end(v));
}
template <typename T>
inline T Min(const vector<T> &v) {
  return *min_element(begin(v), end(v));
}
template <typename T>
inline long long Sum(const vector<T> &v) {
  return accumulate(begin(v), end(v), 0LL);
}

template <typename T>
int lb(const vector<T> &v, const T &a) {
  return lower_bound(begin(v), end(v), a) - begin(v);
}
template <typename T>
int ub(const vector<T> &v, const T &a) {
  return upper_bound(begin(v), end(v), a) - begin(v);
}

constexpr long long TEN(int n) {
  long long ret = 1, x = 10;
  for (; n; x *= x, n >>= 1) ret *= (n & 1 ? x : 1);
  return ret;
}

template <typename T, typename U>
pair<T, U> mkp(const T &t, const U &u) {
  return make_pair(t, u);
}

template <typename T>
vector<T> mkrui(const vector<T> &v, bool rev = false) {
  vector<T> ret(v.size() + 1);
  if (rev) {
    for (int i = int(v.size()) - 1; i >= 0; i--) ret[i] = v[i] + ret[i + 1];
  } else {
    for (int i = 0; i < int(v.size()); i++) ret[i + 1] = ret[i] + v[i];
  }
  return ret;
};

template <typename T>
vector<T> mkuni(const vector<T> &v) {
  vector<T> ret(v);
  sort(ret.begin(), ret.end());
  ret.erase(unique(ret.begin(), ret.end()), ret.end());
  return ret;
}

template <typename F>
vector<int> mkord(int N,F f) {
  vector<int> ord(N);
  iota(begin(ord), end(ord), 0);
  sort(begin(ord), end(ord), f);
  return ord;
}

template <typename T>
vector<int> mkinv(vector<T> &v) {
  int max_val = *max_element(begin(v), end(v));
  vector<int> inv(max_val + 1, -1);
  for (int i = 0; i < (int)v.size(); i++) inv[v[i]] = i;
  return inv;
}

vector<int> mkiota(int n) {
  vector<int> ret(n);
  iota(begin(ret), end(ret), 0);
  return ret;
}

template <typename T>
T mkrev(const T &v) {
  T w{v};
  reverse(begin(w), end(w));
  return w;
}

template <typename T>
bool nxp(vector<T> &v) {
  return next_permutation(begin(v), end(v));
}

template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

}  // namespace Nyaan


// bit operation

namespace Nyaan {
__attribute__((target("popcnt"))) inline int popcnt(const u64 &a) {
  return _mm_popcnt_u64(a);
}
inline int lsb(const u64 &a) { return a ? __builtin_ctzll(a) : 64; }
inline int ctz(const u64 &a) { return a ? __builtin_ctzll(a) : 64; }
inline int msb(const u64 &a) { return a ? 63 - __builtin_clzll(a) : -1; }
template <typename T>
inline int gbit(const T &a, int i) {
  return (a >> i) & 1;
}
template <typename T>
inline void sbit(T &a, int i, bool b) {
  if (gbit(a, i) != b) a ^= T(1) << i;
}
constexpr long long PW(int n) { return 1LL << n; }
constexpr long long MSK(int n) { return (1LL << n) - 1; }
}  // namespace Nyaan


// inout

namespace Nyaan {

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  int s = (int)v.size();
  for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i];
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}

istream &operator>>(istream &is, __int128_t &x) {
  string S;
  is >> S;
  x = 0;
  int flag = 0;
  for (auto &c : S) {
    if (c == '-') {
      flag = true;
      continue;
    }
    x *= 10;
    x += c - '0';
  }
  if (flag) x = -x;
  return is;
}

istream &operator>>(istream &is, __uint128_t &x) {
  string S;
  is >> S;
  x = 0;
  for (auto &c : S) {
    x *= 10;
    x += c - '0';
  }
  return is;
}

ostream &operator<<(ostream &os, __int128_t x) {
  if (x == 0) return os << 0;
  if (x < 0) os << '-', x = -x;
  string S;
  while (x) S.push_back('0' + x % 10), x /= 10;
  reverse(begin(S), end(S));
  return os << S;
}
ostream &operator<<(ostream &os, __uint128_t x) {
  if (x == 0) return os << 0;
  string S;
  while (x) S.push_back('0' + x % 10), x /= 10;
  reverse(begin(S), end(S));
  return os << S;
}

void in() {}
template <typename T, class... U>
void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}

void out() { cout << "\n"; }
template <typename T, class... U, char sep = ' '>
void out(const T &t, const U &...u) {
  cout << t;
  if (sizeof...(u)) cout << sep;
  out(u...);
}

struct IoSetupNya {
  IoSetupNya() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(7);
  }
} iosetupnya;

}  // namespace Nyaan


// debug


#ifdef NyaanDebug
#define trc(...) (void(0))
#else
#define trc(...) (void(0))
#endif

#ifdef NyaanLocal
#define trc2(...) (void(0))
#else
#define trc2(...) (void(0))
#endif


// macro

#define each(x, v) for (auto&& x : v)
#define each2(x, y, v) for (auto&& [x, y] : v)
#define all(v) (v).begin(), (v).end()
#define rep(i, N) for (long long i = 0; i < (long long)(N); i++)
#define repr(i, N) for (long long i = (long long)(N)-1; i >= 0; i--)
#define rep1(i, N) for (long long i = 1; i <= (long long)(N); i++)
#define repr1(i, N) for (long long i = (N); (long long)(i) > 0; i--)
#define reg(i, a, b) for (long long i = (a); i < (b); i++)
#define regr(i, a, b) for (long long i = (b)-1; i >= (a); i--)
#define fi first
#define se second
#define ini(...)   \
  int __VA_ARGS__; \
  in(__VA_ARGS__)
#define inl(...)         \
  long long __VA_ARGS__; \
  in(__VA_ARGS__)
#define ins(...)      \
  string __VA_ARGS__; \
  in(__VA_ARGS__)
#define in2(s, t)                           \
  for (int i = 0; i < (int)s.size(); i++) { \
    in(s[i], t[i]);                         \
  }
#define in3(s, t, u)                        \
  for (int i = 0; i < (int)s.size(); i++) { \
    in(s[i], t[i], u[i]);                   \
  }
#define in4(s, t, u, v)                     \
  for (int i = 0; i < (int)s.size(); i++) { \
    in(s[i], t[i], u[i], v[i]);             \
  }
#define die(...)             \
  do {                       \
    Nyaan::out(__VA_ARGS__); \
    return;                  \
  } while (0)


namespace Nyaan {
void solve();
}
int main() { Nyaan::solve(); }


//




using namespace std;

// MAX bit
template <typename Int, int MAX>
struct Basis {
  array<Int, MAX> v;

  Basis() : _size(0) { fill(begin(v), end(v), Int{0}); }
  Basis(const vector<Int>& a) : _size(0) {
    fill(begin(v), end(v), Int{0});
    for (auto& x : a) add(x);
  }
  const Int operator[](int i) const { return v[i]; }

  // 追加成功かどうかを返す
  bool add(Int x) {
    int t = _msb(x);
    assert(t < MAX);
    while (t != -1 && v[t]) t = _msb(x = x ^ v[t]);
    return t == -1 ? false : (v[t] = x, _size++, true);
  }

  void merge(const Basis& rhs) {
    for (int _t = MAX - 1; _t >= 0; _t--) {
      if (rhs.v[_t] == Int{0}) continue;
      int t = _t;
      Int x = rhs.v[t];
      while (t != -1 && v[t]) t = _msb(x = x ^ v[t]);
      if (x) v[t] = x, _size++;
    }
  }

  vector<Int> get_basis() const {
    vector<Int> res;
    for (int t = 0; t < MAX; t++) {
      if (v[t]) res.push_back(v[t]);
    }
    reverse(begin(res), end(res));
    return res;
  }

  // x を作れるか？
  bool test(Int x) {
    if (x == 0) return true;
    int t = _msb(x);
    if (t >= MAX) return false;
    while (v[t]) t = _msb(x = x ^ v[t]);
    return x == 0;
  }

  // 作れる x の最大値
  Int get_max() const {
    Int res = 0;
    for (int t = MAX - 1; t >= 0; t--) res = max(res, res ^ v[t]);
    return res;
  }

  // 行列を標準化する
  void normalize() {
    for (int t = MAX - 1; t >= 0; t--) {
      if (v[t]) {
        for (int u = MAX - 1; u > t; u--) v[u] = min(v[u], v[u] ^ v[t]);
      }
    }
  }

  vector<Int> orthogonal_complement(int N = MAX) {
    normalize();
    vector<int> b;
    for (int t = N - 1; t >= 0; t--) {
      if (v[t]) b.push_back(t);
    }
    int rank = b.size();
    for (int t = N - 1; t >= 0; t--) {
      if (!v[t]) b.push_back(t);
    }
    vector<Int> res(N - rank);
    for (int i = rank; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (j < rank ? ((v[b[j]] >> b[i]) & 1) : i == j) {
          res[i - rank] |= Int{1} << b[j];
        }
      }
    }
    return res;
  }

  int size() const { return _size; }

  friend ostream& operator<<(ostream& os, const Basis<Int, MAX>& b) {
    os << "{ ";
    for (int i = 0; i < MAX; i++) {
      if (b.v[i]) os << b.v[i] << ", ";
    }
    return os << "}";
  }

 private:
  int _size;
  int _msb(Int x) { return x ? 63 - __builtin_clzll(x) : -1; }
};

/*
 * @brief 掃き出し法
 */


//
using namespace Nyaan;

void q() {
  inl(N);
  vl S(N);
  in(S);
  vvl A(N);
  rep(i, N) {
    A[i].resize(S[i]);
    in(A[i]);
  }

  constexpr int MAX = 60;
  using Ba = Basis<ll, MAX>;

  V<Ba> ot(PW(N));
  u64 ans = 0;
  rep1(i, PW(N) - 1) {
    int t = msb(i);
    if (PW(t) == i) {
      ot[i] = Ba{Ba{A[t]}.orthogonal_complement()};
    } else {
      (ot[i] = ot[i - PW(t)]).merge(ot[PW(t)]);
    }
    trc(i, ot[i], sz(ot[i]));
    ans += (1LL << (MAX - sz(ot[i]))) * (popcnt(i) % 2 ? 1 : -1);
  }
  out(ans);
}

void Nyaan::solve() {
  int t = 1;
  // in(t);
  while (t--) q();
}
accuracy: 1
time_ms: 10
memory_kb: 12092
final_rank: 2

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int 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<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

// AOJ-3277
// https://drive.google.com/drive/u/2/folders/1gZBJHglPKtJR9h8ZRL2vd6MSQTxiqamZ
// D_2.pdf を参照
vector<ll> f2_orthogonal_complement(const int n, vector<ll> vec) {
    // n : 60
    // vecは基底を取ったものとする
    sort(vec.rbegin(), vec.rend());
    int m = vec.size();
    vector<int> top(m);
    ll exist = 0;
    int bit = n-1;
    for (int i = 0; i < m; ++i) {
        while (((1LL << bit) & vec[i]) == 0) {
            bit--;
        }
        top[i] = bit;
        exist |= (1LL << bit);
    }
    reverse(vec.begin(), vec.end());
    reverse(top.begin(), top.end());
    vector<ll> W;
    for (int i = 0; i < n; ++i) {
        if ((1LL << i) & exist) continue;
        ll w = (1LL << i);
        for (int j = 0; j < m; ++j) {
            if (__builtin_popcountll(vec[j]&w) & 1) {
                w ^= (1LL << top[j]);
            }
        }
        W.push_back(w);
    }
    return W;
};

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k; cin >> k;
    vector<int> sz(k);
    for (int i = 0; i < k; ++i) {
        cin >> sz[i];
    }
    vector<vector<ll>> B(k);
    for (int i = 0; i < k; ++i) {
        for (int j = 0; j < sz[i]; ++j) {
            ll a; cin >> a;
            for (ll b : B[i]) a = min(a, a^b);
            if (a != 0) B[i].push_back(a);
        }
    }

    const int N = 60;
    vector<vector<ll>> s(k);
    for (int i = 0; i < k; ++i) {
        s[i] = f2_orthogonal_complement(N, B[i]);
    }

    ll res = 0;
    for (int i = 1; i < (1 << k); ++i) {
        vector<ll> basis;
        for (int j = 0; j < k; ++j) {
            if ((1 << j) & i) {
                for (ll a : s[j]) {
                    for (ll &b : basis) {
                        a = min(a, a^b);
                    }
                    if (a) basis.push_back(a);
                }
            }
        }
        int dim = N - int(basis.size());
        if (__builtin_parity(i)) {
            res += (1LL << dim);
        }
        else {
            res -= (1LL << dim);
        }
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 210
memory_kb: 3472
final_rank: 1

code_snippet: //#define _GLIBCXX_DEBUG

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

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


#ifdef LOCAL
#include <debug_print.hpp>
#define OUT(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define OUT(...) (static_cast<void>(0))
#endif

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using QP = priority_queue<T,vector<T>,greater<T>>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T1,typename T2,typename T3>void anss(T1 x,T2 y,T3 z){ans(x!=y,x,z);};  
template<typename T>void debug(const T &v,ll h,ll w,string sv=" "){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout<<sv<<v[i][j];cout<<endl;}};
template<typename T>void debug(const T &v,ll n,string sv=" "){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout<<sv<<v[i];cout<<endl;};
template<typename T>void debug(const vector<T>&v){debug(v,v.size());}
template<typename T>void debug(const vector<vector<T>>&v){for(auto &vv:v)debug(vv,vv.size());}
template<typename T>void debug(stack<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(queue<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(deque<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop_front();}cout<<endl;}
template<typename T>void debug(PQ<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(QP<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(const set<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T>void debug(const multiset<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T,size_t size>void debug(const array<T, size> &a){for(auto z:a)cout<<z<<" ";cout<<endl;}
template<typename T,typename V>void debug(const map<T,V>&v){for(auto z:v)cout<<"["<<z.first<<"]="<<z.second<<",";cout<<endl;}
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << "(" << p.first << "," << p.second << ")";}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){os<<"[";for(auto &z:v)os << z << ",";os<<"]"; return os;}
template<typename T>void rearrange(vector<int>&ord, vector<T>&v){
  auto tmp = v;
  for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
}
template<typename Head, typename... Tail>void rearrange(vector<int>&ord,Head&& head, Tail&&... tail){
  rearrange(ord, head);
  rearrange(ord, tail...);
}
template<typename T> vector<int> ascend(const vector<T>&v){
  vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int i,int j){return make_pair(v[i],i)<make_pair(v[j],j);});
  return ord;
}
template<typename T> vector<int> descend(const vector<T>&v){
  vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int i,int j){return make_pair(v[i],-i)>make_pair(v[j],-j);});
  return ord;
}
template<typename T> vector<T> inv_perm(const vector<T>&ord){
  vector<T>inv(ord.size());
  for(int i=0;i<ord.size();i++)inv[ord[i]] = i;
  return inv;
}
ll FLOOR(ll n,ll div){assert(div>0);return n>=0?n/div:(n-div+1)/div;}
ll CEIL(ll n,ll div){assert(div>0);return n>=0?(n+div-1)/div:n/div;}
ll digitsum(ll n){ll ret=0;while(n){ret+=n%10;n/=10;}return ret;}
ll modulo(ll n,ll d){return (n%d+d)%d;};
template<typename T>T min(const vector<T>&v){return *min_element(v.begin(),v.end());}
template<typename T>T max(const vector<T>&v){return *max_element(v.begin(),v.end());}
template<typename T>T acc(const vector<T>&v){return accumulate(v.begin(),v.end(),T(0));};
template<typename T>T reverse(const T &v){return T(v.rbegin(),v.rend());};
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};
template<typename T>T poll(queue<T> &q){auto ret=q.front();q.pop();return ret;};
template<typename T>T poll(priority_queue<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(QP<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(stack<T> &s){auto ret=s.top();s.pop();return ret;};
ll MULT(ll x,ll y){if(LLONG_MAX/x<=y)return LLONG_MAX;return x*y;}
ll POW2(ll x, ll k){ll ret=1,mul=x;while(k){if(mul==LLONG_MAX)return LLONG_MAX;if(k&1)ret=MULT(ret,mul);mul=MULT(mul,mul);k>>=1;}return ret;}
ll POW(ll x, ll k){ll ret=1;for(int i=0;i<k;i++){if(LLONG_MAX/x<=ret)return LLONG_MAX;ret*=x;}return ret;}
template< typename T = int >
struct edge {
  int to;
  T cost;
  int id;
  edge():id(-1){};
  edge(int to, T cost = 1, int id = -1):to(to), cost(cost), id(id){}
  operator int() const { return to; }
};

template<typename T>
using Graph = vector<vector<edge<T>>>;
template<typename T>
Graph<T>revgraph(const Graph<T> &g){
  Graph<T>ret(g.size());
  for(int i=0;i<g.size();i++){
    for(auto e:g[i]){
      int to = e.to;
      e.to = i;
      ret[to].push_back(e);
    }
  }
  return ret;
}
template<typename T>
Graph<T> readGraph(int n,int m,int indexed=1,bool directed=false,bool weighted=false){
  Graph<T> ret(n);
  for(int es = 0; es < m; es++){
    int u,v;
    T w=1;
    cin>>u>>v;u-=indexed,v-=indexed;
    if(weighted)cin>>w;
    ret[u].emplace_back(v,w,es);
    if(!directed)ret[v].emplace_back(u,w,es);
  }
  return ret;
}
template<typename T>
Graph<T> readParent(int n,int indexed=1,bool directed=true){
  Graph<T>ret(n);
  for(int i=1;i<n;i++){
    int p;cin>>p;
    p-=indexed;
    ret[p].emplace_back(i);
    if(!directed)ret[i].emplace_back(p);
  }
  return ret;
}
template<typename T>
struct nazo_basis{
  vector<T>basis;
  nazo_basis() = default;
  ll rank(){return basis.size();};
  T insert(T k){
    for(auto b:basis)chmin(k, k^b);
    if(k){
      basis.push_back(k);
    }
    return k;
  }
  void insert(nazo_basis<T>basis){
    for(auto b:basis.basis){
      insert(b);
    }
  }
  bool include(T k){
    for(auto b:basis)chmin(k, k^b);
    return !k;
  }

  T subset_max(){
    T k=0;
    for(auto b:basis)chmax(k, k^b);
    return k;
  }
  nazo_basis<T>orthogonal_complement(int dim){
    nazo_basis<T>ret;
    vector<T>top(basis.size());
    T exist=0;
    for(int i=0;i<basis.size();i++){
      for(int j=dim-1;;j--){
        if(basis[i]>>j&1){
          top[i]=T(1)<<j;
          exist|=top[i];
          break;
        }
      }
      for(int j=0;j<i;j++){
        chmin(basis[j],basis[i]^basis[j]);
      }
    }
    for(int i=0;i<dim;i++){
      if(exist>>i&1)continue;
      T w=T(1)<<i;
      for(int j=0;j<basis.size();j++){
        if(__builtin_popcountll(basis[j]&w)&1){
          w^=top[j];
        }
      }
      ret.insert(w);
    }
    return ret;
  }

  void print(){
    for(auto b:basis)cout<<b<<" ";
    cout<<endl;
  }
};
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll k;cin>>k;
  vector<ll>n(k);
  rep(i,0,k)cin>>n[i];
  using B=nazo_basis<ll>;
  vector<B>b(k);
  ll sz=60;
  rep(i,0,k){
    rep(j,0,n[i]){
      ll a;cin>>a;
      b[i].insert(a);
    }
    b[i]=b[i].orthogonal_complement(sz);
  }
  rep(i,0,k){
    //b[i].print();
    auto tmp=b[i].orthogonal_complement(sz);
    //tmp.print();
  }
  __int128_t ret=0;
  rep(i,1,1<<k){
    B sb;
    rep(j,0,k){
      if(i>>j&1)sb.insert(b[j]);
      OUT(j,b[j].rank());
    }
    ll add=(1LL<<sz-sb.rank());
    OUT(i,add,sb.rank());
    sb=sb.orthogonal_complement(sz);
    //sb.print();
    if(popcount(i)&1)ret+=add;
    else ret-=add;
  }
  cout<<(ll)ret<<endl;
  return 0;
}
accuracy: 1
time_ms: 370
memory_kb: 3476
final_rank: 3

code_snippet: #line 1 "test/matrix/xor_bases/AOJ3277.test.cpp"
#define IGNORE // テストケースが取得できない

#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3277"

#line 2 "src/Template.hpp"

#define CUT
#include <bits/stdc++.h>

using namespace std;

#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define rrep(i, l, r) for (int i = (r); i --> (l);)
#define all(c) begin(c), end(c)

#ifdef LOCAL
#define debug(...) debug_impl(#__VA_ARGS__, __VA_ARGS__)
template <class H, class... Ts> void debug_impl(string s, H&& h, Ts&&... ts) {
  cerr << '(' << s << "): (" << forward<H>(h);
  ((cerr << ", " << forward<Ts>(ts)), ..., (cerr << ")\n"));
}
#else
#define debug(...) void(0)
#endif

template <class T> bool chmax(T& a, const T& b) { return b > a ? (a = b, true) : false; }
template <class T> bool chmin(T& a, const T& b) { return b < a ? (a = b, true) : false; }

template <class T> istream& operator>>(istream& in, vector<T>& v) {
  for (auto& e : v) in >> e;
  return in;
}
template <class ...Args> void read(Args&... args) {
  (cin >> ... >> args);
}
template <class T> ostream& operator<<(ostream& out, const vector<T>& v) {
  int n = v.size();
  rep(i, 0, n) {
    out << v[i];
    if (i + 1 != n) out << ' ';
  }
  return out;
}
template <class H, class ...Ts> void print(H&& h, Ts &&... ts) {
  cout << h, ((cout << ' ' << forward<Ts>(ts)), ..., (cout << '\n'));
}

struct io_setup_ {
  io_setup_() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cout << fixed << setprecision(10);
  }
} io_setup{};
#undef CUT

#define NOTE compile command: \texttt{g++ -std=gnu++17 -Wall -Wextra -g -fsanitize=address -fsanitize=undefined \$\{file\} -o \$\{fileDirname\}/\$\{fileBasenameNoExtension\}}
#undef NOTE
#define NOTE \texttt{-DLOCAL} を加えると \texttt{debug(...)} による出力が有効となる
#undef NOTE
#line 3 "src/matrix/XorBases.hpp"
#define CUT
template <class T>
struct XorBases {
  vector<T> bases;

  bool add(T v) {
    for (const auto& e : bases) chmin(v, e ^ v);
    return v ? (bases.push_back(v), true) : false;
  }

  XorBases intersec(const XorBases& rhs) const {
    vector<pair<T, T>> xs;
    for (const T& e : bases) xs.emplace_back(e, e);
    XorBases<T> res;
    for (T e : rhs.bases) {
      T s{};
      for (const auto& [v, t] : xs) {
        if (chmin(e, e ^ v)) s ^= t;
      }
      if (e) {
        xs.emplace_back(e, s);
      } else {
        res.add(s);
      }
    }
    return res;
  }
};
#undef CUT
#line 6 "test/matrix/xor_bases/AOJ3277.test.cpp"

int main() {
  int k;
  read(k);

  vector<int> siz(k);
  read(siz);

  vector<XorBases<uint64_t>> dp(1 << k);
  for (int i = 0; i < 60; ++i) {
    dp[0].add(uint64_t(1) << i);
  }
  for (int i = 0; i < k; ++i) {
    XorBases<uint64_t> b;
    for (int j = 0; j < siz[i]; ++j) {
      uint64_t v;
      read(v);
      b.add(v);
    }
    dp[1 << i] = b;
  }

  uint64_t ans = 0;
  for (int s = 1; s < 1 << k; ++s) {
    int pc = __builtin_popcount(s);
    if (pc > 1) {
      int l = s & -s, t = s ^ l;
      dp[s] = dp[t].intersec(dp[l]);
    }
    if (pc & 1) {
      ans += uint64_t(1) << dp[s].bases.size();
    } else {
      ans -= uint64_t(1) << dp[s].bases.size();
    }
  }
  print(ans);

  return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 12032
final_rank: 12

code_snippet: #define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3277"

#include <iostream>

#include <vector>

namespace suisen {
    template <typename T>
    struct XorBase {
        XorBase() = default;
        XorBase(const std::vector<T> &a) : XorBase() {
            for (const auto &v : a) add(v);
        }

        bool add(T v) {
            for (const auto &e : _basis) if (T w = e ^ v; w < v) v = std::move(w);
            return v ? (_basis.push_back(v), true) : false;
        }
        XorBase<T>& operator+=(const XorBase<T> &rhs) {
            for (const T &e : rhs._basis) add(e);
            return *this;
        }
        XorBase<T>& operator+=(const T &v) {
            add(v);
            return *this;
        }
        XorBase<T> operator+(const XorBase<T> &rhs) const {
            XorBase<T> res;
            res._basis = _basis;
            return res += rhs;
        }
        XorBase<T> operator+(const T &v) const {
            return *this + XorBase<T>({ v });
        }

        XorBase<T> intersection(const XorBase<T> &rhs) const {
            std::vector<std::pair<T, T>> basis;
            for (const T &e : _basis) basis.emplace_back(e, e);
            XorBase<T> res;
            for (T e : rhs._basis) {
                T s;
                if constexpr (std::is_integral_v<T>) s = 0;
                for (const auto &[v, t] : basis) if (T w = e ^ v; w < e) e = std::move(w), s ^= t;
                if (e) basis.emplace_back(e, s);
                else res.add(s);
            }
            return res;
        }
        XorBase<T>& operator&=(const XorBase<T> &rhs) {
            return *this = intersection(rhs);
        }
        XorBase<T> operator&(const XorBase<T> &rhs) const {
            return intersection(rhs);
        }

        int dim() const { return _basis.size(); }

        const std::vector<T>& get_basis() const { return _basis; }
    private:
        std::vector<T> _basis;
    };
} // namespace suisen

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

    int k;
    std::cin >> k;

    std::vector<int> siz(k);
    for (auto& e : siz) std::cin >> e;

    std::vector<suisen::XorBase<uint64_t>> dp(1 << k);
    for (int i = 0; i < 60; ++i) {
        dp[0] += uint64_t(1) << i;
    }
    for (int i = 0; i < k; ++i) {
        suisen::XorBase<uint64_t> b;
        for (int j = 0; j < siz[i]; ++j) {
            uint64_t v;
            std::cin >> v;
            b += v;
        }
        dp[1 << i] = b;
    }

    uint64_t ans = 0;
    for (int s = 1; s < 1 << k; ++s) {
        int pc = __builtin_popcount(s);
        if (pc > 1) {
            int l = s & -s, t = s ^ l;
            dp[s] = dp[t] & dp[l];
        }
        if (pc & 1) {
            ans += uint64_t(1) << dp[s].dim();
        } else {
            ans -= uint64_t(1) << dp[s].dim();
        }
    }
    std::cout << ans << std::endl;

    return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 12052
final_rank: 8

code_snippet: #line 2 "library/KowerKoint/base.hpp"

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define END(...) { print(__VA_ARGS__); return; }

using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using ll = long long;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
using VS = vector<string>;
using VVS = vector<VS>;
using VVVS = vector<VVS>;
using VC = vector<char>;
using VVC = vector<VC>;
using VVVC = vector<VVC>;
using P = pair<int, int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VVVP = vector<VVP>;
using LP = pair<ll, ll>;
using VLP = vector<LP>;
using VVLP = vector<VLP>;
using VVVLP = vector<VVLP>;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

constexpr int INF = 1001001001;
constexpr ll LINF = 1001001001001001001ll;
constexpr int DX[] = {1, 0, -1, 0};
constexpr int DY[] = {0, 1, 0, -1};

void print() { cout << '\n'; }
template<typename T>
void print(const T &t) { cout << t << '\n'; }
template<typename Head, typename... Tail>
void print(const Head &head, const Tail &... tail) {
    cout << head << ' ';
    print(tail...);
}

#ifdef ONLINE_JUDGE
template<typename... Args>
void dbg(const Args &... args) {}
#else
void dbg() { cerr << '\n'; }
template<typename T>
void dbg(const T &t) { cerr << t << '\n'; }
template<typename Head, typename... Tail>
void dbg(const Head &head, const Tail &... tail) {
    cerr << head << ' ';
    dbg(tail...);
}
#endif

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
    os << p.first << " " << p.second;
    return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
    is >> p.first >> p.second;
    return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
    for(int i = 0; i < (int) v.size(); i++) {
        os << v[i] << (i + 1 != (int) v.size() ? " " : "");
    }
    return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
    for(T &in : v) is >> in;
    return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template <typename T>
pair<VI, vector<T>> compress(const vector<T> &a) {
    int n = a.size();
    vector<T> x;
    REP(i, n) x.push_back(a[i]);
    sort(ALL(x)); x.erase(unique(ALL(x)), x.end());
    VI res(n);
    REP(i, n) res[i] = lower_bound(ALL(x), a[i]) - x.begin();
    return make_pair(res, x);
}

template <typename T>
pair<vector<T>, vector<T>> factorial(int n) {
    vector<T> res(n+1), rev(n+1);
    res[0] = 1;
    REP(i, n) res[i+1] = res[i] * (i+1);
    rev[n] = 1 / res[n];
    for(int i = n; i > 0; i--) {
        rev[i-1] = rev[i] * i;
    }
    return make_pair(res, rev);
}
#line 2 "Contests/Dummy/HUPC2021-day1/d/main.cpp"

/* #include <atcoder/all> */
/* using namespace atcoder; */
/* #include "KowerKoint/expansion/ac-library/all.hpp" */
/* #include "KowerKoint/math/matrix.hpp" */

void solve(){
    int k; cin >> k;
    VI n(k); cin >> n;
    VVL _a(k);
    REP(i, k) {
        _a[i].resize(n[i]);
        cin >> _a[i];
    }
    using Basis = set<ll, greater<ll>>;
    vector<Basis> a(k);
    REP(_, k) {
        sort(ALL(_a[_]));
        reverse(ALL(_a[_]));
        for(ll e : _a[_]) {
            for(ll b : a[_]) {
                chmin(e, e ^ b);
            }
            if(e) a[_].insert(e);
        }
    }
    ll ans = 0;
    vector<Basis> basises(1 << k);
    REP(_, 1 << k) {
        if(_ == 0) {
            continue;
        }
        VI indexes;
        REP(i, k) if(_ >> i & 1) indexes.push_back(i);
        if(indexes.size() == 1) {
            basises[_] = a[indexes[0]];
            ans += 1LL << a[indexes[0]].size();
            continue;
        }
        int index = indexes.back();
        set<LP, greater<LP>> mat;
        Basis basis;
        for(ll base : basises[_ ^ (1 << indexes.back())]) mat.emplace(base, 0LL);
        for(ll ai : a[index]) {
            ll ai_b = ai;
            for(auto [b, b_only] : mat) {
                if(chmin(ai, ai ^ b)) ai_b ^= b_only;
            }
            if(ai_b == 0) continue;
            if(ai == 0){
                basis.emplace(ai_b);
            }
            else {
                set<LP, greater<LP>> new_mat;
                for(auto [b, b_only] : mat) {
                    if(chmin(b, b^ai)) b_only ^= ai_b;
                    if(b) new_mat.emplace(b, b_only);
                }
                mat = new_mat;
                mat.emplace(ai, ai_b);
            }
        }
        for(ll e : basis) {
            for(ll b : basises[_]) chmin(e, e ^ b);
            if(e) basises[_].insert(e);
        }
        if(__builtin_popcount(_) % 2) {
            ans += 1LL << basises[_].size();
        }
        else ans -= 1LL << basises[_].size();
    }
    print(ans);
}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main() {
    // Fasterize input/output script
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(100);
    // scanf/printf user should delete this fasterize input/output script

    int t = 1;
    //cin >> t; // comment out if solving multi testcase
    for(int testCase = 1;testCase <= t;++testCase){
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 1980
memory_kb: 50912
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

vl noshi(vl a){
  vl base;
  for(auto p:a){
    for(auto b:base){
      chmin(p,b^p);
    }
    if(p)base.emplace_back(p);
  }
  return base;
}
vl noshimerge(vl base,vl b){//baseとbの共通空間をとる
  vl res;
  vpl base_p;
  for(auto v:base){
    base_p.emplace_back(v,0);
  }
  for(auto v:b){
    ll x=v;
    for(auto [u,t]:base_p){
      if(chmin(v,v^u)){
        x^=t;
      }
    }
    if(v)base_p.emplace_back(v,x);
    else res.emplace_back(x);
  }
  return res;
}
typedef __int128 lll;
  istream& operator>>(istream& i, lll& x) {
    x = 0;
    string s;
    i >> s;
    int N = s.size(), it = 0;
    if (s[0] == '-') it++;
    for (; it < N; it++) x = (x * 10 + s[it] - '0');
    if (s[0] == '-') x = -x;
    return i;
  }
  ostream& operator<<(ostream& o, const lll& x) {
    ll tmp = x;
    if (tmp == 0) return o << 0;
    if (tmp < 0) o << '-', tmp = -tmp;
    vector<int> ds;
    while (tmp) ds.push_back(tmp % 10), tmp /= 10;
    reverse(ds.begin(), ds.end());
    for (int d : ds) o << d;
    return o;
  }
int main(){
  ll n;cin >> n;
  vl m(n);rep(i,n)cin >> m[i];
  vvl dp(1<<n);
  rep(i,n){
    vl a;
    rep(_,m[i]){
      ll b;cin >> b;
      a.emplace_back(b);
    }
    dp[1<<i]=noshi(a);
  }
  lll ans=0;
  repl(bit,1,1<<n){
    if(__builtin_popcount(bit)==1){
      ans+=1LL<<(dp[bit].size());
      continue;
    }
    int x=bit & -bit;
    int y=bit^x;
    dp[bit]=noshimerge(dp[x],dp[y]);
    ans+=(1LL<<(dp[bit].size()))*(__builtin_popcount(bit)%2? 1:-1);
    /*if(dp[bit].size()>60){
      vl mle(INF);
    }*/
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 160
memory_kb: 11860
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

vl noshi(vl a){
  vl base;
  for(auto p:a){
    for(auto b:base){
      chmin(p,b^p);
    }
    if(p)base.emplace_back(p);
  }
  return base;
}
vl noshimerge(vl base,vl b){//baseとbの共通空間をとる
  vl res;
  vpl base_p;
  for(auto v:base){
    base_p.emplace_back(v,0);
  }
  for(auto v:b){
    ll x=v;
    for(auto [u,t]:base_p){
      if(chmin(v,v^u)){
        x^=t;
      }
    }
    if(v)base_p.emplace_back(v,x);
    else res.emplace_back(x);
  }
  return res;
}
typedef __int128 lll;
  istream& operator>>(istream& i, lll& x) {
    x = 0;
    string s;
    i >> s;
    int N = s.size(), it = 0;
    if (s[0] == '-') it++;
    for (; it < N; it++) x = (x * 10 + s[it] - '0');
    if (s[0] == '-') x = -x;
    return i;
  }
  ostream& operator<<(ostream& o, const lll& x) {
    ll tmp = x;
    if (tmp == 0) return o << 0;
    if (tmp < 0) o << '-', tmp = -tmp;
    vector<int> ds;
    while (tmp) ds.push_back(tmp % 10), tmp /= 10;
    reverse(ds.begin(), ds.end());
    for (int d : ds) o << d;
    return o;
  }
int main(){
  ll n;cin >> n;
  vl m(n);rep(i,n)cin >> m[i];
  vvl dp(1<<n);
  rep(i,n){
    vl a;
    rep(_,m[i]){
      ll b;cin >> b;
      a.emplace_back(b);
    }
    dp[1<<i]=noshi(a);
  }
  lll ans=0;
  repl(bit,1,1<<n){
    if(__builtin_popcount(bit)==1){
      ans+=1LL<<(dp[bit].size());
      continue;
    }
    int x=bit & -bit;
    int y=bit^x;
    dp[bit]=noshimerge(dp[x],dp[y]);
    ans+=(1LL<<(dp[bit].size()))*(__builtin_popcount(bit)%2? 1:-1);
    if(dp[bit].size()>60){
      vl mle(INF);
    }
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 140
memory_kb: 11920
final_rank: 7

code_snippet: #include <iostream>
#include <vector>
using namespace std;
using lint = long long;
template <typename T> bool chmin(T &m, const T q) { return m > q ? (m = q, true) : false; }

constexpr int D = 60;

__int128 lift(lint vec) {
    return __int128(vec) << D;
}

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int K;
    cin >> K;
    vector<int> N(K);
    for (auto &n : N) cin >> n;

    vector<vector<lint>> B;
    for (auto n : N) {
        B.push_back({});
        while (n--) {
            lint a;
            cin >> a;
            for (auto b : B.back()) chmin(a, a ^ b);
            if (a) B.back().push_back(a);
        }
    }

    unsigned long long ret = 0;

    vector<vector<lint>> basis(1 << K);
    for (int d = 0; d < D; ++d) basis.front().push_back(1LL << d);

    for (int S = 1; S < 1 << K; ++S) {
        int d = __builtin_ctz(S), Sprv = S - (1 << d);

        vector<__int128> btmp;
        for (auto b : basis[Sprv]) btmp.push_back(lift(b));

        for (__int128 b : B[d]) {
            b ^= lift(b);
            for (auto x : btmp) chmin(b, b ^ x);
            if (b != 0) btmp.push_back(b);
        }

        for (auto x : btmp) {
            if (x < 1LL << D) basis[S].push_back(x);
        }
        unsigned long long tmp = 1ULL << basis[S].size();
        if (__builtin_parity(S))
            ret += tmp;
        else
            ret -= tmp;
    }
    cout << ret << '\n';
}
accuracy: 1
time_ms: 110
memory_kb: 11988
final_rank: 4