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≤n≤1000) — the total number of numbers pronounced by Tanya.

The second line contains integers a1,a2,…,an (1≤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 x steps, she will pronounce the numbers 1,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 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

//xjb模拟
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define debug() puts("++++")
#define gcd(a,b) __gcd(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a,b,sizeof(a))
#define sz size()
#define be begin()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
#define all 1,n,1
#define rep(i,x,n) for(int i=(x); i<(n); i++)
#define in freopen("in.in","r",stdin)
#define out freopen("out.out","w",stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const ll LNF = 1e18;
const int N = 1e5 + 20;
const int maxm = 1e6 + 10;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int dx[] = {-1,1,0,0,1,1,-1,-1};
const int dy[] = {0,0,1,-1,1,-1,1,-1};
int dir[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int n,a[N];
set<int> s;
vector<int> v;
int main()
{
while(~scanf("%d",&n))
{
s.clear();
v.clear();
rep(i,0,n)
{
scanf("%d",&a[i]);
if(a[i]==1 && i!=0)
{
v.push_back(a[i-1]);
}
s.insert(a[i]);
}
if(s.size() == 1) //复杂的特判
{
printf("%d\n",n);
rep(i,0,n)
{
if(i!=n-1) printf("%d ",a[i]);
else printf("%d\n",a[i]);
}
}
else if(s.size() == n) //复杂的特判
{
printf("1\n");
printf("%d\n",a[n-1]);
}
else
{
printf("%d\n",v.size()+1);
rep(i,0,v.size())
{
printf("%d ",v[i]);
}
printf("%d\n",a[n-1]);
}
}
}
/*
1234 12345 1234567
*/

【非STL-数组】

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a[1010],b[1010],ans=1;
cin>>n>>a[0];
for(int i=1;i<n;i++)
{
cin>>a[i];
if(a[i]==1)
b[ans++]=a[i-1];
}
cout<<ans<<endl;
b[ans++]=a[n-1];
for(int i=1;i<ans;i++)
cout<<b[i]<<" ";
return 0;
}

CF 1005A Tanya and Stairways 【STL】的更多相关文章

  1. 【最短路】【STL】CSU 1808 地铁 (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1808 题目大意: N个点M条无向边(N,M<=105),每条边属于某一条地铁Ci ...

  2. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  3. 【STL】【模拟】Codeforces 696A Lorenzo Von Matterhorn

    题目链接: http://codeforces.com/problemset/problem/696/A 题目大意: 一个满二叉树,深度无限,节点顺序编号,k的儿子是k+k和k+k+1,一开始树上的边 ...

  4. 蓝桥 ADV-233 算法提高 队列操作 【STL】

      算法提高 队列操作   时间限制:1.0s   内存限制:256.0MB      问题描述 队列操作题.根据输入的操作命令,操作队列(1)入队.(2)出队并输出.(3)计算队中元素个数并输出. ...

  5. CF 1006B Polycarp's Practice【贪心】

    Polycarp is practicing his problem solving skill. He has a list of n problems with difficulties a1,a ...

  6. CF987A Infinity Gauntlet【STL】

    [链接]:CF987A [分析]:运用map [代码]: #include <iostream> #include<queue> #include<string.h> ...

  7. 华农oj Problem B: Averyboy找密码【STL】

    Problem B: Averyboy找密码 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 83 Solved: 29 [Submit][Status] ...

  8. 洛谷P1118 数字三角形【dfs】【STL】

    题目链接:https://www.luogu.org/problemnew/show/P1118 题意: 1~n的一个排列,相邻的两项加起来得到下一行. 现在给定最后一行的数字,问最初的1~n的排列是 ...

  9. 【STL】优先队列priority_queue详解+OpenJudge-4980拯救行动

    一.关于优先队列 队列(queue)这种东西广大OIer应该都不陌生,或者说,队列都不会你还学个卵啊(╯‵□′)╯︵┻━┻咳咳,通俗讲,队列是一种只允许从前端(队头)删除元素.从后端(队尾)插入元素的 ...

随机推荐

  1. Hibernate对象状态

    对象状态 瞬时(transient) 自己new出来的对象,数据库没有记录与之对应,与session也没有关联 持久(persistent) 数据库中有记录与之对应,当前与session有关联,相关的 ...

  2. 不使用库函数、自己编写的(strlen、strcpy、strcmp、strcat、memcmp、memcpy、memmove)

    不使用库函数.自己编写的(strlen.strcpy.strcmp.strcat.memcmp.memcpy.memmove) //求字符串长度的函数 int my_strlen(const char ...

  3. 02.Java面向对象问题

    目录介绍 2.0.0.1 重载和重写的区别?重载和重写绑定机制有何区别?父类的静态方法能否被子类重写? 2.0.0.2 封装.继承.多态分别是什么? 2.0.0.3 接口和抽象类的区别是什么?接口的意 ...

  4. [HEOI2015]最短不公共子串

    四合一的题. 简单粗暴的方法: 子串匹配——SAM 子序列匹配——序列自动机 关于序列自动机:序列自动机—— [FJOI2016]所有公共子序列问题 (其实这个玩意没有什么,n+1个点,每个点的字符集 ...

  5. 如何实现加载DOM时执行js代码

    有一些功能需求,需要在DOM载入时马上执行一些函数,但又不愿意仅为了这一个需求而引入整个JQuery库,于是就把jQuery的方法提取出来,单独使用了. 大家可以使用windows.onload事件, ...

  6. SQL SERVER:删除筛选记录中前100条数据

    delete from table1 where id in (select top 100 id from table1)

  7. MAVEN 编译打包测试 指定本地jar

    转载自:http://penuel.iteye.com/blog/1766102 maven对于互联网开发,进行版本管理有着不可或缺的作用;  而经常开发的程序猿直接联调或者依赖未上线或deploy的 ...

  8. 【转载】How long is “too long” for MySQL Connections to sleep?

    From:http://dba.stackexchange.com/questions/1558/how-long-is-too-long-for-mysql-connections-to-sleep ...

  9. Python爬虫学习笔记之爬今日头条的街拍图片

    代码: import requests import os from hashlib import md5 from urllib.parse import urlencode from multip ...

  10. bootstrap再次回顾认识到的东西

    1,需要使用html5文档类型(Doctype),因此在使用bootstrap项目的开头包含下面的代码段. <!DOCTYPE html> <html> ....... < ...