#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18, MAXN = 2e5 + 1, MOD = 1e9 + 7;
long long binpow(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res *= a;
    a *= a;
    n >>= 1;
  }
  return res;
}
long long NOD(long long NOD1, long long NOD2) {
  while (NOD2) {
    NOD1 %= NOD2;
    swap(NOD1, NOD2);
  }
  return NOD1;
}
long long NOK(long long NOK1, long long NOK2) {
  return NOK1 * NOK2 / NOD(NOK1, NOK2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, ans = 0, last = 1000000001, cnt = 0;
  cin >> n;
  vector<long long> v;
  for (long long x, i = 0; i < n; i++) {
    cin >> x;
    if (last != x) {
      last = x;
      v.push_back(cnt);
      cnt = 1;
    } else
      cnt++;
  }
  v.push_back(cnt);
  for (long long x, i = 1; i < v.size(); i++) {
    x = v[i];
    while (x--) ans += v[i] - x;
  }
  cout << ans;
}
