#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long N;
  cin >> N;
  vector<long long> V;
  long long Sum = N;
  for (long long i = 0; i < N; i++) {
    long long X;
    cin >> X;
    V.push_back(X);
  }
  long long L = 0;
  long long Cnt = 0;
  for (long long i = 0; i < N; i++) {
    if (V[i] == V[L])
      Cnt++;
    else {
      if (Cnt >= 2) Sum += Cnt * (Cnt - 1) / 2;
      while (V[L] != V[i]) {
        L++;
        Cnt--;
      }
      Cnt++;
    }
  }
  if (Cnt >= 2) Sum += Cnt * (Cnt - 1) / 2;
  cout << Sum << endl;
  return 0;
}
