#include <cstdio>
#include <vector>
using namespace std;

int main() {
	int N;
	scanf("%d", &N);
	vector<int> V(N);
	for (int &x : V) {
		scanf("%d", &x);
	}

	long long ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j <= N; j++) {
			bool isWeird = true;
			// if there are two consecutive equal it's not weird
			for (int k = i + 1; k < j; k++) {
				if (V[k] == V[k-1]) isWeird = false;
			}
			for (int k = i + 2; k < j; k++) {
				int inc1 = V[k-1] > V[k-2];
				int inc2 = V[k] > V[k-1];
				if (inc1 == inc2) isWeird = false;
			}
			if (isWeird) ans++;
		}
	}

	printf("%lld\n", ans);

	return 0;
}
