#include <bits/stdc++.h>
using namespace std;
long long grid[100005][4];
void pascal() {
  int i, j;
  for (i = 0; i < 100005; i++) grid[i][0] = 1;
  for (j = 0; j < 4; j++) grid[j][j] = 1;
  for (i = 1; i < 100005; i++)
    for (j = 1; j < min(i, 4); j++)
      grid[i][j] = grid[i - 1][j - 1] + grid[i - 1][j];
}
deque<int> v;
int x;
int main() {
  ios_base::sync_with_stdio(0);
  ;
  pascal();
  int n;
  cin >> n;
  int p;
  for (int i = 0; i < n; i++) {
    cin >> p;
    v.push_back(p);
  }
  long long res = 0;
  for (int i = 0; i < v.size();) {
    int j;
    for (j = i; j < v.size();) {
      if (v[i] != v[j]) break;
      j++;
    }
    int dif = j - i;
    if (dif == 1)
      res += 1;
    else {
      res += grid[dif][2];
      res += dif;
    }
    i = j;
  }
  cout << res << "\n";
  return 0;
}
