import std.algorithm, std.array, std.container, std.range; import std.string, std.conv; import std.math, std.bigint, std.bitmanip, std.random; import std.stdio, std.typecons; void main() { auto n = readln.chomp.to!int; auto ai = readln.split.map!(to!int).array; auto r = iota(n - 2).count!(i => isKadomatsu(ai[i..i + 3])); writeln(r); } bool isKadomatsu(int[] ai) { return (ai[0] != ai[1] && ai[0] != ai[2] && ai[1] != ai[2]) && ((ai[1] < ai[0] && ai[1] < ai[2]) || (ai[1] > ai[0] && ai[1] > ai[2])); }