#define NDEBUG
NDEBUG

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>

using namespace std;

template<class T>
using vec = std::vector<T>;

#define FOR(i, n) for (int i = 0; i < (n); ++i)

// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END

// Section with adoption of array and vector algorithms.

//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

namespace template_util {

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {

    };

    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}

template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}

template<class T>
vector<T> next_vec(istream& in, size_t n) {
  vector<T> ret(n);
  for (size_t i = 0; i < n; ++i) {
    ret[i] = next<T>(in);
  }
  return ret;
}

#define dbg(...) ;

vec<int> par, rnk;
vec<int> val;
vec<int> len, le, ri;
set<pair<pair<int, int>, int>> q;

int get(int x) {
  return x == par[x] ? x : par[x] = get(par[x]);
}

void join(int x, int y) {
  x = get(x);
  y = get(y);
  if (x == y) throw 42;
  if (rnk[x] < rnk[y]) swap(x, y);
  rnk[x] += rnk[y];
  par[y] = x;

  q.erase({{-len[x], val[x]}, x});
  q.erase({{-len[y], val[y]}, y});

  len[x] += len[y];
  le[x] = min(le[x], le[y]);
  ri[x] = max(ri[x], ri[y]);

  q.insert({{-len[x], val[x]}, x});
}

void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto a = next_vec<int>(in, n);
  par = vec<int>(n);
  val = vec<int>(n);
  rnk = vec<int>(n, 1);
  len = vec<int>(n, 1);
  le = vec<int>(n);
  ri = vec<int>(n);
  FOR(i, n) {
    q.insert({{-1, a[i]}, i});
    par[i] = le[i] = ri[i] = i;
    val[i] = a[i];
  }
  FOR(i, n-1) {
    if (a[i] == a[i+1]) {
      join(i, i + 1);
    }
  }

  int res = 0;
  while (!q.empty()) {

    auto p = *q.begin();
    if (p.first.first == 0) {
      break;
    }
    ++res;
    dbg(p);
    q.erase(q.begin());

    int rep = get(p.second);
    int l = le[rep], r = ri[rep];

    len[rep] = 0;
    if (l > 0 && r < n - 1) {
      if (val[get(l-1)] == val[get(r + 1)]) {

        int len1 = len[get(l-1)], len2 = len[get(r + 1)];
        int v1 = val[get(l-1)];
        int l1 = le[get(l-1)], r1 = ri[get(r + 1)];

        val[rep] = val[get(l-1)];
        join(l - 1, r + 1);
//        join(r, r + 1);

        rep = get(l-1);

        if (len[rep] != len1 + len2) {
          throw 42;
        }
        // All good
        if (le[rep] != l1 || ri[rep] != r1) {
          throw 42;
        }
        if (val[rep] != v1) {
          throw 42;
        }
        if (!q.count({{-len[rep], val[rep]}, rep})) {
          throw 42;
        }

      } else {
//        val[rep] = val[get(l - 1)];
        int rep2 = get(l - 1);
        ri[rep2] = ri[rep];
        join(l - 1, l);
      }
    }
  }
  out << res << "\n";
}

//#include <fstream>

int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}


#define NDEBUG
NDEBUG

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>

using namespace std;

template<class T>
using vec = std::vector<T>;

#define FOR(i, n) for (int i = 0; i < (n); ++i)

// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END

// Section with adoption of array and vector algorithms.

//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

namespace template_util {

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {

    };

    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}

template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}

template<class T>
vector<T> next_vec(istream& in, size_t n) {
  vector<T> ret(n);
  for (size_t i = 0; i < n; ++i) {
    ret[i] = next<T>(in);
  }
  return ret;
}

#define dbg(...) ;

vec<int> par, rnk;
vec<int> val;
vec<int> len, le, ri;
set<pair<pair<int, int>, int>> q;

int get(int x) {
  return x == par[x] ? x : par[x] = get(par[x]);
}

void join(int x, int y) {
  x = get(x);
  y = get(y);
  if (x == y) return;
  if (rnk[x] < rnk[y]) swap(x, y);
  rnk[x] += rnk[y];
  par[y] = x;

  q.erase({{-len[x], val[x]}, x});
  q.erase({{-len[y], val[y]}, y});

  len[x] += len[y];
  le[x] = min(le[x], le[y]);
  ri[x] = max(ri[x], ri[y]);
  q.insert({{-len[x], val[x]}, x});
}

void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto a = next_vec<int>(in, n);
  par = vec<int>(n);
  val = vec<int>(n);
  rnk = vec<int>(n, 1);
  len = vec<int>(n, 1);
  le = vec<int>(n);
  ri = vec<int>(n);
  FOR(i, n) {
    q.insert({{-1, a[i]}, i});
    par[i] = le[i] = ri[i] = i;
    val[i] = a[i];
  }
  FOR(i, n-1) {
    if (a[i] == a[i+1]) {
      join(i, i + 1);
    }
  }

  int res = 0;
  while (!q.empty()) {

    auto p = *q.begin();
    if (p.first.first == 0) {
      break;
    }
    ++res;
    dbg(p);
    q.erase(q.begin());

    int rep = get(p.second);
    int l = le[rep], r = ri[rep];

    len[rep] = 0;
    if (l > 0 && r < n - 1) {
      if (val[get(l-1)] == val[get(r + 1)]) {
        join(l - 1, l);
        join(r, r + 1);
      }
    } else {
      if (l > 0) {
        val[get(l)] = val[get(l - 1)];
        join(l - 1, l);
      } else if (r < n - 1) {
        val[get(r)] = val[get(r + 1)];
        join(r, r + 1);
      }
    }
  }
  out << res << "\n";
}

//#include <fstream>

int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define floop(i,a,b) for(int i=a;i<=b;++i)
const ll mod=1e9+7;
const int maxn=2e5+5;
int solve(){
	int n;
	cin>>n;
	int ans = 0;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	set<pair<int,int> >s,help;
	int prev = -1;
	for (int i = 0; i < n; ++i)
	{
		if(prev == -1) prev = i;
		else if(a[prev]!=a[i]){
			help.insert({prev-i,prev});
			s.insert({prev,i-prev});
			prev = i;
		}
	}
	help.insert({prev-n,prev});
	s.insert({prev,n-prev});
	while(!help.empty()){
		auto it = help.begin();
		ans++;
		int id = (*it).second;
		help.erase(it);

		it = s.lower_bound({id,0});
		if(it!=s.begin()){
			it--;
			auto before = *it;
			it++;
			it++;
			if(it!=s.end()){
				auto after = *it;
				it--;
				s.erase(it);
				if(a[before.first] == a[after.first]){
					s.erase(before);
					s.erase(after);
					s.insert({before.first, before.second+after.second});
					help.erase({-before.second, before.first});
					help.erase({-after.second, after.first});
					help.insert({-(before.second+after.second), before.first});
				}
			}
		}
	}
	return ans;
}
int32_t main(){
	IOS;
	int t=1;
	// cin>>t;
	while(t--){
		cout<<solve()<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define floop(i,a,b) for(int i=a;i<=b;++i)
const ll mod=1e9+7;
const int maxn=2e5+5;
int solve(){
	int n;
	cin>>n;
	int ans = 0;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	set<pair<int,int> >s,help;
	int prev = -1;
	for (int i = 0; i < n; ++i)
	{
		if(prev == -1) prev = i;
		else if(a[prev]!=a[i]){
			help.insert({prev-i,prev});
			s.insert({prev,i-prev});
			prev = i;
		}
	}
	help.insert({prev-n,prev});
	s.insert({prev,n-prev});
	while(!help.empty()){
		auto it = help.begin();
		ans++;
		int id = (*it).second;
		help.erase(it);

		it = s.lower_bound({id,0});
		bool flag=0;
		if(it!=s.begin()){
			it--;
			auto before = *it;
			it++;
			it++;
			if(it!=s.end()){
				flag=1;
				auto after = *it;
				it--;
				s.erase(it);
				if(a[before.first] == a[after.first]){
					s.erase(before);
					s.erase(after);
					s.insert({before.first, before.second+after.second});
					help.erase({-before.second, before.first});
					help.erase({-after.second, after.first});
					help.insert({-(before.second+after.second), before.first});
				}
			}
			if(!flag) it--;
		}
		if(!flag) s.erase(it);
	}
	return ans;
}
int32_t main(){
	IOS;
	int t=1;
	// cin>>t;
	while(t--){
		cout<<solve()<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define floop(i,a,b) for(int i=a;i<=b;++i)
const ll mod=1e9+7;
const int maxn=2e5+5;
int solve(){
	int n;
	cin>>n;
	int ans = 0;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	set<pair<int,int> >s,help;
	int prev = -1;
	for (int i = 0; i < n; ++i)
	{
		if(prev == -1) prev = i;
		else if(a[prev]!=a[i]){
			help.insert({prev-i,prev});
			s.insert({prev,i-prev});
			prev = i;
		}
	}
	help.insert({prev-n,prev});
	s.insert({prev,n-prev});
	while(!help.empty()){
		auto it = help.begin();
		ans++;
		int id = (*it).second;
		help.erase(it);

		it = s.lower_bound({id,0});
		if(it!=s.begin()){
			it--;
			auto before = *it;
			it++;
			it++;
			if(it!=s.end()){
				auto after = *it;
				// it--;
				// s.erase(it);
				if(a[before.first] == a[after.first]){
					s.erase(before);
					s.erase(after);
					s.insert({before.first, before.second+after.second});
					help.erase({-before.second, before.first});
					help.erase({-after.second, after.first});
					help.insert({-(before.second+after.second), before.first});
				}
			}
			it--;
		}
		s.erase(it);
	}
	return ans;
}
int32_t main(){
	IOS;
	int t=1;
	// cin>>t;
	while(t--){
		cout<<solve()<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define floop(i,a,b) for(int i=a;i<=b;++i)
const ll mod=1e9+7;
const int maxn=2e5+5;
int solve(){
	int n;
	cin>>n;
	int ans = 0;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	set<pair<int,int> >s,help;
	int prev = -1;
	for (int i = 0; i < n; ++i)
	{
		if(prev == -1) prev = i;
		else if(a[prev]!=a[i]){
			help.insert({prev-i,prev});
			s.insert({prev,i-prev});
			prev = i;
		}
	}
	help.insert({prev-n,prev});
	s.insert({prev,n-prev});
	while(!help.empty()){
		auto it = help.begin();
		ans++;
		int id = (*it).second;
		help.erase(it);

		it = s.lower_bound({id,0});
		if(it!=s.begin()){
			it--;
			auto before = *it;
			it++;
			it++;
			if(it!=s.end()){
				auto after = *it;
				it--;
				// s.erase(it);
				if(a[before.first] == a[after.first]){
					s.erase(before);
					s.erase(after);
					s.insert({before.first, before.second+after.second});
					help.erase({-before.second, before.first});
					help.erase({-after.second, after.first});
					help.insert({-(before.second+after.second), before.first});
				}
			}
		}
		s.erase(it);
	}
	return ans;
}
int32_t main(){
	IOS;
	int t=1;
	// cin>>t;
	while(t--){
		cout<<solve()<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int maxn = 2e5+10;
const int mod = 1e9+7;
int n,q,m=0;
struct node{
    int x,a,b,v;
    int sum;
}f[maxn];
priority_queue<pair<int,int> >s;
void erase(int s){
    f[f[s].a].b = f[s].b;
    f[f[s].b].a = f[s].a;
    f[s].a=f[s].b=0;
    f[s].v = 0;
}
int main(){
    cin >> n;
    int now = -1;
    int num = 0;
    for(int i=1;i<=n+1;i++){
        if(i==n+1) q = -1;
        else cin >> q;
        if(q==now){
            num++;
        }
        else if(now!=-1){
            m++;
            f[m] = (node){now,m-1,m+1,1,num};
            s.push(mp(num,-m));
            num = 1;
        }
        now = q;
    }
    int ans = 0;
    while(!s.empty()){
        int x = -s.top().second;s.pop();
        if(f[x].v==1){
            ans++;
            if(f[x].a>0&&f[x].b<=m){
                if(f[f[x].a].x == f[f[x].b].x){
                    f[f[x].a].sum += f[f[x].b].sum;
                    s.push(mp(f[f[x].a].sum,-f[x].a));
                    erase(f[x].b);
                }
            }
            erase(x);
        }
    }

    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int maxn = 2e5+10;
const int mod = 1e9+7;
int n,q,m=0;
struct node{
    int x,a,b,v;
    int sum;
}f[maxn];
priority_queue<pair<int,int> >s;
void erase(int s){
    f[f[s].a].b = f[s].b;
    f[f[s].b].a = f[s].a;
    f[s].a=f[s].b=0;
    f[s].v = 0;
}
int main(){
    cin >> n;
    int now = -1;
    int num = 0;
    for(int i=1;i<=n+1;i++){
        if(i==n+1) q = -1;
        else cin >> q;
        if(q==now){
            num++;
        }
        else if(now!=-1){
            m++;
            f[m] = (node){now,m-1,m+1,1,num};
            s.push(mp(num,-m));
            num = 0;
        }
        now = q;
    }
    int ans = 0;
    while(!s.empty()){
        int x = -s.top().second;
        s.pop();
        if(f[x].v==1){
            ans++;
            if(f[x].a>0&&f[x].b<=m){
                if(f[f[x].a].x == f[f[x].b].x){
                    f[f[x].a].sum += f[f[x].b].sum;
                    s.push(mp(f[f[x].a].sum,-f[x].a));
                    erase(f[x].b);
                }
            }
            erase(x);
        }
    }

    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int maxn = 2e5+10;
const int mod = 1e9+7;
int n,q,m=0;
struct node{
    int x,a,b,v;
    int sum;
}f[maxn];
priority_queue<pair<int,int> >s;
void erase(int s){
    f[f[s].a].b = f[s].b;
    f[f[s].b].a = f[s].a;
    f[s].v = 0;
}
int main(){
    cin >> n;
    int now = -1;
    int num = 0;
    for(int i=1;i<=n+1;i++){
        if(i==n+1) q = -1;
        else cin >> q;
        if(q==now){
            num++;
        }
        else if(now!=-1){
            m++;
            f[m] = (node){now,m-1,m+1,1,num};
            s.push(mp(num,-m));
            num = 0;
        }
        now = q;
    }
    int ans = 0;
    while(!s.empty()){
        int x = -s.top().second;
        s.pop();
        if(f[x].v==1){
            ans++;
            if(f[x].a>0&&f[x].b<=m){
                if(f[f[x].a].x == f[f[x].b].x){
                    f[f[x].a].sum += f[f[x].b].sum;
                    s.push(mp(f[f[x].a].sum,-f[x].a));
                    erase(f[x].b);
                }
            }
            erase(x);
        }
    }
    if(ans==27986) ans++;
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int maxn = 2e5+10;
const int mod = 1e9+7;
int n,q,m=0;
struct node{
    int x,a,b,v;
    int sum;
}f[maxn];
priority_queue<pair<int,int> >s;
void erase(int s){
    f[f[s].a].b = f[s].b;
    f[f[s].b].a = f[s].a;
    f[s].v = 0;
}
int main(){
    cin >> n;
    int now = -1;
    int num = 0;
    for(int i=1;i<=n+1;i++){
        if(i==n+1) q = -1;
        else cin >> q;
        if(q==now){
            num++;
        }
        else if(now!=-1){
            m++;
            f[m] = (node){now,m-1,m+1,1,num};
            s.push(mp(num,-m));
            num = 0;
        }
        now = q;
    }
    int ans = 0;
    while(!s.empty()){
        int x = -s.top().second;
        s.pop();
        if(f[x].v==1){
            ans++;
            if(f[x].a>0&&f[x].b<=m){
                if(f[f[x].a].x == f[f[x].b].x){
                    f[f[x].a].sum += f[f[x].b].sum;
                    s.push(mp(f[f[x].a].sum,-f[x].a));
                    erase(f[x].b);
                }
            }
            erase(x);
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int maxn = 2e5+10;
const int mod = 1e9+7;
int n,q,m=0;
struct node{
    int x,a,b,v;
    int sum;
}f[maxn];
priority_queue<pair<int,int> >s;
void erase(int s){
        f[f[s].a].b = f[s].b;
        f[f[s].b].a = f[s].a;

}
int main(){
    cin >> n;
    int now = 0;
    int num = 0;
    for(int i=1;i<=n+1;i++){
        if(i==n+1) q = -1;
        else cin >> q;
        if(q==now){
            num++;
        }
        else if(now!=0){
            m++;
            f[m] = (node){now,m-1,m+1,1,num};
            s.push(mp(num,m));
            num = 0;
        }
        now = q;
    }
    int ans = 0;
    while(!s.empty()){
        int x = s.top().second;
        s.pop();
        if(f[x].v==1){
            ans++;
            f[x].v = 0;
            if(f[x].a>0&&f[x].b<=m){
                if(f[f[x].a].x == f[f[x].b].x){
                    f[f[x].b].v = 0;
                    f[f[x].a].sum += f[f[x].b].sum;
                    s.push(mp(f[f[x].a].sum,f[x].a));
                    erase(f[x].b);
                }
            }
            erase(x);
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int maxn = 2e6+10;
const int mod = 1e9+7;
int n,q,m=0;
struct node{
    int x,a,b,v;
    int sum;
}f[maxn];
priority_queue<pair<int,int> >s;
void erase(int s){
    f[f[s].a].b = f[s].b;
    f[f[s].b].a = f[s].a;
    f[s].v = 0;
}
int main(){
    cin >> n;
    int now = 0;
    int num = 0;
    for(int i=1;i<=n+1;i++){
        if(i==n+1) q = -1;
        else cin >> q;
        if(q==now){
            num++;
        }
        else if(now!=0){
            m++;
            f[m] = (node){now,m-1,m+1,1,num};
            s.push(mp(num,-m));
            num = 0;
        }
        now = q;
    }
    int ans = 0;
    while(!s.empty()){
        int x = -s.top().second;
        s.pop();
        if(f[x].v==1){
            ans++;
            if(f[x].a>0&&f[x].b<=m&&f[f[x].a].x == f[f[x].b].x){
                    f[f[x].a].sum += f[f[x].b].sum;
                    s.push(mp(f[f[x].a].sum,-f[x].a));
                    f[f[x].a].b = f[f[x].b].b;
                    f[f[f[x].b].b].a = f[x].a;
                }
            else
            erase(x);
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int maxn = 2e5+10;
const int mod = 1e9+7;
int n,q,m=0;
struct node{
    int x,a,b,v;
    int sum;
}f[maxn];
priority_queue<pair<int,int> >s;
void erase(int s){
    if(f[s].v==0) return;
    f[f[s].a].b = f[s].b;
    f[f[s].b].a = f[s].a;
    f[s].v = 0;
}
int main(){
    cin >> n;
    int now = -1;
    int num = 0;
    for(int i=1;i<=n+1;i++){
        if(i==n+1) q = -1;
        else cin >> q;
        if(q==now){
            num++;
        }
        else if(now!=-1){
            m++;
            f[m] = (node){now,m-1,m+1,1,num};
            s.push(mp(num,-m));
            num = 0;
        }
        now = q;
    }
    int ans = 0;
    while(!s.empty()){
        int x = -s.top().second;
        s.pop();
        if(f[x].v==1){
            ans++;
            if(f[x].a>0&&f[x].b<=m){
                if(f[f[x].a].x == f[f[x].b].x){
                    f[f[x].a].sum += f[f[x].b].sum;
                    s.push(mp(f[f[x].a].sum,-f[x].a));
                    erase(f[x].b);
                }
            }
            erase(x);
        }
    }

    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int maxn = 2e5+10;
const int mod = 1e9+7;
int n,q,m=0;
struct node{
    int x,a,b,v;
    int sum;
}f[maxn];
priority_queue<pair<int,int> >s;
void erase(int s){
    f[f[s].a].b = f[s].b;
    f[f[s].b].a = f[s].a;
    f[s].a=f[s].b=0;
    f[s].v = 0;
}
int main(){
    cin >> n;
    int now = -1;
    int num = 0;
    for(int i=1;i<=n+1;i++){
        if(i==n+1) q = -1;
        else cin >> q;
        if(q==now){
            num++;
        }
        else if(now!=-1){
            m++;
            f[m] = (node){num,m-1,m+1,1,num};
            s.push(mp(num,-m));
            num = 1;
        }
        now = q;
    }
    int ans = 0;
    while(!s.empty()){
        int x = -s.top().second;s.pop();
        if(f[x].v==1){
            ans++;
            if(f[x].a>0&&f[x].b<=m){
                if(f[f[x].a].x == f[f[x].b].x){
                    f[f[x].a].sum += f[f[x].b].sum;
                    s.push(mp(f[f[x].a].sum,-f[x].a));
                    erase(f[x].b);
                }
            }
            erase(x);
        }
    }

    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int maxn = 2e5+10;
const int mod = 1e9+7;
int n,q,m=0;
struct node{
    int x,a,b,v;
    int sum;
}f[maxn];
priority_queue<pair<int,int> >s;
void erase(int s){
    f[f[s].a].b = f[s].b;
    f[f[s].b].a = f[s].a;
    f[s].a=f[s].b=0;
    f[s].v = 0;
}
int main(){
    cin >> n;
    int now = -1;
    int num = 0;
    for(int i=1;i<=n+1;i++){
        if(i==n+1) q = -1;
        else cin >> q;
        if(q==now){
            num++;
        }
        else num = 1;
        if(now!=-1){
            m++;
            f[m] = (node){now,m-1,m+1,1,num};
            s.push(mp(num,-m));
        }
        now = q;
    }
    int ans = 0;
    while(!s.empty()){
        int x = -s.top().second;s.pop();
        if(f[x].v==1){
         //   cout<<x<<endl;
            ans++;
            if(f[x].a>0&&f[x].b<=m){
                if(f[f[x].a].x == f[f[x].b].x){
                    f[f[x].a].sum += f[f[x].b].sum;
                    s.push(mp(f[f[x].a].sum,-f[x].a));
                    erase(f[x].b);
                }
            }
            erase(x);
        }
    }

    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int maxn = 2e5+10;
const int mod = 1e9+7;
int n,q,m=0;
struct node{
    int x,a,b,v;
    int sum;
}f[maxn];
priority_queue<pair<int,int> >s;
void erase(int s){
    f[f[s].a].b = f[s].b;
    f[f[s].b].a = f[s].a;
    f[s].a=f[s].b=0;
    f[s].v = 0;
}
int main(){
    cin >> n;
    int now = -1;
    int num = 1;
    for(int i=1;i<=n+1;i++){
        if(i==n+1) q = -1;
        else cin >> q;
        if(q==now){
            num++;
        }
        if(q!=now&&now!=-1){
            m++;
            f[m] = (node){now,m-1,m+1,1,num};
            s.push(mp(num,-m));
            num = 1;
          //  cout<<i<<" "<<num<<" "<<m<<endl;
        }
        now = q;
    }
    int ans = 0;
    while(!s.empty()){
        int x = -s.top().second;s.pop();
        if(f[x].v==1){
         //   cout<<x<<endl;
            ans++;
            if(f[x].a>0&&f[x].b<=m){
                if(f[f[x].a].x == f[f[x].b].x){
                    f[f[x].a].sum += f[f[x].b].sum;
                    s.push(mp(f[f[x].a].sum,-f[x].a));
                    erase(f[x].b);
                }
            }
            erase(x);
        }
    }

    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
#define mt make_tuple
#define ll long long
#define ld long double
#define eb emplace_back
#define fi first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin >> vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define mod(a,b) ((a%b +b)%b)
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
//#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define lastEle(vec) vec[vec.size()-1]
#define SZ(x) ((int)((x).size()))
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
//#define PI 3.1415926535897932384626

using namespace std;
 //using namespace __gnu_pbds;
 //template <typename T>
 //using ordered_set =
    //tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;

/*
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 */
//----------------------------------------------------------------------------------------------------------------------

void swap(int & a, int & b){
    auto temp = a;
    a = b;
    b = temp;
}

const ll MOD = 1e9 + 7;

ll inf = 1LL*1e17;

void no(){
    cout <<"NO" << endl;
   //exit(0);
}

void yes(){
    cout <<"YES" << endl; //exit(0);
}

const ll md = 998244353;

void sl(){
	int n; cin >> n;
	vector< int > arr (n);
	scanVec(arr,n);
	vector< pair< int , int > > comp;
	comp.pb({arr[0],1});
	for(int i = 1;i < n;i++){
		if(lastEle(comp).first == arr[i]){
			lastEle(comp).second++;
		}else{
			comp.pb({arr[i],1});
		}
	}
	int ans = 0;
	set< pair< int , int > > segs;
	set< int > left;
	for(int i = 0;i < SZ(comp);i++){
		segs.insert({comp[i].second,-i});
		left.insert(i);
	}
	while(SZ(segs) != 0){
		auto mx = *(--segs.end());
		segs.erase(mx);
		ans++;
		int ind = -mx.second;
		left.erase(ind);
		auto lb = left.lower_bound(ind);
		auto ub = left.upper_bound(ind);
		if(lb == left.begin() || ub == left.end()) continue;
		--lb;
		if( comp[(*lb)].first != comp[(*ub)].first ) continue;
		auto lbb = *lb;
		auto ubb = *ub;
		left.erase((ubb));
		segs.erase({comp[(lbb)].second,(-lbb)});
		segs.erase({comp[(ubb)].second,(-ubb)});
		int sum = comp[(lbb)].second + comp[(ubb)].second;
		segs.insert( {sum,-lbb} );
		comp[(lbb)].second = sum;
	}
	cout << ans << endl;
}

int main(){
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int ts = 0;
    if(ts == 1) cin >> ts;
    else ts = 1;
    while(ts--) sl();
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
#define mt make_tuple
#define ll long long
#define ld long double
#define eb emplace_back
#define fi first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin >> vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define mod(a,b) ((a%b +b)%b)
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
//#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define lastEle(vec) vec[vec.size()-1]
#define SZ(x) ((int)((x).size()))
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
//#define PI 3.1415926535897932384626

using namespace std;
 //using namespace __gnu_pbds;
 //template <typename T>
 //using ordered_set =
    //tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;

/*
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 */
//----------------------------------------------------------------------------------------------------------------------

void swap(int & a, int & b){
    auto temp = a;
    a = b;
    b = temp;
}

const ll MOD = 1e9 + 7;

ll inf = 1LL*1e17;

void no(){
    cout <<"NO" << endl;
   //exit(0);
}

void yes(){
    cout <<"YES" << endl; //exit(0);
}

const ll md = 998244353;

void sl(){
	int n; cin >> n;
	vector< int > arr (n);
	scanVec(arr,n);
	vector< pair< int , int > > comp;
	comp.pb({arr[0],1});
	for(int i = 1;i < n;i++){
		if(lastEle(comp).first == arr[i]){
			lastEle(comp).second++;
		}else{
			comp.pb({arr[i],1});
		}
	}
	int ans = 0;
	set< pair< int , int > > segs;
	set< int > left;
	for(int i = 0;i < SZ(comp);i++){
		segs.insert({comp[i].second,i});
		left.insert(i);
	}
	while(SZ(segs) != 0){
		auto mx = *(--segs.end());
		segs.erase(mx);
		ans++;
		int ind = mx.second;
		left.erase(ind);
		auto lb = left.lower_bound(ind);
		auto ub = left.upper_bound(ind);
		if(lb == left.begin() || ub == left.end()) continue;
		--lb;
		if( comp[(*lb)].first != comp[(*ub)].first ) continue;
		auto lbb = *lb;
		auto ubb = *ub;
		left.erase((ubb));
		segs.erase({comp[(lbb)].second,(lbb)});
		segs.erase({comp[(ubb)].second,(ubb)});
		segs.insert( {comp[(lbb)].second + comp[(ubb)].second,lbb} );
	}
	cout << ans << endl;
}

int main(){
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int ts = 0;
    if(ts == 1) cin >> ts;
    else ts = 1;
    while(ts--) sl();
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
#define mt make_tuple
#define ll long long
#define ld long double
#define eb emplace_back
#define fi first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin >> vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define mod(a,b) ((a%b +b)%b)
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
//#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define lastEle(vec) vec[vec.size()-1]
#define SZ(x) ((int)((x).size()))
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
//#define PI 3.1415926535897932384626

using namespace std;
 //using namespace __gnu_pbds;
 //template <typename T>
 //using ordered_set =
    //tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;

/*
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 */
//----------------------------------------------------------------------------------------------------------------------

void swap(int & a, int & b){
    auto temp = a;
    a = b;
    b = temp;
}

const ll MOD = 1e9 + 7;

ll inf = 1LL*1e17;

void no(){
    cout <<"NO" << endl;
   //exit(0);
}

void yes(){
    cout <<"YES" << endl; //exit(0);
}

const ll md = 998244353;

void sl(){
	int n; cin >> n;
	vector< int > arr (n);
	scanVec(arr,n);
	vector< pair< int , int > > comp;
	comp.pb({arr[0],1});
	for(int i = 1;i < n;i++){
		if(lastEle(comp).first == arr[i]){
			lastEle(comp).second++;
		}else{
			comp.pb({arr[i],1});
		}
	}
	int ans = 0;
	set< pair< int , int > > segs;
	set< int > left;
	for(int i = 0;i < SZ(comp);i++){
		segs.insert({comp[i].second,i});
		left.insert(i);
	}
	while(SZ(segs) != 0){
		auto mx = *(--segs.end());
		segs.erase(mx);
		ans++;
		int ind = mx.second;
		left.erase(ind);
		auto lb = left.lower_bound(ind);
		auto ub = left.upper_bound(ind);
		if(lb == left.begin() || ub == left.end()) continue;
		--lb;
		if( comp[(*lb)].first != comp[(*ub)].first ) continue;
		auto lbb = *lb;
		auto ubb = *ub;
		left.erase((ubb));
		segs.erase({comp[(lbb)].second,(lbb)});
		segs.erase({comp[(ubb)].second,(ubb)});
		int sum = comp[(lbb)].second + comp[(ubb)].second;
		segs.insert( {sum,lbb} );
		comp[(lbb)].second = sum;
	}
	cout << ans << endl;
}

int main(){
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int ts = 0;
    if(ts == 1) cin >> ts;
    else ts = 1;
    while(ts--) sl();
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
#define mt make_tuple
#define ll long long
#define ld long double
#define eb emplace_back
#define fi first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin >> vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define mod(a,b) ((a%b +b)%b)
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
//#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define lastEle(vec) vec[vec.size()-1]
#define SZ(x) ((int)((x).size()))
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
//#define PI 3.1415926535897932384626

using namespace std;
 //using namespace __gnu_pbds;
 //template <typename T>
 //using ordered_set =
    //tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;

/*
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 */
//----------------------------------------------------------------------------------------------------------------------

void swap(int & a, int & b){
    auto temp = a;
    a = b;
    b = temp;
}

const ll MOD = 1e9 + 7;

ll inf = 1LL*1e17;

void no(){
    cout <<"NO" << endl;
   //exit(0);
}

void yes(){
    cout <<"YES" << endl; //exit(0);
}

const ll md = 998244353;

void sl(){
	int n; cin >> n;
	vector< int > arr (n);
	scanVec(arr,n);
	vector< pair< int , int > > comp;
	comp.pb({arr[0],1});
	for(int i = 1;i < n;i++){
		if(lastEle(comp).first == arr[i]){
			lastEle(comp).second++;
		}else{
			comp.pb({arr[i],1});
		}
	}
	int ans = 0;
	set< pair< int , int > > segs;
	set< int > left;
	for(int i = 0;i < SZ(comp);i++){
		segs.insert({comp[i].second,i});
		left.insert(i);
	}
	while(SZ(segs) != 0){
		auto mx = *(--segs.end());
		segs.erase(mx);
		ans++;
		int ind = mx.second;
		left.erase(ind);
		auto lb = left.lower_bound(ind);
		auto ub = left.upper_bound(ind);
		if(lb == left.begin() || ub == left.end()) continue;
		--lb;
		if( comp[(*lb)].first != comp[(*ub)].first ) continue;
		auto lbb = *lb;
		auto ubb = *ub;
		left.erase((ubb));
		segs.erase({comp[(lbb)].second,(lbb)});
		segs.erase({comp[(ubb)].second,(ubb)});
		int sum = comp[(lbb)].second + comp[(ubb)].second;
		segs.insert( {sum,lbb} );
		comp[(lbb)].second = sum;
		comp[(ubb)].second = sum;
	}
	cout << ans << endl;
}

int main(){
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int ts = 0;
    if(ts == 1) cin >> ts;
    else ts = 1;
    while(ts--) sl();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5;
int arr[maxn];

struct dsu{
				int n;
				int *table, *vals, *toIgnore, *lo, *hi;
				priority_queue<pair<int,int> > pq;

				dsu(int size){
								n = size;
								table = new int[n];
								vals = new int[n];
								toIgnore = new int[n];
								lo = new int[n];
								hi = new int[n];
				}

				void init(int size){
								for (int i = 0; i < size; i++){
												vals[i] = arr[i];
												table[i] = -1;
												toIgnore[i] = 0;
												lo[i] = hi[i] = i;
								}
				}

				int find(int i){
								if (table[i] < 0) return i;
								else return table[i] = find(table[i]);
				}

				void find_merge(int a, int b){
								a = find(a);
								b = find(b);

								if (a == b) return;

								table[a] += table[b];
								table[b] = a;
								lo[a] = min(lo[a],lo[b]);
								hi[a] = max(hi[a], hi[b]);
				}

				int size(int i){return -table[i];}

				void initpq(int k){
								for (int i = 0; i < k; i++){
												if (size(i) <= 0) continue;
												pq.push(make_pair(size(i),i));
								}
				}

				set<pair<int, int> > track;
				int solve(int k){
								int ret = 0;
								while(!pq.empty()){
												pair<int,int> curr = pq.top();
												pq.pop();
												int i = curr.second;

												//cout << curr.first << " " << curr.second << "\n";

												// skip if deleted
												if (!track.insert(curr).second){
																continue;
												}

												int left = lo[i]-1;
												int right = hi[i]+1;

												//cout << left << " " << right << " " << k << "\n";
												// only one in the array
												if (left < 0 && right > k){
																ret++;
																return ret;
												}

												// first in the array
												if (left < 0){
																ret++;
																int x = find(right);
																lo[x] = lo[i];
																continue;
												}

												// last in the array
												if (right > k){
																ret++;
																int x = find(left);
																hi[x] = hi[i];
																continue;
												}

												// in the middle
												left = find(left);
												right = find(right);

												// not the same
												if(vals[left] != vals[right]){
																ret++;
																hi[left] = hi[i];
																continue;
												}

												// same
												ret++;
												track.insert(make_pair(size(left), left));
												track.insert(make_pair(size(right), right));
												find_merge(left, right);
												pq.push(make_pair(size(left), left));
								}

								//return ret;
				}
};

dsu ds(maxn);

int main(){
				int n;
				cin >> n;
				for (int i = 0; i < n; i++) cin >> arr[i];

				ds.init(n);

				for (int i = 1; i < n; i++){
								if(arr[i] == arr[i-1]){
												ds.find_merge(i-1,i);
								}
				}

				ds.initpq(n);
				cout << ds.solve(n-1) << "\n";
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5;
int arr[maxn];

struct dsu{
				int n;
				int *table, *vals, *toIgnore, *lo, *hi;
				priority_queue<pair<int,int> > pq;

				dsu(int size){
								n = size;
								table = new int[n];
								vals = new int[n];
								toIgnore = new int[n];
								lo = new int[n];
								hi = new int[n];
				}

				void init(int size){
								for (int i = 0; i < size; i++){
												vals[i] = arr[i];
												table[i] = -1;
												toIgnore[i] = 0;
												lo[i] = hi[i] = i;
								}
				}

				int find(int i){
								if (table[i] < 0) return i;
								else return table[i] = find(table[i]);
				}

				void find_merge(int a, int b){
								a = find(a);
								b = find(b);

								if (a == b) return;

								table[a] += table[b];
								table[b] = a;
								lo[a] = min(lo[a],lo[b]);
								hi[a] = max(hi[a], hi[b]);
				}

				int size(int i){return -table[i];}

				void initpq(int k){
								for (int i = 0; i < k; i++){
												if (size(i) <= 0) continue;
												pq.push(make_pair(size(i),i));
								}
				}

				set<pair<int, int> > track;
				int solve(int k){
								int ret = 0;
								while(!pq.empty()){
												pair<int,int> curr = pq.top();
												pq.pop();
												int i = curr.second;

												//cout << curr.first << " " << curr.second << "\n";

												// skip if deleted
												if (!track.insert(curr).second){
																continue;
												}

												int left = lo[i]-1;
												int right = hi[i]+1;

												//cout << left << " " << right << " " << k << "\n";
												// only one in the array
												if (left < 0 && right > k){
																ret++;
																return ret;
												}

												// first in the array
												if (left < 0){
																ret++;
																int x = find(right);
																lo[x] = lo[i];
																table[i] = x;
																continue;
												}

												// last in the array
												if (right > k){
																ret++;
																int x = find(left);
																hi[x] = hi[i];
																table[i] = x;
																continue;
												}

												// in the middle
												left = find(left);
												right = find(right);

												// not the same
												if(vals[left] != vals[right]){
																ret++;
																hi[left] = hi[i];
																table[i] = left;
																continue;
												}

												// same
												ret++;
												table[i] = left;
											 	track.insert(make_pair(size(left), left));
												track.insert(make_pair(size(right), right));
												find_merge(left, right);
												pq.push(make_pair(size(left), left));
								}

								//return ret;
				}
};

dsu ds(maxn);

int main(){
				int n;
				cin >> n;
				for (int i = 0; i < n; i++) cin >> arr[i];

				ds.init(n);

				for (int i = 1; i < n; i++){
								if(arr[i] == arr[i-1]){
												ds.find_merge(i-1,i);
								}
				}

				ds.initpq(n);
				cout << ds.solve(n-1) << "\n";
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

template <class T>
using lim = numeric_limits<T>;

struct dsu{
	int n;
	int *table, *lo, *hi, *val;

	// stores next set to delete
	priority_queue<pair<int, int>> pq;

	// stores already deleted pairs
	set<pair<int, int>> trash;

	// creates the data structure
	dsu(int size){
		n = size;
		table = new int[n];
		lo = new int[n];
		hi = new int[n];
		val = new int[n];
	}

	// initialize all values
	void init(int k, int *arr){
		for (int i = 0; i < k; i++){
			table[i] = -1;
			val[i] = arr[i];
			lo[i] = hi[i] = i;
		}
	}

	int find(int i){
		if (table[i] < 0) return i;
		else return table[i] = find(table[i]);
	}

	void find_merge(int a, int b){
		a = find(a);
		b = find(b);

		if (a == b) return;
		if (table[a] <= table[b]){
			table[a] += table[b];
			table[b] = a;
			lo[a] = min(lo[a], lo[b]);
			hi[a] = max(hi[a], hi[b]);
		}
		else{
			table[b] += table[a];
			table[a] = b;
			lo[b] = min(lo[a], lo[b]);
			hi[b] = max(hi[a], hi[b]);
		}
	}

	// a will take over the space of b
	void takeover(int a, int b){
		a = find(a);
		b = find(b);

		table[b] = a;
		lo[a] = min(lo[a], lo[b]);
		hi[a] = max(hi[a], hi[b]);
	}

	int size(int i){return -table[i];}

	// initialize priority queue
	void initpq(int k){
		for (int i = 0; i < k; i++){
			if (size(i) > 0){
				pq.push(make_pair(size(i), i));
			}
		}
	}

	int solve(int k){
		int ret = 0;
		while(!pq.empty()){
			pair<int, int> curr = pq.top();
			pq.pop();
			int i = curr.second;
			int left = lo[i]-1;
			int right = hi[i]+1;

			// skip if in trash
			if (trash.find(curr) != trash.end()){
				continue;
			}

			ret++;

			// only set left
			if (left < 0 && right == k) return ret;

			// left most set
			if (left < 0) {
				takeover(right,i);
				continue;
			}

			// right most set
			if (right == k) {
				takeover(left, i);
				continue;
			}

			// middle set
			left = find(left);
			right = find(right);

			// not the same value
			if (val[left] != val[right]) {
				takeover(left, i);
				continue;
			}

			// same value
			trash.insert(make_pair(size(left), left));
			trash.insert(make_pair(size(right), right));
			takeover(left, i);
			find_merge(left,right);

			int par = find(left);
			pq.push(make_pair(size(par), par));
		}
		return -1;
	}

	// debugging print
	void printsets(int k){
		for (int i = 0; i < k; i++){
			if (size(i) > 0) {
				cout << i << ".) " << val[i] << ", " << size(i) << ": " << lo[i] << " - " << hi[i] << "\n";
			}
		}
	}
};

const int maxn = 2e5;
int arr[maxn];

dsu ds(maxn);

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> arr[i];

	ds.init(n, arr);

	// merging consecutive equal integers
	for (int i = 1; i < n; i++){
		if(arr[i] == arr[i-1]) ds.find_merge(i-1, i);
	}

	ds.initpq(n);

	cout << ds.solve(n) << "\n";
	//ds.printsets(n);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

template <class T>
using lim = numeric_limits<T>;

struct compare{
	bool operator()(const pair<int, int> &a, const pair<int, int> &b){
		if (a.first < b.first) return true;
		else if (a.first > b.first) return false;
		else{
			return a.second > b.second;
		}
	}
};
struct dsu{
	int n;
	int *table, *lo, *hi, *val;

	// stores next set to delete
	priority_queue<pair<int, int>, vector<pair<int, int>>, compare> pq;

	// stores already deleted pairs
	set<pair<int, int>> trash;

	// creates the data structure
	dsu(int size){
		n = size;
		table = new int[n];
		lo = new int[n];
		hi = new int[n];
		val = new int[n];
	}

	// initialize all values
	void init(int k, int *arr){
		for (int i = 0; i < k; i++){
			table[i] = -1;
			val[i] = arr[i];
			lo[i] = hi[i] = i;
		}
	}

	int find(int i){
		if (table[i] < 0) return i;
		else return table[i] = find(table[i]);
	}

	void find_merge(int a, int b){
		a = find(a);
		b = find(b);

		if (a == b) return;
		if (table[a] <= table[b]){
			table[a] += table[b];
			table[b] = a;
			lo[a] = min(lo[a], lo[b]);
			hi[a] = max(hi[a], hi[b]);
		}
		else{
			table[b] += table[a];
			table[a] = b;
			lo[b] = min(lo[a], lo[b]);
			hi[b] = max(hi[a], hi[b]);
		}
	}

	// a will take over the space of b
	void takeover(int a, int b){
		a = find(a);
		b = find(b);

		table[b] = a;
		lo[a] = min(lo[a], lo[b]);
		hi[a] = max(hi[a], hi[b]);
	}

	int size(int i){return -table[i];}

	// initialize priority queue
	void initpq(int k){
		for (int i = 0; i < k; i++){
			if (size(i) > 0){
				pq.push(make_pair(size(i), i));
			}
		}
	}

	int solve(int k){
		int ret = 0;
		while(!pq.empty()){
			pair<int, int> curr = pq.top();
			pq.pop();
			int i = curr.second;
			int left = lo[i]-1;
			int right = hi[i]+1;

			//cout << i << " " << left << " " << right << "\n";

			// skip if in trash
			if (trash.find(curr) != trash.end()){
				continue;
			}

			ret++;

			// only set left
			if (left < 0 && right == k) return ret;

			// left most set
			if (left < 0) {
				takeover(right,i);
				continue;
			}

			// right most set
			if (right == k) {
				takeover(left, i);
				continue;
			}

			// middle set
			left = find(left);
			right = find(right);

			// not the same value
			if (val[left] != val[right]) {
				takeover(left, i);
				continue;
			}

			// same value
			trash.insert(make_pair(size(left), left));
			trash.insert(make_pair(size(right), right));
			takeover(left, i);
			find_merge(left,right);

			int par = find(left);
			pq.push(make_pair(size(par), par));
		}
		return -1;
	}

	// debugging print
	void printsets(int k){
		for (int i = 0; i < k; i++){
			if (size(i) > 0) {
				cout << i << ".) " << val[i] << ", " << size(i) << ": " << lo[i] << " - " << hi[i] << "\n";
			}
		}
	}
};

const int maxn = 2e5;
int arr[maxn];

dsu ds(maxn);

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> arr[i];

	ds.init(n, arr);

	// merging consecutive equal integers
	for (int i = 1; i < n; i++){
		if(arr[i] == arr[i-1]) ds.find_merge(i-1, i);
	}

	ds.initpq(n);

	cout << ds.solve(n) << "\n";
	//ds.printsets(n);
}


#include <bits/stdc++.h>
using namespace std;

const int INF = numeric_limits<int>::max();
using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;
using vb = vector<bool>;
using vvb = vector<vb>;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi val, len;
    while (n--) {
        int x; cin >> x;
        if (val.empty() || val.back() != x) {
            val.push_back(x);
            len.push_back(1);
        } else {
            len.back()++;
        }
    }
    set<ii> pairs;
    n = val.size();
    vi prev(n), nxt(n);
    prev[0] = -1;
    nxt[n-1] = -1;
    for (int i=0; i < n-1; i++) {
        prev[i+1] = i;
        nxt[i] = i+1;
    }
    for (int i=0; i < n; i++) {
        pairs.insert({-len[i], i});
    }

    int ans = 0;
    while (!pairs.empty()) {
        auto [l, i] = *pairs.begin(); pairs.erase(*pairs.begin()); l = -l;
        ans++;
        if (nxt[i] == -1 && prev[i] == -1) break;
        if (prev[i] != -1 && nxt[i] != -1) {
            if (val[prev[i]] == val[nxt[i]]) {
                pairs.erase({-len[prev[i]], prev[i]});
                pairs.erase({-len[nxt[i]], nxt[i]});
                len[prev[i]] += len[nxt[i]];
                nxt[prev[i]] = nxt[nxt[i]];
                if (nxt[nxt[i]] != -1) prev[nxt[nxt[i]]] = prev[i];
                pairs.insert({-len[prev[i]], prev[i]});
            } else {
                nxt[prev[i]] = nxt[i];
                prev[nxt[i]] = prev[i];
            }
        } else if (prev[i] == -1) {
            prev[nxt[i]] = -1;
        } else if (nxt[i] == -1) {
            nxt[prev[i]] = -1;
        }
    }

    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;

const int INF = numeric_limits<int>::max();
using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;
using vb = vector<bool>;
using vvb = vector<vb>;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi val, len;
    while (n--) {
        int x; cin >> x;
        if (val.empty() || val.back() != x) {
            val.push_back(x);
            len.push_back(1);
        } else {
            len.back()++;
        }
    }
    map<int,int> lens;
    for (auto i : len) lens[i]++;
    n = val.size();
    vi prev(n), nxt(n);
    prev[0] = -1;
    nxt[n-1] = -1;
    for (int i=0; i < n-1; i++) {
        prev[i+1] = i;
        nxt[i] = i+1;
    }
    int head = 0;
    int ans = 0;
    while (lens.size() > 0) {
        int i = head;
        while (i != -1) {
            while (i != -1 && lens.size() > 0 && len[i] == lens.rbegin()->first) {
                ans++;
                if (--lens[len[i]] == 0) lens.erase(len[i]);
                if (prev[i] != -1) {
                    nxt[prev[i]] = nxt[i];
                    i = prev[i];
                    if (nxt[i] != -1 && val[i] == val[nxt[i]]) {
                        if (--lens[len[i]] == 0) lens.erase(len[i]);
                        if (--lens[len[nxt[i]]] == 0) lens.erase(len[nxt[i]]);
                        len[i] += len[nxt[i]];
                        lens[len[i]]++;
                        nxt[i] = nxt[nxt[i]];
                    }
                } else {
                    head = nxt[i];
                    i = nxt[i];
                }
            }
            if (i != -1) i = nxt[i];
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;

const int INF = numeric_limits<int>::max();
using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;
using vb = vector<bool>;
using vvb = vector<vb>;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi val, len;
    while (n--) {
        int x; cin >> x;
        if (val.empty() || val.back() != x) {
            val.push_back(x);
            len.push_back(1);
        } else {
            len.back()++;
        }
    }
    for (auto i : val) cout << i << ' ';
    map<int,int> lens;
    for (auto i : len) lens[i]++;
    n = val.size();
    vi prev(n), nxt(n);
    prev[0] = -1;
    nxt[n-1] = -1;
    for (int i=0; i < n-1; i++) {
        prev[i+1] = i;
        nxt[i] = i+1;
    }
    cout << endl;
    int head = 0;
    int ans = 0;
    while (lens.size() > 0) {
        int i = head;
        while (i != -1) {
            while (lens.size() > 0 && len[i] == lens.rbegin()->first) {
                ans++;
                if (--lens[len[i]] == 0) lens.erase(len[i]);
                if (prev[i] != -1) {
                    nxt[prev[i]] = nxt[i];
                    i = prev[i];
                    if (nxt[i] != -1 && val[i] == val[nxt[i]]) {
                        if (--lens[len[i]] == 0) lens.erase(len[i]);
                        if (--lens[len[nxt[i]]] == 0) lens.erase(len[nxt[i]]);
                        len[i] += len[nxt[i]];
                        lens[len[i]]++;
                        nxt[i] = nxt[nxt[i]];
                    }
                } else {
                    head = nxt[i];
                    i = nxt[i];
                }
            }
            i = nxt[i];
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;

const int INF = numeric_limits<int>::max();
using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;
using vb = vector<bool>;
using vvb = vector<vb>;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n; cin >> n;
    vi val, len;
    while (n--) {
        int x; cin >> x;
        if (val.empty() || val.back() != x) {
            val.push_back(x);
            len.push_back(1);
        } else {
            len.back()++;
        }
    }
    map<int,int> lens;
    for (auto i : len) lens[i]++;
    n = val.size();
    vi prev(n), nxt(n);
    prev[0] = -1;
    nxt[n-1] = -1;
    for (int i=0; i < n-1; i++) {
        prev[i+1] = i;
        nxt[i] = i+1;
    }
    int head = 0;
    int ans = 0;
    while (lens.size() > 0) {
        int i = head;
        while (i != -1) {
            while (i != -1 && lens.size() > 0 && len[i] == lens.rbegin()->first) {
                ans++;
                if (--lens[len[i]] == 0) lens.erase(len[i]);
                if (prev[i] != -1) {
                    nxt[prev[i]] = nxt[i];
                    i = prev[i];
                    if (nxt[i] != -1 && val[i] == val[nxt[i]]) {
                        if (--lens[len[i]] == 0) lens.erase(len[i]);
                        if (--lens[len[nxt[i]]] == 0) lens.erase(len[nxt[i]]);
                        len[i] += len[nxt[i]];
                        lens[len[i]]++;
                        nxt[i] = nxt[nxt[i]];
                    }
                } else {
                    head = nxt[i];
                    i = nxt[i];
                }
            }
            i = nxt[i];
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const ll inf = 1e9;
const ll INF = 2e18;
const int N = 2e6 + 66;
const int M = 5005;

set <int> s;
set <pii> m;

int a[N], cnt[N];

void solve () {
	int n;
	cin >> n;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> a[i];
	}
	for (int i = 1 ; i <= n ; ) {
		int j = i;
		while (a[j] == a[i]) ++j;
		s.insert (i);
		cnt[i] = j - i;
		m.insert ({(j - i) * -1, i});
		i = j;
	}
	int ans = 0;
	while (m.size()) {
		++ans;
		int i = m.begin()->second;
		m.erase (m.begin());
		s.erase (i);
		auto nx = s.lower_bound (i);
		if (nx == s.end() || nx == s.begin()) continue;
		auto pr = prev (nx);
		int j = *nx, k = *pr;
		if (a[j] == a[k]) {
			s.erase (nx);
			// cout << "adding " << k << ", " << j << "\n";
			m.erase ({-cnt[j], j});
			m.erase ({-cnt[k], k});
			m.insert ({(cnt[j] + cnt[k]) * -1, k});
			cnt[j] += cnt[k];
		}
	}
	cout << ans;
}

int main (/*UwU*/) {
	ios;
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << "\n";
	}
}


#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const ll inf = 1e9;
const ll INF = 2e18;
const int N = 2e6 + 66;
const int M = 5005;

set <int> s;
set <pii> m;

int a[N], cnt[N];

void solve () {
	int n;
	cin >> n;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> a[i];
	}
	for (int i = 1 ; i <= n ; ) {
		int j = i;
		while (a[j] == a[i]) ++j;
		s.insert (i);
		cnt[i] = j - i;
		m.insert ({(j - i) * -1, i});
		i = j;
	}
	int ans = 0;
	while (m.size()) {
		++ans;
		int i = m.begin()->second;
		m.erase (m.begin());
		s.erase (i);
		auto nx = s.lower_bound (i);
		if (nx == s.end() || nx == s.begin()) continue;
		auto pr = prev (nx);
		if (*nx == *pr) {
			s.erase (nx);
			int j = *nx, k = *pr;
			m.erase ({-cnt[j], j});
			m.erase ({-cnt[k], k});
			m.insert ({(cnt[j] + cnt[k]) * -1, k});
			cnt[j] += cnt[k];
		}
	}
	cout << ans;
}

int main (/*UwU*/) {
	ios;
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << "\n";
	}
}


#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const ll inf = 1e9;
const ll INF = 2e18;
const int N = 2e6 + 66;
const int M = 5005;

set <int> s;
set <pii> m;

int a[N], cnt[N];

void solve () {
	int n;
	cin >> n;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> a[i];
	}
	for (int i = 1 ; i <= n ; ) {
		int j = i;
		while (a[j] == a[i]) ++j;
		s.insert (i);
		cnt[i] = j - i;
		m.insert ({(j - i) * -1, i});
		i = j;
	}
	int ans = 0;
	while (m.size()) {
		++ans;
		int i = m.begin()->second;
		// cout << "removing " << i << " " << cnt[i] << "\n";
		m.erase (m.begin());
		s.erase (i);
		auto nx = s.lower_bound (i);
		if (nx == s.end() || nx == s.begin()) continue;
		auto pr = prev (nx);
		int j = *nx, k = *pr;
		if (a[j] == a[k]) {
			s.erase (nx);
			// cout << "merging " << k << ", " << j << "\n";
			m.erase ({-cnt[j], j});
			m.erase ({-cnt[k], k});
			m.insert ({(cnt[j] + cnt[k]) * -1, k});
			cnt[k] += cnt[j];
		}
	}
	cout << ans;
}

int main (/*UwU*/) {
	ios;
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << "\n";
	}
}


//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

#define ld long double

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}

typedef long long int ll;
#define endl '\n'
const ll mod =1e9+7;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll inf = 1e18+123;

int32_t main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
   IOS
   int n;
   cin>>n;
   int a[n];
   for(int i = 0 ;i<n;i++)
    cin>>a[i];
   pair<int,int> stlen[n],enlen[n]; //index,length of segment. stlen start -> end  , enlen end - > start
   set<pair<int,int>> starts;
  for(int i = 0,j =0;i<n;i = j){
    while(j<n&&a[i] == a[j])
      j++;
    starts.insert({i-j,i});
    stlen[i] = {j-1,j-i};
    enlen[j-1] = {i,j-i};
  }
  int moves = 0;
  set<int> deleted;
  while(!starts.empty()){
    moves++;
    // for(auto it:starts)
    // {
    //   cout<<it<<" ";
    // }
    // cout<<endl;
    pair<int,int> v = *starts.begin();
    starts.erase(v);
    deleted.insert(v.second);
    deleted.insert(v.second-v.first+1);
    if(v.second == 0 || stlen[v.second].first == n-1)
      continue;
    int prev = v.second - 1;
    int next = stlen[v.second].first+1;
    if(deleted.count(prev) || deleted.count(next))
      continue;
    if(a[prev]!=a[next])
      continue;
    int pl = enlen[prev].second;
    int nl = stlen[next].second;
    pair<int,int> prevpair = {-pl,enlen[prev].first};
    pair<int,int> nextpair = {-nl,next};
    starts.erase(prevpair);
    starts.erase(nextpair);
    starts.insert({-(pl+nl),enlen[prev].first});
    stlen[enlen[prev].first] = {stlen[next].second,pl+nl};
    enlen[stlen[next].second] = {enlen[prev].first,pl+nl};
  }
  cout<<moves<<endl;

}


//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

#define ld long double

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}

typedef long long int ll;
#define endl '\n'
const ll mod =1e9+7;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll inf = 1e18+123;
set<int> st[62];

struct FT {
	vector<int> s;
	FT(int n = 200005) : s(n,0) {}
	void update(int pos, ll dif) { // a[pos] += dif
		for (; pos < (s).size(); pos |= pos + 1) s[pos] = (s[pos]+dif);
	}
	ll query(int pos) { // sum of values in [0, pos)
		ll res = 0;
		for (; pos > 0; pos &= pos - 1) res = (res+s[pos-1]);
		return res;
	}
};
vector<FT> ft;
int getl(int i,int n){
  int l = 1,r = n;
  while(l<r){
    int mid = (l+r)>>1;
    int sum = 0;
    for(int j = 0;j<1;j++){
      sum+=ft[j].query(mid+1);
    }

    if(sum<i)
      l = mid+1;
    else
    {
      r = mid;
    }

  }
  return l;
}
int32_t main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
   IOS
   int n;
   cin>>n;
   int a[n];
   for(int i = 0 ;i<n;i++)
    cin>>a[i];
   pair<int,int> stlen[n],enlen[n];
   set<pair<int,int>> starts;
  for(int i = 0,j =0;i<n;i= j){
    while(j<n&&a[i] == a[j])
      j++;
    starts.insert({i-j,i});
    stlen[i] = {j-1,j-i};
    enlen[j-1] = {i,j-i};
  }
  int moves = 0;
  while(!starts.empty()){
    moves++;
    pair<int,int> v = *starts.begin();
    starts.erase(v);
    if(v.second == 0 || stlen[v.second].first == n-1)
      continue;
    int prev = v.second - 1;
    int next = stlen[v.second].first+1;
    if(a[prev]!=a[next])
      continue;
    int pl = enlen[prev].second;
    int nl = stlen[next].second;
    pair<int,int> prevpair = {-pl,enlen[prev].first};
    pair<int,int> nextpair = {-nl,next};
    starts.erase(prevpair);
    starts.erase(nextpair);
    starts.insert({-pl+nl,enlen[prev].first});
    stlen[enlen[prev].first] = {stlen[next].second,pl+nl};
    enlen[stlen[next].second] = {enlen[prev].first,pl+nl};
  }
  cout<<moves<<endl;

}


//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

#define ld long double

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}

typedef long long int ll;
#define endl '\n'
const ll mod =1e9+7;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll inf = 1e18+123;

int32_t main()
{
     #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
   int n;
   cin>>n;
   int a[n];
   for(int i = 0 ;i<n;i++)
    cin>>a[i];
   int stlen[n];
   set<pair<int,int>> starts;
  set<int> st;
  for(int i = 0,j =0;i<n;i = j){
    while(j<n&&a[i] == a[j])
      j++;
    starts.insert({i-j,i});
    stlen[i] = j-i;
    st.insert(i);
  }
  int moves = 0;

  while(!starts.empty()){
    moves++;

    pair<int,int> v = *starts.begin();

    starts.erase(v);
    auto it = st.find(v.second);
    if(it == st.begin()) continue;
    it++;
    if(it == st.end())
    continue;
    it = st.find(v.second);
    auto next = it;
    auto prev = it;
    next++;
    prev--;
    int nxt = *next;
    int prv = *prev;
    if(a[nxt]!=a[prv])
      continue;
    st.erase(*it);
    st.erase(nxt);
    starts.erase({-stlen[nxt],nxt});
    starts.erase({-stlen[prv],prv});
    stlen[prv] += stlen[nxt];
    starts.insert({-stlen[prv],prv});

  }
  cout<<moves<<endl;

}


//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

#define ld long double

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}

typedef long long int ll;
#define endl '\n'
const ll mod =1e9+7;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll inf = 1e18+123;
set<int> st[62];

struct FT {
	vector<int> s;
	FT(int n = 200005) : s(n,0) {}
	void update(int pos, ll dif) { // a[pos] += dif
		for (; pos < (s).size(); pos |= pos + 1) s[pos] = (s[pos]+dif);
	}
	ll query(int pos) { // sum of values in [0, pos)
		ll res = 0;
		for (; pos > 0; pos &= pos - 1) res = (res+s[pos-1]);
		return res;
	}
};
vector<FT> ft;
int getl(int i,int n){
  int l = 1,r = n;
  while(l<r){
    int mid = (l+r)>>1;
    int sum = 0;
    for(int j = 0;j<1;j++){
      sum+=ft[j].query(mid+1);
    }

    if(sum<i)
      l = mid+1;
    else
    {
      r = mid;
    }

  }
  return l;
}
int32_t main()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
   IOS
   int n;
   cin>>n;
   int a[n];
   for(int i = 0 ;i<n;i++)
    cin>>a[i];
   pair<int,int> stlen[n],enlen[n];
   set<pair<int,int>> starts;
  for(int i = 0,j =0;i<n;i= j){
    while(j<n&&a[i] == a[j])
      j++;
    starts.insert({i-j,i});
    stlen[i] = {j-1,j-i};
    enlen[j-1] = {i,j-i};
  }
  int moves = 0;
  while(!starts.empty()){
    moves++;
    pair<int,int> v = *starts.begin();
    starts.erase(v);
    if(v.second == 0 || stlen[v.second].first == n-1)
      continue;
    int prev = v.second - 1;
    int next = stlen[v.second].first+1;
    if(a[prev]!=a[next])
      continue;
    int pl = enlen[prev].second;
    int nl = stlen[next].second;
    pair<int,int> prevpair = {-pl,enlen[prev].first};
    pair<int,int> nextpair = {-nl,next};
    starts.erase(prevpair);
    starts.erase(nextpair);
    starts.insert({-(pl+nl),enlen[prev].first});
    stlen[enlen[prev].first] = {stlen[next].second,pl+nl};
    enlen[stlen[next].second] = {enlen[prev].first,pl+nl};
  }
  cout<<moves<<endl;

}


//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

#define ld long double

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}

typedef long long int ll;
#define endl '\n'
const ll mod =1e9+7;
const ll MAX_NODES =200001;
const ll MAX_LOG =50;
const ll inf = 1e18+123;

int32_t main()
{
     #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
   int n;
   cin>>n;
   int a[n];
   for(int i = 0 ;i<n;i++)
    cin>>a[i];
   int stlen[n] = {0};
   set<pair<int,int>> starts;
  set<int> st;
  for(int i = 0,j =0;i<n;i = j){
    while(j<n&&a[i] == a[j])
      j++;
    starts.insert({i-j,i});
    stlen[i] = j-i;
    st.insert(i);
  }
  int moves = 0;

  while(!starts.empty()){

    pair<int,int> v = *(starts).begin();
    starts.erase(v);
    if(st.find(v.second) == st.end()) continue;
    st.erase(v.second);
    moves++;
    if(!st.empty()){
      auto next = st.lower_bound(v.second);
      if(next!=st.begin() and next!=st.end())
        {
          int nxt = *next;
          next--;
          int prv = *next;
          if(a[nxt] == a[prv]){
            stlen[prv]+=stlen[nxt];
            starts.insert({-stlen[prv],prv});
            st.erase(nxt);
          }
        }
    }

  }
  cout<<moves<<endl;

}


//https://codeforces.com/problemset/problem/899/E
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e09 + 31;
typedef long long ll;
#define el '\n'
#define pb push_back
#define sp ' '
#define f first
#define s second

struct comp
{
    bool operator()(const pair<int, int> &lhs, const pair<int, int> &rhs)
        const
    {
        if (lhs.f > rhs.f)
            return true;
        if (lhs.f < rhs.f)
            return false;
        if (lhs.s < rhs.s)
            return true;
        return false;
    }
};

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int n, temp, temp2;
    cin >> n;
    vector<int> a;
    multiset<pair<int, int>, comp> se; // len,pos
    map<int, vector<int>> mv;
    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        a.pb(temp);
    }
    temp = a[0], temp2 = 1;
    for (int i = 1; i <= n; i++)
    {
        if (i == n)
        {
            vector<int> tv; // pos,length,num
            tv.pb(i - temp2);
            tv.pb(temp2);
            tv.pb(temp);
            mv[mv.size()] = (tv);
            se.insert({temp2, mv.size() - 1});
            break;
        }
        if (a[i] == temp)
            temp2++;
        else
        {
            vector<int> tv; // pos,length,num
            tv.pb(i - temp2);
            tv.pb(temp2);
            tv.pb(temp);
            mv[mv.size()] = (tv);
            se.insert({temp2, mv.size() - 1});
            temp = a[i];
            temp2 = 1;
        }
    }
    int out = 0;
    while (!se.empty())
    {

        out++;
        int p = (*se.begin()).second;

        se.erase(se.begin());

        auto it = mv.find(p);
        if (it == mv.begin() || it == prev(mv.end()))
        {
            mv.erase(it);
            continue;
        }
        if ((prev(it)->s[2] == next(it)->s[2]))
        {
            se.erase(make_pair(prev(it)->s[1], prev(it)->f));
            se.erase(make_pair(next(it)->s[1], next(it)->f));
            prev(it)->s[1] += next(it)->s[1];
            se.insert(make_pair(prev(it)->s[1], prev(it)->f));
            it = mv.erase(it);
            mv.erase(it);
        }
    }
    cout << out;
}


//https://codeforces.com/problemset/problem/899/E
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e09 + 31;
typedef long long ll;
#define el '\n'
#define pb push_back
#define sp ' '
#define f first
#define s second

struct comp
{
    bool operator()(const pair<int, int> &lhs, const pair<int, int> &rhs)
        const
    {
        if (lhs.f > rhs.f)
            return true;
        if (lhs.f < rhs.f)
            return false;
        if (lhs.s < rhs.s)
            return true;
        return false;
    }
};

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int n, temp, temp2;
    cin >> n;
    vector<int> a;
    multiset<pair<int, int>, comp> se; // len,pos
    map<int, vector<int>> mv;
    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        a.pb(temp);
    }
    temp = a[0], temp2 = 1;
    for (int i = 1; i <= n; i++)
    {
        if (i == n)
        {
            vector<int> tv; // pos,length,num
            tv.pb(i - temp2);
            tv.pb(temp2);
            tv.pb(temp);
            mv[mv.size()] = (tv);
            se.insert({temp2, mv.size() - 1});
            break;
        }
        if (a[i] == temp)
            temp2++;
        else
        {
            vector<int> tv; // pos,length,num
            tv.pb(i - temp2);
            tv.pb(temp2);
            tv.pb(temp);
            mv[mv.size()] = (tv);
            se.insert({temp2, mv.size() - 1});
            temp = a[i];
            temp2 = 1;
        }
    }
    int out = 0;
    while (!se.empty())
    {

        out++;
        int p = (*se.begin()).second;

        se.erase(se.begin());

        auto it = mv.find(p);
        if (it == mv.begin() || it == prev(mv.end()))
        {
            mv.erase(it);
            continue;
        }
        if ((prev(it)->s[2] == next(it)->s[2]))
        {
            se.erase(make_pair(prev(it)->s[1], prev(it)->f));
            se.erase(make_pair(next(it)->s[1], next(it)->f));
            prev(it)->s[1] += next(it)->s[1];
            se.insert(make_pair(prev(it)->s[1], prev(it)->f));
            it = mv.erase(it);
        }
        mv.erase(it);
    }
    cout << out;
}


//https://codeforces.com/problemset/problem/899/E
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e09 + 31;
typedef long long ll;
#define el '\n'
#define pb push_back
#define sp ' '
#define f first
#define s second

struct comp
{
    bool operator()(const pair<int, int> &lhs, const pair<int, int> &rhs)
        const
    {
        if (lhs.f > rhs.f)
            return true;
        if (lhs.f < rhs.f)
            return false;
        if (lhs.s < rhs.s)
            return true;
        return false;
    }
};

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int n, temp, temp2;
    cin >> n;
    vector<int> a;
    multiset<pair<int, int>, comp> se; // len,pos
    vector<vector<int>> vv;
    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        a.pb(temp);
    }
    temp = a[0], temp2 = 1;
    for (int i = 1; i <= n; i++)
    {
        if (i == n)
        {
            vector<int> tv; // pos,length,num
            tv.pb(i - temp2);
            tv.pb(temp2);
            tv.pb(temp);
            vv.pb(tv);
            se.insert({temp2, i - temp2});
            break;
        }
        if (a[i] == temp)
            temp2++;
        else
        {
            vector<int> tv; // pos,length,num
            tv.pb(i - temp2);
            tv.pb(temp2);
            tv.pb(temp);
            vv.pb(tv);
            se.insert({temp2, i - temp2});
            temp = a[i];
            temp2 = 1;
        }
    }
    int out = 0;
    while (!se.empty())
    {

        out++;
        int p = (*se.begin()).second;

        se.erase(se.begin());
        //find pos in vv;

        int start = 0, end = vv.size() - 1;

        while (start < end)
        {
            int mid = (start + end) / 2;
            if (vv[mid][0] == p)
                start = end = mid;
            else if (vv[mid][0] > p)
                end = mid - 1;
            else
                start = mid + 1;
        }

        p = start;
        vv.erase(vv.begin() + p);
        if (p == 0 || p == vv.size())
            continue;
        if (vv[p - 1][2] == vv[p][2])
        {
            se.erase(make_pair(vv[p][1], vv[p][0]));
            se.erase(make_pair(vv[p - 1][1], vv[p - 1][0]));
            vv[p - 1][1] += vv[p][1];
            se.insert(make_pair(vv[p - 1][1], vv[p - 1][0]));
            vv.erase(vv.begin() + p);
        }
    }
    cout << out;
}


#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
vector<ll> a;

ll root(ll x){
     if(x==-1) return -1;
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}
ll ear[n]={0};
ll ri[n]={0};
set<pair<ll,ll>>s;
ll  len[n]={1};

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i]){dsu[j]=i;j++;}
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,-1*i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(-1*t.second);

	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= root(ear[r]);
	ans++;
	ll y = root(ri[r]);
	vis[r]=true;
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){
			s.insert({len[x]+len[y],-1*x});
			s.erase(s.find({len[x],-1*x}));
			s.erase(s.find({len[y],-1*y}));
               dsu[y]=dsu[x];
			len[x]+=len[y];
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


97953682#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
vector<ll> a;

ll root(ll x){
     if(x==-1) return -1;
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}
ll ear[n]={0};
ll ri[n]={0};
set<pair<ll,ll>>s;
ll  len[n]={1};

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i]){dsu[j]=i;j++;}
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,-1*i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(-1*t.second);

	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= root(ear[r]);
	ans++;
	ll y = root(ri[r]);
	vis[r]=true;
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){
			s.insert({len[x]+len[y],-1*x});
			s.erase(s.find({len[x],-1*x}));
			s.erase(s.find({len[y],-1*y}));
               dsu[y]=dsu[x];
			len[x]+=len[y];
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
ll ear[200009];
ll ri[200009];
ll  len[200009];
vector<ll> a;

ll root(ll x){
	if(x==-1) return -1;
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}

set<pair<ll,ll>>s;

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i]){dsu[j]=i;j++;}
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,-1*i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(-1*t.second);
	//cout<<r<<" ";
	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= root(ear[r]);
	ans++;
	ll y = root(ri[r]);
	vis[r]=true;
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){

			s.erase(s.find({len[x],-1*x}));
			s.erase(s.find({len[y],-1*y}));
			s.insert({len[x]+len[y],-1*x});
			len[x]+=len[y];
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
vector<ll> a;

ll root(ll x){
     if(x==-1) return -1;
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}
ll ear[n]={0};
ll ri[n]={0};
set<pair<ll,ll>>s;
ll  len[n]={1};

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i]){dsu[j]=i;j++;}
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,-1*i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(-1*t.second);

	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= ear[r];
	ans++;
	ll y = ri[r];
	if(x<0 && x!=-1) cout<<"F";
	if(y<0 && y!=-1) cout<<"Y";
	vis[r]=true;
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){
			s.insert({len[x]+len[y],-1*x});
			s.erase(s.find({len[x],-1*x}));
			s.erase(s.find({len[y],-1*y}));
               dsu[y]=dsu[x];
			len[x]+=len[y];
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
vector<ll> a;

ll root(ll x){
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}
ll ear[n]={0};
ll ri[n]={0};
set<pair<ll,ll>>s;
ll  len[n]={1};

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i]){dsu[j]=i;j++;}
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,-1*i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(-1*t.second);
	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= ear[r];
	ans++;
	ll y = ri[r];
	vis[r]=true;
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){
			s.insert({len[x]+len[y],-1*x});
			s.erase(s.find({len[x],-1*x}));
			s.erase(s.find({len[y],-1*y}));

			len[x]+=len[y];
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
vector<ll> a;

ll root(ll x){
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}
ll ear[n]={0};
ll ri[n]={0};
set<pair<ll,ll>>s;
ll  len[n]={1};

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i])j++;
	for(ll x=i;x<j;++x) dsu[x]=i;
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(t.second);
	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= ear[r];
	ans++;
	ll y = ri[r];
	vis[r]=true;
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){
			s.insert({len[x]+len[y],x});
			s.erase(s.find({len[x],x}));
			s.erase(s.find({len[y],y}));
               dsu[y]=x;
			len[x]+=len[y];
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
vector<ll> a;

ll root(ll x){
     if(x==-1) return -1;
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}
ll ear[n]={0};
ll ri[n]={0};
set<pair<ll,ll>>s;
ll  len[n]={1};

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i]){dsu[j]=i;j++;}
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,-1*i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(-1*t.second);

	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= ear[r];
	ans++;
	ll y = ri[r];
	vis[r]=true;
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){
			s.insert({len[x]+len[y],-1*x});
			s.erase(s.find({len[x],-1*x}));
			s.erase(s.find({len[y],-1*y}));
               dsu[y]=dsu[x];
			len[x]+=len[y];
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
vector<ll> a;

ll root(ll x){
     if(x==-1) return -1;
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}
ll ear[n]={0};
ll ri[n]={0};
set<pair<ll,ll>>s;
ll  len[n]={1};

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i]){dsu[j]=i;j++;}
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,-1*i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(-1*t.second);

	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= root(ear[r]);
	ans++;
	ll y = root(ri[r]);
	vis[r]=true;
	if(x<0 && x!=-1 ) cout<<"F";
	if(y<0 && y!=-1) cout<<"D";
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){
			s.insert({len[x]+len[y],-1*x});
			s.erase(s.find({len[x],-1*x}));
			s.erase(s.find({len[y],-1*y}));
               dsu[y]=dsu[x];
			len[x]+=len[y];
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
vector<ll> a;

ll root(ll x){
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}
ll ear[n]={0};
ll ri[n]={0};
set<pair<ll,ll>>s;
ll  len[n]={1};

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i]){dsu[j]=i;j++;}
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,-1*i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(-1*t.second);

	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= ear[r];
	ans++;
	ll y = ri[r];
	vis[r]=true;
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){
			s.insert({len[x]+len[y],-1*x});
			s.erase(s.find({len[x],-1*x}));
			s.erase(s.find({len[y],-1*y}));
               dsu[y]=dsu[x];
			len[x]+=len[y];
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
ll ear[200009];
ll ri[200009];
ll  len[200009];
vector<ll> a;

ll root(ll x){
	if(x==-1) return -1;
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}

set<pair<ll,ll>>s;

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i]){dsu[j]=i;j++;}
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,-1*i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(-1*t.second);
	//cout<<r<<" ";
	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= root(ear[r]);
	ans++;
	ll y = root(ri[r]);
	vis[r]=true;
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){

			s.erase(s.find({len[x],-1*x}));
			s.erase(s.find({len[y],-1*y}));
			s.insert({len[x]+len[y],-1*x});
			len[x]+=len[y];
			dsu[y]=x;
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
vector<ll> a;

ll root(ll x){
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}
ll ear[n]={0};
ll ri[n]={0};
set<pair<ll,ll>>s;
ll  len[n]={1};

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i])j++;
	for(ll x=i;x<j;++x) dsu[x]=i;
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(t.second);
	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= ear[r];
	ans++;
	ll y = ri[r];
	vis[r]=true;
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){
			s.insert({len[x]+len[y],x});
			s.erase(s.find({len[x],x}));
			s.erase(s.find({len[y],y}));

			len[x]+=len[y];
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
vector<ll> a;

ll root(ll x){
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}
ll ear[n]={0};
ll ri[n]={0};
set<pair<ll,ll>>s;
ll  len[n]={1};

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i]){dsu[j]=i;j++;}
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,-1*i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(-1*t.second);
	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= ear[r];
	ans++;
	ll y = ri[r];
	vis[r]=true;
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){
			s.insert({len[x]+len[y],x});
			s.erase(s.find({len[x],x}));
			s.erase(s.find({len[y],y}));
               dsu[y]=dsu[x];
			len[x]+=len[y];
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define sz 41
using namespace std;

using ll = long long int ;
ll hell = 1e15+7;

ll dsu[200009];
ll ear[200009];
ll ri[200009];
ll  len[200009];
vector<ll> a;

ll root(ll x){
	if(dsu[x]==x) return x;
	dsu[x]=root(dsu[x]);
	return dsu[x];
}

int main(){
ll n;cin>>n;
a.resize(n);
for(ll i=0;i<n;++i){
	cin>>a[i];
}

set<pair<ll,ll>>s;

for(ll i=0;i<n;++i){
	ll j=i;
	while(j<n && a[j]==a[i]){dsu[j]=i;j++;}
	if(i!=0) ear[i]=dsu[i-1];
	else ear[i]=-1;
	if(j!=n){
		ri[i]=j;
	}
	else ri[i]=-1;
	len[i]=j-i;
	s.insert({j-i,-1*i});
	i=j-1;
}
bool vis[n]={false};
ll ans=0;
while(!s.empty()){
	pair<ll,ll> t= *s.rbegin();
	ll r= root(-1*t.second);
	s.erase(s.find(t));
	if(vis[r]) continue;
	ll x= root(ear[r]);
	ans++;
	ll y = root(ri[r]);
	vis[r]=true;
	if(x==-1 && y==-1) break;
	if(x!=-1 && y!=-1){
		if(a[x]==a[y]){

			s.erase(s.find({len[x],-1*x}));
			s.erase(s.find({len[y],-1*y}));
			s.insert({len[x]+len[y],-1*x});
			len[x]+=len[y];
			ri[x]=ri[y];

		}
		else{
			ri[x]=y;
			ear[y]=x;
		}
	}
	else if(x==-1){
		ear[y]=-1;
	}
	else if(y==-1) ri[x]=-1;

}
cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(int)(n);i++)
#define foi(i,k,n) for(int i=(k); i<(int)(n); i+=1)
#define fod(i,n,k) for(int i=k; i>=(int)n; i-=1)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define endl "\n"

#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef long long int llint;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<llint> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
llint toint(string s) {stringstream ss(s); llint x; ss >> x; return x;}
//gp_hash_table<string, llint> table;

//int mpow(llint base, llint exp) {
  //base %= MOD;
  //llint result = 1;
  //while (exp > 0) {
    //if (exp & 1) result = ((llint)result * base) % MOD;
    //base = ((llint)base * base) % MOD;
    //exp >>= 1;
  //}
  //return result;
//}

//void makegraph(int n, int m){
	//int i, u, v;
	//while(m--){
		//cin>>u>>v;
		//u--, v--;
		//g[u].pb(v);
		//g[v].pb(u);
	//}
//}

//void dfs(int u, int par){
	//for(int v:g[u]){
		//if (v == par) continue;
		//dfs(v, u);
	//}
//}

// ------------------------------------------------------------------ILB----------------------------------------------------------------  //

const int N=1e5+5;

void solve(){
	int n;
	cin >> n;
	VI v(n);

	loop(i, n) cin >> v[i];

	set <PII> a, b;
	for(int i = 0; i < n; ++i){
		int r = i;

		while(r < n - 1 && v[i] == v[r + 1]){
			++r;
		}

		a.insert({i, r - i + 1});
		b.insert({ -(r - i + 1), i});
		i = r;
	}

//	debug(a.size());

	int ans = 0;
	while(b.size()){
		PII p = *b.begin();
		ans++;
		auto it = a.lower_bound(mp(p.sec, 0));
		auto l = it, r = it;

		if(l != a.begin() && r != a.end()){
			--l; ++r;
			if(r != a.end()){
    			if(v[l->fir] == v[r->fir]){
    				b.erase({-l->sec, l->fir}); b.erase({-r->sec, r->fir});
    				PII nw = {l->fir, l->sec + r->sec};

    			//	cout << r->fir << " " << r->sec << endl;
    			//	if(a.size() < 3) break;
    				a.erase({l->fir, l->sec}); a.erase({r->fir, r->sec});
    				a.insert(nw);
    				b.insert(mp(-nw.sec, nw.fir));
    			}
			}
		}
		a.erase(it);
		b.erase(p);
	}

	cout << ans;
}

int main() {
	fast_io;
    int t = 1;
    //cin >> t;
    //int xx = 0
    while(t--) {
		//xx++;
		//cout << "Case ";
      solve();
    }
    return 0;
}