prithivMLmods/Coder-Stat huggingface dataset:
Problem p03031 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> vv(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int h;
      cin >> h;
      vv[i].push_back(--h);
    }
  }
  vector<int> swi(m);
  for (auto &x : swi)
    cin >> x;
  int ret = 0;
  for (int i = 0; 1 << n; i++) {
    bool flag = true;
    for (int j = 0; j < m; j++) {
      int on = 0;
      for (const auto &x : vv[j]) {
        if (i >> x & 1)
          on++;
      }
      if (on % 2 != swi[j])
        flag = false;
    }
    if (flag)
      ret++;
  }
  cout << ret << endl;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> vv(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int h;
      cin >> h;
      vv[i].push_back(--h);
    }
  }
  vector<int> swi(m);
  for (auto &x : swi)
    cin >> x;
  int ret = 0;
  for (int i = 0; i < 1 << n; i++) {
    bool flag = true;
    for (int j = 0; j < m; j++) {
      int on = 0;
      for (const auto &x : vv[j]) {
        if (i >> x & 1)
          on++;
      }
      if (on % 2 != swi[j])
        flag = false;
    }
    if (flag)
      ret++;
  }
  cout << ret << endl;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i <= (b); i++)
#define repm(i, a, b) for (int i = (a); i >= (b); i--)

#define all(v) v.begin(), v.end()
// sort( all(v) )　などと使える

int n, m;
vector<vector<int>> ks;
vector<int> p;

bool isOK(int bit) {
  bool res = true;

  rep(i, m) {
    int k_i = ks[i][0];

    int s_cnt = 0;
    for (int j = 1; j <= k_i; j++) {
      int s = ks[i][j];
      if (bit & (1 << s))
        s_cnt++;
    }

    if (s_cnt % 2 != p[i])
      res = false;
  }

  return res;
}

int main() {
  cin >> n >> m;

  ks.resize(m);

  rep(i, m) {

    int k_i;
    cin >> k_i;
    ks[i].resize(k_i);
    ks[i][0] = k_i;

    for (int j = 1; j <= k_i; j++) {
      int s_ij;
      cin >> s_ij;
      ks[i][j] = s_ij - 1;
    }
  }

  p.resize(m);
  rep(i, m) cin >> p[i];

  int cnt = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    if (isOK(bit))
      cnt++;
  }

  cout << cnt << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i <= (b); i++)
#define repm(i, a, b) for (int i = (a); i >= (b); i--)

#define all(v) v.begin(), v.end()
// sort( all(v) )　などと使える

int n, m;
vector<vector<int>> ks;
vector<int> p;

bool isOK(int bit) {
  bool res = true;

  rep(i, m) {
    int k_i = ks[i][0];

    int s_cnt = 0;
    for (int j = 1; j <= k_i; j++) {
      int s = ks[i][j];
      if (bit & (1 << s))
        s_cnt++;
    }

    if (s_cnt % 2 != p[i])
      res = false;
  }

  return res;
}

int main() {
  cin >> n >> m;

  ks.resize(m);

  rep(i, m) {

    int k_i;
    cin >> k_i;
    ks[i].resize(k_i + 1);
    ks[i][0] = k_i;

    for (int j = 1; j <= k_i; j++) {
      int s_ij;
      cin >> s_ij;
      ks[i][j] = s_ij - 1;
    }
  }

  p.resize(m);
  rep(i, m) cin >> p[i];

  int cnt = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    if (isOK(bit))
      cnt++;
  }

  cout << cnt << endl;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define endl "\n"

using ll = long long;
using P = pair<int, int>;
using mp = map<string, int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, m;
  cin >> n >> m;

  vector<vector<int>> s(m);
  vector<int> P(m);
  rep(i, m) {
    int k;
    cin >> k;

    rep(j, k) {
      int x;
      cin >> x;
      x--;
      s[j].push_back(x);
    }
  }

  rep(i, m) { cin >> P[i]; }

  int ans = 0;
  for (int i = 0; i < (1 << n); ++i) {
    bool ok = true;
    rep(j, m) {
      int cnt = 0;
      for (auto &p : s[j]) {
        if ((i >> p) & 1) {
          cnt++;
        }
      }
      if (cnt % 2 != P[j]) {
        ok = false;
      }
    }
    if (ok) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define endl "\n"

using ll = long long;
using P = pair<int, int>;
using mp = map<string, int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, m;
  cin >> n >> m;

  vector<vector<int>> s(m);
  vector<int> P(m);
  rep(i, m) {
    int k;
    cin >> k;

    rep(j, k) {
      int x;
      cin >> x;
      x--;
      s[i].push_back(x);
    }
  }

  rep(i, m) { cin >> P[i]; }

  int ans = 0;
  for (int i = 0; i < (1 << n); ++i) {
    bool ok = true;
    rep(j, m) {
      int cnt = 0;
      for (auto &p : s[j]) {
        if ((i >> p) & 1) {
          cnt++;
        }
      }
      if (cnt % 2 != P[j]) {
        ok = false;
      }
    }
    if (ok) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):

// auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2,
// 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of
// };
//  for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//    bitset<ビット数> s(tmp);
//    // (ビット列sに対する処理)
//  }
//  sort(配列変数.begin(), 配列変数.end());
//  do {
//    // 順列に対する処理
//  } while (next_permutation(配列変数.begin(), 配列変数.end()));
// const double PI = acos(-1); M_PI
//  cout << fixed << setprecision(10);
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG / GCC環境下で[] による配列要素参照のエラーを出す
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() // sort(all(vec)); ,reverse(all(vec));etc
int main() {
  int n, m;
  cin >> n >> m;
  vector<bitset<10>> vec(m);
  vector<int> k(m);
  vector<int> p(m);
  rep(i, m) {
    cin >> k.at(i);
    rep(j, k.at(i)) {
      int pos;
      cin >> pos;
      vec.at(i).set(pos, 1);
    }
  }
  // cout<<vec.at(0)<<vec.at(1)<<endl;
  rep(i, m) { cin >> p.at(i); }
  int sum = 0;
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<10> cnt(tmp);
    rep(i, m) {
      int match = (vec.at(i) & cnt).count();
      if ((match % 2) != p.at(i)) {
        goto SKIP;
      }
    }
    sum += 1;
  // cout<<"hit:"<<cnt<<endl;
  SKIP:
    int alias;
    // cout<<cnt<<endl;
  }
  cout << sum << endl;
}


Fixed submission:

// auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2,
// 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of
// };
//  for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//    bitset<ビット数> s(tmp);
//    // (ビット列sに対する処理)
//  }
//  sort(配列変数.begin(), 配列変数.end());
//  do {
//    // 順列に対する処理
//  } while (next_permutation(配列変数.begin(), 配列変数.end()));
// const double PI = acos(-1); M_PI
//  cout << fixed << setprecision(10);
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG / GCC環境下で[] による配列要素参照のエラーを出す
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() // sort(all(vec)); ,reverse(all(vec));etc
int main() {
  int n, m;
  cin >> n >> m;
  vector<bitset<10>> vec(m);
  vector<int> k(m);
  vector<int> p(m);
  rep(i, m) {
    cin >> k.at(i);
    rep(j, k.at(i)) {
      int pos;
      cin >> pos;
      vec.at(i).set(pos - 1, 1);
    }
  }
  // cout<<vec.at(0)<<vec.at(1)<<endl;
  rep(i, m) { cin >> p.at(i); }
  int sum = 0;
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    bitset<10> cnt(tmp);
    rep(i, m) {
      int match = (vec.at(i) & cnt).count();
      if ((match % 2) != p.at(i)) {
        goto SKIP;
      }
    }
    sum += 1;
  // cout<<"hit:"<<cnt<<endl;
  SKIP:
    int alias;
    // cout<<cnt<<endl;
  }
  cout << sum << endl;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using ll = long long;

int main() {
  int N, M;
  std::cin >> N >> M;
  // i番目のスイッチのつけられる電球の番号
  std::vector<std::vector<int>> k(N);

  for (int i = 0; i < M; i++) {
    int p;
    std::cin >> p;

    for (int j = 0; j < p; j++) {
      int in;
      std::cin >> in;
      in--;
      k[in].emplace_back(i);
    }
  }

  std::vector<int> m(M);
  for (int i = 0; i < M; i++) {
    int p;
    std::cin >> p;
    if (p == 1) {
      m[i]++;
    }
  }

  int ans = 0;
  for (int i = 0; i < (1 << N); i++) {
    std::vector<int> cm(m);
    for (int j = 0; j < N; j++) {
      int l = (i >> j) & 1;
      if (l == 0)
        continue;
      for (int i = 0; i < k[j].size(); i++) {
        cm[k[l][i]]++;
      }
    }
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if (cm[j] % 2 == 1) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using ll = long long;

int main() {
  int N, M;
  std::cin >> N >> M;
  // i番目のスイッチのつけられる電球の番号
  std::vector<std::vector<int>> k(N);

  for (int i = 0; i < M; i++) {
    int p;
    std::cin >> p;

    for (int j = 0; j < p; j++) {
      int in;
      std::cin >> in;
      in--;
      k[in].emplace_back(i);
    }
  }

  std::vector<int> m(M);
  for (int i = 0; i < M; i++) {
    int p;
    std::cin >> p;
    if (p == 1) {
      m[i]++;
    }
  }

  int ans = 0;
  for (int i = 0; i < (1 << N); i++) {
    std::vector<int> cm(m);
    for (int j = 0; j < N; j++) {
      int l = (i >> j) & 1;
      if (l == 0)
        continue;
      for (int i = 0; i < k[j].size(); i++) {
        cm[k[j][i]]++;
      }
    }
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if (cm[j] % 2 == 1) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans++;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define repn(i, x) for (int i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> s(M);
  vector<ll> p;
  vector<ll> K;
  ll i, j, k, l;
  ll ans = 0;
  rep(i, M) {
    ll a;
    cin >> a;
    K.pb(a);
    rep(j, a) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  rep(i, M) {
    ll b;
    cin >> b;
    p.pb(b);
  }
  rep(i, 1 << N) {
    bool ok = true;
    rep(j, M) {
      int cnt = 0;
      rep(k, K[j]) {
        if ((i >> s[j][k]) & 1)
          cnt++;
      }
      if (cnt % 2 != p.at(j))
        ok = false;
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define repn(i, x) for (int i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
int main() {
  ll N, M;
  cin >> N >> M;
  vector<vector<ll>> s(M);
  vector<ll> p;
  vector<ll> K;
  ll i, j, k, l;
  ll ans = 0;
  rep(i, M) {
    ll a;
    cin >> a;
    K.pb(a);
    rep(j, a) {
      ll c;
      cin >> c;
      c--;
      s[i].pb(c);
    }
  }
  rep(i, M) {
    ll b;
    cin >> b;
    p.pb(b);
  }
  rep(i, 1 << N) {
    bool ok = true;
    rep(j, M) {
      int cnt = 0;
      rep(k, K[j]) {
        if ((i >> s[j][k]) & 1)
          cnt++;
      }
      if (cnt % 2 != p.at(j))
        ok = false;
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(m);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int temp;
      cin >> temp;
      temp--;
      s[i].push_back(temp);
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; i++)
    cin >> p[i];

  ll ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    bool flg = true;
    for (int i = 0; i < m; i++) {
      int cnt = 0;
      for (int v : s[i]) {
        if (bit & (1 << v))
          cnt++;
      }
      if (cnt % 2 != p[i])
        flg = false;
    }
    if (flg)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int temp;
      cin >> temp;
      temp--;
      s[i].push_back(temp);
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; i++)
    cin >> p[i];

  ll ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    bool flg = true;
    for (int i = 0; i < m; i++) {
      int cnt = 0;
      for (int v : s[i]) {
        if (bit & (1 << v))
          cnt++;
      }
      if (cnt % 2 != p[i])
        flg = false;
    }
    if (flg)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>

using namespace std;

#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007, INF = 1e18;

int main(void) {
  int n, m;
  cin >> n >> m;

  vector<vi> s(m, vi(m, 0));
  vi p(m, 0);
  for (int i = 0; i < m; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < m; ++i) {
    cin >> p[i];
  }

  int ans = 0;

  if (n == 1) {
    cout << p[0] << endl;
    return 0;
  }

  for (int bit = 0; bit < (1 << n); ++bit) {
    bool is_cnt_up = true;
    for (int j = 0; j < m; ++j) {
      int on_num = 0;
      for (auto sk : s[j]) {
        if ((bit >> (sk - 1)) & 1)
          on_num++;
      }
      if (on_num % 2 != p[j])
        is_cnt_up = false;
    }
    if (is_cnt_up)
      ans++;
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <vector>

using namespace std;

#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007, INF = 1e18;

int main(void) {
  int n, m;
  cin >> n >> m;

  vector<vi> s(m, vi(11, 0));
  vi p(m, 0);
  for (int i = 0; i < m; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < m; ++i) {
    cin >> p[i];
  }

  int ans = 0;

  if (n == 1) {
    cout << p[0] << endl;
    return 0;
  }

  for (int bit = 0; bit < (1 << n); ++bit) {
    bool is_cnt_up = true;
    for (int j = 0; j < m; ++j) {
      int on_num = 0;
      for (auto sk : s[j]) {
        if ((bit >> (sk - 1)) & 1)
          on_num++;
      }
      if (on_num % 2 != p[j])
        is_cnt_up = false;
    }
    if (is_cnt_up)
      ans++;
  }

  cout << ans << endl;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <stdlib.h>

#define MAX_N (10)
#define MAX_M (10)

int main(int argc, char *argv[]) {
  // read inputs
  int N, M, ks[MAX_M], xss[MAX_M][MAX_N], ps[MAX_M];
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d", &ks[i]);
    for (int j = 0; j < N; j++) {
      scanf("%d", &xss[i][j]);
      xss[i][j]--; // NOTE : modified input
    }
  }
  for (int i = 0; i < M; i++) {
    scanf("%d", &ps[i]);
  }

  // search all
  int ans = 0;
  for (int S = 0; S < (1 << N); S++) {
    int is_all_on = 1;
    for (int i = 0; i < M; i++) {
      // check if light bulb i will light up
      const int k = ks[i], p = ps[i];
      int num = 0;
      for (int l = 0; l < k; l++) {
        const int x = xss[i][l];
        if ((S & (1 << x)) != 0) {
          num++;
        }
      }
      if (num % 2 != p) {
        is_all_on = 0;
        break;
      }
    }
    if (is_all_on) {
      ans++;
    }
  }
  printf("%d\n", ans);

  return 0;
}


Fixed submission:
#include <stdio.h>
#include <stdlib.h>

#define MAX_N (10)
#define MAX_M (10)

int main(int argc, char *argv[]) {
  // read inputs
  int N, M, ks[MAX_M], xss[MAX_M][MAX_N], ps[MAX_M];
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d", &ks[i]);
    for (int l = 0; l < ks[i]; l++) {
      scanf("%d", &xss[i][l]);
      xss[i][l]--; // NOTE : modified input
    }
  }
  for (int i = 0; i < M; i++) {
    scanf("%d", &ps[i]);
  }

  // search all
  int ans = 0;
  for (int S = 0; S < (1 << N); S++) {
    int is_all_on = 1;
    for (int i = 0; i < M; i++) {
      // check if light bulb i will light up
      const int k = ks[i], p = ps[i];
      int num = 0;
      for (int l = 0; l < k; l++) {
        const int x = xss[i][l];
        if ((S & (1 << x)) != 0) {
          num++;
        }
      }
      if (num % 2 != p) {
        is_all_on = 0;
        break;
      }
    }
    if (is_all_on) {
      ans++;
    }
  }
  printf("%d\n", ans);

  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, m, k;
  cin >> n >> m;
  vector<bitset<10>> a(m);
  vector<int> c(m);
  rep(i, m) {
    cin >> k;
    int b;
    bitset<10> bs;
    rep(j, k) {
      cin >> b;
      bs.set(b);
    }
    a[i] = bs;
  }
  rep(i, m) { cin >> c[i]; }
  int sum = 0;
  for (int bit = 0; bit < (1 << n); ++bit) {
    rep(i, m) {
      if (c[i] != (int)(a[i] & (bitset<10>)bit).count() % 2) {
        sum--;
        break;
      }
    }
    sum++;
  }
  cout << sum;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, m, k;
  cin >> n >> m;
  vector<bitset<10>> a(m);
  vector<int> c(m);
  rep(i, m) {
    cin >> k;
    int b;
    bitset<10> bs;
    rep(j, k) {
      cin >> b;
      bs.set(b - 1);
    }
    a[i] = bs;
  }
  rep(i, m) { cin >> c[i]; }
  int sum = 0;
  for (int bit = 0; bit < (1 << n); ++bit) {
    rep(i, m) {
      if (c[i] != (int)(a[i] & (bitset<10>)bit).count() % 2) {
        sum--;
        break;
      }
    }
    sum++;
  }
  cout << sum;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> k(m);
  vector<vector<int>> s(m, vector<int>(m));
  vector<int> p(m);

  rep(i, m) {
    cin >> k[i];
    rep(j, k[i]) { cin >> s[i][j]; }
  }
  rep(i, m) cin >> p[i];

  int res = 0;

  for (int bit = 0; bit < (1 << n); bit++) {
    bool flag = 0;
    rep(i, m) {
      bool parity = 0;
      rep(j, k[i]) {
        if ((1 << (s[i][j] - 1)) & bit)
          parity ^= 1;
      }
      if (parity == p[i])
        continue;
      else {
        flag = 1;
        break;
      }
    }
    if (flag == 0)
      res++;
  }
  cout << res << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> k(m);
  vector<vector<int>> s(m, vector<int>(n));
  vector<int> p(m);

  rep(i, m) {
    cin >> k[i];
    rep(j, k[i]) { cin >> s[i][j]; }
  }
  rep(i, m) cin >> p[i];

  int res = 0;

  for (int bit = 0; bit < (1 << n); bit++) {
    bool flag = 0;
    rep(i, m) {
      bool parity = 0;
      rep(j, k[i]) {
        if ((1 << (s[i][j] - 1)) & bit)
          parity ^= 1;
      }
      if (parity == p[i])
        continue;
      else {
        flag = 1;
        break;
      }
    }
    if (flag == 0)
      res++;
  }
  cout << res << endl;

  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  auto k = vector<int>(m);
  auto s = vector<vector<int>>(m);
  auto p = vector<int>(m);
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      int tmp;
      cin >> tmp;
      s[i].push_back(tmp);
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }

  int ans = 0;
  int ok;

  for (int i = 0; i < (int)pow(2, n); i++) {
    ok = 1;
    for (int j = 0; j < m; j++) {
      int sum = 0;
      for (int l = 0; l < k[i]; l++) {
        sum = (sum + ((i / (int)pow(2, s[j][l])) % 2)) % 2;
      }
      if (sum != p[j]) {
        ok = 0;
        break;
      }
    }
    if (ok == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  auto k = vector<int>(m);
  auto s = vector<vector<int>>(m);
  auto p = vector<int>(m);
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      int tmp;
      cin >> tmp;
      s[i].push_back(tmp);
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }

  int ans = 0;
  int ok;

  for (int i = 0; i < (int)pow(2, n); i++) {
    ok = 1;
    for (int j = 0; j < m; j++) {
      int sum = 0;
      for (int l = 0; l < k[j]; l++) {
        sum = (sum + ((i / (int)pow(2, s[j][l] - 1)) % 2)) % 2;
      }
      if (sum != p[j]) {
        ok = 0;
        break;
      }
    }
    if (ok == 1)
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> k(M), p(M);
  vector<vector<int>> s(M);
  for (int i = 0; i < M; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      int num;
      cin >> num;
      s[i].push_back(num);
    }
  }
  for (int i = 0; i < M; i++)
    cin >> p[i];
  // スイッチがonになっているとき1，そうでなければ0
  int res = 0;
  for (int tmp = 0; tmp < (1 << 10); tmp++) {
    bitset<10> b(tmp);
    bool OK = true;
    for (int i = 0; i < M; i++) {
      int num2 = 0;
      for (int j = 0; j < k[i]; j++) {
        if (b.test(s[i][j]))
          num2++;
      }
      if (num2 % 2 != p[i]) {
        OK = false;
        break;
      }
    }
    if (OK)
      res++;
  }
  res /= pow(2, 10 - N);
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> k(M), p(M);
  vector<vector<int>> s(M);
  for (int i = 0; i < M; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      int num;
      cin >> num;
      num--;
      s[i].push_back(num);
    }
  }
  for (int i = 0; i < M; i++)
    cin >> p[i];
  // スイッチがonになっているとき1，そうでなければ0
  int res = 0;
  for (int tmp = 0; tmp < (1 << 10); tmp++) {
    bitset<10> b(tmp);
    bool OK = true;
    for (int i = 0; i < M; i++) {
      int num2 = 0;
      for (int j = 0; j < k[i]; j++) {
        if (b.test(s[i][j]))
          num2++;
      }
      if (num2 % 2 != p[i]) {
        OK = false;
        break;
      }
    }
    if (OK)
      res++;
  }
  res /= pow(2, 10 - N);
  cout << res << endl;
  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> S(M);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> S.at(i).at(j);
    }
  }
  vector<int> P(M);
  for (int i = 0; i < M; i++)
    cin >> P.at(i);
  int count = 0;
  for (int bit; bit < (1 << N); bit++) {
    bool result = true;
    for (int i = 0; i < M; i++) {
      int c = 0;
      for (int x : S.at(i)) {
        if (bit & (1 << (x - 1)))
          c++;
      }
      if (!(c % 2) == P.at(i)) {
        result = false;
        break;
      }
    }
    if (result)
      count++;
  }
  cout << count << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> S(M);
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    S.at(i).resize(k);
    for (int j = 0; j < k; j++) {
      cin >> S.at(i).at(j);
    }
  }
  vector<int> P(M);
  for (int i = 0; i < M; i++)
    cin >> P.at(i);
  int count = 0;
  for (int bit; bit < (1 << N); bit++) {
    bool result = true;
    for (int i = 0; i < M; i++) {
      int c = 0;
      for (int x : S.at(i)) {
        if (bit & (1 << (x - 1)))
          c++;
      }
      if (!(c % 2) == P.at(i)) {
        result = false;
        break;
      }
    }
    if (result)
      count++;
  }
  cout << count << endl;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
#ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("outp.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, m, ans = 0;
  cin >> n >> m;
  vector<vector<int>> light(m);
  vector<int> num(m), prt(m);
  for (int i = 0; i < m; i++) {
    cin >> num[i];
    for (int j = 0; j < num[i]; j++) {
      int temp;
      cin >> temp;
      light[i].push_back(temp);
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> prt[i];
  }

  for (int x = 0; x < (1 << n); x++) {
    bool jury = true;
    for (int i = 0; i < m; i++) {
      int cnt = 0;
      for (int j = 0; j < num[i]; j++) {
        if (x & (1 << (light[i][j] - 1))) {
          cnt++;
        }
      }
      if (cnt % 2 != prt[i]) {
        jury = false;
        break;
      }
    }
    if (jury) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ff first
#define ss second
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, m, ans = 0;
  cin >> n >> m;
  vector<vector<int>> light(m);
  vector<int> num(m), prt(m);
  for (int i = 0; i < m; i++) {
    cin >> num[i];
    for (int j = 0; j < num[i]; j++) {
      int temp;
      cin >> temp;
      light[i].push_back(temp);
    }
  }
  for (int i = 0; i < m; i++) {
    cin >> prt[i];
  }

  for (int x = 0; x < (1 << n); x++) {
    bool jury = true;
    for (int i = 0; i < m; i++) {
      int cnt = 0;
      for (int j = 0; j < num[i]; j++) {
        if (x & (1 << (light[i][j] - 1))) {
          cnt++;
        }
      }
      if (cnt % 2 != prt[i]) {
        jury = false;
        break;
      }
    }
    if (jury) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {

  int n, m;
  cin >> n >> m;

  vector<int> cont(n);

  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      s--;
      cont.at(i) |= 1 << s;
    }
  }

  int p = 0;
  for (int i = 0; i < m; i++) {
    int s;
    cin >> s;

    p |= s << i;
  }

  int ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    int t = 0;
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) {
        t ^= cont.at(j);
      }
    }
    if (t == p) {
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {

  int n, m;
  cin >> n >> m;

  vector<int> cont(n);

  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      s--;
      cont.at(s) |= 1 << i;
    }
  }

  int p = 0;
  for (int i = 0; i < m; i++) {
    int s;
    cin >> s;

    p |= s << i;
  }

  int ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    int t = 0;
    for (int j = 0; j < n; j++) {
      if (i >> j & 1) {
        t ^= cont.at(j);
      }
    }
    if (t == p) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<int, int>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> k(M);
  vector<vector<int>> s(N);
  for (int i = 0; i < M; i++) {
    cin >> k[i];
    s[i].resize(k[i]);
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
    }
  }
  vector<int> p(M);
  for (int i = 0; i < M; i++)
    cin >> p[i];
  int ans = 0;
  for (int bits = 0; bits < (1 << N); bits++) {
    vector<bool> s_on(N, false);
    bool ok = true;
    for (int i = 0; i < N; i++) {
      if ((bits >> i) & 1) {
        s_on[i] = true;
      }
    }
    for (int i = 0; i < M; i++) {
      int sum = 0;
      for (int j = 0; j < k[i]; j++) {
        if (s_on[s[i][j] - 1])
          sum++;
      }
      if (sum % 2 != p[i])
        ok = false;
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using ll = long long;
using P = pair<int, int>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> k(M);
  vector<vector<int>> s(M);
  for (int i = 0; i < M; i++) {
    cin >> k[i];
    s[i].resize(k[i]);
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
    }
  }
  vector<int> p(M);
  for (int i = 0; i < M; i++)
    cin >> p[i];
  int ans = 0;
  for (int bits = 0; bits < (1 << N); bits++) {
    vector<bool> s_on(N, false);
    bool ok = true;
    for (int i = 0; i < N; i++) {
      if ((bits >> i) & 1) {
        s_on[i] = true;
      }
    }
    for (int i = 0; i < M; i++) {
      int sum = 0;
      for (int j = 0; j < k[i]; j++) {
        if (s_on[s[i][j] - 1])
          sum++;
      }
      if (sum % 2 != p[i])
        ok = false;
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
// wawando's template

#include <algorithm>
#include <cctype>
#include <climits> // LLONG_MAX , LLONG_MIN , INT_MAX , INT_MIN
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime> //clock_t , clock() , CLOCKS_PER_SEC
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// MACROS
#define pb push_back
#define mp make_pair
#define INF 1000000000 // 1 billion safer for floyd warshall, avoid overflow

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N, M;
  vector<vi> bulbs;
  vi p;

  cin >> N >> M;
  bulbs.assign(N, vi());
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      bulbs[i].pb(s - 1);
    }
  }
  for (int i = 0; i < M; i++) {
    int pi;
    cin >> pi;
    p.pb(pi);
  }
  int ans = 0;
  for (int mask = 0; mask < (1 << N); mask++) {
    bool isOn = true;
    for (int i = 0; i < M; i++) {
      int onCount = 0;
      for (int j = 0; j < (int)bulbs[i].size(); j++) {
        if (mask & (1 << bulbs[i][j]))
          onCount++;
      }
      isOn &= (onCount % 2 == p[i]);
    }
    ans += (isOn ? 1 : 0);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
// wawando's template

#include <algorithm>
#include <cctype>
#include <climits> // LLONG_MAX , LLONG_MIN , INT_MAX , INT_MIN
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime> //clock_t , clock() , CLOCKS_PER_SEC
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// MACROS
#define pb push_back
#define mp make_pair
#define INF 1000000000 // 1 billion safer for floyd warshall, avoid overflow

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N, M;
  vector<vi> bulbs;
  vi p;

  cin >> N >> M;
  bulbs.assign(M, vi());
  for (int i = 0; i < M; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s;
      cin >> s;
      bulbs[i].pb(s - 1);
    }
  }
  for (int i = 0; i < M; i++) {
    int pi;
    cin >> pi;
    p.pb(pi);
  }
  int ans = 0;
  for (int mask = 0; mask < (1 << N); mask++) {
    bool isOn = true;
    for (int i = 0; i < M; i++) {
      int onCount = 0;
      for (int j = 0; j < (int)bulbs[i].size(); j++) {
        if (mask & (1 << bulbs[i][j]))
          onCount++;
      }
      isOn &= (onCount % 2 == p[i]);
    }
    ans += (isOn ? 1 : 0);
  }
  cout << ans << endl;
  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> k(M);
  vector<vector<int>> s(M);
  vector<int> p(M);

  for (int i = 0; i < M; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }

  for (int i = 0; i < M; i++)
    cin >> p[i];
  ll ans = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    bool ok = true;
    for (int i = 0; i < M; i++) {
      int sum = 0;
      for (auto v : s[i]) {
        if ((1 << v) & bit)
          sum++;
      }
      if (sum % 2 != p[i])
        ok = false;
    }
    if (ok)
      ans += 1;
  }

  cout << ans;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> k(M);
  vector<vector<int>> s(M);
  vector<int> p(M);

  for (int i = 0; i < M; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      int a;
      cin >> a;
      a--;
      s[i].push_back(a);
    }
  }

  for (int i = 0; i < M; i++)
    cin >> p[i];
  ll ans = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    bool ok = true;
    for (int i = 0; i < M; i++) {
      int sum = 0;
      for (auto v : s[i]) {
        if ((1 << v) & bit)
          sum++;
      }
      if (sum % 2 != p[i])
        ok = false;
    }
    if (ok)
      ans += 1;
  }

  cout << ans;

  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define pii_ pair<int, int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define show1(a) cout << #a << " = " << a << endl
#define show2(a, b) cout << #a << " = " << a << "; " << #b << " = " << b << endl
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int maxn = 2e5 + 5;
inline void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int n, m, g[15][15], p[15], cnt[15];

int main() {
  fastio();
  cin >> n >> m;
  rep(i, 0, m - 1) {
    int k, x;
    cin >> k;
    rep(j, 1, k) {
      cin >> x;
      g[--x][i] = 1;
    }
  }
  rep(i, 0, m - 1) cin >> p[i];
  int ans = 0;
  rep(i, 0, (1 << n) - 1) {
    memset(cnt, 0, sizeof(cnt));
    rep(j, 0, i - 1) {
      if ((i >> j) & 1) {
        rep(k, 0, m - 1) {
          if (g[j][k])
            cnt[k]++;
        }
      }
    }
    int flag = 1;
    rep(i, 0, m - 1) if (cnt[i] % 2 != p[i]) flag = 0;
    ans += flag;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define pii_ pair<int, int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define show1(a) cout << #a << " = " << a << endl
#define show2(a, b) cout << #a << " = " << a << "; " << #b << " = " << b << endl
using namespace std;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
const int maxn = 2e5 + 5;
inline void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int n, m, g[15][15], p[15], cnt[15];

int main() {
  fastio();
  cin >> n >> m;
  rep(i, 0, m - 1) {
    int k, x;
    cin >> k;
    rep(j, 1, k) {
      cin >> x;
      g[--x][i] = 1;
    }
  }
  rep(i, 0, m - 1) cin >> p[i];
  int ans = 0;
  rep(i, 0, (1 << n) - 1) {
    memset(cnt, 0, sizeof(cnt));
    rep(j, 0, n - 1) {
      if ((i >> j) & 1) {
        rep(k, 0, m - 1) {
          if (g[j][k])
            cnt[k]++;
        }
      }
    }
    int flag = 1;
    rep(i, 0, m - 1) if (cnt[i] % 2 != p[i]) flag = 0;
    ans += flag;
  }
  cout << ans << endl;
  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<int>> s(M);
  for (int i = 0; i < M; ++i) {
    int k;
    cin >> k;

    s[i].resize(k);
    for (int j = 0; j < k; ++j) {
      cin >> s[i][j];
      --s[i][j];
    }
  }

  vector<int> p(M);
  for (int i = 1; i <= M; ++i) {
    cin >> p[i];
  }

  int ans = 0;
  for (int i = 0; i < (1 << N); ++i) {
    bool flg = true;

    for (int m = 0; m < M; ++m) {
      int cnt = 0;
      for (auto sw : s[m]) {
        if ((i >> sw) & 1)
          ++cnt;
      }
      if (cnt % 2 != p[m])
        flg = false;
    }
    if (flg)
      ++ans;
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;

  vector<vector<int>> s(M);
  for (int i = 0; i < M; ++i) {
    int k;
    cin >> k;

    s[i].resize(k);
    for (int j = 0; j < k; ++j) {
      cin >> s[i][j];
      --s[i][j];
    }
  }

  vector<int> p(M);
  for (int i = 0; i < M; ++i) {
    cin >> p[i];
  }

  int ans = 0;
  for (int i = 0; i < (1 << N); ++i) {
    bool flg = true;

    for (int m = 0; m < M; ++m) {
      int cnt = 0;
      for (auto sw : s[m]) {
        if ((i >> sw) & 1)
          ++cnt;
      }
      if (cnt % 2 != p[m])
        flg = false;
    }
    if (flg)
      ++ans;
  }

  cout << ans << endl;

  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(n);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s_in;
      cin >> s_in;
      s[s_in - 1].push_back(j);
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  int ans = 0;
  for (int k = 0; k < (1 << n); k++) {
    vector<int> o(m, 0);
    for (int i = 0; i < n; i++) {
      if (k & (1 << i)) {
        for (auto itr = s[i].begin(); itr != s[i].end(); itr++) {
          o[*itr]++;
        }
      }
    }
    bool flg = true;
    for (int i = 0; i < m; i++) {
      if (o[i] % 2 != p[i] % 2) {
        flg = false;
        break;
      }
    }
    if (flg) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(n);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int s_in;
      cin >> s_in;
      s[s_in - 1].push_back(i);
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  int ans = 0;
  for (int k = 0; k < (1 << n); k++) {
    vector<int> o(m, 0);
    for (int i = 0; i < n; i++) {
      if (k & (1 << i)) {
        for (auto itr = s[i].begin(); itr != s[i].end(); itr++) {
          o[*itr]++;
        }
      }
    }
    bool flg = true;
    for (int i = 0; i < m; i++) {
      if (o[i] % 2 != p[i] % 2) {
        flg = false;
        break;
      }
    }
    if (flg) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, ans;
  cin >> n >> m;
  vector<vector<int>> ks(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> ks[i][j];
      ks[i][j]--;
    }
  }

  vector<int> p(m);
  for (int i = 0; i < m; i++)
    cin >> p[i];

  for (int i = 0; i < (1 << n); i++) {
    bool ok = true;
    for (int j = 0; j < m; j++) {
      int count = 0;
      for (int num : ks[j]) {
        if ((i >> num) & 1)
          count++;
      }
      count %= 2;
      if (count != p[j])
        ok = false;
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, ans;
  cin >> n >> m;
  vector<vector<int>> ks(m);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    ks[i].resize(k);
    for (int j = 0; j < k; j++) {
      cin >> ks[i][j];
      ks[i][j]--;
    }
  }

  vector<int> p(m);
  for (int i = 0; i < m; i++)
    cin >> p[i];

  for (int i = 0; i < (1 << n); i++) {
    bool ok = true;
    for (int j = 0; j < m; j++) {
      int count = 0;
      for (int num : ks[j]) {
        if ((i >> num) & 1)
          count++;
      }
      count %= 2;
      if (count != p[j])
        ok = false;
    }
    if (ok)
      ans++;
  }
  cout << ans << endl;

  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int k[20], s[20][20], p[20];
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < m; i++)
    cin >> p[i];

  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    int light = 0;
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < k[i]; j++) {
        if (bit & (1 << s[i][j] - 1))
          cnt++;
      }
      if (p[i] == 0 && (cnt % 2 == 0))
        light++;
      if (p[i] == 1 && (cnt % 2 != 0))
        light++;
    }
    if (light == m)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int k[20], s[20][20], p[20];
  for (int i = 0; i < m; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < m; i++)
    cin >> p[i];

  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    int light = 0;
    for (int i = 0; i < m; i++) {
      int cnt = 0;
      for (int j = 0; j < k[i]; j++) {
        if (bit & (1 << s[i][j] - 1))
          cnt++;
      }
      if (p[i] == 0 && (cnt % 2 == 0))
        light++;
      if (p[i] == 1 && (cnt % 2 != 0))
        light++;
    }
    if (light == m)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03031 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> g(n, vector<bool>(m, false));

  rep(i, m) {
    int k;
    cin >> k;
    rep(j, k) {
      int s;
      cin >> s;
      s--;
      g[i][s] = true;
    }
  }
  vector<int> p(m);
  rep(i, m) cin >> p[i];

  ll ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    vector<int> a(m, 0);
    rep(i, n) {
      if (bit & (1 << i)) {
        rep(j, m) {
          if (g[i][j])
            a[j] ^= 1;
        }
      }
    }

    bool jud = true;
    rep(i, m) {
      if (p[i] != a[i])
        jud = false;
    }
    if (jud)
      ans++;
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<bool>> g(n, vector<bool>(m, false));

  rep(i, m) {
    int k;
    cin >> k;
    rep(j, k) {
      int s;
      cin >> s;
      s--;
      g[s][i] = true;
    }
  }
  vector<int> p(m);
  rep(i, m) cin >> p[i];

  ll ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    vector<int> a(m, 0);
    rep(i, n) {
      if (bit & (1 << i)) {
        rep(j, m) {
          if (g[i][j])
            a[j] ^= 1;
        }
      }
    }

    bool jud = true;
    rep(i, m) {
      if (p[i] != a[i])
        jud = false;
    }
    if (jud)
      ans++;
  }

  cout << ans << endl;
}