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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i > ll(b); i--)
using ll = long long;
using namespace std;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
// sort(a, a + N, greater<ll>())   // descend
// sort(a, a+N)                    //  ascend

/*
void comb(vector<vector <ll> > &v) {
        ll mod=1000000007;
        rep (i,0,v.size()) {
                v[i][0] = 1;
                v[i][i] = 1;
        }
        rep (k,1,v.size()) {
                rep (j,1,k) {
                        v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
                }
        }
}
/*main内でnCn~nC0 生成 **
vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
comb(v);
*/

int main() {
  ll n;
  cin >> n;
  ll a[220000];
  rep(i, 1, n + 1) cin >> a[i];
  ll b[220000] = {0};
  ll cnt = 0;
  ll m = 0;
  irep(i, n, 0) {
    irep(j, n, i) {
      if (j % i == 0)
        cnt += b[j];
    }
    cnt = cnt % 2;
    if (a[i] != cnt) {
      b[i] = 1;
      m++;
    }
    cnt = 0;
  }
  cout << m << endl;
  rep(i, 1, n + 1) if (b[i] == 1) cout << i << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define irep(i, a, b) for (ll i = ll(a); i > ll(b); i--)
using ll = long long;
using namespace std;

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
// sort(a, a + N, greater<ll>())   // descend
// sort(a, a+N)                    //  ascend

/*
void comb(vector<vector <ll> > &v) {
        ll mod=1000000007;
        rep (i,0,v.size()) {
                v[i][0] = 1;
                v[i][i] = 1;
        }
        rep (k,1,v.size()) {
                rep (j,1,k) {
                        v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%mod;
                }
        }
}
/*main内でnCn~nC0 生成 **
vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
comb(v);
*/

int main() {
  ll n;
  cin >> n;
  ll a[220000];
  rep(i, 1, n + 1) cin >> a[i];
  ll b[220000] = {0};
  ll cnt = 0;
  ll m = 0;
  irep(i, n, 0) {
    for (ll j = i; j <= n; j += i)
      cnt += b[j];
    cnt = cnt % 2;
    if (a[i] != cnt) {
      b[i] = 1;
      m++;
    }
    cnt = 0;
  }
  cout << m << endl;
  rep(i, 1, n + 1) if (b[i] == 1) cout << i << endl;
}
Problem p02972 (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 m = 0;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);

  for (int i = 1; i <= N; i++) {
    cin >> a[i];
    b[i] = a[i];
  }

  for (int i = N; i >= 1; i--) {
    for (int j = 2; j * i <= N; j++) {
      b[i] += b[j * i];
    }
  }

  for (int i = 1; i <= N; i++) {
    b[i] = b[i] % 2;
  }

  for (int i = 1; i <= N; i++) {
    m += b[i];
  }

  cout << m << endl;

  for (int i = 1; i <= N; i++) {

    if (b[i]) {
      cout << i << " ";
    }
  }
}


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 m = 0;

int main() {
  int N;
  cin >> N;
  vector<int> a(N + 1);
  vector<int> b(N + 1);

  for (int i = 1; i <= N; i++) {
    cin >> a[i];
    b[i] = a[i];
  }

  for (int i = N; i >= 1; i--) {
    for (int j = 2; j * i <= N; j++) {
      b[i] += b[j * i];
    }
  }

  for (int i = 1; i <= N; i++) {
    b[i] = b[i] % 2;
  }

  for (int i = 1; i <= N; i++) {
    m += b[i];
  }

  cout << m << endl;

  for (int i = 1; i <= N; i++) {

    if (b[i]) {
      cout << i << " ";
    }
  }
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9 + 7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

int a[100001];
int d[100001];
vector<int> v;

int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = n; i >= 1; i--) {
    int sum = 0;
    for (int j = 2; j * i <= n; j++)
      sum += d[j * i];
    d[i] = (a[i] ^ (sum % 2));
  }
  for (int i = 1; i <= n; i++) {
    if (d[i])
      v.push_back(i);
  }
  printf("%d\n", v.size());
  for (int i = 0; i < v.size(); i++)
    printf("%d ", v[i]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9 + 7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

int a[200001];
int d[200001];
vector<int> v;

int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = n; i >= 1; i--) {
    int sum = 0;
    for (int j = 2; j * i <= n; j++)
      sum += d[j * i];
    d[i] = (a[i] ^ (sum % 2));
  }
  for (int i = 1; i <= n; i++) {
    if (d[i])
      v.push_back(i);
  }
  printf("%d\n", v.size());
  for (int i = 0; i < v.size(); i++)
    printf("%d ", v[i]);
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int out_print(vector<int> b, int N, int num) {
  cout << num << endl;
  if (num == 0)
    return 0;

  for (int i = 0; i < N; i++) {
    if (b[i] == 1) {
      cout << (i + 1) << " ";
    }
  }
  return 0;
}

int is_odd(vector<int> b, int N, int k) {
  int sum = 0;
  for (int j = 1;; j++) {
    int index = k * j;
    if (index > N)
      break;
    sum += b[index - 1];
  }
  return sum % 2;
}

int main(void) {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b[i] = 0;
  }

  if (N == 1) {
    b[N - 1] = a[N - 1];
    out_print(b, N, b[N - 1]);
    return 0;
  }

  int num = 0;
  for (int i = N - 1; i >= 0; i--) {
    int _is_odd = is_odd(b, N, i + 1);
    b[i] = _is_odd ^ a[i];
    num += b[i];
  }

  out_print(b, N, num);
  return 0;
}

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

int out_print(vector<int> b, int N, int num) {
  cout << num << endl;
  if (num == 0)
    return 0;

  for (int i = 0; i < N; i++) {
    if (b[i] == 1) {
      cout << (i + 1) << " ";
    }
  }
  return 0;
}

int is_odd(vector<int> b, int N, int k) {
  int sum = 0;
  for (int j = 1;; j++) {
    int index = k * j;
    if (index > N)
      break;
    sum += b[index - 1];
  }
  return sum % 2;
}

int main(void) {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b[i] = 0;
  }

  if (N == 1) {
    b[N - 1] = a[N - 1];
    out_print(b, N, b[N - 1]);
    return 0;
  }

  int num = 0;
  for (int i = N - 1; i >= 0; i--) {

    int sum = 0;
    for (int j = 1;; j++) {
      int index = (i + 1) * j;
      if (index > N)
        break;
      sum += b[index - 1];
    }

    b[i] = (sum % 2) ^ a[i];
    num += b[i];
  }

  out_print(b, N, num);
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;
int main() {
  int m;
  cin >> m;
  vector<int> v(m + 1);
  for (int i = 1; i <= m; i++)
    cin >> v[i];
  vector<int> b(m + 1, 0);
  // for(int i=1;i<=m;i++) cout<<v[i]<<" ";
  // cout<<endl;
  int cnt = 0;
  for (int i = m; i > 0; i--) {
    // cout<<endl;
    // cout<<i<<"start"<<endl;
    int sum = 0;
    for (int j = m; j >= i; j--) {
      if (j % i == 0) {
        // cout<<j<<"baisu"<<endl;
        sum += b[j];
      }
    }
    if (v[i] == 0) {
      // cout<<"0"<<endl;
      if (sum % 2 == 0)
        b[i] = 0;
      else {
        b[i] = 1;
        cnt++;
      }
    } else {
      // cout<<"1"<<endl;
      if (sum % 2 == 0) {
        b[i] = 1;
        cnt++;
      } else
        b[i] = 0;
    }
    // cout<<sum<<endl;
    // cout<<"v["<<i<<"]"<<"="<<v[i]<<endl;
  }

  if (cnt == 0)
    cout << 0 << endl;
  else {
    cout << cnt << endl;
    for (int i = 1; i <= m; i++) {
      if (b[i] == 1)
        cout << i << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;
int main() {
  int m;
  cin >> m;
  vector<int> v(m + 1);
  for (int i = 1; i <= m; i++)
    cin >> v[i];
  vector<int> b(m + 1, 0);
  // for(int i=1;i<=m;i++) cout<<v[i]<<" ";
  // cout<<endl;
  int cnt = 0;
  for (int i = m; i > 0; i--) {
    // cout<<endl;
    // cout<<i<<"start"<<endl;
    int sum = 0;
    for (int j = 2 * i; j <= m; j += i) {
      if (j > m)
        break;
      if (b[j] == 1)
        sum += 1;
    }
    if (v[i] == 0) {
      // cout<<"0"<<endl;
      if (sum % 2 == 0)
        b[i] = 0;
      else {
        b[i] = 1;
        cnt++;
      }
    } else {
      // cout<<"1"<<endl;
      if (sum % 2 == 0) {
        b[i] = 1;
        cnt++;
      } else
        b[i] = 0;
    }
    // cout<<sum<<endl;
    // cout<<"v["<<i<<"]"<<"="<<v[i]<<endl;
  }

  if (cnt == 0)
    cout << 0 << endl;
  else {
    cout << cnt << endl;
    for (int i = 1; i <= m; i++) {
      if (b[i] == 1)
        cout << i << endl;
    }
  }
  return 0;
}
Problem p02972 (C++)

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

int main() {
  int N;
  int a[100001];
  int c[100001];
  int res = 0;
  cin >> N;

  rep(i, N) cin >> a[i + 1];
  rep(i, N + 1) c[i] = 0;

  for (int i = N; i > 0; i--) {
    int j = 2;
    int sum = 0;
    while (j * i <= N) {
      sum += c[j * i];
      j++;
    }
    if (sum % 2 == a[i])
      c[i] = 0;
    else
      c[i] = 1;
  }

  for (int i = 1; i <= N; i++) {
    res += c[i];
  }
  cout << res << endl;
  for (int i = 1; i <= N; i++) {
    if (c[i] > 0)
      cout << i << " ";
  }
  cout << endl;
}

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

int main() {
  int N;
  int a[200001];
  int c[200001];
  int res = 0;
  cin >> N;

  rep(i, N) cin >> a[i + 1];
  rep(i, N + 1) c[i] = 0;

  for (int i = N; i > 0; i--) {
    int j = 2;
    int sum = 0;
    while (j * i <= N) {
      sum += c[j * i];
      j++;
    }
    if (sum % 2 == a[i])
      c[i] = 0;
    else
      c[i] = 1;
  }

  for (int i = 1; i <= N; i++) {
    res += c[i];
  }
  cout << res << endl;
  for (int i = 1; i <= N; i++) {
    if (c[i] > 0)
      cout << i << " ";
  }
  cout << endl;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>

int main() {

  // read problem
  long long int N, tmp, factor;
  std::vector<long long int> a, count, box;

  scanf("%lld", &N);
  for (long long int i = 0; i < N; i++) {
    scanf("%lld", &tmp);
    a.push_back(tmp);
    count.push_back(0);
  }

  // solve problem
  for (int i = N; i >= 1; i--) {
    // if add an ball to i-th box
    // if((a[i-1]^count[i-1])&1 != 0){
    if ((a[i - 1] + count[i - 1] + 2) % 2 != 0) {
      // update box
      box.push_back(i);
      // update count
      for (factor = 1; factor * factor < i; factor++) {
        if (i % factor == 0) {
          count[factor - 1]++;
          count[(i % factor) - 1]++;
        }
      }
      if (factor * factor == i) {
        count[factor - 1]++;
      }
    }
  }

  std::cerr << "Answer:" << std::endl;
  std::cout << box.size() << std::endl;
  for (int i = 0; i < box.size(); i++) {
    std::cout << box[i] << " ";
  }
  std::cerr << std::endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>

int main() {

  // read problem
  long long int N, tmp, factor;
  std::vector<long long int> a, count, box;

  scanf("%lld", &N);
  for (long long int i = 0; i < N; i++) {
    scanf("%lld", &tmp);
    a.push_back(tmp);
    count.push_back(0);
  }

  // solve problem
  for (int i = N; i >= 1; i--) {
    // if add an ball to i-th box
    // if((a[i-1]^count[i-1])&1 != 0){
    if ((a[i - 1] + count[i - 1] + 2) % 2 != 0) {
      // update box
      box.push_back(i);
      // update count
      for (factor = 1; factor * factor < i; factor++) {
        if (i % factor == 0) {
          count[factor - 1]++;
          count[(i / factor) - 1]++;
        }
      }
      if (factor * factor == i) {
        count[factor - 1]++;
      }
    }
  }

  std::cerr << "Answer:" << std::endl;
  std::cout << box.size() << std::endl;
  for (int i = 0; i < box.size(); i++) {
    std::cout << box[i] << " ";
  }
  std::cerr << std::endl;

  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
// ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template <typename T> void remove(std::vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N + 1);
  vector<ll> B(N + 1);
  rep(i, N) cin >> A[i + 1];
  ll M = 0;
  rrep(i, N + 1) {
    if (i == 0)
      break;
    ll cnt = 0;
    for (ll j = 0; j * i <= N; j++) {
      cnt += B[i + i * j];
    }
    if (A[i] % 2 != cnt % 2) {
      B[i]++;
      M++;
    }
  }
  cout << M << endl;
  rep(i, N + 1) {
    if (B[i] > 0)
      cout << i << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
// ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template <typename T> void remove(std::vector<T> &vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N + 1);
  vector<ll> B(N + 1);
  rep(i, N) cin >> A[i + 1];
  ll M = 0;
  rrep(i, N + 1) {
    if (i == 0)
      break;
    ll cnt = 0;
    for (ll j = 0; j * i <= N; j++) {
      cnt += B[i * j];
    }
    if (A[i] % 2 != cnt % 2) {
      B[i]++;
      M++;
    }
  }
  cout << M << endl;
  rep(i, N + 1) {
    if (B[i] > 0)
      cout << i << endl;
  }
}
Problem p02972 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> eeai(N, 0);
  vector<int> biiai(N, 0);
  int count = 0;

  for (int i = 0; i < N; i++) {
    cin >> eeai.at(i);
  }

  for (int i = N; i > 0; i--) {
    count = 0;
    for (int j = 0; j < N; j++) {
      if ((j + 1) % i == 0) {
        count += biiai.at(j);
      }
    }
    if (count % 2 == eeai.at(i - 1)) {
      biiai.at(i - 1) = 0;
    } else {
      biiai.at(i - 1) = 1;
    }
  }

  int M = 0;
  for (int i = 0; i < N; i++) {
    M += biiai.at(i);
  }
  cout << M << endl;

  for (int i = 0; i < N; i++) {
    if (biiai.at(i) == 1) {
      cout << i + 1 << " ";
    }
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> eeai(N, 0);
  vector<int> biiai(N, 0);
  int count = 0;

  for (int i = 0; i < N; i++) {
    cin >> eeai.at(i);
  }

  for (int i = N; i > 0; i--) {
    count = 0;
    for (int j = i; j < N + 1; j += i) {
      if (j % i == 0) {
        count += biiai.at(j - 1);
      }
    }
    if (count % 2 == eeai.at(i - 1)) {
      biiai.at(i - 1) = 0;
    } else {
      biiai.at(i - 1) = 1;
    }
  }

  int M = 0;
  for (int i = 0; i < N; i++) {
    M += biiai.at(i);
  }
  cout << M << endl;

  for (int i = 0; i < N; i++) {
    if (biiai.at(i) == 1) {
      cout << i + 1 << " ";
    }
  }
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> ans(n, 0);
  for (int i = n - 1; i >= 0; --i) {
    int res = 0;
    for (int j = i + (i + 1); j < n; j += (i + 1))
      res ^= ans[j];
    ans[i] = res ^ a[i];
  }
  int j_ans = 0;
  rep(i, n) j_ans += ans[i];
  dunk(j_ans);
  rep(i, n) {
    if (ans[i])
      dunk(i + 1);
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> ans(n, 0);
  for (int i = n - 1; i >= 0; --i) {
    int res = 0;
    for (int j = i + (i + 1); j < n; j += (i + 1))
      res ^= ans[j];
    ans[i] = res ^ a[i];
  }
  int j_ans = 0;
  rep(i, n) j_ans += ans[i];
  dunk(j_ans);
  rep(i, n) {
    if (ans[i])
      dunk(i + 1);
  }
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T> using V = vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
const ll inf = (1e18);
// const ll mod=998244353;
const ll mod = 1000000007;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  n++;
  V<int> a(n);
  int cnt = 0;
  for (int i = 1; i < n; i++)
    cin >> a[i];
  V<int> ans(n, 0);
  for (int i = n; i >= 1; i--) {
    int sum = 0;
    for (int j = 1; i * j < n; j++) {
      sum ^= ans[i * j];
    }
    if (sum != a[i]) {
      ans[i] = 1;
      cnt++;
    }
  }
  cout << cnt << "\n";
  for (int i = 1; i < n; i++)
    if (ans[i])
      cout << i << " ";
  if (cnt)
    cout << "\n";
}

Fixed submission:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T> using V = vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
const ll inf = (1e18);
// const ll mod=998244353;
const ll mod = 1000000007;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }
struct __INIT {
  __INIT() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} __init;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  n++;
  V<int> a(n);
  int cnt = 0;
  for (int i = 1; i < n; i++)
    cin >> a[i];
  V<int> ans(n, 0);
  for (int i = n - 1; i >= 1; i--) {
    int sum = 0;
    for (int j = 1; i * j < n; j++) {
      sum ^= ans[i * j];
    }
    if (sum != a[i]) {
      ans[i] = 1;
      cnt++;
    }
  }
  cout << cnt << "\n";
  for (int i = 1; i < n; i++)
    if (ans[i])
      cout << i << " ";
  if (cnt)
    cout << "\n";
}
Problem p02972 (Python)

Buggy submission (status: Time Limit Exceeded):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    result = [0 for _ in range(N)]
    for i, a in enumerate(As[::-1]):
        num = N - i
        idx = num - 1
        if N // num < 2:
            result[idx] = a
        else:
            sum_ = sum([x for i, x in enumerate(result) if idx % (i + 1) == 0])
            if sum_ % 2 == 1:
                result[idx] = 1 if a == 0 else 0
            else:
                result[idx] = 0 if a == 0 else 1
    print(len([x for x in result if x == 1]))
    for i, x in enumerate(result):
        if x == 1:
            print(i + 1, end=" ")


if __name__ == "__main__":
    main()


Fixed submission:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    As = [int(x) for x in stdin.readline().rstrip().split()]
    result = [0 for _ in range(N)]
    for i, a in enumerate(As[::-1]):
        num = N - i
        idx = num - 1
        if N // num < 2:
            result[idx] = a
        else:
            sum_ = 0
            cnt = 2
            while True:
                if N < (num * cnt):
                    break
                sum_ += result[(num * cnt) - 1]
                cnt += 1
            if sum_ % 2 == 1:
                result[idx] = 1 if a == 0 else 0
            else:
                result[idx] = 0 if a == 0 else 1
    print(len([x for x in result if x == 1]))
    for i, x in enumerate(result):
        if x == 1:
            print(i + 1, end=" ")


if __name__ == "__main__":
    main()
Problem p02972 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

t = [0] * N
for i in range(N - 1, -1, -1):
    t[i] = (sum(t[2 * (i + 1) - 1 :: i]) % 2) ^ a[i]

print(sum(t))
print(*[i + 1 for i in range(N) if t[i] == 1])


Fixed submission:
N = int(input())
a = list(map(int, input().split()))

t = [0] * N
for i in range(N - 1, -1, -1):
    t[i] = (sum(t[2 * (i + 1) - 1 :: i + 1]) % 2) ^ a[i]

print(sum(t))
print(*[i + 1 for i in range(N) if t[i] == 1])
Problem p02972 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
a = [0] + list(map(int, input().split()))
for i in range(n // 2, 0, -1):
    a[i] ^= a[i * 2 :: i]

s = [i for i, b in enumerate(a) if b]
print(len(s))
print(*s)


Fixed submission:
n = int(input())
a = [0] + list(map(int, input().split()))
for i in range(n // 2, 0, -1):
    a[i] = sum(a[i::i]) % 2

s = [i for i, b in enumerate(a) if b]
print(len(s))
print(*s)
Problem p02972 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
a = input()
r = [None] * (n + 1)
for i in range(n, 0, -1):
    r[i] = (ord(a[2 * i - 1]) + sum(r[i * 2 :: i])) % 2
print(r.count(1))
print(*(i for i, x in enumerate(r) if x))


Fixed submission:
n = int(input())
a = input()
r = [None] * (n + 1)
for i in range(n, 0, -1):
    r[i] = (ord(a[2 * i - 2]) + sum(r[i * 2 :: i])) % 2
print(r.count(1))
print(*(i for i, x in enumerate(r) if x))
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
const int MAXN = 2e5 + 5;
int A[MAXN]{};
int B[MAXN]{};
int M, N;

int count_up(int i) {
  int sum = 0;
  for (int j = i; j * j <= N; j += i) {
    if (B[j])
      sum ^= 1;
  }
  return sum;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
  }
  M = 0;
  for (int i = N; i >= 1; --i) {
    if (count_up(i) != A[i]) {
      B[i] = 1;
      ++M;
    }
  }
  printf("%d\n", M);
  for (int i = 1; i <= N; ++i) {
    if (B[i])
      printf("%d ", i);
  }
  putchar('\n');
  return 0;
}

Fixed submission:
#include <cstdio>
const int MAXN = 2e5 + 5;
int A[MAXN]{};
int B[MAXN]{};
int M, N;

int count_up(int i) {
  int sum = 0;
  for (int j = i; j <= N; j += i) {
    if (B[j])
      sum ^= 1;
  }
  return sum;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
  }
  M = 0;
  for (int i = N; i >= 1; --i) {
    if (count_up(i) != A[i]) {
      B[i] = 1;
      ++M;
    }
  }
  printf("%d\n", M);
  for (int i = 1; i <= N; ++i) {
    if (B[i])
      printf("%d ", i);
  }
  putchar('\n');
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b(n, 0);
  int count = 0;
  vector<int> c;

  for (int i = n; i >= 1; i--) {
    int sum = 0;
    for (int j = n; j >= i; j--) {
      if (j % i == 0)
        sum += b[j - 1];
    }
    if (sum % 2 != a[i - 1]) {
      c.push_back(i);
      count++;
      b[i - 1]++;
    }
  }
  if (count != 0) {
    cout << count << endl;
    for (auto it : c)
      cout << it << endl;
  } else if (count == 0) {
    if (*max_element(a.begin(), a.end()) == 0)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define _rep(i, m, n) for (long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B) {
  if (B == 0)
    return A;
  return gcd(B, A % B);
}
ll lcm(ll A, ll B) { return A * B / gcd(A, B); }

/*------------------------------------------------------------------*/

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b(n, 0);
  int count = 0;
  vector<int> c;

  for (int i = n; i >= 1; i--) {
    int sum = 0;
    for (int j = i; j <= n; j += i) {
      if (j % i == 0)
        sum += b[j - 1];
    }
    if (sum % 2 != a[i - 1]) {
      c.push_back(i);
      count++;
      b[i - 1]++;
    }
  }
  if (count != 0) {
    cout << count << endl;
    for (auto it : c)
      cout << it << endl;
  } else if (count == 0) {
    if (*max_element(a.begin(), a.end()) == 0)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  }
}
Problem p02972 (C++)

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

int main() {
  int n;
  cin >> n;
  int aa;
  vector<int> a(n + 1);
  rep(i, n) {
    cin >> aa;
    if (aa == 0) {
      a[i + 1] = -1;
    } else {
      a[i + 1] = 1;
    }
  }

  vector<vector<int>> memo(n + 1);

  int k, k2;
  rep(i, n) {
    k = 2;
    while ((i + 1) * k <= n) {
      memo[(i + 1) * k].push_back(i + 1);
      ++k;
    }
  }

  int ka;
  ka = 0;
  int l;
  vector<int> ans(n + 1, 0);
  for (int i = n; i > 0; --i) {
    if (a[i] == 1) {
      ++ka;
      ans[i] = 1;
      if (memo[i].size() != 0) {
        l = memo[i].size();
        rep(i, l) { ans[memo[i][l]] *= -1; }
      }
    }
  }

  cout << ka << endl;
  rep(i, n) {
    if (a[i + 1] == 1) {
      cout << i + 1 << endl;
    }
  }

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  int aa;
  vector<int> a(n + 1);
  rep(i, n) {
    cin >> aa;
    if (aa == 0) {
      a[i + 1] = -1;
    } else {
      a[i + 1] = 1;
    }
  }

  vector<vector<int>> memo(n + 1);

  int k, k2;
  rep(i, n) {
    k = 2;
    while ((i + 1) * k <= n) {
      memo[(i + 1) * k].push_back(i + 1);
      ++k;
    }
  }

  int ka;
  ka = 0;
  int l;
  vector<int> ans(n + 1, 0);
  for (int i = n; i > 0; --i) {
    if (a[i] == 1) {
      ++ka;
      ans[i] = 1;
      if (memo[i].size() != 0) {
        l = memo[i].size();
        rep(j, l) { a[memo[i][j]] *= -1; }
      }
    }
  }

  cout << ka << endl;
  rep(i, n) {
    if (a[i + 1] == 1) {
      cout << i + 1 << endl;
    }
  }

  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod = 1e9 + 7;

int main() {
  int N;
  ll a[300001];
  ll b[300001];
  int cnt(0);
  cin >> N;
  for (int i(1); i <= N; i++)
    cin >> b[i];
  for (int i(N / 2 + 1); i <= N; i++) {
    a[i] = b[i];
    if (a[i] == 1)
      cnt += 1;
  }
  for (int i(N / 2); i > 0; i--) {
    // a[i] is needed
    int sum(0);
    for (int j(i); j <= N; j += i) {
      cerr << j * i << " ";
      sum += a[j];
    }
    // cout <<sum << " " <<  b[i] << endl;
    if (sum % 2 == b[i])
      a[i] = 0;
    else {
      a[i] = 1;
      cnt += 1;
    }
  }

  cout << cnt << endl;
  for (int i(1); i <= N; i++) {
    if (a[i] == 1) {
      cout << i << endl;
    }
  }
  return 0;
}


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

int main() {
  int N;
  ll a[300001];
  ll b[300001];
  int cnt(0);
  cin >> N;
  for (int i(1); i <= N; i++)
    cin >> b[i];
  for (int i(N / 2 + 1); i <= N; i++) {
    a[i] = b[i];
    if (a[i] == 1)
      cnt += 1;
  }
  for (int i(N / 2); i > 0; i--) {
    // a[i] is needed
    int sum(0);
    for (int j(i * 2); j <= N; j += i) {
      sum += a[j];
    }
    // cout <<sum << " " <<  b[i] << endl;
    if (sum % 2 == b[i])
      a[i] = 0;
    else {
      a[i] = 1;
      cnt += 1;
    }
  }

  cout << cnt << endl;
  for (int i(1); i <= N; i++) {
    if (a[i] == 1) {
      cout << i << endl;
    }
  }
  return 0;
}
Problem p02972 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

with open("testcase_12.in") as f:
    n = int(f.readline())
    a = list(map(int, f.readline().split()))

b = [-1] * n
for i in range(n, 0, -1):
    cnt = sum(b[j - 1] for j in range(i + i, n + 1, i))
    b[i - 1] = int(a[i - 1] != cnt % 2)

print(sum(b))
if sum(b) > 0:
    print(*[i + 1 for i in range(n) if b[i] == 1])


Fixed submission:
n = int(input())
a = list(map(int, input().split()))

b = [-1] * n
for i in range(n, 0, -1):
    cnt = sum(b[j - 1] for j in range(i + i, n + 1, i))
    b[i - 1] = int(a[i - 1] != cnt % 2)

print(sum(b))
if sum(b) > 0:
    print(*[i + 1 for i in range(n) if b[i] == 1])
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
int N;
vector<int> a, b;
int recursive(int i) {
  int x = 0;
  for (int k = 2; i * k <= N; k++) {
    x += recursive(i * k);
  }
  return b[i] = (a[i] + x) & 1;
}
int main() {
  cin >> N;
  a = vector<int>(N + 1);
  b = vector<int>(N + 1, -1);
  for (int i = 1; i <= N; i++)
    cin >> a[i];
  recursive(1);
  vector<int> ans;
  for (int i = 1; i <= N; i++) {
    if (b[i])
      ans.push_back(i);
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << (i ? " " : "") << ans[i];
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
int N;
vector<int> a, b;
int recursive(int i) {
  if (b[i] >= 0)
    return b[i];
  int x = 0;
  for (int k = 2; i * k <= N; k++) {
    x += recursive(i * k);
  }
  return b[i] = (a[i] + x) & 1;
}
int main() {
  cin >> N;
  a = vector<int>(N + 1);
  b = vector<int>(N + 1, -1);
  for (int i = 1; i <= N; i++)
    cin >> a[i];
  recursive(1);
  vector<int> ans;
  for (int i = 1; i <= N; i++) {
    if (b[i])
      ans.push_back(i);
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << (i ? " " : "") << ans[i];
  }
  cout << endl;
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[200010], c[200010];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    c[i] = 0;
  }
  vector<int> v;
  for (int i = n; i >= 1; i++) {
    for (int j = i * 2; j <= n; j += i) {
      a[i] ^= c[j];
    }
    c[i] = a[i];
    if (c[i])
      v.push_back(i);
  }
  cout << v.size() << endl;
  for (auto t : v)
    cout << t << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[200010], c[200010];
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    c[i] = 0;
  }
  vector<int> v;
  for (int i = n; i >= 1; i--) {
    for (int j = i * 2; j <= n; j += i) {
      a[i] ^= c[j];
    }
    c[i] = a[i];
    if (c[i])
      v.push_back(i);
  }
  cout << v.size() << endl;
  for (auto t : v)
    cout << t << endl;
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  int a[N + 1];
  int b[N + 1];
  vector<int> v;
  a[0] = 0;
  b[0] = 0;
  int count = 0;
  int tmp = 0;
  for (int i = 0; i < N; i++) {
    a[i + 1] = 0;
    b[i + 1] = 0;
    cin >> a[i + 1];
    if (i >= N / 2) {
      b[i + 1] = a[i + 1];
      if (b[i + 1] == 1) {
        count++;
        v.push_back(i + 1);
      }
    }
  }

  for (int i = N / 2; i > 0; i--) {
    // cout << a[i];
    int total = 0;
    for (int j = i + 1; j < N + 1; j++) {
      if (j % i == 0)
        total += b[j];
      // cout << total << endl;
    }
    b[i] = (total + a[i]) % 2;
    if (b[i] == 1) {
      count++;
      v.push_back(i);
    }
  }

  cout << count << endl;
  // for(int i=0;i<N;i++){
  //     cout << b[i+1];
  // }
  if (count > 0) {
    for (int i = 0; i < count; i++) {
      cout << v[i] << " ";
    }
  }
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  int a[N + 1];
  int b[N + 1];
  vector<int> v;
  a[0] = 0;
  b[0] = 0;
  int count = 0;
  int tmp = 0;
  for (int i = 0; i < N; i++) {
    a[i + 1] = 0;
    b[i + 1] = 0;
    cin >> a[i + 1];
    if (i >= N / 2) {
      b[i + 1] = a[i + 1];
      if (b[i + 1] == 1) {
        count++;
        v.push_back(i + 1);
      }
    }
  }

  for (int i = N / 2; i > 0; i--) {
    // cout << a[i];
    int total = 0;
    int base = 1;
    while (base * i <= N) {
      total += b[base * i];
      base++;
    }
    b[i] = (total + a[i]) % 2;
    if (b[i] == 1) {
      count++;
      v.push_back(i);
    }
  }

  cout << count << endl;
  // for(int i=0;i<N;i++){
  //     cout << b[i+1];
  // }
  if (count > 0) {
    for (int i = 0; i < count; i++) {
      cout << v[i] << " ";
    }
  }
}
Problem p02972 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  rep(i, n) cin >> a[i + 1];

  vector<int> b(n + 1);
  for (int i = n; i >= 1; i--) {
    int sum = 0;
    for (int j = i + i; j * i < n; j += i) {
      sum ^= b[j];
    }
    b[i] = sum ^ a[i];
  }
  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (b[i])
      ans.push_back(i);
  }
  cout << ans.size() << endl;
  for (int i : ans)
    cout << i << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  rep(i, n) cin >> a[i + 1];

  vector<int> b(n + 1);
  for (int i = n; i >= 1; i--) {
    int sum = 0;
    for (int j = i + i; j <= n; j += i) {
      sum ^= b[j];
    }
    b[i] = sum ^ a[i];
  }
  vector<int> ans;
  for (int i = 1; i <= n; i++) {
    if (b[i])
      ans.push_back(i);
  }
  cout << ans.size() << endl;
  for (int i : ans)
    cout << i << endl;
  return 0;
}
Problem p02972 (C++)

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

int a[200005];
int b[200005];
int main() {
  int n;
  cin >> n;
  int tmp;
  int ans;
  int count = 0;
  for (int i = 1; i < n + 1; i++)
    cin >> a[i];
  for (int i = n; i >= 0; i--) {
    tmp = i;
    ans = 0;
    while (tmp <= n) {
      ans += b[tmp];
      tmp += i;
    }
    if (ans % 2 != a[i]) {
      b[i]++;
      count++;
    }
  }
  cout << count << endl;
  for (int i = 1; i < n + 1; i++)
    if (b[i] > 0)
      cout << i << endl;
}

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

int a[200005];
int b[200005];
int main() {
  int n;
  cin >> n;
  int tmp;
  int ans;
  int count = 0;
  for (int i = 1; i < n + 1; i++)
    cin >> a[i];
  for (int i = n; i > 0; i--) {
    tmp = i;
    ans = 0;
    while (tmp <= n) {
      ans += b[tmp];
      tmp += i;
    }
    if (ans % 2 != a[i]) {
      b[i]++;
      count++;
    }
  }
  cout << count << endl;
  for (int i = 1; i < n + 1; i++)
    if (b[i] > 0)
      cout << i << endl;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}

int main() {
  long long N;
  cin >> N;
  vector<int> a(N); // amari
  REP(i, N) { cin >> a[i]; }
  vector<int> b(N, 0);
  // cout << N / 2 << endl;
  for (int i = N - 1; i > N / 2 - 1; i--) {
    b[i] = a[i];
    // cout << "i+1" << i + 1 << " b;" << b[i] << endl;
  }
  // cout << "maji" << endl;
  for (int i = N / 2 - 1; i >= 0; i--) {
    int tmp = 0;
    for (int j = 2 * (i + 1); j * (i + 1) <= N; j += (i + 1)) {
      tmp += b[j - 1];
    }
    if (tmp % 2 == a[i]) {
      b[i] = 0;
    } else {
      b[i] = 1;
    }
  }
  // cout << "maji" << endl;
  cout << accumulate(b.begin(), b.end(), 0) << endl;
  REP(i, N) {
    if (b[i] > 0) {
      cout << i + 1 << " ";
    }
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

void print(const std::vector<int> &v) {
  std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
  std::cout << std::endl;
}

int main() {
  long long N;
  cin >> N;
  vector<int> a(N); // amari
  REP(i, N) { cin >> a[i]; }
  vector<int> b(N, 0);
  // cout << N / 2 << endl;
  for (int i = N - 1; i > N / 2 - 1; i--) {
    b[i] = a[i];
    // cout << "i+1" << i + 1 << " b;" << b[i] << endl;
  }
  // cout << "maji" << endl;
  for (int i = N / 2 - 1; i >= 0; i--) {
    int tmp = 0;
    for (int j = 2 * (i + 1); j <= N; j += (i + 1)) {
      tmp += b[j - 1];
    }
    if (tmp % 2 == a[i]) {
      b[i] = 0;
    } else {
      b[i] = 1;
    }
  }
  // cout << "maji" << endl;
  cout << accumulate(b.begin(), b.end(), 0) << endl;
  REP(i, N) {
    if (b[i] > 0) {
      cout << i + 1 << " ";
    }
  }
  cout << endl;
  return 0;
}
Problem p02972 (C++)

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

int a[200010];
int b[200010];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }

  for (int i = n; i >= 0; --i) {
    int sum = 0;
    for (int j = i; j <= n; j += i) {
      sum += b[j];
    }
    if (sum % 2 != a[i]) {
      b[i] ^= 1;
    }
  }

  for (int i = 1; i <= n; ++i) {
    int sum = 0;
    for (int j = i; j <= n; j += i) {
      sum += b[j];
    }
    if (sum % 2 != a[i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  int m = 0;
  for (int i = 1; i <= n; ++i) {
    if (b[i] == 1)
      m++;
  }
  cout << m << endl;
  for (int i = 1; i <= n; ++i) {
    if (b[i] == 1)
      cout << i << " ";
  }

  return 0;
}


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

int a[200010];
int b[200010];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }

  for (int i = n; i >= 1; --i) {
    int sum = 0;
    for (int j = i; j <= n; j += i) {
      sum += b[j];
    }
    if (sum % 2 != a[i]) {
      b[i] ^= 1;
    }
  }

  for (int i = 1; i <= n; ++i) {
    int sum = 0;
    for (int j = i; j <= n; j += i) {
      sum += b[j];
    }
    if (sum % 2 != a[i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  int m = 0;
  for (int i = 1; i <= n; ++i) {
    if (b[i] == 1)
      m++;
  }
  cout << m << endl;
  for (int i = 1; i <= n; ++i) {
    if (b[i] == 1)
      cout << i << " ";
  }

  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979323846;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  vector<int> b(N, 0);
  for (int i = N - 1; i >= 0; i--) {
    int sum = 0;
    for (int j = i + 1; j < N; j++) {
      if ((j + 1) % (i + 1) == 0)
        sum += b[j];
    }
    if (sum % 2 == 0 && a[i] % 2 != 0)
      b[i] = 1;
    else if (sum % 2 != 0 && a[i] % 2 == 0)
      b[i] = 1;
    else
      b[i] = 0;
  }
  int M = 0;
  for (int i = 0; i < N; i++) {
    if (b[i] == 1)
      M++;
  }
  cout << M << endl;
  for (int i = 0; i < N; i++) {
    if (b[i] == 1)
      cout << i + 1 << " ";
  }
  cout << 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 ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979323846;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  vector<int> b(N, 0);
  for (int i = N - 1; i >= 0; i--) {
    int sum = 0;
    for (int j = i; j < N; j += i + 1)
      sum += b[j];
    if (sum % 2 == 0 && a[i] % 2 != 0)
      b[i] = 1;
    else if (sum % 2 != 0 && a[i] % 2 == 0)
      b[i] = 1;
    else
      b[i] = 0;
  }
  int M = 0;
  for (int i = 0; i < N; i++) {
    if (b[i] == 1)
      M++;
  }
  cout << M << endl;
  for (int i = 0; i < N; i++) {
    if (b[i] == 1)
      cout << i + 1 << " ";
  }
  cout << endl;
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, end) rep2(i, 0, (end))
#define rep2(i, beg, end) for (int i = (beg); i < (end); i++)
#define all(cont) begin(cont), end(cont)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
typedef pair<ll, string> pis;
typedef pair<string, ll> psi;

string gets(bool skipnewline);
vi get_n_array(int n);

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi a = get_n_array(n);
  vi b(n, 0);
  ll cnt = 0;
  for (int i = n; i >= 1; i--) {
    ll s = 0;
    for (int mul = 2; i * mul <= n; mul++) {
      s += b[(i * mul) - 1];
    }
    int x;
    if (s % 2 == 0) { // even
      x = a[i - 1];
    } else { // odd
      x = 1 - a[i - 1];
    }
    if (x) {
      b[i - 1] = x;
      cnt++;
    }
  }
  cout << cnt << endl;
  if (cnt > 0) {
    for (int i = 0; i < n; i++) {
      if (b[i] != 0) {
        cout << i + 1 + " ";
      }
    }
    cout << endl;
  }

  return 0;
}

string gets(bool skipToNextline) {
  if (skipToNextline)
    gets(false);
  const int LINE_MAX = 1024;
  char buf[LINE_MAX];
  cin.getline(buf, sizeof(buf));
  return buf;
}

vi get_n_array(int n) {
  vi v;
  while (n-- > 0) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  return v;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define rep(i, end) rep2(i, 0, (end))
#define rep2(i, beg, end) for (int i = (beg); i < (end); i++)
#define all(cont) begin(cont), end(cont)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
typedef pair<ll, string> pis;
typedef pair<string, ll> psi;

string gets(bool skipnewline);
vi get_n_array(int n);

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi a = get_n_array(n);
  vi b(n, 0);
  ll cnt = 0;
  for (int i = n; i >= 1; i--) {
    ll s = 0;
    for (int mul = 2; i * mul <= n; mul++) {
      s += b[(i * mul) - 1];
    }
    int x;
    if (s % 2 == 0) { // even
      x = a[i - 1];
    } else { // odd
      x = 1 - a[i - 1];
    }
    if (x) {
      b[i - 1] = x;
      cnt++;
    }
  }
  cout << cnt << endl;
  if (cnt > 0) {
    for (int i = 0; i < n; i++) {
      if (b[i]) {
        cout << i + 1 << " ";
      }
    }
    cout << endl;
  }

  return 0;
}

string gets(bool skipToNextline) {
  if (skipToNextline)
    gets(false);
  const int LINE_MAX = 1024;
  char buf[LINE_MAX];
  cin.getline(buf, sizeof(buf));
  return buf;
}

vi get_n_array(int n) {
  vi v;
  while (n-- > 0) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  return v;
}