import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } int[][] doIt(int[][] xss) { const n = cast(int)(xss.length); int get(int i) { return (0 <= i && i < n && !xss[i].empty) ? xss[i][$ - 1] : int.min; } auto yss = new int[][n]; foreach (i; 0 .. n) if (!xss[i].empty) { const l = get(i - 1); const r = get(i + 1); assert(l != r); yss[(l > r) ? (i - 1) : (i + 1)] ~= xss[i]; } foreach (i; 0 .. n) { yss[i].sort; } return yss; } int calc(int n, int s, int t) { assert(s % 2 == 0); assert(t % 2 != 0); s /= 2; t /= 2; int ret; if (n == 2) { ret = 0; } else if (n % 2 != 0) { const sum = s + t; ret = n / 2 + max((n / 2 - 1) - sum, sum - n / 2); } else { if (s == 0 && t == n / 2 - 1) { ret = n / 2; } else { const sum = s + t; ret = (n / 2 - 1) + max((n / 2 - 1) - sum, sum - (n / 2 - 1)); } } return ret; } void main() { /* debug { foreach (n; 2 .. 8 + 1) { auto perm = iota(n).array; do { auto xss = new int[][n]; foreach (i; 0 .. n) { xss[i] ~= perm[i]; } writeln(perm); writeln(" ", xss); int[][] bef; for (int step = -1; ; ++step) { auto yss = xss.doIt; writeln(" ", yss); if (bef == yss) { writeln(" ", step); break; } bef = xss; xss = yss; } } while (perm.nextPermutation); stdout.flush; } } */ debug { // x[0] < ... < x[s] > ... // x[1] < ... < x[t] > ... foreach (n; 2 .. 10 + 1) { for (int s = 0; s < n; s += 2) for (int t = 1; t < n; t += 2) { auto xss = new int[][n]; for (int i = 0; i < n; i += 2) xss[i] ~= (i <= s) ? i : -i; for (int i = 1; i < n; i += 2) xss[i] ~= (i <= t) ? i : -i; int[][] bef; for (int step = -1; ; ++step) { auto yss = xss.doIt; if (bef == yss) { const clc = calc(n, s, t); writeln(n, " ", s, " ", t, ": ", step, " ", clc); assert(step == clc); break; } bef = xss; xss = yss; } } } } try { for (; ; ) { const N = readInt; auto A = new int[N]; foreach (i; 0 .. N) { A[i] = readInt; } int ansMax, ansCnt; if (N == 2) { ansMax = 0; ansCnt = 1; } else { auto xss = new int[][N]; foreach (i; 0 .. N) { xss[i] ~= A[i]; } auto yss = xss.doIt; debug { writeln("yss = ", yss); } for (int i = 0, j; i < N; i = j) { for (j = i; j < N && yss[i].empty == yss[j].empty; ++j) {} if (!yss[i].empty) { const n = j - i; auto zs = new int[n]; foreach (k; 0 .. n) { zs[k] = yss[i + k][$ - 1]; } debug { writeln("zs = ", zs); } int[][2] sss; foreach (k; 0 .. n) { bool ok = true; ok = ok && (k - 2 < 0 || zs[k - 2] < zs[k]); ok = ok && (k + 2 >= n || zs[k] > zs[k + 2]); if (ok) { sss[k & 1] ~= k; } } assert(sss[0].length == 1); assert(sss[1].length == 1); const res = calc(n, sss[0][0], sss[1][0]); chmax(ansMax, 1 + res); ++ansCnt; } } } writeln(ansMax, " ", ansCnt); } } catch (EOFException e) { } }