Problem:


Score : 400 points

Problem Statement

There are N empty boxes arranged in a row from left to right.
The integer i is written on the i-th box from the left (1 \leq i \leq N).

For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it.

We say a set of choices to put a ball or not in the boxes is good when the following condition is satisfied:

For every integer i between 1 and N (inclusive), the total number of balls contained in the boxes with multiples of i written on them is congruent to a_i modulo 2.

Does there exist a good set of choices? If the answer is yes, find one good set of choices.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

a_i is 0 or 1.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

If a good set of choices does not exist, print -1.

If a good set of choices exists, print one such set of choices in the following format:

M
b_1 b_2 ... b_M

where M denotes the number of boxes that will contain a ball, and b_1,\ b_2,\ ...,\ b_M are the integers written on these boxes, in any order.

Sample Input 1

3
1 0 0

Sample Output 1

1
1

Consider putting a ball only in the box with 1 written on it.

There are three boxes with multiples of 1 written on them: the boxes with 1, 2, and 3. The total number of balls contained in these boxes is 1.

There is only one box with a multiple of 2 written on it: the box with 2. The total number of balls contained in these boxes is 0.

There is only one box with a multiple of 3 written on it: the box with 3. The total number of balls contained in these boxes is 0.

Thus, the condition is satisfied, so this set of choices is good.

Sample Input 2

5
0 0 0 0 0

Sample Output 2

0

Putting nothing in the boxes can be a good set of choices.



Sample input:
3
1 0 0


Sample output:
1
1

Submission status: Wrong Answer

Solution code:
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()))
box = [0 for _ in range(n)]
sum_box = [0 for _ in range(n)]
for i in range(n)[::-1]:
    if a[i] == 1 and sum_box[i] % 2 == 0:
        for k in make_divisors(i+1):
            sum_box[k-1] += 1
        box[i] = 1
    elif a[i] == 1 and sum_box[i] % 2 != 0:
        box[i] = 0
    elif a[i] != 1 and sum_box[i] % 2 != 0:
        for k in make_divisors(i+1):
            sum_box[k-1] += 1
        box[i] = 1
    elif a[i] != 1 and sum_box[i] % 2 == 0:
        box[i] = 0
ans = []
for i, b in enumerate(box):
    if b == 1:
        ans.append(str(i+1))
if not ans:
    print(0)
else:
    s = ' '.join(ans)
    print(1)
    print(s)

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

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

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
def inpl():
    return list(map(int, input().split()))


def func(n):
    for j in range(1, n // 2):
        if n % j == 0:
            ans[j - 1] += 1
    return


N = int(input())
A = inpl()
ans = [0 for i in range(N)]

for i in reversed(range(N)):
    ans[i] %= 2
    if ans[i] == A[i]:
        pass
    else:
        ans[i] = (ans[i] + 1) % 2

    if A[i] == 1:
        func(i + 1)

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

print(len(B))
if len(B) > 0:
    print(" ".join(map(str, B)))

Submission status: Wrong Answer

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

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

    ans = []

    for i in range(n, 0, -1):
        if i == 1:
            if a[i] == 0:
                continue
            else:
                if sum(ans) % 2 == 0:
                    ans.append(1)
        else:
            if a[i] == 1:
                ans.append(i)
                tmp = 1
                for j in ans:
                    print(j)
                    if j % 2 == 0:
                        tmp += 1            
                    if tmp % 2 == 1:
                        ans.append(i)

            if a[i] == 0:
                tmp = 0
                for j in ans:
                    print(j)
                    if j % 2 == 0:
                        tmp += 1            
                    if tmp % 2 == 1:
                        ans.append(i)

    if len(ans) == 0:
        print(-1)
    else:
        ans.reverse()
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    a_ = list(map(int, input().split()))
    box = [0 for _ in range(N)]

    logging.info("Hello!")

    half_N = N // 2
    for i in range(N - half_N):
        box[N - i - 1] = a_[N - i - 1]

    for i in range(half_N):
        box_num = half_N - i

        sum = 0
        for j in range((N // (box_num)) - 1):
            sum += a_[(box_num) * (j + 2) - 1]

        box[box_num - 1] = abs(a_[box_num - 1] - (sum % 2))

    logging.info(box)

    print(box.count(1))
    answer = ""
    for i in range(N):
        if box[i] == 1:
            answer += str(i + 1)
            answer += " "

    print(answer)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
def func1(lst, value):
    return [i+1 for i, x in enumerate(lst) if x == value]
N = int(input())
a = list(map(int,input().split()))

b = [0] * N
half = math.ceil(N/2)
summ = 0
for i in reversed(range(N)):
    # print(i)
    if i >= half-1:
        b[i] = a[i]
    else:
        x = N//(i+1)
        for j in range(1,x):
            summ += a[(i+1)*(j+1)-1]
        judge=summ%2
        if (judge==0 and a[i]==0) or (judge==1 and a[i]==1):
            b[i] = 0
        else:
            b[i] = 1
        summ = 0
        judge =0
print(sum(b))
if sum(b) != 0:
    ans = func1(b,1)
    # print(ans)
    if len(ans)>1:
        print(" ".join(str(ans)))
    else:
        print(ans.pop())

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
an = np.array(input().split(" ")).astype("int64")


if an[0] == 0:
    if n % 2 == 0:
        print("1")
        print("1")
    else:
        print("0")
elif an[0] == 1:
    if n % 2 == 0:
        print("0")
    else:
        print("1")
        print("1")

Submission status: Wrong Answer

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

for i in range(int(n/2)+1,n+1):
    b[i]=a[i]

for i in reversed(range(1,int(n/2)+1)):
    c=0
    if a[i]==0:
        for j in range(2*i,n,i):
            if b[j]==1:
                c=c+1
        if c % 2 ==0:
            b[i]=0
        else:
            b[i]=1
    if a[i]==1:
        for j in range(2*i,n,i):
            if b[j]==1:
                c=c+1
        if c % 2 ==0:
            b[i]=1
        else:
            b[i]=0

if any(b)==False:
    print(0)
else:
    def func1(lst, value):
        return [i for i, x in enumerate(lst) if x == value]
    idx=func1(b,1)
    print(' '.join(map(str, idx)))

Submission status: Wrong Answer

Solution code:
import math

def factors(x):
	fac = set({})
	for i in range(1, int(math.sqrt(x))+1):
		if x%i == 0:
			fac.add(i)
			fac.add(x//i)
	return fac


n = int(input())
arr = [int(j) for j in input().split()]

ans = [False for i in range(n)]

for i in range(1, n+1):
	if arr[i-1] == 0:
		continue
	
	f = factors(i)
	for x in f:
		if ans[x-1] == False:
			ans[x-1] = True
		else:
			ans[x-1] = False

var = 1
for i in range(1, n+1):
	temp = 0
	for x in range(i, n+1, i):
		# print(i, x, ans[x-1])
		temp += ans[x-1]
	# print(temp)
	if temp%2 != arr[i-1]:
		var = 0
		break

# print(ans)
if var == 0:
	print(-1)

else:
	ansarr = []
	count = 0
	for x in range(n):
		if ans[x] == True:
			count += 1
			ansarr += [x+1]
	print(count)
	print(*ansarr)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

if a[0] == 1:
  print(1)
  print(1)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
lst = list(map(int, input().split()))
slice_lst = lst[:int(N / 2)]
for i,k in enumerate(reversed(slice_lst)):
  sub_lst = lst[len(slice_lst)-i-1:len(lst):len(slice_lst)+i]
  if (k != sum(sub_lst) % 2):
    if (k == 0):
      lst[len(slice_lst)-i-1] = 1
    else:
      ans = -1
      break

if (ans == -1):
  print(ans)
else:
  ans_lst = []
  for i,k in enumerate(lst):
    if (k == 1):
      ans_lst.append(str(i+1))
  print(len(ans_lst))
  result = ' '.join(ans_lst)
  print(result)

Submission status: Wrong Answer

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

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

print(sum(b))
f=0
for i in range(N):
    if b[i]==1 and f==0:
        f=1
        out=str(i+1)
    elif b[i]==1:
        out = out + " " + str(i+1)
if f==1:
    print(out)

Submission status: Wrong Answer

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

flag = -1
counter = 0

while(True):
    if counter == N // 2:
        break

    total = sum(A[i] for i in range(counter, N, counter+1))
    if total % 2 == A[counter]:
        flag = counter
        break
    
    counter += 1


if flag != -1:
    res = [str(i+1) for i in range(flag, N, flag+1) if A[i] == 1]
    print(len(res))
    if len(res) != 0:
        print(' '.join(res))
else:
    for i in range(counter, N):
        if A[i] == 1:
            flag = i
            print(1)
            print(i+1)
            break

if flag == -1:
    print(flag)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = input().split()
    b = []
    for _ in range(n):
        b.append(0)
    for i in range(n):
        ii = n - i
        sum = 0
        for j in range(ii,n):
            if (j + 1) % ii == 0:
                sum += b[j]
        if (sum % 2) != int(a[ii-1]):
            b[ii-1] = 1
    print(" ".join(map(str, b)))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

ans = {}
for i in range(1, n+1):
    xs = []
    for j in range(i-1, n, i):
        xs.append(a[j])
    ans[i] = sum(xs)

print(max(ans.items(), key = lambda x:x[1])[0])
print(max(ans.values()))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] + list(map(int, input().split()))
ans = [0]*(n+1)
for i in range(n, n//2, -1) : ans[i] = a[i]
for i in range(n//2, 0, -1) :
    tmp = 0
    for j in range(i+i, n+1, i) : tmp += ans[j]
    ans[i] = (tmp+a[i])%2
print(sum(ans))
if(sum(ans) != 0) :
    print(" ".join(map(str, list(filter(lambda x:x==1, ans))))) # sumが0のときまずいかも

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
for i in range(1,n // 2 + 1):
    an = a[n //2 - i]
    if (sum(a[n // 2 - i::i]) - an) % 2 == an:
        a[n // 2 - i] = 0
    else:
        a[n // 2 - i] = 1
b = []
cnt = 0
for i in range(len(a)):
    if a[i] == 1:
        b.append(str(i + 1))
        cnt += 1
if cnt != 0:
    print(cnt)
    print(' '.join(b))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
figure = list(map(int, input().split()))
one = []
error = 0#０だと正常

for x in range(n):
  a = 0
  for i in range(x,n,x+1):
    if figure[i] == 1:
      a +=1
  if figure[x] != a%2:
    error += 1
    print("-1")
    break
if error == 0:
  data = list(map(lambda x:x+1, one))
  if not data:
    print("0")
  else:
    print(*data)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
ans=[0]*N
c=0
for i in range(N)[::-1]:
    I=N//(i+1)
    if I==1:
        ans[i]=a[i]
    elif I>1:
        for j in range(1,I):
            c+=ans[(j+1)*(i+1)-1]
        C=c%2
        if  C==0:
            ans[i]=a[i]
        else:
            print(-1)
            exit()
print(sum(ans))
for i in range(N):
    if ans[i]==1:
        print(i+1,end=' ')

Submission status: Wrong Answer

Solution code:
N = int(input())
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
NN = N
bit = [0]*N
N = len(a)
while N > 0:
    yakusu = make_divisors(N)
    #print(yakusu)
    if a[N-1] != bit[N-1]:
        for i in yakusu:
            bit [i-1] = bit[i-1] + 1
            if bit[i-1] == 2:
                bit[i-1] = 0
    #print(bit)
    N = N-1

if bit == a:
    print(sum(bit))
    STR = ""
    for i in range(NN):
        if bit[i] == 1:
            STR = STR + str(i+1)+" "
    print(STR)
elif sum(bit) != 0:
    print(-1)
else:
    print(0)

Submission status: Wrong Answer

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

if n%2==1:
  for i in range((n//2+1),n):
    b[i]=a[i]
  
  for i in range(n//2,0,-1):
    j=2
    b[i]=a[i]
    while(j*i<n):
      b[i]^=a[j*i]
      j+=1
m=0
for i in range(n):
  m+=b[i]

print(m)
for i in range(n):
  if b[i]==1:
    print(i)

Submission status: Wrong Answer

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

result = []
res_ap = result.append

for i in range(N // 2, N)[::-1]:
    if a[i] == 1:
        res_ap(i)
for i in range(N // 2)[::-1]:
    j = 2 * (i + 1)
    while(j < N + 1):
        cnt = 0
        cnt += a[j - 1]
        j += i + 1
    if (a[i] + cnt % 2) == 1:
        res_ap(i)
M = len(result)
print(M)
if M != 0:
    print(result[0] + 1, end = "")
    for i in range(1, M):
        print(" " + str(result[i] + 1), end = "")

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    boxes = [0] * N

    count = 0
    printlist = []
    for i in range(N//2,N):
        boxes[i] = A[i]
        if A[i] == 1:
            count += 1
            printlist.append(i)
    for i in range(N//2)[::-1]:
        s = A[i]
        print('i=',i)
        for j in range(2,N//(i+1)+1):
            print('idx=',(i+1)*j - 1)
            s ^= boxes[(i+1)*j - 1]
        boxes[i] = s
        if s == 1:
            count += 1

            printlist.append(i)

    import sys
    print(count)
    for i in printlist:
        sys.stdout.write(str(i+1))
        sys.stdout.write(' ')
    print()

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
c = 0
d = [0] * n
ans = []
for i in range(n):
    m = n-i
    p = 1
    b = 0
    while m * p <= n:
        tmp = m * p
        if d[tmp-1] == 1:
            b += 1
        p += 1
    if b % 2 != a[m-1]:
        d[tmp-1] == 1
        ans.append(m)
        c += 1

if c%2 == 1 and c > 1:
    print(-1)
else:
    print(c)
    print(" ".join(repr(e) for e in ans))

Submission status: Wrong Answer

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

for i in range(N, N//2, -1):
  if arg[i-1] == 0:
    x[i-1] = 0
  else:
    x[i-1] = 1

for i in range(N//2, 0, -1):
  others = 0
  for j in range(N, i, -1):
    if j % i == 0:
      others += arg[j-1]
  if arg[i-1] % 2 != others % 2:
    x[i-1] = 1
  else:
    x[i-1] = 0
    
if max(x) == 0:
  print(0)
else:
  for index in range(len(x)):
    if x[index] != 0:
      print(index+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
an = np.array(input().split(" ")).astype("int64")


if an[0] == 0:
    if n % 2 == 0:
        print("0")
    else:
        print("1")
        print("1")
elif an[0] == 1:
    if n % 2 == 0:
        print("1")
        print("1")
    else:
        print("0")

Submission status: Wrong Answer

Solution code:
def factor(n):
    b = 2
    res = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            res.append(b)
        b = b + 1
    if n > 1:
        res.append(n)
    return res
def get_num(num_arr, a):
    boll_sum = 0
    for p in factor(len(num_arr))[1:]:
        boll_sum += num_arr[p - 1]
    if boll_sum % 2 == a:
        return 0
    else:
        return 1
n = int(input())
bs = [int(x) for x in input().split(" ")]
res = ""
s = 0
bolls = []
for i,a in enumerate(bs):
    boll_count = get_num(bolls, a)
    bolls.append(boll_count)
    if boll_count == 1:
        res += str(i + 1)
    s += boll_count
print(s)
if res:
    print(res)
else:
    print("0")

Submission status: Wrong Answer

Solution code:
n = int(input())


def divisor(n):  # 約数全列挙
    ans = [1, n]
    i = 2
    while i ** 2 <= n:
        if n % i == 0:
            ans.append(i)
            if i ** 2 < n:
                ans.append(n // i)
        i += 1
    ans.sort()
    return ans
a = list(map(int,input().split()))
ans = []
for num in range(n-1,-1,-1):
    if a[num] %2== 1:
        ans.append(a[num])
        q = divisor(num+1)
        for j in q:
            a[j-1] += 1

print(len(ans))
for i in ans:
    print(i,end=' ')

print()

Submission status: Wrong Answer

Solution code:
N=int(input())
S=set()
NUM=[]
for i in range(1,N+1):
    S.add(i)
    NUM.append(i)
A=list(map(int,input().split()))
flag = False
for i in reversed(range(1, N+1)):
    for j in range(1, N+1):
        tmp = i * j
        if tmp > N:
            break
        S.discard(tmp)
        if A[i-1] == 1:
            print(tmp)
            flag = True
            break
if not flag:
    print(0)

Submission status: Wrong Answer

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

s = []


def primes(n):
    erat=[False,False]+[True for i in range(n-1)]
    for i in range(n + 1) :
        if erat[i]:
            for j in range(i*2,n+1,i):
                erat[j]=False
    return [i for i in range(n+1)if erat[i]]

ps = primes(n)

def change(i):
    if a[i] == 1: a[i] = 0
    else: a[i]= 1


for i in range(n,0,-1):
    if a[i] == 1:
        s.append(i)
        yakusu=[x for x in ps if i%x==0]
        for x in yakusu:
            change(a[x])

print(len(s))
[print(x) for x in s]

Submission status: Wrong Answer

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

for i in range(int(n/2)+1,n+1):
    b[i]=a[i]

for i in reversed(range(1,int(n/2)+1)):
    c=0
    if a[i]==1:
        for j in range(2*i,n,i):
            if a[j]==1:
                c=c+1
        if c % 2 ==0:
            b[i]=0
        else:
            b[i]=1
    if a[i]==0:
        for j in range(2*i,n,i):
            if a[j]==1:
                c=c+1
        if c % 2 ==0:
            b[i]=1
        else:
            b[i]=0

if any(b)==False:
    print(0)
else:
    def func1(lst, value):
        return [i for i, x in enumerate(lst) if x == value]
    idx=func1(b,1)
    print(' '.join(map(str, idx)))

Submission status: Wrong Answer

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

a_count = len(a_list)

boll_list = [0] * n

for rev_index, a in enumerate(reversed(a_list)):
    index = a_count - rev_index - 1
    if (a + 1) * 2 > a_count:
        boll_list[index] = a_list[index]
    else:
        divide_max = a_count // (index + 1)
        total = 0
        for divide in range(divide_max):
            total += boll_list[(index + 1) * (divide + 1) - 1]
        total = total % 2
        if a_list[index] != total:
            boll_list[index] = 1

if 1 in boll_list:
    output_list = []
    for index, i in enumerate(boll_list):
        if i == 1:
            output_list.append(str(index + 1))
    print(' '.join(output_list))
else:
    print('0')

Submission status: Wrong Answer

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

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	# = list(input())
	#L,R = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))
	P = getPrimeNumList(200000)
	A = input().split()

	ans = []

	print(-1)
	sys.exit()

	for i, val in enumerate(A):
		tmp = i+1
		if tmp == 1 and int(val) == 1:
			ans.append(tmp)
			continue
		if tmp in P:
			if int(val) == 1:
				ans.append(tmp)

	print(len(ans))
	if len(ans) != 0:
		ans2 = ""
		for i in reversed(ans):
			ans2 = ans2 + str(i) + " "

		print(ans2[:-1])

def getPrimeNumList(n):
	is_prime = [True] * (n + 1)
	is_prime[0] = False
	is_prime[1] = False
	for i in range(2, int(n**0.5) + 1):
		if not is_prime[i]:
			continue
		for j in range(i * 2, n + 1, i):
			is_prime[j] = False
	return [i for i in range(n + 1) if is_prime[i]]

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
c=0
for i in reversed(range(n)):
    count=0
    for j in range(i+1,n+1):
        if j%(i+1)==0:
            count+=a[j-1]
    if count%2==1:       
        c+=1
        
if c>0:       
  for _ in range(c):
  	print("1")
else:
  print("0")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
m = 0
b = []
c = 0
half = int(n/2)

for i in range(len(a)-1, 0, -1):
    if i>half:
        b.append(a[i])
    else:
        for j in range(i, len(a), 1):
            if j%i == 0:
                c += a[j]
        if c%2 == a[i]:
            b.append(0)
            c = 0
        else:
            b.append(1)
            c = 0

for i in range(len(b)):
    c += a[j]
if c!= a[0]:
    b.append(1)
else:
    b.append(0)

if b[0]!= 1:
    for i in range(len(b)-1, -1, -1):
        if b[i] == 1:
            m+=1
    print(m)
    
    for i in range(len(b)):
        if b[i] == 1:
            print(i-1, end=" ")
else: 
    print(-1)

Submission status: Wrong Answer

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

b = [i for i, ci in enumerate(c,1) if ci % 2 == 1]
M = b.count(1)
if M == 0:
  print(0)
else:
  print(M)
  print(' '.join(map(str, b)))

Submission status: Wrong Answer

Solution code:
print('-1')

Submission status: Wrong Answer

Solution code:
N=int(input())

l=list(map(int,input().split()))
l=[0]+l
L=[0 for i in range(N+1)]
A=[]
for i in range(1,N+1):
    cnt=0
    if l[N+1-i]==1:
        for j in range(2,10**5):
            if (N+1-i)*j>N:
                break
            else:
                if L[(N+1-i)*j]==1:
                    cnt+=1
        if cnt%2==0:
            L[N+1-i]+=1
            A.append(N+1-i)
    else:
        for j in range(2,10**5):
            if (N+1-i)*j>N:
                break
            else:
                if L[(N+1-i)*j]==1:
                    cnt+=1
        if cnt%2==1:
            L[N+1-i]+=1
            A.append(N+1-i)
    
    
A.sort()
print(len(A))
print(*A)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] + list(map(int, input().split()))
B = []
failed = False
for i in range(1, N+1):
  if A[i] == 1:
    if sum(A[i:N+1:i])%2 == 0:
      failed=True
      break
    else:
      B.append(i)
  elif A[i] == 0:
    if sum(A[i:N+1:i])%2 == 1:
      failed=True
      break
if failed:
  print(-1)
else:
  b_sum = len(B)
  print(b_sum)
  if b_sum > 0:
    print(' '.join(map(str, B)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a = [0] + list(map(int, input().split()))
b = [0 for i in range(n + 1)]

for i in range(n, n // 2, -1):
    b[i] = a[i]

for i in range(n // 2, 0, -1):
    s = 0
    for j in range(2, n + 1):
        if i * j > n:
            break
        s += a[i * j]
    mod = s % 2
    if mod == 0:
        b[i] = a[i]
    else:
        b[i] = 1 - a[i]

num_balls = sum(b)
print(num_balls)
if num_balls > 0:
    print(" ".join([str(i) for i, x in enumerate(b) if x == 1]))

Submission status: Wrong Answer

Solution code:

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

box = [0] * N
if A[0] == 1:
  box[0] = 1

def trial_division(n):
  factor = []
  tmp = n**2 + 1
  for num in range(2,tmp):
    while n % num == 0:
      n //= num
      factor.append(num)
  print(factor)
  if not factor:
    return -1
  else:
    factor.append(n)
    return factor

for i in range(1,N-1):
  if sum(A[i+1::i+1]) % 2 == 1:
    for n in trial_division(i+1):
      if n == 1:
        continue
      box[n-1] += 1

res = []
for i, b in enumerate(box):
  res.append(i+1)
print(len(res))
if res:
  print(*res)

Submission status: Wrong Answer

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

b = [i for i, ci in enumerate(c,1) if ci % 2 == 1]
print(b)
M = b.count(1)
if M == 0:
  print(0)
else:
  print(M)
  print(' '.join(map(str, b)))

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())

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

b = [0] * N

num = 0

for i in range(N-1, -1, -1):
    sum = 0
    for j in range(2, N):
        if i * j < len(a):
            sum += a[i*j]
        else:
            break
    if sum % 2 == 1:
        b[i] = 1
        num += 1

print(num)

if num == 0 or num == -1:
    sys.exit(0)

flag = False

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

print("")

Submission status: Wrong Answer

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

p1=N
acount=0
astr=''

for i in range(p1):
  num=p1-i-1
  if (num+1)*2-1<N:
    #count=abs(ans[(num+1)*2-1]-A[num])
    count=A[(num+1)*2-1]
    ans[num]=abs(count-A[num])
    #ans[num]=count
    if ans[num]==1:
      acount+=1
      astr=' '+str(num+1)+astr
  else:
    Anum=A[num]
    ans[num]=Anum
    if Anum==1:
      acount+=1
      astr=' '+str(num+1)+astr
#print(ans)
print(acount)
print(astr[1:])

Submission status: Wrong Answer

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

if len(set(A)) == 1:
  print(0)
else:
  flag=1
  ans = []
  while N:
    end = N
    N = N // 2
    if end == 3:
      N+=1
    ans += [N+(i+1) for i, x in enumerate(A[N:end]) if x==flag]
    flag = 1 - flag
  print(len(ans))
  print(' '.join([str(n) for n in ans]))

Submission status: Wrong Answer

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

for i in range(N):
    total = 0
    b = []
    for j in range(N):
        if (j + 1) % (i + 1) == 0:
            total = total + 1
            b.append(j + 1)
    if total % 2 == a[i]:
        print(i+1)
        for k in range(i+1):
            if k == i+1 - 1:
                print(b[k])
            else:
                print(b[k], " ")
        exit()

print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
a =list(map(int, input().split()))
b=[]
c=[]
for x in range(N):
    b.append(0)
for z in range(0,N-1):
    if z!=0:
        a=b
    for x in range(1,N//2+1):
        X=0
        for y in range(x,N+1):
            if y%x==0 and a[y-1]==1:
                X=X+1
        b[x-1]=X%2
    for x in range(N//2+1,N+1):
        b[x-1]=a[x-1]
print(b.count(1))
if b.count(1)!=0:
    for x in range(N):
        if b[x]==1:
            c.append(x+1)
    L=[str(k) for k in c]
    L=" ".join(L)
    print(L)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
l=[]
for i in range(1,1+n):
    limit=n//(i)
    s=0
    for j in range(1,1+limit):
        s+=a[j*i-1]
    if s%2!=a[i-1]:
        print(-1)
        sys.exit()
    elif s%2==a[i-1] and s%2==1:
        l.append(i)
if l==[]:
    print(0)
else:
    print(len(l))
    d=map(str,l)
    print(" ".join(d))

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

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

input = lambda: stdin.readline()
main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] + list(map(int, input().split()))
ans = [0]*(n+1)
for i in range(n, n//2, -1) : ans[i] = a[i]
for i in range(n//2, 0, -1) :
    tmp = 0
    for j in range(i+i, n+1, i) : tmp += ans[j]
    ans[i] = (tmp+a[i])%2
print(sum(ans))
print(" ".join(map(str, list(filter(lambda x:x==1, ans))))) # sumが0のときまずいかも

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int,input().split()))
    boxes = [0] * N

    count = 0
    printlist = []
    for i in range(N//2,N):
        boxes[i] = A[i]
        if A[i] == 1:
            count += 1
            printlist.append(i)
    for i in range(N//2):
        s = A[i]
        #print('i=',i)
        for j in range(2,N//(i+1)+1):
            #print('idx=',(i+1)*j - 1)
            s ^= boxes[(i+1)*j - 1]
        boxes[i] = s
        if s == 1:
            count += 1

            printlist.append(i)

    import sys
    print(count)
    for i in printlist:
        sys.stdout.write(str(i+1))
        sys.stdout.write(' ')
    print()

if __name__ == '__main__':
    main()