前自加和后自加

Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from 11 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 33 steps, and the second contains 44 steps, she will pronounce the numbers 1,2,3,1,2,3,41,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 nn (1≤n≤10001≤n≤1000) — the total number of numbers pronounced by Tanya.

The second line contains integers a1,a2,…,ana1,a2,…,an (1≤ai≤10001≤ai≤1000) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway with xx steps, she will pronounce the numbers 1,2,…,x1,2,…,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 tt — the number of stairways that Tanya climbed. In the second line, output tt 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 

小女孩Tanya爬上一栋多层建筑内的楼梯。每当Tanya爬上楼梯,她就开始计算从11到步骤的步数。她大声说出每一个号码。例如,如果她爬上两个楼梯,第一个包含33个台阶,第二个包含44个台阶,她会发出数字1,2,3,1,2,3,41,2,3,1,2 ,3,4。

你得到了Tanya发出的所有数字。她爬了多少楼梯?此外,输出每个楼梯的步数。

给定的序列将是Tanya在攀爬一个或多个楼梯时可能发出的有效序列。

输入
第一行包含nn(1≤n≤10001≤n≤1000) - 由Tanya发音的总数。

第二行包含整数a1,a2,...,ana1,a2,...,an(1≤ai≤10001≤ai≤1000) - Tanya在爬楼梯时发出的所有数字,从第一个到最后一个显着的数字。通过xx步骤的楼梯,她将按顺序发出数字1,2,...,x1,2,...,x。

给定的序列将是Tanya在攀爬一个或多个楼梯时可能发出的有效序列。

产量
在第一行,输出tt - Tanya攀登的楼梯数量。在第二行,输出tt数字 - 她攀爬的每个楼梯的步数。以正确的楼梯通道顺序写下数字。

例子
输入
7
1 2 3 1 2 3 4
产量
2
3 4
输入
4
1 1 1 1
产量
4
1 1 1 1
输入

1 2 3 4 5
产量
1

输入

1 2 1 2 1
产量
3
2 2 1


#include<iostream>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		int a[n];
		 int b[n];
		int max;
		int count=0;
		for(int i=0;i<n;i++){
			cin>>a[i];}
			max=a[0];
			for(int q=1;q<n;q++){
			
			
			  if(a[q]==1)
			  {
			  	b[++count]=a[q-1];//每加一次,count+=1,并且放到了方框里
			  }
			  
			  }
		
		cout<<count+1<<endl;
		for(int j=1;j<=count;j++)
		cout<<b[j]<<" ";
		cout<<a[n-1]<<endl;
	}
	
		  return 0;
}
#include<iostream>
using namespace std;
int main()
{
	int n;
	while(cin>>n)
	{
		int a[n];
		 int b[n];
		int max;
		int count=1;
		for(int i=0;i<n;i++){
			cin>>a[i];}
			max=a[0];
			for(int q=1;q<n;q++){
			
			
			  if(a[q]==1)
			  {
			  	b[count++]=a[q-1];//b[count]=a[q-1]; count++;
			  }
			  
			  }
		
		cout<<count<<endl;
		for(int j=1;j<count;j++)
		cout<<b[j]<<" ";
		cout<<a[n-1]<<endl;
	}
	
		  return 0;
}

猜你喜欢

转载自blog.csdn.net/xyy19990130/article/details/82082379