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: Wrong Answer

Solution code:
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    M = 0
    ret_M = []
    memo_N = [-1]*N # memo: 倍数を足したときに2で割った余り
    for i in range(N)[::-1]:
        i_ = i+1
        q = N//i_
        
        if q == 1:
            memo_N[i] = A[i]
            if A[i] == 1:
                M += 1
                ret_M.append(i_)
        else:
            memo_N[i] = memo_N[i_*2-1]^A[i]
            if memo_N[i]:
                M += 1
                ret_M.append(i_)
                
    print(M)
    if M: print(' '.join(map(str, ret_M[::-1])))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]

for i in range(n,0,-1):
  now=0
  j=i
  for j in range(i-1,n,i):
    now+=a[j]

  if now%2!=a[i-1]:
    ans[i-1]=1

print(sum(ans))
ind=""
for i in range(n):
  if ans[i]==1:ind+=str(i+1)+" "
print(ind)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]

for i in range(n,0,-1):
  now=0
  j=i
  for j in range(i-1,n,i):
    now+=a[j]

  if now%2!=a[i-1]:
    ans[i-1]=1

print(sum(ans))
ind=""
for i in range(n):
  if ans[i]==1:ind+=str(i+1)+" "

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]

for i in range(n,0,-1):
  now=0
  j=i
  for j in range(i-1,n,i):
    now+=a[j]

  if now%2!=a[i-1]:
    ans[i-1]=1

print(sum(a))
ind=""
for i in range(n):
  if ans[i]==1:ind+=str(i+1)+" "

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]

for i in range(n,0,-1):
  now=0
  j=i
  for j in range(i-1,n,i):
    now+=a[j]

  if now%2!=a[i-1]:
    ans[i-1]=1

print(sum(a))
for i in range(n):
  if ans[i]==1:print(i+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]

for i in range(n,0,-1):
  now=0
  j=i
  for j in range(i-1,n,i):
    now+=a[j]

  if now%2!=a[i-1]:
    ans[i-1]=1

print(sum(a))
for i in range(n):
  if a[i]==1:print(i+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]

for i in range(n,0,-1):
  now=0
  j=i
  for j in range(i-1,n,i):
    now+=a[j]

  if now%2!=a[i-1]:
    ans[i-1]=1

print(sum(a))
for i in ans:
  if i==1:print(i)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]

for i in range(n-1,1,-1):
  now=0
  j=i
  end=2
  for j in range(i*2,n,i):
    now+=a[j]

  if now%2!=a[i]:
    ans[i]=1

print(sum(a))
for i in ans:
  if i==1:print(i)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(x) for x in input().rstrip().split()]
ans=[0 for i in range(n)]

for i in range(n-1,1,-1):
  now=0
  j=i
  end=2
  for j in range(i,n,i):
    now+=a[j]

  if now%2!=a[i]:
    ans[i]=1

print(sum(a))
for i in ans:
  if i==1:print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
#print(a)
b = [0]*(N)

for i in range(N, 0, -1):
    to = 0
    #print(i)

    for j in range(i-1, N ,i):
        to += b[j]

    if to%2 != a[i-1]:
        b[i-1] = 1
    #print(b)
if sum(b)==0:
    print(-1)

else:
    print(sum(b))
    ans = str()
    for i in range(N):
        if b[i]:
            ans += str(i+1)+" "
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = ri()
a = rl()

ans=[]

for i in range(n,0, -1):
    sum_=0
    iter_=2
    while i*iter_<=n:
        sum_+=a[i*iter_-1]
        iter_+=1

    if sum_%2!=a[i-1]:
        ans.append(i)
print(len(ans))
if ans:
    print(*ans)

Submission status: Wrong Answer

Solution code:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = ri()
a = rl()

ans=[]

for i in range(n,0, -1):
    sum_=0
    iter_=2
    while i*iter_<=n:
        sum_+=a[i*iter_-1]
        iter_+=1
    if a[i-1]!=sum_%2:
        ans.append(i)
print(len(ans))
if ans:
    print(*ans)

Submission status: Wrong Answer

Solution code:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = ri()
a = rl()

ans=[]

for i in range(n-1, 0, -1):
    sum_=0
    iter_=2
    while i*iter_<=n:
        sum_+=a[i*iter_-1]
        iter_+=1
    if a[i-1]!=sum_%2:
        ans.append(i)
print(len(ans))
if ans:
    print(*ans)

Submission status: Wrong Answer

Solution code:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = ri()
a = rl()

ans=[]
print(-1)
sys.exit()
for i, a_i in enumerate(a):
    sum_=0
    i+=1
    iter_=2
    while i*iter_<=n:
        sum_+=a[i*iter_-1]
        iter_+=1
    if a_i!=sum_%2:
        ans.append(i)
#print(len(ans))
if ans:
    print(*ans)

Submission status: Wrong Answer

Solution code:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = ri()
a = rl()

ans=[]
for i, a_i in enumerate(a):
    sum_=0
    i+=1
    iter_=2
    while i*iter_<=n:
        sum_+=a[i*iter_-1]
        iter_+=1
    if a_i!=sum_%2:
        ans.append(i)
print(len(ans))
if ans:
    print(*ans)

Submission status: Wrong Answer

Solution code:
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = ri()
a = rl()
sum_=0
ans=[]
for i, a_i in enumerate(a):
    i+=1
    iter_=2
    while i*iter_<=n:
        sum_+=a[i*iter_-1]
        iter_+=1
    if a_i!=sum_%2:
        ans.append(i)
print(len(ans))
if ans:
    print(*ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0] + list(map(int,input().split()))

state=[0]*(n+1)
m=0
b=[]
for i in reversed(range(n)):
    if state[i] != a[i]:
        m+=1
        b.append(i)
        j = 1
        while j*j <= i:
            if j % i == 0:
                state[j]=state[j]^1
                if j != i // j:
                    state[i//j]=state[i//j]^1
            j += 1
print(m)
print(*b)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    A=lispin()
    cnt=[0]*N
    ans=set()#1個入れるものを書く
    hurui=list(range(2,450))
    for i in range(2,25):
        temp=[]
        t=hurui[0]
        for j in hurui:
            if j==t or j%t!=0:
                temp.append(j)
        hurui=temp
    #print(hurui)
    for i in range(N-1,-1,-1):
        
        if A[i]!=cnt[i]:
            ans.add(i+1)
            temp=i+1
            ok=0
            cond=0
            for j in range(N):
                if temp==1 or cond==1:
                    break
                cond=1
                for x in range(ok,min(int(temp**0.5)+2,len(hurui))):
                    k=hurui[x]
                    if temp%k==0:                        
                        temp//=k
                        cond=0
                        cnt[temp-1]+=1
                        cnt[temp-1]%=2
                        ok=x
                        break
        #print(cnt,i+1)
    print(len(ans))
        
    if len(ans)>0:print(*sorted(ans))
#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    A=lispin()
    cnt=[0]*N
    ans=set()#1個入れるものを書く
    hurui=list(range(2,450))
    #for i in range(2,450):
        
        
    for i in range(N-1,-1,-1):
        
        if A[i]!=cnt[i]:
            ans.add(i+1)
            temp=i+1
            ok=2
            cond=0
            for j in range(N):
                if temp==1 or cond==1:
                    break
                cond=1
                for k in range(ok,int(temp**0.5)+2):
                    if temp%k==0:                        
                        temp//=k
                        cond=0
                        cnt[temp-1]+=1
                        cnt[temp-1]%=2
                        ok=k
                        break
        #print(cnt,i+1)
    print(len(ans))
        
    if len(ans)>0:print(*sorted(ans))
#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    A=lispin()
    cnt=[0]*N
    ans=set()#1個入れるものを書く
    hurui=list(range(2,450))
    #for i in range(2,450):
        
        
    for i in range(N-1,-1,-1):
        
        if A[i]!=cnt[i]:
            ans.add(i+1)
            temp=i+1
            ok=2
            cond=0
            for j in range(N):
                if temp==1 or cond==1:
                    break
                cond=1
                for k in range(ok,temp):
                    if temp%k==0:                        
                        temp//=k
                        cond=0
                        cnt[temp-1]+=1
                        cnt[temp-1]%=2
                        ok=k
                        break
        #print(cnt,i+1)
    print(len(ans))
        
    if len(ans)>0:print(*sorted(ans))
#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    A=lispin()
    cnt=[0]*N
    ans=set()#1個入れるものを書く
    hurui=list(range(2,450))
    #for i in range(2,450):
        
        
    for i in range(N-1,-1,-1):
        
        if A[i]!=cnt[i]:
            ans.add(i+1)
            temp=i+1
            ok=2
            cond=0
            for j in range(N):
                if temp==1 or cond==1:
                    break
                cond=1
                for k in range(ok,int(temp**0.5)+1):
                    if temp%k==0:                        
                        temp//=k
                        cond=0
                        cnt[temp-1]+=1
                        cnt[temp-1]%=2
                        ok=k
                        break
        #print(cnt,i+1)
    print(len(ans))
        
    if len(ans)>0:print(*sorted(ans))
#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    A=lispin()
    cnt=[0]*N
    ans=set()#1個入れるものを書く
    for i in range(N-1,-1,-1):
        
        if A[i]!=cnt[i]:
            ans.add(i+1)
            temp=i+1
            ok=2
            for j in range(N):
                if temp==1:
                    break
                    
                for k in range(ok,int(N**0.5)+1):
                    if temp%k==0:                        
                        temp//=k
                        cnt[temp-1]+=1
                        cnt[temp-1]%=2
                        ok=k
                        break
        #print(cnt,i+1)
    print(len(ans))
        
    if len(ans)>0:print(*sorted(ans))
#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    A=lispin()
    cnt=0
    ans=set()#1個入れるものを書く
    for i in range(N-1,-1,-1):
        if i==0:
            cnt%=2
            if cnt!=A[i]:
                ans.add(1)
        else:
            if A[i]==1:
                ans.add(i+1)
                cnt+=1
    print(len(ans))
        
    if len(ans)>0:print(*sorted(ans))
#%%submit!
resolve()

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

# ここから書き始める
n = int(input())
a = list(map(int, input().split()))

def func(n, a):
    x = [[] for i in range(n)]
    for i in range(n):
        d = make_divisors(i + 1)
        for j in d[:-1]:
            x[j - 1].append(i + 1)
    # print("x =", x)

    ans = [0 for i in range(n)]
    for i in reversed(range(n)):
        total = 0
        for j in x[i]:
            total += ans[j - 1]
        if total % 2 != a[i]:
            ans[i] = 1
    # print("ans =", ans)

    m = ans.count(1)
    print(m)
    # print("ans =", ans)
    for i in range(m):
        if ans[i] == 1:
            print(i + 1)
    # return ans

func(n, a)
# for n in range(1, 10):
#     for i in range(1 << n):
#         bit = bin(i)[2:].zfill(n)
#         a = [int(i) for i in bit]
#         ans = func(n, a)
#         for i in range(n):
#             total = ans[i]
#             for j in range(n):
#                 if i == j or (j + 1) % (i + 1) != 0:
#                     continue
#                 total += ans[j]
#             if total % 2 != a[i]:
#                 print("error")

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

# ここから書き始める
n = int(input())
a = list(map(int, input().split()))

x = [[] for i in range(n)]
for i in range(n):
    d = make_divisors(i + 1)
    for j in d[:-1]:
        x[j - 1].append(i + 1)
# print("x =", x)

ans = [0 for i in range(n)]
for i in reversed(range(n)):
    total = 0
    for j in x[i]:
        total += ans[j - 1]
    if total % 2 != a[i]:
        ans[i] = 1
# print("ans =", ans)

m = ans.count(1)
print(m)
# print("ans =", ans)
for i in range(m):
    print(1)

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

# ここから書き始める
print(-1)
# n = int(input())
# a = list(map(int, input().split()))

# x = [[] for i in range(n)]
# for i in range(n):
#     d = make_divisors(i + 1)
#     for j in d:
#         x[j - 1].append(i + 1)

# ans = [0 for i in range(n)]
# for i in reversed(range(n)):
#     total = 0
#     for j in x[i]:
#         total += ans[j - 1]
#     if total % 2 != a[i]:
#         ans[i] = 1
# # print("ans =", ans)

# m = ans.count(1)
# print(m)
# for i in range(m):
#     print(1)