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.

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array([0] + lr())
for i in range(N//2, 0, -1):
    a = A[i]
    result = A[i::i].sum()
    if result % 2 != a:
        A[i] = 1 - a

B = np.where(A == 1)[0]
print(len(B))
print(*B)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[0]*(n+1)
c=[]
for i in range(n,0,-1):
  b[i]=1-(a[i-1]==sum([b[i*(j+1)] for j in range(n//i)])%2)
  if b[i]==1:
    c+=[i]
print(len(c))
print(*c)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
ans = [0] * n
for itr, val in enumerate(A[::-1]):
  idx = n - itr
  if sum([ans[(i + 1) * idx - 1] for i in range(n // idx)]) % 2 != val:
    ans[idx - 1] = int(not ans[idx - 1])


    
p = sum(ans)
print(p)    

if p > 0:
  print(*[i + 1 for i, j in enumerate(ans) if j == 1])

Solution (Python):

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

count = [0 for _ in range(n)]
for i in reversed(range(1, n + 1)):
    tmp = 0
    for j in range(i, n+1, i):
        tmp += count[j-1]
    
    if a[i-1] % 2 != tmp % 2:
        count[i-1] += 1

m = sum(count)
ans = []
for i in range(n):
    if count[i] == 1:
        ans.append(str(i+1))

print(m)
print(' '.join(ans))

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

X = [0] * (N + 1)
for i in range(N, 0, -1):
    
    tmp = A[i-1]
    
    for j in range(i, N+1, i):
        
        if j == i:
            continue
        
        
        tmp ^= X[j]
    
    X[i] = tmp
    
    
    
    
    




print(sum(X))
ans = []
for i in range(N):
    if X[i+1] == 1:
        ans.append(i+1)
print(*ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

B = [0]*n

for i in reversed(range(n)):
    j = i+1
    cnt = 0
    while j <= n:
        cnt += B[j-1]
        j += i+1
    if cnt%2 != A[i]:
        B[i] = 1

m = 0
ans = []
for i, b in enumerate(B):
    if b != 0:
        m += 1
        ans.append(i+1)
print(m)
if len(ans) > 0:
    print(*ans)

Solution (Python):
import os, sys, re, math

N = int(input())

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

memo = [0 for _ in range(N+1)]

for i in range(N,0,-1):
    tmp_s = 0
    idx = i

    while idx <= N:
        tmp_s += memo[idx]
        idx += i

    memo[i] = (tmp_s % 2) ^ a[i-1]

ret = [i for i in range(1,N+1) if memo[i] == 1]
if len(ret) == 0:
    print(0)
else:
    print(len(ret))
    ret = list(map(str,ret))
    print(' '.join(ret))

Solution (Python):
import math
N = int(input())
a = list(map(int,input().split()))
b = [0]*N
ans = []
for k in range(N,0,-1):
    if a[k-1]%2 != b[k-1]%2:
        ans.append(k)
        b[0] += 1
        b[k-1] += 1
        for l in range(2,math.floor(math.sqrt(k))+1):
            if k % l == 0:
                if l*l == k:
                    b[l-1] += 1
                else:
                    b[l-1] += 1
                    b[k//l-1] += 1
print(len(ans))
if len(ans) > 0:
    print(*ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
ind = list(range(1, N+1))


B = [0] * (N + 1)
for i in reversed(range(1, N + 1)):
    if i > N // 2:
        B[i] = A[i - 1]
        continue

    cnt = 0
    x = i * 2
    while x <= N:
        cnt += B[x]
        x += i
    cnt %= 2
    B[i] = cnt ^ A[i - 1]


ans = [i for i in range(1, N+1) if B[i] == 1]
print(len(ans))
if ans:
    print(*ans)

Solution (Python):
import sys

def div(i):
    ans = []
    for d in range(1, i + 1):
        if d ** 2 > i: break
        if i % d == 0:
            if d ** 2 == i: ans.append(d)
            else:
                ans.append(d)
                ans.append(i // d)
    return ans

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    Count = [0] * N
    In = []
    add = 0
    for i in reversed(range(N)):
        if Count[i] % 2 == A[i]: continue
        elif (Count[i] + 1) % 2 == A[i]:
            add += 1
            In.append(i + 1)
            D = div(i + 1)
            for d in D: Count[d - 1] += 1
        else:
            print(-1)
            break
    else:
        print(add)
        print(" ".join(map(str, In)))

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    box = [0] * N
    for i in range(N - 1, -1, -1):
        
        cnt = 0
        
        num = i + 1
        while num <= N:
            cnt += box[num - 1]
            num += (i + 1)
        
        if cnt % 2 != A[i]:
            box[i] = 1

    ans = [idx + 1 for idx in range(N) if box[idx]]

    print(len(ans))
    if ans:
        print(*ans, sep=" ")

if __name__ == "__main__":
    main()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
b = [0 for _ in range(n)]
for i in reversed(range(n)):
    if i * 2 >= n:
        b[i] = a[i]
        continue
    s = 0
    for j in range(i, n, i + 1):
        s += b[j]
    if s % 2 != a[i]:
        b[i] = 1
print(sum(b))
for i in range(n):
    if b[i] == 1:
        print(i + 1, end=' ')
print('')

Solution (Python):
def main():
    N = int(input())
    A = [0] + [int(i) for i in input().split()]
    C = [0]*(N+1)
    for i in range(1, N+1)[::-1]:
        cur = 0
        for j in range(i, N+1, i):
            cur += C[j]
        if cur % 2 != A[i] % 2:
            C[i] += 1
    M = sum(C)
    print(M)
    if M:
        C = [i for i in range(1, N+1) if C[i]]
        print(*C)


if __name__ == '__main__':
    main()

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

box = [0]*(N+1)
ans = []
for n in range(N,0,-1):
    c = 0
    for i in range(n,N+1,n):
        c += box[i]
    c %= 2
    if A[n-1] != c:
        box[n] = 1
        ans.append(n)
print(len(ans))
if ans:
    print(*ans)

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

ans = [0] * N
for i in range(N)[:: -1]:
    a = A[i]
    cnt = 0
    for j in range(i, N, (i + 1)):
        cnt += ans[j]
    if cnt % 2 != a % 2:
        ans[i] = 1

M = sum(ans)
print(M)
if M > 0:
    print(*[i for i, a in enumerate(ans, start=1) if a > 0])

Solution (Python):
N = int(input())
A = [0] + [int(s) for s in input().split(' ')]

B = [0] * (N + 1)
count = 0
ret = []
for i in range(N, 0, -1):
    ai = A[i]
    ii = i
    total = 0
    while ii <= N:
        total += B[ii]
        ii += i
    
    if total % 2 == ai:
        continue
    else:
        B[i] = 1
        count += 1
        ret.append(i)

print(count)
print(' '.join(str(i) for i in ret))

Solution (Python):









n = int(input())
aaa = list(map(int, input().split(' ')))
aaa = [0] + aaa
bbb = [0] * len(aaa)
ans_count = 0
ans = []
for i in range(n, 0, -1):
    hoge = 0
    for j in range(i+i, n+1, i):  
        hoge += bbb[j]
    bbb[i] = 0 if (hoge % 2) == aaa[i] else 1
    if bbb[i] == 1:
        ans_count += 1
        ans.append(i)
    
print(ans_count)
if ans:
    print(' '.join(map(str, ans)))

Solution (Python):
import sys
from heapq import heappush, heappop


def main():
    n=int(input())
    a=list(map(int,input().split()))
    b=[0]*(n+1)
    m=0
    for i in range(n,0,-1):
        k=n//i
        if k==1:
            b[i]=a[i-1]
        else:
            s=0
            for j in range(2,k+1):
                s+=b[i*j]
            b[i]=(s+a[i-1])%2
    ans=[]
    for i in range(1,n+1):
        if b[i]==1:
            ans.append(i)
    print(sum(b))
    if len(ans)!=0:
        print(' '.join(map(str,ans)))
    
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
alist = 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)

    divisors.sort()
    return divisors

balls_multiple = [0] * N
ans = []
for num in range(N-1, -1, -1):
    if balls_multiple[num] % 2 != alist[num]:
        ans.append(num+1)
        for div in make_divisors(num+1):
            balls_multiple[div-1] += 1
if ans:
    print(len(ans))
    print(*sorted(ans))
else:
    print(0)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = [0] + [int(x) for x in input().split()]

ans = [0 for _ in range(N+1)]
for i in reversed(range(1,N+1)) :
    temp = 0
    for j in range(N//i) :
        temp += ans[(j+1) * i]
    if temp%2 != a[i] :
        ans[i] = 1

print(sum(ans))
ans2 = []
for i in range(N+1) :
    if ans[i] == 1 :
        ans2.append(i)
print(*ans2)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
b = [0]*N
bina = 0
M = 0
for i in reversed(range(1,N+1)):
    next_num = i+i
    while(next_num <= N):
        bina ^= b[next_num-1]
        next_num += i
    b[i-1] = bina^a[i-1]
    bina = 0
M = sum(b)
print(M)
for i in range(N):
    if(b[i] == 1):
        print(i+1)

Solution (Python):

def divisor(x):
    ret = []
    for i in range(1,int(x ** 0.5) + 1):
        if x % i == 0:
            ret.append(i)
            if i != x // i:
                ret.append(x // i)
    return ret

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

ans = []
d = [0] * n

for i in range(len(a) - 1,-1,-1):
    if d[i] % 2 != a[i]:
        ans.append(i + 1)
        for j in divisor(i + 1):
            d[j - 1]+=1

print(len(ans))
if len(ans):
    print(*ans)

Solution (Python):
N = int(input())
A = [int(a) for a in 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


divisor = []
for i in range(1, N + 1):
    divisor.append(make_divisors(i))
B = [0]*N
rs = [0]*N
for i in range(N - 1, -1, -1):
    if rs[i] != A[i]:
        B[i] = 1
        for j in divisor[i]:
            rs[j-1] = 1 - rs[j-1]

print(sum(B))
for i in range(N):
    if B[i] == 1:
        print(i+1)

Solution (Python):

"""
D - Preparing Boxes
https://atcoder.jp/contests/abc134/tasks/abc134_d

"""
import sys


def solve(N, arr):
    res = [0] * (N//2) + arr[N//2:]
    for i in range(N//2, 0, -1):
        t = res[i-1::i]
        s = sum(t)
        res[i-1] = 1 if (s + 1) % 2 == arr[i-1] else 0
    
    return sum(res), [i for i, a in enumerate(res, start=1) if a]


def main(args):
    N = int(input())
    arr = [int(i) for i in input().split()]
    M, balls = solve(N, arr)
    print(M)
    if M:
        print(*balls)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):


def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    b = [0 for _ in range(n)]
    for i in reversed(range(1, n+1)):
        s = 0
        j = i + i
        while j <= n: 
            s ^= b[j-1]
            j += i
        b[i-1] = s^a[i-1]
    
    m = sum(b)
    print(m)
    for i in range(n):
        if b[i] == 1:
            if i == n-1:
                print(i+1)
            else:
                print(i+1, end=' ')
        
main()

Solution (Python):









import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    a = list(map(int,ipti().split()))
    ball = [0] * (n+1)

    for i in range(n, 0, -1):
        cnt = a[i-1]
        num = i
        while num <= n:
            if ball[num] == 1:
                cnt += 1
            num += i
        if cnt % 2 == 1:
            ball[i] = 1

    res = []
    m = 0

    for i in range(1, n+1):
        if ball[i] == 1:
            res.append(i)
            m+=1
    if m > 0:
        print(m)
        print(*res)
    else:
        print(0)


if __name__ == '__main__':
    main()

Solution (Python):

n = int(input())
a = list(map(int, input().split()))
ans = [0 for i in range(n+1)]
a.reverse()
for i,num in enumerate(a):
    sum_a = 0
    for j in range(0, n+1, (n-i)):
        sum_a += ans[j]
    if sum_a%2 == 0:
        if num == 1:
            ans[n-i] = 1
    else:
        if num == 0:
            ans[n-i] = 1
sum_ans = 0
ansprint = []
for i,num in enumerate(ans):
    if num == 1:
        ansprint.append(i)
        sum_ans+=1
print(sum_ans)
print(*ansprint, sep=' ')

Solution (Python):
N = int(input())
a = [None]
b = list(map(int,input().split()))
a.extend(b)
ball = [0]*(N+1)

for i in range(1,N+1)[::-1]:
    s = 0
    now = 0
    k = 2

    while True:
        now = i*k
        if now > N:
            break
        s += ball[now]
        k += 1

    if s%2 == a[i]:
        ball[i] = 0
    else:
        ball[i] = 1

print(sum(ball))

for i in range(N+1):
    if ball[i] == 1:
        print(i,end=" ")

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
B = [0]*N
for i in range(N,0,-1):
  s = A[i-1]
  k = i*2
  while k<=N:
    s ^= B[k-1]
    k += i
  if s==1:
    B[i-1] = s
if sum(B)==0:
  print(0)
else:
  print(sum(B))
  for i in range(N):
    if B[i]==1:
      print(i+1,end=' ')

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]

cnt = [0]*n
for i in range(n,0,-1):
  total = sum(cnt[i*k-1] for k in range(1,n//i+1))
  if total % 2 != a[i-1]:
    cnt[i-1] = 1

b = [i+1 for i in range(n) if cnt[i] > 0]

print(sum(cnt))
print(*b)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
ans = [0]*(n+1)

for i in range(n,0,-1):
    
    k = 1
    count = 0
    while k*i <= n:
        count += ans[k*i]
        k += 1
    if count%2 != l[i-1]:
        ans[i] = 1
print(sum(ans))
if sum(ans) > 0:
    for i in range(n+1):
        if ans[i] == 1:
            print(i,end=" ")

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for i in range(n, 0, -1):
    if i > n / 2:
        if a[i - 1] == 1:
            b[i - 1] = 1
    else:
        j = 2 * i
        c = 0
        while True:
            if j > n:
                break
            c += b[j - 1]
            j += i
        if (a[i - 1] + c) % 2 != 0:
            b[i - 1] = 1
ans = []
m = 0
for i in range(n):
    if b[i] == 1:
        ans.append(i + 1)
        m += 1
print(m)
if len(ans) != 0:
    print(" ".join(map(str, ans)))

Solution (Python):
from collections import deque

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

check = [0] * N

for i in reversed(range(1, N + 1)):
    if sum(check[i - 1::i]) % 2 != A[i - 1]:
        check[i - 1] = 1

M = sum(check)
ans = deque()

for index, value in enumerate(check):
    if value == 1:
        ans.append(index + 1)

print(M)
if M > 0:
    print(*ans)

Solution (Python):
from collections import deque

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

check = [0] * N

for i in reversed(range(1, N + 1)):
    x = i
    total = 0
    while x <= N:
        total += check[x - 1]
        x += i
    if total % 2 != A[i - 1]:
        check[i - 1] = 1

M = sum(check)
ans = deque()

for index, value in enumerate(check):
    if value == 1:
        ans.append(index + 1)

print(M)
if M > 0:
    print(*ans)

Solution (Python):
n = int(input())
a = list(map(int , input().split()))
b = [0] * n
for i in reversed(range(1, n+1)):
    tmp = 0
    for j in range(2 * i, n+1, i):
        tmp += b[j-1]
    if tmp % 2 == 1 and a[i-1] == 1:
        b[i-1] = 0
        
        
    if tmp % 2 == 1 and a[i-1] == 0:
        b[i-1] = 1
    if tmp % 2 == 0 and a[i-1] == 1:
        b[i-1] = 1
    if tmp % 2 == 0 and a[i-1] == 0:
        b[i-1] = 0

print(sum(b))
ans = []
for i in range(n):
    if b[i] == 1:
        ans.append(i+1)
print(' '.join(map(str, ans)))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())

a = list( map(int, input().split()))
b=[]
c = [0]*n
ans = 0

for i in reversed(range(n)):
    if a[i] > 1:
        print(-1)
        exit()
    cnt = n // (i+1)
    tmp = 0
    for j in range(2,cnt+1):
        tmp += c[(i+1) * j-1]
    tmp2 = (tmp%2+a[i])%2
    c[i] = tmp2
    ans += tmp2
    if tmp2 == 1:
        b.append(i+1)
b.sort()
print(ans)
print(*b, sep=' ')

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
jud = [0] * n
ans = []
for i in range(n//2, n):
    if a[i] == 1:
        jud[i] = 1
        ans.append(i+1)
for i in range(n//2-1, -1, -1):
    cou = 0
    for j in range(2, n//(i+1)+1):
        cou ^= jud[(i+1)*j-1]
    if a[i] != cou:
        jud[i] = 1
        ans.append(i+1)
ans.sort()
print(jud.count(1))
print(*ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 
MOD = 10**9+7

N = int(inp())
A = [0] + list(map(int, inp().split()))


for i in range(N//2, 0, -1):
  A[i] = sum(A[i::i])&1
  
ans = [i for i, a in enumerate(A) if a]  

print(len(ans))
if len(ans) > 0:
  print(*ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = set()
for i in range(n,0,-1):
    count = 0
    for j in range(1,n//i+1):
        if i*j in ans:
            count += 1
    if count % 2 != a[i-1] :
        ans.add(i)
print(len(ans))
print(" ".join(map(str,ans)))

Solution (Python):
n=int(input())

A=[0]+list(map(int,input().split()))

for i in reversed(range(1,n+1)):
    if sum(A[::i])%2!=A[i]:
        if A[i]==0:
            A[i]=1
        else:
            A[i]=0
        
print(sum(A))
if sum(A)!=0:
    for i,a in enumerate(A):
        if a==1:
            print(i)

Solution (Python):
n=int(input())

A=[0]+list(map(int,input().split()))

for i in reversed(range(1,n+1)):
    if sum(A[::i])%2!=A[i]:
        A[i]^=1
        
print(sum(A))
if sum(A)!=0:
    for i,a in enumerate(A):
        if a==1:
            print(i)

Solution (Python):
from collections import deque
n=int(input())

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

x=[]

for i in range(n//2,n):
    if A[i]==1:
        x.append(i+1)

x=deque(x)



for i in reversed(range(0,n//2)):
    A[i]=A[i]*2-sum(A[i::i+1])
    A[i]%=2
    if A[i]==1:
        x.appendleft(i+1)
        
print(len(x))
if len(x)!=0:
    print(*x)

Solution (Python):
from collections import deque
n=int(input())

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

x=[]

for i in range(n//2,n):
    if A[i]==1:
        x.append(i+1)

x=deque(x)



for i in reversed(range(0,n//2)):
    A[i]=A[i]*2-sum(A[i::i+1])
    A[i]%=2
    if A[i]==1:
        x.appendleft(i+1)
        
print(len(x))
if len(x)!=0:
    print(*x)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

ball = [0] * (N+1)
for i in range(N, 0, -1):
    tmp = A[i-1]
    for j in range(i, N+1, i):
        if j == i:
            continue
        tmp ^= ball[j]
    
    ball[i] = tmp
print(sum(ball))
for i, b in enumerate(ball):
    if b == 1:
        print(i, end=" ")

Solution (Python):
n=int(input())
A=[0]+list(map(int,input().split()))
for i in range(n,0,-1):
  if sum(A[::i])%2!=A[i]:
    A[i]^=1
print(sum(A))
for i,a in enumerate(A):
  if a==1:print(i)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
rem = [0]*(n+1)
for i in range(1, n+1)[::-1]:
    Sum = 0
    for j in range(i, n+1, i):
        Sum += rem[j]
    if Sum % 2 != a[i-1]:
        rem[i] = 1

print(sum(rem))

if sum(rem):
    ans = []
    for i, ele in enumerate(rem):
        if ele:
            ans.append(i)
    print(*ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
b=[0 for i in range(N)]
for i in range(0,N):
    x=N-i
    cnt=0
    for j in range(0, N//x):
        if b[x*(j+1)-1]==1:
            cnt+=1
    b[x-1]=(cnt-a[x-1])%2
print(sum(b))
for i in range(N):
    if b[i]:
        print(i+1)

Solution (Python):

n=int(input())
a=[0]+list(map(int,input().split()))
b=[0 for _ in range(n+1)]
for i in range(n,0,-1):
    if i>n//2:
        b[i]=a[i]
    else:
        b[i]=int(sum([b[k] for k in range(i*2,n+1,i)])%2!=a[i])
print(sum(b))
if sum(b)>0:
    ans=[]
    for i in range(1,n+1):
        if b[i]==1:
            ans.append(i)
    print(*ans)

Solution (Python):
def main():
    box = int(input())
    target = [0] + list(map(int, input().split()))
    balls = [0] * (box + 1)
    put = []
    for i in range(box, 1, -1):
        if not sum(balls[i::i]) % 2 == target[i]:
            balls[i] = 1
            put.append(str(i))
    all_balls = sum(balls)
    if not all_balls % 2 == target[1]:
        put.append("1")
        all_balls += 1
    print(all_balls)
    print(" ".join(put))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [0]*N
    for i in range(N)[::-1]:
        cur_sum = -B[i]
        for j in range(i, N, i+1):
            cur_sum += B[j]
        if cur_sum % 2 != A[i] % 2:
            B[i] = 1
    
    ans = [i+1 for i, b in enumerate(B) if b]
    print(len(ans))
    if ans:
        print(*ans)


if __name__ == '__main__':
    main()

Solution (Python):



N = int(input())
a_list = list(map(int, input().split()))
current_num = [0]*N

M = 0
b_list = []
is_equivalent = True

for i in reversed(range(1,N+1)):
    num = 1
    for j in range(i,N+1,i):
        if current_num[j-1]==1:
            num = num + 1
    if num%2==a_list[i-1]:
        current_num[i-1] = 1

for i in range(N):
    if current_num[i]>=1:
        M = M + 1
        b_list.append(i+1)


print(M)
for b in b_list:
    print(b, end=" ")

Solution (Python):
n, *a = map(int, open(0).read().split())

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

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))

box = [0] * n
ans = []

cnt = 0
for itr, val in enumerate(A[::-1]):
  idx = n - itr -1
  sums_mod2 = sum(box[idx::idx+1]) % 2
  if val != sums_mod2:
    box[idx] += 1
    cnt += 1
    ans.append(idx + 1)
    
print(cnt)
print(*ans)

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

check = [0] * (n+1)
res = []

for i in range(n,0,-1):
    if sum(check[2*i::i])%2 == a[i]:
        continue
    else:
        check[i] = 1
        res.append(i)
print(len(res))
print(*res)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
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
res = []
for i in range(n,0,-1):
    if a[i-1]:
        res.append(i)
        for j in make_divisors(i):
            a[j-1] ^= 1
print(len(res))
if len(res) > 0:
    print(*res)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [0] * (n + 1)

for i in range(n, 0, -1):
    cnt = sum(b[::i])
    
    if cnt % 2 != a[i - 1]:
        b[i] = 1
m = sum(b)
print(m)
for i in range(1, n + 1):
    if b[i]:
        print(i, end=' ')

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [0] * n

for i in range(n - 1, -1, -1):
    cnt = 0
    for j in range(2 * (i + 1), n + 1, i + 1):
        cnt += b[j - 1]
    
    if cnt % 2 != a[i]:
        b[i] = 1
m = b.count(1)
print(m)
for i in range(n):
    if b[i]:
        print(i + 1, end=' ')

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for i in range(n - 1, -1, -1):
    cnt = 0
    for j in range(2 * (i + 1), n + 1, i + 1):
        cnt += b[j - 1]
    if cnt % 2 != a[i]:
        b[i] = 1
m = b.count(1)
print(m)
for i in range(n):
    if b[i]:
        print(i + 1, end=' ')

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
arr = [0 for _ in range(n)]
for i in reversed(range(n)):
    s = 0
    for j in range(i, n, i+1):
        s += arr[j]
    s %= 2
    if a[i] != s:
        arr[i] = 1
print(sum(arr))
for i in range(n):
    if arr[i] == 1:
        print(i+1, end=' ')
print('')

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    b = list(map(int, input().split()))
    lst = b[:]
    for i in range(N,0,-1):
        j = i
        a = 0
        while j <=N: a, j = a^lst[j-1], j+i
        lst[i-1] = a
    ans = [i+1 for i in range(N) if lst[i]]
    print(len(ans))
    print(*ans)
    

if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
def main():
	readline=stdin.readline
	N=int(readline())
	a=list(map(int,readline().split()))
	b=[0]*N
	for i in range(N):
		n=N-i
		count=0
		for k in range(n,N+1,n):
			if k==n:
				pass
			else:
				count+=b[k-1]
		if count%2!=a[n-1]:
			b[n-1]=1
		else:
			b[n-1]=0
	
	res=[]
	M=0
	for i in range(N):
		if b[i]==1:
			res.append(i+1)
			M+=1
	
	print(M)
	print(*res)
if __name__=="__main__":
	main()

Solution (Python):
N = int(input())
A = tuple(map(int,input().split()))

box = [0] * N

for i in range(N-1, -1, -1):
    cnt = 0
    tmp = i + 1
    while tmp <= N:
        cnt += box[tmp - 1]
        tmp += (i + 1)
    
    if cnt  % 2 != A[i]:
        box[i] = 1

ans = [idx+1 for idx in range(N) if box[idx] == 1]

print(len(ans))

if ans:
    print(*ans)

Solution (Python):
import sys

def div(n):
    if n == 1: return [1]
    d = [1]
    for k in range(2, n):
        if k ** 2 > n: break
        if n % k == 0:
            if k ** 2 == n: d.append(k)
            else: 
                d.append(k)
                d.append(n // k)
    return d

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    SumB = [0] * N
    Ans = []
    count = 0

    for i in reversed(range(N)):
        if SumB[i] % 2 == A[i]: continue
        elif (SumB[i] + 1) % 2 == A[i]:
            Ans.append(i + 1)
            count += 1
            d = div(i + 1)
            for j in d: SumB[j - 1] += 1
        else:
            print(-1)
            break
    else: 
        Ans.sort()
        print(count)
        print(" ".join(map(str, Ans)))
        

    return 0
if __name__ == "__main__":
    solve()

Solution (Python):
N=int(input())
a=[int(i) for i in input().split()]
res=[0]*N
for i in range(N,0,-1):
    cnt=0
    for times in range(2,N//i+1):
        cnt+=res[i*times-1]
    res[i-1] = 0 if cnt%2==a[i-1] else 1
print(sum(res))
for i in range(N):
    if res[i]==1:
        print(i+1,end=" ")
print()

Solution (Python):
N = int(input())
arr = list(int(x) for x in input().split())
flag = [-1] * N
ans = []


for i in range(N-1,-1,-1):
    
    sum = 0

    
    for j in range(i,N,i+1):
        
        if j == i:
            continue
        else:
            if flag[j] == 1:
                sum += 1

    
    if sum % 2 == arr[i]:
        flag[i] = 0
    else:
        flag[i] = 1
        
        
        ans.append(i+1)


num = len(ans)

if num == 0:
    print(num)
else:
    print(num)
    print(*ans)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
a=[0]+a
b=[0]*(n+1)

for i in range(n,0,-1):
  sum=0
  for j in range(i+i,n+1,i):
    sum^=b[j]
  b[i]=sum^a[i]
ans=[]
for i in range(1,len(b)):
  if b[i]:
    ans.append(i)
print(len(ans))
print(*ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

b = [0]*n
ans = []
for i in range(n)[::-1]:
    tmp = 0
    for j in range(n//(i+1)):
        tmp += b[(i+1)*(j+1)-1]
    if tmp%2 != a[i]:
        b[i] += 1
        ans.append(i+1)

print(sum(b))
print(*ans)