Problem:


Score : 400 points

Problem Statement

There are N empty boxes arranged in a row from left to right.
The integer i is written on the i-th box from the left (1 \leq i \leq N).

For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.

We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:

For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2.

Does there exist a good set of choices? If the answer is yes, find one good set of choices.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

a_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If a good set of choices does not exist, print -1.

If a good set of choices exists, print one such set of choices in the following format:

M
b_1 b_2 ... b_M

where M denotes the number of boxes that will contain a ball, and b_1,\ b_2,\ ...,\ b_M are the integers written on these boxes, in any order.

Sample Input 1

3
1 0 0

Sample Output 1

1
1

Consider putting a ball only in the box with 1 written on it.

There are three boxes with multiples of 1 written on them: the boxes with 1, 2, and 3. The total number of balls contained in these boxes is 1.

There is only one box with a multiple of 2 written on it: the box with 2. The total number of balls contained in these boxes is 0.

There is only one box with a multiple of 3 written on it: the box with 3. The total number of balls contained in these boxes is 0.

Thus, the condition is satisfied, so this set of choices is good.

Sample Input 2

5
0 0 0 0 0

Sample Output 2

0

Putting nothing in the boxes can be a good set of choices.



Sample input:
3
1 0 0


Sample output:
1
1

Submission status: Runtime Error

Solution code:
import numpy as np
import math

N = int(input())
A = input().split(' ')

an = np.array(A, dtype=np.int64)

M = 0
b = []

for i in range(1,N):
   chk_num = int(N/(i))

   if(chk_num<2):
      continue

   ball = 0
   for j in range(1,chk_num):
      c = i * j
      ball += A[j]
   M += 1
   b.append(ball%2)


print(M)
print(b)

Submission status: Runtime Error

Solution code:
# ABC134-D

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  a=1
  ind=0
  ad=l[0]
  while True:
    if ind+a<n:
      ind+=a
      ad+=l[ind]
    else:
      if ad%2!=l[a-1]:
        # print(ad,l[a-1])
        print(-1)
        exit()
      else:
        a+=1
        ad=0
        ind=a-1
        if a==n:
          break

  ans=[]
  for i,x in enumerate(l):
    if x==1:
      ans.append(i+1)

  print(len(ans))
  if len(ans)==0:
    exit()
  print(' '.join([str(x) for x in ans]))

main()
# print(main())

Submission status: Runtime Error

Solution code:
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    int N;
    cin >> N;
    vint A(N + 1);
    vector<bool> ans(N + 1, false);
    vector<int> divi(N + 1, 0);
    rep(i, N) cin >> A[i + 1];
    int M = 0;
    for (int i = N; i > 0; i--) {

        if (A[i] == 0) {
            if((divi[i]%2) == 0)
                ans[i] = false;
            else {
                ans[i] = true;
                M++;
                for (int j = 1; j * j <= i; j++) {
                    if (i % j == 0) {
                        divi[j] += A[i];
                        if (j * j != i)
                            divi[i / j] += A[i];
                    }
                }
            }
        }
        else {
            if ((divi[i] % 2) == 0) {
                ans[i] = true;
                M++;
                for (int j = 1; j * j <= i; j++) {
                    if (i % j == 0) {
                        divi[j] += A[i];
                        if(j * j != i)
                            divi[i / j] += A[i];
                    }
                }
            }
            else {
                ans[i] = false;
            }
        }
    }
    
    cout << M << endl;
    if (M == 0) return 0;
    REP(i,1, N + 1) {
        if (ans[i] == true)
            cout << i << " " ;
    }
    cout << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
import math

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError("n is int-type.")
    if n < 2:
        raise ValueError("n is more than 2")
    data = [i for i in range(2, n + 1)]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return [1] + data

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())
A = [int(zz) for zz in input().split()]

p = get_sieve_of_eratosthenes(N)
ans = 0
for i in range(N):
    p = make_divisors(i+1)
    for j in p:
        if j != i+1:
            A[j-1] = A[j-1]^A[i]
z = sum(A)
print(z)
if z != 0:
    for i in range(z):
        print(1,end='')

Submission status: Runtime Error

Solution code:
N,*A=list(map(int, open(0).read().split()))

ni=-1
for n in range(1, N+1):
    if A[n-1] == sum(A[n-1::n]):
        ni = n
        break

if ni = -1:
    print("-1")
    exit(0)

am=len(list(filter(lambda x: x==1, A[ni-1::ni])))
print(am)
if am > 0:
    print(" ".join(map(str, list(range(1,am+1)))))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**5)

N = int(input())
a = [0]+[int(i) for i in input().split()]
ret = [0] * (N+1)

def rec(i) :
    if i == N + 1 :
        return
    rec(i+1)
    s = 0
    for j in range(i, N + 1, i) :
        s += ret[j]
    ret[i] = (s%2)^a[i]
    
rec(1)
b = []
for i in range(1, N + 1) :
    if ret[i] :
        b.append(str(i))
print(len(b))
print(' '.join(b))

Submission status: Runtime Error

Solution code:
import math
def add(n):
    return n + 1

def lcm(a):
    ans = a[0]
    for i in range(1, len(a)):
        ans = ans * a[i] // math.gcd(ans, a[i])
    return ans

if __name__ == "__main__":

    n = int(input())
    buf = input().split()
    a = [int(s) for s in buf]

    indexes = [i for i, x in enumerate(a) if x == 1]
    indexes = list(map(add, indexes))
    
    if indexes:
        num = lcm(indexes)
        if num > n:
            print("-1")
        else:
            print(num)
    else:
        print("0")

Submission status: Runtime Error

Solution code:

N = int(input())

a = list(map(int,input().split()))

"""
for i in range(N):

    cnt = 1
    summ = 0
    flag = True

    while (i + 1) * cnt <= N:

        summ += a[(i + 1) * cnt -1]
        cnt += 1

    if summ % 2 != a[i]:
        flag = False
        print (i+1,"はみたさない")
        break

    else:
        pass
        print (summ,a[i],"でおｋ")

if flag :
    

    #print (lis)

    print (sum(a))

    ans = ""

    for i in range(len(a)):
        if a[i] == 1:
            ans += str(i+1) + " "

    print (ans[:-1])

else:
    print (-1)

"""

lis = [-1] * N



for i in range(N):

    i = N-i
    cnt = 2
    summ = 0
    flag = True

    while i * cnt <= N:

        summ += lis[i * cnt -1]
        cnt += 1

    #print (a[i-1],summ)

    if a[i-1] == 0 and summ % 2 == 0:
        lis[i-1] = 0
        #print ("a")

    elif a[i-1] == 0 and summ % 2 == 1:
        llis[i-1] = 1

    elif a[i-1] == 1 and summ % 2 == 0:
        lis[i-1] = 1

    elif a[i-1] == 1 and summ % 2 == 1:
        lis[i-1] = 0

    if not flag:
        break

if flag:

    #print (lis)

    print (sum(lis))

    ans = ""

    for i in range(len(lis)):
        if lis[i] == 1:
            ans += str(i+1) + " "

    print (ans)

else:
    print (-1)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())  
a = np.array(input().split(), dtype=np.int64)
b = copy.deepcopy(A)
M = np.arange(N) + 1
    
for i in np.arange(N // 2)[::-1]:
    A = a[np.where(M % (i+1) == 0)]
    if (np.sum(A) + a[i]) % 2  == 0:
        b[i] = a[i]
    else:
        b[i] = (a[i] + 1) % 2
        
ans = np.where(b == 1)[0] + 1

print(np.size(ans))

if np.size(ans) > 0:
    print(*ans.astype(np.int32))

Submission status: Runtime Error

Solution code:
def make_divisors(n):
    #divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            B[i]+=1
            if i != n // i:
                B[n//i]+=1

    # divisors.sort()
    #return divisors

N=int(input())
A=list(map(int,input().split()))

B=[0]*3000000
C=[]
count=0
for i in reversed(range(N)):
    if B[i]%2!=A[i]:
        make_divisors(i+1)
        count +=1
        C.append(i+1)
print(count)
if count!=0:
    print(C[0],end="")
    for i in range(1,count):
        print(" "+str(C[i]),end=""

Submission status: Runtime Error

Solution code:
5
0 0 0 0 0

Submission status: Runtime Error

Solution code:
#n=list(map(int,input().split()))
n = int(input()) 
#num = [input() for i in range(n)] 
a=[0]*n    
ama=list(map(int,input().split()))

for i in reversed(ama):
    if sum(a[n-1::n])%2==i:
        next
    else:
        a[n-1]=(a[n-1]+1)%2
    n=n-1


print(sum(a))
print(" ".join([i for i, x in enumerate(a) if x == 1]))
#for i in range(n):
#    print(max(num[:i]+num[i+1:]))

Submission status: Runtime Error

Solution code:
N = int(input())
a = [0]+[int(i) for i in input().split()]
ret = [0] * (N+1)

def rec(i) :
    if i == N :
        return
    rec(i+1)
    s = 0
    for j in range(i, N + 1, i) :
        s += ret[j]
    ret[i] = s^a[i]
    
rec(1)
b = []
for i in range(1, N + 1) :
    if ret[i] :
        b.append(str(i))
print(len(b))
print(' '.join(b))

Submission status: Runtime Error

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            B[i]+=1
            if i != n // i:
                B[n//i]+=1

    # divisors.sort()
    return divisors

N=int(input())
A=list(map(int,input().split()))

B=[0]*3000000
C=[]
count=0
for i in reversed(range(N)):
    if B[i]%2!=A[i]:
        make_divisors(i+1)
        count +=1
        C.append(i+1)
print(count)
if count!=0:
    print(C[0],end="")
    for i in range(1,count):
        print(" "+C[i],end="")

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input.split()))

suma = sum(a[1:])

if a[0] == 0:
	if suma== 0:
		print(0)
	else:
		print(-1)
else:
	if suma == 1:
		i = 1
		for i in range(1, N):
			if a[i] == 1:
				break
		
		if (i-1)*2 <= N-1:
			print(-1)
		else:
			print(1)
			print(i+1)
		
	elif suma == 0:
		print(1)
		print(1)

Submission status: Runtime Error

Solution code:
n = int(input())

arr = []
flag_0 = 1
for i in range(n):
    inp = int(input())
    if inp != 0:
        flag_0 = 0
        arr.appned(inp)

if flag_0 == 1:
    print(0)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    s = list(map(int,input().split()))
    r = []
    for i in range(n,0,-1):
        c = sum(x % i == 0 for x in r)
        c1 = c % 2
        if c1 != s[i-1]:
            r.append(str(i))

    print(len(r))
    if len(r) > 0:
        print(" ".join(r))
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
a=list(map(int,input().split()))
B=[]
for i in range(n,0,-1):
    if n//i>1:
        l=n//i
        cnt=0
        for k in range(2,l+1):
            cnt+=a[i*k-1]
        if cnt%2!=a[i-1]:
            B.append(str(i))
    else:
        if a[i-1]==1:
            B.append(str(i))

print(len(B))
if len(B)>0:
    for i in range(len(B)):
        B[i]=str(B[i])
    print(' '.join(B))

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    s = list(map(int,input().split()))
    r = []
    for i in range(n,0,-1):
        c = sum(x % i == 0 for x in r)
        c1 = c % 2
        if c1 != s[i-1]:
            r.append(str(i))
            
    print(len(r))
    print(" ".join(r))
    

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = list(range(n))
k = 2
s = 0
for i in range(n):
  if (n/2-1) < (n-i-1):
    b[n-i-1] = a[n-i-1]
  else:
    for j in range(2,k+1):
      s += b[j*(n-i)-1]
    if s % 2 == a[n-i-1]:
      b[n-i-1] = 0
    else:
      b[n-i-1] = 1
    k += 1
ans = b.count(1)
print(ans)
for i in range(n):
  if b[i] == 1:
    print(i+1)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

import numpy as np
baisuu_count = np.zeros(N)
b = []
for i in reversed(range(N)):
    a = A[i]
    if (baisuu_count[i] // 2 == 1 and a == 0) or (baisuu_count[i] // 2 == 0 and a == 1):
        b.append(i + 1)
        divisors = np.array(make_divisors(i + 1))
        baisuu_count[divisors] += 1


if len(b) == 0:
    print(0)
else:
    print(len(b))
    for _b in range(len(b)):
        print(_b + 1)

Submission status: Runtime Error

Solution code:
n=int(input())

li=[-100]+list(map(int,input().split()))

ans=[0 for i in range(len(li))]
b=len(li)//2+1

for i in range(len(li)-1,b,-1):
    ans[i]=li[i]
    print(i,ans[i])
    
for i in range(b,0,-1):
    k=0
    for j in range(1,n//i+1):
        k+=ans[j*i]
      #  print(k,n//i)

    
  #  print(k,i,li[i])
    k=k//2
    
    if k==0:
        ans[i]=li[i]
    else:
        ans[i]=abs(li[i]-1)
        
print(sum(ans))
anse=""
for i in range(len(ans)):
    if ans[i]==1:
        anse+=str(i)+" "
print(anse)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
D={}
ans=""
M=0
for i in range(N):
    if N//(N-i)==1:
        a=A[N-i-1]
        D[N-i]=a
        if a==1:
            M+=1
            ans=ans+str(N-i)+" "
    else:
        a=N//(N-i)
        memo=0
        for j in range(1,a):
            memo+=D[(N-i)*(j+1)]
        if memo%2==A[N-i-1]:D[N-i]=0
        else:
            D[N-i-1]=1
            M+=1
            ans=ans+str(N-i)+" "
ans=ans[:-1]
print(M)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
p = input().split()
k = []
l = []
for i in range(len(p)):
    w = int(p[-i-1])
    a = len(p)-i
    if len(k) >= a:
        s = 0
        for j in range(len(k)//a):
            s += k[-w*j]
    k.append((w+s)%2)
    if (w+s)%2 == 1:
        l.append(str(a))
print(len(l))
l.reverse()
print(" ".join(l))

Submission status: Runtime Error

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
ans=[]
for i in range(N):
    n=N-i
    syou=N//n
    c=0
    for l in range(1,syou):
        aa=n*(l+1)-1
        c=(c+b[aa])%2
    if a[n-1]==0:
        if c==0:
            b[n-1]=0
        else:
            b[n-1]=1
            ans.append(n)
    if a[n-1]==1:
        if c==0:
            b[n-1]=1
            ans.append(n)
        else:
            b[n-1]=0
print(len(ans))
if len(ans)>1:
    print(' '.join(ans))
if len(ans)==1:
    print(1)

Submission status: Runtime Error

Solution code:
# input
N = int(input())
A = []

#list
for i in range(N):
    n = int(input())
    A.append(n)

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

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import copy

MOD = 2  # type: int

def solve(N: int, A: "List[int]"):
    ans = []
    for i in range(N,0,-1):
        c = 0
        for j in range(2,N + 1):
            if i * j <= N:
                if A[i*j-1] == 1:
                    c += 1
        if A[i-1] == 0:
            if c % 2 == 1:
                ans.append(i)
        else:
            if c % 2 == 0:
                ans.append(i)

    print(len(ans))
    for i in ans:
        print(f"{i} ",end="")

    print("")

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def solve():
    n = int(input())
    A = list(map(int, input().split()))
    for i in range(n // 2, 1, -1):
        cnt = 0
        for j in range(n // i, 1, -1):
            if A[i] != (len([1 for k in range(i, n + 1, j) if A[k] == 1]) & 1):
                A[i] = 1 - A[i]
                cnt += 1
        if cnt > 1:
            print(-1)
            return
    if A[0] != (sum(A) & 1):
        A[0] = 1 - A[0]
    print(sum(A))
    print(*list(A[i] for i in range(n) if A[i]))
solve()

Submission status: Runtime Error

Solution code:
from math import sqrt

N = int(input())
A = list(map(int,input().split()))

upper = int(sqrt(N))+1

ans = []
flg = 0
for i in range(1,upper+1) :
    cnt = 0
    if flg :
        break
    for j,a in enumerate(A) :
        if (j+1) % i != 0 :
            continue
        
        cnt += a
    
    #print("i cnt:", i, cnt)
    
    if cnt % 2 != A[i-1] :
        ans = -1
        flg = 1
        break
    
    if A[i-1] == 1 :
        ans.append(i)
if ans != -1 :
    for i in range(upper+1,N) :
        if A[i] == 1 :
            ans.append(i+1)
if ans == -1 :
    print(ans)
else :
    print(len(ans))
    print(*ans,sep="\n")

Submission status: Runtime Error

Solution code:
n = int(input())
p = input().split()
k = []
l = []
for i in range(len(p)):
    w = int(p[-i-1])
    a = len(p)-i
    if len(k) >= a:
        s = 0
        for j in range(len(k)//a):
            s += k[-w*j]
    k.append(w+s)
    if w+s == 1:
        l.append(str(a))
print(len(l))
l.reverse()
print(" ".join(l))

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))
    results = []
    for i, a in enumerate(a_s):
        if a == 1:
            for result in results:
                if (i+1) % result == 0:
                    print(-1)
                    quit() 
            results.append(str(i+1))
    print(len(results))
    if results:
        print(' '.join(results))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "1" : "0");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{'; for(auto it=lb; it!=ub; it++) cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */



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

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

  for(int p=n; p>=1; p--) {
    int f = 0;
    for(int i=p; i<=n; i+=p) {
      f ^= a[i];
    }
    if( f != a[p] ) {
      pr(f, p);
      cout << -1 << nl;
      return 0;
    }
  }

  vi v;
  for(int i=1; i<=n; i++)
    if( a[i] == 1 ) v.emplace_back(i);
  cout << v.size() << nl;
  for(auto&x:v)cout<<x<<' ';
  cout << endl;

}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

Submission status: Runtime Error

Solution code:
n = int(input())
l = [[int(input()),i] for i in range(n)]
l.sort(key=lambda x:x[0])
#print(n,l)

for i in range(n):
    if l[-1][1] == i:
        print(l[-2][0])
    else:
        print(l[-1][0])