#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 123;
const int inf = 1e9 + 7;
const long long INF = 1e18 + 7;
int n, a[N], mn[4 * N], mx[4 * N];
long long ans, cur;
void build(int v, int tl, int tr) {
  if (tl == tr)
    mn[v] = a[tl], mx[v] = a[tl];
  else {
    int mid = (tl + tr) / 2;
    build(2 * v, tl, mid);
    build(2 * v + 1, mid + 1, tr);
    mn[v] = min(mn[2 * v], mn[2 * v + 1]);
    mx[v] = max(mx[2 * v], mx[2 * v + 1]);
  }
}
int getMax(int v, int tl, int tr, int l, int r) {
  if (tl > r || tr < l) return -inf;
  if (tl >= l && tr <= r) return mx[v];
  int mid = (tl + tr) / 2;
  return max(getMax(2 * v, tl, mid, l, r),
             getMax(2 * v + 1, mid + 1, tr, l, r));
}
int getMin(int v, int tl, int tr, int l, int r) {
  if (tl > r || tr < l) return inf;
  if (tl >= l && tr <= r) return mn[v];
  int mid = (tl + tr) / 2;
  return min(getMin(2 * v, tl, mid, l, r),
             getMin(2 * v + 1, mid + 1, tr, l, r));
}
bool ok(int l, int r) { return getMin(1, 1, n, l, r) == getMax(1, 1, n, l, r); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  build(1, 1, n);
  for (int i = 1; i <= n; i++) {
    int l = i, r = n;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (ok(i, mid))
        cur = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    ans += cur - i + 1;
  }
  cout << ans;
}
