#include <bits/stdc++.h>
using namespace std;
#define Sonic ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define tests(t) int t; cin >> t; while(t--)
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define ln cout<<endl;
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define read(x) for(auto &el : x) cin >> el;
#define reads(s, n) for(int i = 0, x; i < n; ++i) {cin >> x; s.insert(x);}
#define forn(i,n) for(int i=0; i < int(n); ++i)
#define forsn(i, s, n) for (int i = s; i < n; ++i)
#define dforn(i, n) for (int i = n - 1; i >= 0; --i)
#define DBG(x) cout << #x << " = " << x << endl;
#define print(x) for(auto &el : x) {cout << el << " ";} cout<<endl;
#define lw(c, x) int(lower_bound((c).begin(), (c).end(), (x)) - (c).begin())
#define up(c, x) int(upper_bound((c).begin(), (c).end(), (x)) - (c).begin())
#define sino(b) cout<<(b ? "YES\n":"NO\n");
#define syso(x) cout<< (x) <<endl;
#define kill(x) {cout<< (x) <<endl; return;}
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef pair<ll,ll> pll;
ll gcd(ll a, ll b){while(b){a%=b; swap(a,b);} return a;} ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int lg2(const int &x) { return 31-__builtin_clz(x);} // int lg2(const ll &x) {return 63-__builtin_clzll(x);}
// Para leer e imprimir .txt
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);


const int MAX = 1e5+5;
// int A[MAX];
int dp[MAX];
vector<int> LIS; // PARA Lis_opt
int n;

int lis_opt(vector<int> &A) {
    LIS.clear();
    for (int i = 0; i < n; i++) {
        auto id = lower_bound(LIS.begin(), LIS.end(), A[i]);
        if (id == LIS.end()) {
            LIS.pb(A[i]);
            dp[i] = LIS.size();
        }
        else {
            int idx = id - LIS.begin();
            LIS[idx] = A[i];
            dp[i] = idx + 1;
        }
    }
    return LIS.size();
}

stack<int> rb;
void build(vector<int> &A) {
    int k = LIS.size();
    int cur = 1e9;
    for (int i = n - 1; i >= 0, k; i--) {
        if (A[i] < cur && k == dp[i]) {
            cur = A[i];
            rb.push(A[i]);
            k--;
        }
    }
}

void solve(){
    int x;
    vi a;
    while (cin>>x) a.pb(x);
    n = sz(a);
    lis_opt(a);
    build(a);
    syso(sz(rb))
    syso('-')
    while (!rb.empty()){syso(rb.top())rb.pop();}
    cout << endl;
}

int main(){
    Sonic
    // tests(t)
        solve();
    return 0;
}
//"Quiero picha" - Sebastian Nieto 2026