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:
import sys
n = int(input())
a = list(map(int, input().split()))

for i in range(2**n):
    b = [0]*n
    judge = 0
    for j in range(n):
        if ((i >> j) & 1):
            b[j] = 1

    """
    if any(sum(b[j::j+1])%2 != a[j] for j in range(n)):
        continue
    
    else:
        print(sum(b))
        for k in range(n):
            if b[k] == 1:
                print(k+1,end=" ")
        print()
        sys.exit()
        """
    for j in range(n):
        if not (sum(b[j::j+1]%2 != a[j])):
            judge = 0
            break

    if judge == 1:
        print(sum(b))
        for k in range(n):
            if b[k] == 1:
                print(k+1,end=" ")
        print()
        sys.exit()

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(s) for s in input().split()]
cen = n //2
ANS = [0]*(cen)
A_p = A[cen:n]
ANS = ANS + A_p

for i in range(cen):
    part_sum = sum(ANS[cen-i-1::cen-i])
    dot = part_sum % 2
    if dot == A[cen-i-1]:
        pass
    else:
        ANS[cen-i-1] = 1

sum_ans = sum(ANS)
print(sum_ans)
if sum_ans == 0:
    pass
else:
    B=[]
    for i in range(n):
        if ANS[i] != 0:
            B.append(i+1)
        else:
            pass
    B = " ".join(B)
    print(B)

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

print(len(ans))
for i in reversed(range(len(ans))):
    print(ans[i])

Submission status: Runtime Error

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

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

#print(A)

X = {}

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)

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


print()

Submission status: Runtime Error

Solution code:
#from sympy import *
#solve([x * y * z], [x, y, z])

n = int(input())
lst = list(map(int, input().split()))
#vals = [Symbol("x"+str(i))for i in range(n)]
#vals2 = []
for i in range(1, n+1):
  lsum = 0
  for j in range(i*2, n+1, i):
    lsum += lst[j-1]
    if lst[i] != lst[j]:
      ans=-1
      break
  ans = 0
  if lsum%2 != lst[i-1]:
    ans = -1
    break
if ans == -1:
  print(ans)
else:
  print(sum(lst))
  print(" ".join(list(map(str, filter(lambda x:x==1,lst)))))

Submission status: Runtime Error

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

b=[]
wa=0
flag=0
for i in range(N):
    wa=0
    if flag==1:
        break
    for j in range(N):
        if i>0 and j==0:
            continue
        if i*j>N:
            break
        wa=wa+a[j*i]
    mod=wa % 2
#    print(i,wa,mod)
    if mod!=a[i]:
        print("-1")
        flag=1
    if mod==1:
        b.append(a[i])

if b==[] and flag!=1:
    print("0")
elif flag!=1:
    print(len(b))
    for i in range(len(b)):
        print(b[i],end=" ")

Submission status: Runtime Error

Solution code:
answer = []
M=0
for i in range(n-1,-1,-1):
    if a[i] == 1:
        answer.append(1)
        M += 1
    else:
        answer.append(0)
    
print(M)
print(answer[::-1])

Submission status: Runtime Error

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

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

#print(A)

X = {}

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)

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


print()

Submission status: Runtime Error

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

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

b=[]
wa=0
for i in range(N):
    wa=0
    for j in range(N):
        if i>0 and j==0:
            continue
        if i*j>N:
            break
        wa=wa+a[j*i]
    mod=wa % 2
#    print(i,wa,mod)
    if mod!=a[i]:
        print("-1")
        break
    if mod==1:
        b.append(a[i])

if b==[]:
    print("0")
else:
    print(len(b))
    for i in range(len(b)):
        print(b[i],end=" ")

Submission status: Runtime Error

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

for i in range(1,n+1):
    boll = [i*k for k in range(1,n+1) if i*k <= n]
    if sum(boll) % 2 == a[i]:
        print(i)
        for j in boll:
            print(a[j-1],'',end="")
        break

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = [int(i) for i in input().split()]
    ans_list = []
    list =[]
    ans_count =0
    for i in a:
        list.append(i)

    for i in range(n):
        x = n-i-1
        y = x+1
        count =1
        sum = 0
        while n+1 > y:
            sum = sum+list[y-1]
            count = count+1
            y = y*count
        mod = sum %2
        if mod ==1:
            ans_list.append(1)
            ans_count = ans_count+1
    print(ans_count)
    ans = ''
    for i in ans_list:
        if len(ans) > 0:
          ans = ans + ' ' + i
        else:
            ans = str(i)
    if len(ans) > 0:
        print(ans)

Submission status: Runtime Error

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

b=[]
wa=0
for i in range(N):
    wa=0
    for j in range(N):
        if i>0 and j==0:
            continue
        if i*j>N:
            break
        wa=wa+a[j*i]
    mod=wa % 2
#    print(i,wa,mod)
    if mod!=a[i]:
        print("-1")
        break
    if mod==1:
        b.append(a[i])

if b==[]:
    print("0")
else:
    for i in range(len(b)):
        print(b[i],end=" ")

Submission status: Runtime Error

Solution code:
import sys

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

    M = []
    lenA = len(A)
    for i in range(len(A))[::-1]:
        if i > lenA/2:
            if A[i] == 1:
                M.append(i+1)
        else:
            num = len([x for x in M if x%(i)==0]) % 2
            if A[i] != num:
                M.append(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()))
c = a

for k in range(2,N):
  for l in range(int(N/(k+1)),int(N/k)+1):
    j = l
    c[j] = a[j] + a[j*2]
    if c[j] > 1:
      c[j] = 0

#print(c)

M = c.count(1)
b = []

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

print(M)

for i in range(M):
  print(b[i]," ")

Submission status: Runtime Error

Solution code:
def isPrime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

def Solve():
    flag=True
    PL=[]
    N=int(input())
    L=[int(x) for x in input().split()]
    for i in range(N):
        if i==0:
            continue
        j=i+1
        if sum(L[i::j])%2-L[i]:#ちがったらTrue
            if isPrime(j):#素数ならTrue
                L[i]=0 if L[i]==1 else 1#L[i]を入れ替え（どうせ大勢に影響はない）
            else:
                print(-1)
                return
                
    if sum(L)-L[0]:#ちがったらTrue
        L[0]=0 if L[0]==1 else 1

    print(sum(L))
    result=""
    for i,a in enumerate(L):
        if a:
            result+=str(i+1)
            result+=" "
    if result:
        print(result)
    
Solve()

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())

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


def judge(_list, n):
    _sum = sum(_list[n-1:N:n])
    return _sum % 2


answer = None
false = 0

for base in range(2**N):
    bin_base = format(base, 'b')
    array = [s for s in bin_base]
    for i in range(1, N+1):
        if collect[i-1] != judge(array, i):
            false = 1
            break
    if not false:
        answer = array
        break
    false = 0

if answer:
    print(answer)
else:
    print('-1')

Submission status: Runtime Error

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

b=[]
wa=0
for i in range(N):
    wa=0
    for j in range(N):
        if i>0 and j==0:
            continue
        if i*j>N:
            break
        wa=wa+a[j*i]
    mod=wa % 2
#    print(i,wa,mod)
    if mod!=a[i]:
        print("-1")
        break
    if mod==1:
        b.append(a[i])

if b==[]:
    print("0")
else:
    b=[str(b) for i in b]
    b=' '.join(b)
    print(b)

Submission status: Runtime Error

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

b=[]
wa=0
for i in range(N):
    wa=0
    for j in range(N):
        if i>0 and j==0:
            continue
        if i*j>N:
            break
        wa=wa+a[j*i]
    mod=wa % 2
#    print(i,wa,mod)
    if mod!=a[i]:
        print("-1")
        break
    if mod==1:
        b.append(a[i])
b=[str(b) for i in b]
b=' '.join(b)
print(b)

Submission status: Runtime Error

Solution code:

import numpy as np
n = int(input())
a = np.array(list(map(int, input().strip().split())))

b = np.zeros((n))




from numpy.linalg import solve

c = np.zeros((n,n))
for i in range(n):

    j = 1
    while (i+1) * j <= n:
        c[i][(i+1) * j-1] = 1
        j += 1

#print(c)
b = solve(c,a)
#print(b)

'''
for i in range(n):
    b[i] = a[i]

#print(b)

if n % 2 == 0:
    p = int(np.ceil(n/2))
else:
    p = int(np.ceil(n/2)-1)
#print(p)

for i in reversed(range(p+1)):
    for j in reversed(range(1,int(n/(i+1)))):
        #print(i,j)
        b[i] -= b[(i+1)*(j+1)-1]

'''


b = b.astype(int)

#print(b)

flag = True
for i in range(n):
    if b[i] < 0:
        flag = False
        break

if flag:
    print(str(b).replace('[','').replace(']','').replace(' 0',''))

else:
    print(-1)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(int(x) for x in input().split())


b=[0]*n
m=n
while m>1:
    mnew=math.ceil(m/2)
    mult=n//(mnew+1)
    for i in range(mnew,m):
        numrest=0
        for j in range(mult):
            numrest+=b[(i+1)*j-1]
            if a[i]!=numrest%2:
                b[i]=1
    m=mnew
sumb=sum(b)%2
if a[0]!=sumb:
    b[0]=1
print (sum(b))
if sum(b)==0:
    print (0)
else:
    for i in range(sum(b)):
        print (1, end=' ')

Submission status: Runtime Error

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

def primes(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]]

prime_list = primes(N // 2)

dps = [0 for _ in range(N)]

ans =[]
#半分までは確定
fs = N // 2
for i in range(fs, N):
    dps[i] += A[i]
    if A[i] == 1:
        ans.append(i+1)


for i in reversed(range(fs)):
    # 考慮すべき数i*素数 < N
    num = 0
    for p in prime_list:
        if (i+1) * p <= N:
            num += dps[(i+1) * p - 1]

    
    if num % 2 != A[i]:
        dps[i] += 1
        ans.append(i+1)


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

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
a=np.array( [int(i) for i in input().split()])
b=np.array([99]*n)
for i in range(n//2,n):
    b[i]=a[i]
print(b)
for i in range(n//2,0,-1):        
    cand = np.array([i*j for j in range(2,n//i+1)])
    print(i,cand,a[cand-1])
    if sum(a[cand-1])%2==0:
        b[i-1]=a[i-1]
    else:
        b[i-1]=1-a[i-1]
posi=np.where(b==1)[0]
print(len(posi))
for j in range(len(posi))):
    print(posi[j],end=" ")

Submission status: Runtime Error

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


m = 2
def box(m):
    ans = 0
    if m >= n/2:
        print(-1)
    for i in range(1,n,m):
        ans += a[i]
    if a[m-1] == 1:
        if ans % 2 == 0:
            print(m)
            print(1)
        elif ans % 2 == a[m-1]:
            print(0)
        else:
            return box(m+1)
    elif a[m-1] == 0:
        if ans % 2 == 1:
            print(m)
            print(1)
        elif ans % 2 == a[m-1]:
            print(0)
        else:
            return box(m+1)
    
box(m)

Submission status: Runtime Error

Solution code:
N = int(input())
arr = map(int, input().split(' '))
ans = []
for i, num in enumerate(arr)
	if num == 1:
    	ans.append(i+1)
print(sum(arr))
print(' '.join(ans))

Submission status: Runtime Error

Solution code:
N=int(input())
A = [int(a) for a in input().split()]
#print(N,A)
B = [0]*N
for i in reversed(range(N)):
  C=[b for j,b in enumerate(B[(i+1):]) if (j+i+1)%(i+1) == 0]
  if sum(C)%2 == A[i]:
    B[i] = 0
  else:
    B[i] = 1
C = " ".join([i+1 for i,b in enumerate(B) if b == 1])
print(len(C))
print(" ".join(C))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = []
temp = [0]*80
for i in range(n):
    x = n-i
    y = 0
    for j in range(n):
        if x*(j+2) <= n:
            if temp[x*(j+2)-1] == 1:
                y += 1
        else:
            break
    if not y%2 == a[x-1]:
        ans.append(x)
        temp[x-1] += 1
s = len(ans)
print(s)
if s > 0:
    print(" ".join([str(i) for i in ans]))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = []
b = 0
for i in range(n):
	j = n - 1 - i
  1 n = int(input())
	if b == 0:
		if a[j] == 1:
			ans.append(j+1)
			c = j + 1
			b = 1
	elif b == 1 and j + 1 > c / 2:
		if a[j] == 1:
			ans.append(j+1)
	else:
		rem = list(map(lambda x: x % (j + 1),ans))
		count = rem.count(0)
		count_01 = count % 2
		if a[j] == 0:
			if count_01 == 1:
				ans.append(j+1)
		elif a[j] == 1:
			if count_01 == 0:
				ans.append(j+1)
if not ans:
	print(0)
else:
	print(len(ans))
	print(" ".join(list(map(str,ans))))

Submission status: Runtime Error

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


m = 2
def box(m):
    ans = 0
    if m >= n:
        print(-1)
    for i in range(1,n,m):
        ans += a[i]
    if a[m-1] == 1:
        if ans % 2 == 0:
            print(m)
            print(1)
        elif ans % 2 == a[m-1]:
            print(0)
        else:
            return box(m+1)
    elif a[m-1] == 0:
        if ans % 2 == 1:
            print(m)
            print(1)
        elif ans % 2 == a[m-1]:
            print(0)
        else:
            return box(m+1)
    
box(m)

Submission status: Runtime Error

Solution code:
N = int(input())
arr = map(int, input().split(' '))
ans = []
for i, num in enumerate(arr)
	if num == 1:
    	ans.append(i+1)
print(' '.join(ans))

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)):
        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:
        num = lcm(indexes)
        if max(indexes) > n:
            print("-1")
        else:
            while num > n:
                boxes.append(indexes.pop())
                num = lcm(indexes)
            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:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = [0] * N
    for i, a in enumerate(reversed(A)):
        tmp = N - i 
        cnt = 1
        tmp_sum = 0
        if tmp == 1:
            if a % 2 == sum(ans) % 2:
                break
            else:
                ans[tmp-1] = 1
                break
        while tmp <= N:
            tmp_sum += ans[tmp-1]
            cnt = cnt + 1
            tmp = tmp * cnt
        
        if a % 2 == tmp_sum % 2:
            continue
        else:
            ans[tmp-1] = 1
    if ans.count(0) == len(ans):
        print(0)
    else:
        print(len(ans))
        print(*ans)
main()

Submission status: Runtime Error

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

n=int(input())
P=primes(n)
A=[int(i) for i in input().split()]
Ans=[]
C=[False]*n
for i in reversed(range(n)):
  if A[i]==1:    
    if 2*(i+1)>n:
      Ans.append(i+1)
      C[i]=True
    else:
      c=1
      j=0
      while P[j]*(i+1)<=n:
        if C[P[j]*(i+1)-1]==True:
          c^=1
        j+=1
      if c==1:
        Ans.append(i+1)
        C[i]=True
  elif A[i]==1:    
    c=0
    j=0
    while P[j]*(i+1)<=n:
      if C[P[j]*(i+1)-1]==True:
        c^=1
      j+=1
    if c==1:
      Ans.append(i+1)
      C[i]=True
if len(Ans)==0:
  print(0)
else:
  print(len(Ans))
  Ans.sort()
  print(*Ans)

Submission status: Runtime Error

Solution code:
import math

N = int(input())

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

bb = aa[:]

i = math.floor(N / 2)

while i >= 0:
    bai = (i + 1) * 2 - 1
    if aa[i] == 1:  # 自分が奇数
        if aa[bai] == 0:  # 2倍が偶数
            bb[i] = 1
        else:  # 2倍が奇数
            bb[i] = 0
    else:  # 自分が偶数
        if aa[bai] == 0:  # 2倍が偶数
            bb[i] = 0
        else:  # 2倍が奇数
            bb[i] = 1
    i -= 1

bbKisu = filter(lambda n: n % 2 == 1, bb)
count = len(list(bbKisu))

print(count)
for i in range(N):
    if bb[i] == 1:
        print(i + 1)

Submission status: Runtime Error

Solution code:
def factor(n):
    res = []
    for i in range(1, n + 1):
        if n % i == 0:
            res.append(i)
    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
for a in bs:
    boll_count = get_num(bolls, a)
    if boll_count == 1:
      res += str(i + 1)
    s += boll_count
print(s)
if res:
    print(res)
else:
    print("0")

Submission status: Runtime Error

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

b = []

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
arr = map(int, input().split(' '))
ans = []
for i, num in enumerate(arr)
	if num != 0:
    	ans.append(i+1)
print(''.join(ans))

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)):
        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:
        num = lcm(indexes)
        if max(indexes) > n:
            print("-1")
        else:
            while num > n:
                boxes.append(indexes.pop())
                num = lcm(indexes)
            print("{}".format(len(boxes)+1))
            print(boxes)
            boxes = ' '.join(map(str,boxes)) + " " + str(num)
            print(boxes)
    else:
        print("0")

Submission status: Runtime Error

Solution code:
import math

N = int(input())

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

bb = aa[:]

i = math.floor(N / 2)

while i >= 0:
    if aa[i] == 1:  # 自分が奇数
        if aa[i * 2] == 0:  # 2倍が偶数
            bb[i] = 1
        else:  # 2倍が奇数
            bb[i] = 0
    else:  # 自分が偶数
        if aa[i * 2] == 0:  # 2倍が偶数
            bb[i] = 0
        else:  # 2倍が奇数
            bb[i] = 1
    i -= 1

bbKisu = filter(lambda n: n % 2 == 1, bb)
count = len(list(bbKisu))

print(count)
for i in range(N):
    if bb[i] == 1:
        print(i + 1)

Submission status: Runtime Error

Solution code:
N = int(input())
arr = map(input().split(' '))
ans = []
for i, num in enumerate(arr)
	if num != 0:
    	ans.append(i+1)
print(''.join(ans))

Submission status: Runtime Error

Solution code:
import math

N = int(input())

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

bb = aa[:]

i = math.floor(N / 2)

while i > 0:
    if aa[i] == 1:  # 自分が奇数
        if aa[i * 2] == 0:  # 2倍が偶数
            bb[i] = 1
        else:  # 2倍が奇数
            bb[i] = 0
    else:  # 自分が偶数
        if aa[i * 2] == 0:  # 2倍が偶数
            bb[i] = 0
        else:  # 2倍が奇数
            bb[i] = 1
    i -= 1

bbKisu = filter(lambda n: n % 2 == 1, bb)
count = len(list(bbKisu))

print(count)
for i in range(N):
    if bb[i] == 1:
        print(i + 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

b = [0 for x in range(n)]
out = []

for i in range(n , 0, -1):
  temp = [b[x - 1] for x in range(n , i , -1) if x % i == 0]
  if sum(temp) % 2 != a[i - 1]:
    b[i] = 1
    out.append(i)

print(sum(b))
if sum(b) != 0:
  print(*out)

Submission status: Runtime Error

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


m = 2
def box(m):
    ans = 0
    for i in range(1,n,m):
        ans += a[i]
    if ans % 2 == a[m-1] - 1:
        print(m)
        print(1)
    elif ans % 2 == a[m-1] + 1:
        print(-1)
    elif ans % 2 == a[m-1]:
        print(0)
    else:
        return box(m+1)
    
        
box(m)

Submission status: Runtime Error

Solution code:
N = int(input())

A = [0]*N
B = [0]*N

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


q = N//2

B[q:] = A[q:]

for i in range(q)[::-1]:
	s = 0
	j = i
	while j < N:
		s += A[j]
		j += i+1
	if s%2 != A[i]:
		A[i] = 1

print(sum(A))

f = 0
if sum(A)!=0:
	for i in range(N):
		if A[i]!=0:
			if f == 0:
				f += 1
				print(i+1, end='')
			else:
				print(f' {i+1}', end='')
	print()

Submission status: Runtime Error

Solution code:
N = int(input())
a_list = list(map(int, input().split()))
#print(a_list)

for i, a in enumerate(a_list):
  if a == 1:
    print(str(i+1))
    num = N // (i+1)
    b_list = [ str((b + 1) * (i+1)) for b in range(num)]
    print(' '.join(b_list))
    end_flag = True
    break
    
if not end_flag:
  print('0')

Submission status: Runtime Error

Solution code:
from math import log


def solve(A, N):
    r = N // 2
    l = N
   
    M = set()
    for i in range(r, l):
        if A[i]:
            M.add(i)
    l = r
    r //=2

    while l > 0:
        for i in range(r, l):
            if A[i] and A[i<<1]:
                M.add(i)
                A[i] = 1
            else:
                A[i] = 0
        l = r
        r //=2

    return M


def main():
    N = int(input())
    X = [0] * (2**15)
    A = [int(x) for x in input().split()]
    for i in range(len(A)):
        X[i] = A[i]
    m = solve(X, 2**15)
    print(len(m))
    for i in m:
        print(i+1)

main()

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
n = int(input())
ans = [int(input())]
for i in range(n-1):
    now = int(input())
    j = bisect_left(ans,now)
    if j == 0:
        ans.insert(0,now)
    else:
        ans[j-1] = now

print(len(ans))

Submission status: Runtime Error

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(" ")))
	A = input().split()
	A = [int(s) for s in A]
	#P = getPrimeNumList(200000)

	tmp = A[1]
	for i in range(4, N, 2):
		if tmp != A[i-1]:
			print(-1)
			sys.exit()

	ans = []
	hafe = N//2
	for i in range(N, 0, -1):
		if i > hafe:
			if A[i-1] == 1:
				ans.append(i)
			continue

		if A[i-1] != A[(i*2)-1]:
			ans.append(i)

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

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
maxa = max(a)
max_index = [i for i, x in enumerate(a) if x == maxa]
if len(max_index) >= 2:
    for i in range(n):
        print(maxa)
else:
    for i in range(n):
        if i == max_index[0]:
            print(sorted(a)[-2])
        else:
            print(maxa)

Submission status: Runtime Error

Solution code:
#

#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop
import math

def main():
    n = int(input())
    al = list(map(int, input().split()))

    ans = [0] * n

    half = math.ceil(n/2)
    for i in range(half, n):
        ans[i] = al[i]

    for i in range(half, -1, -1):
        num = i + 1
        val = 0
        for j in range(num * 2 - 1, n, num):
            # print(j)
            val += ans[j]

        val %= 2
        ans[i] = 0 if val == al[i] else 1

    c = ans.count(1)
    print(c)
    if c > 0:
        boxes = []
        for i in range(len(ans)):
            if ans[i] == 1:
                boxes.append(i + 1)
        print(' '.join(map(str, boxes)))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
a_list = list(map(int, input().split()))
#print(a_list)

for i, a in enumerate(a_list):
  if a == 1:
    print(str(i+1))
    print(a)
    end_flag = True
    break
    
if not end_flag:
  print('0')

Submission status: Runtime Error

Solution code:
import math

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

ball_arr = [0] * N

for i in range(math.ceil(N/2), N):
    ball_arr[i] = a[i]
    
# print(ball_arr)

for i in reversed(range(math.ceil(N/2))):
    # print(i+1)
    # print(sum(ball_arr[i-1::i+1]))
    # print(sum(ball_arr[i-1::i+1]) != a[i])
    mul_arr = ball_arr[i-1::i+1]
    if sum(mul_arr) != a[i]:
        # print((mull_arr.index(0)+1)*i)
        ball_arr[(mul_arr.index(0)+1)*i] = 1
    # print(ball_arr)
    # print('---')
# print(ball_arr)

M = sum(ball_arr)
print(M)
for i, v in enumerate(ball_arr):
    if v == 1:
        print(i+1, end=' ')

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0]*N
n = N
for a in (reversed(A)):
    if n*2 > N:
        B[n-1] = a
        n -= 1
        continue
    total = 0
    for i in range(2,N+2):
        if n*i <= N:
            total += B[n*i-1]
        else:
            if a == total % 2:
                B[n-1] = 0
            else:
                B[n-1] = 1
    n -= 1

print(tmp)