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

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

using namespace std;
typedef long long ll;
ll n;
int a[1000000];
int b[1000000];
int c[1000000];
int main() {
  ll cnt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    b[i] = 0;
  // cerr << " end in" << endl;
  for (ll i = n; i > 0; i--) {
    ll sum = 0;
    // for( ll j=i; j<=n; j+=i) sum+=b[j];
    for (ll j = 0; j < cnt; j++)
      if (c[j] % i == 0)
        sum++;
    if (a[i] != (sum % 2)) {
      b[i] = 1;
      c[cnt] = i;
      cnt++;
    } else
      b[i] = 0;
  }
  /*
  for(ll i=1; i<=n; i++){
      cout << b[i] << endl;
  }
  */
  // cerr << "end calc" << endl;
  cout << cnt << endl;
  for (ll i = 0; i < cnt; i++) {
    cout << c[i] << " ";
  }
  if (cnt != 0)
    cout << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
ll n;
int a[1000000];
int b[1000000];
int c[1000000];
int main() {
  ll cnt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    b[i] = 0;
  // cerr << " end in" << endl;
  for (ll i = n; i > 0; i--) {
    ll sum = 0;
    for (ll j = i; j <= n; j += i)
      sum += b[j];
    // for( ll j=0; j<cnt; j++) if( c[j]%i == 0) sum++;
    if (a[i] != (sum % 2)) {
      b[i] = 1;
      c[cnt] = i;
      cnt++;
    } else
      b[i] = 0;
  }
  /*
  for(ll i=1; i<=n; i++){
      cout << b[i] << endl;
  }
  */
  // cerr << "end calc" << endl;
  cout << cnt << endl;
  for (ll i = 0; i < cnt; i++) {
    cout << c[i] << " ";
  }
  if (cnt != 0)
    cout << endl;
  return 0;
}
Problem p02972 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i * 2 + 1; j < n; j += i + 1) {
      a[i] ^= a[j];
    }
    count += a[i];
  }
  cout << count << endl;
  for (int i = 0; i < n; i++) {
    if (a[i])
      cout << i + " ";
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i * 2 + 1; j < n; j += i + 1) {
      a[i] ^= a[j];
    }
    count += a[i];
  }
  cout << count << endl;
  for (int i = 0; i < n; i++) {
    if (a[i])
      cout << i + 1 << " ";
  }
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
using namespace std;

const int M = 2e5 + 5;
int a[M];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int cnt = 0;
  for (int i = n; i >= 1; i--) {
    for (int j = 2; j <= n; j++)
      a[i] = (a[i] + a[i * j]) % 2;
    if (a[i])
      cnt++;
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= n; i++)
    if (a[i])
      printf("%d ", i);
  printf("\n");
  return 0;
}

Fixed submission:
#include <iostream>
#include <stdio.h>
using namespace std;

const int M = 2e5 + 5;
int a[M];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  int cnt = 0;
  for (int i = n; i >= 1; i--) {
    for (int j = 2; i * j <= n; j++)
      a[i] = (a[i] + a[i * j]) % 2;
    if (a[i])
      cnt++;
  }
  printf("%d\n", cnt);
  for (int i = 1; i <= n; i++)
    if (a[i])
      printf("%d ", i);
  printf("\n");
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {

  int N;
  bool A[2010], C[2010];
  vector<int> B;
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    bool a;
    cin >> a;
    A[i] = (a > 0 ? true : false);
  }
  int sum = 0;
  for (int i = N; i >= 1; --i) {
    int j = i;
    bool c = A[i];
    while (j + i <= N) {
      j += i;
      c ^= C[j];
    }
    C[i] = c;
    if (c) {
      sum++;
      B.push_back(i);
    }
  }

  cout << sum << endl;
  for (auto b : B) {
    cout << b << endl;
  }
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {

  int N;
  bool A[200010], C[200010];
  vector<int> B;
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    bool a;
    cin >> a;
    A[i] = (a > 0 ? true : false);
  }
  int sum = 0;
  for (int i = N; i >= 1; --i) {
    int j = i;
    bool c = A[i];
    while (j + i <= N) {
      j += i;
      c ^= C[j];
    }
    C[i] = c;
    if (c) {
      sum++;
      B.push_back(i);
    }
  }

  cout << sum << endl;
  for (auto b : B) {
    cout << b << endl;
  }
}
Problem p02972 (C++)

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

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

  int N;
  cin >> N;

  int a[2100];
  int b[2100];
  vector<int> x;
  int c = 0;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }
  for (int i = N; i > 0; i--) {
    int z = 2;
    int sum = 0;
    while (z * i <= N) {
      sum += b[z * i];
      z++;
    }
    if (sum % 2 == a[i])
      b[i] = 0;
    else {
      b[i] = 1;
      x.push_back(i);
      c++;
    }
  }
  cout << c << endl;
  for (int i = 0; i < c; i++) {
    cout << x[i] << " ";
  }
}

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

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

  int N;
  cin >> N;

  int a[210000];
  int b[210000];
  vector<int> x;
  int c = 0;
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }
  for (int i = N; i > 0; i--) {
    int z = 2;
    int sum = 0;
    while (z * i <= N) {
      sum += b[z * i];
      z++;
    }
    if (sum % 2 == a[i])
      b[i] = 0;
    else {
      b[i] = 1;
      x.push_back(i);
      c++;
    }
  }
  cout << c << endl;
  for (int i = 0; i < c; i++) {
    cout << x[i] << " ";
  }
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
ll min(ll a, ll b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

ll max(ll a, ll b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

ll power(ll a, ll b) {
  ll ans = 1;
  for (ll i = 1; i <= b; i++) {
    ans *= a;
  }
  return ans;
}

ll gcd(ll m, ll n) {
  if (n == 0) {
    return m;
  }
  return gcd(n, m % n);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / gcd(a, b) * b;
}
int main() {

  ll N;
  cin >> N;

  vector<ll> a(N);
  ll sum = 0;
  rep(i, N) { cin >> a[i]; }
  vector<bool> ans(N);
  ll num = 0;

  for (ll i = N - 1; i >= 0; i--) {
    if (i == N - 1) {
      if (a[i] == 1) {
        ans[i] = true;
        num++;
      } else {
        ans[i] = false;
      }

    } else {
      ll sum = 0;
      for (ll j = i + 1; j <= N - 1; j++) {
        if (ans[j]) {
          if ((j + 1) % (i + 1) == 0) {
            sum++;
          }
        }
      }

      if ((sum % 2 == 1 && a[i] == 0) || (sum % 2 == 0 && a[i] == 1)) {
        ans[i] = true;
        num++;
      } else {
        ans[i] = false;
      }
    }
  }

  cout << num << endl;
  rep(i, N) {
    if (ans[i]) {
      cout << i + 1 << " ";
    }
  }

  cout << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
ll min(ll a, ll b) {
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

ll max(ll a, ll b) {
  if (a > b) {
    return a;
  } else {
    return b;
  }
}

ll power(ll a, ll b) {
  ll ans = 1;
  for (ll i = 1; i <= b; i++) {
    ans *= a;
  }
  return ans;
}

ll gcd(ll m, ll n) {
  if (n == 0) {
    return m;
  }
  return gcd(n, m % n);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / gcd(a, b) * b;
}
int main() {

  ll N;
  cin >> N;

  vector<ll> a(N);
  ll sum = 0;
  rep(i, N) { cin >> a[i]; }
  vector<bool> ans(N);
  ll num = 0;

  for (ll i = N - 1; i >= 0; i--) {
    if (i == N - 1) {
      if (a[i] == 1) {
        ans[i] = true;
        num++;
      } else {
        ans[i] = false;
      }

    } else {
      ll sum = 0;
      ll X = N / (i + 1);
      for (ll j = 2; j <= X; j++) {
        if (ans[j * (i + 1) - 1]) {

          sum++;
        }
      }

      if ((sum % 2 == 1 && a[i] == 0) || (sum % 2 == 0 && a[i] == 1)) {
        ans[i] = true;
        num++;
      } else {
        ans[i] = false;
      }
    }
  }

  cout << num << endl;
  rep(i, N) {
    if (ans[i]) {
      cout << i + 1 << " ";
    }
  }

  cout << endl;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005], b[100005];
int main() {
  int n, num = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = n; i >= 1; i--) {
    int j = i * 2;
    b[i] = a[i];
    while (j <= n) {
      b[i] ^= b[j];
      j += i;
    }
    if (b[i])
      num++;
  }
  cout << num << endl;
  for (int i = 1; i <= n; i++) {
    if (b[i])
      cout << i << " ";
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200005], b[200005];
int main() {
  int n, num = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = n; i >= 1; i--) {
    int j = i * 2;
    b[i] = a[i];
    while (j <= n) {
      b[i] ^= b[j];
      j += i;
    }
    if (b[i])
      num++;
  }
  cout << num << endl;
  for (int i = 1; i <= n; i++) {
    if (b[i])
      cout << i << " ";
  }
  cout << endl;
}
Problem p02972 (C++)

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

int main() {
  long long n, sum = 0, mod = 2019;
  cin >> n;
  vector<bool> vec(n + 1, 0);
  vector<int> ans;
  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = n; i >= 1; i--) {
    int j = i;
    sum = 0;
    while (j + i <= n) {
      j += i;
      sum += vec[j];
    }
    if (sum % 2 != a[i]) {
      vec[i] = 1;
      ans.push_back(i);
    }
  }

  cout << ans.size() << endl;

  for (int i = ans.size(); i >= 0; i--)
    cout << ans[i] << endl;
}

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

int main() {
  long long n, sum = 0, mod = 2019;
  cin >> n;
  vector<bool> vec(n + 1, 0);
  vector<int> ans;
  int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = n; i >= 1; i--) {
    int j = i;
    sum = 0;
    while (j + i <= n) {
      j += i;
      sum += vec[j];
    }
    if (sum % 2 != a[i]) {
      vec[i] = 1;
      ans.push_back(i);
    }
  }

  cout << ans.size() << endl;

  for (int i = ans.size() - 1; i >= 0; i--)
    cout << ans[i] << endl;
}
Problem p02972 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  REP(i, n) { cin >> a[i]; }
  vector<int> ans(n + 1, 0);

  for (int i = n; i >= 1; --i) {
    int count = 0;
    for (int j = i; j <= n; ++j) {
      if (j % i == 0) {
        count += ans[j];
      }
    }
    if (count % 2 == a[i]) {
      ans[i] = 0;
    } else {
      ans[i] = 1;
    }
  }

  int hako = 0;
  REP(i, n) {
    if (ans[i] == 1)
      hako++;
  }

  cout << hako << endl;

  REP(i, n) {
    if (ans[i] != 0)
      cout << i << " ";
  }
  cout << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  REP(i, n) { cin >> a[i]; }
  vector<int> ans(n + 1, 0);

  for (int i = n; i >= 1; --i) {
    int count = 0;
    for (int j = 1; j * i <= n; ++j) {
      count += ans[j * i];
    }
    if (count % 2 == a[i]) {
      ans[i] = 0;
    } else {
      ans[i] = 1;
    }
  }

  int hako = 0;
  REP(i, n) {
    if (ans[i] == 1)
      hako++;
  }

  cout << hako << endl;

  REP(i, n) {
    if (ans[i] != 0)
      cout << i << " ";
  }
  cout << endl;
  return 0;
}
Problem p02972 (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 REP(i, n) for (int i = 1; i <= n; i++)
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) { cin >> a[i]; }

  vector<int> ans(N + 1);
  ans.assign(N + 1, 0);

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

  int num = 0;
  REP(i, N) { num += ans[i]; }

  cout << num << endl;
  REP(i, N) {
    if (ans[i] != 0) {
      cout << i << " ";
    }
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N + 1);
  REP(i, N) { cin >> a[i]; }

  vector<int> ans(N + 1);
  ans.assign(N + 1, 0);

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

  int num = 0;
  REP(i, N) { num += ans[i]; }

  cout << num << endl;
  REP(i, N) {
    if (ans[i] != 0) {
      cout << i << " ";
    }
  }
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

unsigned int a[100001];
bool ans[100001];

int main(void) {
  int N;
  cin >> N;
  for (int i = 0; i <= N; i++)
    ans[i] = false;
  for (int i = 1; i <= N; i++)
    cin >> a[i];

  int ans_cnt = 0;
  for (int i = N; i > 0; i--) {
    unsigned int sum = 0;
    for (int j = i; j <= N; j += i) {
      if (ans[j])
        sum++;
    }
    if ((sum & 1u) == a[i])
      ;    // 何もしない
    else { // 入れる
      ans[i] = true;
      ans_cnt++;
    }
  }

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


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

unsigned int a[200001];
bool ans[200001];

int main(void) {
  int N;
  cin >> N;
  for (int i = 0; i <= N; i++)
    ans[i] = false;
  for (int i = 1; i <= N; i++)
    cin >> a[i];

  int ans_cnt = 0;
  for (int i = N; i > 0; i--) {
    unsigned int sum = 0;
    for (int j = i; j <= N; j += i) {
      if (ans[j])
        sum++;
    }
    if ((sum & 1u) == a[i])
      ;    // 何もしない
    else { // 入れる
      ans[i] = true;
      ans_cnt++;
    }
  }

  cout << ans_cnt << endl;
  for (int i = 1; i <= N; i++) {
    if (ans[i])
      cout << i << " ";
  }
  return 0;
}
Problem p02972 (C++)

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

using namespace std;

int main() {
  long n;
  cin >> n;
  vector<long> a(n);
  for (long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<long> ans;
  for (long i = n - 1; i >= n / 2 + 1; --i) {
    ans.push_back(a[i]);
  }
  for (long i = n / 2; i >= 0; --i) {
    long sum = 0;
    for (long j = i + 1 + i + 1; j <= n; j += i + 1) {
      sum += ans[j - 1];
    }
    ans.push_back((sum + a[i]) % 2);
  }
  long sum = accumulate(ans.begin(), ans.end(), 0L);
  cout << sum << endl;
  if (sum != 0) {
    long last_1;
    for (long i = n - 1; i >= 0; --i) {
      if (ans[i] == 1) {
        last_1 = i;
        break;
      }
    }
    for (long i = 0; i < last_1; ++i) {
      if (ans[i] == 1) {
        cout << n - i;
        cout << ' ';
      }
    }
    cout << n - last_1 << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
  long n;
  cin >> n;
  vector<long> a(n);
  for (long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<long> ans;
  for (long i = n - 1; i >= n / 2 + 1; --i) {
    ans.push_back(a[i]);
  }
  for (long i = n / 2; i >= 0; --i) {
    long sum = 0;
    for (long j = i + 1 + i + 1; j <= n; j += i + 1) {
      sum += ans[n - j];
    }
    ans.push_back((sum + a[i]) % 2);
  }
  long sum = accumulate(ans.begin(), ans.end(), 0L);
  cout << sum << endl;
  if (sum != 0) {
    long last_1;
    for (long i = n - 1; i >= 0; --i) {
      if (ans[i] == 1) {
        last_1 = i;
        break;
      }
    }
    for (long i = 0; i < last_1; ++i) {
      if (ans[i] == 1) {
        cout << n - i;
        cout << ' ';
      }
    }
    cout << n - last_1 << endl;
  }

  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
/*
Original problem: https://atcoder.jp/contests/abc134/tasks/abc134_d
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x, l, u) for (ll x = l; x < u; x++)
#define RREP(x, l, u) for (ll x = l; x >= u; x--)

#define PII pair<int, int>
#define PLL pair<ll, ll>
#define MP make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const ll mod = 1e9 + 7;

namespace SOLVE {
void main() {
  int n;
  cin >> n;
  VI A(n + 1);
  REP(i, 1, n + 1) { cin >> A[i]; }

  int onecount = 0;
  VI ans(n);
  RREP(i, n, 1) {
    int c = 0;
    // check forward and see what had been set
    for (int mult = 2 * i; mult <= n; mult += i) {
      c += ans[mult];
    }
    c %= 2;
    ans[i] = c != A[i];
    if (ans[i] == 1) {
      onecount++;
    }
  }

  cout << onecount << endl;
  REP(i, 1, n + 1) {
    if (ans[i] == 1) {
      cout << i << ' ';
    }
  }
  cout << endl;
}
} // namespace SOLVE

signed main() {
  int t;
  t = 1;
  // cin >> t;
  while (t--) {
    SOLVE::main();
  }

  return 0;
}

Fixed submission:
/*
Original problem: https://atcoder.jp/contests/abc134/tasks/abc134_d
Author: sammochen
*/

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

#define REP(x, l, u) for (ll x = l; x < u; x++)
#define RREP(x, l, u) for (ll x = l; x >= u; x--)

#define PII pair<int, int>
#define PLL pair<ll, ll>
#define MP make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef vector<ll> VLL;
typedef vector<int> VI;

const ll mod = 1e9 + 7;

namespace SOLVE {
void main() {
  int n;
  cin >> n;
  VI A(n + 1);
  REP(i, 1, n + 1) { cin >> A[i]; }

  int onecount = 0;
  VI ans(n + 1);
  RREP(i, n, 1) {
    int c = 0;
    // check forward and see what had been set
    for (int mult = 2 * i; mult <= n; mult += i) {
      c += ans[mult];
    }
    c %= 2;
    ans[i] = c != A[i];
    if (ans[i] == 1) {
      onecount++;
    }
  }

  cout << onecount << endl;
  REP(i, 1, n + 1) {
    if (ans[i] == 1) {
      cout << i << ' ';
    }
  }
  cout << endl;
}
} // namespace SOLVE

signed main() {
  int t;
  t = 1;
  // cin >> t;
  while (t--) {
    SOLVE::main();
  }

  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int n, a[200005], b[200005];
vector<int> ans;
inline void dd() {
  for (int i = 1; i <= n; ++i)
    printf("%d ", b[i]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  for (int i = n; i >= 1; --i) {
    int t = 0;
    for (int j = i; j >= 1; j += i) {
      t += b[j];
    }
    if ((t % 2) != a[i]) {
      b[i] = 1;
      ans.push_back(i);
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); ++i)
    printf("%d ", ans[i]);
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int n, a[200005], b[200005];
vector<int> ans;
inline void dd() {
  for (int i = 1; i <= n; ++i)
    printf("%d ", b[i]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  for (int i = n; i >= 1; --i) {
    int t = 0;
    for (int j = i; j <= n; j += i) {
      t += b[j];
    }
    if ((t % 2) != a[i]) {
      b[i] = 1;
      ans.push_back(i);
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); ++i)
    printf("%d ", ans[i]);
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  vector<long long int> pre(n, 0);
  vector<long long int> hoge;
  long long int ans = 0;
  for (long long int i = n - 1; i >= 0; i--) {
    long long int now = 0;
    long long int step = 1;
    long long int start = n - 1;
    if (i + 1 > n / 2)
      start = n / 2;
    for (long long int j = start; j > i; j -= step) {
      if ((j + 1) % (i + 1) == 0) {
        step = i + 1;
        now += pre.at(j);
      }
    }
    if (now % 2 != a.at(i)) {
      ans++;
      hoge.push_back(i + 1);
      pre.at(i) = 1;
    }
  }
  cout << ans << endl;
  for (long long int i = 0; i < hoge.size(); i++) {
    cout << hoge.at(i) << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  vector<long long int> pre(n, 0);
  vector<long long int> hoge;
  long long int ans = 0;
  for (long long int i = n - 1; i >= 0; i--) {
    long long int now = 0;
    long long int step = 1;
    long long int start = n - n % (i + 1) - 1;
    for (long long int j = start; j > i; j -= step) {
      if ((j + 1) % (i + 1) == 0) {
        step = i + 1;
        now += pre.at(j);
      }
    }
    if (now % 2 != a.at(i)) {
      ans++;
      hoge.push_back(i + 1);
      pre.at(i) = 1;
    }
  }
  cout << ans << endl;
  for (long long int i = 0; i < hoge.size(); i++) {
    cout << hoge.at(i) << endl;
  }
}
Problem p02972 (C++)

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 5;
int a[N], b[N];

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef ONLINE_JUDGE
  // freopen("", "r", stdin);
  // freopen("", "w", stdout);
#endif
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  vector<int> v;
  for (int i = n; i >= 1; i--) {
    int total = 0;
    for (int j = i + i; j <= n; j += i)
      total += b[j];
    if (total % 2 != a[i] % 2)
      v.push_back(i), b[i] = 1;
  }
  cout << v.size() << '\n';
  for (auto &x : v)
    cout << x << ' ';
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 5;
int a[N], b[N];

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef ONLINE_JUDGE
  // freopen("", "r", stdin);
  // freopen("", "w", stdout);
#endif
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  vector<int> v;
  for (int i = n; i >= 1; i--) {
    int total = 0;
    for (int j = i + i; j <= n; j += i)
      total += b[j];
    if (total % 2 != a[i] % 2)
      v.push_back(i), b[i] = 1;
  }
  cout << v.size() << '\n';
  for (auto &x : v)
    cout << x << ' ';
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
// D.

#include <algorithm>
#include <bitset>
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

typedef long long LL;
typedef bitset<100002> BS;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  BS a, r;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x) {
      a[i] = true;
    }
  }
  for (int i = n; i >= 1; --i) {
    bool c = a[i];
    for (int j = i + i; j <= n; j += i) {
      c ^= r[j];
    }
    r[i] = c;
  }
  vector<int> res;
  for (int i = 1; i <= n; ++i) {
    if (r[i]) {
      res.push_back(i);
    }
  }
  cout << res.size() << endl;
  if (res.size()) {
    for (int i = 0; i < (int)res.size(); ++i) {
      if (i)
        cout << " ";
      cout << res[i];
    }
    cout << endl;
  }
  return 0;
}


Fixed submission:
// D.

#include <algorithm>
#include <bitset>
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

typedef long long LL;
typedef bitset<200002> BS;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  BS a, r;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    if (x) {
      a[i] = true;
    }
  }
  for (int i = n; i >= 1; --i) {
    bool c = a[i];
    for (int j = i + i; j <= n; j += i) {
      c ^= r[j];
    }
    r[i] = c;
  }
  vector<int> res;
  for (int i = 1; i <= n; ++i) {
    if (r[i]) {
      res.push_back(i);
    }
  }
  cout << res.size() << endl;
  if (res.size()) {
    for (int i = 0; i < (int)res.size(); ++i) {
      if (i)
        cout << " ";
      cout << res[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = n; i >= 1; i--) {
    int ans = 0;
    for (ll j = i; j <= n; j += i) {
      ans += b[j];
    }
    if (ans % 2 != a[i])
      b[i] = 1;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (b[i] > 0) {
      cnt++;
    }
  cout << cnt << endl;
  ll k = 0;
  for (ll i = 1; i <= n; i++) {
    if (b[i] && k == 0) {
      cout << i << endl;
      k++;
    } else if (b[i]) {
      cout << i << endl;
    }
  }
}


Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(2 * n), b(2 * n, 0);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = n; i >= 1; i--) {
    int ans = 0;
    for (ll j = i; j <= n; j += i) {
      ans += b[j];
    }
    if (ans % 2 != a[i])
      b[i] = 1;
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (b[i] > 0) {
      cnt++;
    }
  cout << cnt << endl;
  ll k = 0;
  for (ll i = 1; i <= n; i++) {
    if (b[i] && k == 0) {
      cout << i << endl;
      k++;
    } else if (b[i]) {
      cout << i << endl;
    }
  }
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9 + 7;
Int INF = 1e18;
double EPS = 0.00000001;
// Int mod = 998244353;

int main() {
  Int n;
  cin >> n;
  vector<bool> a(n + 1);
  for (Int i = 1; i <= n; i++) {
    Int x;
    cin >> x;
    a[i] = (x == 1);
  }
  vector<bool> b(n, false);
  vector<bool> res(n, false);
  for (Int i = n; i >= 1; i--) {
    if (a[i] != b[i]) {
      res[i] = true;
      for (Int j = 1; j * j <= i; j++) {
        if (i % j == 0) {
          if (j * j == i) {
            b[j] = !b[j];
          } else {
            b[j] = !b[j];
            b[i / j] = !b[i / j];
          }
        }
      }
    }
  }
  // else {
  Int cnt = 0;
  for (Int i = 1; i <= n; i++) {
    if (res[i])
      cnt++;
  }
  dump(cnt);
  if (cnt == 0) {
    return 0;
  }
  for (Int i = 1; i <= n; i++) {
    if (res[i])
      cout << i << " ";
  }
  cout << endl;
  //}
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9 + 7;
Int INF = 1e18;
double EPS = 0.00000001;
// Int mod = 998244353;

int main() {
  Int n;
  cin >> n;
  vector<bool> a(n + 1);
  for (Int i = 1; i <= n; i++) {
    Int x;
    cin >> x;
    a[i] = (x == 1);
  }
  vector<bool> b(n + 1, false);
  vector<bool> res(n + 1, false);
  for (Int i = n; i >= 1; i--) {
    if (a[i] != b[i]) {
      res[i] = true;
      for (Int j = 1; j * j <= i; j++) {
        if (i % j == 0) {
          if (j * j == i) {
            b[j] = !b[j];
          } else {
            b[j] = !b[j];
            b[i / j] = !b[i / j];
          }
        }
      }
    }
  }
  // else {
  Int cnt = 0;
  for (Int i = 1; i <= n; i++) {
    if (res[i])
      cnt++;
  }
  dump(cnt);
  if (cnt == 0) {
    return 0;
  }
  for (Int i = 1; i <= n; i++) {
    if (res[i])
      cout << i << " ";
  }
  cout << endl;
  //}
  return 0;
}
Problem p02972 (C++)

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n + 1);
  a[0] = -1;
  for (ll i = 1; i <= n; i++)
    cin >> a[i];

  vector<ll> b(n + 1);
  b[0] = -1;
  for (ll i = n; i >= n / 2 + 1; i--)
    b[i] = a[i];

  for (ll i = n / 2; i >= 1; i--) {
    int g = 2, t = 0;
    ll j = i;
    while (j <= n) {
      j = i;
      j *= g;
      if (b[j] == 1)
        t++;
      g++;
    }
    if (t % 2 == a[i])
      b[i] = 0;
    else
      b[i] = 1;
  }

  ll count = 0;
  for (ll i = 1; i <= n; i++) {
    if (b[i] == 1)
      count++;
  }
  cout << count << endl;
  for (ll i = 1; i <= n; i++) {
    if (b[i] == 1)
      cout << i << endl;
  }
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n + 1);
  a[0] = -1;
  for (ll i = 1; i <= n; i++)
    cin >> a[i];

  vector<ll> b(n + 1);
  b[0] = -1;
  for (ll i = n; i >= n / 2 + 1; i--)
    b[i] = a[i];

  for (ll i = n / 2; i >= 1; i--) {
    int g = 2, t = 0;
    ll j = i;
    while (1) {
      ll h = j * g;
      if (h > n)
        break;
      if (b[h] == 1)
        t++;
      g++;
    }
    if (t % 2 == a[i])
      b[i] = 0;
    else
      b[i] = 1;
  }

  ll count = 0;
  for (ll i = 1; i <= n; i++) {
    if (b[i] == 1)
      count++;
  }
  cout << count << endl;
  for (ll i = 1; i <= n; i++) {
    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++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
  ll n;
  cin >> n;
  vll vec(n);
  REP(i, n) cin >> vec.at(i);
  vll ans(n);
  for (int i = n - 1; i >= 0; i--) {
    ll total = 0;
    for (int j = i + 1; j <= n; j += i + 1) {
      total += ans.at(j);
    }
    if (vec.at(i) != total % 2)
      ans.at(i) = 1;
  }
  cout << count(ALL(ans), 1) << endl;
  if (count(ALL(ans), 1) == 0) {
    return 0;
  }
  vll out;
  REP(i, n) {
    if (ans.at(i) == 1)
      out.push_back(i + 1);
  }
  REP(i, out.size() - 1) { cout << out.at(i) << " "; }
  cout << out.at(out.size() - 1) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
  ll n;
  cin >> n;
  vll vec(n);
  REP(i, n) cin >> vec.at(i);
  vll ans(n);
  for (int i = n - 1; i >= 0; i--) {
    ll total = 0;
    for (int j = i + 1; j <= n; j += i + 1) {
      total += ans.at(j - 1);
    }
    if (vec.at(i) != total % 2)
      ans.at(i) = 1;
  }
  cout << count(ALL(ans), 1) << endl;
  if (count(ALL(ans), 1) == 0) {
    return 0;
  }
  vll out;
  REP(i, n) {
    if (ans.at(i) == 1)
      out.push_back(i + 1);
  }
  REP(i, out.size() - 1) { cout << out.at(i) << " "; }
  cout << out.at(out.size() - 1) << endl;
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);

#define l_ength size

void mul_mod(ll &a, ll b) {
  a *= b;
  a %= MOD;
}

void add_mod(ll &a, ll b) {
  a = (a < MOD) ? a : (a - MOD);
  b = (b < MOD) ? b : (b - MOD);
  a += b;
  a = (a < MOD) ? a : (a - MOD);
}

int a[100100], b[100100];
vector<int> ans;

int main(void) {
  int n, i, j, t, m;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (i = n; i > 0; --i) {
    t = 0;
    for (j = i * 2; j <= n; j += i) {
      t += b[j];
    }
    t %= 2;
    b[i] = (t ^ a[i]);
  }
  for (i = 1; i <= n; ++i) {
    if (b[i]) {
      ans.push_back(i);
    }
  }
  m = ans.l_ength();
  cout << m << endl;
  if (!m) {
    return 0;
  }
  for (i = 0; i < m; ++i) {
    cout << ((i) ? " " : "") << ans[i];
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);

#define l_ength size

void mul_mod(ll &a, ll b) {
  a *= b;
  a %= MOD;
}

void add_mod(ll &a, ll b) {
  a = (a < MOD) ? a : (a - MOD);
  b = (b < MOD) ? b : (b - MOD);
  a += b;
  a = (a < MOD) ? a : (a - MOD);
}

int a[225816], b[225816];
vector<int> ans;

int main(void) {
  int n, i, j, t, m;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (i = n; i > 0; --i) {
    t = 0;
    for (j = i * 2; j <= n; j += i) {
      t += b[j];
    }
    t %= 2;
    b[i] = (t ^ a[i]);
  }
  for (i = 1; i <= n; ++i) {
    if (b[i]) {
      ans.push_back(i);
    }
  }
  m = ans.l_ength();
  cout << m << endl;
  if (!m) {
    return 0;
  }
  for (i = 0; i < m; ++i) {
    cout << ((i) ? " " : "") << ans[i];
  }
  cout << endl;
  return 0;
}
Problem p02972 (C++)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

vector<int> divisor(int n) {
  vector<int> ret;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  int n;
  cin >> n;
  vector<int> la(n);
  la[0] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> la[i];
  }
  vector<int> ans;
  for (int i = n; i > 0; --i) {
    if (la[i] == 0)
      continue;
    ans.push_back(i);
    vector<int> div = divisor(i);
    for (int d : div) {
      la[d] = 1 - la[d];
    }
  }
  cout << ans.size() << endl;
  for (int a : ans) {
    cout << a << " ";
  }
  cout << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}

// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

vector<int> divisor(int n) {
  vector<int> ret;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  int n;
  cin >> n;
  vector<int> la(n + 1);
  la[0] = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> la[i];
  }
  vector<int> ans;
  for (int i = n; i > 0; --i) {
    if (la[i] == 0)
      continue;
    ans.push_back(i);
    vector<int> div = divisor(i);
    for (int d : div) {
      la[d] = 1 - la[d];
    }
  }
  cout << ans.size() << endl;
  for (int a : ans) {
    cout << a << " ";
  }
  cout << endl;
}
Problem p02972 (C++)

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

int a[200001] = {};
int b[200001] = {};

int main() {
  long N;
  cin >> N;
  for (long i = 1; i <= N; i++) {
    cin >> a[i];
  }
  long M = 0;
  if (a[N] == 1) {
    M++;
    b[N] = 1;
  }
  for (long i = N - 1; i >= 1; i--) {
    long c = 0;
    for (long j = i; j <= N; j++) {
      if (j % i == 0 && b[j] == 1)
        c++;
    }
    if (c % 2 != a[i]) {
      b[i] = 1;
      M++;
    }
  }
  cout << M << endl;
  if (M != 0) {
    for (long i = 1; i <= N; i++) {
      if (b[i] == 1)
        cout << i << " ";
    }
    cout << endl;
  }
  return 0;
}

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

int a[200001] = {};
int b[200001] = {};

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

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define INF 1e9
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n)                                                        \
  std::vector<type> c(n);                                                      \
  for (auto &i : c)                                                            \
    std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  auto a = vec(int, n);
  rep(i, n + 1) {
    if (i == 0)
      a[0] = 0;
    else
      cin >> a[i];
  }
  auto b = vec(int, n + 1);
  int i = n;
  int sum = 0;
  while (i) {
    if (n < 2 * i)
      b[i] = a[i];
    else if (n >= 2 * i && i > 1) {
      int memo = 0, j = 2;
      while (n >= i * j) {
        memo += b[i * j];
        j++;
      }
      b[i] = (memo + a[i]) % 2;
    } else
      b[1] = (a[1] + sum) % 2;
    sum += b[i];
    i--;
  }
  cout << sum << endl;
  REP(i, 1, n) if (b[i]) cout << i << " ";
}


Fixed submission:
#include <iostream>
#include <stdio.h>
// #include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cmath>
#include <cstring>
#include <float.h>
#include <iomanip>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define INF 1e9
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++)
#define VEC(type, c, n)                                                        \
  std::vector<type> c(n);                                                      \
  for (auto &i : c)                                                            \
    std::cin >> i;
#define vec(type, n) vector<type>(n)
#define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n))

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  auto a = vec(int, n + 1);
  REP(i, 1, n) cin >> a[i];
  auto b = vec(int, n + 1);
  int i = n;
  int sum = 0;
  while (i) {
    if (n < 2 * i)
      b[i] = a[i];
    else if (n >= 2 * i && i > 1) {
      int memo = 0, j = 2;
      while (n >= i * j) {
        memo += b[i * j];
        j++;
      }
      b[i] = (memo + a[i]) % 2;
    } else
      b[1] = (a[1] + sum) % 2;
    sum += b[i];
    i--;
  }
  cout << sum << endl;
  REP(i, 1, n) if (b[i]) cout << i << " ";
}
Problem p02972 (C++)

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

int main() {
  int n;
  cin >> n;
  vector<int> res(n + 1), a(n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    if (i >= n / 2) {
      res.at(i + 1) = a.at(i);
      if (res.at(i + 1) == 1)
        cnt++;
    }
  }
  for (int i = n / 2; i > 0; i--) {
    int cnt1 = 2;
    while (cnt1 * i <= n) {
      res.at(i) += res.at(i * cnt1);
      cnt1++;
      res.at(i) %= 2;
    }
    if ((a.at(i - 1) + res.at(i)) % 2 == 0)
      res.at(i) = 0;
    else {
      res.at(i) = 1;
      cnt++;
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= 10; i++) {
    if (res.at(i))
      cout << i << " ";
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> res(n + 1), a(n);
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    if (i >= n / 2) {
      res.at(i + 1) = a.at(i);
      if (res.at(i + 1) == 1)
        cnt++;
    }
  }
  for (int i = n / 2; i > 0; i--) {
    int cnt1 = 2;
    while (cnt1 * i <= n) {
      res.at(i) += res.at(i * cnt1);
      cnt1++;
      res.at(i) %= 2;
    }
    if ((a.at(i - 1) + res.at(i)) % 2 == 0)
      res.at(i) = 0;
    else {
      res.at(i) = 1;
      cnt++;
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= n; i++) {
    if (res.at(i))
      cout << i << " ";
  }
}
Problem p02972 (C++)

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

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++)  // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1)                  // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void) {
  ll N;
  cin >> N;
  vll a(N + 1), b(N + 1);
  a[0] = 0;
  b[0] = 0;
  bool f;
  FOR(i, 1, N) { cin >> a[i]; }
  // b[N/2+1] ~ b[N]は確定
  FOR(i, N / 2 + 1, N) { b[i] = a[i]; }
  rFOR(i, N / 2, 1) {
    f = 0;
    FOR(j, 2, N / i) { f ^= a[j * i]; }
    b[i] = !f;
  }
  ll balls = count(b.begin(), b.end(), 1);
  cout << balls << endl;
  if (balls > 0) {
    FOR(i, 1, N) {
      if (b[i] == 1) {
        cout << i << endl;
      }
    }
  }
}

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

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++)  // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1)                  // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void) {
  ll N;
  cin >> N;
  vll a(N + 1), b(N + 1);
  a[0] = 0;
  b[0] = 0;
  bool f;
  FOR(i, 1, N) { cin >> a[i]; }
  if (N > 2) {
    // b[N/2+1] ~ b[N]は確定
    FOR(i, N / 2 + 1, N) { b[i] = a[i]; }
    //        puts("a");
    rFOR(i, 1, N / 2) {
      f = 0;
      FOR(j, 2, N / i) { f ^= b[j * i]; }
      b[i] = f ^ a[i];
      //            cout << "b[" << i << "]=" << b[i] << endl;;
    }
  } else if (N == 1) {
    b[1] = a[1];
  } else { // N==2
    b[2] = a[2];
    b[1] = a[1] ^ a[2];
  }
  ll balls = count(b.begin(), b.end(), 1);
  cout << balls << endl;
  if (balls > 0) {
    FOR(i, 1, N) {
      if (b[i] == 1) {
        cout << i << endl;
      }
    }
  }
}
Problem p02972 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  vector<int> A(N, 0);
  // reverse(a.begin(),a.end());
  int tmp = 0;
  for (int i = 0; i < N; i++) {
    int j = N - i - 1;
    tmp = 0;
    for (int l = 1; l <= N % (j + 1); l++) {
      int L = l * (j + 1);
      tmp += A.at(L - 1);
    }
    tmp = tmp % 2;
    if (tmp != a.at(j)) {
      A.at(j) = 1;
    }
  }
  int ans = accumulate(A.begin(), A.end(), 0);
  cout << ans << endl;
  for (int i = 0; i < N; i++) {
    if (A.at(i) == 1) {
      if (ans != 1) {
        cout << i + 1 << " ";
      } else {
        cout << i + 1 << endl;
      }
      ans -= 1;
    }
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  vector<int> A(N, 0);
  // reverse(a.begin(),a.end());
  int tmp = 0;
  for (int i = 0; i < N; i++) {
    int j = N - i - 1;
    tmp = 0;
    for (int l = 1; l <= N / (j + 1); l++) {
      int L = l * (j + 1);
      tmp += A.at(L - 1);
    }
    tmp = tmp % 2;
    if (tmp != a.at(j)) {
      A.at(j) = 1;
    }
  }
  int ans = accumulate(A.begin(), A.end(), 0);
  cout << ans << endl;
  for (int i = 0; i < N; i++) {
    if (A.at(i) == 1) {
      if (ans != 1) {
        cout << i + 1 << " ";
      } else {
        cout << i + 1 << endl;
      }
      ans -= 1;
    }
  }
}