#include <cstdio>
#include <algorithm>
using namespace std;
#define n_max 100000
#define h_max 50000
int h[n_max + 1] = { 0 }, q1[n_max + 1] = { 0 }, q2[n_max + 1] = { 0 }, num = 0;
//op=1是求最长不增序列的长度;op=2是求最长上升序列的长度
int longest(int a[], int t[], int op)
{
int len = 0, i;
for (i = 1; i <= num; ++i)
{
bool flag;
if (op == 1)
flag = t[len] >= a[i];
else
flag = t[len] < a[i];
if (flag)
t[++len] = a[i];
else{
if(op == 1)
*upper_bound(t + 1, t + len + 1, a[i], greater<int>()) = a[i];
else
*lower_bound(t + 1, t + len + 1, a[i]) = a[i];
}
}
return len;
}
int main()
{
do {
scanf("%d", &h[++num]);
} while (getchar() == ' ');
q1[0] = h_max + 1;
printf("%d\n%d\n", longest(h, q1, 1), longest(h, q2, 2));
return 0;
}