#include <cstdio>
#include <cstring>
#include <climits>
#include <new>
#include <queue>
#include <algorithm>
const int MAXN = 500;
struct Node;
struct Edge;
struct Node {
Edge *e, *c;
int level;
} N[MAXN * 2 + 10];
struct Edge {
Node *fr, *to;
Edge *ne, *rev;
int cap, flow;
Edge() {}
Edge(Node *fr, Node *to, int cap) : fr(fr), to(to), ne(fr->e), cap(cap), flow(0) {}
};
inline void addEdge(int fr, int to, int cap) {
N[fr].e = new Edge(&N[fr], &N[to], cap);
N[to].e = new Edge(&N[to], &N[fr], 0);
N[fr].e->rev = N[to].e, N[to].e->rev = N[fr].e;
}
struct Dinic {
bool makeLevelGraph(Node *s, Node *t, int n) {
for (int i = 0; i < n; i++) N[i].c = N[i].e, N[i].level = 0;
std::queue<Node *> q;
q.push(s);
s->level = 1;
while (!q.empty()) {
Node *v = q.front();
q.pop();
for (Edge *e = v->e; e; e = e->ne) {
if (e->cap > e->flow && e->to->level == 0) {
e->to->level = v->level + 1;
if (e->to == t) return true;
q.push(e->to);
}
}
}
return false;
}
int findPath(Node *s, Node *t, int limit = INT_MAX) {
if (s == t) return limit;
for (Edge *&e = s->c; e; e = e->ne) {
if (e->cap > e->flow && e->to->level == s->level + 1) {
int flow = findPath(e->to, t, std::min(e->cap - e->flow, limit));
if (flow > 0) {
e->flow += flow;
e->rev->flow -= flow;
return flow;
}
}
}
return 0;
}
int operator()(int s, int t, int n) {
int res = 0;
while (makeLevelGraph(&N[s], &N[t], n)) {
int flow;
if ((flow = findPath(&N[s], &N[t])) > 0) res += flow;
}
return res;
}
} dinic;
int a[MAXN + 1], f[MAXN + 1], n, maxLength;
int subTask1() {
int res = 0;
for (int i = 1; i <= n; i++) f[i] = 1;
for (int i = 1; i <= n; i++) {
int lastStat = 0;
for (int j = 1; j < i; j++) {
if (a[i] >= a[j] && lastStat < f[j]) lastStat = f[j];
}
f[i] = lastStat + 1;
res = std::max(res, f[i]);
}
return res;
}
int subTask2() {
const int s = 0, t = n * 2 + 1;
for (int i = 1; i <= n; i++) {
addEdge(i, i + n, 1);
if (f[i] == maxLength) addEdge(i + n, t, 1);
if (f[i] == 1) addEdge(s, i, 1);
for (int j = 1; j < i; j++) {
if (f[j] == f[i] - 1 && a[j] <= a[i]) addEdge(j + n, i, 1);
}
}
int res = dinic(s, t, n * 2 + 2);
return res;
}
int subTask3() {
const int s = 0, t = n * 2 + 1;
for (int i = 1; i <= n; i++) {
int cap = 1;
if (i == 1 || i == n) cap = INT_MAX;
addEdge(i, i + n, cap);
if (f[i] == maxLength) addEdge(i + n, t, cap);
if (f[i] == 1) addEdge(s, i, cap);
for (int j = 1; j < i; j++) {
if (f[j] == f[i] - 1 && a[j] <= a[i]) addEdge(j + n, i, 1);
}
}
int res = dinic(s, t, n * 2 + 2);
return res;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
printf("%d\n", maxLength = subTask1());
if (maxLength == 1) {
printf("%d\n%d", n, n);
} else {
printf("%d\n", subTask2());
for (int i = 0; i < n * 2 + 2; i++) {
for (Edge *&e = N[i].e, *ne; e; ne = e->ne, delete e, e = ne);
N[i].e = N[i].c = NULL;
N[i].level = 0;
}
printf("%d\n", subTask3());
}
return 0;
}