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:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

N = i_inpl()
A = l_inpl()

ans = [0] * N
flag = True
for i in range(N)[::-1]:
    cnt = N//(i+1)
    if cnt == 1:
        if A[i] > 1:
            flag = False
            break
        else:
            ans[i] = A[i]
    else:
        tmp = 0
        for j in range(1, cnt+1):
            tmp += ans[j*(i+1)-1]
        if tmp == A[i]:
            ans[i] = 0
        elif tmp == A[i]-1:
            ans[i] = 1
        else:
            flag = False
            break

if flag:
    print(sum(ans))
    l = []
    for ind, i in enumerate(ans):
        if i != 0:
            l.append(str(ind+1))
    if sum(ans) != 0:
        print(" ".join(l))
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
a_list = [-1] + list(map(int, input().split()))

cache = {}
def decompose(n):
	if n in cache:
		return cache[n]
	
	if n % 2 == 0:
		return [2] + decompose(n // 2)
	
	for i in range(3, math.floor(math.sqrt(n)), 2):
		if n % i == 0:
			return [i] + decompose(n // i)
	return [n]

rels = [set() for _ in range(N + 1)]
for i in range(2, N + 1):
	for d in decompose(i):
		if d != i:
			rels[d].add(i)
	rels[1].add(i)

b_list = [None] * (N + 1)
for i in range(N, 0, -1):
	b = a_list[i]
	for j in rels[i]:
		b = b ^ b_list[j]
	b_list[i] = b

count = 0
b_list2 = []
for i in range(1, N + 1):
	if b_list[i] == 1:
		count += 1
		b_list2.append(str(i + 1))

print(count)
print(" ".join(b_list2))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque
import sys

sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


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

    return divisors


def main():
    N = int(input())
    # A = [
    #     int(input())
    #     for _ in range(N)
    # ]
    A = [int(a) for a in input().split()]

    res_c = 0
    res1 = []
    bucket = [0] * (N + 1)

    for i in reversed(range(N)):
        k = i + 1
        if k * 2 >= N:
            if A[i] == 1:
                res_c += 1
                res1.append(k)
                for di in d(k):
                    bucket[di] += 1
            continue
        if k == 1:
            if res_c % 2 != A[i]:
                res_c += 1
                res1.append(k)
            break

        if bucket[k] % 2 != A[i]:
            res_c += 1
            res1.append(k)
            for di in d(k):
                bucket[di] += 1
    print(res_c)
    print(*res1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N =int(input())
As = [int(x) for x in input().split()]
res = [0]*(N)
ks = range(N)

for i in range(N-1,N//2,-1):
    res[i] = As[i]
for i in range(N//2,0,-1):
    res[i] = (As[i]+sum(res[i::(i+1)]))%2
res[0] = (As[0]+sum(res[1:]))%2
print(" ".join(map(str,res)))

Submission status: Wrong Answer

Solution code:
#def sqrt2(n):
#    i = 1
#    while i * i <= n:
#        i += 1
#    return i - 1

if __name__ == '__main__':
    n = int(input())
    a = [int(s) for s in input().split()]
    b = [0] * n
    for i in range(n, 0, -1):
        if i + i <= n:
            b[i - 1] = a[i - 1] ^ a[i + i - 1]
        else:
            b[i - 1] = a[i - 1]
    m = b.count(1)
    print(m)
    if m:
        print(*(i + 1 for i, x in enumerate(b) if x))

Submission status: Wrong Answer

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

N = int(input())
A = list(map(int, input().split()))
B = []
D = [0 for i in range(N)]
for i in range(N):
    if A[N-i-1]:
        incre_divisors(N-i, D)
    if D[N-i-1] % 2:
        B.append(N-i)

B.sort()
print(len(B))
print(" ".join(map(str, B)))


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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0] * N
if A[-1] == 1:
  B[N-1] = 1

for i in range(N)[::-1]:
  if( not sum(B[::i+1])%2 == A[i]):
    B[i] = 1
  if(not sum(B[::i+1])%2 == A[i]):
    print(-1)
    quit()
  
print(sum(B))
for i, b in enumerate(B):
  if b == 1:
    print(i+1, end=" ")

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
t = np.array(range(1,N+1))
ans = np.zeros(N)
amari = list(map(int,input().split()))
for i in range(N):
  sum = 0
  p = N-i
  for k in t[t%p == 0]:
    sum += ans[k-1]
  if (sum % 2) != amari[p-1]:
    ans[p-1] = 1
for i in range(N):
  print(int(ans[i]))

Submission status: Wrong Answer

Solution code:


def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = A.copy()
    for i in reversed(range(1, N // 2)):
        tag = i * 2
        tmp = 0
        while tag <= N:
            tmp += ans[tag - 1]
            tag += i
        ans[i - 1] = 1 if tmp % 2 != ans[i - 1] else 0
    print(sum(ans))
    s = ''
    for i, a in enumerate(ans, 1):
        if a == 1:
            s += str(i) + ' '
    if s != '':
        print(s.strip())


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
put = [0]*N

for i in reversed(range(N)):
    if A[i] == 1:
        put[i] = 1
        # iを素因数分解して、約数に1をxorしていく
        A[i] ^= 1
        if i != 0:
            A[0] ^= 1
        tmp = 2
        n = i+1
        while tmp*tmp <= n:
            if n % tmp == 0:
                n //= tmp
                A[tmp-1] ^= 1
            else:
                tmp += 1

ans = []
for i in range(N):
    if put[i] == 1:
        ans.append(i+1)
print(len(ans))
if len(ans) > 0:
    print(*ans)

Submission status: Wrong Answer

Solution code:
# from sys import exit, stderr
# from inspect import currentframe
# def debug(*args):
#     names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
#     print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args), file=stderr)
#     return
N = int(input())
a = [int(_) for _ in input().split()]
b = set()
out = []
n = 0
for i in range(N-1, -1, -1):
    if a[i] == 1:
        tmp = 1
        for e in b:
            tmp *=e
        out.append(tmp + a[i])
        a[i] = 0
        n += 1
    b.add(a[i])
print(n)
if len(out) > 0:
    for i in range(len(out)):
        print(out[i], end=" ")
    print()

Submission status: Wrong Answer

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

b=[-1]*N
b[N-1]=a[N-1]
for i in range(N-1)[::-1]: #N=4なら 2,1,0
    sum_count = N // (i+1)
    if sum_count==1:
        b[i]=a[i]
    else:
        sum1=0
        for j in range(sum_count-1):
            sum1 = sum1 + b[(i+1)*(j+1)]
        sum1 = sum1 % 2
        b[i]=(a[i]+ sum1%2)%2

print(sum(b))
for i in range(N):
    if b[i]==1:
        if i == N-1:
            print(i+1)
        else:
            print(i+1,end=" ")

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input())
    
    a = list(map(int,input().split()))
    
    if(sum(a) == 0):
        print(0)
        exit()

    count = 0
    buf = []
    
    for i, abuf in enumerate(a):
        # print(i+1, abuf)
        if abuf == 1:
            count += 1
            buf.append(abuf)
    
    print(count)
    if(count != 0):
        print(' '.join(map(str, buf)))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import sqrt

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

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

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

ans = [0] * n

def baisuu(num, max):
    ret = []
    i = num
    while i <= max:
        ret.append(i)
        i = i + num
    return ret
    

print("{}".format(baisuu(4,4)))

an = list(map(int, input().split()))
for i in range(n):
    a = an[i]
    if a == 1:
#        print("{}".format(yakusuu(i+1)))
        for mltp in baisuu(i+1, n):
            ans[mltp-1] = ans[mltp-1] + 1


ans = list(map(lambda x: x%2,ans))
print("{}".format(ans.count(1)))

for i in range(n):
    if ans[i] == 1:
        print("{}".format(i+1))

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import defaultdict
from heapq import heappush, heappop
from math import ceil


def djkstra_adj_list(adj_list, src):
    dist = defaultdict(lambda: np.inf)
    dist[src] = 0

    prev = defaultdict(lambda: None)

    queue = []
    heappush(queue, (dist[src], src))

    while len(queue) > 0:
        dist_u, u = heappop(queue)
        vs = adj_list[u]
        for v, weight in vs:
            alt = dist_u + weight
            if alt < dist[v]:
                dist[v] = alt
                prev[v] = u
                heappush(queue, (alt, v))

    return dist, prev


def djkstra_adj_mat(adj_mat, src):
    dist = defaultdict(lambda: np.inf)
    dist[src] = 0

    prev = defaultdict(lambda: None)

    queue = []
    heappush(queue, (dist[src], src))

    while len(queue) > 0:
        dist_u, u = heappop(queue)
        vs = np.argwhere(adj_mat[u] > 0).flatten()
        for v in vs:
            weight = adj_mat[u, v]
            alt = dist_u + weight
            if alt < dist[v]:
                dist[v] = alt
                prev[v] = u
                heappush(queue, (alt, v))

    return dist, prev


def main():

    N = int(input())
    a_arr = list(map(int, input().split()))
    a_arr = np.array(a_arr, dtype=np.int)

    boxes = np.zeros(N, dtype=np.int)

    boxes[N//2:] = a_arr[N//2:]

    for i in range(N//2, 0, -1):
        boxes[i-1] = np.sum([boxes[(j + 1) * i-1]
                             for j in range(N // i)]) + a_arr[i-1] % 2

    # print(boxes)
    M = int(np.sum(boxes == 1))
    print(M)
    j = 0
    for i in range(N):
        if boxes[i] == 1:
            if j == M - 1:
                print(i+1)
            else:
                print(i+1, end=' ')
            j += 1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def ch(i):
  return 1- i
n = int(input())
ai = list(map(int,input().split()))
ans = [0 for i in range(n)]

while n != 0:
  for i in range(int(n/2),n):#後半の処理
    ans[i] = ai[i]
    for j in range(int(n/2)):#前半の処理
      if ai[i] == 1 and (i+1)%(j+1) ==0:
        ai[j] = 1 - ai[j]
  n = int(n/2)
if ai[0] == ans[0]:
  print(sum(ans))
  if (sum(ans) == 0):
    print(0)
    exit(0)
  else:
    for i in range(len(ans)):
      if(ans[i] == 1):
        print('{} '.format(i+1),end='')
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
ans = [0]*n
cnt = 0
for i in range(1, n+1):
    dp = cnt%2
    if a[n-i] == 0 and dp == 0:
        ans[i-1] = 0
    elif a[n-i] == 1 and dp == 1:
        ans[i-1] = 0
    else:
        ans[i-1] = 1
        cnt += 1
print(cnt)
if cnt == 0:
    sys.exit()
for i in range(n):
    if ans[n-i-1] == 1:
        print(i+1, end=" ")

Submission status: Wrong Answer

Solution code:
N=int(input())
a = list(map(int,input().split()))
# N = 2*10**5
# a = [0 for i in range(N)]

fail = False
r = [0 for i in range(N)]
for i in range(N)[::-1]:
  tmpsum = 0
  for t in range(2,(N//(i+1))+1):
#     print(f"  {t*(i+1)}")
    tmpsum += a[(i+1)*t-1]
  diff = (a[i]-tmpsum)%2
#   print(diff)
  if diff == 1:
    r[i] = 1
  elif diff == 0:
    r[i] = 0
  else:
    fail = True
    break

if fail:
  print(-1)
else:
  print(sum(r))
  result = []
  for i in range(N):
    if r[i]==1:
      result.append(i+1)
  if len(result) > 0:
    print(" ".join(map(str,result)))

Submission status: Wrong Answer

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(N):
   chk_num = int(N/(i+1))

   if(chk_num<2):
      continue

   M += 1
   b.append(chk_num%2)


print(M)
print(b)

Submission status: Wrong Answer

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:
    while n > k*(n-i)-1:
      s += b[k*(n-i)-1]
      k += 1
    k = 2
    if s % 2 == a[n-i-1]:
      b[n-i-1] = 0
    else:
      b[n-i-1] = 1

ans = b.count(1)
print(ans)
for i in range(n):
  if b[i] == 1:
    print(i+1, end=" ")

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a = input().split()

#インデックスは1~n
oku = {}
okun = 0
for i in range(int(n/2)+1, n+1):
  oku[i] = int(a[i-1])
  if int(a[i-1]) == 1:
    okun += 1
    
for i in range(int(n/2), 0, -1):
  b = 0
  for j in range(i*2, n, i):
    if oku[j] == 1:
      b+=1
  if b % 2 == int(a[i-1]):
    oku[i] = 0
  else:
    oku[i] = 1
    okun += 1

print(okun)
for i in range(1,n+1):
  if oku[i] == 1:
    print("1", end = " ")

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
arr=[]
c=0
for i in range(0,N):
    vec=np.zeros(N,dtype=bool)
    vec[np.arange(i,N,i+1)]=True
    if sum(A[vec])%2==A[i]:
        if A[i]==1:
            c+=1
            arr.extend([i+1])
if c==N:    
    ans=len(arr)
    print(ans)
    if ans>0:
        for i in range(ans):
            print(arr[i],end=" ")
else:
    print(-1)

Submission status: Wrong Answer

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

b = [0]*(N+1)
b = [0]*(N+1)
for i in range(N//2,N):
    b[i] = a[i]

for i in range(N//2,-1):
    if b[i*2] % 2 != a[i]:
        b[i] = 1


m = 0
ans = []
for i in range(1,len(b)):
    if b[i] == 1:
        ans.append(i)
        m+=1

if m % 2 != a[0]:
    print(-1)
    exit()

print(m)
if m > 0:
    print(" ".join(map(str,ans)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
C = [0 for i in range(N)]

for i in range(N-1, -1, -1):
    if i > N // 2:
        C[i] = A[i]
    else:
        sum_b = 0
        for k in range(1, 10**6):
            if i * k > N-1:
                break
            else:
                sum_b += C[i * k]
        if sum_b % 2 == A[i]:
            C[i] = 0
        else:
            C[i] = 1

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

Submission status: Wrong Answer

Solution code:
def main():

    """ convenient functions
    # for i, a in enumerate(iterable)
    # q, mod = divmod(a, b)
    # divmod(x, y) returns the tuple (x//y, x%y)
    # Higher-order function: reduce(operator.mul, xyz_count, 1)
    # manage median(s) using two heapq https://atcoder.jp/contests/abc127/tasks/abc127_f
    """

    """convenient decorator
    # @functools.lru_cache():
    # to facilitate use of recursive function
        # ex:
        # from functools import lru_cache
        # import sys
        # sys.setrecursionlimit(10**9)
        # @lru_cache(maxsize=None)
        # def fib(n):
        #     if n < 2:
        #         return n
        #     return fib(n-1) + fib(n-2)
        # print(fib(1000))
    """
    
    # import numpy as np
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product # https://docs.python.org/ja/3/library/itertools.html
    # accumulate() returns iterator! to get list: list(accumulate())
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  # prime factor
        b, e = 2, 0  # base, exponent
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        # TODO: How should I do when n - r is negative?
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict # https://docs.python.org/ja/3/library/collections.html#collections.deque
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
    from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
    import operator
    from operator import itemgetter
    # ex1: List.sort(key=itemgetter(1))
    # ex2: sorted(tuples, key=itemgetter(1,2))
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)

    # first create factorial_list
    # fac_list = mod_factorial_list(n)
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) # Recursive function in python is slow!
    def modinv(a, p = MOD):
        # evaluate reciprocal using Fermat's little theorem:
        # a**(p-1) is identical to 1 (mod p) when a and p is coprime
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        # fac_list = modfactorial_list(100)
        # print(modcomb(100, 5, modfactorial_list(100)))
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    """ initialize variables and set inputs
    # initialize variables
        # to initialize list, use [0] * n
        # to initialize two dimentional array, use [[0] * N for _ in range(N)]
    # set inputs
        # open(0).read() is a convenient method:
        # ex) n, m, *x = map(int, open(0).read().split())
        #     min(x[::2]) - max(x[1::2])
        # ex2) *x, = map(int, open(0).read().split())
        #     don't forget to add comma after *x if only one variable is used
    # preprocessing
        # transpose = [x for x in zip(*data)]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [(1, 4, 7), (2, 5, 8), (3, 6, 9)]
        # flat = [flatten for inner in data for flatten in inner]
        # ex) [[1, 2, 3], [4, 5, 6], [7, 8, 9]] => [1, 2, 3, 4, 5, 6, 7, 8, 9]
    # calculate and output
        # output pattern
        # ex1) print(*l) => when l = [2, 5, 6], printed 2 5 6
    """

    # functions used
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    R = lambda: list(map(int, r().split()))
    Rmap = lambda: map(int, r().split())
    Rfloat = lambda: list(map(float, r().split()))
    Rtuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    # single int: int(r())
    # single string: r()
    # single float: float(r())
    # line int: R()
    # line string: r().split()
    # line (str, int, int): [j if i == 0 else int(j) for i, j in enumerate(r().split())]
    # lines int: [R() for _ in range(n)]
    """

    if __name__ != '__main__':
        # for test
        sys.stdin = open('sample.txt')

    # ----------------------------------
    # main

    N = int(r())
    A = R()
    B = [0] * N
    for i in range(N-1, -1, -1):
        j = i + 1
        B[i] = sum(B[i::j])%2 + A[i]
    print(sum(B))
    if sum(B) != 0:
        C = []
        for i, b in enumerate(B):
            if b == 1:
                C.append(i+1)
        print(*C)
    
    # end of main
    # ----------------------------------

    """memo: how to use defaultdict of list
    # initialize
    Dic = defaultdict(list)
    # append / extend
    Dic[x].append(y)
    # for
    for k, v in Dic.items():
    """

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

import collections
import math
import math
import collections
import itertools

def eratosthenes_sieve(n):
    table = [0] * (n + 1)
    prime_list = []

    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1

    return prime_list

def trial_division_prime(n, prime_list):
    prime_count = collections.Counter()

    for i in prime_list:
        if i * i > n:
            break
        while n % i == 0:
            n /= i
            prime_count[i] += 1
    if n > 1:
        prime_count[n] += 1

    return prime_count

def solve():
    N = int(input())
    a_list = list(map(int, input().split()))

    # 素因数の01を数えるdict
    bits = collections.defaultdict(int)
    prime_list = eratosthenes_sieve(N)

    ans = []
    # 後ろから見ていく
    for i in range(N-1, -1, -1):
        num = i + 1
        a = a_list[i]
        if a == bits[num]:
            # 入れる必要がないなら気にしない
            continue

        # 入れる場合
        c = trial_division_prime(num, prime_list)
        for k in c:
            bits[k] = (bits[k] + 1) % 2
        ans.append(num)
        #
        # print(c, bits)

    print(len(ans))
    print(' '.join([str(num) for num in reversed(ans)]))
solve()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input())
    
    a = list(map(int,input().split()))
    
    if(sum(a) == 0):
        print(0)
        exit()

    count = 0
    buf = []
    
    for i, abuf in enumerate(a):
        # print(i+1, abuf)
        if abuf == 1:
            count += 1
            buf.append(abuf)
        
    print(count)
    print(' '.join(map(str, buf)))
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

b = [0 for i in range(N)]

def check(i):
    cnt = 0
    n = i
    while n <= N:
        cnt += b[n-1]
        n += i
    return cnt

for i in range(N-1,-1,-1):
    if a[i] + check(i+1) == 1:
        b[i] = 1
print(b.count(1))
L = [str(int(i)) for i in b]
print(' '.join(L))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
C = [0 for i in range(N)]

for i in range(N-1, -1, -1):
    if i > N // 2:
        C[i] = A[i]
    else:
        sum_b = 0
        for k in range(1, 10**6):
            if i * k > N-1:
                break
            else:
                sum_b += C[i * k]
        if sum_b % 2 == A[i]:
            C[i] = 0
        else:
            C[i] = 1

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

Submission status: Wrong Answer

Solution code:
import copy
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
	b.append(0)
for i in reversed(range(1,n+1)):
	j = copy.deepcopy(i)
	j -= 1
	sums = 0
	for k in range(1,int(n/i)+1):
		s = k*i - 1
		sums += b[s]
	if(sums%2 == a[j]):
		b[j] = 0
	else:
		b[j] = 1

ans = []
anstext = ''
for i in reversed(b):
	if(i!=0):
		ans.append(i)
		anstext = anstext + str(i) + ' '
print(len(ans))
if(len(anstext)!=0):
	print(anstext[:-2])

Submission status: Wrong Answer

Solution code:
n = int(input())
a_lst = [int(elem) for elem in input().split()]

m = a_lst.count(1)
b_lst = [str(i + 1) for i, elem in enumerate(a_lst) if elem == 1]
print(m)
if b_lst != []:
    print(' '.join(b_lst))

Submission status: Wrong Answer

Solution code:
n = int(input())
boxes = [0] * n
amari = list(map(lambda x: int(x), input().split()))


# boxes の うち c の倍数の要素を足し合わせて2で割った余りを返す
def box_count(boxes, c):
    counter = 0
    for i in range(0, len(boxes), c):
        if i == 0:
            continue
        else:
            counter += boxes[i - 1]
    return counter % 2
        

ballbox = ''   
# 後ろから決めていく
for i in range(n):
    if box_count(boxes, n - i) == 1:
        boxes[n - i - 1] = 1 - amari[n - i - 1]
    else:
        boxes[n - i - 1] = 0 + amari[n - i - 1]

    if boxes[n - i - 1] == 1:
        ballbox += str(n - i) + ' '

print(sum(boxes))
print(ballbox)