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

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

#define ll long long
#define ld long double
#define ii pair<int, int>
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);

const int N = 100100;

ll n, q, a[N], seg[N << 2];

ll mrg(ll x1, ll x2) { return max(x1, x2); }

void build(int idx, int from, int to) {
  if (from == to) {
    seg[idx] = a[from];
    return;
  }
  int mid = (from + to) >> 1;
  build(idx << 1, from, mid);
  build(idx << 1 | 1, mid + 1, to);
  seg[idx] = mrg(seg[idx << 1], seg[idx << 1 | 1]);
}

ll query(int idx, int from, int to, int l, int r) {
  if (from >= l && to <= r)
    return seg[idx];
  if (from > r || to < l)
    return 0LL;
  int mid = (from + to) >> 1;
  ll x1 = query(idx << 1, from, mid, l, r);
  ll x2 = query(idx << 1 | 1, mid + 1, to, l, r);
  return mrg(x1, x2);
}

int main() {
  SPEED
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  build(1, 1, n);
  cout << query(1, 1, n, 2, n) << endl;
  for (int i = 2; i < n; i++) {
    cout << max(query(1, 1, n, 1, i - 1), query(1, 1, n, i + 1, n)) << endl;
  }
  cout << query(1, 1, n, 1, n - 1);
}


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

#define ll long long
#define ld long double
#define ii pair<int, int>
#define S second
#define F first
#define PI 3.1415926535897932384626
#define SPEED std::ios_base::sync_with_stdio(false);

const int N = 200100;

ll n, q, a[N], seg[N << 2];

ll mrg(ll x1, ll x2) { return max(x1, x2); }

void build(int idx, int from, int to) {
  if (from == to) {
    seg[idx] = a[from];
    return;
  }
  int mid = (from + to) >> 1;
  build(idx << 1, from, mid);
  build(idx << 1 | 1, mid + 1, to);
  seg[idx] = mrg(seg[idx << 1], seg[idx << 1 | 1]);
}

ll query(int idx, int from, int to, int l, int r) {
  if (from >= l && to <= r)
    return seg[idx];
  if (from > r || to < l)
    return 0LL;
  int mid = (from + to) >> 1;
  ll x1 = query(idx << 1, from, mid, l, r);
  ll x2 = query(idx << 1 | 1, mid + 1, to, l, r);
  return mrg(x1, x2);
}

int main() {
  SPEED
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  build(1, 1, n);
  cout << query(1, 1, n, 2, n) << endl;
  for (int i = 2; i < n; i++) {
    cout << max(query(1, 1, n, 1, i - 1), query(1, 1, n, i + 1, n)) << endl;
  }
  cout << query(1, 1, n, 1, n - 1);
}
Problem p02971 (C++)

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

int main() {
  vector<int> v, v2;
  int counter, tmp, max, second, result;

  cin >> counter;

  for (int i = 0; i < counter; i++) {
    cin >> tmp;
    v.emplace_back(tmp);
  }
  max = *max_element(v.begin(), v.end());
  v2 = v;
  sort(v2.begin(), v2.end(), greater<int>());
  second = v2[1];
  for (int i = 0; i < counter; i++) {
    if (v[i] == max) {
      cout << second << endl;
      continue;
    }
    cout << *max_element(v.begin(), v.end()) << endl;
  }

  return 0;
}

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

int main() {
  vector<int> v, v2;
  int counter, tmp, max, second, result;

  cin >> counter;

  for (int i = 0; i < counter; i++) {
    cin >> tmp;
    v.emplace_back(tmp);
  }
  max = *max_element(v.begin(), v.end());
  v2 = v;
  sort(v2.begin(), v2.end(), greater<int>());
  second = v2[1];
  for (int i = 0; i < counter; i++) {
    if (v[i] == max) {
      cout << second << endl;
      continue;
    }
    cout << max << endl;
  }

  return 0;
}
Problem p02971 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int maxM = 2e5 + 7;
const int maxV = 90010;

const int MOD = 1e9 + 7;

int T;
const int maxN = 1e2 + 8;
const ll INF = 1000000000000000010LL;
const int K = 15;
int n;
int a[maxN];
int b[maxN];
int c[maxN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  b[1] = a[1];
  for (int i = 2; i <= n; i++) {
    b[i] = max(b[i - 1], a[i]);
  }
  c[n] = a[n];
  for (int i = n - 1; i >= 1; i--) {
    c[i] = max(c[i + 1], a[i]);
  }
  for (int i = 1; i <= n; i++) {
    int L = 0, R = 0;
    if (i - 1 >= 1)
      L = b[i - 1];
    if (R + 1 <= n)
      R = c[i + 1];
    int ans = max(L, R);
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int maxM = 2e5 + 7;
const int maxV = 90010;

const int MOD = 1e9 + 7;

int T;
const int maxN = 2e5 + 8;
const ll INF = 1000000000000000010LL;
const int K = 15;
int n;
int a[maxN];
int b[maxN];
int c[maxN];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  b[1] = a[1];
  for (int i = 2; i <= n; i++) {
    b[i] = max(b[i - 1], a[i]);
  }
  c[n] = a[n];
  for (int i = n - 1; i >= 1; i--) {
    c[i] = max(c[i + 1], a[i]);
  }
  for (int i = 1; i <= n; i++) {
    int L = 0, R = 0;
    if (i - 1 >= 1)
      L = b[i - 1];
    if (R + 1 <= n)
      R = c[i + 1];
    int ans = max(L, R);
    cout << ans << endl;
  }
  return 0;
}
Problem p02971 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from copy import copy


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    for i in range(N):
        tmp = copy(A)
        tmp[i] = 0
        print(max(tmp))


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from copy import copy


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A_max = copy(A)
    A_max.sort(reverse=True)

    for a in A:
        if a == A_max[0]:
            print(A_max[1])
        else:
            print(A_max[0])


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

Buggy submission (status: Runtime Error):
n = int(input())
a = [int(input()) for _ in range(n)]
m1, m2 = sorted(set(a))[n - 2 :]
if a.count(m1) > 1:
    for _ in range(n):
        print(m1)
else:
    for x in a:
        print(m1) if x == m2 else print(m2)


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
b = sorted(a)
for x in a:
    print(b[(x < b[-1]) - 2])
Problem p02971 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

for i in range(n):
    _a = a.copy()
    _a.pop(i)
    print(max(_a))


Fixed submission:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

m = max(a)
idxs = [i for i, v in enumerate(a) if v == m]

if len(idxs) > 1:
    for i in range(n):
        print(m)

if len(idxs) == 1:
    idx = idxs[0]
    for i in range(n):
        if idx == i:
            _a = a.copy()
            _a.pop(i)
            print(max(_a))
        else:
            print(m)
Problem p02971 (Python)

Buggy submission (status: Runtime Error):
import itertools

n = int(input())
a = [int(input()) for i in range(n)]

max_list = [0] + list(itertools.accumulate(a, func=max))
max_list_r = [0, *itertools.accumulate(reversed(a), func=max)][::-1]
# print(max_list)
# print(max_list_r)
for i in range(n):
    print(max(max_list[i], max_list_r[i + 1]))


Fixed submission:
import itertools

n = int(input())
a = [int(input()) for i in range(n)]

max_list = [0] + list(itertools.accumulate(a, func=max))
max_list_r = ([0] + list(itertools.accumulate(reversed(a), func=max)))[::-1]
for i in range(n):
    print(max(max_list[i], max_list_r[i + 1]))
Problem p02971 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  REP(i, N) {
    cin >> A[i];
    B[i] = A[i];
  }
  sort(A.begin(), A.end());
  REP(i, N) {
    sort(A.begin(), A.end());
    if (A[N - 1] == B[i]) {
      cout << A[N - 2] << endl;
    } else {
      cout << A[N - 1] << endl;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  REP(i, N) {
    cin >> A[i];
    B[i] = A[i];
  }
  sort(A.begin(), A.end());
  REP(i, N) {
    if (A[N - 1] == B[i]) {
      cout << A[N - 2] << endl;
    } else {
      cout << A[N - 1] << endl;
    }
  }
}
Problem p02971 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <algorithm>
#include <climits>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int i, ans = 0, n, j, x, max;
  int kari = 0;
  vector<int> a;

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  max = *max_element(a.begin(), a.end());
  for (i = 0; i < n; i++) {
    if (a[i] == max) {
      for (j = 0; j < n; j++) {
        if (i != j and kari < a[j]) {
          kari = a[j];
        }
      }
      cout << kari << "\n";
      kari = 0;
    } else
      cout << max << "\n";
  }
}


Fixed submission:

#include <algorithm>
#include <climits>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int i, ans = 0, n, j, x, max;
  int kari = 0;
  vector<int> a;

  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  max = *max_element(a.begin(), a.end());
  for (i = 0; i < n; i++) {
    if (a[i] == max) {
      for (j = 0; j < n; j++) {
        if (i != j and kari < a[j]) {
          kari = a[j];
          if (kari == max)
            break;
        }
      }
      cout << kari << "\n";
      kari = 0;
    } else
      cout << max << "\n";
  }
}
Problem p02971 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P, ll> P3;
typedef pair<P, P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
  int n, a[MAX_N], f, s;
  cin >> n;
  REP(i, n) {
    cin >> a[i];
    if (f < a[i]) {
      s = f;
      f = a[i];
    } else if (s < a[i]) {
      s = a[i];
    }
  }
  REP(i, n) {
    if (a[i] < f) {
      cout << f << endl;
    } else {
      cout << s << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P, ll> P3;
typedef pair<P, P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(2e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
  int n, a[MAX_N], f, s;
  cin >> n;
  REP(i, n) {
    cin >> a[i];
    if (f < a[i]) {
      s = f;
      f = a[i];
    } else if (s < a[i]) {
      s = a[i];
    }
  }
  REP(i, n) {
    if (a[i] < f) {
      cout << f << endl;
    } else {
      cout << s << endl;
    }
  }
  return 0;
}
Problem p02971 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> iP;
typedef pair<P, P> PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

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

  int n;
  cin >> n;
  int tmp[SIZE], a[SIZE];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    tmp[i] = a[i];
  }
  sort(tmp, tmp + n, greater<>());
  int tmx = tmp[1];
  int mx = tmp[0];
  for (int i = 0; i < n; ++i) {
    if (a[i] == mx)
      cout << tmx;
    else
      cout << mx;
    cout << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> iP;
typedef pair<P, P> PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

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

  int n;
  cin >> n;
  int tmp[SIZE], a[SIZE];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    tmp[i] = a[i];
  }
  sort(tmp, tmp + n, greater<>());
  int tmx = tmp[1];
  int mx = tmp[0];
  for (int i = 0; i < n; ++i) {
    if (a[i] == mx)
      cout << tmx;
    else
      cout << mx;
    cout << endl;
  }
  return 0;
}
Problem p02971 (Python)

Buggy submission (status: Time Limit Exceeded):
# -*- coding: utf-8 -*-

n = int(input())

a = list()
for i in range(n):
    a.append(int(input()))

a_sorted = sorted(a, reverse=True)

for i in range(n):
    index = a_sorted.index(a[i])
    if a[i] == a_sorted[0]:
        print(a_sorted[1])
        continue

    print(a_sorted[0])


Fixed submission:
# -*- coding: utf-8 -*-

n = int(input())

a = list()
for i in range(n):
    a.append(int(input()))

a_sorted = sorted(a, reverse=True)

for i in range(n):
    if a[i] == a_sorted[0]:
        print(a_sorted[1])
        continue

    print(a_sorted[0])
Problem p02971 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
k = max(a)
for i in range(n):
    if a[i] < k:
        print(k)
    else:
        tmp = a[i]
        a[i] = 0
        print(max(a))
        a[i] = tmp


Fixed submission:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
bl = [0 for i in range(n)]
bl[0] = a[0]
br = [0 for i in range(n)]
br[0] = a[n - 1]
for i in range(1, n):
    bl[i] = max(bl[i - 1], a[i])
a.reverse()
for i in range(1, n):
    br[i] = max(br[i - 1], a[i])
br.reverse()
print(br[1])
for i in range(1, n - 1):
    print(max(bl[i - 1], br[i + 1]))
print(bl[n - 2])
Problem p02971 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

sa = sorted(a)
for i in range(n):
    val = a[i]
    idx = sa.index(val)
    sa.pop(idx)
    print(sa[-1])
    sa.insert(idx, val)


Fixed submission:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

sa = sorted(a)
mx = sa[-1]
for val in a:
    if val != mx:
        print(sa[-1])
    else:
        print(sa[-2])
Problem p02971 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]

for j in range(N):
    p = A.pop(j)
    print(max(A))
    A.insert(j, p)


Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]

max1 = [A.index(max(A)), max(A)]
p = A.pop(A.index(max(A)))
max2 = max(A)
ans = [max2 if j == max1[0] else max1[1] for j in range(N)]
for k in range(N):
    print(ans[k])
Problem p02971 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]
# maxA = max(A)
for x in range(len(A)):
    a_tmp = A[x]
    A[x] = 0
    print(max(A))
    A[x] = a_tmp


Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
maxA = max(A)
copy_A = A[:]
copy_A.remove(maxA)
secondA = max(copy_A)
for x in A:
    if x == maxA:
        print(secondA)
    else:
        print(maxA)
Problem p02971 (Python)

Buggy submission (status: Time Limit Exceeded):
import copy

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

chinpo = max(A)
B = copy.copy(A)
B.remove(max(A))
chinchin = max(B)

for i in range(N):
    if i == A.index(max(A)):
        print(chinchin)
    else:
        print(chinpo)


Fixed submission:
import copy

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

chinpo = max(A)
B = copy.copy(A)
B.remove(max(A))
chinchin = max(B)

for i in range(A.index(max(A))):
    print(chinpo)
print(chinchin)
for i in range(A.index(max(A)) + 1, N):
    print(chinpo)
Problem p02971 (Python)

Buggy submission (status: Time Limit Exceeded):
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

for _ in range(n):
    val = a.pop(0)
    print(max(a))
    a.append(val)


Fixed submission:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

desc = sorted(list(set(a)), reverse=True)
max = desc[0]
large_2 = desc[1] if len(desc) > 1 else 0

if a.count(max) == 1:
    for val in a:
        if val == max:
            print(large_2)
        else:
            print(max)
else:
    for _ in range(n):
        print(max)
Problem p02971 (Python)

Buggy submission (status: Runtime Error):
from heapq import heappush, heappop

N = int(input())
A = [int(input()) for i in range(N)]
hq = []
for i in range(N):
    heappush(hq, -A[i])
max1 = -heappop(hq)
while True:
    max2 = -heappop(hq)
    if max2 != max1:
        break
ans = [0] * N
for i in range(N):
    if A[i] == max1:
        ans[i] = max2
    else:
        ans[i] = max1
print(*ans, sep="\n")


Fixed submission:
from heapq import heappush, heappop

N = int(input())
A = [int(input()) for i in range(N)]
hq = []
for i in range(N):
    heappush(hq, -A[i])
max1 = -heappop(hq)
max2 = -heappop(hq)
ans = [0] * N
for i in range(N):
    if A[i] == max1:
        ans[i] = max2
    else:
        ans[i] = max1
print(*ans, sep="\n")
Problem p02971 (Python)

Buggy submission (status: Time Limit Exceeded):
#!/usr/bin/env python3


def main():
    N = int(input())
    As = [int(input()) for _ in range(N)]
    for i in range(N):
        tmp = As[:]
        tmp.pop(i)
        print(max(tmp))


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3


def main():
    N = int(input())
    As = [int(input()) for _ in range(N)]
    max1 = max(As)
    max_idx = As.index(max1)
    As.remove(max1)
    max2 = max(As)
    max_list = [max1] * N
    max_list[max_idx] = max2
    for m in max_list:
        print(m)


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

Buggy submission (status: Time Limit Exceeded):
N = int(input())
a = []
for _ in range(N):
    a.append(int(input()))
tmp = 0
idx = 0
while idx < N:
    tmp, a[idx] = a[idx], tmp
    print(max(a))
    tmp, a[idx] = a[idx], tmp
    idx += 1


Fixed submission:
N = int(input())
a = []
for _ in range(N):
    a.append(int(input()))
a_sorted = sorted(a)
max_a = a_sorted.pop()
second_a = a_sorted.pop()
if max_a == second_a:
    for _ in range(N):
        print(max_a)
else:
    idx = 0
    while idx < N:
        if a[idx] == max_a:
            print(second_a)
        else:
            print(max_a)
        idx += 1
Problem p02971 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
    temp = A[:i] + A[i + 1 :]
    print(max(temp))


Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]
sorted_A = sorted(A)
[print(sorted_A[-2] if sorted_A[-1] == A[i] else sorted_A[-1]) for i in range(N)]
Problem p02971 (Python)

Buggy submission (status: Runtime Error):
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    max_value = max(A)
    max_index = A.index(max_value)

    for i in range(N):
        if i != max_index:
            print(max_value)
        else:
            if i == 0:
                print(max(A[1:]))
            elif i == N:
                print(max(A[:N]))
            else:
                print(max(max(A[:i]), max(A[i + 1 :])))

    return


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    max_value = max(A)
    max_index = A.index(max_value)

    for i in range(N):
        if i != max_index:
            print(max_value)
        else:
            if i == 0:
                print(max(A[1:]))
            elif i == N - 1:
                print(max(A[: N - 1]))
            else:
                print(max(max(A[:i]), max(A[i + 1 :])))

    return


if __name__ == "__main__":
    main()
Problem p02972 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <iostream>

using namespace std;
long long head[200001];
long long save[200001][1000];
int main() {
  long long N;
  long long a[200001];
  long long b[200001];
  long long size = 0;
  cin >> N;
  for (int i = 1; i <= N; i++)
    cin >> a[i];

  for (int i = 1; i <= N; i++) {
    for (int j = 2; i * j <= N; j++) {
      save[i * j][head[i * j]] = i;
      head[i * j]++;
    }
  }
  for (int i = N; i >= 1; i--) {
    b[i] = a[i];
    if (b[i] == 1)
      size++;
    for (int jh = 0; jh < head[i]; jh++) {
      a[save[i][jh]] ^= b[i];
    }
  }
  cout << size << endl;
  for (int i = 1; i <= N; i++) {
    if (b[i] == 1) {
      cout << i;
      size--;
      if (size > 0)
        cout << " ";
      else
        cout << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;
int head[200001];
int save[200001][200];
int main() {
  long long N;
  long long a[200001];
  long long b[200001];
  long long size = 0;
  cin >> N;
  for (int i = 1; i <= N; i++)
    cin >> a[i];

  for (int i = 1; i <= N; i++) {
    for (int j = 2; i * j <= N; j++) {
      save[i * j][head[i * j]] = i;
      head[i * j]++;
    }
  }
  for (int i = N; i >= 1; i--) {
    b[i] = a[i];
    if (b[i] == 1)
      size++;
    for (int jh = 0; jh < head[i]; jh++) {
      a[save[i][jh]] ^= b[i];
    }
  }
  cout << size << endl;
  for (int i = 1; i <= N; i++) {
    if (b[i] == 1) {
      cout << i;
      size--;
      if (size > 0)
        cout << " ";
      else
        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 rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<set<ll>>;

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  rep1(i, N) cin >> A.at(i);
  int M = 0;
  vector<int> B(N + 1, 0);
  for (int i = N; i >= 1; i--) {
    int tmp = 0;
    for (int j = 2 * i; i * j <= N; j++) {
      tmp += B.at(j);
    }
    if (tmp % 2 != A.at(i)) {
      B.at(i)++;
      M++;
    }
  }
  cout << M << endl;
  rep1(i, N) if (B.at(i)) cout << i << " ";
  cout << endl;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<set<ll>>;

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  rep1(i, N) cin >> A.at(i);
  int M = 0;
  vector<int> B(N + 1, 0);
  for (int i = N; i >= 1; i--) {
    int tmp = 0;
    for (int j = 2; i * j <= N; j++) {
      tmp += B.at(j * i);
    }
    if (tmp % 2 != A.at(i)) {
      B.at(i)++;
      M++;
    }
  }
  cout << M << endl;
  rep1(i, N) if (B.at(i)) cout << i << " ";
  cout << endl;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
#define ll long long
int main() {
  ll N, M = 0;
  ll i, j;
  ll tmp;
  cin >> N;
  ll a[N + 1], b[N + 1];
  for (i = 1; i <= N; i++) {
    cin >> a[i];
    b[i] = 0;
  }
  for (i = N; i > 0; i--) {
    tmp = 0;
    j = i;
    while (tmp <= N) {
      tmp = (tmp + b[j]) % 2;
      j += i;
    }
    b[i] = (tmp + a[i]) % 2;
    if (b[i] == 1)
      M++;
  }
  cout << M << endl;
  for (i = 1; i <= N; i++) {
    if (b[i] == 1)
      cout << i << " ";
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
#define ll long long
int main() {
  ll N, M = 0;
  ll i, j;
  ll tmp;
  cin >> N;
  ll a[N + 1], b[N + 1];
  for (i = 1; i <= N; i++) {
    cin >> a[i];
    b[i] = 0;
  }
  for (i = N; i > 0; i--) {
    tmp = 0;
    j = i;
    while (j <= N) {
      tmp = (tmp + b[j]) % 2;
      j += i;
    }
    b[i] = (tmp + a[i]) % 2;
    if (b[i] == 1)
      M++;
  }
  cout << M << endl;
  for (i = 1; i <= N; i++) {
    if (b[i] == 1)
      cout << i << " ";
  }
  return 0;
}
Problem p02972 (C++)

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

// DAME:
int main() {
  ll n;
  cin >> n;
  vector<int> a(n + 1);
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> ans(n + 1);

  for (ll i = n; i >= 1; i--) {
    ll tmp = i;
    int sum = 0;
    while (tmp <= n) {
      tmp += i;
      sum += ans[tmp];
    }
    if (sum % 2 != a[i]) {
      ans[i] = 1;
    }
  }
  int size = 0;
  for (ll i = 1; i <= n; i++) {
    if (ans[i]) {
      size++;
    }
  }
  cout << size << endl;
  for (ll i = 1; i <= n; i++) {
    if (ans[i]) {
      cout << i << ' ';
    }
  }

  return 0;
}

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

// DAME:
int main() {
  ll n;
  cin >> n;
  vector<int> a(n + 1);
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }
  vector<int> ans(n + 1);

  for (ll i = n; i >= 1; i--) {
    ll tmp = i;
    int sum = 0;
    while (tmp + i <= n) {
      tmp += i;
      sum += ans[tmp];
    }
    if (sum % 2 != a[i]) {
      ans[i] = 1;
    }
  }
  int size = 0;
  for (ll i = 1; i <= n; i++) {
    if (ans[i]) {
      size++;
    }
  }
  cout << size << endl;
  for (ll i = 1; i <= n; i++) {
    if (ans[i]) {
      cout << i << ' ';
    }
  }

  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)

int main() {
  int N;
  cin >> N;
  vector<int> a(N + 1);
  rep(i, 1, N + 1) cin >> a[i];
  vector<int> ans(N + 1);
  rem(i, N, 0) if (a[i]) {
    ans[i] = 1;
    rep(j, 1, i) if (i % j == 0) a[j] ^= 1;
  }
  int cnt = 0;
  rep(i, 1, N + 1) if (ans[i]) cnt++;
  cout << cnt << endl;
  rep(i, 1, N + 1) if (ans[i]) cout << i << " ";
  if (cnt)
    cout << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N + 1);
  rep(i, 1, N + 1) cin >> a[i];
  vector<int> ans(N + 1);
  rem(i, N, 0) {
    ans[i] = a[i];
    for (int j = 2 * i; j <= N; j += i) {
      ans[i] ^= ans[j];
    }
  }
  int cnt = 0;
  rep(i, 1, N + 1) if (ans[i]) cnt++;
  cout << cnt << endl;
  rep(i, 1, N + 1) if (ans[i]) cout << i << " ";
  if (cnt)
    cout << endl;
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 1; i <= n; i++)
    cin >> v[i];

  vector<int> ans(n + 1);

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

  int cnt = 0;
  for (int i = 1; i <= n; i++)
    cnt += ans[i];

  cout << cnt << endl;
  for (int i = 1; i <= n; i++) {
    if (ans[i] == 1)
      cout << i << " ";
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v(n + 1);
  for (int i = 1; i <= n; i++)
    cin >> v[i];

  vector<int> ans(n + 1);

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

  int cnt = 0;
  for (int i = 1; i <= n; i++)
    cnt += ans[i];

  cout << cnt << endl;
  for (int i = 1; i <= n; i++) {
    if (ans[i] == 1)
      cout << i << " ";
  }
  cout << endl;
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MAT_DEFINES
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

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

  int cnt = 0;
  vector<int> ans;
  for (int i = N; i >= 1; i--) {
    // ballの個数を数える
    int ball = 0;
    int now = 2 * i;
    while (now <= N) {
      ball += b[now];
      now += i;
    }
    // 偶奇が違ったら追加
    if (ball % 2 != a[i]) {
      b[i] = 1;
      cnt++;
      ans.push_back(i);
    }
  }

  cout << cnt << endl;
  for (int i = 0; i < b.size(); i++)
    cout << ans[i] << " ";
}


Fixed submission:
#define _USE_MAT_DEFINES
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

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

  int cnt = 0;
  vector<int> ans;
  for (int i = N; i >= 1; i--) {
    // ballの個数を数える
    int ball = 0;
    int now = 2 * i;
    while (now <= N) {
      ball += b[now];
      now += i;
    }
    // 偶奇が違ったら追加
    if (ball % 2 != a[i]) {
      b[i] = 1;
      cnt++;
      ans.push_back(i);
    }
  }

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

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

int main() {
  int n;
  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 = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
}

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

int main() {
  int n;
  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;
  rep(i, ans.size()) cout << ans[i] << endl;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int a[N + 1];
  int b[N + 1];
  int ans[N + 1];
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }
  for (int i = N; i >= 1; i--) {
    int cnt = 0;
    for (int j = i + 1; j <= N; j++) {
      if (j % i == 0) {
        if (b[j] == 1)
          cnt++;
      }
    }
    if (a[i] == 1) {
      if (cnt % 2 == 0) {
        b[i] = 1;
      } else {
        b[i] = 0;
      }
    } else {
      if (cnt % 2 == 1) {
        b[i] = 1;
      } else {
        b[i] = 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 << ' ';
    }
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int a[N + 1];
  int b[N + 1];
  int ans[N + 1];
  for (int i = 1; i <= N; i++) {
    cin >> a[i];
  }
  for (int i = N; i >= 1; i--) {
    int cnt = 0;
    for (int j = i + i; j <= N; j += i) {
      if (j % i == 0) {
        if (b[j] == 1)
          cnt++;
      }
    }
    if (a[i] == 1) {
      if (cnt % 2 == 0) {
        b[i] = 1;
      } else {
        b[i] = 0;
      }
    } else {
      if (cnt % 2 == 1) {
        b[i] = 1;
      } else {
        b[i] = 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 << ' ';
    }
  }
  cout << endl;
  return 0;
}
Problem p02972 (C++)

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

int main() {
  int n;
  scanf("%d", &n);

  vector<int> a(n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);

  vector<int> out;
  for (int i = n; i > 0; --i) {
    for (int j = 2 * i; j <= n; j += i)
      a[i] ^= a[j];
    if (a[i])
      out.push_back(i);
  }

  printf("%d\n", (int)out.size());
  reverse(out.begin(), out.end());
  for (int i : out)
    printf("%d ", i);
}


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

int main() {
  int n;
  scanf("%d", &n);

  vector<int> a(n + 1);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);

  vector<int> out;
  for (int i = n; i > 0; --i) {
    for (int j = 2 * i; j <= n; j += i)
      a[i] ^= a[j];
    if (a[i])
      out.push_back(i);
  }

  printf("%d\n", (int)out.size());
  reverse(out.begin(), out.end());
  for (int i : out)
    printf("%d ", i);
}
Problem p02972 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int a[20005];
int b[20005];

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

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

  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (b[i] == 1)
      cnt++;
  }

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

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int a[200005];
int b[200005];

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

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

  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (b[i] == 1)
      cnt++;
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int arr[N], n, val[N];
vector<int> v;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> arr[i];
  for (int i = n; i >= 1; i--) {
    int sum = 0;
    for (int j = i; j <= n; j += i)
      sum += val[j];
    if (sum % 2 != arr[i]) {
      v.push_back(i);
      val[i]++;
    }
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++)
    cout << v[i] << " ";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int arr[N], n, val[N];
vector<int> v;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> arr[i];
  for (int i = n; i >= 1; i--) {
    int sum = 0;
    for (int j = i; j <= n; j += i)
      sum += val[j];
    if (sum % 2 != arr[i]) {
      v.push_back(i);
      val[i]++;
    }
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++)
    cout << v[i] << " ";
  return 0;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, n) for (int i = a; i < n; i++)

typedef long long ll;

void Main() {
  int n;
  cin >> n;
  int a[200010];
  rep(i, n) cin >> a[i + 1];
  int res[200010];
  int cnt = 0;
  for (int i = n; i > 0; --i) {
    int other = 0;
    for (int j = i + 1; j <= n; ++j) {
      if (j % i == 0 && res[j] == 1) {
        ++other;
      }
    }
    if (a[i] == 0) {
      if (other % 2 == 0) {
        res[i] = 0;
      } else {
        res[i] = 1;
        ++cnt;
      }
    } else {
      if (other % 2 == 0) {
        res[i] = 1;
        ++cnt;
      } else {
        res[i] = 0;
      }
    }
  }
  cout << cnt << endl;
  rep(i, n) {
    if (res[i + 1] == 1) {
      cout << (i + 1);
      if (i == n - 1) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
  }
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  Main();
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, n) for (int i = a; i < n; i++)

typedef long long ll;

void Main() {
  int n;
  cin >> n;
  int a[200010];
  rep(i, n) cin >> a[i + 1];
  int res[200010];
  int cnt = 0;
  for (int i = n; i > 0; --i) {
    int other = 0;
    for (int j = 2; true; ++j) {
      if (j * i > n) {
        break;
      }
      if (res[j * i] == 1) {
        ++other;
      }
    }
    if (a[i] == 0) {
      if (other % 2 == 0) {
        res[i] = 0;
      } else {
        res[i] = 1;
        ++cnt;
      }
    } else {
      if (other % 2 == 0) {
        res[i] = 1;
        ++cnt;
      } else {
        res[i] = 0;
      }
    }
  }
  cout << cnt << endl;
  rep(i, n) {
    if (res[i + 1] == 1) {
      cout << (i + 1);
      if (i == n - 1) {
        cout << endl;
      } else {
        cout << " ";
      }
    }
  }
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  Main();
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <math.h>    // sqrt
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
  int N;
  cin >> N;
  vi data(N);
  for (int i = 0; i < N; i++) {
    cin >> data[i];
  }
  vi ans(N, 0);
  int ansa = 0;
  for (int i = N - 1; i >= 0; i--) {
    int count = 0;
    for (int j = N - 1; j >= i; j--) {
      if ((j + 1) % (i + 1) == 0) {
        count += ans[j];
      }
    }
    count %= 2;
    if (count != data[i]) {
      ans[i]++;
      ansa++;
    }
  }
  cout << ansa << endl;
  for (int i = 0; i < N; i++) {
    if (ans[i] == 1) {
      cout << i + 1 << " ";
    }
  }
  cout << endl;
}


Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <math.h>    // sqrt
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
  int N;
  cin >> N;
  vi data(N);
  for (int i = 0; i < N; i++) {
    cin >> data[i];
  }
  vi ans(N, 0);
  int ansa = 0;
  for (int i = N - 1; i >= 0; i--) {
    int count = 0;
    int max = floor(N / (i + 1)) * (i + 1) - 1;
    for (int j = max; j >= i; j -= i + 1) {
      count += ans[j];
    }
    count %= 2;
    if (count != data[i]) {
      ans[i]++;
      ansa++;
    }
  }
  cout << ansa << endl;
  for (int i = 0; i < N; i++) {
    if (ans[i] == 1) {
      cout << i + 1 << " ";
    }
  }
  cout << endl;
}
Problem p02972 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(c) c.begin(), c.end()
#define print(x) cerr << (#x) << "is " << x << "\n"
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7, N = 2e5 + 10;

ll sum[N], a[N];
vector<ll> factor[N];

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  f(i, 1, n + 1) { cin >> a[i]; }
  vector<int> res;
  f(i, 1, n + 1) {
    for (int j = i; j <= n; j++) {
      factor[j].pb(i);
    }
  }
  // f(i,1,n+1){
  // 	for(auto &el : factor[i]){
  // 		cout << el << " ";
  // 	}
  // 	cout << "\n";
  // }
  for (int i = n; i >= 1; i--) {
    if (sum[i] % 2 != a[i] % 2) {
      res.pb(i);
      for (auto &el : factor[i]) {
        sum[el]++;
      }
    }
  }
  f(i, 1, n + 1) {
    if (sum[i] % 2 != a[i] % 2) {
      cout << "-1\n";
      return 0;
    }
  }
  sort(all(res));
  cout << (int)res.size() << '\n';
  for (auto &el : res) {
    cout << el << ' ';
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(c) c.begin(), c.end()
#define print(x) cerr << (#x) << "is " << x << "\n"
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7, N = 2e5 + 10;

ll sum[N], a[N];
vector<ll> factor[N];

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  f(i, 1, n + 1) { cin >> a[i]; }
  vector<int> res;
  f(i, 1, n + 1) {
    for (int j = i; j <= n; j += i) {
      factor[j].pb(i);
    }
  }
  // f(i,1,n+1){
  // 	for(auto &el : factor[i]){
  // 		cout << el << " ";
  // 	}
  // 	cout << "\n";
  // }
  for (int i = n; i >= 1; i--) {
    if (sum[i] % 2 != a[i] % 2) {
      res.pb(i);
      for (auto &el : factor[i]) {
        sum[el]++;
      }
    }
  }
  f(i, 1, n + 1) {
    if (sum[i] % 2 != a[i] % 2) {
      cout << "-1\n";
      return 0;
    }
  }
  sort(all(res));
  cout << (int)res.size() << '\n';
  for (auto &el : res) {
    cout << el << ' ';
  }
  return 0;
}