//
#include "bits/stdc++.h"
using namespace std;
#define pr1(a) for(auto b : a) cout << b << " ";cout << endl;
#define pr2(a) for(auto b : a){for(auto c:b) cout << c << " ";cout << endl;}
#define prc(...) for(auto b:{ __VA_ARGS__ }) cout << b << " ";cout << endl;

const int NN=200000;
vector<vector<int>> g(NN+1,vector<int>());
vector<bool> visited(NN+1,false);
long long ans=0;

void dfs(int p){
    for(auto e:g[p]){
        if (visited[e]==false){
            ans++;
            visited[e]=true;
            dfs(e);
        }
    }
}

void solve()
{
    fill(g.begin(),g.end(),vector<int>());
    fill(visited.begin(),visited.end(),false);
    ans=0;
    int a,b,n,val;
    cin >> n ;
    vector<int> d(n);
    for(int &i:d) cin>>i;
    for(int i=0;i<n/2;i++){
        int v1=d[i], v2=d[n-i-1];
        if (v1!=v2){
            g[v1].push_back(v2);
            g[v2].push_back(v1);
        }
    }
    for(int i=0;i<=NN;i++){
        if (visited[i]==false)
            visited[i]=true;
            dfs(i);
    }
    
    cout<<ans<<endl;
}

int main()
{
    ios_base::sync_with_stdio(0);    cin.tie(0);    cout.tie(0);
#ifndef ONLINE_JUDGE
    stringstream in(R"(3
8
1 5 3 2 5 2 3 1
7
1 2 3 4 1 2 3
1
200000
)"); //ans 2 1 0
    std::cin.rdbuf(in.rdbuf());
#endif
    int tn = 1;
    //cin >> tn;
    while (tn--)
        solve();
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1e9+7;

ll max(ll a,ll b){
    if(a>b){
        return a;
    }
    return b;
}

ll min(ll a,ll b){
    if(a<b){
        return a;
    }
    return b;
}

void solve(){
    string s;
    cin >> s;
    ll n = s.size();
    map<char,ll> mp;
    ll ans=0;
    mp[s[n-1]]++;
    for(int i=n-2;i>=1;i--){
        if(s[i]==s[i-1]&&s[i-1]!=s[i+1]){
            ans+=(n-i-mp[s[i]]-1);
            mp.clear();
            mp[s[i]]=(n-i);
        }
        else{
            mp[s[i]]++;
        }
    }
    cout << ans;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
    solve();
    return 0;
}