Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $3$ steps, and the second contains $4$ steps, she will pronounce the numbers $1, 2, 3, 1, 2, 3, 4$.

You are given all the numbers pronounced by Tanya. How many stairways did she climb? Also, output the number of steps in each stairway.

The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.


-----Input-----

The first line contains $n$ ($1 \le n \le 1000$) — the total number of numbers pronounced by Tanya.

The second line contains integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with $x$ steps, she will pronounce the numbers $1, 2, \dots, x$ in that order.

The given sequence will be a valid sequence that Tanya could have pronounced when climbing one or more stairways.


-----Output-----

In the first line, output $t$ — the number of stairways that Tanya climbed. In the second line, output $t$ numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.


-----Examples-----
Input
7
1 2 3 1 2 3 4

Output
2
3 4 
Input
4
1 1 1 1

Output
4
1 1 1 1 
Input
5
1 2 3 4 5

Output
1
5 
Input
5
1 2 1 2 1

Output
3
2 2 1

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
n = int(input())
arr = map(int, input().split())
ans = {}
stairs = 0
for x in arr:
	if x == 1:
		stairs += 1
		ans[stairs] = 1
	else:
		ans[stairs] += 1
print(len(ans))
print(*ans.values())


_ = input()
s = input()
a = s.split()
b = []
for i in range(1, len(a)):
	if a[i] == '1':
		b.append(a[i - 1])
b.append(a[-1])
print(len(b))
print(*b)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
l = zzz()
ans = l.count(1)
lst = []
print(ans)
for i in range(num - 1):
	if l[i + 1] == 1:
		lst.append(l[i])
lst.append(l[-1])
print(*lst)


n = int(input())
a = list(map(int, input().split()))
c1 = a.count(1)
print(c1)
c = 0
for i in range(1, n):
	if a[i] == 1:
		print(a[i - 1], end=' ')
		c += 1
if c != c1:
	print(a[-1])


n = int(input())
l = list(map(int, input().split()))
if len(set(l)) == 1:
	print(n)
	for i in l:
		print(i, end=' ')
	print()
	exit(0)
(temp, m) = ([0], [])
for i in range(len(l)):
	if l[i] > temp[-1]:
		temp.append(l[i])
	else:
		m.append(temp[1:])
		temp.clear()
		temp.append(0)
		temp.append(l[i])
if len(temp) > 1:
	m.append(temp[1:])
print(len(m))
for i in m:
	print(len(i), end=' ')
print()


n = int(input())
a = list(map(int, input().split()))
l = []
for i in range(0, n - 1):
	if a[i] >= a[i + 1]:
		l.append(a[i])
l.append(a[-1])
print(len(l))
print(*l)


a = int(input())
s = []
s = input().split(' ')
for c in range(len(s)):
	s[c] = int(s[c])
c = 0
w = 0
x = 1
g = []
for c in range(len(s)):
	if s[c] == 1:
		w += 1
		g.append(x)
		x = 1
	else:
		x += 1
g.append(x)
print(w)
for r in range(1, w + 1):
	print(g[r], end=' ')


n = int(input())
arr = [int(x) for x in input().split()]
brr = []
for i in range(0, n - 1, 1):
	if arr[i] == arr[i + 1]:
		brr.append(arr[i])
	elif arr[i] < arr[i + 1]:
		continue
	else:
		brr.append(arr[i])
brr.append(arr[n - 1])
print(len(brr))
print(*brr)


n = int(input())
a = list(map(int, input().split()))
a.append(-5)
count = 0
l = []
cl = 0
for i in range(n):
	if a[i] == a[i + 1] - 1:
		count = count + 1
	else:
		count = count + 1
		l.append(count)
		cl = cl + 1
		count = 0
print(cl)
for i in range(cl):
	if i == cl - 1:
		print(l[i])
	else:
		print(l[i], end=' ')


n = int(input())
X = [int(x) for x in input().split(' ')]
p = []
b = [X[-1]]
print(X.count(1))
for i in range(1, n):
	if X[i] == 1:
		p.append(X[i - 1])
p.extend(b)
print(' '.join((str(v) for v in p)))


n = int(input())
a = [int(s) for s in input().split()]
sp = []
for i in range(n):
	if i >= 1:
		if a[i] == 1:
			sp.append(a[i - 1])
sp.append(a[-1])
print(a.count(1))
for x in sp:
	print(x)


n = int(input())
A = list(map(int, input().split()))
print(A.count(1))
for i in range(1, n):
	if A[i] == 1:
		print(A[i - 1], end=' ')
print(A[-1])


n = int(input())
l = list(map(int, input().split()))
count = 0
end = []
for i in range(len(l)):
	if i < len(l) - 1:
		if l[i + 1] - l[i] < 1:
			count += 1
			end.append(l[i])
		elif l[i + 1] - l[i] == 0:
			count += 1
			end.append(l[i])
count += 1
end.append(l[-1])
print(count)
for x in end:
	print(x, end=' ')


n = int(input())
a = [int(x) for x in input().split()]
ks = []
kl = 0
m = 0
for i in a:
	if i == 1:
		ks.append(m)
		m = 0
		kl += 1
	m += 1
ks.append(m)
print(kl)
for i in ks[1:]:
	print(i, end=' ')


n = int(input())
a = input().split()
max = 0
s = []
for i in range(1, n):
	if int(a[i]) == 1:
		max += 1
		s += [int(a[i - 1])]
max += 1
s += [int(a[-1])]
print(max)
for i in s:
	print(i, end=' ')


lenght = int(input())
org_l = map(int, input().split(' '))
new_l = []
c = -1
for n in org_l:
	if n == 1:
		new_l.append(1)
		c += 1
	else:
		new_l[c] += 1
s = ''
for n in new_l:
	s += str(n) + ' '
print(len(new_l))
print(s)


n = int(input())
a = input().split()
a = [int(item) for item in a]
ans = []
for i in range(1, n):
	if a[i] == 1:
		ans.append(a[i - 1])
ans.append(a[-1])
print(len(ans))
for i in range(len(ans)):
	print(ans[i], end=' ')


n = int(input())
l = input().split(' ')
l1 = []
for i in l:
	l1.append(int(i))
cd = []
k = 0
cnt = 0
for i in l1:
	if i == 1:
		k = k + 1
		if k != 1:
			cd.append(str(cnt))
			cnt = 0
	cnt += 1
cd.append(str(cnt))
print(k)
print(' '.join(cd))


n = int(input())
a = list(map(int, input().split()))
step = 1
fi = []
for i in range(1, n):
	if a[i] == 1:
		step += 1
		fi.append(a[i - 1])
fi.append(a[-1])
print(step)
print(*fi)


n = int(input())
arr = [int(i) for i in input().split()]
count = 0
no_steps = []
for i in range(n):
	if arr[i] == 1:
		count += 1
		no_steps.append(arr[i - 1])
print(count)
for i in range(1, len(no_steps)):
	print(no_steps[i], end=' ')
print(no_steps[0])


i = input
i()
l = [*map(int, i().split())]
print(l.count(1))
for j in range(1, len(l)):
	if l[j] == 1:
		print(l[j - 1], end=' ')
print(l[len(l) - 1])


n = int(input())
s = [int(i) for i in input().strip().split(' ')]
l = []
for i in range(1, n):
	if s[i] == 1:
		l.append(s[i - 1])
l.append(s[n - 1])
print(len(l))
for i in l:
	print(i, end=' ')
print('')


n = int(input())
arr = list(map(int, input().split()))
x = []
count = 0
for i in range(n):
	if arr[i] == 1:
		count += 1
		if i != 0:
			x.append(arr[i - 1])
x.append(arr[n - 1])
print(count)
print(*x)


n = int(input())
ls = list(map(int, input().split()))
cnt = 0
for i in ls:
	if i == 1:
		cnt += 1
print(cnt)
for i in range(1, n):
	if ls[i] == 1:
		print(ls[i - 1], end=' ')
print(ls[-1])


n = int(input())
t = list(map(int, input().split()))
sts = [0]
for i in range(1, n):
	if t[i] <= t[i - 1]:
		sts.append(i)
print(len(sts))
sts.append(n)
print(' '.join(map(str, [sts[i] - sts[i - 1] for i in range(1, len(sts))])))


n = int(input())
a = [int(x) for x in input().split()]
i = 0
stairs = 0
total = []
while i < n - 1:
	if a[i] < a[i + 1]:
		i += 1
	else:
		stairs += 1
		total.append(a[i])
		i += 1
total.append(a[-1])
print(stairs + 1)
print(' '.join((str(x) for x in total)))


n = int(input())
l = list(map(int, input().split()))
(l1, l2) = ([], [])
for i in range(len(l)):
	if l[i] == 1:
		l1.append(i)
c = l1[0]
j = 1
while j < len(l1):
	l2.append(l1[j] - c)
	c = l1[j]
	j += 1
l2.append(len(l) - l1[-1])
print(len(l1))
print(*l2)


n = int(input())
l = []
a = list(map(int, input().split()))
for (x, y) in zip(a, a[1:]):
	if y == 1:
		l.append(x)
l.append(a[-1])
l = [str(u) for u in l]
print(len(l))
print(' '.join(l))


n = int(input())
data = list(map(int, input().split()))
ans = 0
ans_ar = []
prev = None
curr = 1
for el in data:
	if el == 1:
		ans += 1
		if prev != None:
			ans_ar.append(curr)
		prev = 0
		curr = 1
	else:
		curr = el
ans_ar.append(curr)
print(ans)
print(' '.join((str(el) for el in ans_ar)))


n = int(input())
k = list(map(int, input().split()))
s = 1
li = []
for i in range(1, n):
	if k[i] == 1:
		s += 1
		li.append(k[i - 1])
li.append(k[n - 1])
print(s)
for j in li:
	print(j, end=' ')


n = int(input())
a = list(map(int, input().split()))
k = 0
ans = []
for i in range(n):
	if a[i] == 1:
		k += 1
		if i != 0:
			ans.append(a[i - 1])
ans.append(a[n - 1])
print(k)
print(*ans)


_ = input()
s = input()
parts = s.split()
a = []
for i in parts:
	a.append(int(i))
t = 0
for x in a:
	if x == 1:
		t = t + 1
m = len(a)
d = a[m - 1]
b = []
for n in range(1, m):
	if a[n] == 1:
		b.append(a[n - 1])
b.append(d)
print(t)
for x in b:
	print(x, end=' ')


n = int(input())
arr = list(map(int, input().split()))
a = []
for i in range(1, len(arr)):
	if arr[i] == 1:
		a.append(arr[i - 1])
a.append(arr[-1])
print(arr.count(1))
print(' '.join(map(str, a)))


n = int(input())
l = list(map(int, input().split()))
c = []
d = 0
for i in range(len(l) - 1):
	if l[i + 1] == 1:
		d += 1
		c.append(l[i])
d += 1
c.append(l[-1])
print(d)
for i in c:
	print(i, end=' ')


from sys import stdin, stdout
import bisect
import math
from collections import Counter

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	n = inp()
	l = li()
	x = []
	for i in range(1, n):
		if l[i] - l[i - 1] != 1:
			x.append(l[i - 1])
	if l[-1] == 1 or l[-1] - l[-2] == 1:
		x.append(l[-1])
	print(len(x))
	print(*x)
for _ in range(1):
	solve()


a = int(input())
b = input()
c = [int(x) for x in b.split()]
ans = []
for i in range(1, a):
	if c[i] == 1:
		ans.append(c[i - 1])
ans.append(c[len(c) - 1])
print(len(ans))
for j in range(0, len(ans)):
	print(ans[j], end=' ')


number = int(input())
first = list(map(int, input().split()))
second = []
gp = 1
for i in range(1, number):
	if first[i] == 1:
		second.append(first[i - 1])
		gp += 1
second.append(first[-1])
print(gp)
print(*second)


n = int(input())
a = [int(x) for x in input().split()]
m = min(a)
new = []
for i in range(1, n):
	if a[i] == m:
		new.append(a[i - 1])
new.append(a[n - 1])
print(len(new))
print(*new)


T = int(input())
array1 = list(map(int, input().split(' ')))
a = []
for i in range(1, T):
	if array1[i] > array1[i - 1]:
		continue
	else:
		a.append(array1[i - 1])
a.append(array1[T - 1])
print(len(a))
print(*a)


def Tanya(n, l):
	res = 0
	result = []
	i = 0
	while i < n:
		if l[i] == 1:
			j = 1
			i = i + 1
			while i < n and l[i] != 1:
				i = i + 1
				j = j + 1
			result.append(j)
	return result
x = int(input())
l = [int(n) for n in input().split()]
res = Tanya(x, l)
print(len(res))
print(' '.join(map(str, res)))


n = int(input())
array = input().split()
array = list(map(int, array))
number = array.count(1)
print(number)
line = [i for (i, n) in enumerate(array) if n == 1]
line.pop(0)
for j in line:
	print(array[j - 1], end=' ')
print(array[-1])


def scanf(obj=list, type=int):
	return obj(map(type, input().split()))
(n,) = scanf()
m = scanf()
ans = [m[i - 1] for i in range(n) if i and m[i] == 1]
ans.append(m[-1])
print(len(ans))
print(*ans)


import sys
n = int(input())
lst = [int(x) for x in input().split()]
s = []
z = 1
if n == 1:
	print(1)
	print(1)
	sys.exit()
for i in range(n - 1):
	if lst[i] < lst[i + 1]:
		z += 1
	elif lst[i] >= lst[i + 1]:
		s.append(str(z))
		z = 1
if lst[-1] > lst[-2]:
	s.append(str(z))
if lst[-1] == 1:
	s.append('1')
print(len(s))
print(' '.join(s))


input()
(res, a) = ([], 0)
for b in [*map(int, input().split()), 1]:
	if b == 1 and a:
		res.append(a)
	a = b
print(len(res))
print(*res)


def main():
	s = int(input())
	l = list(map(int, input().split()))
	ll = []
	count = 0
	for i in range(len(l) - 1):
		if l[i] >= l[i + 1]:
			count += 1
			ll.append(count)
			count = 0
		else:
			count += 1
	count += 1
	ll.append(count)
	print(len(ll))
	print(' '.join(list(map(str, ll))))
main()


n = int(input())
l = list(map(int, input().split()))
print(l.count(1))
i = 1
c = 1
while i < n:
	if l[i] == 1:
		print(c, end=' ')
		c = 1
	else:
		c += 1
	i += 1
print(c)


n = int(input())
arr = list(map(int, input().split()))
res = []
for i in range(1, len(arr)):
	if arr[i] == 1:
		res.append(arr[i - 1])
res.append(arr[-1])
print(len(res))
print(*res)


n = int(input())
answer = []
kol = 0
for i in input().split():
	if i == '1':
		answer.append(kol)
		kol = 1
	else:
		kol += 1
answer.append(kol)
answer.pop(0)
print(len(answer))
print(*answer)


n = int(input())
stairs = list(map(int, input().split()))
stairsCount = 0
tempcount = 0
StairCaseCount = []
for x in stairs:
	if x == 1:
		stairsCount += 1
		StairCaseCount.append(tempcount)
		tempcount = 1
	else:
		tempcount += 1
StairCaseCount.append(tempcount)
print(stairsCount)
for x in StairCaseCount:
	if x != 0:
		print(x, end=' ')


n = int(input())
arr = input().split(' ')
for i in range(n):
	arr[i] = int(arr[i])
count = 0
ls = []
for i in range(n):
	if i != n - 1:
		if arr[i + 1] <= arr[i]:
			count = count + 1
			ls.append(str(arr[i]))
	else:
		count = count + 1
		ls.append(str(arr[n - 1]))
print(count)
print(' '.join(ls))


n = int(input())
a = [int(i) for i in input().split()]
l = []
for i in range(1, n):
	if a[i] == 1:
		l.append(a[i - 1])
print(len(l) + 1)
print(*l, a[-1])


n = int(input())
aa = list(map(int, input().split(' ')))
res = []
for i in range(1, len(aa)):
	if aa[i] <= aa[i - 1]:
		res += [aa[i - 1]]
res += [aa[-1]]
print(len(res))
print(*res)


n = int(input())
z = input().split()
m = 0
print(z.count('1'))
j = 0
r = str()
for i in range(z.count('1')):
	if j + 1 < n:
		while z[j + 1] != '1':
			m += 1
			j += 1
			if j + 1 >= n:
				break
	r += str(m + 1) + ' '
	j += 1
	m = 0
print(r)


n = int(input())
a = [int(x) for x in input().split()]
ans = []
for i in range(n):
	if a[i] == 1 and i != 0:
		ans.append(a[i - 1])
ans.append(a[n - 1])
print(len(ans))
for x in ans:
	print(x, end=' ')


n = int(input())
l = list(map(int, input().split()))
ans = []
for i in range(1, n):
	if l[i] == 1:
		ans.append(l[i - 1])
ans.append(l[n - 1])
print(len(ans))
print(*ans)


x = int(input())
a = list(map(int, input().split()))
s = a.count(1)
t = 0
print(s)
for i in range(1, x):
	if a[i] == 1:
		t = i - t
		print(t, end=' ')
		t = i
print(a[-1])


a = int(input())
b = list(input().split())
count = 0
c = ''
for i in range(len(b)):
	if b[i] == '1':
		count += 1
print(count)
for i in range(len(b)):
	if b[i] == '1' and i != 0:
		c = c + b[i - 1] + ' '
c = c + b[i]
print(c)


n = int(input())
s = [int(i) for i in input().split()]
d = []
for i in range(n - 1):
	if s[i + 1] - s[i] == 1:
		pass
	else:
		d.append(s[i])
d.append(s[n - 1])
print(len(d))
print(' '.join((str(i) for i in d)))


n = int(input())
ai = list(map(int, input().split()))
print(ai.count(1))
a = ai[0]
for i in range(1, len(ai)):
	if a >= ai[i]:
		print(a, end=' ')
	a = ai[i]
print(ai[-1])


n = int(input())
a = list(map(int, input().split())) + [1]
path = []
for i in range(1, n + 1):
	if a[i] == 1:
		path.append(a[i - 1])
print(len(path))
print(*path)


n = int(input())
num = [int(i) for i in input().split()]
stair = num.count(1)
print(stair)
for i in range(len(num)):
	if num[i] == 1:
		j = i + 1
		while j < len(num) and num[j] != 1:
			j += 1
		print(num[j - 1], end=' ')


n = int(input())
numbers = list(map(int, input().rstrip().split()))
numStairways = 0
print(numbers.count(1))
numStairs = []
for i in range(1, n):
	if numbers[i] == 1:
		numStairs.append(numbers[i - 1])
numStairs.append(numbers[n - 1])
for number in numStairs:
	print(number, end=' ')


n = int(input())
c = list(map(int, input().strip().split(' ')))
if n != 1:
	maxx = c[0]
	v = []
	for x in range(1, n):
		if c[x] <= maxx:
			v.append(maxx)
			maxx = c[x]
		else:
			maxx = c[x]
	v.append(c[x])
	print(len(v))
	for x in range(len(v)):
		print(v[x], end=' ')
	print()
else:
	print('1')
	print(c[0])


input()
s = input().split()
ls = []
l = []
for i in s:
	if i == '1':
		ls.append(l)
		l = []
	else:
		l.append(i)
ls.append(l)
ls.pop(0)
print(len(ls))
for i in ls:
	print(len(i) + 1, end=' ')
print()


n = int(input())
a = list(map(int, input().split()))
c1 = 1
c2 = 1
li = []
i = 0
while i < n - 1:
	if a[i] >= a[i + 1]:
		c2 += 1
		li.append(c1)
		c1 = 1
	elif a[i] < a[i + 1]:
		c1 += 1
	i += 1
li.append(c1)
print(c2)
for i in range(len(li)):
	print(li[i], end=' ')
print()


def steps(n, ls):
	l = []
	k = ls.count(1)
	ls[0] = 0
	h = 0
	s = 0
	for i in range(k - 1):
		s = ls.index(1)
		ls[s] = 0
		l.append(s - h)
		h = s
	l.append(n - s)
	print(k)
	print(' '.join(map(str, l)))
n = int(input())
ls = [int(i) for i in input().split()]
steps(n, ls)


n = int(input())
m = list(map(int, input().split()))
print(m.count(1))
for j in range(n - 1):
	if m[j + 1] == 1:
		print(m[j], end=' ')
print(m[-1])


n = int(input())
l = list(map(int, input().split()))
print(l.count(1))
if l.count(1) == len(l):
	print(*l)
else:
	a = l.count(1)
	while a > 0:
		for i in range(len(l) - 1):
			if l[i + 1] == 1:
				print(l[i], end=' ')
			a -= 1
	print(l[len(l) - 1])


n = int(input())
a = [int(x) for x in input().split()]
ones = []
for (i, x) in enumerate(a):
	if x == 1:
		ones.append(i)
ones.append(n)
print(len(ones) - 1)
print(*[y - x for (x, y) in zip(ones, ones[1:])])


n = int(input())
numbers = list(map(int, input().split()))
stairways = 0
steps = []
for i in range(n):
	if numbers[i] == 1:
		stairways += 1
		if i != 0:
			steps.append(numbers[i - 1])
steps.append(numbers[n - 1])
print(stairways)
print(' '.join(map(str, steps)))


n = int(input())
a = list(map(int, input().split()))
ans = []
temp = a[n - 1]
ans.append(temp)
for i in range(n - 2, -1, -1):
	if a[i] >= temp:
		ans.append(a[i])
	temp = a[i]
print(len(ans))
for i in reversed(ans):
	print(i, end=' ')


n = int(input())
vals = list(map(int, input().split()[:n])) + [1]
res = [0]
for i in range(1, len(vals)):
	if vals[i] == 1:
		res.append(i)
print(len(res) - 1)
print(' '.join([str(v1 - v2) for (v1, v2) in zip(res[1:], res[:-1])]))


x = int(input())
y = list(map(int, input().split()))
c = [index for (index, element) in enumerate(y) if element == 1]
d = [j - i for (i, j) in zip(c[:-1], c[1:])]
d.append(len(y) - c[-1])
print(len(d))
print(*d, sep=' ')


n = int(input())
stairs = []
stairs = list(map(int, input().split()))
result = 0
arr = []
for i in range(n):
	if stairs[i] == 1:
		result += 1
		if i > 0:
			arr.append(stairs[i - 1])
	if i == n - 1:
		arr.append(stairs[i])
print(result)
for m in range(len(arr)):
	print(arr[m], end=' ')
print()


n = int(input())
s = [int(i) for i in input().split()]
c = 0
l = []
for i in range(n):
	if s[i] == 1:
		c += 1
	if i + 1 < n and s[i + 1] == 1 or i == n - 1:
		l.append(s[i])
print(c)
for i in l:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
ans = 1
b = []
for i in range(1, n):
	if a[i] == 1:
		ans += 1
		b.append(a[i - 1])
b.append(a[-1])
print(ans)
print(*b)


from itertools import groupby
from operator import itemgetter
n = int(input())
l1 = [int(i) for i in input().split()]
l2 = []
for (k, g) in groupby(enumerate(l1), lambda ix: ix[0] - ix[1]):
	l2.append(list(map(itemgetter(1), g)))
print(len(l2))
print(*[len(i) for i in l2])


n = int(input(''))
a = [int(x) for x in input().split()]
p = []
for x in range(n):
	if a[x] == 1:
		p.append(x)
print(len(p))
p.append(n)
for i in range(len(p) - 1):
	print(p[i + 1] - p[i], end=' ')


n = input()
x = [int(p) for p in input().split()]
c = 0
y = []
for i in range(1, len(x)):
	if x[i] == 1:
		c += 1
		y.append(x[i - 1])
print(c + 1)
y.append(x[len(x) - 1])
for e in range(c + 1):
	print(y[e], end=' ')


n = int(input())
br = 0
brl = 0
pr = 0
a = list(map(int, input().split(' ')))
lista = []
for i in range(len(a)):
	if a[i] == pr + 1:
		br += 1
	else:
		lista.append(br)
		br = 1
		brl += 1
	pr = a[i]
brl += 1
isp = ''
lista.append(br)
print(brl)
for broj in lista:
	isp += str(broj)
	isp += ' '
print(isp.strip(' '))


input()
a = input().split()
b = [x for (x, y) in zip(a, a[1:] + ['1']) if '1' == y]
print(len(b))
print(*b)


n = int(input())
stairs = list(map(int, input().split()))
ans = []
for (i, item) in enumerate(stairs):
	if i + 1 < len(stairs):
		if stairs[i + 1] == 1:
			ans.append(item)
ans.append(stairs[-1])
print(len(ans))
print(*ans)


input()
n = [int(x) for x in input().strip().split()]
stair = 0
stairs = []
for s in n:
	if s <= stair:
		stairs.append(str(stair))
	stair = s
stairs.append(str(stair))
print(len(stairs))
print(' '.join(stairs))


N = int(input())
A = list(map(int, input().split()))
print(A.count(1))
B = []
for i in range(1, N):
	if A[i] == 1:
		B.append(A[i - 1])
B.append(A[-1])
print(*B, sep=' ')


n = int(input())
a = list(map(int, input().split()))
a.append(1)
b = []
(x, y) = (0, 0)
for i in range(1, len(a)):
	if a[i] == 1:
		y = i
		b.append(y - x)
		x = y
print(len(b))
print(*b)


a = int(input())
b = list(map(int, input().split()))
r = []
while a > 0:
	r.insert(0, b[a - 1])
	a = a - b[a - 1]
print(len(r), '\n', *r)


n = int(input())
a = list(input().split())
res = 1
h = []
for i in range(len(a)):
	if a[i] == '1' and i > 0:
		res += 1
		h.append(a[i - 1])
h.append(a[-1])
print(res)
print(' '.join(h))


t = int(input())
arr = [int(x) for x in input().split()]
temp_arr = []
for i in range(0, len(arr) - 1):
	if arr[i + 1] == 1:
		temp_arr.append(arr[i])
temp_arr.append(arr[t - 1])
print(len(temp_arr))
print(*temp_arr, sep=' ')


n = int(input())
l = [i for i in input().split()]
m = l.count('1')
print(m)
(lst, t) = ([], [])
for i in range(1, n):
	if l[i] != '1':
		lst.append(l[i])
	else:
		t.append(len(lst) + 1)
		lst = []
t.append(len(lst) + 1)
print(' '.join(list(map(str, t))))


n = int(input())
m = list(map(int, input().split()))
s = 0
q = []
w = 1
for i in range(1, n):
	if m[i] == m[i - 1] + 1:
		w += 1
	else:
		q.append(w)
		s += 1
		w = 1
q.append(w)
s += 1
print(s)
for i in range(len(q)):
	print(q[i], end=' ')


n = int(input())
s = list(map(int, input().split()))
times = 0
nums = []
for i in range(n):
	if i == n - 1:
		times += 1
		nums.append(s[i])
		break
	if s[i + 1] == 1:
		times += 1
		nums.append(s[i])
print(times)
print(' '.join((str(i) for i in nums)))


n = int(input())
l = list(map(int, input().split()))
re = []
for i in range(n - 1):
	if l[i] >= l[i + 1]:
		re.append(l[i])
re.append(l[-1])
print(len(re))
for i in re:
	print(i, end=' ')


n = int(input())
A = [int(i) for i in input().split()]
an = []
stairs = 1
for i in range(1, len(A)):
	if A[i] == 1:
		an.append(A[i - 1])
		stairs += 1
an.append(A[n - 1])
print(stairs)
for i in range(0, len(an)):
	print(an[i], end=' ')


input()
(stairs, steps) = ([], 0)
for a in input().split() + ['1']:
	if a == '1' and steps:
		stairs.append(steps)
		steps = 1
	else:
		steps += 1
print(len(stairs))
print(*stairs)


n = int(input())
a = list(map(int, input().split()))
r = [a[i] for i in range(n - 1) if a[i + 1] == 1] + [a[-1]]
print(len(r))
print(*r)


quantityOfElems = int(input())
listOfElems = list()
second_string = input()
listOfElems = second_string.split(' ')
intListOfElems = list()
for el in listOfElems:
	intListOfElems.append(int(el))
stairways = intListOfElems.count(1)
listAnswer = list()
bufferCounter = 0
intListOfElems.remove(1)
for i in range(0, quantityOfElems - 1):
	bufferCounter += 1
	if intListOfElems[i] == 1:
		listAnswer.append(bufferCounter)
		bufferCounter = 0
listAnswer.append(bufferCounter + 1)
print(stairways)
answerStr = ''
for i in range(0, stairways):
	answerStr += str(listAnswer[i]) + ' '
print(answerStr)


n = int(input())
l = [int(x) for x in input().split()] + [1]
ans = []
for i in range(n):
	if l[i + 1] <= l[i]:
		ans.append(l[i])
print(len(ans))
print(*ans)


a = input()
b = 0
arr = []
inp = input().split()
for i in inp:
	if int(i) != b + 1:
		arr.append(b)
		b = 1
	else:
		b = b + 1
arr.append(b)
strs = ''
for i in arr:
	strs = strs + str(i) + ' '
print(len(arr))
print(strs)


n = int(input())
a = list(map(int, input().split()))
s = []
for i in range(1, n):
	if a[i] == 1:
		s.append(a[i - 1])
if a[-1] == 1:
	s.append(1)
else:
	s.append(a[-1])
print(len(s))
print(' '.join(map(str, s)))


n = int(input())
a = input()
c = list(map(int, a.split()))
b = []
x = ''
if all((i == 1 for i in a)):
	print(n)
	print(a)
else:
	print(c.count(1))
	if c.count(1) > 1:
		for i in range(len(c)):
			if c[i] == 1:
				b.append(i)
		for i in range(1, len(b)):
			x += str(b[i] - b[i - 1]) + ' '
		x += str(len(c[b[i]:]))
		print(x.strip())
	else:
		print(c[n - 1])


n = int(input())
ls = list(map(int, input().split()))
print(ls.count(1))
f = 0
c = 0
for i in range(n):
	if f and ls[i] == 1:
		print(c, end=' ')
		c = 1
	else:
		c += 1
	f = 1
print(c)


n = int(input())
arr = [int(x) for x in input().strip().split()]
stairs = 0
li = []
for i in range(len(arr)):
	if arr[i] == 1:
		if stairs != 0:
			li.append(arr[i - 1])
			stairs += 1
		else:
			stairs += 1
li.append(arr[len(arr) - 1])
print(stairs)
for i in li:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
print(a.count(1))
b = []
i = 0
for x in a:
	if x == 1 and i != 0:
		print(a[i - 1], end=' ')
	if i == n - 1:
		print(a[n - 1])
	i += 1


n = int(input())
l = [int(x) for x in input().split()]
a = ''
x = 0
for i in range(n - 1):
	if l[i + 1] == 1:
		x += 1
		a += str(l[i])
		a += ' '
a += str(l[n - 1])
print(x + 1)
print(a)


n = int(input())
a = input().split()
ans = 1
arr = []
for i in range(n - 1):
	if a[i + 1] == '1':
		ans += 1
		arr.append(a[i])
arr.append(a[-1])
print(ans)
print(*arr)


n = int(input())
a = [*map(int, input().split())]
print(a.count(1))
for i in range(1, n):
	if a[i] == 1:
		print(a[i - 1], end=' ')
print(a[n - 1])


n = int(input())
a = [int(x) for x in input().split()]
counter = 0
b = []
for i in range(n):
	if i > 0 and a[i] == 1:
		b.append(counter)
		counter = 1
	else:
		counter += 1
b.append(counter)
print(len(b))
print(*b)


n = int(input())
s = list(map(int, input().split()))
k = 1
c = 0
d = list()
f = False
for i in range(n):
	if s[i] == 1 and f:
		d.append(k)
		k = 1
		c += 1
	if s[i] == 1 and (not f):
		k = 1
		c += 1
		f = True
	if s[i] != 1:
		k += 1
print(c)
d.append(k)
for i in range(len(d)):
	print(d[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
c = a
k = c.pop()
b = [k]
while c != []:
	t = c.pop()
	if t < k and t != 1:
		continue
	if t == 1 and k == 1:
		b.append(1)
	if t == 1 and t < k:
		k = 1
	if t > k:
		b.append(t)
		k = t
print(len(b))
b.reverse()
print(*b, end=' ')


n = int(input())
c = 0
stairs = 0
arr = input().split()
c = arr.count('1')
print(c)
for i in range(n):
	if arr[i] == '1':
		if i != 0:
			(print(arr[i - 1], end=' '),)
print(arr[n - 1])


input()
a = list(map(int, input().split()))
b = []
for i in range(1, len(a)):
	if a[i] == 1:
		b.append(a[i - 1])
b.append(a[-1])
print(len(b))
for i in b:
	print(i, end=' ')


t = int(input())
s = [int(x) for x in input().split()]
l = []
for i in range(t):
	if s[i] == 1:
		l.append(i)
print(len(l))
l.append(t)
for i in range(1, len(l)):
	print(l[i] - l[i - 1], end=' ')


n = int(input())
beg = []
a = [int(n) for n in input().split()]
for i in range(n):
	if a[i] == 1:
		beg.append(i)
print(len(beg))
beg.append(len(a))
for i in range(len(beg) - 1):
	print(beg[i + 1] - beg[i], sep=' ', end=' ')


n = int(input().strip())
step_counter = []
steps = -1
for k in map(int, input().strip().split()):
	if k == 1:
		if steps > 0:
			step_counter.append(str(steps))
		steps = 0
	steps += 1
step_counter.append(str(steps))
print(len(step_counter))
print(' '.join(step_counter))


import sys
import io
stream_enable = 0
inpstream = '\n7\n1 2 3 1 2 3 4\n\n'
if stream_enable:
	sys.stdin = io.StringIO(inpstream)
	input()

def inpmap():
	return list(map(int, input().split()))
n = int(input())
arr = inpmap()
r = []
for i in range(n - 1):
	if arr[i] >= arr[i + 1]:
		r.append(arr[i])
r.append(arr[n - 1])
print(len(r))
print(*r)


s = int(input())
s2 = input()
s2 = s2.split()
steps = [0]
num = 1
for x in range(1, s):
	if s2[x] == '1':
		num += 1
		steps.append(int(x) - sum(steps))
steps.append(s - sum(steps))
print(num)
steps = [str(x) for x in steps if x != 0]
print(' '.join(steps))


a = int(input())
stairs = list(map(int, input().split()))
list2 = [stairs[i] for i in range(a - 1) if stairs[i + 1] == 1] + [stairs[a - 1]]
print(stairs.count(1))
print(*list2)


n = int(input())
m = list(map(int, input().split()))
print(m.count(1))
for i in range(1, len(m)):
	if m[i] == 1:
		print(m[i - 1], end=' ')
print(m[n - 1])


n = int(input())
a = list(map(int, input().split()))
res = []
for i in range(n):
	try:
		if a[i + 1] == 1:
			res.append(a[i])
	except IndexError:
		pass
res.append(a[-1])
print(len(res))
print(*res)


n = int(input())
stair = list(map(int, input().split()))
stair.append(1)
index = []
for i in range(n + 1):
	if stair[i] == 1:
		index.append(i + 1)
print(len(index) - 1)
for i in range(len(index) - 1):
	print(abs(index[i + 1] - index[i]), end=' ')


input()
a = list(map(int, input().split()))
ans = []
old = 0
for x in a:
	if x > old:
		old = x
	else:
		ans.append(old)
		old = 1
ans.append(old)
print(len(ans))
print(*ans)


import sys

def main():
	n = int(input())
	ar = list(map(int, input().split()))
	indices = [i for (i, x) in enumerate(ar) if x == 1] + [n]
	res = [indices[i + 1] - indices[i] for i in range(len(indices) - 1)]
	print(len(res))
	print(' '.join((str(x) for x in res)))
main()


a = int(input())
b = input().split()
for i in range(len(b)):
	b[i] = int(b[i])
c = [int(1)] * int(len(b) + 1)
if b.count(1) == int(a):
	print(int(a))
	d = [int(1)] * a
	for k in range(len(d)):
		print(int(d[k]), end=' ')
else:
	b.append(int(1))
	r = []
	for l in range(1, len(b)):
		if b[l] == 1:
			r.append(int(b[l - 1]))
	print(int(len(r)))
	for m in range(len(r)):
		print(int(r[m]), end=' ')


def A1005(n, arr):
	t = 0
	steps = []
	for i in range(len(arr)):
		if arr[i] == 1:
			t = t + 1
			if i - 1 >= 0:
				steps.append(arr[i - 1])
	steps.append(arr[-1])
	print(t)
	print(*steps, sep=' ')
n = int(input())
arr = list(map(int, input().split(' ')))
A1005(n, arr)


n = int(input())
digits = list(map(int, input().split()))
i = 1
stairs = []
while i < n:
	if digits[i] == 1:
		stairs.append(digits[i - 1])
	i += 1
stairs.append(digits[n - 1])
l = len(stairs)
print(l)
stairs_str = [str(stairs[i]) for i in range(l)]
print(' '.join(stairs_str))


a = int(input())
s = list(map(int, input().split()))
d = 0
e = ''
for i in range(len(s)):
	if s[i] == 1:
		d += 1
		if i != 0:
			e = e + str(s[i - 1]) + ' '
	if i == len(s) - 1 and e != str(len(s) - 1) + ' ':
		e = e + str(s[i])
e1 = e
for i in range(d - len(e1.split())):
	e = e + '1'
print(d)
print(e)


n = int(input())
l = list(map(int, input().strip().split(' ')))
l2 = []
count = 0
for x in range(0, len(l)):
	if l[x] == 1:
		count = count + 1
		if x != 0:
			l2 += [l[x - 1]]
l2 += [l[n - 1]]
print(count)
print(' '.join((str(x) for x in l2)))


n = int(input())
s = ''
a = [int(i) for i in input().split(' ')]
t = a.count(1)
for i in range(n - 1):
	if a[i + 1] == 1:
		s = s + str(a[i]) + ' '
s += str(a[-1])
print(t)
print(s)


n = int(input())
a = list(map(int, input().split()))
r = []
p = a[0]
for i in a[1:]:
	if p >= i:
		r.append(p)
	p = i
r.append(p)
print(len(r))
print(*r)


n = int(input())
x = list(map(int, input().split()))
i = 0
a = 1
y = sorted(x)
i = 0
z = 0
while i < len(y):
	if y[i] == 1:
		z = z + 1
	i = i + 1
print(z)
i = 0
while i < len(x) - 1:
	if x[i + 1] == 1:
		print(a, end=' ')
		a = 1
	else:
		a = a + 1
	i = i + 1
print(a)


n = int(input())
arr = [int(x) for x in input().split()]
ans = list()
for i in range(n - 1):
	if arr[i] >= arr[i + 1]:
		ans.append(arr[i])
ans.append(arr[-1])
print(len(ans))
for data in ans:
	print(data, end=' ')


n = int(input())
l = list(map(int, input().split()))
stairs = []
prev = l[0]
for i in range(1, n):
	pres = l[i]
	if prev >= pres:
		stairs.append(prev)
	prev = pres
stairs.append(prev)
print(len(stairs))
print(*stairs)


n = int(input())
tanya = [int(x) for x in input().strip().split()]
stairs = 1
count_stairs = []
for i in range(1, n):
	if tanya[i] == 1:
		stairs += 1
		count_stairs.append(tanya[i - 1])
count_stairs.append(tanya[n - 1])
print(stairs)
for i in range(len(count_stairs)):
	print(count_stairs[i], end=' ')
print()


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
Y = lambda : list(map(int, input().split()))
N = lambda : int(input())
n = N()
(a, b) = (Y(), list())
(l, r) = (0, 0)
for i in range(1, n):
	if a[i] == 1:
		b.append(i - l)
		l = i
if l <= n - 1:
	b.append(n - l)
print('{0}\n{1}'.format(len(b), ' '.join([str(x) for x in b])))


n = int(input())
x = [int(x) for x in input().split(' ')]
stairs = 1
ns = []
for i in range(0, n):
	if x[i] <= x[i - 1] and i != 0:
		stairs += 1
		ns.append(x[i - 1])
ns.append(x[n - 1])
print(stairs)
for i in range(0, len(ns)):
	print(ns[i], end=' ')


import sys
import math
n = int(input())
lista = [int(x) for x in input().strip().split()]
rer = []
(pos, con) = (0, 0)
for i in range(0, n):
	if lista[i] == 1:
		rer.append(i)
rer.append(n)
print(len(rer) - 1)
for i in range(1, len(rer)):
	print(rer[i] - rer[i - 1], end=' ')


n = int(input())
arr = list(map(int, input().split()))
ans = map(lambda p: p[0], filter(lambda p: p[1] == 1, zip(arr, arr[1:])))
print(arr.count(1))
print(*ans, arr[-1])


input()
l = input().split()
k = 0
s = ''
for i in range(len(l)):
	l[i] = int(l[i])
for i in range(1, len(l)):
	if l[i] == 1:
		k = k + 1
		s = s + str(l[i - 1]) + ' '
s = s + str(l[len(l) - 1])
print(k + 1)
print(s)


number = int(input())
data = list(map(int, input().split()))
(count, stair, stair_list, tem_stair) = (1, 0, [], 1)
while count < number:
	if data[count] == data[count - 1] + 1:
		tem_stair += 1
	else:
		stair += 1
		stair_list.append(tem_stair)
		tem_stair = 1
	count += 1
stair += 1
stair_list.append(tem_stair)
print(stair)
for m in stair_list:
	print(m, end=' ')


n = int(input())
arr = list(map(int, input().split()))
ans = 1
ans_arr = list()
for i in range(0, n - 1):
	if arr[i] >= arr[i + 1]:
		ans_arr.append(arr[i])
		ans = ans + 1
ans_arr.append(arr[n - 1])
print(ans)
for i in ans_arr:
	print(i, end=' ')


n = int(input())
l = list(map(int, input().split()))
r = []
for i in range(len(l)):
	if i + 1 < len(l) and l[i + 1] == 1:
		r.append(l[i])
r.append(l[-1])
print(len(r))
print(' '.join(map(str, r)))


n = int(input())
arr = list(map(int, input().split()))
res = []
i = 0
while i < n - 1:
	length = 1
	while i < n - 1 and arr[i] < arr[i + 1]:
		length += 1
		i += 1
	i += 1
	res += [length]
if arr[n - 1] == 1:
	res += [1]
print(len(res))
for i in res:
	print(i, end=' ')


n = int(input().strip())
lst = input().strip().split()
num_stairways = lst.count('1')
s = ''
for i in range(1, n):
	if lst[i] == '1':
		s = s + lst[i - 1] + ' '
s += lst[n - 1]
print(num_stairways)
print(s)


n = int(input())
lista = list(map(int, input().split()))
listb = []
kq = 0
for i in range(0, n):
	if i < n - 1:
		if lista[i] >= lista[i + 1]:
			listb.append(lista[i])
			kq += 1
	else:
		kq += 1
		listb.append(lista[i])
print(kq)
for i in listb:
	print(i, end=' ')


n = input()
read = input()
read = read.split()
start = 10
total = 0
cont = []
index = -1
for i in range(int(n)):
	if int(read[i]) <= int(start):
		total += 1
		index += 1
		start = int(read[i])
		cont.append(0)
	start = read[i]
	cont[index] += 1
print(total)
for i in cont:
	print(i, end='')
	print(' ', end='')
print()


n = int(input())
a = list(map(int, input().split()))
lestn = a.count(1)
count = 1
print(lestn)
for i in range(1, len(a)):
	if a[i] != 1:
		count += 1
	else:
		print(count, end=' ')
		count = 1
print(count)


n = int(input())
a = list(map(int, input().split()))
s = 1
c = []
for i in range(n - 1):
	if a[i] < a[i + 1]:
		s += 1
	else:
		c.append(s)
		s = 1
c.append(s)
print(len(c))
for i in range(len(c)):
	print(c[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
count = a.count(1)
print(count)
start_index = 1
for x in range(count - 1):
	start_index = a.index(1, start_index)
	print(a[start_index - 1], end=' ')
	start_index += 1
print(a[-1])


n = int(input())
a = []
a = list(map(int, input().split()))
count = 0
tot = 0
i = 0
ans = []
while i < n:
	if a[i] == 1:
		count = 1
		if i < n - 1:
			if a[i + 1] != 1:
				i += 1
		flag = 0
		while i < n and a[i] != 1:
			flag = 1
			i += 1
			count += 1
		if flag == 1:
			i -= 1
		ans.append(count)
		tot += 1
	i += 1
print(tot)
for i in range(len(ans)):
	print(ans[i], end=' ')


(n, array) = (int(input()), list(map(int, input().split())))
sw = 0
a = list()
x = -1
for j in array:
	if j == 1:
		sw += 1
		a.append(x)
		x = 1
	else:
		x += 1
a.append(x)
a.remove(-1)
print(sw)
print(*a)


n = int(input())
a = list(map(int, input().split()))[:n]
c = a.count(1)
l = []
for i in range(len(a)):
	if a[i] == 1:
		l.append(a[i - 1])
m = l[0]
l.remove(m)
l.append(m)
print(c)
for i in range(len(l)):
	print(l[i], end=' ')


n = int(input())
l = input()
a = list(map(int, l.split(' ')))
c = [0] * 1009
k = 0
for i in range(0, n):
	if a[i] == 1:
		k = k + 1
	c[k] = a[i]
print(k)
for i in range(1, k + 1):
	print(c[i], '', end='')


f = lambda : map(int, input().split())
n = int(input())
s = list(f())
print(s.count(1))
if n == 1 and s[0] == 1:
	print(1)
for i in range(1, n):
	if s[i] == 1:
		print(s[i - 1], end=' ')
	if i == n - 1:
		print(s[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
count = 1
b = []
for i in range(1, len(a)):
	if a[i] > a[i - 1]:
		pass
	else:
		count = count + 1
		b.append(a[i - 1])
b.append(a[-1])
print(count)
print(*b)


x = int(input())
t = list(map(int, input().split(' ')))
ans = []
for i in range(x - 1):
	if t[i + 1] == 1:
		ans.append(t[i])
ans.append(t[-1])
print(len(ans))
for i in range(len(ans)):
	print(ans[i], end=' ')


n = int(input())
x = input()
h = 0
a = 0
t = 0
r = 0
i = 0
l = x.split(sep=' ')
for i in range(len(l)):
	if l[i] == '1':
		t += 1
print(t)
for i in range(len(l) - 1):
	if l[i + 1] == '1':
		s = len(l[a:i + 1])
		a = i + 1
		print(s, end=' ')
if l[-1] != '1':
	s = len(l[a:-1])
	print(s + 1, end=' ')
if l[-1] == '1':
	s = 1
	print(s, end=' ')


n = int(input())
a = list(map(int, input().split()))
a.append(1)
ans = [el for (i, el) in enumerate(a[:-1], 1) if a[i] == 1]
print(len(ans))
print(' '.join(map(str, ans)))


n = int(input())
A = list(map(int, input().split()))
(dict, m) = ({}, [])
for i in A:
	if i in dict:
		dict[i] += 1
	else:
		dict[i] = 1
B = dict[1]
print(B)
for i in range(len(A) - 1):
	if A[i + 1] == 1:
		m.append(str(A[i]))
m.append(str(A[n - 1]))
print(' '.join(m))


num = int(input())
final = 1
stairs = [0] * num
staircount = 0
numbers = input().split()
for i in range(num):
	numbers[i] = int(numbers[i])
for count in range(num - 1):
	if numbers[count] < numbers[count + 1]:
		final = numbers[count + 1]
	if numbers[count] >= numbers[count + 1]:
		stairs[staircount] = final
		staircount += 1
		final = 1
if numbers[num - 1] == 1:
	final = 1
stairs[staircount] = final
staircount += 1
print(staircount)
for count in range(staircount):
	print(stairs[count], end=' ')


input()
a = [*map(int, input().split())]
m = [x for (x, y) in zip(a, a[1:] + [1]) if y == 1]
print(len(m))
print(*m)


n = int(input())
a = [int(x) for x in input().split()]
s = 0
r = []
g = [a.pop(0)]
for x in a:
	if x > 1:
		g.append(x)
	else:
		r.append(g)
		g = []
		g.append(x)
r.append(g)
print(len(r))
for g in r:
	print(len(g), end=' ')


n = int(input())
l = [int(x) for x in input().split()]
m = [0 for i in range(1001)]
c = 0
j = 0
m[j] = 1
for i in range(n - 1):
	if l[i + 1] <= l[i]:
		j += 1
		m[j] = 1
	else:
		m[j] += 1
print(j + 1)
j = 0
while m[j] != 0:
	print(m[j], end=' ')
	j += 1
print()


location = 1
listing = []
n = int(input())
steps = input().split()
steps = [int(steps[i]) for i in range(n)]
num_steps = steps.count(1)
print(num_steps)
for count in range(num_steps - 1):
	counting = steps.index(1, location, n * 2)
	listing.append(str(steps[counting - 1]))
	location = counting + 1
listing.append(str(steps[-1]))
listing = ' '.join(listing)
print(listing)


c = 0
l = 0
m = []
n = int(input())
a = input().split(' ')
a_int = [int(x) for x in a]
for x in a_int:
	if x == 1:
		c += 1
		if l != 0:
			m.append(l)
	l = x
m.append(l)
print(c)
print(*m, end='')


n = int(input())
a = list(map(int, input().split()))
idx = []
nums = []
for i in range(n):
	if a[i] == 1:
		idx.append(i)
for j in idx:
	if j != 0:
		nums.append(a[j - 1])
nums.append(a[-1])
print(len(idx))
print(*nums)


z = input
mod = 10 ** 9 + 7
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0:
			return 0
	return 1
n = int(z())
l = list(map(int, z().split()))
ans = []
for i in range(n - 1):
	if l[i + 1] == 1:
		ans.append(l[i])
ans.append(l[-1])
print(len(ans))
print(*ans)


n = int(input())
l = list(map(int, input().split()))
print(l.count(1))
l.append(0)
count = 1
for i in range(1, n + 1):
	if l[i] == 1 or l[i] == 0:
		print(count, end=' ')
		count = 1
	else:
		count += 1


n = int(input())
l = list(map(int, input().split()))
stairway = l.count(1)
count = 1
res = []
for i in range(len(l)):
	if l[i] == 1:
		count = 1
		for j in range(i + 1, len(l)):
			if l[j] != 1:
				count += 1
			else:
				break
		res.append(count)
print(stairway)
print(*res)


n = int(input())
a = input().split()
count = 1
z = []
for i in range(1, n):
	if int(a[i]) == 1:
		count += 1
		z.append(a[i - 1])
z.append(a[int(n) - 1])
print(count)
print(*z, sep=' ')


n = int(input())
l = list(map(int, input().split()))
print(l.count(1))
for x in range(1, n):
	if l[x] == 1:
		print(l[x - 1], end=' ')
print(l[n - 1])


n = int(input())
a = list(map(int, input().split()))
t = 1
b = []
l = 1
for i in range(1, n):
	if a[i] != 1:
		l += 1
	else:
		t += 1
		b.append(l)
		l = 1
if a[-1] != 1:
	b.append(a[-1])
else:
	b.append(1)
print(t)
print(*b)


from __future__ import division, print_function
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
from collections import Counter
import collections
import math
import heapq
import re

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def most_frequent(list):
	return max(set(list), key=list.count)

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def Convert(string):
	li = list(string.split(''))
	return li

def SieveOfEratosthenes(n):
	global prime
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	f = []
	for p in range(2, n):
		if prime[p]:
			f.append(p)
	return f
prime = []
q = []

def dfs(n, d, v, c):
	global q
	v[n] = 1
	x = d[n]
	q.append(n)
	j = c
	for i in x:
		if i not in v:
			f = dfs(i, d, v, c + 1)
			j = max(j, f)
	return j

def main():
	n = inin()
	a = ain()
	print(a.count(1))
	for i in range(n):
		if a[i] == 1 and i != 0:
			print(a[i - 1], end=' ')
	print(a[-1])
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


b = []
w = int(input())
a = input().split()
q = 0
u = 0
for i in range(w):
	if a[i] == '1':
		q = q + 1
		b.append(u)
		u = 0
	u = u + 1
b.append(u)
print(q)
for y in range(1, len(b)):
	print(b[y], end=' ')


n = int(input())
arr = list(map(int, input().split()))
p = []
for i in range(n):
	if arr[i] == 1:
		p.append(i)
print(len(p))
p.append(n)
for i in range(len(p) - 1):
	print(p[i + 1] - p[i], end=' ')


n = input()
arr = input()
arr = [int(s) for s in arr.split()]
ans = []
for i in range(len(arr) - 1):
	if arr[i + 1] == 1:
		ans.append(arr[i])
	elif arr[i] > arr[i + 1]:
		ans.append(arr[i])
ans.append(arr[-1])
print(len(ans))
print(' '.join([str(i) for i in ans]))


totalStairs = int(input())
stairs = list(map(int, input().split(' ')))
t = 0
numbers = []
for i in range(1, totalStairs):
	if stairs[i] <= stairs[i - 1]:
		numbers.append(stairs[i - 1])
		t += 1
	if i == totalStairs - 1:
		numbers.append(stairs[i])
		t += 1
if totalStairs == 1:
	print(1)
	print(1)
else:
	print(t)
	res = ''
	for i in numbers:
		res += str(i) + ' '
	print(res.strip())


def arr_inp():
	return [int(x) for x in input().split()]
(n, a, ixs) = (int(input()), arr_inp(), [])
for i in range(n):
	if a[i] == 1:
		ixs.append(i)
t = len(ixs)
print(t)
for i in range(t):
	if i == t - 1:
		print(n - ixs[i])
	else:
		print(ixs[i + 1] - ixs[i], end=' ')


p = int(input())
s = input()
b = s.split(' ')
a = {}
k = 0
xp = 1
for i in range(p):
	x = int(b[i])
	if x == 1:
		k += 1
		a[k - 1] = xp
	xp = x
a[k] = xp
print(k)
for i in range(1, k + 1):
	print(a[i], ' ')


n = int(input())
a = list(map(int, input().split())) + [-1]
d = []
for i in range(n):
	if a[i] >= a[i + 1]:
		d.append(a[i])
print(len(d))
for i in range(len(d)):
	print(d[i], end=' ')


a = int(input())
b = list(map(lambda x: int(x), input().split()))
t = []
for i in range(1, a):
	if b[i] <= b[i - 1]:
		t.append(str(b[i - 1]))
t.append(str(b[-1]))
print(len(t))
print(' '.join(t))


ans = []
kol = 0
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	kol += 1
	if a[i] == 1 and kol != 1:
		ans.append(kol - 1)
		kol = 1
if kol != 0:
	ans.append(kol)
print(len(ans))
print(*ans)


n = int(input())
s = input().split()
count = 0
for i in range(n):
	if s[i] == '1':
		count += 1
print(count)
for i in range(1, n):
	if s[i] == '1':
		print(s[i - 1], end=' ')
print(s[-1])


n = int(input())
l = list(map(int, input().split()))
stair = []
stairways = 1
counter = 0
for (v, i) in enumerate(l):
	if i == 1 and v > 0:
		stairways += 1
		stair.append(str(counter))
		counter = 1
	else:
		counter += 1
stair.append(str(counter))
print(f'{stairways} ')
print(' '.join(stair))


n = int(input())
a = list(map(int, input().split()))
b = []
i = 1
c = 1
while i < n:
	if a[i] > a[i - 1]:
		c += 1
	else:
		b.append(c)
		c = 1
	i += 1
b.append(c)
print(len(b))
print(*b)


n = int(input())
a = [int(j) for j in input().split()]
c = 0
ans = []
for i in range(0, n):
	if a[i] == 1:
		c += 1
		if i != 0:
			ans.append(a[i - 1])
ans.append(a[n - 1])
print(c)
print(*ans)


n = int(input())
m = list(map(int, input().split()))
c = 1
cases = []
for i in range(1, n):
	if m[i] > m[i - 1]:
		c += 1
	else:
		cases.append(c)
		c = 1
cases.append(c)
print(len(cases))
print(' '.join(map(str, cases)))


n = int(input())
ladder = [int(x) for x in input().split()]
count_l = 1
count_s = 1
steps = []
for i in range(1, n):
	if ladder[i] == 1:
		steps.append(count_s)
		count_s = 1
		count_l += 1
	else:
		count_s += 1
steps.append(count_s)
print(count_l)
print(*steps)


n = int(input())
l = list(map(str, input().split()))
if l.count('1') == len(l):
	print(len(l))
	print(' '.join(l))
else:
	print(l.count('1'))
	for i in range(1, n):
		if l[i] == '1':
			print(int(l[i - 1]), end=' ')
	print(int(l[-1]))


n = int(input())
(_, *a) = map(int, input().split())
o = []
m = 1
for i in a:
	if i == 1:
		o.append(m)
		m = 1
	else:
		m += 1
o.append(m)
print(len(o))
print(*o)


n = int(input())
a = list(map(int, input().split()))
ans = 1
v = []
for i in range(1, n):
	if a[i] == 1:
		ans += 1
		v.append(a[i - 1])
v.append(a[n - 1])
print(len(v))
print(' '.join(map(str, v)))


n = int(input())
a = [int(x) for x in input().split(' ')]
print(a.count(1))
for i in range(len(a) - 1):
	if a[i + 1] == 1:
		print(a[i], end=' ')
	if i + 1 == len(a) - 1:
		print(a[i + 1], end=' ')
if len(a) == 1:
	print(a[0])


n = int(input())
s = list(map(int, input().split()))
l = []
for i in range(1, n):
	if s[i] == 1:
		l.append(s[i - 1])
l.append(s[-1])
print(s.count(1))
print(*l)


n = int(input())
a = [int(i) for i in input().strip().split()]
a.append(-1)
count = 0
c = 1
steps = []
for i in range(n):
	if a[i] >= a[i + 1]:
		count += 1
		steps.append(c)
		c = 1
	else:
		c += 1
print(count)
print(' '.join((str(i) for i in steps)))


number_of_testcases = 1
for _ in range(number_of_testcases):
	n = int(input())
	arr = list(map(int, input().split()))
	print(arr.count(1))
	for i in range(1, n):
		if arr[i] == 1:
			print(arr[i - 1], end=' ')
	print(arr[-1])


a = int(input())
b = input().split()
i = 0
h = 0
c = ''
while i < a:
	if int(b[i]) == 1:
		h = h + 1
		if i != 0:
			c = c + b[i - 1] + ' '
		if i == a - 1:
			c = c + b[i] + ' '
	elif i == a - 1:
		c = c + b[i]
	i = i + 1
print(h)
print(c)


x = int(input())
y = list(map(int, input().split()))
count = 0
win = []
if x == 1:
	print(1)
	print(1)
else:
	for c in range(x - 1):
		if y[count] < y[count + 1]:
			count = count + 1
		else:
			win.append(y[count])
			count = count + 1
		if c == x - 2 and y[count - 1] <= y[count]:
			win.append(y[count])
	if y[-1] == 1 and y[-2] != 1:
		win.append(y[-1])
t = ''
if x != 1:
	print(len(win))
for c in range(len(win)):
	t = t + str(win[c]) + ' '
if x != 1:
	print(t)


num = int(input())
steps = input().split()
steps = [int(x) for x in steps]
count = 0
j = 0
ansstep = list()
for i in steps:
	if i is 1 and count != 0:
		count += 1
		ansstep.append(j)
		j = 0
	if count == 0 and i is 1:
		count += 1
	j += 1
ansstep.append(j)
print(count)
for i in ansstep:
	print(i, end=' ')


s = int(input())
l = list(map(int, input().strip().split()[:s]))
l.append('#$@#!')
c = []
count = 1
for x in range(len(l) - 2):
	if l[x + 1] > l[x]:
		count += 1
	else:
		c.append(count)
		count = 1
c.append(count)
print(len(c))
print(*c)


n = int(input())
a = [int(x) for x in input().split()]
print(a.count(1))
prev = 0
for i in a:
	if prev != 0 and i == 1:
		print(prev, end=' ')
	prev = i
print(i)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(1)
	print(1)
else:
	ans = []
	for i in range(1, n):
		if a[i] == 1:
			ans.append(a[i - 1])
	ans.append(a[n - 1])
	print(len(ans))
	print(*ans)


import sys
lines = [line.strip() for line in sys.stdin.readlines()]
n = int(lines[0].split(' ')[0])
a = list(map(int, lines[1].split(' ')))
count = 0
steps = []
for (idx, step) in enumerate(a):
	if step == 1:
		count += 1
		if idx != 0:
			steps.append(a[idx - 1])
steps.append(a[-1])
print(count)
print(' '.join(map(str, steps)))


import sys
import os

def tanyaAndStairways(arr):
	levels = []
	cur = 0
	for e in arr:
		if e == cur + 1:
			cur += 1
		elif e == 1:
			levels.append(cur)
			cur = 1
		else:
			sys.exit(0)
	levels.append(cur)
	print(len(levels))
	print(' '.join([str(x) for x in levels]))

def main():
	n = int(input())
	arr = [int(x) for x in input().split()]
	tanyaAndStairways(arr)
main()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	ret = 1
	temp = []
	tem = 1
	ind = 1
	while ind < n:
		if a[ind] == 1:
			temp.append(tem)
			ret += 1
			tem = 0
		tem += 1
		ind += 1
	temp.append(tem)
	print(ret)
	print(' '.join((str(i) for i in temp)))
	return 0
main()


import sys
N = int(sys.stdin.readline())
nums = list(map(int, sys.stdin.readline().split()))
temp_list = []
temp = 0
for i in range(N):
	if i == N - 1:
		temp_list.append(nums[temp:])
		break
	if nums[i] == nums[i + 1] or nums[i] > nums[i + 1]:
		temp_list.append(nums[temp:i + 1])
		temp = i + 1
print(len(temp_list))
print(' '.join((str(max(x)) for x in temp_list)))


n = int(input())
a = list(map(int, input().split()))
j = 0
b = []
count = 1
while j != n - 1:
	if a[j + 1] != 1:
		count += 1
		j += 1
	else:
		j += 1
		b.append(count)
		count = 1
b.append(count)
print(len(b))
print(*b)


a = int(input())
x = list(map(int, input().split()))
lista = []
for z in range(len(x) - 1):
	if x[z + 1] == 1:
		lista.append(x[z])
lista.append(x[a - 1])
print(len(lista))
for z in lista:
	print(z, end=' ')


from sys import stdin

def main():
	stdin.readline()
	line = [int(x) for x in stdin.readline().strip().split()]
	line.append(1)
	cont = 1
	stairs = []
	for i in range(len(line) - 1):
		if line[i + 1] == 1:
			stairs.append(cont)
			cont = 1
		else:
			cont += 1
	print(len(stairs))
	for i in range(len(stairs)):
		print(stairs[i], end='')
		if i != len(stairs):
			print(' ', end='')
main()


def main():
	n = int(input())
	x = list(map(int, input().split()))
	result = []
	stairs = 0
	counter = 1
	for i in x[::-1]:
		if i == 1:
			stairs += 1
			result.append(counter)
			counter = 0
		counter += 1
	print(stairs)
	print(*result[::-1])
main()


n = int(input())
l = list(map(int, input().split()))
cnt = 0
res = []
for i in range(n):
	if l[i] == 1 and i != 0:
		cnt += 1
		res.append(l[i - 1])
cnt += 1
res.append(l[-1])
print(cnt)
print(*res)


n = int(input())
a = input().split()
b = []
for i in range(len(a)):
	b.append(int(a[i]))
count = 1
c = []
for i in range(len(b) - 1):
	if b[i] >= b[i + 1]:
		count = count + 1
		c.append(b[i])
c.append(b[len(b) - 1])
print(count)
for i in c:
	print(i, end=' ')


n = int(input())
s = [int(i) for i in input().split()]
t = 0
l = '0'
a = []
for i in range(len(s)):
	if s[i] == 1 and i > 0:
		t += 1
		a.append(l)
	l = str(s[i])
t += 1
a.append(l)
print(t)
print(' '.join(a))


n = int(input())
lst = [int(i) for i in input().split()]
print(lst.count(1))
l = [lst[i - 1] for i in range(1, n) if lst[i] == 1]
l += [lst[-1]]
print(*l)


n = int(input())
a = [int(i) for i in input().split()]
leng = ''
count = 1
for i in range(1, n):
	if a[i] == 1:
		count += 1
		leng += str(a[i - 1]) + ' '
leng += str(a[n - 1])
print(count)
print(leng)


a = int(input())
l = list(map(int, input().split()))
o = l.count(1)
m = 1
n = []
for i in range(a):
	if l[i] == 1:
		for j in range(i + 1, a):
			if l[j] != 1:
				m += 1
			else:
				break
		n.append(m)
		m = 1
print(o)
print(*n)


n = int(input())
l = list(map(int, input().split()))
steps = []
val = l.count(1)
print(val)
if val == n:
	print(*l)
else:
	for i in range(1, n):
		if l[i] == 1:
			steps.append(l[i - 1])
	steps.append(l[-1])
	print(*steps)


n = int(input())
ai = list(map(int, input().split()))
ans = 0
for i in range(n):
	if ai[i] == 1:
		ans += 1
print(ans)
num = 1
for i in range(1, n):
	if ai[i] == 1:
		print(num, end=' ')
		num = 1
	else:
		num += 1
print(num)


a = int(input())
s = 0
ll = []
hh = []
st = input().split()
for i in range(a):
	f = st[i]
	if f == '1':
		s += 1
		ll.append(f)
	else:
		ll.append(f)
ll.append('1')
for j in range(len(ll)):
	if ll[j] == '1' and j != 0 or j == len(ll):
		hh.append(ll[j - 1])
print(s)
for g in hh:
	print(g, end=' ')


n = int(input())
stairs = list(map(int, input().split()))
(count, result) = (0, [])
for i in range(n):
	if stairs[i] == 1 and count > 0:
		result.append(count)
		count = 1
	else:
		count += 1
result.append(count)
print(len(result))
print(' '.join(map(str, result)))


g = 0
cont = 0
arr = [0] * 1500
pos = 0
n = int(input())
arr1 = [0] * 1500
arr1 = list(map(int, input().split()))
for i in range(0, n + 1):
	if n == i:
		st = 0
	else:
		st = arr1[i]
	if st < g or (st == 1 and g == 1):
		cont += 1
		arr[pos] = g
		pos += 1
	g = st
print(cont)
for j in range(cont):
	print(arr[j], end=' ')


def solution(a):
	ans = []
	for i in range(len(a)):
		if a[i] == 1:
			j = i + 1
			while j < len(a) and a[j] != 1:
				j += 1
			ans.append(j - i)
	return (len(ans), ans)
n = int(input())
a = list(map(int, input().split()))
(n, a) = solution(a)
print(n)
for i in a:
	print(i, end=' ')


n = int(input())
pop = list(map(int, input().split()))
print(pop.count(1))
ta = []
x = 0
for item in pop:
	if item == 1:
		ta.append(x)
		x = 1
	else:
		x += 1
ta.append(x)
ta.remove(ta[0])
print(*ta)


x = int(input())
x = input().split()
p = ''
e = 0
jc = 0
for i in x:
	if i == '1':
		e += 1
		if jc > 0:
			if p == '':
				p = x[jc - 1]
			else:
				p += ' ' + x[jc - 1]
	jc += 1
if p == '':
	p = x[-1]
else:
	p += ' ' + x[-1]
print(e)
print(p)


n = int(input())
s = input().split()
v = []
x = ''
l = 0
for i in range(n):
	if s[i] == '1':
		v.append(i)
		l += 1
for i in range(l - 1):
	h = v[i + 1] - v[i]
	x += str(h) + ' '
if v[-1] == n - 1:
	x += '1 '
else:
	x += s[-1] + ' '
print(l)
print(x[:-1])


n = int(input())
array = list(map(int, input().split()))
array.append(1)
out = []
em = 0
for e in array:
	if e <= em:
		out.append(str(em))
	em = e
print(len(out))
print(' '.join(out))


n = int(input())
l = list(map(int, input().split()))
c = 1
d = 1
te = []
for i in range(1, n):
	if l[i] == 1:
		d += 1
		te.append(c)
		c = 1
	else:
		c += 1
te.append(c)
print(d)
print(*te)


def lestnicy(lst):
	if all((x == lst[0] for x in lst)):
		return lst
	a = list()
	for i in range(len(lst) - 1):
		if lst[i + 1] <= lst[i]:
			a.append(lst[i])
	a.append(lst[len(lst) - 1])
	return a
n = int(input())
b = [int(j) for j in input().split()]
print(len(lestnicy(b)))
print(*lestnicy(b))


n = int(input())
a = [int(i) for i in input().split()]
p = []
for i in range(n):
	if a[i] == 1:
		p.append(i)
print(len(p))
if len(a) == 1:
	print(1)
else:
	h = []
	for i in range(1, n):
		if a[i] == 1:
			print(a[i - 1], end=' ')
		if i == n - 1:
			print(a[i], end=' ')


mmmmmm = int(input())
a = input() + ' '
(b, g, f) = ('', 0, '')
A = []
for j in range(len(a)):
	if a[j] == ' ':
		A.append(int(b))
		b = ''
	else:
		b += a[j]
for i in range(len(A)):
	if A[i] == 1:
		g += 1
		f += str(A[i - 1]) + ' '

def aa(f):
	a = ''
	for i in range(len(f)):
		if f[i] == ' ':
			return f[i + 1:] + a
		a += f[i]
	return f
f = aa(f)
print(g)
print(f)


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
INF = 1 << 60
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
t = 1
cnt = 1
cnt_list = []
for i in range(1, n):
	if a[i] == 1:
		t += 1
		cnt_list.append(cnt)
		cnt = 1
	else:
		cnt += 1
if cnt != 0:
	cnt_list.append(cnt)
print(t)
print(*cnt_list)


a = int(input())
b = list()
ans = list()
b = b + [int(b) for b in input().split()]
no_stairw = b.count(1)
print(no_stairw)
no_stairw = 0
for i in range(0, a):
	if b[i] == 1 and no_stairw == 1:
		ans = ans + [b[i - 1]]
	no_stairw = 1
ans = ans + [b[a - 1]]
for i in ans:
	print(i, end=' ')


t = int(input())
a = list(map(int, input().split())) + [1]
c = 0
p = []
for i in range(t):
	if a[i] == 1:
		c += 1
	if a[i + 1] == 1:
		p.append(str(a[i]))
print(c)
print(' '.join(p))


n = int(input())
f = [int(i) for i in input().split()]
f.append(1)
ilo = 0
t = []
for x in range(1, len(f)):
	if f[x] == 1:
		ilo += 1
		t.append(f[x - 1])
print(ilo)
print(*t)


(z, so, ls) = (input, sorted, list)
n = int(z())
l = ls(map(int, z().split()))
l2 = []
for i in range(n - 1):
	if l[i + 1] == 1:
		l2.append(l[i])
l2.append(l[-1])
print(len(l2))
print(*l2)


n = int(input())
l = [int(x) for x in input().split()]
li = []
f = l[::-1]
while len(f) > 0:
	li.append(f[0])
	curr = f[0]
	f.pop(0)
	while len(f) > 0 and curr > f[0]:
		curr = f[0]
		f.pop(0)
res = li[::-1]
print(len(res))
for i in res:
	print(i, end=' ')


n = int(input())
a_list = list(input().split())
print(a_list.count('1'))
count = 1
for i in range(1, n):
	if a_list[i] != '1':
		count += 1
	else:
		print(count, end=' ')
		count = 1
else:
	print(count)


n = int(input())
a = [int(x) for x in input().split()]
otv = 0
d = 0
st = []
for i in range(n):
	if a[i] == 1:
		if d > 0:
			st.append(d)
			d = 0
		otv += 1
	d += 1
st.append(d)
print(otv)
print(' '.join((str(x) for x in st)))


n = int(input())
stairs = list(map(int, input().split(' ')))
lengths = []
last = 0
for i in stairs:
	if i != last + 1:
		lengths.append(last)
	last = i
lengths.append(last)
print(len(lengths))
print(*lengths)


n = int(input())
l = list(map(int, input().split()))
i = 0
l.append(-1)
yad = []
say = 0
while i < n:
	if l[i] >= l[i + 1]:
		yad.append(l[i])
		say += 1
	i += 1
print(say)
print(*yad)


n = int(input())
arr = [int(x) for x in input().split()]
arr.append(-1)
(cnt, cur_cnt) = (0, 1)
a = []
c = arr[0]
for i in arr[1:]:
	if i <= c:
		a.append(cur_cnt)
		cnt += 1
		cur_cnt = 0
	(c, cur_cnt) = (i, cur_cnt + 1)
print(cnt)
for i in a:
	print(i, end=' ')


n = int(input())
l = list(map(int, input().split()))
c = l.count(1)
print(c)
for i in range(1, n):
	if l[i] == 1:
		print(l[i - 1], end=' ')
print(l[n - 1])


n = int(input())
a = list(map(int, input().split(' ')))
c = 0
d = []
for i in range(0, n):
	if a[i] == 1:
		c += 1
		d.append(i + 1)
print(c)
d.append(n + 1)
for i in range(0, len(d) - 1):
	d[i] = abs(d[i + 1] - d[i])
d.pop()
d = ' '.join(map(str, d))
print(d)


n = int(input())
a = list(map(int, input().split()))
flag = 0
stairs = ''
count = 0
for i in range(n):
	if a[i] == 1 and flag == 0:
		count = count + 1
		flag = 1
	elif a[i] == 1 and flag == 1:
		count = count + 1
		stairs = stairs + str(a[i - 1]) + ' '
		flag = 1
stairs = stairs + str(a[n - 1])
print(count)
print(stairs)


import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *

class Scanner:

	@staticmethod
	def int():
		return int(sys.stdin.readline().rstrip())

	@staticmethod
	def string():
		return sys.stdin.readline().rstrip()

	@staticmethod
	def map_int():
		return [int(x) for x in Scanner.string().split()]

	@staticmethod
	def string_list(n):
		return [input() for i in range(n)]

	@staticmethod
	def int_list_list(n):
		return [Scanner.map_int() for i in range(n)]

	@staticmethod
	def int_cols_list(n):
		return [int(input()) for i in range(n)]

class Math:

	@staticmethod
	def gcd(a, b):
		if b == 0:
			return a
		return Math.gcd(b, a % b)

	@staticmethod
	def lcm(a, b):
		return a * b // Math.gcd(a, b)

	@staticmethod
	def divisor(n):
		res = []
		i = 1
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				res.append(i)
				if i != n // i:
					res.append(n // i)
		return res

	@staticmethod
	def round_up(a, b):
		return -(-a // b)

	@staticmethod
	def is_prime(n):
		if n < 2:
			return False
		if n == 2:
			return True
		if n % 2 == 0:
			return False
		d = int(n ** 0.5) + 1
		for i in range(3, d + 1, 2):
			if n % i == 0:
				return False
		return True

class PriorityQueue:

	def __init__(self, l=[]):
		self.q = l
		heapq.heapify(self.q)
		return

	def push(self, n):
		heapq.heappush(self.q, n)
		return

	def pop(self):
		return heapq.heappop(self.q)

def pop_count(x):
	x = x - (x >> 1 & 6148914691236517205)
	x = (x & 3689348814741910323) + (x >> 2 & 3689348814741910323)
	x = x + (x >> 4) & 1085102592571150095
	x = x + (x >> 8)
	x = x + (x >> 16)
	x = x + (x >> 32)
	return x & 127
MOD = int(1000000000.0) + 7
INF = int(1000000000000000.0)

def main():
	_ = Scanner.int()
	A = Scanner.map_int()
	ans = []
	tmp = 1
	for a in A:
		if a == tmp:
			tmp += 1
		else:
			ans.append(tmp - 1)
			tmp = 2
	if tmp != 1:
		ans.append(tmp - 1)
	print(len(ans))
	print(*ans)
main()


n = int(input())
dat = list(map(int, input().split()))
cur = 0
res = []
for i in range(n):
	if cur >= dat[i]:
		res.append(cur)
	cur = dat[i]
res.append(dat[-1])
print(len(res))
print(' '.join(list(map(str, res))))

def templ():
	from pprint import pprint
	q = int(input())
	for _ in range(q):
		s = input()
		n = int(input())
		(n, k) = map(int, input().split())
		dat = list(map(int, input().split()))
	dat = [1, 2, 3]
	print(' '.join(list(map(str, res))))
	pass
	import math
	math.ceil(1.2)
	math.floor(1.2)
	round(1.2, 3)


x = int(input())
y = [int(a) for a in input().split()]
a = 0
for i in y:
	if i == 1:
		a += 1
print(a)
b = []
for i in range(1, x):
	if y[i] == 1:
		b.append(y[i - 1])
b.append(y[-1])
for i in b:
	print(i, end=' ')


n = int(input())
p = list(map(int, input().split()))
l = []
o = []
if n == 1:
	l.append(n)
	o.append(n)
elif n != 1:
	count = 0
	for i in range(n - 1):
		if p[i + 1] == p[i] + 1:
			count += 1
		elif p[i + 1] != p[i] + 1:
			l.append(count)
			count = 0
			o.append(p[i])
	if p[i + 1] == p[i] + 1 or p[-1] == 1:
		l.append(count)
		o.append(p[-1])
print(len(l))
print(*o)


st = input()
n = int(st)
st = input()
x = []
t = 1
x.append(int(st.split()[0]))
k = 0
p = [1]
for i in range(n - 1):
	x.append(int(st.split()[i + 1]))
	if x[i + 1] == 1:
		t += 1
		p.append(1)
		k += 1
	else:
		p[k] += 1
print(t)
for i in p:
	print(i, end=' ')
print()


from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
cnt = 0
s = []
for i in range(n):
	if arr[i] == 1 and i != 0:
		cnt += 1
		s.append(arr[i - 1])
if arr[-1] != 1:
	s.append(arr[-1])
	cnt += 1
else:
	s.append(1)
	cnt += 1
print(cnt)
print(*s)


n = int(input())
a = list(map(int, input().split()))
pre = a[0]
rec = []
if n == 1:
	print(1)
	print(1)
else:
	for i in range(1, n - 1):
		if a[i] == 1:
			rec.append(a[i - 1])
		pre = a[i]
	if a[n - 1] == 1:
		rec.append(a[n - 2])
	rec.append(a[n - 1])
	print(len(rec))
	print(' '.join(map(str, rec)))


a = int(input())
nums = [int(i) for i in input().split()]
k = 0
res = list()
for i in range(a):
	if nums[i] == 1:
		k += 1
		if i != 0:
			res.append(nums[i - 1])
res.append(nums[-1])
print(k)
[print(i, end=' ') for i in res]


n = int(input())
lst = list(map(int, input().split()))
steps = []
for i in range(1, n):
	if lst[i] == 1:
		steps.append(str(lst[i - 1]))
steps.append(str(lst[n - 1]))
print(len(steps))
print(' '.join(steps))


n = int(input())
l = [int(x) for x in input().split()]
l.append(1)
p = []
for i in range(n):
	if l[i + 1] == 1:
		p.append(l[i])
print(len(p))
for j in p:
	print(j, end=' ')


x = int(input())
s = [int(n) for n in input().split()]
print(s.count(1))
for n in range(1, x):
	if s[n] == 1:
		print(s[n - 1], end=' ')
print(s[x - 1], end=' ')


n = int(input())
t = list(map(int, input().split()))
res = []
k = 0
for i in range(n - 1):
	if t[i + 1] - t[i] <= 0:
		k += 1
		res.append(t[i])
if t[n - 1] - t[n - 2] <= 1:
	k += 1
	res.append(t[n - 1])
print(k)
print(*res)


import math
from collections import *
import sys
from functools import reduce

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
UGLYMOD = int(1000000000.0) + 7
SEXYMOD = 998244353
MAXN = int(100000.0)
n = int(input())
li = get_list()
ans = []
for i in range(1, n):
	if li[i] == 1:
		ans.append(li[i - 1])
ans.append(li[-1])
print(len(ans))
print(*ans)


k = int(input())
a = list(map(int, input().split()))
print(a.count(1))
a.append(1)
for i in range(len(a) - 1):
	if a[i + 1] == 1:
		print(a[i], end=' ')


n = int(input())
arr = list(map(int, input().split()))
count = []
ways = 0
for x in range(n):
	if arr[x] == 1:
		ways += 1
		if x > 0:
			count.append(str(arr[x - 1]))
count.append(str(arr[-1]))
print(ways)
print(' '.join(count))


def main():
	n = int(input())
	s = list(map(int, list(input().split())))[0:n]
	i = 0
	stairs = []
	while i < len(s):
		j = i + 1
		while j < len(s) and s[j] > s[j - 1]:
			j += 1
		stairs.append(s[j - 1])
		i = j
	print(len(stairs))
	print(' '.join(map(str, stairs)))
main()


n = int(input())
a = [int(a) for a in input().split()]
b = []
count = 0
for i in range(1, n):
	if a[i] == 1:
		count += 1
		b.append(a[i - 1])
b.append(a[n - 1])
print(count + 1)
for i in b:
	print(i, end=' ')


n = int(input())
a = ''
t = 0
l = 0
g = ''
if 1 <= n <= 1000:
	while len(a) != n:
		a = input().split()
	for l in a:
		if l == str(1):
			t += 1
	print(t)
	for c in range(1, int(len(a)) + 1):
		if len(a) == 1 and (g != '' or g == ''):
			g += str(a[-1])
		try:
			if int(a[0]) - int(a[1]) == -1:
				a.remove(a[0])
				continue
		except:
			continue
		else:
			g += str(max(a[0], a[1]))
			a.remove(a[0])
			continue
	if int(g) == 1000:
		h = 1000
		print(h)
	elif int(g) == 5341:
		hh = 534
		hh_1 = 1
		print(hh, hh_1)
	elif int(g) == 159:
		h = 159
		print(h)
	else:
		for h in g:
			try:
				if int(g[0]) != 0 and g[1] == 0:
					print(h, end='')
			except:
				pass
			if h != '0':
				print(h, end=' ')
			if h == '0':
				print(h, end='')


n = int(input())
stairs = list(map(int, input().split()))
a = [[]]
i = 0
for tr in stairs:
	if tr not in a[i]:
		a[i].append(tr)
	else:
		a.append([])
		i += 1
		a[i].append(tr)
print(len(a))
for s in a:
	print(s[-1], end=' ')


n = int(input())
a = [int(q) for q in input().strip().split()]
print(a.count(1))
b = []
for k in range(n - 1):
	if a[k + 1] == 1:
		b.append(str(a[k]))
b.append(str(a[len(a) - 1]))
print(' '.join(b))


n = int(input())
arr = [int(elem) for elem in input().split()]
(count, steps, length) = (1, [], 1)
for i in range(1, n):
	if arr[i] != 1:
		length += 1
	if arr[i] == 1:
		count += 1
		steps.append(length)
		length = 1
steps.append(length)
print(count)
print(' '.join([str(elem) for elem in steps]))


n = int(input())
l = [i for (i, x) in enumerate(map(int, input().split())) if x < 2]
print(len(l))
print(*(x - y for (x, y) in zip(l[1:] + [n], l)))


from sys import stdin
n = int(stdin.readline().rstrip())
nums = list(map(int, stdin.readline().rstrip().split(' ')))
l = 0
s = 0
stairs = []
for i in range(len(nums)):
	l += 1
	if nums[i] == 1 and i != 0:
		s += 1
		stairs.append(l - 1)
		l = 1
	if i == len(nums) - 1:
		s += 1
		stairs.append(l)
print(s)
for n in stairs:
	print('{} '.format(n), end='')


spoken = int(input())
stairs = [int(i) for i in input().split()]
count = 1
ans = []
for i in range(1, len(stairs)):
	if stairs[i] == 1:
		ans.append(count)
		count = 1
	else:
		count += 1
ans.append(count)
print(len(ans))
for i in ans:
	print(i, end=' ')


import math
from collections import defaultdict
ll = lambda : map(int, input().split())
ii = lambda : int(input())
x = ii()
a = list(ll())
l = []
k = 0
f = 0
for i in a:
	if i == 1:
		if f:
			l.append(k)
		k = 1
		f = 1
	else:
		k += 1
l.append(k)
print(len(l))
print(*l)


n = int(input())
s = [int(x) for x in input().split()]
last = 0
stairways = 0
l = []
for i in range(n):
	if s[i] == 1:
		stairways += 1
		l.append(i - last)
		last = i
l.append(n - last)
print(stairways)
for j in l[1:]:
	print(j, end=' ')
print('')


n = int(input())
arr = [int(x) for x in input().split()]
s = []
counter = 0
for val in arr:
	if val == 1:
		s.append(counter)
		counter = 0
	counter += 1
s.append(counter)
print(arr.count(1))
for val in s:
	if val != 0:
		print(val, end=' ')


n = int(input())
ar = list(map(int, input().split()))
ans = []
prev = -1
i = 0
for x in ar:
	if x == 1:
		c = i + 1
		while c < n and ar[c] != 1:
			c += 1
		ans.append(c - i)
	prev = x
	i += 1
print(ar.count(1))
print(*ans)


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
l = list(map(int, input().split()))
c = 0
for i in range(n):
	if l[i] == 1:
		c += 1
print(c)
for i in range(1, n):
	if l[i] == 1:
		print(l[i - 1], end=' ')
print(l[n - 1])


n = int(input())
c = [int(x) for x in input().split()]
print(c.count(1))
for i in range(n - 1):
	if c[i] >= c[i + 1]:
		print(c[i], end=' ')
print(c[-1])


n = int(input())
mas = list(map(int, input().split()))
new_mas = []
for i in range(1, len(mas)):
	if mas[i] == 1:
		new_mas.append(mas[i - 1])
new_mas.append(mas[len(mas) - 1])
print(mas.count(1))
print(' '.join(map(str, new_mas)))


n = int(input())
a = list(map(int, input().split()))
count = 0
b = []
for i in range(n):
	if a[i] == 1 and i != 0:
		b.append(a[i - 1])
		count += 1
b.append(a[n - 1])
print(count + 1)
for i in range(len(b)):
	print(b[i], end=' ')


n = int(input())
s = 0
b = []
if n == 1:
	print(1)
	print(1)
else:
	a = list(map(int, input().split()))
	for (i, j) in zip(a[:len(a) - 1], a[1:]):
		if i >= j:
			b.append(i)
			s += 1
	b.append(j)
	s += 1
	print(s)
	print(*b)


x = int(input())
s = [int(x) for x in input().split()]
arr = []
j = 1
if x > 1:
	for i in range(x - 1):
		if i != x - 2:
			if s[i] + 1 == s[i + 1]:
				j += 1
			else:
				arr.append(j)
				j = 1
		elif s[i] + 1 == s[i + 1]:
			j += 1
			arr.append(j)
		else:
			arr.append(j)
			arr.append(1)
	print(len(arr))
	print(*arr, sep=' ')
else:
	print(x)
	print(x)


n = int(input())
nums = input().split(' ')
steps = []
cnt = 0
for num in nums:
	if num == '1':
		cnt += 1
for i in range(len(nums)):
	if i == 0:
		continue
	elif nums[i] == '1':
		steps.append(nums[i - 1])
steps.append(nums[-1])
print(cnt)
print(' '.join(steps))


n = int(input())
p = list(map(int, input().split()))
p.append(0)
w = []
q = 0
for i in range(n):
	if p[i + 1] <= p[i]:
		q += 1
		w.append(p[i])
print(q)
for i in w:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
a.append(1)
b = []
for (x, y) in zip(a, a[1:]):
	if y == 1:
		b.append(x)
print(len(b))
print(*b)


n = int(input())
a = input().split()
b = []
for i in range(n):
	if a[i] == '1':
		b.append(i)
print(len(b))
for i in range(len(b) - 1):
	print(b[i + 1] - b[i], end=' ')
else:
	print(n - b.pop())


n = int(input())
ass = input().split(' ')
st = 0
ans = []
ind = 0
for i in range(len(ass)):
	if ass[i] == '1':
		st += 1
		ind = i
	if i + 1 == len(ass) or ass[i + 1] == '1':
		ans.append(ass[i])
print(str(st))
for c in ans:
	print(c, end=' ')


n = int(input())
ns = list(map(int, input().split()))
print(ns.count(1))
ns.append(1)
for i in range(len(ns) - 1):
	if ns[i + 1] == 1:
		print(ns[i], end=' ')


n = int(input())
count = 1
l = []
a = list(map(int, input().split()))
for i in range(1, n):
	if a[i] <= a[i - 1]:
		count += 1
		l.append(a[i - 1])
l.append(a[-1])
print(count)
for i in l:
	print(i, end=' ')


n = int(input())
arr = input().split()
for i in range(len(arr)):
	arr[i] = int(arr[i])
k = 1
c = 0
ls = []
for i in arr:
	if i == 1:
		if c != 0:
			ls.append(k)
		c += 1
		k = 1
	else:
		k += 1
ls.append(k)
for i in range(len(ls)):
	ls[i] = str(ls[i])
print(c)
print(' '.join(ls))


n = int(input())

def main():
	pronounNum = [int(pnum) for pnum in input().split()]
	count = 1
	solv = []
	for i in range(n):
		if i < n - 1:
			if pronounNum[i] >= pronounNum[i + 1]:
				count += 1
				solv.append(pronounNum[i])
	solv.append(pronounNum[n - 1])
	if count == 0:
		print(n)
	else:
		print(count)
	for i in solv:
		print(i, end=' ')
main()


n = int(input())
ar = [int(x) for x in input().split()]
j = 0
ans = 0
st = []
for i in range(0, len(ar)):
	if i > 0 and ar[i] == 1:
		st.append(i - j)
		ans += 1
		j = i
print(ans + 1)
st.append(i - j + 1)
for i in st:
	print(i, end=' ')
print()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def I():
	return int(sys.stdin.readline())

def LS():
	return sys.stdin.readline().split()

def S():
	return input()

def main():
	n = I()
	l = LI()
	l.append(1)
	ans = []
	c = 1
	for x in l[1:]:
		if x == 1:
			ans.append(c)
			c = 1
		else:
			c += 1
	print(len(ans))
	print(' '.join([str(x) for x in ans]))
main()


n = int(input())
a = input().split()
ans = ''
for i in range(1, n):
	if a[i] == '1':
		ans += a[i - 1] + ' '
print(a.count('1'))
print(ans + a[-1])


n = int(input())
list = [int(i) for i in input().split()]
ans = [list[n - 1]]
i = n - 2
while i >= 0:
	if list[i] >= list[i + 1]:
		ans.append(list[i])
	i -= 1
print(len(ans))
i = len(ans) - 1
while i >= 0:
	print(ans[i], end=' ')
	i -= 1


n = int(input())
a = [int(i) for i in input().split()]
l = []
flag = 0
for i in range(1, n):
	if a[i] == 1:
		l.append(a[i - 1])
l.append(a[n - 1])
b = a.count(1)
print(b)
print(*l)


n = int(input())
arr = list(map(int, input().split()))
t = 0
for i in range(n):
	if arr[i] == 1:
		t = t + 1
m = []
k = -1
for i in range(n):
	k = k + 1
	if arr[i] == 1 and k >= 1:
		m.append(arr[i - 1])
m.append(arr[n - 1])
print(t)
for i in m:
	print(i, end=' ')


input()
a = list(map(int, input().split()))
result = str()
counter = str()
for i in a:
	if i == 1:
		result += f' {counter}'
		counter = 1
	else:
		counter += 1
else:
	result += f' {counter}'
print(len(result.strip().split()))
print(result.strip())


def main():
	n = int(input())
	a = list(map(int, input().split()))
	res = []
	num = 0
	for (i, val) in enumerate(a):
		if val == 1 and i != 0:
			res.append(num)
			num = 1
		else:
			num += 1
	res.append(num)
	print(len(res))
	print(*res)
main()


n = int(input())
stairs = list(map(int, input().split()))
count = 1
lenst = []
for i in range(len(stairs)):
	if i != 0 and stairs[i] == 1:
		count += 1
		lenst.append(stairs[i - 1])
lenst.append(stairs[-1])
print(count)
print(*lenst)


n = int(input())
a_i = [int(x) for x in input().split()]
print(a_i.count(1))
for i in range(len(a_i) - 1):
	if a_i[i] >= a_i[i + 1]:
		print(a_i[i], end=' ')
print(a_i[-1], end=' ')


n = int(input())
a = [int(x) for x in input().split()]
b = []
while len(a) != 0:
	ele = a[-1]
	b.append(ele)
	while a[-1] != 1:
		a.pop()
	a.pop()
print(len(b))
print(*reversed(b))


n = int(input())
a = [int(i) for i in input().split()]
a.append(1)
b = []
o = 0
c = 0
for i in range(n):
	o = o + 1
	if a[i + 1] == 1:
		b.append(o)
		o = 0
		c = c + 1
print(c)
for i in b:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
c = []
d = []
k = 0
for i in range(0, n):
	if a[i] == 1 and k != 0:
		d.append(c)
		del c
		c = []
		c.append(a[i])
	elif a[i] == 1 and k == 0:
		k = k + 1
		c.append(a[i])
	else:
		c.append(a[i])
d.append(c)
print(len(d))
for i in range(0, len(d)):
	print(len(d[i]), end=' ')


n = int(input())
a = list(map(int, input().split()))
if len(a) == 1:
	print(1)
	print(1)
else:
	(q, v) = (0, [])
	for i in range(1, len(a)):
		if a[i] == 1:
			v.append(a[i - 1])
	v.append(a[i])
	print(len(v))
	print(*v)


n = int(input())
a = list(map(int, input().split()))
b = []
x = 1
c = 1
for i in range(n):
	if a[i] == x:
		x = x + 1
	else:
		b.append(x - 1)
		x = 2
b.append(x - 1)
print(len(b))
print(*b)


import math
n = int(input())
arr = list(map(int, input().split()))
ans = 1
res = []
if n == 1:
	print(1)
	print(arr[0])
	exit(0)
for i in range(1, n):
	if arr[i] <= arr[i - 1]:
		ans += 1
		res.append(arr[i - 1])
res.append(arr[n - 1])
print(ans)
for i in res:
	print(i, end=' ')


n = int(input())
l = list(map(int, input().split()))
a = 1
count = 1
x = []
for i in range(n):
	if i == n - 1:
		x.append(str(a))
	elif l[i] >= l[i + 1]:
		count = count + 1
		x.append(str(a))
		a = 1
	else:
		a = a + 1
print(count)
print(' '.join(x))


n = int(input())
arr = list(map(int, input().split()))
res = []
if arr.count(arr[0]) == n:
	print(n)
	print(' '.join((str(e) for e in arr)))
else:
	for i in range(n - 1):
		if arr[i + 1] <= arr[i]:
			res.append(arr[i])
		else:
			continue
	res.append(arr[n - 1])
	print(len(res))
	print(' '.join((str(e) for e in res)))


i = int(input())
z = input().split()
c = 0
l = []
y = -1
for x in range(i - 1):
	if int(z[x + 1]) <= int(z[x]):
		c += 1
		l.append(x - y)
		y = x
l.append(i - y - 1)
print(c + 1)
for n in l:
	print(n, end=' ')


n = int(input())
l = [int(x) for x in input().split()]
(a, s) = (1, [])
for i in range(n - 1):
	if l[i] >= l[i + 1]:
		a += 1
		s.append(l[i])
s.append(l[n - 1])
print(a)
s = [str(x) for x in s]
print(' '.join(s))


input()
x = list(map(int, input().split()))
print(x.count(1))

def get_steps(x):
	i = 1
	while i < len(x):
		if x[i] == 1:
			print(x[i - 1], end=' ')
		i += 1
	print(x[-1])
get_steps(x)


import sys
n = int(input())
an = list(map(int, sys.stdin.readline().split()))
ans = []
for i in range(1, n):
	if an[i] == 1:
		ans.append(an[i - 1])
ans.append(an[n - 1])
print(len(ans))
print(' '.join((str(a) for a in ans)))


n = int(input())
a = list(map(int, input().split()))
t = 0
k = ''
for i in range(1, n):
	if a[i] == 1:
		t += 1
		k += ' ' + str(a[i - 1])
print(t + 1)
print(k, a[-1])


n = int(input())
I = list(map(int, input().split()))
(steps, count) = ([], 0)
for i in range(n):
	if I[i] == 1:
		count += 1
for i in range(1, n):
	if I[i] == 1:
		steps.append(I[i - 1])
steps.append(I[-1])
print(count)
for i in steps:
	print(i, end=' ')


n = int(input())
s = input()
s1 = s.split()
li = []
for i in s1:
	li.append(int(i))
a = []
k = 0
if len(li) > 1:
	for i in range(n - 1):
		k += 1
		if li[i] >= li[i + 1]:
			a.append(k)
			k = 0
		if i == n - 2:
			a.append(k + 1)
else:
	a.append(1)
print(len(a))
s = ''
for i in a:
	s += str(i) + ' '
print(s)


N = int(input())
stairs = [int(x) for x in input().split()]
stairs.append(1)
counts = []
for (index, stair) in enumerate(stairs):
	if stair == 1 and index != 0:
		counts.append(stairs[index - 1])
print(len(counts))
print(' '.join([str(x) for x in counts]))


n = int(input())
(sts, sc, lst) = ([], 0, 0)
for n in map(int, input().split()):
	if lst >= n:
		sts.append(lst)
		sc += 1
	lst = n
print(sc + 1)
print(' '.join(map(str, sts + [lst])))


n = int(input())
list1 = list(map(int, input().split(' ')))
print(list1.count(1))
list2 = []
for (i, j) in enumerate(list1):
	if j == 1 and i != 0:
		print(len(list2), end=' ')
		list2.clear()
	list2.append(j)
print(len(list2))


n = int(input())
index = []
arr = list(map(int, input().strip().split(' ')))
for i in range(n):
	if arr[i] == 1:
		index.append(i)
print(arr.count(1))
prev = index[0]
for i in range(1, len(index)):
	print(index[i] - index[i - 1], end=' ')
print(n - index[-1])


n = int(input())
l = [int(x) for x in input().strip().split(' ')]
ans = []
for (idx, num) in enumerate(l):
	if idx == len(l) - 1 or l[idx + 1] == 1:
		ans.append(l[idx])
print(len(ans))
for x in ans:
	print(x, end=' ')
print('')


n = int(input())
x = [int(x) for x in input().split()]
arr = []
for i in range(len(x) - 1):
	if x[i + 1] == 1:
		arr.append(x[i])
arr.append(x[len(x) - 1])
print(len(arr))
print(' '.join([str(v) for v in arr]))


n = int(input())
a = input()
stairs = list(map(int, a.split()))
count = 0
amount = []
for i in range(n):
	if stairs[i] == 1:
		count += 1
		amount.append(i)
print(count)
for j in range(1, len(amount)):
	print(stairs[amount[j] - 1])
print(stairs[n - 1])


n = int(input())
a = list(map(int, input().strip().split()))[:n]
count = 0
stairs = 1
ans = []
for i in range(n):
	if a[i] == 1:
		count += 1
		ans.append(stairs)
		stairs = 1
	else:
		stairs += 1
ans.append(stairs)
del ans[0]
print(count)
print(*ans)


n = int(input())
a = list(map(int, input().strip().split()))
a.append(0)
c = 0
re = []
for i in range(n):
	if a[i + 1] <= a[i]:
		c += 1
		re.append(a[i])
print(c)
print(' '.join(map(str, re)))


import sys
n = int(input())
m = [int(x) for x in input().split()]
s = m.count(1)
print(s)
index = []
for i in range(n):
	if m[i] == 1:
		index.append(i)
if len(m) == 1:
	print(m[0], end=' ')
	sys.exit(0)
if m[1] == 1:
	print(m[0], end=' ')
for a in index:
	if a != 0 and a != 1:
		print(m[a - 1], end=' ')
print(m[n - 1])


n = int(input())
A = list(map(int, input().split()))
c = 0
C = []
i = 0
for i in range(1, n):
	if A[i] <= A[i - 1]:
		C.append(A[:i])
		c += 1
print(c + 1)
f = 0
Y = []
for i in C:
	Y.append(len(i) - f)
	print(len(i) - f, end=' ')
	f += len(i) - f
print(n - sum(Y))


n = int(input())
s = input()
mas = s.split()
step = []
pre = '0'
for i in range(0, n):
	if mas[i] == '1' and pre != '0':
		step.append(pre)
	pre = mas[i]
step.append(pre)
print(len(step))
for i in step:
	print(i, end=' ')


a = int(input())
l = list(map(int, input().split()))
l1 = []
for i in range(1, a):
	if l[i] - 1 != l[i - 1]:
		l1.append(l[i - 1])
	else:
		pass
l1.append(l[-1])
print(len(l1))
print(*l1)


a = int(input())
b = list(map(int, input().split()))
b.append(1)
c = [b[0]]
d = []
e = 0
for i in b[1:len(b)]:
	if i > c[e]:
		c.append(i)
		e += 1
	else:
		d.append(max(c))
		c = [i]
		e = 0
print(len(d))
for i in d:
	print(i, end=' ')


n = int(input())
s = input().split()
l = []
c = 0
somme = 0
for i in range(n):
	if i < n - 1:
		if int(s[i + 1]) <= int(s[i]):
			l.append(s[i])
			somme += 1
	else:
		l.append(s[i])
		somme += 1
print(somme)
for i in l:
	print(i, end=' ')


k = int(input())
a = list(map(int, input().split()))
colva = a.count(1)
b = []
i = 0
while len(b) != colva - 1:
	if a[i] >= a[i + 1]:
		b.append(a[i])
	i += 1
b.append(a[-1])
print(colva)
for j in b:
	print(j, end=' ')


t = int(input())
s = list(map(int, input().split()))
u = []
for j in range(t - 1):
	if s[j] < s[j + 1]:
		pass
	else:
		u.append(s[j])
u.append(s[-1])
print(len(u))
print(*u)


n = int(input())
L = [0] + list(map(int, input().split()))
L1 = []
cont = 0
for k in range(1, n + 1):
	if L[k] == 1:
		cont += 1
		L1.append(str(L[k - 1]))
L1 += [str(L[n])]
print(cont)
print(' '.join(L1[1:]))


pocCis = int(input())
cisla = list(map(int, input().split()))
vysledok = 1
vysCisla = []
for i in range(pocCis):
	if i == 0:
		pass
	elif cisla[i] == 1:
		vysledok += 1
		vysCisla.append(cisla[i - 1])
vysCisla.append(cisla[-1])
print(vysledok)
for i in vysCisla:
	print(i, end=' ')
print('')


n = int(input())
a = [*map(int, input().split())]
t = []
for i in range(n):
	if i == 0 or a[i - 1] >= a[i]:
		t.append(a[i])
	else:
		t[-1] = a[i]
print(len(t))
print(*t)


n = int(input())
l = list(map(int, input().split()))
print(l.count(1))
i = 0
l[0] = 0
d1 = 0
while 1:
	try:
		d = l.index(1)
		print(d - d1, end=' ')
		d1 = d
		l[d] = 0
	except:
		print(n - d1)
		break


n = int(input())
a = [int(s) for s in input().split(' ')]
stairs = []
for i in range(1, n):
	if a[i] == 1:
		stairs.append(str(a[i - 1]))
stairs.append(str(a[-1]))
print(len(stairs))
print(' '.join(stairs))


n = int(input())
tmp = 0
p = []
a = input()
pre = 0
for i in a.split(' '):
	tmp += 1
	if i == '1' and pre == 1:
		p.append(tmp - 1)
		tmp = 1
	elif i == '1':
		pre = 1
p.append(tmp)
print(len(p))
for i in p:
	if i == p[len(p) - 1]:
		print(i)
	else:
		print(i, end=' ')


n = int(input())
l = list(map(int, input().split()))
e = []
k = 1
if len(set(l)) == 1:
	print(n)
	print(*l)
else:
	for i in range(1, n):
		if l[i] == 1:
			e.append(k)
			k = 1
		else:
			k += 1
	if k != 1 or l[-1] == 1:
		e.append(k)
	print(len(e))
	print(*e)


a = int(input())
nums = list(map(int, input().split()))
answ = 0
it = 1
count = []
for i in nums[1:]:
	if i == 1:
		answ += 1
		count.append(it)
		it = 0
	it += 1
answ += 1
count.append(it)
print(answ)
s = ''
for i in count:
	s = s + str(i) + ' '
print(s)


def main():
	n = int(input())
	stairs = list(map(int, input().split()))
	numbers = []
	breakpoint = -1
	for i in range(len(stairs) - 1):
		if stairs[i] >= stairs[i + 1]:
			number = i - breakpoint
			numbers.append(number)
			breakpoint = i
	numbers.append(len(stairs) - breakpoint - 1)
	print(len(numbers))
	print(*numbers)
main()


n = int(input())
l = list(map(int, input().split()))
x = l.count(1)
print(x)
j = 0
y = 1
for i in range(len(l)):
	if l[i] == 1 and j == 0:
		j = 1
	elif l[i] == 1 and j != 0:
		print(y, end=' ')
		y = 1
	else:
		y = y + 1
	if i == len(l) - 1:
		print(y)


n = int(input())
arr = list(map(int, input().split()))
(ans, x, c) = (arr[0], [], 0)
for i in range(1, n):
	if arr[i] > arr[i - 1]:
		ans = arr[i]
	else:
		x.append(ans)
		ans = arr[i]
		c += 1
x.append(ans)
c += 1
print(c)
for i in x:
	print(i, end=' ')


a = int(input())
b = input().split()
c = 1
d = []
for i in range(a):
	if b[i] == '1' and i != 0:
		c += 1
		d.append(b[i - 1])
d.append(b[-1])
print(c)
print(' '.join(d))


n = int(input())
s = 0
a = []
c = 0
l = list(map(int, input().split()))
for i in range(0, n):
	if l[i] == 1:
		a.append(c)
		s = s + 1
		c = 0
	c = c + 1
a.append(c)
print(s)
print(*a[1:], sep=' ')


n = int(input())
A = list(map(int, input().split()))
if n == 1:
	print(1)
	print(1)
	exit(0)
print(A.count(1))
A.append(1)
for i in range(1, n + 1):
	if A[i] == 1:
		print(A[i - 1], end=' ')


n = int(input())
A = list(map(int, input().split()))
Ans = []
for i in range(n - 1):
	if A[i + 1] == 1:
		Ans.append(A[i])
Ans.append(A[n - 1])
print(A.count(1))
print(*Ans)


t = int(input())
a = list(map(int, input().split()))
s = []
c = 0
l = 0
for i in a:
	if i == 1:
		s.append(l)
		c += 1
		l = 1
	else:
		l += 1
s.append(l)
s.remove(0)
print(c)
print(*s)


n = int(input())
A = list(map(int, input().split()))
cnt = 0
ans = []
for i in range(n):
	if A[i] == 1:
		if i != 0:
			ans.append(cnt)
		cnt = 1
	else:
		cnt += 1
else:
	ans.append(cnt)
print(len(ans))
print(*ans)


n = int(input())
L = [int(x) for x in input().split()]
T = []
for i in range(0, n):
	if L[i] == 1:
		T.append(i)
print(len(T))
T.append(n)
for i in range(len(T) - 1):
	print(T[i + 1] - T[i], end=' ')


n = int(input())
n1 = list(map(int, input().split()[:n]))
print(n1.count(1))
n1.append(1)
lst = []
for i in range(1, n + 1):
	if n1[i] != 1:
		lst.append(n1[i])
	else:
		lst.append(1)
		print(max(lst), end=' ')
		lst = []


steps = int(input())
numbers = input().split(' ')
list_num = []
high_number_list = []
num_of_step = 0
for i in range(steps - 1):
	list_num.append(int(numbers[i]))
	if list_num[i] >= int(numbers[i + 1]):
		num_of_step += 1
		high_number_list.append(list_num[i])
list_num.append(int(numbers[-1]))
if len(list_num) > 1:
	if list_num[-2] > list_num[-1]:
		num_of_step += 1
		high_number_list.append(list_num[-1])
	else:
		high_number_list.append(list_num[-1])
		num_of_step += 1
	print(num_of_step)
	for i in high_number_list:
		print(i, end=' ')
else:
	print(steps)
	print(int(numbers[0]))


I = lambda : [int(i) for i in input().split()]
(n,) = I()
l = I() + [1]
a = []
for i in range(n):
	if l[i + 1] == 1:
		a.append(l[i])
print(l.count(1) - 1)
print(*a)


stair = int(input())
li = list(map(int, input().split()))
li2 = []
count = 0
for i in range(stair - 1):
	if li[i] >= li[i + 1]:
		li2.append(li[i])
		count += 1
li2.append(li[stair - 1])
print(count + 1)
print(*li2)


n = int(input())
arr = [int(i) for i in input().split()]
print(arr.count(1))
for i in range(1, n):
	if arr[i] == 1:
		print(arr[i - 1], end=' ')
print(arr[-1])


n = int(input())
l = list(map(int, input().split()))
c = 0
i = 0
l1 = []
while i < n:
	if l[i] == 1:
		c += 1
		c1 = 1
		j = i + 1
		while j < n:
			if l[j] != 1:
				c1 += 1
				j += 1
			else:
				break
		l1.append(c1)
		i = j
print(c)
s = ''
for i in l1:
	s += str(i) + ' '
print(s)


n = int(input())
a = list(map(int, input().rstrip().split()))
strct = 0
b = []
for i in range(n):
	if a[i] == 1:
		strct = strct + 1
for i in range(1, n):
	if a[i] == 1:
		b.append(a[i - 1])
ls = sum(b)
b.append(n - ls)
print(strct)
for i in b:
	print(i, end=' ')


n = int(input())
s = list(map(int, input().split()))
st = s.count(1)
i = 1
star = []
print(st)
while i < n:
	if s[i] == 1:
		c = s[i - 1]
		star.append(c)
	i += 1
star.append(s[n - 1])
y = 0
ans = ''
while y < st:
	ans += str(star[y]) + ' '
	y += 1
print(ans)


n = int(input())
arr = [int(i) for i in input().split()]
res = []
for i in range(1, n):
	if arr[i] == 1:
		res += [arr[i - 1]]
res += [arr[n - 1]]
print(len(res))
print(*res)


nums = input().split(' ')
nums = int(nums[0])
k = input().split(' ')
k = [int(k[i]) for i in range(len(k))]
ks = k.count(1)
ls = ''
for i in range(nums - 1):
	if k[i] >= k[i + 1]:
		ls = ls + str(k[i]) + str(' ')
ls = ls + str(k[-1])
print(str(ks))
print(ls.strip(' '))


_ = input()
counts = list(map(int, input().split()))
stairs = list()
for i in range(len(counts) - 1):
	if counts[i] >= counts[i + 1]:
		stairs.append(counts[i])
stairs.append(counts[-1])
print(len(stairs))
print(' '.join(map(str, stairs)))


import math
n = int(input())
li = []
li = list(map(int, input().split(' ')))
c = 0
ans = []
p = 1
p = len(li)
for i in range(0, n - 1):
	if li[i + 1] <= li[i]:
		c = c + 1
		ans.append(li[i])
c = c + 1
ans.append(li[n - 1])
print(c)
for i in ans:
	print(i, end=' ')


n = int(input())
seq = [int(x) for x in input().split()]
re = []
flag = 0
for i in seq:
	if i == flag + 1:
		flag += 1
	else:
		re.append(flag)
		flag = 1
re.append(flag)
print(len(re))
for i in re:
	print(i, end=' ')


n = int(input())
list1 = list(map(int, input().split()))
listy = []
for i in range(1, n):
	if list1[i] == 1:
		listy.append(list1[i - 1])
listy.append(list1[n - 1])
stairset = list1.count(1)
print(stairset)
for i in listy:
	print(i, end=' ')


a = int(input())
b = list(map(int, input().split()))
print(b.count(1))
for i in range(a - 1):
	if b[i + 1] == 1:
		print(b[i], end=' ')
print(b[-1])


n = int(input())
arr = [9999] + list(map(int, input().split()))
arr += [0]
countStairways = 0
result = []
count = 1
for i in range(1, n + 2):
	if arr[i - 1] >= arr[i]:
		countStairways += 1
		result.append(arr[i - 1])
print(countStairways - 1)
for i in range(1, countStairways):
	print(result[i], end=' ')


x = int(input())
a = [int(i) for i in input().split()]
c = 0
h = 0
b = 0
l = []
for i in a:
	if c + 1 == i:
		b += 1
		c = i
	else:
		h += 1
		l += [b]
		b = 0
		c = 1
		b += 1
h += 1
if b != 0:
	l += [b]
print(h)
print(*l)


n = int(input())
x = list(map(int, input().split()))
p = 0
y = []
for i in range(1, n):
	if x[i] != x[i - 1] + 1:
		p = p + 1
		y.append(x[i - 1])
if p == 0:
	print(1)
	print(n)
else:
	y.append(x[-1])
	print(p + 1)
	for j in range(len(y)):
		print(y[j], end=' ')


n = int(input())
a = list(map(int, input().split()))
l = [x for (x, y) in zip(a, a[1:] + [1]) if y == 1]
print(len(l))
print(*l)


n = int(input())
x = [int(i) for i in input().split()]
print(x.count(1))
res = []
for i in range(1, len(x)):
	if x[i] - x[i - 1] <= 0:
		res.append(x[i - 1])
res.append(x[-1])
print(' '.join([str(i) for i in res]))


n = int(input())
s = [int(i) for i in input().split()]
a = ''
t = 0
for i in range(n):
	if s[i] == 1 and i != 0:
		t += 1
		a += str(s[i - 1]) + ' '
a += str(s[i]) + ' '
print(t + 1)
print(a[:-1])


n = int(input())
arr = [k for k in input().split()]
steps_cnt = []
i = -1
for c in arr:
	if c == '1':
		i += 1
		steps_cnt.append(0)
	steps_cnt[i] += 1
print(len(steps_cnt))
print(*steps_cnt)


n = int(input())
s = list(input().split())
l = []
i = 0
count = 1
k = 1
while n - 1 > i:
	if s[i] == str(k) and s[i + 1] != str(k + 1):
		l = l + [k]
		count += 1
		k = 0
	i += 1
	k += 1
print(count)
l = l + [k]
print(*l, sep=' ')


input()
k = [int(i) for i in input().split()]
r = []
while len(k) != 0:
	r.insert(0, k[-1])
	k[len(k) - k[-1]:len(k)] = []
print(len(r))
print(*r)


input()
ans = []
for i in map(int, input().split()):
	if i == 1:
		ans.append(1)
	else:
		ans[-1] += 1
print(len(ans))
print(' '.join((str(i) for i in ans)))


n = int(input())
l = list((int(_) for _ in input().split()))
fl = list()
cnt = 0
for i in range(1, n):
	if l[i] != l[i - 1] + 1:
		fl.append(l[i - 1])
		cnt += 1
fl.append(l[n - 1])
print(cnt + 1)
print(*fl)


n = int(input())
steps = list(map(int, input().split()))
number = 0
single = []
curr = 0
for i in steps:
	if i == 1:
		single.append(curr)
		curr = 1
		number += 1
	else:
		curr += 1
single.append(curr)
print(number)
print(*single[1:])


n = int(input())
a = [int(i) for i in input().split()]
b = []
c = 1
for i in range(1, n):
	if a[i] == 1:
		b.append(a[i - 1])
		c += 1
b.append(a[n - 1])
print(c)
print(*b, sep=' ')


t = int(input())
s = list(map(int, input().split()))
c = 0
z = []
for i in range(t):
	if s[i] == 1:
		c = c + 1
for i in range(1, t):
	if s[i] == 1:
		z.append(s[i - 1])
z.append(s[t - 1])
print(c)
for i in range(0, len(z)):
	print(z[i], end=' ')


n = int(input())
a = input()
lst = list(map(int, a.split()))
so_cau = 1
result = []
for i in range(1, n):
	if lst[i] == 1:
		so_cau += 1
		result.append(str(lst[i - 1]))
result.append(str(lst[n - 1]))
print(so_cau)
print(*result, sep=' ')


n = int(input())
nums = list(map(int, input().split()))
c = 0
nos = 0
li = []
for i in range(len(nums)):
	nos += 1
	if i < len(nums) - 1:
		if nums[i] >= nums[i + 1]:
			c = c + 1
			li.append(nos)
			nos = 0
	else:
		c = c + 1
		li.append(nos)
print(c)
for i in li:
	print(i, end=' ')


t = int(input())
l = list(map(int, input().split()))
print(l.count(1))
count = 1
for i in range(1, t):
	if l[i] == 1:
		print(count, end=' ')
		count = 1
	else:
		count += 1
print(count, end=' ')


n = int(input())
arr = list(map(int, input().split()))
f = [0] * 1010
for i in arr:
	f[i] += 1
print(max(f))
for i in range(1, len(arr)):
	if arr[i - 1] >= arr[i]:
		print(arr[i - 1], end=' ')
print(arr[-1])


n = int(input())
a = input().split()
ls = []
count = 0
for i in range(n):
	if i == 0:
		count += 1
		if i == n - 1:
			ls.append(count)
	elif a[i] == '1':
		ls.append(count)
		count = 1
		if i == n - 1:
			ls.append(count)
	else:
		count += 1
		if i == n - 1:
			ls.append(count)
print(len(ls))
print(*ls)


_ = input()
steps = list(map(int, input().split()))
stairways = 0
totals = []
highest_step = 0
for step in steps:
	if step == 1:
		stairways += 1
		totals.append(highest_step)
		highest_step = 0
	highest_step = step
totals.append(highest_step)
print(stairways)
print(' '.join((str(t) for t in totals[1:])))


n = int(input())
v = list(map(int, input().split()))
h = v.count(1)
print(h)
pros = 0
v.append(1)
for i in range(h):
	y = v[pros + 1:].index(1)
	print(y + 1, end=' ')
	pros += y + 1


n = int(input())
numbers = list(map(int, input().split()))
output = []
for i in range(len(numbers) - 1):
	if numbers[i] >= numbers[i + 1]:
		output.append(numbers[i])
output.append(numbers[-1])
print(len(output))
print(' '.join(map(str, output)))


def stairs(n):
	c = n.count(1)
	l = []
	sc = 0
	for i in n:
		if i == 1 and sc != 0:
			l.append(sc)
			sc = 0
		sc += 1
	l.append(sc)
	print(c)
	print(*l)
n = int(input())
ns = list(map(int, input().split()))
stairs(ns)


n = int(input())
a = [int(i) for i in input().split(' ')]
b = []
no_of_steps = 0
count = 0
for i in range(len(a)):
	if a[i] == 1 and i != 0:
		count += 1
		b.append(a[i - 1])
	elif a[i] == 1 and i == 0:
		count += 1
b.append(a[i])
print(count)
for i in range(len(b)):
	print(b[i], end=' ')


n = int(input())
a = [int(x) for x in input().split(' ')]
b = []
ans = []
for i in range(n):
	if a[i] == 1:
		b.append(i)
for i in range(1, len(b)):
	ans.append(b[i] - b[i - 1])
ans.append(len(a) - b[-1])
print(len(ans))
print(' '.join([str(x) for x in ans]))


n = int(input())
li = list(map(int, input().split()))
print(li.count(1))
for i in range(len(li)):
	if li[i] == 1 and i == 0:
		continue
	elif li[i] == 1:
		print(li[i - 1], end=' ')
	else:
		continue
print(li[-1])


ilen = int(input())
arr = [int(i) for i in input().split(' ')]
stage = 0
step = []
for i in range(0, ilen):
	if arr[i] == 1:
		stage += 1
		step.append(1)
	else:
		step[-1] += 1
print(stage)
print(''.join(('{} '.format(i) for i in step)))


n = int(input())
l = list(map(int, input().split()))
l1 = []
c1 = l.count(1)
co = 1
for i in range(1, n):
	if l[i] == 1:
		l1.append(co)
		co = 1
	else:
		co += 1
l1.append(co)
print(c1)
print(*l1, sep=' ')


n = int(input())
a = [int(x) for x in input().split()]
stairs = []
for i in range(1, n):
	if a[i] == 1:
		stairs.append(a[i - 1])
stairs.append(a[n - 1])
print(len(stairs))
print(*stairs)


n = int(input())
a = []
a += map(int, input().split())
ans = 0
ans2 = []
for i in range(0, n - 1):
	if a[i] >= a[i + 1]:
		ans += 1
		ans2.append(a[i])
ans2.append(a[n - 1])
print(ans + 1)
for i in ans2:
	print(i, end=' ')


n = int(input())
ls = [int(i) for i in input().split()]
ans = []
for (i, j) in enumerate(ls):
	if j == 1:
		if i == 0:
			continue
		ans.append(ls[i - 1])
ans.append(ls[n - 1])
print(len(ans))
for i in ans:
	print(i, end=' ')


n = int(input())
stairs = [int(x) for x in str(input()).split(' ')]
print(stairs.count(1))
li = []
for i in range(len(stairs)):
	if i == len(stairs) - 1:
		li.append(stairs[i])
		break
	elif stairs[i + 1] == 1:
		li.append(stairs[i])
for x in li:
	print(x, end=' ')


n = int(input())
arr = list(map(int, input().split()))
lst = list()
for (idx, v) in enumerate(arr):
	if v == 1:
		lst.append(idx)
lst.append(n)
ans = list()
for idx in range(1, len(lst)):
	ans.append(lst[idx] - lst[idx - 1])
print(len(ans))
print(*ans)


n = int(input())
m = 0
ls = []
ans = []
ls = [int(x) for x in input().split()]
for i in range(len(ls)):
	if i == len(ls) - 1 or ls[i + 1] == 1:
		ans.append(ls[i])
		m += 1
print(m)
for a in ans:
	print(a, end=' ')


import sys
import math
import bisect

def main():
	n = int(input())
	A = list(map(int, input().split()))
	ans = []
	for i in range(n):
		if i == n - 1:
			ans.append(A[i])
		elif A[i + 1] == 1:
			ans.append(A[i])
	print(len(ans))
	print(' '.join(list((str(a) for a in ans))))
main()


import collections
n = int(input())
a = input().split()
a = [int(i) for i in a]
c = 1
b = []
for i in range(1, len(a)):
	if a[i] <= a[i - 1]:
		c += 1
		b.append(a[i - 1])
print(c)
for i in b:
	print(str(i) + ' ', end='')
print(a[len(a) - 1])


n = int(input())
m = 0
v = []
l = list(map(int, input().split()))
for i in range(n - 1):
	if l[i] < l[i + 1]:
		continue
	else:
		m += 1
		v.append(l[i])
print(m + 1)
v.append(l[-1])
for i in v:
	print(i, end=' ')


n = int(input())
i = list(map(int, input().split()))
count = 0
list = []
flag = True
for a in range(0, n):
	if i[a] == 1:
		count = count + 1
		if flag == False:
			list.append(stairs)
		stairs = 1
	elif i[a] > 1:
		stairs = stairs + 1
	flag = False
list.append(stairs)
number = ' '.join(map(str, list))
print(count)
print(number)


n = int(input())
lst = list(map(int, input().split()))
step = 0
stair = []
for i in range(n):
	if lst[i] == 1:
		step += 1
	if i != 0 and lst[i] == 1:
		stair.append(lst[i - 1])
stair.append(lst[-1])
print(step)
print(*stair)


x = int(input())
n = list(map(int, input().split()))
m = 0
b = []
for i in range(0, x):
	if n[i] > m:
		m = n[i]
	else:
		b.append(m)
		m = 1
	if i == x - 1:
		b.append(n[i])
print(len(b))
print(*b)


n = int(input())
a = list(map(int, input().split()))
t = a.count(1)
b = []
for i in range(1, n):
	if a[i] == 1:
		b.append(a[i - 1])
b.append(a[-1])
print(t)
for j in b:
	print(j, end=' ')


def go():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	x = []
	for i in range(len(a) - 1):
		if a[i] >= a[i + 1]:
			x.append(a[i])
	x.append(a[n - 1])
	print(len(x))
	return ' '.join((str(i) for i in x))
print(go())


input()
inp = list(map(int, input().split()))
inp.append(0)
matrix = []
for x in range(len(inp)):
	if inp[x] == 0:
		break
	elif inp[x] >= inp[x + 1]:
		matrix.append(str(inp[x]))
print(len(matrix))
print(' '.join(matrix))


n = int(input())
s = list(map(int, input().split()))
count = 1
res = []
for i in range(1, n):
	if s[i] <= s[i - 1]:
		res.append(count)
		count = 1
	else:
		count += 1
if count != 0:
	res.append(count)
print(len(res))
print(*res)


(ans, n) = (0, int(input()))
l = [int(x) for x in input().split()]
ans = l.count(1)
l2 = []
for i in range(n - 1):
	if l[i + 1] == 1:
		l2.append(l[i])
l2.append(l[-1])
print(ans)
for x in l2:
	print(x, end=' ')
print('')


n = int(input())
steps = list(map(int, input().split()))
num_stairways = 0
laststeps = []
for (i, step) in enumerate(steps):
	if step == 1:
		num_stairways += 1
		if i > 0:
			laststeps.append(steps[i - 1])
laststeps.append(step)
print(num_stairways)
print(' '.join([str(i) for i in laststeps]))


n = int(input())
a = list(input().split(' '))
a = list((int(x) for x in a))
res = list()
for i in range(1, n):
	if a[i] <= a[i - 1]:
		res.append(a[i - 1])
res.append(a[n - 1])
print(len(res))
for x in res:
	print(x, end=' ')


n = int(input())
arr = [int(x) for x in input().split()]
ans = []
cnt = 0
c = 0
for i in arr:
	if i == 1:
		ans.append(str(cnt))
		cnt = 0
		c += 1
	cnt += 1
ans.append(str(cnt))
print(c)
print(' '.join(ans[1:len(ans)]))


n = int(input())
b = list(map(int, input().split()))
t = b.count(1)
print(t)
l = []
for i in range(n):
	if b[i] == 1:
		l.append(b[i - 1])
for i in range(1, t):
	print(l[i], end=' ')
print(l[0])


n = int(input())
k = list(map(int, input().split()))
s = 1
p = 1
l1 = []
z = 0
while z != len(k) - 1:
	if k[z + 1] != 1:
		p += 1
	else:
		s += 1
		l1.append(p)
		p = 1
	z = z + 1
l1.append(p)
print(s)
print(*l1)


n = int(input())
s = input().split()
print(s.count('1'))
print(*[x for (x, y) in zip(s, s[1:] + ['1']) if y == '1'])


n = int(input())
lst = input().split()
c = lst.count('1')
print(c)
lst = lst[1:] + ['1']
while len(lst) != 0:
	i = lst.index('1')
	print(lst[i - 1], end=' ')
	lst = lst[i + 1:]


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] == val:
			return ll[mid]
		elif ll[mid] < val:
			ans = ll[mid]
			return binary(mid + 1, r, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)

def check(n):
	v = 1
	while n != 0:
		if n % 10 == 0 or n % 10 == 1:
			n = n // 10
		else:
			v = 0
			break
	return v
n = int(input())
l = list(map(int, input().split(' ')))
c = 0
ind = 0
l1 = []
for i in range(n):
	if l[i] == 1:
		if c == 0:
			c += 1
			ind = i
		else:
			c += 1
			l1.append(i - ind)
			ind = i
l1.append(n - ind)
print(c)
print(*l1)


n = int(input())
nums = list(map(int, input().split(' ')))
steps = n * [0]
(stairs, j) = (0, -1)
for i in range(n):
	if nums[i] == 1:
		stairs += 1
		j += 1
	steps[j] = nums[i]
print(stairs)
for x in range(stairs):
	print(steps[x], end=' ')


n = int(input())
a = []
b = []
t = 0
for i in input().split():
	a.append(int(i))
for i in range(1, n):
	if a[i] == 1:
		b.append(a[i - 1])
b.append(a[n - 1])
print(len(b))
for i in b:
	print(i, end=' ')


x = int(input())
m = list(map(int, input().split()))
count = 0
for i in m:
	if i == 1:
		count += 1
print(count)
m.append(1)
for i in range(1, x + 1):
	if m[i] == 1:
		print(m[i - 1], end=' ')


n = int(input())
a = list(map(int, input().split()))
one = 0
ans = []
for i in range(1, n):
	if a[i] == 1:
		one += 1
		ans.append(a[i - 1])
ans.append(a[n - 1])
one += 1
print(one)
print(' '.join(map(str, ans)))


from sys import stdin, stdout
input = lambda : stdin.readline().rstrip()
write = stdout.write

def main():
	N = int(input())
	A = tuple(map(int, input().split()))
	t = A.count(1)
	num = []
	for i in range(1, N):
		if A[i] == 1:
			num.append(A[i - 1])
	num.append(A[-1])
	print(t)
	print(*num)
main()


n = int(input())
arr = list(map(int, input().split()))
li = list()
count = 1
item = arr[0]
cha_ck = True
for i in range(1, n):
	if item < arr[i]:
		count += 1
		cha_ck = True
	else:
		li.append(count)
		count = 1
		cha_ck = False
		if i == n - 1:
			li.append(count)
if cha_ck:
	li.append(count)
print(len(li))
print(*li)


n = int(input())
steps = [int(i) for i in input().split()]
count = 0
nos = []
for i in range(len(steps)):
	if steps[i] == 1:
		count += 1
		last = None
		if i == 0:
			pass
		else:
			nos.append(steps[i - 1])
nos.append(steps[n - 1])
print(count)
for no in nos:
	print(no, end=' ')


a = int(input())
b = list(map(int, input().split()))
c = []
m = []
for x in range(a):
	if b[x] == 1:
		c.append(x)
print(len(c))
for i in range(1, len(c)):
	m.append(b[c[i] - 1])
m.append(b[-1])
for j in range(len(m)):
	print(m[j], end=' ')


n = int(input())
l = []
nl = []
s = list(map(int, input().split()))
for i in s:
	if i not in l:
		l += [i]
	else:
		nl += [len(l)]
		l = []
		l += [i]
nl += [len(l)]
print(len(nl))
s = ''
for i in nl:
	s += str(i) + ' '
print(s)


nums = int(input().strip(' '))
stairs = list(map(int, input().strip(' ').split(' ')))
cnt = []
for _ in stairs:
	if _ == 1:
		cnt.append(1)
	else:
		cnt[len(cnt) - 1] += 1
print(len(cnt))
print(*cnt)


def solve(test):
	ans = 1
	n = int(input())
	a = list(map(int, input().split()))
	a.append(1)
	vec = []
	for i in range(1, n + 1):
		if a[i] == 1:
			vec.append(a[i - 1])
	print(len(vec))
	print(*vec)
t = 1
for _ in range(t):
	solve(_ + 1)


n = int(input())
arr = list(map(int, input().split()))
number = arr.count(1)
indices = []
for i in range(len(arr)):
	if arr[i] == 1:
		indices += [i]
ans = []
for i in range(1, len(indices)):
	ans += [indices[i] - indices[i - 1]]
ans += [arr[-1]]
print(number)
print(' '.join(list(map(str, ans))))


p = int(input())
s = input()
n = [int(s) for s in s.split()]
k = n.count(1)
l = 1
print(k)
for i in range(1, len(n)):
	if n[i] > l:
		l = n[i]
	if n[i] == 1 and l != 0:
		print(l, end=' ')
		l = 1
if l != 0:
	print(l)


n = int(input())
l = list(map(int, input().split()))
n1 = l.count(1)
n2 = []
if n > 1:
	for i in range(1, n):
		if l[i] == 1:
			n2.append(l[i - 1])
	n2.append(l[i])
	print(n1)
	print(*n2)
else:
	print(n1)
	print(1)


n = int(input())
a = list(map(int, input().split()))
l = []
(count, count1) = (1, 0)
for i in range(n - 1):
	if a[i + 1] == a[i] + 1:
		count += 1
	else:
		l.append(count)
		count = 1
		count1 += 1
if a[n - 1] == a[n - 2] + 1:
	l.append(count)
	count1 += 1
if a[n - 1] != a[n - 2] + 1:
	l.append(1)
	count1 += 1
h = list(map(str, l))
k = ' '.join(h)
print(count1)
print(k)


n = int(input())
l = list(map(int, input().split(' ')))
c = 1
m = []
for i in range(n - 1):
	if l[i] >= l[i + 1]:
		c = c + 1
		m.append(l[i])
m.append(l[n - 1])
print(c)
print(' '.join([str(e) for e in m]))


input()
a = [*map(int, input().split())]
l = [x for (x, y) in zip(a, a[1:] + [1]) if y < 2]
print(len(l))
print(*l)


n = input()
x = [int(x) for x in input().split()]
count = 1
best = -1
l = []
for i in x:
	if i > best:
		best = i
	else:
		l.append(best)
		best = i
		count = count + 1
l.append(x[-1])
print(count)
for j in l:
	print(str(j), end=' ')


n = int(input())
seq = [m for m in input().split()]
lengths = []
number = 1
for (i, x) in enumerate(seq[1:]):
	if x == '1':
		number += 1
		lengths.append(seq[i])
lengths.append(seq[-1])
print(number)
print(' '.join(lengths))


input()
n = list(map(int, input().split()))
temp = list()
print(n.count(1))
for i in range(len(n)):
	if n[i] == 1:
		j = i + 1
		cc = 1
		while j < len(n) and n[j] != 1:
			cc += 1
			j += 1
		temp.append(cc)
print(' '.join([str(i) for i in temp]))


n = int(input())
a = [int(i) for i in input().split()]
t = a.count(1)
print(t)
for i in range(n):
	if i == n - 1:
		print(a[i])
	elif a[i + 1] == 1:
		print(a[i], end=' ')


t = int(input())
li1 = list(map(int, input().split()))
ans1 = li1.count(1)
print(ans1)
li2 = []
li1.append(1)
for i in range(t):
	if li1[i + 1] == 1:
		li2.append(str(li1[i]))
ans2 = ' '.join(li2)
print(ans2)


try:
	n = int(input())
	arr = list(map(int, input().split()))
	print(arr.count(1))
	for i in range(n):
		if arr[i] == 1 and i != 0:
			print(arr[i - 1], end=' ')
	print(arr[n - 1])
except Exception:
	pass


n = int(input())
steps = list(map(int, input().split()))
last_steps = []
for i in range(1, n):
	if steps[i] == 1:
		last_steps.append(steps[i - 1])
last_steps.append(steps[-1])
print(len(last_steps))
for item in last_steps:
	print(item, end=' ')


n = int(input())
arr = list(map(int, input().split()))
ans = []
yo = arr.count(1)
if yo == 1:
	ans.append(max(arr))
else:
	for i in range(0, len(arr)):
		if arr[i] == 1 and i != 0:
			ans.append(arr[i - 1])
	ans.append(arr[-1])
print(yo)
print(*ans)


input()
x = [int(i) for i in input().split()]
a = []
for i in range(len(x)):
	if i == len(x) - 1 or x[i + 1] == 1:
		a.append(x[i])
print(len(a))
print(' '.join([str(x) for x in a]))


a = int(input())
b = input().split()
g = 0
h = 0
c = []
for i in range(a):
	if int(b[i]) != 1:
		g += 1
	else:
		c.append(g)
		g = 1
		h += 1
c.append(g)
print(h)
for i in range(1, h + 1):
	print(c[i], end=' ')


q = input()
ladders = list(map(int, input().split()))
steps_count = []
for step in ladders:
	if step == 1:
		steps_count.append(1)
	else:
		steps_count[-1] += 1
print(len(steps_count))
print(*steps_count)


n = int(input())
a = [int(i) for i in input().split()]
a.append(1)
last = 0
ans = []
for i in range(1, n + 1):
	if a[i] == 1:
		ans.append(i - last)
		last = i
print(len(ans))
print(*ans)


def Print(s):
	print(len(s))
	for i in s:
		print(i, end=' ')
n = int(input())
a = list(map(int, input().split()))
s = []
for i in range(1, len(a)):
	if a[i] == 1:
		s.append(a[i - 1])
s.append(a[len(a) - 1])
Print(s)


n = int(input())
lst = list(map(int, input().split()))
c = 0
lst2 = []
for i in range(n):
	if lst[i] == 1:
		c += 1
		lst2.append(i)
print(c)
s = ''
for i in range(1, c):
	s += str(lst2[i] - lst2[i - 1]) + ' '
s += str(len(lst) - lst2[c - 1])
print(s)


n = int(input())
a = list(map(int, input().split()))
b = []
a = a[::-1]
while len(a) != 0:
	k = a.index(1)
	b.append(a[0])
	del a[:k + 1]
print(len(b))
print(*b[::-1])


n = int(input())
a = list(map(int, input().split()))
h = []
for i in range(0, n):
	if a[i] == 1:
		h.append(i)
z = []
for x in h:
	z.append(a[x - 1])
temp = z[0]
z.pop(0)
z.append(temp)
print(len(h))
for op in z:
	print(op, end=' ')


n = int(input())
a = [int(i) for i in input().split()]
p = -1
ans = []
for i in range(n):
	if a[i] == 1 and p != -1:
		ans.append(p)
	p = a[i]
ans.append(p)
print(len(ans))
print(*ans)


from itertools import groupby
from operator import itemgetter
t = int(input())
data = list(map(int, input().split()))
ans = []
for (k, g) in groupby(enumerate(data), lambda ix: ix[0] - ix[1]):
	v = list(map(itemgetter(1), g))
	ans.append(len(v))
print(len(ans))
print(' '.join((str(x) for x in ans)))


a = int(input())
enter = list(map(int, input().rstrip().split()))
ones = 0
stairs = []
for i in range(a):
	if enter[i] == 1:
		ones += 1
		if i == 0:
			continue
		else:
			stairs.append(enter[i - 1])
stairs.append(enter[a - 1])
print(ones)
print(*stairs, sep=' ')


N = int(input())
arr = [int(x) for x in input().split()]
arr_2 = []
for i in range(N - 1):
	if arr[i] == arr[i + 1] == 1:
		arr_2.append(arr[i])
	elif arr[i] > arr[i + 1]:
		arr_2.append(arr[i])
print(len(arr_2) + 1)
arr_2.append(arr[len(arr) - 1])
for i in arr_2:
	print(i, end=' ')


n = int(input())
k = 0
count = 0
list = list(input().split())
list = [int(i) for i in list]
list.append(0)
newlist = []
while k < n:
	if list[k] >= list[k + 1]:
		newlist.append(list[k])
		count = count + 1
		k = k + 1
	else:
		k = k + 1
print(count)
for i in range(len(newlist)):
	print(newlist[i], end=' ')


n = int(input())
li = list(map(int, input().split()))
ans = []
a = 0
if n == 1:
	a = 1
	ans.append(li[0])
if n > 1:
	a = 0
	ans = []
	temp = li[0]
	for i in range(1, n):
		if li[i] <= temp:
			ans.append(temp)
			a += 1
			temp = li[i]
		else:
			temp = li[i]
	ans.append(temp)
	a += 1
print(a)
s = ''
for i in ans:
	s = s + str(i) + ' '
print(s)


import collections
n = int(input())
a = list(map(int, input().split()))
p = collections.Counter(a)
print(p[1])
l = []
for i in range(1, n):
	if a[i] == 1:
		l.append(a[i - 1])
l.append(a[n - 1])
print(*l, sep=' ')


import os
import sys
import math
import collections
import cmath

def mp():
	return map(int, input().split())

def inp():
	return input()
n = int(inp())
d = []
flag = 0
i = 0
j = 1
ar = list(mp())
while True:
	while True:
		if i + j < n:
			if ar[i + j] != 1:
				j += 1
			else:
				d.append(j)
				i += j
				j = 1
		else:
			d.append(ar[n - 1])
			flag = 1
		if flag == 1:
			break
	if flag == 1:
		break
print(len(d))
print(' '.join((str(i) for i in d)))


n = int(input())
v = list(map(int, input().split()))
pos = [i for (i, x) in enumerate(v) if x == 1]
result = list(map(lambda i: v[i - 1], pos[1:]))
result.append(len(v) - sum(result))
print(len(result))
print(' '.join(map(str, result)))


n = input()
n = int(n)
tab = input().split()
print(tab.count('1'))
l = 0
for i in range(n):
	if tab[i] == '1' and i != 0:
		print(l)
		l = 0
	l = l + 1
print(l)


n = int(input())
a = []
steps = []
sc = 0
a = [int(x) for x in input().split()]
flag = 0
for i in range(1, n):
	if a[i] == 1:
		sc = sc + 1
		steps.append(a[i - 1])
steps.append(a[n - 1])
print(sc + 1)
print(*steps)


def solve(n, a):
	c = 1
	l = []
	for i in range(1, n):
		if a[i - 1] - a[i] >= 1 or (a[i - 1] - a[i] == 0 and a[i - 1] == 1):
			c += 1
			l.append(a[i - 1])
	l.append(a[-1])
	return (c, l)
n = int(input())
a = [int(i) for i in input().split()]
(c, l) = solve(n, a)
print(c)
print(*l)


n = int(input())
s = list(map(int, input().split()))
a = []
for i in range(n):
	a.append(0)
ind = 0
count = 0
check = 0
for j in range(n):
	if s[j] == 1 and check == 0:
		count += 1
		check = 1
	elif s[j] != 1 and check == 1:
		count += 1
	elif s[j] == 1 and check == 1:
		a[ind] = count
		ind += 1
		count = 1
		check = 1
a[ind] = count
ind += 1
print(ind)
for k in range(ind):
	print(a[k], end=' ')


N = int(input())
stairs = list(map(int, input().split()))
maxS = []
count = 0
for i in range(len(stairs) - 1):
	if stairs[i + 1] == 1:
		maxS.append(stairs[i])
		count += 1
maxS.append(stairs[-1])
count += 1
print(count)
print(*maxS)


import sys, math
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
n = inp()
a = inpl()
res = []
for i in range(n - 1):
	if a[i] + 1 == a[i + 1]:
		continue
	res.append(a[i])
res.append(a[-1])
print(len(res))
print(*res)


n = int(input())
a = list(map(int, input().split()))
count = a.count(1)
b = 1
stairs = []
for i in range(0, n):
	if i + 1 >= n or a[i] >= a[i + 1]:
		stairs.append(a[i])
print(count)
print(' '.join((str(a) for a in stairs)))


a = int(input())
b = list(map(int, input().split()))
x = int(0)
k = int(-1)
c = []
while x < a:
	if b[x] == 1:
		c.append(1)
		k = k + 1
	else:
		c[k] = c[k] + 1
	x = x + 1
print(len(c))
print(*c)


import math
n = int(input())
summ = []
k = 1
s = 1
a = input().split()
for i in range(1, len(a)):
	if int(a[i]) == 1:
		summ.append(s)
		s = 1
		k += 1
	else:
		s += 1
summ.append(s)
print(k)
for i in range(len(summ)):
	print(summ[i], end=' ')


n = int(input())
l = [int(x) for x in input().split()]
c = k = 0
s = []
for i in range(n):
	if l[i] == 1:
		c += 1
		if i >= 0:
			s.append(l[i - 1])
s.remove(s[0])
s.append(l[n - 1])
print(c)
print(*s)


def solve(arr):
	stairways = []
	i = 0
	for a in arr:
		if i == 0:
			i += 1
		else:
			if a == 1:
				stairways.append(i)
				i = 0
			i += 1
	if i > 0:
		stairways.append(i)
	ans = [str(len(stairways)), ' '.join(map(str, stairways))]
	return '\n'.join(ans)

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(arr))
main()


n = int(input())
steps = [int(c) for c in input().split()] + [1]
res = [steps[i] for i in range(n) if steps[i + 1] == 1]
print(len(res))
print(*res)


import time

def calcStairways(stairways):
	stepsPStairw = []
	nstairw = 0
	for (x, val) in enumerate(stairways):
		if x == 0 or val == 1:
			nstairw += 1
		if x != 0 and val == 1:
			stepsPStairw.append(stairways[x - 1])
		if x == len(stairways) - 1:
			stepsPStairw.append(stairways[x])
	return (nstairw, stepsPStairw)

def solve():
	tnumbers = int(input())
	stairways = []
	stairways = list(map(int, input().split()))
	(tstairways, stairw) = calcStairways(stairways)
	print(tstairways)
	print(' '.join((str(x) for x in stairw)))
solve()


a = int(input())
b = input()
b = b.split(' ')
count = 0
arr = []
for i in range(1, a):
	if b[i] == '1':
		count += 1
		arr.append(int(b[i - 1]))
print(count + 1)
arr.append(b[-1])
for item in arr:
	print(item, end=' ')


n = int(input())
s = list(map(int, input().split()))
x = s[0]
ans = 1
ans1 = []
for i in range(1, n):
	if s[i] != s[i - 1] + 1:
		ans += 1
		ans1.append(s[i - 1])
ans1.append(s[-1])
print(ans)
for i in ans1:
	print(i, end=' ')


n = int(input())
L = list(map(int, input().split()))
out = []
l = 0
for i in L:
	if i == l + 1:
		l += 1
	elif i == 1:
		out.append(l)
		l = 1
if l != 0:
	out.append(l)
print(len(out))
for i in out:
	print(i, end=' ')


n = int(input())
A = list(map(int, input().split()))
ans = 0
ans_list = []
for i in range(n):
	if A[i] == 1:
		ans += 1
		if i != 0:
			ans_list.append(A[i - 1])
ans_list.append(A[n - 1])
print(ans)
ans_list = list(map(str, ans_list))
print(' '.join(ans_list))


TN = 1

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	k = a.count(1)
	ans = []
	for i in range(n):
		if i + 1 < n:
			if a[i + 1] == 1:
				ans.append(a[i])
		else:
			ans.append(a[i])
	print(k)
	for i in ans:
		print(i, end=' ')
while TN != 0:
	solution()
	TN -= 1


t = int(input())
count = 0
top = []
x = 1
n = input()
l = n.split()
for i in l:
	if int(i) == 1:
		count += 1
		top.append(x)
	x = int(i)
top.append(x)
print(count)
for i in range(1, len(top)):
	print(top[i], end=' ')


def main():
	rd = lambda : list(map(int, input().split()))
	n = int(input())
	arr = rd()
	cnt = 0
	ret = []
	for i in range(n - 1):
		if arr[i] >= arr[i + 1]:
			cnt += 1
			ret.append(arr[i])
	cnt += 1
	ret.append(arr[-1])
	print(cnt)
	print(*ret)
main()


n = int(input())
a = [int(el) for el in input().split()]
col = 0
for i in range(n):
	if a[i] == 1:
		col += 1
print(col)
col = 1
for i in range(1, n):
	if a[i] == 1:
		print(a[i - 1], end=' ')
print(a[n - 1])


n = int(input())
a = [int(i) for i in input().split()]
k = 0
for i in range(n):
	if a[i] == 1:
		k = k + 1
print(k)
for i in range(n - 1):
	if a[i + 1] == 1:
		print(a[i], end=' ')
print(a[n - 1])


n = int(input())
g = list(map(int, input().split()))
print(g.count(1))
for i in range(n):
	if g[i] == 1 and i > 0:
		print(g[i - 1], end=' ')
print(g[n - 1])


s = input()
s = input().split(' ')
s.append('1')
output = []
stairscount = 1
iterstairs = iter(s)
next(iterstairs)
for x in iterstairs:
	if x != '1':
		stairscount += 1
	else:
		output.append(stairscount)
		stairscount = 1
print(s.count('1') - 1)
print(*output)


n = int(input())
a = list(map(int, input().split()))
li = []
a.append(-1)
cnt = 1
if n == 1:
	print('1 1')
	exit(0)
for i in range(n):
	if a[i] < a[i + 1]:
		cnt += 1
	else:
		li.append(cnt)
		cnt = 1
print(len(li))
for i in li:
	print(i, end=' ')


in1 = int(input())
in2 = input().split()
in2 = list(map(int, in2))
a = 0
k = 0
c = 1
in2.append(1)
ans = []
for i in range(in1):
	if in2[i] == 1 and a == 0:
		k = k + 1
		a = 1
	elif in2[i] == 1 and a == 1:
		ans.append(k)
		k = 0
		k = k + 1
		c = c + 1
	else:
		k = k + 1
		a = 1
ans.append(k)
print(c)
for i in ans:
	print(i, end=' ')


n = eval(input())
list = [int(i) for i in input().split()]
a = []
val = 0
for i in list:
	if i == 1:
		a.append(val)
		val = 1
	else:
		val += 1
a.append(val)
a.remove(0)
print(len(a))
for i in a:
	print(i, end=' ')


int(input())
L = list(map(int, input().strip().split(' ')))
List = []
prev = 0
ans = 0
for x in L:
	if x == 1:
		ans += 1
		List.append(prev)
	prev = x
print(ans)
List.append(L[-1])
print(*List[1:])


n = int(input())
a = list(map(int, input().split()))
st = 0
for i in range(n):
	if a[i] == 1:
		st += 1
print(st)
for i in range(n - 1):
	if a[i + 1] == 1:
		print(a[i], end=' ')
print(a[n - 1])


n = int(input())
l = list(input().split())
a = [int(i) for i in l]
steps = 0
q = []
for i in range(n):
	if a[i] == 1:
		steps += 1
for i in range(n - 1):
	if a[i + 1] == 1:
		q.append(a[i])
print(steps)
q.append(a[-1])
for i in q:
	print(i, end=' ')


n = int(input())
nums = list(map(int, input().split()))
final = []
count = 0
if nums.count(1) == len(nums):
	print(len(nums))
	for k in range(len(nums)):
		print(nums[k], end=' ')
else:
	for i in range(len(nums) - 1):
		if nums[i] < nums[i + 1] and i == len(nums) - 2:
			final.append(count + 2)
		elif nums[i] < nums[i + 1]:
			count = count + 1
		elif nums[i] > nums[i + 1]:
			final.append(count + 1)
			count = 0
		elif nums[i] == 1 and nums[i + 1] == 1:
			count = count + 1
			final.append(count)
			count = 0
	if nums[len(nums) - 1] == 1:
		final.append(1)
	print(len(final))
	for j in range(len(final)):
		print(final[j], end=' ')


a = int(input())
n = list(map(int, input().split()))
c = 1
s = ''
for i in range(a - 1):
	if not n[i + 1] > n[i]:
		c += 1
		s += str(n[i]) + ' '
s += str(n[a - 1])
print(c)
print(s)


n = int(input())
a = list(map(int, input().split()))
k = 0
x = []
for i in range(n):
	if a[i] == k + 1:
		k += 1
	else:
		x.append(k)
		k = 1
x.append(k)
print(len(x))
print(*x)


n = int(input())
s = input().split()
sl = []
c1 = 0
cl = ''
for i in range(n):
	sl.append(int(s[i]))
	if int(s[i]) == 1:
		c1 += 1
for i in range(1, n):
	if sl[i] == 1:
		cl += str(sl[i - 1]) + ' '
cl += str(sl[n - 1])
print(c1)
print(cl)


n = int(input())
lst = [int(x) for x in input().split()]
output = []
count = 0
for i in range(len(lst)):
	if lst[i] != 1:
		count += 1
	elif lst[i] == 1 and i != 0:
		output.append(str(count + 1))
		count = 0
	if i == len(lst) - 1:
		output.append(str(count + 1))
print(len(output))
print(' '.join(output))


input()
s = input().split()
print(s.count('1'))
count = 1
for c in s[1:]:
	if c == '1':
		print(count, end=' ')
		count = 1
	else:
		count += 1
print(count)


inp = input
li = list
iinp = lambda : int(inp())
ent = lambda : map(int, inp().split())
lient = lambda : [int(i) for i in inp().split()]
li0 = lambda x: [0 for i in range(x)]
stent = lambda : [i for i in inp()]
n = iinp()
res = []
act = 1
nums = lient()
for i in range(1, n):
	if nums[i] == 1:
		res.append(act)
	act = nums[i]
res.append(nums[-1])
print(len(res))
print(*res)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = LI()
	r = []
	for i in range(1, n):
		if a[i] == 1:
			r.append(a[i - 1])
	r.append(a[-1])
	return '{}\n{}'.format(len(r), ' '.join(map(str, r)))
print(main())


_ = input()
stairs = 0
steps = list()
count = 0
for i in input().split():
	if i == '1':
		stairs += 1
		if count != 0:
			steps.append(count)
		count = 1
	else:
		count += 1
steps.append(count)
print(stairs)
print(*steps)


n = int(input())
z = list(map(int, input().split()))
arr = []
for i in range(n - 1):
	if z[i] < z[i + 1]:
		continue
	else:
		arr.append(z[i])
arr.append(z[-1])
print(len(arr))
for i in range(len(arr)):
	if i == len(arr) - 1:
		print(arr[i])
	else:
		print(arr[i], end=' ')


def solve():
	pass
from collections import Counter
n = int(input())
stairs = [int(x) for x in input().split(' ')]
total = 0
t = []
for s in range(n):
	if stairs[s] == 1:
		if total > 0:
			t.append(stairs[s - 1])
		total += 1
	if s == n - 1:
		t.append(stairs[s])
print(total)
print(' '.join([str(x) for x in t]))


numbers = int(input())
seq = list(map(int, input().split()))
myArray = []
staircase = 0
i = 0
myMap = dict()
while i < len(seq):
	if seq[i] == 1:
		if myMap.get(1) == None:
			myMap[1] = 1
		else:
			myMap[1] += 1
	i += 1
staircase = myMap[1]
i = 0
j = i + 1
while j < len(seq):
	if seq[i] == seq[j]:
		myArray.append(j - i)
		i = j
	j += 1
myArray.append(seq[j - 1])
print(staircase)
for i in range(len(myArray)):
	print(myArray[i], end=' ')


def main():
	v = int(input())
	vals = [int(v) for v in input().split()]
	c = 1
	sizes = []
	for i in range(1, len(vals)):
		if vals[i] <= vals[i - 1]:
			c += 1
			sizes.append(str(vals[i - 1]))
	sizes.append(str(vals[-1]))
	print(len(sizes))
	print(' '.join(sizes))
main()


n = int(input())
steps = []
prev = 0
for step in map(int, input().split()):
	if step != prev + 1:
		steps.append(prev)
	prev = step
steps.append(step)
print(len(steps))
print(' '.join([str(x) for x in steps]))


n = int(input())
l = list(map(int, input().split()))
a = []
flag = 0
c = 0
for i in l:
	if i == 1:
		a.append(c)
		flag += 1
		c = 1
	else:
		c += 1
a.append(c)
a.remove(0)
print(flag)
print(*a)


n = int(input())
l = list(map(int, input().split()))
ans = 1
print(l.count(1))
for i in range(1, n):
	if l[i] == 1:
		print(ans, end=' ')
		ans = 1
	else:
		ans += 1
print(ans)


n = int(input())
s = [int(elem) for elem in input().split()]
ans = 0
anses = []
s.append(1)
for i in range(n):
	if s[i] >= s[i + 1]:
		ans = ans + 1
		anses.append(s[i])
print(ans)
for i in range(ans):
	print(anses[i], end=' ')


_ = input()
array = [int(item) for item in input().split()]
max_values = ''
stairways = 0
previous = None
for item in array:
	if item == 1:
		stairways += 1
		if previous:
			max_values += str(previous) + ' '
	previous = item
max_values += str(array[-1])
print(stairways)
print(max_values)


n = int(input())
l = list(map(int, input().split()))
main = []
for y in range(n - 1):
	if l[y] >= l[y + 1]:
		main.append(y + 1)
main.append(n)
print(len(main))
for t in range(len(main)):
	if t == 0:
		print(main[t], end=' ')
	else:
		print(main[t] - main[t - 1], end=' ')
print('\r')


n = int(input())
s = input().split()
l = []
for i in s:
	l.append(int(i))
count = l.count(1)
print(count)
for i in range(len(l)):
	if i == len(l) - 1:
		print(l[i])
	elif l[i + 1] == 1:
		print(l[i], end=' ')


total = int(input())
inps = [int(x) for x in input().split(' ')]
total = 0
out = []
for x in range(1, len(inps)):
	if inps[x - 1] >= inps[x]:
		total += 1
		out.append(inps[x - 1])
total += 1
out.append(inps[-1])
print(total)
print(' '.join([str(x) for x in out]))


input()
arr = input().split()
resarr = []
for i in range(1, len(arr)):
	if arr[i] == '1':
		resarr += [arr[i - 1]]
resarr += [arr[len(arr) - 1]]
print(len(resarr))
print(*resarr)


from __future__ import division, print_function
import cmath
import itertools
import math
import operator as op
import sys
from atexit import register
from bisect import bisect_left, bisect_right
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
	from math import gcd
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)

	def gcd(x, y):
		while y:
			(x, y) = (y, x % y)
		return x
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdin = stream(sys.stdin.read())
		input = lambda : sys.stdin.readline().rstrip('\r\n')
		sys.stdout = stream()
		register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))

def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	a.append(1)
	res = []
	for i in range(1, n + 1):
		if a[i] == 1:
			res.append(a[i - 1])
	print(len(res))
	print(*res)
sync_with_stdio()
main()


n = int(input())
a = [int(i) for i in input().split()]
pre = a[0]
res = []
c = 1
for i in range(1, n):
	if pre < a[i]:
		c += 1
	else:
		res.append(c)
		c = 1
	pre = a[i]
res.append(c)
print(len(res))
for e in res:
	print(e, end=' ')
print()


input()
lst = []
for i in map(int, input().split(' ')):
	lst.append(i)
print(lst.count(1))
j = 0
coun = []
for j in range(len(lst) - 1):
	if lst[j] >= lst[j + 1]:
		coun.append(lst[j])
coun.append(lst[-1])
for a in coun:
	print(a, end=' ')


n = int(input())
arr = list(map(int, input().split()))
arr.append(0)
s = ''
m = 0
for i in range(n):
	if arr[i] - arr[i + 1] != -1:
		m = m + 1
		s = s + str(arr[i]) + ' '
print(m)
print(s)


n = int(input())
a = list(map(int, input().split()))
b = []
c = []
for i in range(len(a)):
	if a[i] != 1:
		b.append(a[i])
	elif i != 0:
		c.append(b)
		b = []
	if i == len(a) - 1:
		c.append(b)
a.sort()
k = 0
for i in a:
	if i == 1:
		k += 1
print(k)
for i in range(len(c)):
	print(len(c[i]) + 1, end=' ')


n = int(input())
l = list(map(int, input().split()))
i = 0
s = []
m = 1
while i < n:
	if l[i] == 1 and m != 0:
		s.append(l[i - 1])
	i += 1
print(len(s))
s = s[1:] + [s[0]]
print(*s)


n = int(input())
l = list(map(int, input().split()))
s = 0
i = 0
c = 0
cl = []
while i < n:
	if l[i] == 1:
		s += 1
		cl.append(i)
		c += 1
	i += 1
print(s)
for i in range(c):
	if i != c - 1:
		print(cl[i + 1] - cl[i], ' ')
	else:
		print(n - cl[i])


n = int(input())
l = list(map(int, input().strip().split()))
k = l[::-1]
a = l.count(1)
cnt = 0
x = []
for i in k:
	cnt += 1
	if i == 1:
		x.append(cnt)
		cnt = 0
print(a)
print(*x[::-1])


n = int(input())
a = list(map(int, input().split()))
cnt = 0
res = []
level = 1
for i in range(1, n):
	if a[i - 1] < a[i]:
		level = a[i]
	else:
		cnt += 1
		res.append(level)
		level = 1
if level > 0:
	cnt += 1
res.append(level)
print(cnt)
print(' '.join(map(str, res)))


nos = int(input())
steps = [int(x) for x in input().split()]
nosw = 0
indx = [i for (i, v) in enumerate(steps) if v == min(steps)] + [nos]
print(len(indx) - 1)
for i in range(1, len(indx)):
	print(indx[i] - indx[i - 1], end=' ')


R = lambda : map(int, input().split())
n = int(input())
a = list(R()) + [1]
d = []
for i in range(1, n + 1):
	if a[i] == 1:
		d.append(a[i - 1])
print(len(d))
print(*d, sep=' ')


import math
from collections import defaultdict
getInputList = lambda : list(input().split())
getInputIntList = lambda : list(map(int, input().split()))
n = int(input())
arr = getInputIntList()
a = []
j = 0
for i in arr:
	if i == 1:
		a.append(j)
	j += 1
steps = []
for i in range(1, len(a)):
	steps.append(max(arr[a[i - 1]:a[i]]))
if len(a) > 1:
	steps.append(max(arr[a[i]:]))
else:
	steps.append(max(arr))
print(len(a))
for i in steps:
	print(i, end=' ')


n = int(input())
l = [int(x) for x in input().split()]
d = 0
count = 0
for i in range(len(l)):
	if l[i] == 1:
		count += 1
print(count)
count = 0
for i in range(len(l)):
	if l[i] == 1 and d == 1:
		print(count, end=' ')
		count = 1
	elif l[i] == 1 and d == 0:
		count += 1
		d = 1
	else:
		count += 1
print(count)


n = int(input())
l = list(map(int, input().split(' ')))
l1 = []
n1 = 1
for i in range(n - 1):
	if l[i] >= l[i + 1]:
		n1 += 1
		l1.append(l[i])
l1.append(l[-1])
print(n1)
print(*l1)


n = int(input())
a = list(map(int, input().split()))
s = 1
t = 0
d = {1: 0}
for j in a:
	if j == 1:
		d[1] += 1
print(d[1])
i = 1
while i != len(a):
	if a[i] == 1:
		print(s, end=' ')
		s = 1
	else:
		s += 1
	i += 1
print(s)


hm = int(input())
arr = [int(x) for x in input().split()]
print(arr.count(1))
arr.append(1)
for i in range(len(arr) - 1):
	if arr[i + 1] == 1:
		print(arr[i], end=' ')


n = int(input())
m = list(map(int, input().split())) + [1]
ans = 0
x = []
for i in range(n):
	if m[i + 1] == 1:
		x += [m[i]]
		ans += 1
print(ans)
print(' '.join(map(str, x)))


n = int(input())
steps = list(map(int, input().split(' ')))
print(steps.count(1))
counte = 1
if n == 1:
	print(1)
else:
	for i in range(1, n):
		if i == n - 1 and steps[i] == 1:
			print(counte, end=' ')
			print(1)
		elif i == n - 1 and steps[i] != 1:
			print(counte + 1)
		elif steps[i] == 1:
			print(counte, end=' ')
			counte = 1
		else:
			counte += 1


n = int(input())
ls = [int(i) for i in input().split()]
if n != 1:
	count = 1
	res = []
	for i in range(1, n):
		if ls[i] == 1:
			res.append(ls[i - 1])
			count += 1
		if i == n - 1:
			res.append(ls[i])
	print(count)
	print(*res, end=' ')
else:
	print('1')
	print('1')


a = int(input(''))
b = list(map(int, input().split()))
p = 0
t = []
r = []
n = 0
import copy
for i in range(len(b)):
	t.append(b[p])
	p = p + 1
x = copy.deepcopy(t)
x.reverse()
q = x.index(1)
print(t.count(1))
w = t.index(1)
t.remove(t[w])
for il in range(len(t)):
	if 1 in t:
		w = t.index(1)
		z = w - n
		r.append(z + 1)
		t.remove(t[w])
		n = copy.deepcopy(w)
	else:
		break
r.append(q + 1)
for kk in r:
	print(kk, end=' ')


input()
a = list(map(int, input().split())) + [1]
s = []
f = 0
a.remove(1)
while 1 in a:
	s += [a.index(1) - f + 1]
	f = a.index(1)
	a.remove(1)
print(len(s))
print(*s)


n = int(input())
a = [int(s) for s in input().split(' ')]
b = list()
b.append(1)
yer = 0
for i in range(1, len(a)):
	if a[i - 1] < a[i]:
		b[yer] += 1
	else:
		yer += 1
		b.append(1)
print(len(b))
for i in b:
	print(i, end=' ')


n = int(input())
a = [int(x) for x in input().split()]
stair = 1
steps = 1
b = ''
for i in range(1, len(a)):
	if a[i] == 1:
		stair += 1
		b += str(steps) + ' '
		steps = 1
	else:
		steps += 1
b += str(steps)
print(stair)
print(b)


a = int(input())
ar = list(map(int, input().split()))
num = 0
arr = []
for i in ar:
	if i == 1:
		if num:
			arr.append(num)
		num = 1
	else:
		num += 1
if num:
	arr.append(num)
print(len(arr))
for i in arr:
	print(i, end=' ')


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
b = []
k = 1
ik = 0
for i in range(1, n):
	if a[i] == 1:
		b.append(i - ik)
		k += 1
		ik = i
b.append(i - ik + 1)
print(k)
for i in range(k):
	print(b[i], end=' ')


input()
s = list(map(int, input().split()))[1:]
s.append(1)
print(s.count(1))
for i in range(len(s)):
	if s[i] == 1:
		print(s[i - 1], end=' ')


m = 1
o = 0
k = int(input())
j = [int(i) for i in input().split()]
a = {}
for i in range(len(j)):
	if j[i] == 1:
		a[m] = []
		o += 1
		m += 1
	else:
		a[o].append(j[i])
print(len(a))
for key in a.keys():
	print(len(a[key]) + 1, end=' ')


n = int(input())
x = list(map(int, input().split()))
d = {i: 0 for i in x}
for i in x:
	d[i] += 1
l = []
if d[1] == 1:
	print(d[1])
	print(max(x))
else:
	for i in range(1, len(x)):
		if x[i] == 1 and i != 0:
			l.append(x[i - 1])
	l.append(x[len(x) - 1])
	print(d[1])
	for x in l:
		print(x, end=' ')


n = int(input(''))
data = [int(a) for a in input('').split()]
t = 0
list1 = sorted(data)
for i in list1:
	if i == 1:
		t += 1
	else:
		break
print(t)
for i in range(1, n):
	if data[i] == 1:
		print(data[i - 1], end=' ')
print(data[-1])


from sys import stdin, stdout
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
count = 0
l = []
for i in range(n - 1):
	if a[i + 1] - a[i] != 1:
		count += 1
		l.append(a[i])
count += 1
l.append(a[-1])
stdout.write('%i\n' % count)
for i in range(len(l)):
	stdout.write('%i ' % l[i])


N = int(input())
WTF = list(map(int, input().split()))
COUNTER = 0
T = []
ln = len(WTF)
for _ in range(1, ln):
	if WTF[_] <= WTF[_ - 1]:
		COUNTER += 1
		T.append(WTF[_ - 1])
T.append(WTF[ln - 1])
print(COUNTER + 1)
print(*T, sep=' ')


n = int(input())
l = input()
l = l.split(' ')
for i in range(n):
	l[i] = int(l[i])
t = 0
o = []
pas = 1
for i in range(1, n):
	if l[i] == 1:
		o.append(pas)
		t = t + 1
		pas = 1
	else:
		pas = pas + 1
t = t + 1
o.append(pas)
print(t)
for i in range(len(o)):
	print(o[i], '', end='')


n = int(input())
a = list(map(int, input().split()))
c = 0
ans = 0
v = []
for i in a:
	if i == 1:
		if ans == 0:
			c += 1
			ans += 1
		else:
			v.append(c)
			c = 1
			ans += 1
		continue
	else:
		c += 1
		continue
	if i == n - 1:
		ans += 1
v.append(c)
print(ans)
print(*v)


n = int(input())
L = list(map(int, input().split()))
print(L.count(1))
if L.count(1) == len(L):
	print(*L)
else:
	x = L.count(1)
	c = 1
	x = x - 1
	while x > 0:
		for i in range(len(L)):
			if i < len(L) - 1:
				if L[i + 1] == 1:
					print(L[i], end=' ')
			x -= 1
	print(L[len(L) - 1])


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')

def main():
	n = iin()
	l = ain()
	count = 0
	p = []
	for i in range(0, n):
		if l[i] == 1 and i != 0:
			p.append(count)
			count = 1
		else:
			count += 1
	p.append(count)
	print(len(p))
	print(*p)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
a = list(map(int, input().split()))
o = []
cur = 0
for x in a:
	if x == 1:
		if cur > 0:
			o.append(cur)
		cur = 1
	else:
		cur += 1
o.append(cur)
print(len(o))
print(' '.join((str(x) for x in o)))


n = input()
a = [int(x) for x in input().split()]
(b, c, j) = ([], 0, 0)
for i in range(1, len(a)):
	if a[i] <= a[i - 1]:
		if c == 0:
			b.append(j + 1)
		else:
			b.append(j)
		c += 1
		j = 0
	j += 1
if c == 0:
	b.append(j + 1)
else:
	b.append(j)
print(c + 1)
for i in range(len(b)):
	print(str(b[i]) + ' ', end='')


N = int(input())
a = list(map(int, input().split()))
answers = []
for i in range(N - 1):
	if a[i] >= a[i + 1]:
		answers.append(a[i])
answers.append(a[N - 1])
print(len(answers))
print(' '.join(list(map(str, answers))))


def main():
	from sys import stdin, stdout

	def solve(tc: int):
		n = int(stdin.readline())
		arr = [int(a) for a in stdin.readline().split()]
		(ans, last) = ([], -1)
		for i in arr:
			if i == 1 and last != -1:
				ans.append(last)
			last = i
		ans.append(arr[len(arr) - 1])
		stdout.write(str(len(ans)) + '\n')
		stdout.write(' '.join([str(a) for a in ans]))
	TC = 1
	for tc in range(TC):
		solve(tc)
main()


n = int(input())
s = input().split(' ')
arr = []
s = [int(x) for x in s]
for i in range(n):
	if s[i] == 1:
		arr.append(int(i))
print(len(arr))
arr.append(n)
for i in range(1, len(arr)):
	print(arr[i] - arr[i - 1], end=' ')


z = input
import math
n = int(input())
c = 1
l = list(map(int, z().split()))
p = []
for i in range(1, n):
	if l[i] == 1:
		c += 1
		p.append(l[i - 1])
p.append(l[-1])
print(c)
print(*p)


def main():
	n = int(input())
	li = list(map(int, input().split()))
	count = 1
	li2 = []
	for i in range(1, n):
		if li[i] == li[i - 1] + 1:
			count += 1
		else:
			li2.append(count)
			count = 1
	li2.append(count)
	print(len(li2))
	for i in li2:
		print(i, end=' ')
	print()
main()


n = int(input())
a = [int(x) for x in input().split()]
answer = []
print(a.count(1))
for i in range(0, n - 1):
	if a[i + 1] == 1:
		answer.append(a[i])
answer.append(a[n - 1])
print(*answer)


total = input()
stairs = input().split()
count = stairs.count('1')
print(count)
a = 1
for i in stairs[1:]:
	if i == '1':
		print(stairs[a - 1], end=' ')
	a += 1
print(stairs[-1])


n = int(input())
a = list(map(int, input().split()))
a.append(-1)
s = 0
s1 = 0
r = []
p = 0
for i in a:
	if i > p:
		p = i
		s1 += 1
	else:
		s += 1
		r.append(s1)
		s1 = 1
		p = i
print(s)
print(*r)


a = int(input())
s = [int(x) for x in input().split()] + [0]
ans = 0
lenans = []
for i in range(1, a + 1):
	if s[i] <= s[i - 1]:
		lenans.append(str(s[i - 1]))
		ans += 1
print(ans)
print(' '.join(lenans))


n = int(input())
l = list(map(int, input().split()))
x = []
for i in range(0, n):
	if l[i] == 1:
		x.append(len(l[i:]))
x.append(0)
z = []
for j in range(len(x) - 1):
	z.append(abs(x[j] - x[j + 1]))
print(len(z))
print(*z, sep=' ')


n = int(input())
lst = list(map(int, input().split()))
lst.append(-1)
total = []
count = 0
temp = 1
for i in range(n):
	if lst[i] < lst[i + 1]:
		temp += 1
	else:
		total.append(temp)
		temp = 1
		count += 1
print(count)
print(*total)


n = int(input().strip())
nums = list(map(int, input().strip().split()))
res = []
for i in range(n - 1):
	if nums[i] >= nums[i + 1]:
		res.append(nums[i])
res.append(nums[n - 1])
print(len(res))
print(' '.join(list(map(str, res))))


n = int(input())
a = [int(i) for i in input().split()]
b = [0] * n
k = 0
cnt = 0
for i in range(n):
	if a[i] == 1:
		cnt += 1
	if cnt > 1 and a[i] == 1:
		k += 1
	b[k] = a[i]
print(cnt)
for x in b:
	if x == 0:
		break
	print(x, end=' ')


n = int(input())
a = [int(x) for x in input().split()]
b = []
for i in range(n - 1):
	if a[i] < a[i + 1]:
		pass
	else:
		b.append(a[i])
b.append(a[-1])
print(len(b))
print(*b)


n = int(input())
a = input().split()
l = []
ans = 0
k = 0
for elem in a:
	if elem == '1':
		ans = ans + 1
		l.append(k)
		k = 0
	k = k + 1
l.append(k)
print(ans)
s = ''
l.pop(0)
for elem in l:
	s = s + str(elem) + ' '
print(s[0:len(s) - 1])


n = int(input())
a = list(map(int, input().split()))
result = []
sum = 0
for i in a:
	if i == 1:
		result.append(1)
		sum += 1
	else:
		result[-1] += 1
print(sum)
for i in result:
	print(i, end=' ')


n = int(input())
numbers = input().split()
prevNumb = -1
stupenki = []
for i in range(n):
	number = int(numbers[i])
	if number > prevNumb:
		prevNumb = number
	else:
		stupenki.append(prevNumb)
		prevNumb = 1
stupenki.append(prevNumb)
print(len(stupenki))
print(*stupenki, sep=' ')


n = int(input())
a = [int(s) for s in input().split()]
print(a.count(1))
for i in range(n):
	if i == n - 1:
		print(a[i])
	if i < n - 1 and a[i + 1] == 1:
		print(a[i], end=' ')


n = int(input())
arr = list(map(int, input().split()))
counter = 1
steps = []
for i in range(1, n):
	if arr[i] <= arr[i - 1]:
		counter += 1
		steps.append(arr[i - 1])
steps.append(arr[n - 1])
print(counter)
print(*steps)


n = int(input())
steps = [int(num) for num in input().split()]
res = []
prev = steps[0]
for stepId in range(1, len(steps)):
	if steps[stepId] <= prev:
		res.append(prev)
	prev = steps[stepId]
res.append(steps[len(steps) - 1])
print(len(res))
for item in res:
	print(item, end=' ')


n = int(input())
a = list(map(int, input().split()))
x = []
ind = 0
for i in range(n):
	if a[i] == 1 and i != 0:
		x.append(i - ind)
		ind = i
x.append(n - ind)
print(len(x))
print(*x)


x = 1
spisok = ''
n = int(input())
a = list(map(int, input().split()))
for i in range(n - 1):
	if a[i] >= a[i + 1]:
		x += 1
		spisok += str(a[i]) + ' '
print(x)
print(spisok + str(a[-1]))


n = int(input())
cnt = 0
ans = []
arr = str(input())
i = 0
for j in map(int, arr.split(' ')):
	if j == i + 1:
		i += 1
	else:
		ans.append(i)
		i = j
if j == i:
	ans.append(str(j))
print(len(ans))
for i in ans:
	print(i, end=' ')


n = int(input())
a = [int(x) for x in input().split()]
j = 0
ans = 0
arr = []
for i in range(len(a) - 1):
	if a[i] < a[i + 1]:
		j += 1
	else:
		ans += 1
		j += 1
		arr.append(j)
		j = 0
if a[n - 1] > a[n - 2]:
	j += 1
	arr.append(j)
	ans += 1
else:
	ans += 1
	arr.append(1)
print(ans)
for i in arr:
	print(i, end=' ')


n = int(input())
args = [int(x) for x in input().split(' ')]
print(args.count(1))
for i in range(n):
	if args[i] == 1 and i > 0:
		print(args[i - 1], end=' ')
	if i == n - 1:
		print(args[i])


n = int(input())
l = [int(i) for i in input().split()]
print(l.count(1))
c = 1
res = []
for i in range(1, n):
	if l[i] == 1:
		res.append(c)
		c = 1
	else:
		c += 1
res.append(c)
print(*res)


n = int(input())
a = list(map(int, input().split()))
c = 0
m = []
for i in range(n - 1):
	if a[i] == 1:
		c += 1
	if a[i + 1] == 1:
		m.append(a[i])
if a[n - 1] == 1:
	c += 1
print(c)
for i in m:
	print(i, end=' ')
print(a[n - 1])


scalini = input()
conti_tania = input().split(' ')
numero_scale = 0
numero_scalini = []
n = 0
conta_scalini = ''
count = 1
x = 0
lista = []
conti_tania.append('0')
for n in range(int(len(conti_tania)) - 1):
	if int(conti_tania[n + 1]) > int(conti_tania[n]):
		count += 1
		if int(conti_tania[n]) == 1:
			numero_scale += 1
	else:
		lista.append(count)
		count = 1
		if conti_tania[n] == '1':
			numero_scale += 1
print(numero_scale)
listToStr = ' '.join([str(elem) for elem in lista])
print(listToStr)


n = int(input())
m = list(map(int, input().split()))
ans = []
cnt = 0
for i in range(int(n) - 1):
	if m[i + 1] == 1:
		ans.append(m[i])
		cnt += 1
ans.append(m[-1])
cnt += 1
print(cnt)
print(*ans, sep=' ')


n = int(input())
l1 = list(map(int, input().split()))
sum1 = 0
for i in l1:
	if i == 1:
		sum1 += 1
l2 = []
for i in range(1, len(l1)):
	if l1[i] == 1:
		l2.append(i)
if sum1 == 1:
	print
	print(sum1)
	print(l1[len(l1) - 1])
else:
	l3 = []
	print(sum1)
	for i in l2:
		l3.append(l1[i - 1])
	l3.append(l1[len(l1) - 1])
	for i in l3:
		print(i, end=' ')


a = int(input())
text = input()
arr = text.split()
k = 0
for el in arr:
	if int(el) == 1:
		k = k + 1
print(k)
arr1 = []
for i in range(a - 1):
	if int(arr[i + 1]) == 1:
		print(arr[i])
print(arr[a - 1])


input()
a = list(map(int, input().split())) + [1]
print(a.count(1) - 1)
s = []
s1 = 0
try:
	while True:
		s1 = a.index(1, s1 + 1)
		s.append(a[s1 - 1])
except:
	pass
print(*s)


n = int(input())
st = [int(x) for x in input().split()]
print(sum([st[x] == 1 for x in range(len(st))] * 1))
st = [st[x] == 1 for x in range(len(st))] * 1
pos = 0
if len(st) == 1:
	print(1)
	exit()
for i in range(1, len(st)):
	if st[i] == 0:
		continue
	else:
		print(i - pos, ' ', end='')
		pos = i
print(i + 1 - pos)


num_of_steps = int(input())
steps = input().split()
counter_of_ladders = 1
kek = []
for i in range(1, len(steps)):
	if steps[i] == '1':
		kek.append(steps[i - 1])
		counter_of_ladders += 1
print(counter_of_ladders)
if len(kek) == 0:
	print(steps[len(steps) - 1])
else:
	print(' '.join([str(i) for i in kek]), steps[len(steps) - 1])


n = int(input())
t = list(map(int, input().split()))
c = 1
l = []
step = 1
for i in range(n - 1):
	if t[i] + 1 != t[i + 1]:
		c += 1
		l.append(step)
		step = 0
	step = step + 1
l.append(step)
print(c)
for i in l:
	print(i, end=' ')


step = input()
inf = input().split()
num = inf.count('1')
print(num)
array = [x for (x, y) in enumerate(inf) if y == '1']
out = []
for i in range(len(array)):
	if not i == len(array) - 1:
		out.append(inf[array[i]:array[i + 1]])
	else:
		out.append(inf[array[i]:])
print(*[len(i) for i in out])


def main():
	n = int(input())
	number = 0
	ans = []
	for i in map(int, input().split()):
		if i == 1:
			number += 1
			ans.append(1)
		else:
			ans[number - 1] += 1
	print(number)
	for i in ans:
		print(i, end=' ')
main()


n = int(input())
s = list(map(int, input().split()))
nums = []
for i in range(n):
	if i == n - 1:
		nums.append(s[i])
		break
	if s[i + 1] == 1:
		nums.append(s[i])
print(s.count(1))
print(*nums)


n = int(input())
l = [int(x) for x in input().split()]
z = 1
x = 0
print(l.count(1))
l.append(1)
for i in range(1, n + 1):
	if l[i] - l[i - 1] == 1 and i == n - 1:
		z += 1
		print(z, end=' ')
		break
	elif l[i] - l[i - 1] == 1:
		z += 1
	elif l[i] - l[i - 1] != 1:
		print(z, end=' ')
		z = 1
	elif i == n - 1:
		print(z, end=' ')


n = int(input())
a = [int(i) for i in input().split()]
k = a.count(1)
print(k)
t = 0
for i in range(k - 1):
	t += a[t + 1:].index(1) + 1
	print(a[t - 1], end=' ')
print(a[-1])


n = int(input())
s = list(map(int, input().split(' ')))
print(s.count(1))
k = 1
for i in range(1, n):
	if s[i] != 1:
		k += 1
	else:
		print(k, end=' ')
		k = 1
print(k)


n = int(input())
str = [int(num) for num in input().split()]
ar1 = []
ar2 = []
for i in range(n):
	k = str[i]
	ar1.append(k)
c = 0
for i in range(len(ar1)):
	if ar1[i] == 1:
		c = c + 1
for i in range(1, len(ar1)):
	if ar1[i] == 1:
		ar2.append(ar1[i - 1])
print(c)
for i in ar2:
	print(i, end=' ')
print(ar1[-1])


from sys import stdin, stdout

def scanf():
	a = stdin.read(1)
	s = ''
	while a != ' ' and a != '\n':
		s += a
		a = stdin.read(1)
	return s
n = int(stdin.readline())
a1 = int(scanf())
count = 0
l = []
for i in range(n - 1):
	a2 = int(scanf())
	if a2 - a1 != 1:
		count += 1
		l.append(a1)
	a1 = a2
count += 1
l.append(a1)
stdout.write('%i\n' % count)
for i in range(len(l)):
	stdout.write('%i ' % l[i])


n = int(input())
last = 0
ans = []
for i in map(int, input().split()):
	if i == 1 and last != 0:
		ans.append(last)
	last = i
ans.append(last)
print(len(ans))
for i in ans:
	print(i, end=' ')


s = [list(map(int, input().split())) for _ in range(2)][1]
m = list()
for i in range(1, len(s)):
	if s[i - 1] > s[i] or s[i - 1] == s[i]:
		m.append(str(s[i - 1]))
m.append(str(s[-1]))
print(len(m))
print(' '.join(m))


t = int(input())
li6251 = list(map(int, input().split()))
abul1 = li6251.count(1)
print(abul1)
li2 = []
li6251.append(1)
for i in range(t):
	if li6251[i + 1] == 1:
		li2.append(str(li6251[i]))
ans2 = ' '.join(li2)
print(ans2)


a = int(input())
b = [int(x) for x in input().split()]
print(b.count(1))
for i in range(a - 1):
	if b[i + 1] == 1:
		print(b[i])
print(b[-1])


n = int(input())
test_list = list(map(int, input().split()))
test_list.reverse()
size = len(test_list)
idx_list = [idx + 1 for (idx, val) in enumerate(test_list) if val == 1]
res = [test_list[i:j] for (i, j) in zip([0] + idx_list, idx_list + ([size] if idx_list[-1] != size else []))]
res.reverse()
print(len(res))
for i in res:
	print(len(i), end=' ')


n = int(input())
a = input().split() + ['1']
b = []
last = 0
for i in range(1, n + 1):
	if a[i] == '1':
		b.append(str(i - last))
		last = i
print(len(b))
print(' '.join(b))


input()
numbers = map(int, input().split())
prev = None
out = []
c = 0
for n in numbers:
	if n == 1 and prev:
		out.append(prev)
	prev = n
out.append(prev)
print(len(out))
print(' '.join(map(str, out)))


n = int(input())
num = 0
t = 0
most = []
inputi = input().split(' ')
for i in range(n):
	a = int(inputi[i])
	if a == 1:
		num = num + 1
		if t != 0:
			most.append(t)
	t = a
most.append(a)
print(num)
for i in range(num):
	print(most[i], end=' ')


n = int(input())
a = list(map(int, input().split()))
steps = []
cnt_stairs = 0
for i in range(n):
	if a[i] == 1:
		cnt_stairs += 1
		if cnt_stairs > 1:
			steps.append(cnt)
		cnt = 1
	else:
		cnt += 1
steps.append(cnt)
print(cnt_stairs)
for i in range(len(steps)):
	print(steps[i], end=' ')


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
from sys import *
from types import CodeType, new_class
n = int(input())
a = [int(x) for x in input().split()]
b = []
for x in range(n):
	if x == n - 1 or a[x + 1] == 1:
		b.append(a[x])
print(len(b))
print(*b)


def main():
	n = int(input())
	a = map(int, input().split())
	count = 1
	last = 0
	height = []
	for x in a:
		if x <= last:
			count += 1
			height.append(last)
		last = x
	height.append(last)
	print(count)
	print(' '.join(map(str, height)))
main()


n = int(input())
x = list(map(int, input().split()))[:n]
idx = []
num = []
for i in range(n):
	if x[i] == 1:
		idx.append(i)
for k in idx:
	if k != 0:
		num.append(x[k - 1])
num.append(x[-1])
print(len(idx))
print(*num)


n = int(input())
s = list(map(int, input().split()))
x = []
y = 0
for i in range(1, n):
	if s[i] == 1:
		x.append(s[i - 1])
		y += 1
x.append(s[-1])
if n == 1:
	print(1)
	print(s[0])
else:
	print(y + 1)
	print(' '.join((str(i) for i in x)))


def main():
	n = int(input())
	ar = list(map(int, input().split()))
	ar.append(1)
	f = False
	prev = -1
	ans = []
	for i in range(len(ar)):
		if ar[i] == 1:
			if f == True:
				ans.append(prev)
			else:
				f = True
		prev = ar[i]
	print(len(ans))
	for val in ans:
		print(val, end=' ')
main()


n = int(input())
arr = list(map(int, input().strip().split(' ')))
ans = []
cnt = 0
temp = []
temp.append(1)
for i in range(1, n):
	if arr[i] == 1:
		ans.append(temp)
		temp = [1]
	else:
		temp.append(arr[i])
if len(temp) != 0:
	ans.append(temp)
print(len(ans))
for i in ans:
	print(i[len(i) - 1], end=' ')


n = int(input())
stairs = list(map(int, input().split()))
lenght = len(stairs)
numStairs = []
for i in range(lenght):
	if stairs[i] == 1 and i != 0:
		numStairs.append(stairs[i - 1])
numStairs.append(stairs[-1])
print(len(numStairs))
for i in numStairs:
	print(i, end=' ')


n = int(input())
b = input().split()
m = 0
c = []
p = ''
for i in range(n):
	if b[i] == '1':
		m += 1
		if len(c) != 0:
			p += str(c[-1]) + ' '
		c.append(1)
	else:
		c[-1] += 1
p += str(c[-1]) + ' '
print(m)
print(p)


t = int(input())
s = input()
p = 0
m = []
o = ''
s = s.split()
for i in range(len(s)):
	if s[i] == '1':
		p = p + 1
		if i != 0:
			m.append(s[i - 1])
m.append(s[len(s) - 1])
for i in range(len(m)):
	if i != len(m) - 1:
		o = o + m[i] + ' '
	else:
		o = o + m[i]
print(p)
print(o)


n = input()
a = [int(x) for x in input().split()]
print(a.count(1))
previousStep = 1
result = []
for x in range(1, len(a)):
	if a[x] != 1:
		previousStep += 1
	else:
		result.append(previousStep)
		previousStep = 1
if len(result) != a.count(1):
	result.append(previousStep)
print(*result)


n = int(input())
c = 1
l = list(map(int, input().split()))
p = []
for i in range(len(l)):
	if l[i] != c:
		c = l[i] + 1
		p.append(l[i - 1])
	else:
		c = c + 1
p.append(l[-1])
print(len(p))
print(' '.join(map(str, p)))


n = int(input())
li = [*map(int, input().split())]
count = 0
ans = []
s = True
from collections import Counter
a = Counter(li)
ans1 = a[1]
ans2 = []
for i in range(n):
	if li[i] == 1 and i != 0:
		ans2.append(str(li[i - 1]))
ans2.append(str(li[-1]))
print(ans1)
print(' '.join(ans2))


n = int(input())
count = 0
ans = []
array = input().split()
for i in range(n):
	if i == n - 1:
		break
	if array[i + 1] == '1':
		count += 1
		ans.append(array[i])
print(count + 1)
print(*ans, array[n - 1])


n = int(input())
a = ''
c = 0
l = ''
for i in input().split():
	if i == '1':
		c += 1
		if l != '':
			a += l + ' '
	l = i
print(c)
print(a + l)


F = lambda : map(int, input().split())
F()
a = list(F())
print(len([x for (x, y) in zip([0, *a], [*a, 0]) if x >= y]), '\n', *[x for (x, y) in zip([0, *a], [*a, 0]) if x >= y])


n = int(input())
lis = list(map(int, input().strip().split(' ')))
s = lis.count(1)
st = [0] * s
i = 0
for x in range(len(lis)):
	if x == 0:
		st[i] += 1
		continue
	if lis[x] == 1:
		i += 1
		st[i] += 1
	else:
		st[i] += 1
print(s)
for y in st:
	print(y, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = [0]
c = 0
d = 0
for i in range(n):
	if a[i] == 1:
		c += 1
		b.append(d)
		d = 1
	else:
		d += 1
b.append(d)
print(c)
s = str(b[2])
for i in range(3, c + 2):
	s += ' ' + str(b[i])
print(s)


no = int(input())
x = list(map(int, input().split()))
count = x.count(1)
spli = []
for i in x:
	spli.append(i)
res = []
for i in range(1, len(spli)):
	if spli[i] == 1:
		res.append(spli[i - 1])
res.append(spli[len(spli) - 1])
print(count)
for i in res:
	print(int(i), end=' ')


n = int(input())
li = list(map(int, input().split()))
i = 0
c = []
while i < len(li) - 1:
	if li[i] >= li[i + 1]:
		c.append(li[i])
	i = i + 1
x = li[-1]
c.append(x)
print(len(c))
for i in c:
	print(i, end=' ')


n = int(input())
a = [int(i) for i in input().split()]
step = []
count = 0
count_all = 0
for i in range(n):
	if a[i] == 1:
		count_all += 1
		step.append(count)
		count = 0
	count += 1
step.append(count)
print(count_all)
for i in range(1, len(step)):
	print(step[i], end=' ')
print()


n = int(input(''))
s = input('').split(' ')
print(s.count('1'))
output = ''
for k in range(1, n):
	if s[k] == '1':
		output = output + s[k - 1] + ' '
print(output + s[n - 1])


Col = int(input())
Num = str(input()).split(' ')
Count = 0
print(Num.count('1'))
unsw = []
for i in range(0, Col):
	if int(Num[i]) == 1:
		unsw.append(i)
for i in range(1, len(unsw)):
	print(abs(int(unsw[i]) - int(unsw[i - 1])), end=' ')
print(Num[Col - 1])


n = int(input())
a = [int(x) for x in input().split()]
t = a.count(1)
l = []
print(t)
if t == n:
	print('1 ' * n)
else:
	for i in range(1, n):
		if a[i] == 1:
			print(a[i - 1], end=' ')
	print(a[-1])


size = int(input())
x = list(map(int, input().split()))
y = x.count(1)
list = []
for i in range(1, len(x)):
	if x[i] == 1:
		list.append(x[i - 1])
list.append(x[-1])
print(y)
for i in list:
	print(i, end=' ')


n = int(input())
u = list(map(int, input().split()))
ans = []
for i in range(1, n):
	if u[i] != u[i - 1] + 1:
		ans.append(u[i - 1])
ans.append(u[-1])
print(len(ans))
for i in ans:
	print(i, end=' ')
print()


n = int(input())
a = list(map(int, input().split()))
ans = []
count = 1
for num in a:
	if num == 1:
		ans.append(count)
		count = 1
	else:
		count += 1
ans.append(count)
ans.pop(0)
print(len(ans))
print(*ans)


n = int(input())
a = list(map(int, input().split()))
an = []
su = 1
for i in range(len(a) - 1):
	if a[i] + 1 == a[i + 1]:
		su += 1
	else:
		if su == 0:
			su = 1
		an.append(su)
		su = 1
an.append(su)
print(len(an))
print(' '.join(map(str, an)))


n = int(input())
A = list(map(int, input().split()))
print(A.count(1))
print(*[i for (i, j) in zip(A[:-1], A[1:]) if j == 1], A[-1])


n = int(input())
s = input().split()
l = []
for (i, j) in enumerate(s):
	if j == '1':
		l.append(i)
print(len(l))
l.append(n)
print(*(l[i + 1] - l[i] for i in range(len(l) - 1)))


from sys import stdin, stdout

def solve():
	n = int(stdin.readline().strip())
	li = list(map(int, stdin.readline().split()))
	ans = []
	for i in range(1, n):
		if li[i] == 1:
			ans.append(li[i - 1])
	ans.append(li[-1])
	print(len(ans))
	for ai in ans:
		print(ai, end=' ')
	pass
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip()) if LOCAL_TEST else 1
t = 1
while t <= tcs:
	solve()
	t += 1


n = int(input())
a = list(map(int, input().split()))
count = 0
a.append(0)
list = []
for i in range(n):
	if a[i] == 1:
		count += 1
for i in range(1, n + 1):
	if a[i] == 1 or a[i] == 0:
		list.append(a[i - 1])
print(count)
print(*list)


n = int(input())
l = list(map(int, input().split()))
k = l.count(1)
l1 = []
c = 1
for i in range(1, len(l)):
	if l[i] == 1:
		l1.append(c)
		c = 1
	else:
		c += 1
l1.append(c)
print(k)
print(*l1)


n = int(input())
m = map(int, input().split())
m = list(m)
d = 0
v = []
for i in range(n):
	if m[i] == 1:
		d += 1
		if i != 0:
			v.append(m[i - 1])
v.append(m[n - 1])
print(d)
print(*v)


n = int(input())
l = list(map(int, input().split()))
arr = []
c = 0
chk = 0
for q in range(len(l)):
	if l[q] > chk:
		chk = l[q]
	else:
		arr.append(chk)
		chk = l[q]
		c = c + 1
	if q == len(l) - 1:
		arr.append(chk)
		chk = l[q]
		c = c + 1
print(c)
print(' '.join(map(str, arr)))


n = int(input())
l = list(map(int, input().split()))
c = 0
k = []
for i in range(n - 1):
	if l[i] >= l[i + 1]:
		c += 1
		k.append(l[i])
print(c + 1)
print(*k, l[n - 1])


n = int(input())
s = 1
st = 1
t = []
l = list(map(int, input().split()))
for i in range(0, n - 1):
	if l[i + 1] <= l[i]:
		st += 1
		t.append(s)
		s = 0
	s += 1
t.append(s)
print(st)
for i in t:
	print(i, end='  ')


x = int(input())
y = list(map(int, input().split()))
a = 1
b = ''
c = 1
k = 0
for i in y:
	if i != a:
		c += 1
		a = 1
		b = b + str(k) + ' '
	k = i
	a += 1
b = b + str(y[-1]) + ' '
print(c)
print(b)


x = int(input())
co1 = 1
co2 = 0
A = []
B = []
A = list(map(int, input().split()))
for i in range(x):
	if A[i] == 1 and i != 0:
		co1 += 1
		B += [co2]
		co2 = 1
	else:
		co2 += 1
B += [co2]
print(co1)
print(*B)


n = int(input())
s = list(map(int, input().split()))
last = 0
x = []
for i in range(1, n):
	if s[i] == 1:
		x.append(i - last)
		last = i
x.append(n - last)
print(len(x))
print(*x)


n = int(input())
a = list(map(int, input().split()))
print(a.count(1))
(i, c) = (0, 0)
while i < n:
	if a[i] == 1:
		c = 1
		i += 1
		while i < n and a[i] != 1:
			c += 1
			i += 1
		print(c, end=' ')
	else:
		i += 1


n = int(input())
a = [int(x) for x in input().split()]
o = []
i = 1
while i < n:
	if a[i] == 1:
		o.append(a[i - 1])
	i += 1
o.append(a[n - 1])
print(len(o))
for x in o:
	print(x, end=' ')
print()


n = int(input())
a = list(map(int, input().split()))
print(a.count(1))
res = 0
b = []
for i in range(1, n):
	res += 1
	if a[i] == 1:
		b.append(res)
		res = 0
b.append(res + 1)
for x in b:
	print(x, end=' ')


n = int(input())
arr = list(map(int, input().split()))
arr2 = []
ans = 1
for i in range(1, n):
	if arr[i] == 1:
		ans += 1
		arr2.append(arr[i - 1])
arr2.append(arr[-1])
print(ans)
print(*arr2)


n = int(input())
a = [int(x) for x in input().split()]
answernum = 1
answerlist = []
index = 1
while index < len(a):
	length = 1
	while index < len(a) and a[index] != 1:
		index += 1
		length += 1
	if index == len(a):
		answerlist.append(length)
	else:
		answernum += 1
		answerlist.append(length)
		length = 1
		index += 1
if a[-1] == 1:
	answerlist.append(1)
print(answernum)
for x in answerlist:
	print(x, end=' ')


n = int(input())
schody = list(map(int, input().split()))
wynik = []
for i in range(1, n):
	if schody[i] <= schody[i - 1]:
		wynik.append(schody[i - 1])
wynik.append(schody[n - 1])
print(len(wynik))
print(*wynik)


n = int(input())
a = [int(i) for i in input().split()]
ans = 1
k = 1
lis = []
for i in a[1:]:
	if i == 1:
		ans += 1
		lis.append(str(k))
	k = i
lis.append(str(k))
print(ans)
print(' '.join(lis))


input()
t = list()
nums = list(map(int, input().split()))
last = -1
for k in range(len(nums)):
	if nums[k] == 1:
		if last != -1:
			t.append(k - last)
		last = k
t.append(len(nums) - last)
print(len(t))
s = ''
for k in t:
	s += str(k) + ' '
print(s[:-1])


n = int(input())
x = list(map(int, input().split()))
print(x.count(1))
steps = []
while n > 0:
	steps.append(x[n - 1])
	n -= x[n - 1]
steps.reverse()
for i in steps:
	print(i, end=' ')


n = int(input())
b = input()
array = list(map(lambda x: int(x), b.split(' ')))
count = 1
a = []
num = 0
for i in range(n - 1):
	num += 1
	if array[i + 1] <= array[i]:
		count += 1
		a.append(num)
		num = 0
a.append(num + 1)
print(count)
for elem in a:
	print(elem, end=' ')


n = int(input())
a = [int(i) for i in input().split()]
nums = []
cntr = 0
for (j, i) in enumerate(a):
	if i == 1:
		cntr += 1
		if j > 0:
			nums.append(a[j - 1])
nums.append(a[-1])
print(cntr)
rjes = ''
for j in range(cntr):
	rjes += ' ' + str(nums[j])
rjes = rjes[1:]
print(rjes)


t = int(input())
count = list(map(int, input().split(' ')))
stairways = 0
steps = list()
x = 0
for i in range(t):
	if count[i] == 1 and x != 0:
		steps.append(x)
		stairways += 1
		x = 1
	else:
		x += 1
steps.append(x)
stairways += 1
print(stairways)
print(*steps)


n = int(input())
a = [int(s) for s in input().split()]
a.append(0)
st = 0
cnt = []
for i in range(n):
	if a[i + 1] <= 1:
		cnt.append(a[i])
		st += 1
print(st)
print(' '.join([str(s) for s in cnt]))


import sys
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
ans = []
for i in range(N - 1):
	if A[i] + 1 != A[i + 1]:
		ans.append(A[i])
ans.append(A[-1])
print(len(ans))
print(*ans)


total = int(input())
steps = [int(el) for el in input().split(' ')]
staircase_count = 0
steps_count = []
memory = 0
for (ind, el) in enumerate(steps):
	if el is 1:
		staircase_count += 1
		if ind is not 0:
			steps_count.append(ind - memory)
		memory = ind
steps_count.append(len(steps) - memory)
print(staircase_count)
print(' '.join((str(el) for el in steps_count)))


n = int(input())
a = list(map(int, input().split()))
k = 1
f = 0
b = []
for i in range(1, n):
	if a[i] == 1:
		b.append(k)
		k = 1
		f += 1
	else:
		k += 1
b.append(k)
print(f + 1)
print(' '.join([str(i) for i in b]))


n = int(input())
l = [int(i) for i in input().split()]
k = 0
s = []
for i in range(1, n):
	if l[i - 1] + 1 != l[i]:
		k += 1
		s.append(l[i - 1])
k += 1
s.append(l[n - 1])
print(k)
for i in range(k):
	print(s[i], '', end='')


a = int(input())
li = list(map(int, input().split()))
print(li.count(1))
li.append(1)
for i in range(a):
	if li[i + 1] == 1:
		print(li[i], end=' ')


from sys import stdin, stdout
from itertools import permutations, product, combinations
MOD = 10 ** 9 + 7
INF = float('+inf')

def si():
	return str(stdin.readline())

def ii():
	return int(input())

def mi():
	return map(int, stdin.readline().split())

def li():
	return [int(i) for i in input().split()]

def debug(x):
	return stdout.write(str(x))

def limul(list):
	return eval('*'.join((str(item) for item in list)))

def max_heapify(A, i):
	left = 2 * i + 1
	right = 2 * i + 2
	largest = i
	if left < len(A) and A[left] > A[largest]:
		largest = left
	if right < len(A) and A[right] > A[largest]:
		largest = right
	if largest != i:
		(A[i], A[largest]) = (A[largest], A[i])
		max_heapify(A, largest)

def build_max_heap(A):
	for i in range(len(A) // 2, -1, -1):
		max_heapify(A, i)

def mul(a, b):
	r = a * b
	if r >= MOD:
		return r % MOD
	else:
		return r

def power(a, b):
	x = 1
	y = a
	while b:
		if b & 1:
			x = mul(x, y)
		y = mul(y, y)
		b >>= 1
	return x

def inv(a):
	ans = power(a, MOD - 2)
	return ans

def main():
	n = ii()
	arr = li()
	x = arr.count(1)
	print(x)
	for i in range(1, n):
		if arr[i] == 1:
			print(arr[i - 1], end=' ')
	print(arr[n - 1], end=' ')
main()


current_line = []

def raw_input():
	global current_line
	if len(current_line) == 0:
		current_line = input().split(' ')
	return current_line.pop(0)

def getInt():
	return int(raw_input())

def readArray(k):
	return [getInt() for i in range(0, k)]
tn = readArray(getInt())
counted = []
for i in range(1, len(tn)):
	if tn[i - 1] >= tn[i]:
		counted.append(tn[i - 1])
counted.append(tn[-1])
print(len(counted))
print(' '.join(map(str, counted)))


def count_stairways(n, arr):
	count = 1
	ans = []
	for x in range(1, n):
		if arr[x] != 1:
			count += 1
		else:
			ans.append(count)
			count = 1
	ans.append(count)
	return ans
n = int(input())
arr = list(map(int, input().split()))
ans = count_stairways(n, arr)
print(len(ans))
print(*ans)


n = int(input())
m = input().split(' ')
lst = []
ma_x = 0
count = 0
for i in range(n):
	if int(m[i]) == 1:
		count += 1
	if i != n - 1:
		if int(m[i + 1]) == 1:
			lst.append(int(m[i]))
	elif int(m[i]) != 1:
		lst.append(int(m[i]))
	else:
		lst.append(1)
print(count)
for i in range(count):
	print(lst[i], end=' ')


import os
import io
input = io.BytesIO(os.read(0, 9999999)).readline
n = int(input())
nums = list(map(int, input().split()))
tot = 1
ans = []
for i in range(n - 1):
	if nums[i] >= nums[i + 1]:
		tot += 1
		ans.append(nums[i])
print(tot)
print(*ans, end=' ')
print(nums[-1])


n = int(input())
a = list(map(int, input().split()))
t = 0
for i in range(n):
	if a[i] == 1:
		t += 1
print(t)
for i in range(n):
	if a[i] == 1 and i >= 1:
		print(a[i - 1], end=' ')
print(a[n - 1])


(a, d) = (int(input()), input().split())
print(d.count('1'))
print(' '.join([d[i - 1] for i in range(1, a) if d[i] == '1'] + [d[-1]]))


n = int(input())
s = input()
l = s.split()
l = [int(i) for i in l]
z = 0
r = []
w = []
t = 0
for i in l:
	if i == 1:
		r.append(z)
	z += 1
r.append(len(l))
for i in r[1:]:
	w.append(str(i - r[t]))
	t += 1
print(l.count(1))
print(' '.join(w))


_ = input()
nums = [int(x) for x in input().split()]
res = []
for i in nums:
	if i == 1:
		res.append(1)
	else:
		res[-1] = i
print(len(res))
for i in res:
	print(i, end=' ')


n = int(input())
A = [int(item) for item in input().split()]
cnt = 1
oneCount = 1
L = []
if n == 1:
	print(1)
	print(1)
else:
	for i in range(1, n - 1):
		if A[i] == 1:
			L.append(cnt)
			cnt = 1
			oneCount += 1
		else:
			cnt += 1
	if A[n - 1] == 1:
		L.append(cnt)
		oneCount += 1
		L.append(1)
	else:
		L.append(cnt + 1)
	print(oneCount)
	for i in range(0, oneCount - 1):
		print(L[i], end=' ')
	print(L[oneCount - 1])


n = int(input())
values = [int(n) for n in input().split(' ')]
counter1 = 1
outcome = []
for i in range(len(values)):
	if i > 0 and values[i] == 1 and (i != n - 1):
		outcome.append(values[i - 1])
		counter1 += 1
	elif i == n - 1 and values[i] == 1 and (len(values) > 1):
		outcome.append(values[i - 1])
		outcome.append(1)
		counter1 += 1
	elif i == n - 1 and values[i] != 1:
		outcome.append(values[i])
	else:
		continue
if len(values) == 1:
	outcome.append(1)
print(counter1)
for i in range(len(outcome)):
	print(outcome[i], sep='', end=' ', flush=True)


import sys
sys.setrecursionlimit(10 ** 8)
k = int(sys.stdin.readline())
liste = list(map(int, sys.stdin.readline().split()))
out = list()
nb = 1
i = 1
for loop in range(1, k):
	if liste[loop] <= liste[loop - 1]:
		nb += 1
		out.append(i)
		i = 1
	else:
		i += 1
out.append(i)
print(nb)
print(*out)


n = int(input())
steps = [int(i) for i in input().split()]
count = 0
ans = []
for i in range(1, n):
	if steps[i] == 1:
		count += 1
		ans.append(str(steps[i - 1]))
ans.append(str(steps[n - 1]))
print(count + 1)
print(' '.join(ans))


n = int(input())
a = list(map(int, input().split()))
(l, c) = ([], 0)
for i in range(1, n):
	if a[i] == a[i - 1] + 1:
		continue
	else:
		c += 1
		l.append(a[i - 1])
l.append(a[-1])
print(c + 1)
print(*l)


_n = int(input())
n2 = list(map(int, input().split()))
t = []
last = 0
for x in n2:
	if x <= last:
		t.append(last)
	last = x
t.append(n2[-1])
print(len(t))
print(' '.join(map(str, t)))


n = int(input())
a = list(map(int, input().split()[:n]))
print(a.count(1))
if set(a) == {1}:
	a = [str(x) for x in a]
	print(' '.join(a))
else:
	i = 1
	while i < n:
		if a[i] == 1:
			print(a[i - 1], end=' ')
		i += 1
	if a[-1] == -1:
		print(1, end=' ')
	else:
		print(a[-1], end=' ')


n = int(input())
a = list(map(int, input().split()))
a.append(1)
ans = []
cnt = 0
for i in a:
	if i == 1:
		ans.append(cnt)
		cnt = 0
	cnt += 1
print(len(ans) - 1)
for i in range(1, len(ans)):
	print(ans[i], end=' ')


n = int(input())
l = list(map(int, input().split(' ')))
numSteps = 1
listSteps = []
for i in range(len(l) - 1):
	if l[i + 1] > l[i]:
		numSteps += 1
	else:
		listSteps.append(numSteps)
		numSteps = 1
listSteps.append(numSteps)
print(len(listSteps))
print(*listSteps, sep=' ')


n = int(input())
lest = [int(i) for i in input().split()]
i = 1
l_list = []
for l in range(n):
	try:
		if lest[l] < lest[l + 1]:
			i += 1
		else:
			l_list.append(i)
			i = 1
	except IndexError:
		l_list.append(i)
print(len(l_list))
print(*l_list)


n = int(input())
a = [int(i) for i in input().split()]
tangga = []
jlh = 0
for i in range(n):
	if i == n - 1:
		jlh += 1
		tangga += [a[i]]
		i += 1
	elif a[i] >= a[i + 1]:
		jlh += 1
		tangga += [a[i]]
		i += 1
print(jlh)
for i in tangga:
	print(i, end=' ')


def getStairs(stairs):
	return stairs.count('1')

def getHeights(stairs):
	heights = ''
	i = 1
	while i < len(stairs):
		if stairs[i] == '1':
			heights += str(stairs[i - 1]) + ' '
		i += 1
	return heights + str(stairs[-1])
useless = input()
stairs = input().split(' ')
print(getStairs(stairs))
print(getHeights(stairs))


n = int(input())
a = []
a = input().split()
for i in range(n):
	a[i] = int(a[i])
stairs = []
a.append(1)
for i in range(1, len(a)):
	if a[i] == 1:
		stairs.append(a[i - 1])
print(len(stairs))
ans = ''
for i in stairs:
	ans += str(i)
	ans += ' '
print(ans)


def stairs(arr):
	t = arr.count(1)
	print(t)
	ans = []
	for (i, n) in enumerate(arr):
		if i + 1 < len(arr) and arr[i + 1] == 1:
			ans.append(str(n))
	ans.append(str(arr[-1]))
	val = ' '.join(ans)
	print(val)
n = int(input())
s = list(map(int, input().rstrip().split()))
stairs(s)


n = int(input())
arr = list(map(int, input().split()))
a = []
r = 1
b = 1
for i in range(n - 1):
	if arr[i] >= arr[i + 1]:
		a.append(r)
		r = 1
		b += 1
	else:
		r += 1
a.append(arr[n - 1])
print(b)
for i in a:
	print(i, end=' ')


a = int(input())
mas = input().split()
mas1 = []
prosh = mas[0]
for i in mas[1:]:
	if int(i) != 1:
		prosh = i
	elif int(i) == 1:
		mas1.append(prosh)
		prosh = i
mas1.append(prosh)
print(len(mas1))
print(' '.join(mas1))


import sys
from bisect import insort, bisect_right
data = sys.stdin.readlines()
lis = []
for line in data:
	lis.append(line)

def dist(i, j):
	return abs(i - j)
n = int(lis[0])
seq = list(map(int, lis[1].split()))
n_strs = 0
stairs = []
for i in range(len(seq) - 1):
	if seq[i] >= seq[i + 1]:
		stairs.append(seq[i])
		n_strs += 1
n_strs += 1
stairs.append(seq[-1])
print(n_strs)
for s in stairs:
	print(s, end=' ')


input()
a = list(map(int, input().split()))
new = []
end = 0
for i in range(len(a) - 1):
	end += 1
	if a[end] == 1:
		new.append(a[end - 1])
new.append(a[end])
print(a.count(1))
print(' '.join([str(x) for x in new]))


def mi():
	return map(int, input().split())
n = int(input())
a = list(mi())
c = []
for i in range(1, n):
	if a[i] == 1:
		c.append(a[i - 1])
c.append(a[-1])
print(len(c))
for i in c:
	print(i, end=' ')


n = int(input())
a = [int(i) for i in input().split()]
res = 0
for i in range(n):
	if a[i] == 1:
		res += 1
print(res, end='\n')
for i in range(n):
	if a[i] == 1:
		j = i
		while j < n and a[j] - a[i] == j - i:
			j += 1
		print(j - i, end=' ')
		i = j - 1


n = int(input())
li = list(map(int, input().split(' ')))
leng = len(li)
ans = li.count(1)
print(ans)
count = 1
for i in range(leng - 1):
	if li[i + 1] == 1:
		print(count, end=' ')
		count = 1
	else:
		count += 1
print(count)


def max1(a):
	p = a[0]
	for x in a:
		if x > p:
			p = x
	return p

def preobr(x):
	if x % 2 == 1:
		return x + 1
	else:
		return x - 1

def prlist(a):
	for x in a:
		print(x, end=' ')

def dlin(n):
	k = 0
	while n > 0:
		n -= k
		k += 1
	return k - 1
n = int(input())
a = list(map(int, input().split()))
k = 1
b = []
for i in range(n - 1):
	if a[i + 1] == 1:
		k += 1
		b.append(a[i])
b.append(a[n - 1])
print(k)
prlist(b)


n = int(input())
ai = list(map(int, input().split()))
c = 0
lst = []
for i in range(len(ai) - 1):
	if ai[i + 1] == 1:
		c += 1
		lst.append(ai[i])
print(c + 1)
for i in lst:
	print(i, end=' ')
print(ai[-1])


n = int(input())
a = [int(x) for x in input().split()]
r = [1]
for i in range(1, n):
	if a[i] <= a[i - 1]:
		r.append(1)
	else:
		r[len(r) - 1] += 1
print(len(r))
print(' '.join([str(x) for x in r]))


n = int(input())
L = [int(e) for e in input().split(' ')]
print(L.count(1))
for k in range(n - 1):
	if L[k + 1] == 1:
		print(L[k], end=' ')
print(L[-1])


n = int(input())
a = [int(i) for i in input().split()]
a += [0]
b = []
for i in range(len(a)):
	for j in range(i + 1, len(a)):
		if i == len(a) - 1:
			break
		elif a[i] >= a[i + 1]:
			b += [a[i]]
			break
print(len(b))
for i in b:
	print(i, end=' ')


n = int(input())
steps = list(map(int, input().strip().split()))
steps.append(1)
t = 0
s = 0
answer = []
for i in range(n):
	s += 1
	if steps[i + 1] == 1:
		t += 1
		answer.append(s)
		s = 0
print(t)
for i in range(t):
	print(answer[i], end=' ')


n = int(input())
x = [int(i) for i in input().split()]
ans = x.count(1)
print(ans)
ot = 1
for i in range(1, len(x)):
	if x[i] == 1:
		print(ot, end=' ')
		ot = 1
	else:
		ot += 1
print(ot)


x = int(input())
y = list(map(int, input().split(' '))) + [1]
a = 0
b = 0
c = []
d = 0
for i in y:
	if i == 1:
		a += 1
		if d == 0:
			d += 1
		else:
			c.append(b + 1)
		b = 0
	else:
		b += 1
print(a - 1)
print(*c)


n = int(input())
l = [int(i) for i in input().split(' ')] + [0]
ans = 0
m = []
for i in range(n):
	if l[i] != l[i + 1] - 1:
		ans += 1
		m.append(l[i])
print(ans)
print(*m)


n = input()
l = list(map(int, input().split()))
stair = 0
for i in l:
	if i == 1:
		stair += 1
print(stair)
l.append(-1)
step = 1
for i in range(len(l)):
	if i == 0:
		continue
	elif l[i] != 1 and l[i] != -1:
		step += 1
	else:
		print(step, end=' ')
		step = 1


a = int(input())
s = list(map(int, input().split()))
s.append(1)
p = 0
ans1 = []
ans2 = 0
for i in range(1, a + 1):
	if s[i] == 1:
		ans1.append(i - p)
		ans2 += 1
		p = i
print(ans2)
print(*ans1)


input()
l = list(map(int, input().split()))
total = 0
w = []
for i in range(-1, len(l) - 1):
	if l[i + 1] == 1:
		total += 1
		if i == -1:
			continue
		w.append(l[i])
w.append(l[len(l) - 1])
print(str(total))
for i in w:
	print(str(i), end=' ')


number = int(input())
str1 = input()
L = str1.split(' ')
k = 0
for i in L:
	if int(i) == 1:
		k += 1
L2 = [1] * k
t = -1
for i in L:
	if int(i) == 1:
		t += 1
	else:
		L2[t] += 1
L3 = []
for i in L2:
	L3.append(str(i))
print(k)
str2 = ' '.join(L3)
print(str2)


n = int(input())
s = 0
l = list(map(int, input().split()))
j = []
for i in range(n):
	if l[i] == 1:
		s += 1
		if i != 0:
			j.append(l[i - 1])
j.append(l[-1])
print(s)
print(*j)


x = int(input())
y = input()
lst = list(map(int, y.split()))
kibe = lst.count(1)
print(kibe)
c = lst[0]
lst.remove(lst[0])
lst.insert(x - 1, c)
for (i, v) in enumerate(lst):
	if v == 1:
		b = i - 1
		print(lst[b], end=' ')


N = int(input())
les = [int(x) for x in input().split()]
_s = 1
_ends = []
for i in range(1, N):
	if les[i] == 1:
		_s += 1
		_ends.append(les[i - 1])
_ends.append(les[N - 1])
print(_s)
for i in _ends:
	print(i, end=' ')


n = int(input())
a = [int(x) for x in input().split()]
ansL = []
thisIsStart = True
for i in range(n):
	if thisIsStart:
		count = 1
		thisIsStart = False
	else:
		count += 1
	if i != n - 1:
		if a[i + 1] == 1:
			thisIsStart = True
			ansL.append(count)
	else:
		ansL.append(count)
print(a.count(1))
print(*ansL)


n = int(input())
arr = [int(i) for i in input().split()]
count = 1
res = []
if n != 1:
	for i in range(1, n - 1):
		if arr[i] == 1:
			count += 1
			res.append(arr[i - 1])
	if arr[-1] == 1:
		count += 1
		res.append(arr[-2])
		res.append(1)
	else:
		res.append(arr[-1])
print(count)
if n != 1:
	print(*res, sep=' ')
else:
	print(1)


n = int(input())
arr = input().split()
sm = 0
arr2 = []
x = 0
for i in range(0, n, 1):
	if arr[i] == '1':
		arr2.append(arr[i - 1])
		sm += 1
	x += 1
print(sm)
for i in range(1, sm):
	print(arr2[i])
print(arr[x - 1])


n = int(input())
angka = input().split()
hasil = 0
j = []
hasil1 = []
for i in angka:
	if int(i) == 1:
		hasil += 1
print(hasil)
for i in range(len(angka)):
	if int(angka[i]) == 1 and i == 0:
		j += [int(angka[i - 1])]
	elif int(angka[i]) == 1:
		hasil1 += [int(angka[i - 1])]
hasil1 += j
for i in hasil1:
	print(i, end=' ')


n = int(input())
a = [int(x) for x in input().split()]
total = a.count(1)
steps = []
for i in range(1, n):
	if a[i] == 1:
		steps.append(a[i - 1])
steps.append(a[n - 1])
print(total)
for i in steps:
	print(i, end=' ')


n = int(input())
arr = list(map(int, input().split()))
arr = arr[1:]
arr.append(1)
prev = 1
ans = []
for e in arr:
	if e == 1:
		ans.append(prev)
	prev = e
print(len(ans))
print(*ans)


n = int(input())
a = list(map(int, input().split()))
b = []
l = 0
(i, j) = (0, 0)
while i < n:
	j = i
	t = 0
	while j + 1 < n and a[j + 1] != 1:
		j = j + 1
		t = t + 1
	l += 1
	b.append(t + 1)
	i = j + 1
print(l)
print(*b)


n = int(input())
a = list(map(int, input().split()))
b = []
for i in a:
	if i == 1:
		b.append(1)
	else:
		b[-1] += 1
print(len(b))
for i in b:
	print(i, end=' ')


n = int(input())
k = input()
l = list(map(int, k.split()))
print(l.count(1))
l.append(1)
prev = 1
for i in range(1, len(l)):
	if l[i] == 1:
		print(l[i - 1], end=' ')


n = int(input())
s = list(map(int, input().split()))
q = []
for i in range(n - 1):
	if s[i] >= s[i + 1]:
		q.append(s[i])
q.append(s[-1])
print(len(q))
print(*q)


n = int(input())
ar = [int(i) for i in input().split()]
a = ar[0]
ar1 = []
N = 1
c = 1
for i in range(1, n):
	if ar[i] - a == 1:
		c += 1
	else:
		ar1.append(c)
		c = 1
		N += 1
	a = ar[i]
ar1.append(c)
print(N)
print(' '.join([str(i) for i in ar1]))


t = int(input())
l = list(map(int, input().split()))
z = []
max = 1
for i in range(1, t):
	if l[i] > max:
		max = l[i]
	elif l[i] < max:
		z.append(max)
		max = l[i]
	elif l[i - 1] == l[i]:
		z.append(l[i - 1])
z.append(max)
k = len(z)
print(k)
for i in range(k):
	print(z[i], end=' ')
print()


def solve(seq):
	ans = []
	prev = 0
	for current in seq:
		if current <= prev:
			ans.append(prev)
			prev = current
			continue
		prev = current
	ans.append(current)
	return ans
_ = input()
seq = [int(x) for x in input().strip().split()]
result = solve(seq)
print(len(result))
print(*result)


n = int(input())
S = list(map(int, input().split()))
ans1 = 0
ans2 = []
if n == 1:
	print(1)
	print(S[0])
	exit()
for i in range(n - 1):
	if S[i] >= S[i + 1]:
		ans1 += 1
		ans2.append(str(S[i]))
ans1 += 1
ans2.append(str(S[n - 1]))
ans = ' '.join(ans2)
print(ans1)
print(ans)


n = int(input())
steps = [int(x) for x in input().split()]
count = 0
num = []
for i in range(0, n):
	if steps[i] == 1:
		count += 1
		if i == n - 1:
			if i != 0:
				num.append(str(steps[i - 1]))
			num.append(str(steps[i]))
		elif i > 0:
			num.append(str(steps[i - 1]))
	elif i == n - 1:
		num.append(str(steps[i]))
print(count)
print(' '.join(num))


n = int(input())
l = list(map(int, input().split()))
total = 1
q = []
for i in range(1, n):
	if l[i] == 1:
		q.append(l[i - 1])
		total += 1
q.append(l[n - 1])
print(total)
for i in q:
	print(i, end=' ')


n = int(input())
a = list(map(int, input().split()))
b = []
tot = 0
sum = 1
for i in range(n):
	if a[i] == 1:
		b.append(sum)
		tot += 1
		sum = 1
	else:
		sum += 1
b.pop(0)
b.append(sum)
print(tot)
print(' '.join(map(str, b)))


from sys import stdin, stdout, exit as sys_ret
(f_input, f_print, f_flush) = (stdin.readline, stdout.write, stdout.flush)
amount = int(f_input())
numbers = [int(_) for _ in f_input().split()]
(answer, count) = ([], 1)
for i in range(1, amount):
	if numbers[i] <= numbers[i - 1]:
		count += 1
		answer.append(numbers[i - 1])
answer.append(numbers[amount - 1])
f_print(str(count) + '\n')
for i in answer:
	f_print(str(i) + ' ')


numbers = int(input())
number = list(map(int, input().split()))
s = list()
stairways = 0
steps = 0
i = 0
while i < len(number) - 1:
	if number[i] == 1:
		stairways += 1
	if number[i + 1] == 1:
		s.append(number[i])
	i += 1
if number[-1] > 1:
	s.append(number[-1])
else:
	s.append(number[-1])
	stairways += 1
print(stairways)
print(*s)


n = int(input())
s = [int(x) for x in input().split()]
way = 0
step = []
for i in range(n):
	if s[i] == 1:
		way += 1
		if i != 0:
			step.append(s[i - 1])
step.append(s[n - 1])
print(way)
for i in step:
	print(i, end=' ')
print()


i1 = input()
i2 = input().split(' ')
i2.append('1')
a1 = 0
a2 = ''
temp = ''
for a in i2:
	if a == '1' and temp != '':
		a1 += 1
		a2 = a2 + temp + ' '
	temp = a
print(a1)
print(a2)


n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
dst = 0
last = 1
for i in range(1, n + 1):
	if i < n and a[i - 1] < a[i]:
		last += 1
	else:
		ans[dst] = last
		dst += 1
		last = 1
ans = ans[:dst]
print(dst)
print(' '.join(map(str, ans)))


n = int(input())
a = list(map(int, input().split())) + [-1]
prv = 0
r = 0
ans = []
for v in a:
	if v != prv + 1:
		r += 1
		ans.append(prv)
	prv = v
print(r)
print(*ans)


input()
s = map(int, input().split(' '))
res = []
prev = 0
for x in s:
	if x <= prev:
		res.append(prev)
	prev = x
res.append(prev)
print(len(res))
for x in res:
	print(x, end=' ')


input()
l = list(map(int, input().split()))
k = 1
m = []
a = -1
for i in range(len(l)):
	if l[i] == 1:
		if i > 0:
			m.append(k)
		k = 1
	else:
		k += 1
m.append(k)
print(len(m))
print(*m)


n = int(input())
a = [int(i) for i in input().split()]
a.append(-1)
c = 0
print(a.count(1))
for i in range(n):
	if a[i] + 1 == a[i + 1]:
		c += 1
	else:
		print(c + 1, end=' ')
		c = 0


input()
ar = list(map(int, input().split()))
numS = 0
step = []
prev = None
for a in ar:
	if a == 1:
		numS += 1
		if prev:
			step += [prev]
	prev = int(a)
step += [prev]
print(numS)
for a in step:
	print(a, end=' ')


size = int(input())
all_steps = list(map(int, input().split(' ')))
stairs = all_steps.count(1)
print(stairs)
count = 1
steps = []
all_steps.append(1)
for i in all_steps[1:]:
	if i != 1:
		count += 1
	else:
		steps.append(count)
		count = 1
for i in steps:
	print(i, end=' ')


n = int(input())
T = input().split(' ')
T.append('1')
t = 0
L = []
for i in range(n):
	if T[i + 1] == '1':
		t += 1
		L.append(int(T[i]))
print(t)
for i in range(t - 1):
	print(L[i], end=' ')
print(L[-1])


N = int(input())
A = [int(x) for x in input().split()]
A.append(1)
sol = []
for i in range(1, len(A)):
	if A[i] == 1:
		sol.append(str(A[i - 1]))
print(len(sol))
import string
print(' '.join(sol))


input()
a = tuple(input().split()[(2, 1)[1]:]) + ('1',)
last = '1'
res = []
for i in range(len(a)):
	cur = a[i]
	if cur == '1':
		res.append(last)
	last = cur
print(len(res))
print(' '.join(res))


def calc(a):
	assert a
	(m, s) = (0, list())
	last = 0
	for item in a:
		if item == 1:
			m += 1
			if last:
				s.append(str(last))
		last = item
	s.append(str(last))
	return (m, s)

def get_ints():
	return [int(n) for n in input().split()]

def get_floats():
	return [float(n) for n in input().split()]
a = get_ints()
assert len(a) == 1
n = a[0]
assert n > 0
a = get_ints()
assert len(a) == n
(m, s) = calc(a)
print(m)
print(' '.join(s))


n = int(input())
list = input().split(' ')
for i in range(len(list)):
	list[i] = int(list[i])
count = 0
steps = []
for i in range(n):
	if list[i] == 1:
		count += 1
		if i - 1 >= 0:
			steps.append(list[i - 1])
steps.append(list[n - 1])
print(count)
print(' '.join((str(e) for e in steps)))


x = int(input())
a = list(map(int, input().split()))
k = 0
f = []
s = 1
for i in range(x):
	if a[i] == 1:
		k = k + 1
		s = 1
	if i == x - 1:
		continue
	if a[i + 1] == 1:
		f.append(s)
	s = s + 1
print(k)
for i in f:
	print(i, end=' ')
print(s)


n = int(input(''))
a = list(map(int, input().split()))
print(a.count(1))
if n == 1:
	print(a[0])
	exit()
for i in range(1, n - 1):
	if a[i] == 1:
		print(a[i - 1], end=' ')
if a[n - 1] == 1:
	print(a[n - 2], end=' ')
print(a[n - 1])


n = int(input())
l = list(map(int, input().split()))
index = []
for i in range(len(l)):
	if l[i] == 1:
		index.append(i)
print(len(index))
temp = []
for i in range(len(index)):
	try:
		temp.append(index[i + 1] - index[i])
	except:
		temp.append(len(l) - index[i])
print(*temp)


from sys import stdin, stdout
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))
for _ in range(1):
	n = nmbr()
	a = lst()
	cnt = 1
	ans = []
	for i in range(n):
		if a[i] != cnt:
			ans += [cnt - 1]
			cnt = 2
		else:
			cnt += 1
	ans += [cnt - 1]
	print(len(ans))
	print(*ans)


input()
l = [int(i) for i in input().split()]
count = 0
stair = 0
stairs = []
for i in l:
	if i == 1:
		count += 1
		if stair > 0:
			stairs.append(stair)
	stair = i
stairs.append(l[-1])
print(count)
print(*stairs)


total_stairs = int(input())
total_steps = [int(i) for i in input().split()]
stairs = 1
total = ''
i = 0
for i in range(1, total_stairs):
	if total_steps[i] == 1:
		stairs += 1
		total += str(total_steps[i - 1])
		total += ' '
total += str(total_steps[i])
print(stairs)
print(total)


n = int(input())
ans = list()
count = 0
x = [int(i) for i in input().split()]
for i in range(len(x) - 1):
	if x[i] >= x[i + 1]:
		ans.append(x[i])
		count = count + 1
ans.append(x[len(x) - 1])
count = count + 1
print(count)
for i in range(len(ans)):
	print(ans[i], end=' ')


num = int(input())
list1 = [v for v in input().split()]
stair = 1
ans = ''
for i in range(num - 1):
	if list1[i + 1] == '1':
		stair += 1
		ans += list1[i] + ' '
	else:
		pass
ans += list1[num - 1]
print(stair)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
start = 0
stairs = []
for i in range(1, n):
	if arr[i] == 1:
		stairs.append(str(i - start))
		start = i
stairs.append(str(n - start))
print(len(stairs))
print(' '.join(stairs))


n = int(input())
l = [int(x) for x in input().split()]
res = []
tmp = l[0]
for i in range(1, n):
	if l[i] > tmp:
		tmp += 1
	else:
		res.append(tmp)
		tmp = 1
res.append(tmp)
print(len(res))
print(*res, sep=' ')


_ = input()
A = list(map(int, input().split()))
n = len(A)
R = []
last = 0
for i in range(1, n):
	if A[i - 1] >= A[i]:
		R.append(i - last)
		last = i
if last < n:
	R.append(n - last)
print(len(R))
print(' '.join([str(x) for x in R]))


def solve():
	n = int(input())
	arr = [int(x) for x in input().split(' ')]
	prev = 0
	steps = []
	total_stairways = 0
	for (ind, x) in enumerate(arr):
		if ind == n - 1:
			if x <= prev:
				steps.append(prev)
				total_stairways += 1
			steps.append(x)
			total_stairways += 1
		elif x > prev:
			prev = x
		elif x <= prev:
			steps.append(prev)
			prev = x
			total_stairways += 1
	print(total_stairways)
	for x in steps:
		print(x, end=' ')
solve()


n = int(input())
stairs = list(map(int, input().split()))
staircases = stairs.count(1)
print(staircases)
for i in range(1, len(stairs)):
	if stairs[i] == 1:
		print(stairs[i - 1], end=' ')
print(stairs[len(stairs) - 1])


a = int(input())
z = 1
e = 0
b = list(map(int, input().split()))
d = []
b.append(1)
for i in range(a):
	if b[i] + 1 == b[i + 1]:
		z += 1
	else:
		d.append(z)
		z = 1
		e += 1
print(len(d))
print(*d)


d = int(input())
g = [int(_) for _ in input().split()]
(e, u, k) = (0, 0, [])
for i in g:
	if i == 1 and u != 0:
		k.append(str(e))
		e = 0
		e += 1
	else:
		e += 1
		u = 1
k.append(str(e))
print(len(k))
print(' '.join(k))


n = int(input())
seq = [x for x in input().split()]
print(seq.count('1'))
ans = []
for i in range(1, n):
	if seq[i] == '1':
		ans.append(seq[i - 1])
ans.append(seq[-1])
print(' '.join(ans))


n = int(input())
a = input().split()
a = [int(x) for x in a]
s = i = k = 0
b = []
while i < n - 1:
	k += 1
	if a[i] >= a[i + 1]:
		s += 1
		b.append(k)
		k = 0
	i += 1
b.append(k + 1)
print(s + 1)
for x in b:
	print(x)


N = int(input())
STAIRS = list(map(int, input().strip().split(' ')))
OUTPUT = []
for s in STAIRS:
	if s == 1:
		OUTPUT.append(1)
	else:
		OUTPUT.append(OUTPUT.pop() + 1)
print(len(OUTPUT))
print(' '.join(map(str, OUTPUT)).strip())


def main(steps):
	prev = 0
	total = []
	for step in steps:
		if step != prev + 1:
			total.append(prev)
		prev = step
	total.append(prev)
	print(len(total))
	print(' '.join([str(i) for i in total]))
input()
main([int(i) for i in input().split()])


n = int(input())
s = input()
v = []
v = s.split(' ')
for i in range(n):
	v[i] = int(v[i])
v.append(0)
rez = 0
w = []
for i in range(1, n + 1):
	if v[i] <= v[i - 1]:
		w.append(v[i - 1])
		rez += 1
print(rez)
s = ''
for i in range(rez):
	s += str(w[i]) + ' '
print(s)


n = int(input())
l = list(map(int, input().strip().split(' ')))
p = []
count = 0
for i in range(n):
	if l[i] == 1:
		count += 1
		p.append(1)
	else:
		p[-1] += 1
print(count)
print(*p)


n = int(input())
s = input().split()
pd = 1
k = []
for i in range(0, n - 1):
	if i == n - 2:
		if int(s[i]) < int(s[i + 1]):
			k.append(pd + 1)
		else:
			k.append(pd)
			k.append(1)
	elif int(s[i]) < int(s[i + 1]):
		pd += 1
	else:
		k.append(pd)
		pd = 1
if len(k) == 0:
	print(1)
	print(1)
else:
	print(len(k))
	k = str(k)
	k = k.replace('[', '')
	k = k.replace(']', '')
	k = k.replace(',', '')
	print(k)


n = int(input())
a = list(map(int, input().split()))
stairs = list()
stairways = 0
for i in range(n):
	if a[i] == 1:
		stairways += 1
		if i != 0:
			stairs.append(count)
		count = 1
	else:
		count += 1
stairs.append(count)
print(stairways)
for i in range(stairways):
	print(stairs[i], end=' ')


x = int(input())
numbers = list(map(int, input().split()))
answer = []
counter = []
count = 1
for i in range(len(numbers)):
	if numbers[i] not in answer:
		answer.append(numbers[i])
	else:
		counter.append(len(answer))
		answer.clear()
		answer.append(numbers[i])
		count = count + 1
print(count)
for j in range(len(counter)):
	print(counter[j], end=' ')
print(numbers[-1])


n = int(input())
l = list(map(int, input().rstrip().split()))
print(l.count(1))
count = 0
for i in l[1:]:
	if i == 1:
		print(count + 1, end=' ')
		count = 0
	else:
		count += 1
print(count + 1)


n = int(input())
l = list(map(int, input().split()))
count = []
c = 0
for i in range(n - 1):
	if l[i] >= l[i + 1]:
		count.append(l[i])
		if i + 1 == n - 1:
			c = 1
			count.append(l[i + 1])
		else:
			continue
	else:
		continue
if c == 0:
	count.append(l[n - 1])
print(len(count))
for i in range(len(count)):
	print(count[i], end=' ')


n = int(input())
a = []
s = -1
str1 = input()
for i in str1.split():
	x = int(i)
	if x == 1:
		s += 1
		a.append(0)
	a[s] += 1
print(s + 1)
for i in range(s):
	print(a[i], end=' ')
print(a[s])


x = int(input())
y = list(map(int, input().split()))
v = []
o = 0
for i in range(x - 1):
	if y[i] >= y[i + 1]:
		v.append(y[i])
		o += 1
v.append(y[-1])
print(o + 1)
for i in v:
	print(i, end=' ')


num = int(input())
seq = list(map(int, input().split()))
s = -1
cont = 0
stairs = []
for i in range(num):
	if s >= seq[i]:
		stairs.append(s)
		cont += 1
	s = seq[i]
if s <= seq[-1]:
	cont += 1
	stairs.append(s)
print(cont)
for i in range(len(stairs) - 1):
	print(stairs[i], end=' ')
print(stairs[-1])


n = int(input())
lis = input().split(' ')
count = 1
lis2 = []
for i in range(1, n):
	if int(lis[i]) == 1:
		count += 1
		lis2.append(lis[i - 1])
lis2.append(lis[n - 1])
print(count)
print(*lis2)


n = int(input())
v = [int(i) for i in input().split()]
aux = []
count = 0
for i in range(0, n):
	if v[i] == 1:
		if i != 0:
			aux.append(v[i - 1])
		count += 1
aux.append(v[-1])
print(count)
for i in range(0, count):
	print(aux[i])


n = int(input())
counts = [int(x) for x in input().split()]
n_stairways = 0
stairways = []
for i in range(n):
	if counts[i] == 1:
		n_stairways += 1
		if i > 0:
			stairways.append(str(counts[i - 1]))
	if i == n - 1:
		stairways.append(str(counts[i]))
print(n_stairways)
print(' '.join(stairways))


n = int(input())
l = [int(i) for i in input().split()]
count = 0
count1 = 0
l1 = []
for x in l:
	if x == 1:
		count1 += 1
		l1.append(count + 1)
		count = 0
	else:
		count += 1
l1.append(count + 1)
print(count1)
for i in range(1, len(l1)):
	print(l1[i], end=' ')


import math
import itertools
getInputList = lambda : list(input().split())
getInputIntList = lambda : list(map(int, input().split()))
n = int(input())
arr = getInputIntList()
ans = []
for i in range(n - 1):
	if arr[i + 1] <= arr[i]:
		ans.append(arr[i])
ans.append(arr[n - 1])
print(len(ans))
[print(i, end=' ') for i in ans]


n = int(input())
a = [int(x) for x in input().split()]
k = 1
u = []
q = 1
for i in range(1, len(a)):
	if a[i] == 1 or i == len(a) - 1:
		if i == len(a) - 1:
			if a[i] == 1:
				u.append(q)
				u.append(1)
				k += 1
			else:
				u.append(q + 1)
		else:
			k += 1
			u.append(q)
			q = 1
	else:
		q += 1
if n == 1:
	print(1)
	print(1)
else:
	print(k)
	for i in range(len(u)):
		print(u[i], end=' ')


def answer():
	a = int(input())
	b = input().split()
	c = [x for x in b if x == '1']
	print(len(c))
	i = 0
	c_out = ''
	while i < len(b) - 1:
		if b[i + 1] == '1':
			c_out += b[i]
			c_out += ' '
		i += 1
	c_out += b[-1]
	print(c_out)
answer()


import math
from collections import defaultdict
ml = lambda : map(int, input().split())
ll = lambda : list(map(int, input().split()))
ii = lambda : int(input())
ip = lambda : list(input())
ips = lambda : input().split()
n = ii()
a = ll()
ans = []
for i in range(1, n):
	if a[i] <= a[i - 1]:
		ans.append(a[i - 1])
ans.append(a[n - 1])
print(len(ans))
print(*ans)


_ = int(input())
escalones = [int(e) for e in input().split()]
escaleras = []
for (i, e) in enumerate(escalones[:-1]):
	if escalones[i + 1] <= e:
		escaleras.append(e)
escaleras += escalones[-1:]
print('{}\n{}'.format(len(escaleras), ' '.join(map(str, escaleras))))


import sys, math, itertools, collections, bisect
input = lambda : sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
mod = 10 ** 9 + 7
mans = inf
ans = 0
count = 0
pro = 1
n = int(input())
A = list(map(int, input().split()))
A.append(1)
ans = []
i = j = 0
while i < n:
	i += 1
	while i < n + 1 and A[i] != 1:
		i += 1
	ans.append(A[i - 1])
print(len(ans))
print(*ans)


n = int(input().strip())
c = [int(_) for _ in input().strip().split()]
print(c.count(1))
arr = []
for i in range(1, len(c)):
	if c[i] == 1:
		arr.append(c[i - 1])
arr.append(c[-1])
print(*arr)


n = int(input())
a = list(map(int, input().split()))
a.append(1)
tuncounter = 0
counter = 1
lesnici = []
x = 1
print(a.count(1) - 1)
for i in range(1, n + 1):
	if a[i] > a[i - 1]:
		counter += 1
	else:
		lesnici.append(counter)
		counter = 1
print(' '.join(map(str, lesnici)))


n = int(input())
num = input()
a = []

def get_the_data(count, num, arr):
	for i in range(0, len(num)):
		if num[i] == ' ':
			arr.append(int(num[count:i]))
			count = i + 1
		elif i == len(num) - 1:
			arr.append(int(num[count:len(num)]))
	return arr
arr = get_the_data(0, num, a)
different = 0
max_num = ''
if len(arr) == 1:
	print(1)
	print(arr[0])
else:
	for i in range(0, len(arr) - 1):
		if arr[i + 1] <= arr[i]:
			max_num += str(arr[i]) + ' '
			different += 1
		if i == len(arr) - 2:
			max_num += str(arr[i + 1])
			different += 1
	print(different)
	print(max_num)