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: Time Limit Exceeded

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    boxes = [0] * (N+1)
    ans_boxes = [0]
    [ans_boxes.append(x) for x in list(map(int, input().split()))]

    count = 0
    ans = []

    def judge(n):
        s = 0
        for b in range(n, len(boxes)):
            if b % i == 0:
                s += boxes[b]

        if s % 2 == ans_boxes[i]:
            return True
        else:
            return False

    for i in reversed(range(1, len(boxes))):
        if judge(i):
            continue

        else:
            count += 1
            ans.append(i)
            boxes[i] += 1
            if judge(i):
                pass
            else:
                print(-1)
                sys.exit()

    print(count)
    if ans:
        print(*ans, sep=' ')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    boxes = [0] * (N+1)
    ans_boxes = [0]
    [ans_boxes.append(x) for x in list(map(int, input().split()))]

    count = 0
    ans = []

    def judge(n):
        s = 0
        for b in range(len(boxes)):
            if b % i == 0:
                s += boxes[b]

        if s % 2 == ans_boxes[i]:
            return True
        else:
            return False

    for i in reversed(range(1, len(boxes))):
        if judge(i):
            continue

        else:
            count += 1
            ans.append(i)
            boxes[i] += 1
            if judge(i):
                pass
            else:
                print(-1)
                sys.exit()

    print(count)
    if ans:
        print(*ans, sep=' ')


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors
n=int(input())
ans=[0]*n
count=[0]*n

a=list(map(int,input().split()))
for i in range(n,0,-1):
    if count[i-1]%2!=a[i-1]:
        ans[i-1]=1
        b=make_divisors(i)
        for j in b:
            count[j-1]+=1
print(sum(ans))
kai=[]
for i in range(n):
    if ans[i]==1:
        kai.append(i+1)
print(*kai)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
*a, = map(int,input().split())
box = [0]*n
cnt=0
ans=[]
for i in range(n,0,-1):
    sum = 0
    for j in range(i,n+1,i):
        sum+=box[j-1]
    if sum%2!=a[i-1]:
        ans.insert(0,i)
        cnt+=1
        box[i-1]+=1

if cnt!=0:
    print(cnt)
    print(*ans)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input().strip())
A = [None] + list(map(int, input().strip().split(' ')))

# 番号の大きい方から見ていく

# N以下のrの倍数
def multiple(r, N):
  return [r*i for i in range(1,N+1) if r*i < N]

B = [None] + [0]*N
for i in range(N, 0, -1):
  if i*2 > N:
    B[i] = A[i]
    continue
  muls = multiple(i, N)
  B[i] = (A[i] + sum(B[j] for j in muls[1:]))%2

print(sum(B[1:]))
print(*[i+1 for i,b in enumerate(B[1:]) if b == 1])

Submission status: Time Limit Exceeded

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

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

ans = []


def ball_ok(balls):
    global ans
    for i in range(1, n + 1):
        sum_ = 0
        for j in range(i, n + 1, i):

            sum_ += balls[j]

        if sum_ % 2 != a[i-1]:
            return 0

    ans = balls
    return 1


def ball(balls, k):
    if k == n+1:
        return ball_ok(balls)
    b0 = ball(balls + [0], k + 1)
    b1 = ball(balls + [1], k + 1)
    return b0 or b1


res = ball(balls=[1], k=1)

cnt = 0

ansi = []

for i in range(1, len(ans)):
    if ans[i] == 1:
        cnt += 1
        ansi.append(i)

if cnt == 0:
    print(0)
else:
    print(len(ansi))
    for _ in ansi:
        print(_)

Submission status: Time Limit Exceeded

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

info = [0] * (n+1)

for i in range(0,n):
    count = 0
    for j in range(n-i,n+1):
        count += info[j]
    if count != a[n-i]:
        info[n-i] = 1

ans = []

for k in range(1,n+1):
    if info[k] == 1:
        ans.append(k)

print(len(ans))
if ans != []:
    print(" ".join(map(str,ans)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
flags=[]
 
for i in reversed(range(0,n)):
    l=b[i:]
    if a[i] == sum(b[j-1] for j in range(i+1,n+1,i+1))%2:
        b[i]=0
    else:
        b[i]=1
        flags.append(i+1)
 
 
 
if sum(b)%2!=a[0]:
    print(-1)
else:
    print(len(flags))
    for i in flags:
        print(i)

Submission status: Time Limit Exceeded

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

for i in reversed(range(0,n)):
    l=b[i:]
    if a[i] == sum(b[j-1] for j in range(i+1,n+1,i+1))%2:
        b[i]=0
    else:
        b[i]=1
        flags.append(i+1)



if sum(b)%2!=a[0]:
    print(-1)
else:
    print(len(flags))
    for i in flags:
        print(i)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
listA = list(map(int,input().split()))[::-1]

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

    # divisors.sort()
    return divisors

# Nの倍数の数を格納する辞書
baisuu = {i:0 for i in range(1,N+1)}
M=0
out_list=[]

a=listA

half=N//2

for i,ai in enumerate(a):
    now_index=N-i
    if now_index > half:
        if ai==1:
            soinsuu = make_divisors(now_index)
            out_list.append(now_index)
            M+=1
            for so in soinsuu:
                baisuu[so]+=1
    else:
        if baisuu[now_index]%2!=ai:
            out_list.append(now_index)
            M+=1
            soinsuu = make_divisors(now_index)
            for so in soinsuu:
                baisuu[so]+=1

print(M)
if M>0:
    out_list=sorted(out_list)
    print(" ".join(list(map(str, out_list))))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = input().split(' ')
ball_list = [0] * N
output_list = []
count = 0
for i in range(N):
    sum_amari = sum(ball_list[(N - i -1)::(N - i)])
    if sum_amari % 2 != int(An[N - i -1]): 
        ball_list[N - i -1] = 1
        output_list.insert(0,str(N - i))

print(len(output_list))
if len(output_list) > 0:
    print(' '.join(output_list))

Submission status: Time Limit Exceeded

Solution code:
import glob
import numpy as np


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\134\\D'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class D(Common):

    def resolve(self):

        box_num = int(self.input_data())
        remain = [int(i) for i in self.input_data().split()]

        boxes = np.zeros(box_num, dtype=np.int)
        for box in range(box_num, 0, -1):
            ball_num = 0
            for j in range(box-1, box_num, box):
                ball_num += boxes[j]
            if ball_num % 2 != remain[box-1]:
                boxes[box-1] = 1

        print(str(np.sum(boxes)))
        for i in range(box_num):
            if boxes[i] == 1:
                print(str(i+1), end=" ")


solver = D(REL_PATH)
solver.exec_resolve()

Submission status: Time Limit Exceeded

Solution code:
import glob
import numpy as np



# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\134\\D'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class D(Common):

    def resolve(self):

        box_num = int(self.input_data())
        remain = [int(i) for i in self.input_data().split()]

        boxes = np.zeros(box_num, dtype=np.int)
        for box in range(box_num, 0, -1):
            ball_num = np.sum(boxes[box-1::box])
            if ball_num % 2 != remain[box-1]:
                boxes[box-1] = 1

        print(str(np.sum(boxes)))
        for i in range(box_num):
            if boxes[i] == 1:
                print(str(i+1), end=" ")


solver = D(REL_PATH)
solver.exec_resolve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
moto = [int(i) for i in input().split()]
 
array=[0]*n
 
for i in reversed(range(1,n+1)):
  if sum(array[i-1::i])%2 != moto[i-1]:
    array[i-1] = 1
    
m = array.count(1)
ans = ""
for i in range(n):
  if array[i] == 1:
    ans = ans + str(i+1) + " "
print(m)
if ans != "":
  print(ans[:-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
moto = [int(i) for i in input().split()]
 
array=[0]*n
 
for i in reversed(range(1,n+1)):
  sum = 0
  for j in range(i,n+1,i):
    sum += array[j-1]
  if array[i-1] != (sum-moto[i-1])%2:
    array[i-1] = 1
    
m = array.count(1)
ans = ""
for i in range(n):
  if array[i] == 1:
    ans = ans + str(i+1) + " "
print(m)
if ans != "":
  print(ans[:-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
moto = [int(i) for i in input().split()]

array=[0]*n

for i in reversed(range(1,n+1)):
  sum = 0
  for j in range(i,n+1,i):
    sum += array[j-1]
  if array[i-1] != (sum-moto[i-1])%2:
    array[i-1] = 1

m = array.count(1)
ans = ""
cnt = 0
for a in array:
  cnt += 1
  if a == 1:
    ans = ans + str(cnt) + " "
print(m)
if ans != "":
  print(ans[:-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
moto = [int(i) for i in input().split()]

array=[0]*n

for i in reversed(range(1,n+1)):
  sum = 0
  for j in range(i,n+1,i):
    sum += array[j-1]
  if array[i-1] != (sum-moto[i-1])%2:
    array[i-1] = 1

m = array.count(1)
ans = ""
for i in range(n):
  if array[i] == 1:
    ans = ans + str(i+1) + " "
print(m)
if ans != "":
  print(ans[:-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
def input():
    return sys.stdin.readline()
n = int(input())
a = [int(i) for i 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)

  # divisors.sort()
  return divisors

ans = []
tmp = []
for i,x in enumerate(reversed(a)):
  y = n-i
  if x:
    ans.append(y)
    tmp = make_divisors(y)
    for j in tmp:
      a[j-1] ^= 1
      #print(a)
print(len(ans))
for i in reversed(ans):
  print(i,end=' ')

Submission status: Time Limit Exceeded

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

filled = [0]*(n+1)
ans = []
for i in range(n-1, -1, -1):
  if sum(filled[i:][::i+1]) % 2 != A[i]:
    filled[i] = 1
    ans.append(i+1)
print(len(ans))
print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

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

filled = [0 for _ in range(n)]
ans = []
for i in range(n-1, -1, -1):
  if sum(filled[i:][::i+1]) % 2 != A[i]:
    filled[i] = 1
    ans.append(i+1)
print(len(ans))
print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

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

filled = [0 for _ in range(n)]
ans = []
for i in range(n-1, -1, -1):
  if sum(filled[i:][::i+1]) % 2 != A[i]:
    filled[i] = 1
    ans.append(i+1)
print(len(ans))
if len(ans) > 0:
	print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    A = list(map(int, input().split()))

    filled = [0 for _ in range(n)]
    ans = []
    for i in range(n-1, -1, -1):
        if sum(filled[i:][::i+1]) % 2 != A[i]:
            filled[i] = 1
            ans.append(i+1)
    print(len(ans))
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    A = [int(x) for x in input().split()]

    filled = set()
    for i in range(n-1, -1, -1):
        count = 0
        for j in filled:
            if (j+1) % (i+1) == 0:
                count += 1
        if count % 2 != A[i]:
            filled.add(i)

    return len(filled), [i+1 for i in filled]



if __name__ == '__main__':
    m, output = main()
    if m == -1: print(str(m))
    else:
        print(str(m))
        if m > 0:
            print(' '.join(map(str, output)))

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    A = [int(x) for x in input().split()]

    m = 0
    B = [0 for _ in range(n)]

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

    for i in range(n//2, -1, -1):
        count = 0
        for j in range(n-1, -1, -1):
            if B[j] == 1: count += 1
        if count % 2 != A[i]:
            added = False
            for j in range(n):
                if (j+1) % (i+1) == 0 and B[j] == 0:
                    B[j] = 1
                    added = True
                    break
            if not added:
                return -1, -1

    output = []
    for i in range(n):
        if B[i] == 1:
            output.append(i+1)
    return len(output), output

if __name__ == '__main__':
    m, output = main()
    if m == -1: print(str(m))
    else:
        print(str(m))
        if m > 0:
            print(' '.join(map(str, output)))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(N):
    j = N-i
    count = 0
    k = j
    while k<N+1:
        if k in ans:
            count += 1
        k += j
    if count%2 != a[j-1]:
        ans.append(j)
print(len(ans))
ans = [str(x) for x in ans]
ans = ' '.join(ans)
print(ans)

Submission status: Time Limit Exceeded

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

blist=[0]*(N+1)
for i in reversed(range(1,N+1)):
  blist[i]^=alist[i]
  for j in range(2,N+1):
    if i%j==0:
      blist[i//j]^=blist[i]
    
#print(blist)
answer=sum(blist)
print(answer)
if answer>0:
  print(" ".join(["1"]*answer))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_ls = list(map(int,input().split(" ")))
N = [0]*N
l = len(a_ls)

# 大きい方からチェック
for i in range(l):
    a = a_ls[-(i+1)]
    s = sum(N[(l-i)-1::(l-i)])%2
    # print(s)
    # print(a)
    if a != s:
        N[-(i+1)]=1
        
sen = ""
for i,n in enumerate(N):
    if n == 1:
        sen += "{} ".format(i+1)

if len(sen) == 0:
    print(0)
else:
    print(sum(N))
    print(sen[:-1])

Submission status: Time Limit Exceeded

Solution code:
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

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

ansList = []
for i in range(len(A),0,-1):
    if(ANS[i-1]%2!=A[i-1]):
        tList = make_divisors(i)
        for j in tList:
            ANS[j-1]+=1
        ansList.append(i)
print(len(ansList))

for i in ansList:
    print(i, end=" ")

Submission status: Time Limit Exceeded

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

    divisors.sort()
    return divisors

N = int(input())
A = list(map(int, input().split()))
ANS = [0]*len(A)
sum=0
ansList = []
for i in range(len(A),0,-1):
    if(ANS[i-1]%2!=A[i-1]):
        tList = make_divisors(i)
        for j in tList:
            ANS[j-1]+=1
        ansList.append(i)
print(len(ansList))

for i in ansList:
    print(i, end=" ")

Submission status: Time Limit Exceeded

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

    divisors.sort()
    return divisors

N = int(input())
A = list(map(int, input().split()))
ANS = [0]*len(A)
sum=0
ansList = []
for i in range(len(A),0,-1):
    if(ANS[i-1]%2!=A[i-1]):
        tList = make_divisors(i)
        for j in tList:
            ANS[j-1]+=1
        sum+=1
        ansList.append(i)
ansList.sort()
#print("")
#print(A)
#print(ANS)
print(sum)
for i in ansList:
    print(i, end=" ")

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = list(map(int, input().split()))
ans = [0] * N

for i in reversed(range(1,N+1)):
    count = 0
    total = 0
    for j in range(i,N+1):
        if j % i == 0:
            count += 1
            # 既にfixされた数を加算
            total += ans[j-1]
    # 倍数が一つのとき
    if count == 1:
        if nums[i-1] == 0:
            ans[i-1] = 0
        else:
            ans[i-1] = 1
    # 倍数が複数ある
    else:
        # 指定が偶数
        if nums[i-1] == 0:
            if total % 2 != 0:
                ans[i-1] = 1
        else:
            if total % 2 == 0:
                ans[i-1] = 1


result = [i+1 for i in range(len(ans)) if ans[i] == 1]
result = [str(i) for i in result]
print(len(result))
print(" ".join(result))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
nums = list(map(int, input().split()))
ans = [0] * N

for i in reversed(range(1,N+1)):
    count = 0
    total = 0
    for j in range(i,N+1):
        if j % i == 0:
            count += 1
            # 既にfixされた数を加算
            total += ans[j-1]
    # 倍数が一つのとき
    if count == 1:
        if nums[i-1] == 0:
            ans[i-1] = 0
        else:
            ans[i-1] = 1
    # 倍数が複数ある
    else:
        # 指定が偶数
        if nums[i-1] == 0:
            if total % 2 != 0:
                ans[i-1] = 1
        else:
            if total % 2 == 0:
                ans[i-1] = 1


result = [i+1 for i in range(len(ans)) if ans[i] == 1]
result = [str(i) for i in result]
print(len(result))
print(" ".join(result))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0]+[int(x) for x in input().split()]
dp = [0]*(N+1)
res = 0
resstr = ''
for i in range(N):
    # 今見てるところ
    k = N-i
    if k < N//2:
        dp[k] = A[k]-sum([x for i,x in enumerate(dp[k+1:]) if i%k==0])%2
    else:
        dp[k] = A[k]
    if dp[k]==1:
        resstr = str(k)+' '+resstr
    res += dp[k]

print(res)
print(' '.join(resstr))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [0]+[int(x) for x in input().split()]
dp = [0]*(N+1)
res = 0
for i in range(N):
    # 今見てるところ
    k = N-i
    if k < N//2:
        dp[k] = A[k]-sum([x for i,x in enumerate(dp[k+1:]) if i%k==0])%2
    else:
        dp[k] = A[k]
    res += dp[k]

print(res)
print(' '.join([str(i) for i,x in enumerate(dp) if x==1]))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

ans = []
for i in range(n):
    ans.append(0)

for i in range(len(a)-1, -1, -1):
    k = 0
    for j in range(i, len(a), 1):
        if i > 0 and j % i == 0:
            k += ans[j]
    if a[i] != ans[j]:
        ans[i] = 1

print(ans.count(1))
for i in range(len(ans)):
    if ans[i] != 0:
        print(i+1)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
nums = list(map(int, input().split()))
box = []
memo = []

tmp = [0,1]
for balls in itertools.product(tmp, repeat=N):
    box.append(list(balls))

for x in range(len(box)):
    for i in range(1, N+1):
        total = 0
        for j in range(1, N+1):
            if j % i == 0:
                total += box[x][i-1]
        if nums[i-1] != total % 2:
            break
    else:
        memo = box[x]
        break
ans = []
count = 0
for i in range(len(memo)):
    if memo[i] == 1:
        count += 1
        ans.append(i+1)

print(count)
ans = [str(n) for n in ans]
ans = " ".join(ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = 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
ans = []
for i in reversed(range(n)):
    if li[i] == 1:
        ans.append(i+1)
        for j in make_divisors(i+1):
            li[j-1] = abs(li[j-1]-1)

if 1 in li:
    print(-1)
else:
    print(len(ans))
    if len(ans) > 0:
        print(" ".join(map(str, ans)) if len(ans) > 1 else ans[0])

Submission status: Time Limit Exceeded

Solution code:

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

tmp_ans = 0
for j in range(2 ** n):
    flag = True
    x = [int(y) for y in str(bin(j))[2:].zfill(n)]
    for i in range(n):
        if sum(x[i::i+1]) % 2 != a[i]:
            flag = False
            break
    if flag:
        tmp_ans = x
        break

if tmp_ans:
    m = sum(tmp_ans)
    b = [i+1 for i, y in enumerate(tmp_ans) if y == True]
    print(m)
    print(*b)
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

sys.setrecursionlimit(1 + 2 * 10 ** 5)

def check(s):
    for i in range(len(s)):
        if sum(s[i::i+1]) % 2 != A[i]:
            return False
    return True

def dfs(s=[]):
    if check(s):
        if len(s) == N:
            return s
        return dfs(s + [0])
    else:
        if len(s) == N:
            return None
        return dfs(s + [1])

if sum(A) == 0:
    print(0)
else:
    ret = dfs([0]) or dfs([1])
    if ret is None:
        print(-1)
    else:
        ans = []
        for i in range(len(ret)):
            if ret[i] == 1:
                ans.append(i+1)
        print(len(ans))
        if len(ans) > 0:
            print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

sys.setrecursionlimit(1 + 2 * 10 ** 5)

def check(s):
    for i in range(len(s)):
        if sum(s[i::i+1]) % 2 != A[i]:
            return False
    return True

def dfs(s=[]):
    if len(s) == N:
        if check(s):
            return s
        else:
            return None

    ret0 = dfs(s + [0])
    if ret0 is not None:
        return ret0

    ret1 = dfs(s + [1])
    if ret1 is not None:
        return ret1
    return None


if sum(A) == 0:
    print(0)
else:
    ret = dfs()
    if ret is None:
        print(-1)
    else:
        ans = []
        for i in range(len(ret)):
            if ret[i] == 1:
                ans.append(i+1)
        print(len(ans))
        if len(ans) > 0:
            print(*ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

B = np.array([0] * N)

for idx in range(N, 0, -1):
    a = A[idx - 1]

    q = N // idx

    target = [idx * i - 1 for i in range(2, q + 1)]
    r = sum(B[target]) % 2

    if a == 0:
        if r == 1:
            B[idx - 1] = 1
        else:
            B[idx - 1] = 0
    else:
        if r == 1:
            B[idx - 1] = 0
        else:
            B[idx - 1] = 1

g = sum(B)
print(g)

if g != 0:
    print(*list(np.where(B == 1)[0] + 1))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

B = np.array([0] * N)

for n in range(N):
    idx = N - n

    a = A[idx - 1]

    q = N // idx

    target = [idx * i - 1 for i in range(2, q + 1)]
    r = sum(B[target]) % 2

    if a == 0:
        if r == 1:
            B[idx - 1] = 1
        else:
            B[idx - 1] = 0
    else:
        if r == 1:
            B[idx - 1] = 0
        else:
            B[idx - 1] = 1

g = sum(B)
print(g)

if g != 0:
    print(*list(np.where(B == 1)[0] + 1))

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(10**9)

input = sys.stdin.readline

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

for i in reversed(range(N)):
    if A[i]:
        put.append(i + 1)

        tmp = 1
        n = i + 1
        while tmp * tmp <= n:
            if n % tmp == 0:
                A[tmp - 1] ^= 1
                if tmp != n // tmp:
                    A[n // tmp - 1] ^= 1
            tmp += 1

if len(put) > 0:
    print(len(put))
    print(*put)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(2 ** n):
  m = []
  for j in range(n):  # このループが一番のポイント
    if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
      m.append(1)  # フラグが立っていたら bag に果物を詰める
    else:
      m.append(0)

  flag = False
  for a in range(n):
    S = 0
    for b in range(n):
      if ((b+1) % (a+1)) == 0:
        S += m[b]
    if (S % 2) != l[a]:
      flag = True
      break
  if not flag:
    print(sum(m))
    if sum(m) == 0:
      exit()
    for a in range(n):
      if m[a] == 1:
        print("{} ".format(a+1),end="")
    exit()
print("-1")

Submission status: Time Limit Exceeded

Solution code:
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))


N = int(input())
A = [int(x) for x in input().split()]
A = [0] + A

R = []

dl = [[0] * (N + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
    cnt = 1
    while i * cnt <= N:
        dl[i][i * cnt] = 1
        cnt += 1

for i in range(N, 0, -1):
    if A[i] == 1:
        R.append(i)
        for j in range(i, 0, -1):
            A[j] = (A[j] + 1) % 2

print(len(R))
print(" ".join([str(i) for i in R]))

# print(R)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))

b_list = []
index = n
for i in range(n):
    # b_listにindexの倍数の数字が何個入っているか
    count = 0
    for b in b_list:
        if b % index == 0:
            count += 1

    if count % 2 != a_list[index-1]:
        b_list.append(index)
    index -= 1

print(len(b_list))
print(*b_list)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a_list = list(map(int, input().split()))

b_list = []
index = n
for i in range(n):
    # b_listにindexの倍数の数字が何個入っているか
    count = 0
    for b in b_list:
        if b % index == 0:
            count += 1

    if count%2 != a_list[index-1]:
        b_list.append(index)
    index -= 1

print(len(b_list))
if len(b_list) != 0:
    for b in b_list:
        print(b, end="")
        print(" ", end="")

Submission status: Time Limit Exceeded

Solution code:
def pbox(n,a):
    count = 0
    result = []
    for i in xrange(n):
        total = 0
        b = [a[j] for j in xrange(n) if (j+1)%(i+1) == 0]
#        print("i %d, b %s" %(i+1,b))
        total = sum(b)
#        print("a[i] %d, total %d" %(a[i],total))
        if total % 2 == 1 and a[i] % 2 == 1:
            result.append(i+1)
            count += 1
        else:
            pass

    m = len(result)
    print count
    for i in xrange(m):
        print result[i],

if __name__ == '__main__':
    n = int(raw_input())
    a = map(int,raw_input().split())

    pbox(n,a)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
a = [ int(x) for x in stdin.readline().rstrip().split()]

b = []

for i, x in enumerate(a[::-1], 1):
    t = n-i+1
    if len(b) == 0 and x == 1:
        b.append(t)
    elif sum([ y%t == 0 for y in b])%2 != x:
        b.append(t)

l = len(b)
print(l)
if l != 0:
    b_str = [str(x) for x in b[::-1]]
    print(" ".join(b_str))