https://pintia.cn/problem-sets/994805046380707840/exam/problems/1649748772841508872?type=7&page=1
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;
typedef vector<long long> VI;
#define int long long
#define INF 0x3f3f3f3f
#define endl '\n'
#define N 200010
const int mod = 1e9 + 7;
ll ksm(ll a, ll b) {
ll ans = 1;
for (; b; b >>= 1LL) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
ll lowbit(ll x) {
return -x & x;
}
int p[N], si[N];
int find(int x) {
if (x == p[x])return p[x];
p[x] = find(p[x]);
return p[x];
}
//size[find(b)] += size[find(a)];
//p[find(a)] = find(b);
void solve() {
int n;
cin >> n;
vector<int> a, b;
int res = 0, ans = 0;
for (int i = 1; i <= n ; i ++) {
int x;
cin >> x;
if (a.empty())a.push_back(x);
else if (x < a.back())a.push_back(x);
else {
if (b.empty() || x > b.back())b.push_back(x);
else {
res ++;
ans = max(ans, (int)a.size());
a.clear();
while (!b.empty() && b.back() > x) {
a.push_back(b.back());
b.pop_back();
}
a.push_back(x);
}
}
}
if (!a.empty()) {
res ++;
ans = max(ans, (int)a.size());
}
if (!b.empty()) {
res ++;
ans = max(ans, (int)a.size());
}
cout << res << " " << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
// cin >> T;
while (T --)
solve();
return 0;
}