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: Runtime Error

Solution code:
N = int(input())
arr = map(int, input().split(' '))
ans = [0 for x in range(N)]
for i in reversed(range(N)):
  n = i + 1
  if i > N/2.0:
    ans[i] == 0:
  else:
    s = 0
  	for k in reversed(range(1, N // n)):
    	index = n*k - 1
        s += arr[index]
    if s % 2 == arr[i]:
      ans[i] = 0
    else:
      ans[i] = 1
    	
ans_arr = []
for i in ans:
  if ans == 1:
    ans_arr.append(i)

print(sum(ans))
print(' '.join(ans_arr))

Submission status: Runtime Error

Solution code:
N = int(input())
arr = map(int, input().split(' '))
ans = [0 for x in range(N)]
for i in reversed(range(N)):
  n = i + 1
  if i > N/2.0:
    ans[i] == 0:
  else:
    s = 0
  	for k in reversed(range(1, N // n)):
    	index = n*k - 1
        s += arr[index]
    if s % 2 == arr[i]:
      arr[i] = 0
    else:
      arr[i] = 1
    	
ans_arr = []
for i in ans:
  if ans == 1:
    ans_arr.append(i)

print(sum(ans))
print(' '.join(ans_arr))

Submission status: Runtime Error

Solution code:
import sys

N = int(input())
Atmp = [0] + list(map(int, input().split()))
A = {}

for i,a in enumerate(Atmp):
    A[i] = a

#print(A)

X = {}

for i in reversed(list(range(1,N+1))):
    Xsum = 0
    j = 2
    while(i*j =< N):
        Xsum += X[i*j]
        j += 1
        continue
    odd = Xsum % 2
    if odd == A[i]:
        X[i] = 0
    else:
        X[i] = 1
    



def umeru(X, M, last):
    #print('---')
    for i in reversed(list(range(N//(M+1)+1, N//M+1))):
        if M == 1:
            X[i] = A[i]
        else:
            Xsum = 0
            j = 2
            while(i*j < N):
                Xsum += X[i*j]
                j += 1
                continue
            odd = Xsum % 2
            #print(M, i, odd, A[i])
            if odd == A[i]:
                X[i] = 0
            else:
                X[i] = 1
    #print(N,M,X)
    if last:
        return
    if N//(M+1) == 0:
        umeru(X, M+1, True)
    else:
        umeru(X, M+1, False)

#umeru(X, 1, False)
#print(X)

M = 0
for i in range(1, N+1):
    if X[i] == 1:
        M += 1

print(M)
if M == 0:
    sys.exit()

xxx = []
for i in range(1, N+1):
    if X[i] == 1:
        xxx.append(str(X[i]))

print(' '.join(xxx))

Submission status: Runtime Error

Solution code:
N = int(input())
a = []
b = []
n = 1
a = list(map(int,input().split()))

if a[0] == 0:
    print(0)
    exit(0)

b.append(set((range(1, N+1, 1))))
for i in range(1, N):
    if a[i] == 1:
        b.append(set((range(0, N+1, i+1))))
        b[n].pop()
        n = n + 1
        
if len(b) == 1:
    print(1)
    exit(0)
for i in range(0, n-1):
    b[i+1] = b[i] & b[i+1]

print(len(b[n-1]))
s = str(b[n-1].pop())
for i in range(1, len(b[n-1])+1):
    s += " " + str(b[n-1].pop())     
print(s)

Submission status: Runtime Error

Solution code:
N = int(input())
a = []
b = []
n = 1
a = list(map(int,input().split()))

if a[0] == 0:
    print(0)
    exit(0)

b.append(set((range(1, N+1, 1))))
for i in range(1, N):
    if a[i] == 1:
        b.append(set((range(0, N+1, i+1))))
        b[n].pop()
        n = n + 1
        
for i in range(0, n-1):
    b[i+1] = b[i] & b[i+1]

print(len(b[n-1]))
s = str(b[n-1].pop())
for i in range(1, len(b[n-1])+1):
    s += " " + str(b[n-1].pop())     
print(s)

Submission status: Runtime Error

Solution code:
n = int(input())
a = input()
r = [None] * (n + 1)
for i in range(n, 0, -1):
    r[i] = (ord(a[2 * i - 1]) + sum(r[i * 2::i])) % 2
print(r.count(1))
print(*(i for i, x in enumerate(r) if x))

Submission status: Runtime Error

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

ball = [0] * N

for i in range(N-1, -1, -1) :
    bit = A[i]
    for j in range(i + 1, N) :
        bit = (ball + ball[i]) % 2
    ball[i] = bit % 2

print(*ball)

Submission status: Runtime Error

Solution code:
import sys

N = int(input())
Atmp = [0] + list(map(int, input().split()))
A = {}

for i,a in enumerate(Atmp):
    A[i] = a

#print(A)

X = {}

for i in reversed(list(range(1,N+1))):
    Xsum = 0
    j = 2
    while(i*j < N):
        Xsum += X[i*j]
        j += 1
        continue
    odd = Xsum % 2
    if odd == A[i]:
        X[i] = 0
    else:
        X[i] = 1
    



def umeru(X, M, last):
    #print('---')
    for i in reversed(list(range(N//(M+1)+1, N//M+1))):
        if M == 1:
            X[i] = A[i]
        else:
            Xsum = 0
            j = 2
            while(i*j < N):
                Xsum += X[i*j]
                j += 1
                continue
            odd = Xsum % 2
            #print(M, i, odd, A[i])
            if odd == A[i]:
                X[i] = 0
            else:
                X[i] = 1
    #print(N,M,X)
    if last:
        return
    if N//(M+1) == 0:
        umeru(X, M+1, True)
    else:
        umeru(X, M+1, False)

#umeru(X, 1, False)
#print(X)

M = 0
for i in range(1, N+1):
    if X[i] == 1:
        M += 1

print(M)
if M == 0:
    sys.exit()

xxx = []
for i in range(1, N+1):
    if X[i] == 1:
        xxx.append(X[i])

print(' '.join(xxx))

Submission status: Runtime Error

Solution code:
N = int(input())
aN = [ int(i) for i in input().split() ]
aN.reverse()
bN = []

for a in aN:
    if len([b for b in bN if b%N == 0])%2 == a:
        pass
    else:
        bN.append(N)
    N -= 1

print(len(bN))
print(' '.join(bN))

Submission status: Runtime Error

Solution code:
import sys
import math

def add_ball(idx):
    add_list = [idx]
    if idx > 1:
        for j in range(2, int(math.sqrt(idx))+1):
            if idx%j == 0:
                add_list.append(j)
                if j != idx//i:
                    add_list.append(idx//j)
    for k in add_list:
        b_list[k-1] = (b_list[k-1]+1)%2

if __name__ == "__main__":
    input = sys.stdin.readline

    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = [0] * n
    for i, a in enumerate(a_list[::-1]):
        if a != b_list[-i-1]:
            add_ball(n-i)
    ball_sum = sum(b_list)
    ball_list = [i+1 for i, b in enumerate(b_list) if b == 1]
    print(ball_sum)
    if ball_sum > 0:
        print(' '.join(map(str, ball_list)))

Submission status: Runtime Error

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

for i in range(n-1, (n-1)//2, -1):
    ball.insert(0, a[i])
for i in range((n-1)//2, -1, -1):
    for j in range(len(ball)):
        if (j+1) % (i+1) == 0:
            s += ball[j]

    s = s % 2
    if a[i] == s:
        ball.insert(0, 0)
    else:
        ball.insert(0, 1)
ans = ""
for i in range(n):
    if ball[i] == 1:
        ans += " " + str(i)
    elif i == 1 and ans == "":
        print("0")

Submission status: Runtime Error

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

lst = [0 for _ in range(n)]
for x in range(n) :
    if a[x] == 1 :
        for i in range(x//2) :
            if x%i == 0 :
                lst[i] ^= 1
        lst[x] ^= 1

b = 0
print(sum(lst))
for i, x in enumerate(lst, 1) :
    if x == 1 :
        print(i, end=" ")
        b = 1
if b == 1 :
    print()

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
res = [0] + a[:]
 
for i in range(n, 0, -1):
    ans[i] = sum(ans[i : : i]) % 2 
print(sum(res))
print(*[i + 1 for i in range(n) if res[i]])

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
res = a[:]
 
for i in range(n, 0, -1):
    ans[i] = sum(ans[i : : i]) % 2 
print(sum(res))
print(*[i + 1 for i in range(n) if res[i]])

Submission status: Runtime Error

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

lst = [0 for _ in range(n)]
for x in range(n) :
    if a[x] == 1 :
        for i in range(x//2) :
            if x%i == 0 :
                lst[i] ^= 1
        lst[x] ^= 1


print(sum(lst))
for i, x in enumerate(lst, 1) :
    if x == 1 :
        print(i, end=" ")
print()

Submission status: Runtime Error

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

ans=[]
for i in range(n,n//2,-1):
  if li[i]==1:
    ans.append(i+1)

for i in range(n//2,0,-1):
  count=0
  for j in ans:
    if j%i==0:
      count+=1
  count+=li[i-1]
  if count%2==1:
    ans.append(i)
ans.reverse()
print(len(ans))
L=[str(a) for a in ans]
L=" ".join(L)
if len(L)!=0:
  print(L)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
B = []
BB = []
for k in range(N):
  i = k+1
  p = 10-k
  C = B
  B = [0]
  B.extend(C)
  if sum(B[0::p])% 2 != a[p-1]:
    B[0] = 1
print(len(BB))
print(*BB)

Submission status: Runtime Error

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

def sol(i,want):
    num=int(N/(i+1))
    wa=-A[0]
    for j in range(num):
        wa+=A[i+j*i]
    wa=wa%2
    if wa==want:
        x=0
    else:
        x=1
#     print(num)
    return x 

B=A[:]
for i in range(half):
    j=half-1-i
#     print(j)
    B[j]=sol(j,A[j])
m=sum(B)
print(m)
for i in range(N):
    if B[i]==1:
        print(i+1)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
for i in range(N//2 + 1):
    j = N//2 - i + 1
    su = 0
    if A[j] == 1:
        for k in range(N//j):
            su += A[k*j + j-1]
        if su == 1:
            A[j] = 0
        elif su > 1:
            print(-1)
            exit(1)
    elif A[j] == 0:
        for k in range(N//j):
            su += A[k*j + j-1]
        if su > 1:
            print(-1)
            exit(1)

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

Submission status: Runtime Error

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

a.insert(0, 0)
b.insert(0, 0)

n = int(N/2)

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

    for ii in range(2, int(N/i)):
        nums += b[i*ii - 1]

    if nums % 2 != a[i]:
        b[i] += 1

sum_b = sum(b)
print(sum_b)

flag = True
for i, bb in enumerate(b):
    if i == 0:
        continue

    if bb != 0:
        flag = False
        print(i, end=' ')

if flag:
    print()

Submission status: Runtime Error

Solution code:
import sys


def main():
    _ = int(input())
    A = list(map(int,input().split()))

    M = set()
    lenA = len(A)
    for i in range(len(A))[::-1]:
        if i > lenA/2:
            if A[i] == 1:
                M.add(i+1)
        else:
            bai = [x*(i+1) for x in range(1, int(lenA/(i+1))+1)]
            num = len(M&bai) % 2
            if A[i] != num:
                M.add(i+1)
    
    print(len(M))
    if len(M) > 0:
        print(*M)

if __name__=='__main__':
    main()

Submission status: Runtime Error

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()))

b = []
for _ in range(N):
    b.append(0)

ans = []

for i in range(2,(N // 2) + 2):
  min = (N // i) + 1
  max = N // (i - 1)
  
  if min <= max:

    for j in range(min - 1,max):
      if a[j] % 2 != b[j] % 2:
        ans.append(j + 1)
        make_divisors(j + 1)
        for k in divisors:
          b[k - 1] = b[k - 1] + 1

          
if a[0] % 2 == b[0] % 2:
  print(len(ans))
  print(ans)

else:
  ans.append(1)
  print(len(ans))
  print(ans)

Submission status: Runtime Error

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

def sol(i,want):
    num=int(N/(i+1))
    wa=-A[0]
    for j in range(num):
        wa+=A[i+j*i]
    wa=wa%2
    if wa==want:
        x=0
    else:
        x=1
#     print(num)
    return x 

B=A[:]
for i in range(half):
    j=half-1-i
#     print(j)
    B[j]=sol(j,A[j])
print(sum(B))
ans=''
for b in B:
    ans+=str(b)+ ' '
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
from collections import deque
import numbers as np
import math


def isPrime(x):
    if x < 2:
        return True
    elif x == 2:
        True
    elif x % 2 == 0:
        False

    for i in range(1, int(math.sqrt(x))+1):
        if x % i == 0:
            return False

    return True


def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = a[:]
    prime_list = deque()

    for i in range(1, N+1):
        if isPrime(i):
            prime_list.appendleft(i)

    for i in reversed(range(N//2 - 1)):
        a_t = a[i]
        t_sum = 0
        for prime in prime_list:
            ids = prime * (i+1)
            if N >= ids:
                t_sum += b[ids-1]
        guuki = t_sum % 2
        if a_t == 1 and guuki == 0:
            b[i] = 1
        elif a_t == 0 and guuki == 0:
            b[i] = 0
        elif a_t == 1 and guuki == 1:
            b[i] = 0
        elif a_t == 0 and guuki == 1:
            b[i] = 1
    cnt = 0
    ret = deque()
    for i in range(N):
        if b[i] > 0:
            cnt += 1
            ret.appendleft(i + 1)
    print(cnt)
    for i in ret:
        print(i, end=' ')
        if i == ret - 1:
            print()


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

def main():
    _ = int(input())
    A = list(map(int,input().split()))

    M = set()
    lenA = len(A)
    for i in range(len(A))[::-1]:
        if i > lenA/2:
            if A[i] == 1:
                M.add(i+1)
        else:
            bai = [x*(i+1) for x in range(lenA/(i+1))]
            num = len(M&bai) % 2
            if A[i] != num:
                M.add(i+1)
    
    print(len(M))
    if len(M) > 0:
        print(*M)

if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
B = []
BB = []
for k in range(N):
  i = k+1
  p = 10-k
  B.append(0)
  if sum(B[i::-p])% 2 != a[k-1]:
    B[k] = 1
    BB.append(k)
print(len(BB))
print(*BB)

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())

c = []
for i in range(N):
    n = int(input())
    index = bisect.bisect_left(c,n)
    if index == 0:
        c.append(n)
    else:
        c[index-1] = n
    c.sort()
    #print(c)

print(len(c))

Submission status: Runtime Error

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

lst = [0 for _ in range(n)]
for x in range(n) :
    if a[x] == 1 :
        for i in range(x//2) :
            if x%i == 0 :
                lst[i] ^= 1
        lst[x] ^= 1

print(sum(lst))
print(" ".join(list(map(str, lst))))

Submission status: Runtime Error

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

def sol(i,want):
    num=int(N/(i+1))
    wa=-A[0]
    for j in range(num):
        wa+=A[i+j*i]
    wa=wa%2
    if wa==want:
        x=0
    else:
        x=1
#     print(num)
    return x 

B=A[:]
for i in range(half):
    j=half-1-i

    B[j]=sol(j,A[j])
    
print(sum(B))
for b in B:
    print(b)

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
B = []
BB = []
for k in range(N):
  i = k+1
  p = 10-k
  B.append(0)
  if sum(B[i::p])% 2 != a[p-1]:
    B[k] = 1
    BB.append(k)
print(len(BB))
print(*BB)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
a = []
b = []
n = 0
a = list(map(int,input().split()))

if a[0] == 0:
    print(0)
    exit(0)

for i in range(0, N):
    if a[i] == 1:
        b.append(set((range(0, N+1, i+1))))
        n = n + 1
        
b[n-1].pop()
for i in range(0, n-1):
    b[i+1] = b[i] & b[i+1] 
    
print(len(b[n-1]))
s = "" + str(b[n-1].pop())
for i in range(len(b[n-1])):
    s += " " + str(b[n-1].pop())

print(s)

Submission status: Runtime Error

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

def sol(i,want):
    num=int(N/(i+1))
    wa=-A[0]
    for j in range(num):
        wa+=A[i+j*i]
    wa=wa%2
    if wa==want:
        x=0
    else:
        x=1
#     print(num)
    return x 

B=A[:]
for i in range(half):
    j=half-1-i
#     print(j)
    B[j]=sol(j,A[j])
print(sum(B))
for b in B:
    print(b)

Submission status: Runtime Error

Solution code:
import fractions
from collections import deque
import numbers as np
import math


def isPrime(x):
    if x < 2:
        return True
    elif x == 2:
        True
    elif x % 2 == 0:
        False

    for i in range(int(sqrt(x))):
        if x % i == 0:
            return False

    return True


def main():
    N = int(input())
    a = [int(input()) for _ in range(N)]
    b = a[:]
    prime_list = deque()

    for i in range(1, N+1):
        if isPrime(i):
            prime_list.appendleft(i)

    for i in reversed(range(N//2 - 1)):
        a_t = a[i]
        t_sum = 0
        for prime in prime_list:
            ids = prime * (i+1)
            if N >= ids:
                t_sum += b[ids-1]
        guuki = t_sum % 2
        if a_t == 1 and guuki == 0:
            b[i] = 1
        elif a_t == 0 and guuki == 0:
            b[i] = 0
        elif a_t == 1 and guuki == 1:
            b[i] = 0
        elif a_t == 0 and guuki == 1:
            b[i] = 1
    cnt = 0
    ret = deque()
    for i in range(N):
        if b[i] > 0:
            cnt += 1
            ret.appendleft(i + 1)
    print(cnt)
    for i in ret:
        print(i, end=' ')


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int,input().split()))
R = []
info = []

for i in range(N):
  q, mod = divmod(N, i+1)
  if mod == 0:
    if q == 1:
      if A[i] == 1:
        R.append(i+1)
    if q >= 2:
      for j in range(q):
        info.append(A[(i+1)*(j+1)-1])
      l = len(info) % 2
      if A[i] == l:
        R.append(i+1)
  else:
    R.append(i+1)
if len(R) >= 1:
  print(len(R))
  print(' '.join(R))
else:
  print(0)

Submission status: Runtime Error

Solution code:
N = int(input())    
color_list =  [int(input())]
for i in range(N-1):
    new_value = int(input())
    if(new_value > color_list[0]):
        color_list[0] = new_value
    elif(new_value <= color_list[-1]):
        color_list.append(new_value)
    else:
        for i in range(len(color_list)):
            break
print(len(color_list))

Submission status: Runtime Error

Solution code:
from math import ceil
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))
b = ['0'] * (n+1)
c = ceil((n+1)/2)-1
for i in range(c, n):
    if a[i] == 1:
        b[i+1] = '1'
    else:
        b[i+1] = '0'
    
for i in reversed(range(0, c)):
    d = n // (i+1)
    cn = 0
    for j in range(1, d+1, i+1):
        if b[j] == '1':
            cn += 1
    if cn % 2 == a[i]:
        b[i+1] = '0'
    else:
        b[i+1] = '1'
print(b.count('1'))
del b[0]
ee = []
for i,v in enumerate(b):
    if v == '1':
        ee.append(i)
print(' '.join(ee))

Submission status: Runtime Error

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

def sol(i,want):
    num=int(N/(i+1))
    wa=-A[0]
    for j in range(num):
        wa+=A[i+j*i]
    wa=wa%2
    if wa==want:
        x=0
    else:
        x=1
#     print(num)
    return x 

B=A[:]
for i in range(half):
    j=half-1-i
    print(j)
    B[j]=sol(j,A[j])
print(sum(B))
for b in B:
    print(b)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N=int(input())
a=list(map(int,input().split()))
seta=set()

for i in range(N//2,N):
    if a[i]==1:
        seta.add(i)
        
for i in range(3,N+1):
    if N//i<N//(i-1):
        for j in range(N//i+1,N//(i-1)+1):
            m=2
            asum=0
            while j*m<=N:
                if j*m-1 in seta:
                    asum=asum+1
                m=m+1
            if asum%2!=a[j-1]:
                seta.add(j-1)
    else:
        j=N//i
        m=2
        asum=0
        while j*m<=N:
            if j*m-1 in seta:
                asum=asum+1
            m=m+1
        if asum%2!=a[j-1]:
            seta.add(j-1)

print(len(seta))
print(" ".join(list(seta)))

Submission status: Runtime Error

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

box = [0] * n
m = 0
b = set()

for i in range(n)[::-1]:
    if i > n//2:
        if a[i] == 1:
            box[i] = 1
            m += 1
            b.add(i)
    else:
        num = 0
        for j in range(i, n, i):
            num += box[j]
        num %= 2
        if num != a[i]:
            box[i] = 1
            m += 1
            b.add(i)
    
print(m)
for i in list(b):
    print(i + ' ')

Submission status: Runtime Error

Solution code:
def make_divisors(n: int) -> list:
    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 = [int(i) for i in input().split()]

ans = []
for i in reversed(range(N)):
    if A[i] == 1:
        ans.append(i + 1)
        divisors = make_divisors(i + 1)
        for j in divisors:
            A[j + 1] = (A[j + 1] + 1) % 2

if A.count(1) != 0:
    print(len(ans))
    for i in reversed(range(len(ans))):
        print(ans[i])
else:
    print(-1)

Submission status: Runtime Error

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

ms = np.arange(1, M + 1)
multiple = dict()
for i in range(0, M):
    multiple[i] = np.where(np.mod(ms, i + 1) == 0)

prime = np.zeros(M, dtype=np.int)

ans = list()
for i in range(M - 1, -1, -1):
    p = prime[multiple[i]]
    if sum(prime[multiple[i]]) % 2 < a[i]:
        prime[i] = 1

    if sum(prime[multiple[i]]) % 2 != a[i]:
        print('-1')
        exit()

    
print(np.where(prime == 1))

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    
    
B = []
B.append(A[0])
pre = A[0]
cnt = 0
for i in range(1, N):
    if A[i] > B[cnt] and A[i] > pre:
        pre = A[i]
    elif A[i] <= pre:
        if A[i] <= B[cnt]:
            pre = A[i]
            B.append(A[i])
            cnt += 1
        else:
            del B[-1]
            if A[i] > max(B):
                pre = A[i]
            else:
                cnt += 1
                pre = A[i]
print(cnt+1)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
a_list = [int(x) for x in input().split()]
b_list = [0] * N
for i in range(len(a_list), 0, -1):
    if (a_list[i-1] != b_list[i-1]):
        b_list[i-1] ^= 1
        if (i >= 2):
            b_list[0] ^= 1
            for j in range(2, int(math.sqrt(i)+1)):
                if i % j == 0:
                    b_list[j-1] ^= 1
                    b_list[i//j-1] ^= 1
ans = []
cnt = 0
for i, b in enumerate(b_list):
    if (b):
        cnt += 1
        ans.append(str(b))
print(cnt)
if (cnt):
    print(" ".split(ans))

Submission status: Runtime Error

Solution code:
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

import functools
@functools.lru_cache(maxsize=None)
def make_divisors(n):
  if n == 1:
    divisors.append(1)
    return divisors
  for i in range(int(n**0.5)+1,1,-1):
    if n % i == 0:
      divisors.append(i)
      break
  return make_divisors(n//i)

N = I()
a = IL()
cnt = [0]*N

ans = ""
M = 0
for i in range(N-1,-1,-1):
  if cnt[i]%2 == 0 and a[i] == 1 or cnt[i]%2 == 1 and a[i] == 0:
    M += 1
    ans += str(i+1) + " "
  if a[i] == 1:
    divisors = []
    l = make_divisors(i+1)
    for j in l:
      cnt[j-1] += 1

if ans == "":
  print(0)
else:
  print(M)
  print(ans[:-1])

Submission status: Runtime Error

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

def sol(i,want):
    num=int(N/(i+1))
    wa=-A[0]
    for j in range(num):
        wa+=A[i+j*i]
    wa=wa%2
    if wa==want:
        x=0
    else:
        x=1
#     print(num)
    return x 

B=A[:]
for i in range(half):
    j=half-1-i
    print(j)
    B[j]=sol(j,A[j])

Submission status: Runtime Error

Solution code:
N = int(input())
a_list = [int(x) for x in input().split()]
b_list = [0] * N
for i in range(len(a_list), 0, -1):
    if (a_list[i-1] != b_list[i-1]):
        b_list[i-1] ^= 1
        if (i >= 2):
            b_list[0] ^= 1
            for j in range(2, int(math.sqrt(i)+1)):
                if i % j == 0:
                    b_list[j-1] ^= 1
                    b_list[i//j-1] ^= 1
ans = []
cnt = 0
for i, b in enumerate(b_list):
    if (b):
        cnt += 1
        ans.append(str(b))
print(cnt)
if (cnt):
    print(" ".split(ans))

Submission status: Runtime Error

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

n2 = math.ceil(n/2)
cnt = 0
ans = 0
seq = []
for i in reversed(range(n2)):
    sumi = sum([a[j] for j in range(i,n,i+1)])
    if sumi%2 != a[i-1]:
        a[i*n//i-1] += 1
        seq.append(i*n//i)
        if a[i*n//i-1] > 1:
            ans = -1
            break
        else:
            cnt += 1
    
if ans == -1:
    print(-1)
else:
    print(cnt)
    print(' '.join(list(map(str, seq))))

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
A.insert(0, 0)

balls = list()
sums = dict()
# for i, a in enumerate(reversed(A)):
for bn in range(n, 0, -1):
    a = A[bn]
    if 2*bn > n:
        sums[bn] = a
        if a == 1:
            balls.append(str(bn))
    else:
        a2_sum = sums[2*bn]
        if a2_sum % 2 == a:
            # not
            sums[bn] = a2_sum
        else:
            # in
            sums[bn] = a2_sum + 1
            balls.append(str(bn))

# all_balls = len(balls)
# if all_balls % 2 != A[0]:
#     print(-1)
# else:
#     print(all_balls)
#     print(' '.join(balls))
print(all_balls)
print(' '.join(balls))

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    
    
B = []
B.append(A[0])
pre = A[0]
cnt = 0
for i in range(1, len(A)):
    if A[i] > B[cnt] and A[i] > pre:
        pre = A[i]
    elif A[i] <= pre:
        if A[i] <= B[cnt]:
            pre = A[i]
            B.append(A[i])
            cnt += 1
        else:
            del B[-1]
            if A[i] > max(B):
                pre = A[i]
            else:
                cnt += 1
                pre = A[i]
print(cnt+1)

Submission status: Runtime Error

Solution code:
N = int(input())
args  = input().split()

rev = []

for i in range(N):
	n = int(args[N-i])
	j = 1
	oe = 0
	while n * j <= N +1:
		oe = (oe + int(args[n])) % 2
	if oe == 1:
		rev.append(1)
	else:
		rev.append(0)
		
rev.reverse()
print(rev)

Submission status: Runtime Error

Solution code:
import copy

N = int(input())
a = list(map(int, input().split()))
b = [0] * N
ans = []
count = 0
for i in reversed(range(N)):
  if i > N / 2:
    if a[i] == 1:
      b[i] = 1
      count += 1
      ans.append(int(i+1))
  elif  i == 0:
    if a[i] == 1:
      if (count % 2) == 0:
#        print("hello")
        b[i] = 1
        count += 1
        ans.append(int(i+1))
  else:
    if a[i] == 1:
      sumi = 0
      j = 2
      while True:
        sumi += b[i * j]
        j += 1
        if (i * j) > N:
          break
      if sumi % 2 == 0:
        b[i] = 1
        count += 1
        ans.append(int(i+1))
print(count)
print(' '.join(map(str, ans)))

Submission status: Runtime Error

Solution code:
N = int(input())
a = list(map(int, input().split()))
B = []
BB = []
for k in range(N):
  i = k+1
  p = 10-k
  B.append(0)
  if sum(B[i::p])% 2 != a[k-1]:
    B[k] = 1
    BB.append(k)
print(len(BB))
print(*BB)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
A_sort = sorted(A, reverse=True)

cnt = 0
for a in A:
    while len(A_sort):
        if a not in set(A_sort):
            break
        else:
            del A_sort[:A_sort.index(a) + 1]
            cnt += 1
            break
print(cnt)

Submission status: Runtime Error

Solution code:
import math
def add(n):
    return n + 1

def lcm(a):
    ans = a[0]
    for i in range(1, len(a)-1):
        ans = ans * a[i] // math.gcd(ans, a[i])
    return ans

if __name__ == "__main__":

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

    indexes = [i for i, x in enumerate(a) if x == 1]
    indexes = list(map(add, indexes))
    
    boxes = []
    if indexes:
        if max(indexes) > n:
            print("-1")
        else:
            
            while 1:
                num = lcm(indexes)
                if num < n:
                    break
                buf = [x for x in indexes if (max(indexes) % x) == 0]
                boxes.extend(buf)
                indexes = [x for x in indexes if (max(indexes) % x) != 0]
                if not indexes:
                    break 

            print("{}".format(len(boxes)+1))
            if boxes:
                boxes = ' '.join(map(str,boxes)) + " " + str(num)
            else:
                boxes = str(num)
            print(boxes)
    else:
        print("0")

Submission status: Runtime Error

Solution code:
N = int(input())
arr = map(int, input().split(' '))
ans = [0 for x in range(N)]
for i in reversed(range(N))
	if (i+1) > N/2.0:
    	ans[i] = arr[i]
    else:
      sum_v = 0
      for k in range(N//(i+1)):
        index = (k+1) * (i+1)
        sum_v += ans[index]
      if sum_v % 2 == arr[i]:
        ans[i] = 0
      else:
		ans[i] = 1
ans_arr = []
for i in ans:
  if ans == 1:
    ans_arr.append(i)

print(sum(ans))
print(' '.join(ans_arr))