$\textbf{algorithm, solve }(B_i, B_j) , i < j$
$\text{目标是把 } B_2, B_3\cdots, B_n 全部变成0$
$\textbf{i) } 2\leqslant i < j \leqslant n, \text{ 能够处理 } B[2\cdots n] \text{ 中的 } 2 \text{ 个数 } B_i, B_j$
$\quad \text{改变的是区间 } A[i, \cdots, j-1]$
$\quad \text{在一正一负的时候尽可能用这种操作}$
$\textbf{algorithm 差分}$
$A[…]=A_1,A_2,A_3, \cdots ,A_n$
$B_i = A_i - A_{i-1}, \ B_1 = A_1$
$B就是A的差分序列$
$\textbf{性质1}$
$$A_i = \sum_{j = 1}^{i} B_j$$
$\textbf{性质2}$
$A[l, r] \xleftarrow{+C}$
$给区间 A[l, r] 的元素都加上 C$
$\Leftrightarrow B_{r+1} - C, B_{l} + C$
$\textbf{ii) } i = 1, 2 \leqslant j \leqslant n$
$\quad \text{改变的是} A[\cdots] 的前缀$
$\textbf{iii) } 2 \leqslant i \leqslant n, j = n + 1$
$\quad \text{改变的是} A[\cdots] 的后缀$
$\textbf{iv) } i = 1, j = n + 1$
$\quad \text{改变了整个 }A 序列,无意义$
$\textbf{algorithm}$
$\textbf{i) do } \text{type i) , when } B_i \cdot B_j <0$
$\textbf{ii) } \text{other, do type ii) or iii)}$
$\quad \text{ example, remain }\textbf{r unpaired}$
$\quad \rightarrow [\text{ii)}, \text{iii)}] = (0, r), (1, r), \cdots, (r, 0)$
$\quad \rightarrow tot =r+1$
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef set<int>::iterator ssii;
#define Cmp(a, b) memcmp(a, b, sizeof(b))
#define Cpy(a, b) memcpy(a, b, sizeof(b))
#define Set(a, v) memset(a, v, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define _forS(i, l, r) for(set<int>::iterator i = (l); i != (r); i++)
#define _rep(i, l, r) for(int i = (l); i <= (r); i++)
#define _for(i, l, r) for(int i = (l); i < (r); i++)
#define _forDown(i, l, r) for(int i = (l); i >= r; i--)
#define debug_(ch, i) printf(#ch"[%d]: %d\n", i, ch[i])
#define debug_m(mp, p) printf(#mp"[%d]: %d\n", p->first, p->second)
#define debugS(str) cout << "dbg: " << str << endl;
#define debugArr(arr, x, y) _for(i, 0, x) { _for(j, 0, y) printf("%c", arr[i][j]); printf("\n"); }
#define _forPlus(i, l, d, r) for(int i = (l); i + d < (r); i++)
#define lowbit(i) (i & (-i))
#define MPR(a, b) make_pair(a, b)
const int maxn = 1e5 + 10;
int A[maxn], B[maxn];
int n;
void init() {
Set(B, 0);
}
int main() {
freopen("input.txt", "r", stdin);
scanf("%d", &n);
init();
_rep(i, 1, n) scanf("%d", &A[i]);
B[1] = 1;
_rep(i, 2, n) B[i] = A[i] - A[i - 1];
ll s1 = 0, s2 = 0;
_rep(i, 2, n) {
if(B[i] > 0) s1 += B[i];
else s2 -= B[i];
}
ll ans = min(s1, s2) + abs(s1 - s2);
cout << ans << endl;
ll ans2 = abs(s1 - s2) + 1;
cout << ans2 << endl;
}