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:
from sys import stdin


def main():
    N = int(input())
    a_lists = [int(x) for x in stdin.readline().rstrip().split()]

    for n in range(N-1, -1, -1):
        if N // (n+1) <= 2:
            pass
        else:
            n_multiple = [a_lists[x] for x in range(N) if (x+1) % (n+1) == 0]
            if (sum(n_multiple) % 2) == a_lists[n]:
                pass
            else:
                if a_lists[n] == 0:
                    a_lists[n] = 1
                else:
                    a_lists[n] = 0

    ansaer = [i+1 for i, x in enumerate(a_lists) if x == 1]

    print(len(ansaer))
    if len(ansaer) == 0:
        pass
    else:
        s = ' '.join([str(n) for n in ansaer])
        print(s)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def main():
    N = int(input())
    a_lists = [int(x) for x in stdin.readline().rstrip().split()]

    for n in range(N-1, -1, -1):
        n_multiple = [a_lists[x] for x in range(N) if (x+1) % (n+1) == 0]
        if (sum(n_multiple) % 2 ) == a_lists[n]:
            pass
        else:
            if a_lists[n] == 0:
                a_lists[n] = 1
            else:
                a_lists[n] = 0

    ansaer = [i+1 for i, x in enumerate(a_lists) if x == 1]
    
    print(len(ansaer))
    if len(ansaer) == 0:
        pass
    else:
        s = ' '.join([str(n) for n in ansaer])
        print(s)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(N):
	if sum(x % (N - i) for x in ans) != a[N - 1 - i]:
		ans.append(N - i)
print(len(ans))
Ans = [str(x) for x in ans]
print(' '.join(Ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
N = int(input())
A = list(map(int, input().split()))
result = np.zeros(N)
num = []
for i in range(N-1, -1, -1):
  if A[i] != np.sum(result[2*i+1::(i+1)]) % 2:
    result[i] = 1
    num.append(str(i+1))

print(int(np.sum(result)))
print(" ".join(num))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
N = int(input())
A = list(map(int, input().split()))
result = np.zeros(N)
num = []
for i in range(N-1, -1, -1):
  if A[i] != np.sum(result[i::(i+1)]) % 2:
    result[i] = 1
    num.append(str(i+1))

print(int(np.sum(result)))
print(" ".join(num))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
N = int(input())
A = list(map(int, input().split()))
index = np.arange(1, N+1)
result = np.zeros(N)
for i in range(N-1, -1, -1):
  if A[i] != np.sum(result[index%(i+1)==0]):
    result[i] = 1

print(int(np.sum(result)))
for i in result:
  if i == 1:
    print(1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [0] * n
ans = []
for i in range(n, 0, -1):
    multi_list = [j for j in range(1, n + 1, 1) if j % i == 0]
    for multi in multi_list:
        b[i - 1] = (b[i - 1] + a[multi - 1]) % 2
    if b[i - 1] == 1:
        ans.append(str(i))
if a == b:
    print(len(ans))
    if len(ans) > 0:
        print(" ".join(ans))
else:
    print("-1")

Submission status: Time Limit Exceeded

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


def returnResMod2(i):
    # i+1の倍数の箱のaiの和の剰余を求める
    res = sum([ansList[k] for k in range(N) if (k+1) % (i+1) == 0]) % 2
    return res


ansList = [0 for i in range(N)]
for i in range(N-1, -1, -1):
    tmp = (returnResMod2(i)+A[i]) % 2
    ansList[i] = tmp


M = sum(ansList)
print(M)
if M == 0:
    quit()
print(' '.join([str(i+1) for i, a in enumerate(ansList) if a == 1]))

Submission status: Time Limit Exceeded

Solution code:
import math
m = list(map(int, input().split()))[0]
a = list(map(int, input().split()))


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

    # divisors.sort()
    return divisors
  
b = [False for i in range(m)]
c = [False for i in range(m)]

for i in range(m):
    ii = m - i
    if(a[ii-1] != b[ii-1]):
        k = make_divisors(ii)
        for j in k:
            b[j-1] = not b[j-1]
        c[ii-1] = True
    #print("b",b)
    #print("c",c)
    #print()

ans = ""
count = 0
for i in range(m):
    if(c[i] == True):
        ans+= str(i+1) + " "
        count +=1
        
print(count)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]

B = []
for i in range(1, N+1)[::-1]:
    a = A[i-1]
    v = len(list(filter(lambda x: x % i == 0, B)))
    if v % 2 != a:
        B.append(i)

for i in range(1, N+1)[::-1]:
    a = A[i-1]
    v = len(list(filter(lambda x: x % i == 0, B)))
    if v % 2 != a:
        print(-1)
        exit(0)

print(len(B))
if B != []:
    print(" ".join([str(b) for b in B]))

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache, reduce
from operator import xor


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


# 右の箱から順に詰める
@lru_cache(maxsize=None)
def f(i):
    return reduce(
        xor,
        (f(j) for j in range(2 * i, N + 1, i)),
        a[i - 1]
    )


b = [i for i in reversed(range(1, N + 1)) if f(i)]
ans = (
    '0' if len(b) == 0 else
    '{}\n{}'.format(
        len(b),
        ' '.join(map(str, b))
    )
)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache, reduce
from operator import xor


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


# 右の箱から順に詰める
@lru_cache(maxsize=None)
def f(i):
    return reduce(
        xor,
        (f(j) for j in range(2 * i, N + 1, i)),
        a[i - 1]
    )


b = [i for i in range(1, N + 1) if f(i)]
ans = (
    '0' if len(b) == 0 else
    '{}\n{}'.format(
        len(b),
        ' '.join(map(str, b))
    )
)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
if sum(a)%2==0:
  ans=0
  anlis=[]
else:
  ans=1
  anlis=[1]
for i in range(1,n):
  li=[a[j] for j in range(n) if j%(i+1)==i]
  if sum(li)%2==1:
    ans+=1
    anlis.append(i+1)

print(ans)
for s in anlis:
  print(s, end =" ")

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = [0] * n
k = []
for i in range(n):
    for j in range(i, n):
        if (j+1) % (i+1) == 0:
            b[i] += a[j]
            b[i] = b[i] % 2
    if b[i] == 1:
        k.append(str(i+1))
if a == b:
    print(len(k))
    for kk in k:
        print(kk)
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

N = int(input())
A = list(map(int, input().split()))
que = deque([0]*N)
bn = 0
for i in range(N, 0, -1):
    nn = 0
    for j in range(2*i, N+1, i):
        nn += que[j-1]

    if nn % 2 != A[i-1]:
        que[i-1] = 1

M = sum(que)
print(sum(que))
if M != 0:
    ans = []
    flg = False
    for i, n in enumerate(que):
        if flg:
            print(' ', end='')
        if n == 1:
            print(i+1, end='')
        flg = True

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

N = int(input())
A = list(map(int, input().split()))
que = deque([0]*N)
bn = 0
for i in range(N, 0, -1):
    nn = 0
    for j in range(2*i, N+1, i):
        nn += que[j-1]

    if nn % 2 == A[i-1]:
        que[i-1] = 0
    else:
        que[i-1] = 1

M = sum(que)
print(sum(que))
if M != 0:
    ans = []
    for i, n in enumerate(que):
        if n == 1:
            ans.append(i+1)
    print(' '.join(map(str, ans)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [0 for i in range(n+1)]
a.reverse()
a.insert(0,0)
counter = 0
for i in range(1,n+1): #a[i]を見ている
    temp = 0
    for k in range(n+1-i,n+1): #b[k]を見ている
        if k % (n+1-i) == 0:
            temp += b[k]
    if temp%2 != a[i]:
        b[n+1-i] = 1
        counter += 1
print(counter)
for i in range(1,n+1):
    if b[i] == 1:
        if counter != 1:
            print(i,end= " ")
        else:
            print(i)
        counter -= 1

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
tmp=[]
ans=""
for i in range(n-1,-1,-1):
  num = i+1
  total=0
  for j in range(i,n):
    if (j+1)%(i+1)==0:
      total+=b[j]
  if total%2==a[i]:
    b[i]=0
  else:
    b[i]=1
    tmp.append(i+1)

print(sum(b))
tmp = sorted(tmp)

for i in range(len(tmp)):
  ans += str(tmp[i]) + " "
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
tmp=[]
ans=""
for i in range(n-1,-1,-1):
  num = i+1
  total=0
  for j in range(i,n):
    if (j+1)%(i+1)==0:
      total+=b[j]
  if total%2==a[i]:
    b[i]=0
  else:
    b[i]=1
    tmp.append(i+1)

print(sum(b))
tmp = sorted(tmp)

for i in range(len(tmp)):
  ans += str(tmp[i]) + " "
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[0]+[int(i) for i in input().split()]
m=0
ans=[]
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
for i in range(n,0,-1):
    if a[i]%2==1:
        m+=1
        ans.append(i)
        l=make_divisors(i)
        for j in l:
            a[j]+=1
print(m)
if ans!=[]:
    for i in range(m):
        if i!=m-1:
            print(ans[i],end=" ")
        else:
            print(ans[i])

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

box_num = int(input())
ball_in_box_num_list = tuple([int(i), []] for i in input().split(" "))
for i in range(1, box_num + 1):
    k = 2
    while i * k <= box_num:
        ball_in_box_num_list[i * k - 1][1].append(i - 1)
        k += 1
ans_num = 0
ans_list = []
for i in range(box_num):
    a = box_num - 1 - i
    b = ball_in_box_num_list[a]
    if b[0] == 1:
        ans_num += 1
        ans_list.append(a + 1)
        for j in b[1]:
            ball_in_box_num_list[j][0] = 1 - ball_in_box_num_list[j][0]
print(ans_num)
if ans_list != 0:
    ans_list = [str(i) for i in ans_list]
    ans_list = ans_list[::-1]
    print(" ".join(ans_list))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

box_num = int(input())
ball_in_box_num_list = [[int(i), []] for i in input().split(" ")]
for i in range(1, box_num + 1):
    k = 2
    while i * k <= box_num:
        ball_in_box_num_list[i * k - 1][1].append(i - 1)
        k += 1
ans_num = 0
ans_list = []
for i in range(box_num):
    a = box_num - 1 - i
    b = ball_in_box_num_list[a]
    if b[0] == 1:
        ans_num += 1
        ans_list.append(a + 1)
        for j in b[1]:
            ball_in_box_num_list[j][0] = 1 - ball_in_box_num_list[j][0]
print(ans_num)
if ans_list != 0:
    ans_list = [str(i) for i in ans_list]
    ans_list = ans_list[::-1]
    print(" ".join(ans_list))

Submission status: Time Limit Exceeded

Solution code:

n=int(input())
a=[int(i) for i in input().split()]
a.sort()
ans=[]
for i in range(1,n+1):
    if ans!=[]:
        break
    for j in [x for x in range(1,n+1)if x%i==0]:
        x=a.count(j)
        ans+=[j for i in range(x)]

cnt=len(ans)
if cnt>0:
    print(cnt)
    for i in ans:print(i)
else:
    print(0)

Submission status: Time Limit Exceeded

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

ans = -1

tf_li = []
b_li = []
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
tf_li = [True if i == 0 else False for i in li]

for i in reversed(range(0, n)):
    if tf_li[i] == False:
        b_li.append(i+1)
        for j in make_divisors(i+1):
            if tf_li[j-1]:
                tf_li[j-1] = False
            else:
                tf_li[j-1] = True

if False not in tf_li:
    print(len(b_li))
    print(" ".join(map(str, b_li)))
else:
    print("-1")

Submission status: Time Limit Exceeded

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

box = [0] * N
v = N // 2  # 後半部の最初のindex

for i in range(v, N):
    if ai[i] == 0:
        box[i] = 0
    else:
        box[i] = 1

for i in range(v - 1, -1, -1):
    s = [ai[x] == 1 for x in range(i + 1, N) if (x + 1) % (i + 1) == 0]
    cnt = s.count(True)
    if cnt & 1 == 1:
        box[i] = 0 if ai[i] & 1 == 1 else 1
    else:
        box[i] = 0 if ai[i] & 1 == 0 else 1

print(box.count(1))
for x in box:
    if x == 1:
        print(x)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = map(int, input().split())
a = [0] + list(a)
b = [0] * (N+1)
result_str = ''

for i in range(N, 0, -1):
  i_sum = sum(b[i::i])
  if i_sum % 2 != a[i]:
    b[i] = 1
    result_str = '{} '.format(i) + result_str

print(sum(b))
print(result_str[:-1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = map(int, input().split())
a = [0] + list(a)
b = [0] * (N+1)
result_str = ''

for i in range(N, 1, -1):
  i_sum = 0
  for j in range(1, N//i + 1):
    i_sum += b[j*i]
  if i_sum % 2 != a[i]:
    b[i] = 1
    result_str = '{} '.format(i) + result_str

i = 1
i_sum = sum(b)
if i_sum % 2 != a[i]:
  b[i] = 1
  result_str = '{} '.format(i) + result_str


print(sum(b))
print(result_str[:-1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = map(int, input().split())
a = [0] + list(a)
b = [0 for i in range(N+1)]
result_str = ''

for i in range(N, 0, -1):
  i_sum = 0
  for j in range(1, N // i + 1):
    i_sum += b[j*i]
  if i_sum % 2 != a[i]:
    b[i] = 1
    result_str = '{} '.format(i) + result_str
    
print(sum(b))
print(result_str[:-1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = map(int, input().split())
a = [0] + list(a)
b = [0 for i in range(N+1)]

for i in range(N, 0, -1):
  i_sum = 0
  for j in range(1, N // i + 1):
    i_sum += b[j*i]
  if i_sum % 2 != a[i]:
    b[i] = 1
  
print(sum(b))
result_str = ''
for i in range(i, N+1):
  if b[i] == 1:
    result_str += '{} '.format(i)
print(result_str[:-1])

Submission status: Time Limit Exceeded

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

def f(n,m):
  tmp=[]
  for i in range(n,m+1):
    if i%n==0:
      tmp.append(i)
  return tmp
def ff(arr_1):
  tmp=0
  for i in arr_1:
    tmp+=b[i-1]
  tmp = tmp%2
  return tmp
b = [0]*n
for i in range(n-1,-1,-1):
  num = f(i+1,n)
  if len(num)==1:
    b[i] = a[i]
  else:
    if ff(num[1:])==a[i]:
      b[i]=0
    else:
      b[i]=1
print(sum(b))
ans=""
for i in range(n):
  if b[i]==1:
    ans+=str(i+1)+" "
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = [0]*N
    B=[]
    ans_str = ""
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i, N+1, i):
            if ans[j-1] == 1:
                cons += 1
        if A[i-1] == 1 and cons % 2 == 0:
            ans[i-1] = 1
            B.append(i)
            continue
        if A[i-1] == 0 and cons % 2 == 1:
            ans[i-1] = 1
            B.append(i)
            continue
            
    print(len(B))
    for i in B:
        ans_str = ans_str + str(i) + " "
    print(ans_str)
    #print(*B)
            	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = [0]*N
    B=[]
    ans_str = ""
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i, N+1, i):
            if ans[j-1] == 1:
                cons += 1
        if A[i-1] == 1 and cons % 2 == 0:
            ans[i-1] = 1
            B.append(i)
            ans_str = ans_str + str(i) + " "
            continue
        if A[i-1] == 0 and cons % 2 == 1:
            ans[i-1] = 1
            B.append(i)
            ans_str = ans_str + str(i) + " "
            continue
            
    print(len(B))
    print(ans_str)
            	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = [0]*N
    ans_cnt = 0
    ans_str = ""
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i, N+1, i):
            cons ^= ans[j-1]
        if A[i-1] != cons:
            ans[i-1] = 1
            ans_cnt += 1
            ans_str = ans_str + str(i) + " "
            continue
        if A[i-1] != cons:
            ans[i-1] = 1
            ans_cnt += 1
            ans_str = ans_str + str(i) + " "
            continue
            
    print(ans_cnt)
    print(ans_str)
            	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-


# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = [0 for i in range(N)]
    ans_cnt = 0
    ans_str = ""
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i, N+1, i):
            cons ^= ans[j-1]
        if A[i-1] != cons:
            ans[i-1] = 1
            ans_cnt += 1
            ans_str = ans_str + str(i) + " "
            continue
        if A[i-1] != cons:
            ans[i-1] = 1
            ans_cnt += 1
            ans_str = ans_str + str(i) + " "
            continue
            
    print(ans_cnt)
    print(ans_str)
            	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = [0 for i in range(N)]
    ans_cnt = 0
    ans_str = ""
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i, N+1, i):
            cons ^= ans[j-1]
        if A[i-1] != cons:
            ans[i-1] = 1
            ans_cnt += 1
            ans_str = ans_str + str(i) + " "
            continue
        if A[i-1] != cons:
            ans[i-1] = 1
            ans_cnt += 1
            ans_str = ans_str + str(i) + " "
            continue
            
    print(ans_cnt)
    print(ans_str)
            	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = [0 for i in range(N)]
    ans_cnt = 0
    ans_str = ""
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i, N+1, i):
            cons ^= ans[j-1]
        if A[i-1] == 1 and cons % 2 == 0:
            ans[i-1] = 1
            ans_cnt += 1
            ans_str = ans_str + str(i) + " "
            continue
        if A[i-1] == 0 and cons % 2 == 1:
            ans[i-1] = 1
            ans_cnt += 1
            ans_str = ans_str + str(i) + " "
            continue
            
    print(ans_cnt)
    print(ans_str)
            	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = [0 for i in range(N)]
    ans_cnt = 0
    ans_str = ""
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i*2, N+1, i):
            if ans[j-1] == 1:
                cons += 1
        if A[i-1] == 1 and cons % 2 == 0:
            ans[i-1] = 1
            ans_cnt += 1
            ans_str = ans_str + str(i) + " "
            continue
        if A[i-1] == 0 and cons % 2 == 1:
            ans[i-1] = 1
            ans_cnt += 1
            ans_str = ans_str + str(i) + " "
            continue
            
    print(ans_cnt)
    print(ans_str)
            	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = [0 for i in range(N)]
    ans_cnt = 0
    ans_str = ""
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i, N+1, i):
            if ans[j-1] == 1:
                cons += 1
        if A[i-1] == 1 and cons % 2 == 0:
            ans[i-1] = 1
            ans_cnt += 1
            ans_str = ans_str + str(i) + " "
            continue
        if A[i-1] == 0 and cons % 2 == 1:
            ans[i-1] = 1
            ans_cnt += 1
            ans_str = ans_str + str(i) + " "
            continue
            
    print(ans_cnt)
    print(ans_str)
            	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    A = inputList()
    
    ans = []
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i, N+1, i):
            if j in ans:
                cons += 1
        if A[i-1] == 1 and cons % 2 == 0:
            ans.append(i)
            continue
        if A[i-1] == 0 and cons % 2 == 1:
            ans.append(i)
            continue
            
    print(len(ans))
    print(*ans)
            	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    N = int(input())
    A = input().split()
    
    ans = set()
    ans_str = ""
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i, N+1, i):
            if j in ans:
                cons += 1
        if A[i-1] == "1" and cons % 2 == 0:
            ans.add(i)
            ans_str = ans_str + str(i) + " "
            continue
        if A[i-1] == "0" and cons % 2 == 1:
            ans.add(i)
            ans_str = ans_str + str(i) + " "
            continue
            
    print(len(ans))
    print(ans_str)
            	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = map(int, input().split())
a = [0] + list(a)
b = [0 for i in range(N+1)]

for i in range(N, 0, -1):
  i_sum = 0
  for j in range(1, N // i + 1):
    i_sum += b[j*i]
  if i_sum % 2 != a[i]:
    b[i] = 1
  
print(sum(b))
result_str = ''
for i in range(i, N+1):
  if b[i] == 1:
    result_str += '{} '.format(i)
print(result_str[:-1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    N = int(input())
    A = input().split()
    
    ans = []
    ans_str = ""
    for i in range(N, 0, -1):
        cons = 0
        for j in range(i, N+1, i):
            if j in ans:
                cons += 1
        if A[i-1] == "1" and cons % 2 == 0:
            ans.append(i)
            ans_str = ans_str + str(i) + " "
            continue
        if A[i-1] == "0" and cons % 2 == 1:
            ans.append(i)
            ans_str = ans_str + str(i) + " "
            continue
            
    print(len(ans))
    print(ans_str)
            	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ball = [0 for i in range(n)]
count = 0 #ボールが入ってる箱の数
index = [] #ボールが入ってる番号

for i in range(n-1, -1, -1):
    balls = 0
    for j in [k for k in range(i,n) if (k+1)%(i+1)]:
        balls += ball[j]
    if a[i] != balls%2:
        a[i] = 1
        count += 1
        index.append(i+1)
        
ans = ""
for i in range(len(index)):
    if i < len(index)-1:
        ans += str(index[i]) + " "
    else:
        ans += str(index[i])
print(count)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
ball = [0 for i in range(n)]
count = 0 #ボールが入ってる箱の数
index = [] #ボールが入ってる番号

for i in range(n-1, n//2 - 1, -1):
    if a[i] == 1:
        ball[i] = 1
        count += 1
        index.append(i+1)
for i in range(n//2 - 1, -1, -1):
    balls = 0
    for j in [k for k in range(n//2, n) if (k+1)%(i+1)]:
        balls += ball[j]
    if a[i] != balls%2:
        a[i] = 1
        count += 1
        index.append(i+1)
        
ans = ""
for i in range(len(index)):
    if i < len(index)-1:
        ans += str(index[i]) + " "
    else:
        ans += str(index[i])
print(count)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import numpy as np

N = int(input())

A = list(map(int,input().split()))
B = A
ct = 0

for i in range(N):
    j = N-i-1
    if(j+1>N/2):
        B[j] = A[j]
        if(B[j]==1):
            ct = ct + 1
    else:
        for k in range(j+1,N):
            sum = 0
            if(k%(j+1)==0 and k!=j):
                sum = sum + B[k];
        if(sum%2==0):
            B[j] = A[j]
            if(B[j]==1):
                ct = ct + 1
        else:
            B[j] = 1 - A[j]
            if(B[j]==1):
                ct = ct + 1

print(ct)
C = []

for i in range(N):
    if(B[i]==1):
        C.append(i+1)
print(*C)