Odpowiedź :
n=int(input())
y=0
i=0
tab=[]
zestawy=0
while i<n:
x=int(input())
if x==1:
if y!=0:
tab.append(y)
zestawy+=1
y=x
i+=1
tab.append(y)
print(zestawy)
for i in tab:
print(i,end=" ")
Oczywiście język python
n=int(input())
y=0
i=0
tab=[]
zestawy=0
while i<n:
x=int(input())
if x==1:
if y!=0:
tab.append(y)
zestawy+=1
y=x
i+=1
tab.append(y)
print(zestawy)
for i in tab:
print(i,end=" ")
Oczywiście język python