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

Difficulty: introductory

Starter code:

Solutions:
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 = int(input())
a = list(map(int, input().split()))
ans = []
cnt = 0
for i in range(n):
    if a[i] == 1:
        if cnt != 0:
            ans.append(cnt)
            cnt = 0
    cnt += 1
ans.append(cnt)
print(len(ans))
print(*ans)

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)



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 = ' ')

def scanf(obj=list, type=int):
    return obj(list(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)


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()
a = list(map(int, input().split()))
b = []
for i in range(1, len(a)):
    if a[i] == 1:
        b += [a[i - 1]]
b += [a[-1]]
print(len(b))
print(*b)


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

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


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


# import sys
# sys.stdin=open('F:\\C\\Script\\input.txt','r')
# sys.stdout=open('F:\\C\\Script\\output.txt','w')
# sys.stdout.flush()

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)

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)

import sys
import io

stream_enable = 0

inpstream = """
7
1 2 3 1 2 3 4

"""

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)


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

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


#1
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 = [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())
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=" ")