longlongsolve(longlong n){ longlong ans = n * (n - 1) / 2; longlong same = 1; for (longlong i = 1; i < n; i++) { if (arr[i - 1] == arr[i]) same++; else { ans -= same; same = 1; } }
same = 1; for (longlong i = n - 2; i >= 0; i--) { if (arr[i] == arr[i + 1]) same++; else { ans -= same; same = 1; } } for (longlong i = 1; i < n; i++) if (arr[i - 1] != arr[i]) ans++; return ans; }
intmain(){ longlong n; while (!(cin >> n).eof()) { for(longlong i = 0; i < n; i++) cin >> arr[i]; longlong ans = solve(n); cout << ans << endl; }