#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1000000];
bool seen[1000000];
int inv[1000000];
int cntIso[1000000];
int cntPieni[1000000];
int solve(int n) {
int ans = 0;
for (int i = 1; i <= n; i++) seen[i] = false;
for (int i = 1; i <= n; i++) {
if (a[i] == 1 || !seen[a[i]-1]) ans++;
seen[a[i]] = true;
}
return ans;
}
bool identity(int n) {
for (int i = 2; i <= n; i++) {
if (a[i] != a[i-1]+1) return false;
}
return true;
}
#define N (1<<18)
ll p[2*N];
void muuta(int k, int x) {
k += N;
p[k] += x;
for (k /= 2; k >= 1; k /= 2) {
p[k] = p[2*k]+p[2*k+1];
}
}
void muutavali(int a, int b, int x) {
if (a > b) return;
muuta(a,x);
muuta(b+1, -x);
}
ll summa(int a, int b) {
a += N;
b += N;
ll s = 0;
while (a <= b) {
if (a%2 == 1) s += p[a++];
if (b%2 == 0) s += p[b--];
a /= 2; b /= 2;
}
return s;
}
int apu[1000000];
void muunna(int n) {
for (int i = 0; i <= n+1; i++) apu[i] = a[n+1-i];
for (int i = 0; i <= n+1; i++) a[i] = apu[i];
for (int i = 0; i <= n+1; i++) a[i] = n + 1 - a[i];
for (int i = 0; i <= n+1; i++) inv[a[i]] = i;
/*
cout << "a : ";
for (int i = 0; i <= n+1; i++) cout << a[i] << " ";
cout << endl;
cout << "b : ";
for (int i = 0; i <= n+1; i++) cout << inv[i] << " ";
cout << endl;
*/
}
ll ratkaise(int n) {
ll ans = 0;
//cout << "summa: " << 0 << " " << summa(1, 1) << endl;
for (int i = 1; i <= n; i++) {
if (inv[a[i]-1] < inv[a[i]] && inv[a[i]] < inv[a[i]+1]) { // 7 8 9
muutavali(inv[a[i]-1]+1, inv[a[i]]-1, 1);
}
else if (inv[a[i]-1] < inv[a[i]+1] && inv[a[i]+1] < inv[a[i]]) { // 7 9 8
//muutavali(1,inv[a[i]]-1, 1);
muutavali(1, inv[a[i]+1]-1, 1);
muutavali(inv[a[i]+1]+1, inv[a[i]]-1, 1);
}
else if (inv[a[i]] < inv[a[i]+1] && inv[a[i]+1] < inv[a[i]-1]) { // 8 9 7
muutavali(1,inv[a[i]]-1, 1);
}
else if (inv[a[i]] < inv[a[i]-1] && inv[a[i]-1] < inv[a[i]+1]) { // 8 7 9
muutavali(1,inv[a[i]]-1, 1);
}
else if (inv[a[i]+1] < inv[a[i]-1] && inv[a[i]-1] < inv[a[i]]) { // 9 7 8
muutavali(1,inv[a[i]+1]-1, 1);
muutavali(inv[a[i]-1]+1, inv[a[i]]-1, 1);
}
else if (inv[a[i]+1] < inv[a[i]] && inv[a[i]] < inv[a[i]-1]) { // 9 8 7
muutavali(1,inv[a[i]]-1, 1);
}
/*
cout << "summa: " << a[i] << endl;
for (int i = 1; i <= n; i++) {
cout << summa(1,i) << " ";
}
cout << endl;
*/
}
//cout << endl;
for (int i = 1; i <= n; i++) {
//cout << "summa: " << i << " " << a[i] << endl;
if (inv[a[i]-1] < inv[a[i]] && inv[a[i]] < inv[a[i]+1]) { // 7 8 9
muutavali(inv[a[i]-1]+1, inv[a[i]]-1, -1);
}
else if (inv[a[i]-1] < inv[a[i]+1] && inv[a[i]+1] < inv[a[i]]) { // 7 9 8
//muutavali(1,inv[a[i]]-1, 1);
muutavali(1, inv[a[i]+1]-1, -1);
muutavali(inv[a[i]+1]+1, inv[a[i]]-1, -1);
}
else if (inv[a[i]] < inv[a[i]+1] && inv[a[i]+1] < inv[a[i]-1]) { // 8 9 7
muutavali(1,inv[a[i]]-1, -1);
}
else if (inv[a[i]] < inv[a[i]-1] && inv[a[i]-1] < inv[a[i]+1]) { // 8 7 9
muutavali(1,inv[a[i]]-1, -1);
}
else if (inv[a[i]+1] < inv[a[i]-1] && inv[a[i]-1] < inv[a[i]]) { // 9 7 8
muutavali(1,inv[a[i]+1]-1, -1);
muutavali(inv[a[i]-1]+1, inv[a[i]]-1, -1);
}
else if (inv[a[i]+1] < inv[a[i]] && inv[a[i]] < inv[a[i]-1]) { // 9 8 7
muutavali(1,inv[a[i]]-1, -1);
}
cntIso[a[i]] = summa(1, inv[a[i]+1]);
cntPieni[a[i]] = summa(1,inv[a[i]-1]);
/*
for (int i = 1; i <= n; i++) {
cout << summa(1,i) << " ";
}
cout << endl;
*/
}
for (int i = 1; i <= n; i++) {
//cout << i << " " << ans << endl;
if (inv[a[i]] < inv[a[i]-1] && inv[a[i]-1] < inv[a[i]+1]) {
ans += cntIso[a[i]-1] - cntPieni[a[i]+1];
/*
cout << "here" << endl;
cout << cntIso[a[i]-1] << " " << a[i]-1 << endl;
cout << cntPieni[a[i]+1] << " " << a[i] + 1 << endl;
cout << endl;
*/
}
if (inv[a[i]+1] < inv[a[i]] && inv[a[i]] < inv[a[i]-1]) {
ans += cntIso[a[i]-1];
}
}
return ans;
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
if (identity(n)) {
cout << 2 << " " << n-1 << "\n";
return 0;
}
int startval = solve(n);
a[n+1] = n+1;
for (int i = 0; i <= n+1; i++) inv[a[i]] = i;
for (int i = 1; i <= n; i++) {
if (inv[i-1] < inv[i+1] && inv[i+1] < inv[i]) {
muutavali(inv[i-1]+1, inv[i+1]-1, 1);
}
if (inv[i+1] < inv[i] && inv[i] < inv[i-1]) {
muutavali(1,inv[i+1]-1, 1);
}
}
for (int i = 1; i <= n; i++) {
if (inv[a[i]-1] < inv[a[i]+1] && inv[a[i]+1] < inv[a[i]]) { // 7 9 8
muutavali(inv[a[i]-1]+1, inv[a[i]+1]-1, -1);
}
if (inv[a[i]+1] < inv[a[i]] && inv[a[i]] < inv[a[i]-1]) { // 9 8 7
muutavali(1,inv[a[i]+1]-1, -1);
}
cntIso[a[i]] = summa(1, inv[a[i]+1]);
cntPieni[a[i]] = summa(1,inv[a[i]-1]);
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
if (inv[a[i]] < inv[a[i]-1] && inv[a[i]-1] < inv[a[i]+1]) {
ans += cntIso[a[i]-1] - cntPieni[a[i]+1];
}
if (inv[a[i]+1] < inv[a[i]] && inv[a[i]] < inv[a[i]-1]) {
ans += cntIso[a[i]-1];
}
}
/*
for (int i = 1; i <= n; i++) {
cout << i << " " << cntIso[i] << " " << cntPieni[i] << endl;
}
*/
if (ans > 0) {
cout << startval - 2 << " " << ans << "\n";
return 0;
}
/*
for (int i = 1; i <= n; i++) {
cntIso[i] = 0;
cntPieni[i] = 0;
}
*/
//for (int i = 0; i < 2*N; i++) p[i] = 0;
for (int i = 1; i < n; i++) {
if (inv[i+1] < inv[i] && (inv[i+2] < inv[i+1] || inv[i+2] > inv[i]) && (inv[i-1] < inv[i+1] || inv[i-1] > inv[i])) ans++;
}
//cout << ans << endl;
ans += ratkaise(n);
muunna(n);
//for (int i = 0; i <= n+1; i++) cout << a[i] << " ";
//cout << endl;
//cout << ans << endl;
ans += ratkaise(n);
muunna(n);
for (int i = 1; i < n; i++) {
if (inv[i] < inv[i+1] && (inv[i-1] > inv[i] && inv[i-1] < inv[i+1]) && (inv[i+2] > inv[i] && inv[i+2] < inv[i+1])) ans--;
}
if (ans > 0) {
cout << startval - 1 << " " << ans << "\n";
return 0;
}
ans = (ll)n*(n-1)/2;
//cout << ans << endl;
for (int i = 1; i < n; i++) {
if (inv[i] < inv[i+1]) {
ans -= n - (inv[i+1] - inv[i]);
} else {
ans += n - (inv[i] - inv[i+1]);
}
}
for (int i = 0; i <= n+1; i++) apu[i] = a[n+1-i];
for (int i = 0; i <= n+1; i++) a[i] = apu[i];
for (int i = 0; i <= n+1; i++) inv[a[i]] = i;
ll ans2 = 0;
for (int i = 1; i <= n; i++) {
if (inv[i-1] < inv[i+1] && inv[i+1] < inv[i]) {
muutavali(inv[i-1]+1, inv[i+1]-1, 1);
}
if (inv[i+1] < inv[i] && inv[i] < inv[i-1]) {
muutavali(1,inv[i+1]-1, 1);
}
}
for (int i = 1; i <= n; i++) {
if (inv[a[i]-1] < inv[a[i]+1] && inv[a[i]+1] < inv[a[i]]) { // 7 9 8
muutavali(inv[a[i]-1]+1, inv[a[i]+1]-1, -1);
}
if (inv[a[i]+1] < inv[a[i]] && inv[a[i]] < inv[a[i]-1]) { // 9 8 7
muutavali(1,inv[a[i]+1]-1, -1);
}
cntIso[a[i]] = summa(1, inv[a[i]+1]);
cntPieni[a[i]] = summa(1,inv[a[i]-1]);
}
for (int i = 1; i <= n; i++) {
if (inv[a[i]] < inv[a[i]-1] && inv[a[i]-1] < inv[a[i]+1]) {
ans2 += cntIso[a[i]-1] - cntPieni[a[i]+1];
}
if (inv[a[i]+1] < inv[a[i]] && inv[a[i]] < inv[a[i]-1]) {
ans2 += cntIso[a[i]-1];
}
}
cout << startval << " " << ans+ans2 << "\n";
}