#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 && v[i] == v[r]){
			++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(it != a.begin() && it != --a.end() && it != a.end()){
			--l; ++r;

			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};
				a.erase(l); a.erase(r);
				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;
}


#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 && v[i] == v[r]){
			++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(it != a.begin() && it != --a.end() && it != a.end()){
			--l; ++r;

			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};
				a.erase(l); a.erase(r);
				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;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;

typedef long long ll;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, ll> LP;
const ll inf = 1e9+100;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll ksm(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]

unordered_map<ll, ll> mp;

ll  vis[N],num[N],did[N];
ll n, m,  k, x, y, z;
ll a[N], b[N],c[N];
ll cx, cy, cz,cnt, ans, sum, flag, t, ff,w;

vector<int> v[N],res;
string s;
struct node
{
	int x,num,id;
	node(){x=num=0;}
	bool friend operator < (node a,node b)
	{
		return a.num<b.num;
	}
}p[N];
priority_queue<node> q;
set<int> st;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	p[++cnt].x=a[1];
	p[cnt].num=1;
	p[cnt].id=cnt;
	st.insert(-1);
	st.insert(inf);
	st.insert(cnt);

	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			p[cnt].num++;
		}
		else
		{
			p[++cnt].x=a[i];
			p[cnt].num=1;
			p[cnt].id=cnt;
			st.insert(cnt);
			//show2("cnt",cnt)
		}
	}
	for(int i=1;i<=cnt;i++)
	{
		//show3(p[i].x,p[i].num,p[i].id)
		q.push(p[i]);
	}
	while(q.size())
	{
		//show3("size",q.size(),st.size())
		node nx=q.top();
		q.pop();
		//show3(nx.x,nx.num,nx.id)
		if(!vis[nx.id]) ans++;
		vis[nx.id]=1;
		int id=nx.id;
		int l=*(--st.lower_bound(id));
		int r=*(st.upper_bound(id));
		if(st.count(id))	st.erase(id);
		if(l<=0) continue;
		if(r>cnt) continue;
		//show3("l-r",l,r)
		if(p[l].x==p[r].x)
		{
			p[l].num+=p[r].num;
			vis[r]=1;

			if(st.count(r))	st.erase(r);
			q.push(p[l]);
			st.insert(p[l].id);
		}

	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;

typedef long long ll;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, ll> LP;
const ll inf = 1e9+100;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll ksm(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]

unordered_map<ll, ll> mp;

ll  vis[N],num[N],did[N];
ll n, m,  k, x, y, z;
ll a[N], b[N],c[N];
ll cx, cy, cz,cnt, ans, sum, flag, t, ff,w;

vector<int> v[N],res;
string s;
struct node
{
	int x,num,id;
	node(){x=num=0;}
	bool friend operator < (node a,node b)
	{
		return a.num<b.num;
	}
}p[N];
priority_queue<node> q;
set<int> st;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	p[++cnt].x=a[1];
	p[cnt].num=1;
	p[cnt].id=cnt;
	st.insert(-1);
	st.insert(inf);
	st.insert(cnt);

	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			p[cnt].num++;
		}
		else
		{
			p[++cnt].x=a[i];
			p[cnt].num=1;
			p[cnt].id=cnt;
			st.insert(cnt);
			//show2("cnt",cnt)
		}
	}
	for(int i=1;i<=cnt;i++)
	{
		//show3(p[i].x,p[i].num,p[i].id)
		q.push(p[i]);
	}
	while(q.size())
	{
		//show3("size",q.size(),st.size())
		node nx=q.top();
		q.pop();
		//show3(nx.x,nx.num,nx.id)
		if(!vis[nx.id]) ans++;
		if(vis[nx.id]) continue;
		vis[nx.id]=1;
		int id=nx.id;
		int l=*(--st.lower_bound(id));
		int r=*(st.upper_bound(id));
		if(st.count(id))	st.erase(id);
		if(l<=0) continue;
		if(r>cnt) continue;
		//show3("l-r",l,r)
		if(p[l].x==p[r].x)
		{
			p[l].num+=p[r].num;
			vis[r]=1;

			if(st.count(r))	st.erase(r);
			q.push(p[l]);
			//st.insert(p[l].id);
		}

	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;

typedef long long ll;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, ll> LP;
const ll inf = 1e9+100;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll ksm(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]

unordered_map<ll, ll> mp;

ll  vis[N],num[N],did[N];
ll n, m,  k, x, y, z;
ll a[N], b[N],c[N];
ll cx, cy, cz,cnt, ans, sum, flag, t, ff,w;
int pre[N],nex[N];

vector<int> v[N],res;
string s;
struct node
{
	int x,num,id;
	node(){x=num=0;}
	bool friend operator < (node a,node b)
	{
		if(a.num==b.num) return a.id>b.id;
		return a.num<b.num;
	}
}p[N];
priority_queue<node> q;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	p[++cnt].x=a[1];
	p[cnt].num=1;
	p[cnt].id=cnt;

	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			p[cnt].num++;
		}
		else
		{
			p[++cnt].x=a[i];
			p[cnt].num=1;
			p[cnt].id=cnt;

		}
	}
	for(int i=1;i<=cnt;i++)
	{
		pre[i]=i-1;
		nex[i]=i+1;
		q.push(p[i]);
	}
	while(cnt)
	{
		node nx=q.top();
		q.pop();
		if(!vis[nx.id]) ans++,cnt--;
		else continue;
		//show2("id:",nx.id)
		vis[nx.id]=1;
		int id=nx.id;
		int l=pre[id],r=nex[id];
		if(l&&p[l].x==p[r].x)
		{
			p[l].num+=p[r].num;
			vis[r]=1;
			nex[l]=nex[r];
			pre[nex[r]]=l;
			q.push(p[l]);
			cnt--;
		}
		else
		{
			nex[l]=r;
			pre[r]=l;
		}
	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;

typedef long long ll;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, ll> LP;
const ll inf = 1e9+100;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll ksm(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]

unordered_map<ll, ll> mp;

ll  vis[N],num[N],did[N];
ll n, m,  k, x, y, z;
ll a[N], b[N],c[N];
ll cx, cy, cz,cnt, ans, sum, flag, t, ff,w;

vector<int> v[N],res;
string s;
struct node
{
	int x,num,id;
	node(){x=num=0;}
	bool friend operator < (node a,node b)
	{
		return a.num<b.num;
	}
}p[N];
priority_queue<node> q;
set<int> st;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	p[++cnt].x=a[1];
	p[cnt].num=1;
	p[cnt].id=cnt;
	st.insert(-1);
	st.insert(inf);
	st.insert(cnt);

	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			p[cnt].num++;
		}
		else
		{
			p[++cnt].x=a[i];
			p[cnt].num=1;
			p[cnt].id=cnt;
			st.insert(cnt);
		}
	}
	for(int i=1;i<=cnt;i++)
	{
		//show3(p[i].x,p[i].num,p[i].id)
		q.push(p[i]);
	}
	while(q.size())
	{
		node nx=q.top();
		q.pop();
		//show3(nx.x,nx.num,nx.id)
		if(!vis[nx.id]) ans++;
		vis[nx.id]=1;
		int id=nx.id;
		int l=*(--st.lower_bound(id));
		int r=*(++st.lower_bound(id));
		st.erase(id);
		if(l<=0) continue;
		if(r>cnt) continue;
		//show3("l-r",l,r)
		if(p[l].x==p[r].x)
		{
			p[l].num+=p[r].num;
			vis[r]=1;
			st.erase(r);
			q.push(p[l]);
			st.insert(p[l].id);
		}

	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;

typedef long long ll;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, ll> LP;
const ll inf = 1e9+100;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll ksm(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]

unordered_map<ll, ll> mp;

ll  vis[N],num[N],did[N];
ll n, m,  k, x, y, z;
ll a[N], b[N],c[N];
ll cx, cy, cz,cnt, ans, sum, flag, t, ff,w;

vector<int> v[N],res;
string s;
struct node
{
	int x,num,id;
	node(){x=num=0;}
	bool friend operator < (node a,node b)
	{
		return a.num<b.num;
	}
}p[N];
priority_queue<node> q;
set<int> st;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	p[++cnt].x=a[1];
	p[cnt].num=1;
	p[cnt].id=cnt;
	st.insert(-1);
	st.insert(inf);
	st.insert(cnt);

	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			p[cnt].num++;
		}
		else
		{
			p[++cnt].x=a[i];
			p[cnt].num=1;
			p[cnt].id=cnt;
			st.insert(cnt);
		}
	}
	for(int i=1;i<=cnt;i++)
	{
		//show3(p[i].x,p[i].num,p[i].id)
		q.push(p[i]);
	}
	while(q.size())
	{
		node nx=q.top();
		q.pop();
		//show3(nx.x,nx.num,nx.id)
		if(!vis[nx.id]) ans++;
		vis[nx.id]=1;
		int id=nx.id;
		int l=*(--st.lower_bound(id));
		int r=*(st.lower_bound(id));
		st.erase(id);
		if(l<=0) continue;
		if(r>cnt) continue;
		//show3("l-r",l,r)
		if(p[l].x==p[r].x)
		{
			p[l].num+=p[r].num;
			vis[r]=1;
			st.erase(r);
		}

		q.push(p[l]);
		st.insert(p[l].id);
	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;

typedef long long ll;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, ll> LP;
const ll inf = 1e9+100;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll ksm(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]

unordered_map<ll, ll> mp;

ll  vis[N],num[N],did[N];
ll n, m,  k, x, y, z;
ll a[N], b[N],c[N];
ll cx, cy, cz,cnt, ans, sum, flag, t, ff,w;

vector<int> v[N],res;
string s;
struct node
{
	int x,num,id;
	node(){x=num=0;}
	bool friend operator < (node a,node b)
	{
		if(a.num==b.num) return a.id>b.id;
		return a.num<b.num;
	}
}p[N];
priority_queue<node> q;
set<int> st;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	p[++cnt].x=a[1];
	p[cnt].num=1;
	p[cnt].id=cnt;
	st.insert(-1);
	st.insert(inf);
	st.insert(cnt);

	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			p[cnt].num++;
		}
		else
		{
			p[++cnt].x=a[i];
			p[cnt].num=1;
			p[cnt].id=cnt;
			st.insert(cnt);
			//show2("cnt",cnt)
		}
	}
	for(int i=1;i<=cnt;i++)
	{
		//show3(p[i].x,p[i].num,p[i].id)
		q.push(p[i]);
	}
	while(q.size())
	{
		//show3("size",q.size(),st.size())
		node nx=q.top();
		q.pop();
		//show3(nx.x,nx.num,nx.id)
		if(!vis[nx.id]) ans++;
		//show2("ans:", ans)
		//if(vis[nx.id]) continue;
		vis[nx.id]=1;
		int id=nx.id;
		int l=*(--st.lower_bound(id));
		int r=*(st.upper_bound(id));
		if(st.count(id))	st.erase(id);
		if(l<=0) continue;
		if(r>cnt) continue;
		if(p[l].x==p[r].x)
		{
			p[l].num+=p[r].num;
			vis[r]=1;
			if(st.count(r))	st.erase(r);
			q.push(p[l]);
		}

	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;

typedef long long ll;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, ll> LP;
const ll inf = 1e9+100;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll ksm(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]

unordered_map<ll, ll> mp;

ll  vis[N],num[N],did[N];
ll n, m,  k, x, y, z;
ll a[N], b[N],c[N];
ll cx, cy, cz,cnt, ans, sum, flag, t, ff,w;

vector<int> v[N],res;
string s;
struct node
{
	int x,num,id;
	node(){x=num=0;}
	bool friend operator < (node a,node b)
	{
		return a.num<b.num;
	}
}p[N];
priority_queue<node> q;
set<int> st;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	p[++cnt].x=a[1];
	p[cnt].num=1;
	p[cnt].id=cnt;
	st.insert(-1);
	st.insert(inf);
	st.insert(cnt);

	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			p[cnt].num++;
		}
		else
		{
			p[++cnt].x=a[i];
			p[cnt].num=1;
			p[cnt].id=cnt;
			st.insert(cnt);
		}
	}
	for(int i=1;i<=cnt;i++)
	{
		//show3(p[i].x,p[i].num,p[i].id)
		q.push(p[i]);
	}
	while(q.size())
	{
		node nx=q.top();
		q.pop();
		//show3(nx.x,nx.num,nx.id)
		if(!vis[nx.id]) ans++;
		vis[nx.id]=1;
		int id=nx.id;
		int l=*(--st.lower_bound(id));
		int r=*(++st.lower_bound(id));
		st.erase(id);
		if(l<=0) continue;
		if(r>cnt) continue;
		//show3("l-r",l,r)
		x=p[l].x;
		y=p[r].x;
		if(x==y)
		{
			p[l].num+=p[r].num;
			vis[r]=1;
			st.erase(r);
		}

		q.push(p[l]);
	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;

typedef long long ll;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, ll> LP;
const ll inf = 1e9+100;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll ksm(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]

unordered_map<ll, ll> mp;

ll  vis[N],num[N],did[N];
ll n, m,  k, x, y, z;
ll a[N], b[N],c[N];
ll cx, cy, cz,cnt, ans, sum, flag, t, ff,w;

vector<int> v[N],res;
string s;
struct node
{
	int x,num,id;
	node(){x=num=0;}
	bool friend operator < (node a,node b)
	{
		return a.num<b.num;
	}
}p[N];
priority_queue<node> q;
set<int> st;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	p[++cnt].x=a[1];
	p[cnt].num=1;
	p[cnt].id=cnt;
	st.insert(-1);
	st.insert(inf);
	st.insert(cnt);

	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			p[cnt].num++;
		}
		else
		{
			p[++cnt].x=a[i];
			p[cnt].num=1;
			p[cnt].id=cnt;
			st.insert(cnt);
			//show2("cnt",cnt)
		}
	}
	for(int i=1;i<=cnt;i++)
	{
		//show3(p[i].x,p[i].num,p[i].id)
		q.push(p[i]);
	}
	while(q.size())
	{
		//show3("size",q.size(),st.size())
		node nx=q.top();
		q.pop();
		//show3(nx.x,nx.num,nx.id)
		if(!vis[nx.id]) ans++;
		if(vis[nx.id]) continue;
		vis[nx.id]=1;
		int id=nx.id;
		int l=*(--st.lower_bound(id));
		int r=*(st.upper_bound(id));
		if(st.count(id))	st.erase(id);
		if(l<=0) continue;
		if(r>cnt) continue;
		//show3("l-r",l,r)
		if(p[l].x==p[r].x)
		{
			p[l].num+=p[r].num;
			vis[r]=1;

			if(st.count(r))	st.erase(r);
			q.push(p[l]);
			st.insert(p[l].id);
		}

	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;

typedef long long ll;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, ll> LP;
const ll inf = 1e9+100;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll ksm(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]

unordered_map<ll, ll> mp;

ll  vis[N],num[N],did[N];
ll n, m,  k, x, y, z;
ll a[N], b[N],c[N];
ll cx, cy, cz,cnt, ans, sum, flag, t, ff,w;

vector<int> v[N],res;
string s;
struct node
{
	int x,num,id;
	node(){x=num=0;}
	bool friend operator < (node a,node b)
	{
		return a.num<b.num;
	}
}p[N];
priority_queue<node> q;
multiset<int> st;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	p[++cnt].x=a[1];
	p[cnt].num=1;
	p[cnt].id=cnt;
	st.insert(-1);
	st.insert(inf);
	st.insert(cnt);

	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			p[cnt].num++;
		}
		else
		{
			p[++cnt].x=a[i];
			p[cnt].num=1;
			p[cnt].id=cnt;
			st.insert(cnt);
			//show2("cnt",cnt)
		}
	}
	for(int i=1;i<=cnt;i++)
	{
		//show3(p[i].x,p[i].num,p[i].id)
		q.push(p[i]);
	}
	while(q.size())
	{
		//show3("size",q.size(),st.size())
		node nx=q.top();
		q.pop();
		//show3(nx.x,nx.num,nx.id)
		if(!vis[nx.id]) ans++;
		vis[nx.id]=1;
		int id=nx.id;
		int l=*(--st.lower_bound(id));
		int r=*(st.upper_bound(id));
		auto it=st.find(id);
		//show2("it",*it)
		if(it!=st.end())
		{
			//show2("it rease",*it)
			st.erase(it);
		}
		if(l<=0) continue;
		if(r>cnt) continue;
		//show3("l-r",l,r)
		if(p[l].x==p[r].x)
		{
			p[l].num+=p[r].num;
			vis[r]=1;
			it=st.find(r);
			if(it!=st.end())st.erase(it);
			q.push(p[l]);
			st.insert(p[l].id);
		}

	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;

typedef long long ll;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, ll> LP;
const ll inf = 1e9+100;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll ksm(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]

unordered_map<ll, ll> mp;

ll  vis[N],num[N],did[N];
ll n, m,  k, x, y, z;
ll a[N], b[N],c[N];
ll cx, cy, cz,cnt, ans, sum, flag, t, ff,w;

vector<int> v[N],res;
string s;
struct node
{
	int x,num,id;
	node(){x=num=0;}
	bool friend operator < (node a,node b)
	{
		return a.num<b.num;
	}
}p[N];
priority_queue<node> q;
set<int> st;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	p[++cnt].x=a[1];
	p[cnt].num=1;
	p[cnt].id=cnt;
	st.insert(-1);
	st.insert(inf);
	st.insert(cnt);

	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			p[cnt].num++;
		}
		else
		{
			p[++cnt].x=a[i];
			p[cnt].num=1;
			p[cnt].id=cnt;
			st.insert(cnt);
		}
	}
	for(int i=1;i<=cnt;i++)
	{
		//show3(p[i].x,p[i].num,p[i].id)
		q.push(p[i]);
	}
	while(q.size())
	{
		node nx=q.top();
		q.pop();
		//show3(nx.x,nx.num,nx.id)
		if(!vis[nx.id]) ans++;
		vis[nx.id]=1;
		int id=nx.id;
		int l=*(--st.lower_bound(id));
		int r=*(++st.lower_bound(id));
		st.erase(id);
		if(l==-1) continue;
		if(r==inf) continue;
		//show3("l-r",l,r)
		if(p[l].x==p[r].x)
		{
			p[l].num+=p[r].num;
			vis[r]=1;
			st.erase(r);
		}

		q.push(p[l]);
	}
	cout<<ans;

}


#include<bits/stdc++.h>
#define fi first
#define se second
#define log2(a) log(n)/log(2)
#define show(a) cout<<a<<endl;
#define show2(a,b) cout<<a<<" "<<b<<endl;
#define show3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
#define tim printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
using namespace std;

typedef long long ll;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, ll> LP;
const ll inf = 1e9+100;
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const int base = 131;
const double pi = acos ( -1 );
const double eps = 1e-8;
inline ll ksm(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
#define a(i,j) a[(i-1)*m+(j)]
#define b(i,j) b[(i-1)*m+(j)]

unordered_map<ll, ll> mp;

ll  vis[N],num[N],did[N];
ll n, m,  k, x, y, z;
ll a[N], b[N],c[N];
ll cx, cy, cz,cnt, ans, sum, flag, t, ff,w;

vector<int> v[N],res;
string s;
struct node
{
	int x,num,id;
	node(){x=num=0;}
	bool friend operator < (node a,node b)
	{
		if(a.num==b.num) return a.id>b.id;
		return a.num<b.num;
	}
}p[N];
priority_queue<node> q;
set<int> st;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	p[++cnt].x=a[1];
	p[cnt].num=1;
	p[cnt].id=cnt;
	st.insert(-1);
	st.insert(inf);
	st.insert(cnt);

	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			p[cnt].num++;
		}
		else
		{
			p[++cnt].x=a[i];
			p[cnt].num=1;
			p[cnt].id=cnt;
			st.insert(cnt);
		}
	}
	for(int i=1;i<=cnt;i++)
	{
		q.push(p[i]);
	}
	while(cnt)
	{
		node nx=q.top();
		q.pop();
		if(!vis[nx.id]) ans++,cnt--;
		else continue;
		//show2("id:",nx.id)
		vis[nx.id]=1;
		int id=nx.id;
		int l=*(--st.lower_bound(id));
		int r=*(st.upper_bound(id));
		if(st.count(id))	st.erase(id);
		if(l<=0) continue;
		if(r==inf) continue;
		if(p[l].x==p[r].x)
		{
			p[l].num+=p[r].num;
			vis[r]=1;
			if(st.count(r))	st.erase(r);
			q.push(p[l]);
			cnt--;
		}
	}
	cout<<ans;

}


#include <bits/stdc++.h>

#define pii pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, x) for(int i = 0; i < x; i++)
#define rforn(i, x) for(int i = x - 1; i >= 0; i--)
#define printp(x) for(int i = 0; i < (x).size(); i++) cout << (x)[i] + 1 << " "; cout << endl;
#define print(x) for(int i = 0; i < (x).size(); i++) cout << (x)[i] << " "; cout << endl;

using namespace std;

vector<int> p, ranks;
vector<pii> root;

int get(int a)
{
    if (p[a] == a)
        return a;
    return p[a] = get(p[a]);
}

void unite(int a, int b, int l, int r)
{
    a = get(a);
    b = get(b);
    if (a != b)
    {
        if (ranks[a] > ranks[b])
            swap(a, b);
        p[a] = b;
        root[b] = {l, r};
        if (ranks[a] == ranks[b])
            ranks[b]++;
    }
}

signed main()
{
    //freopen("test.txt", "r", stdin);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);

    forn (i, n)
        cin >> a[i];

    p.resize(n);
    ranks.resize(n);
    root.resize(n);
    forn (i, n)
    {
        root[i] = {-1, -1};
        p[i] = i;
        ranks[i] = 1;
    }

    set<vector<int> > s;

    vector<int> left(n), right(n);

    int last = 0;
    forn (i, n)
    {
        if (a[i] != a[last])
        {
            s.insert({-(i - last), last, i - 1});
            //cout << -(i - last) << ' ' << last << ' ' << i - 1 << endl;
            left[i - 1] = last;
            right[last] = i - 1;
            last = i;
        }
    }
    s.insert({-(n - 1 - last + 1), last, n - 1});

    //cout << -(n - 1 - last + 1) << ' ' << last << ' ' << n - 1 << endl;
    //cout << endl;

    left[n - 1] = last;
    right[last] = n - 1;

    int ans = 0;
    while (s.size())
    {
        ans++;

        int l = (*s.begin())[1], r = (*s.begin())[2];
        s.erase(s.begin());

        //cout << l << ' ' << r << endl;

        int prev_seg = l - 1;
        int next_seg = r + 1;

        unite(l, r, l, r);

        if (prev_seg < 0 || next_seg >= n)
            continue;

        int l0 = l;
        int final_l = l, final_r = r;

        if (prev_seg >= 0)
        {
            prev_seg = get(prev_seg);

            int l1 = root[prev_seg].ff;

            if (l1 != -1)
            {
                unite(prev_seg, l, l1, r);
                l0 = l1;
                final_l = l1;
            }
        }

        if (next_seg < n)
        {
            next_seg = get(next_seg);

            int r1 = root[next_seg].ss;
            if (r1 != -1)
            {
                unite(next_seg, l, l0, r1);
                final_r = r1;
            }
        }

        int l1 = final_l;
        int r1 = final_r;

        l1--;
        r1++;

        //cout << l1 << ' ' << r1 << endl;

        //cout << endl << endl;

        if (l1 < 0 || r1 >= n)
            continue;

        if (a[l1] == a[r1])
        {
            //cout << -(l1 - left[l1] + 1) << ' ' << left[l1] << ' ' <<  l1 << endl;
            //cout << -(right[r1] - r1 + 1) << ' ' << r1 << ' ' << right[r1] << endl;
            //cout << -(right[r1] - left[l1] - (r1 - l1 - 1) + 1) << ' ' << left[l1] << ' ' << right[r1] << endl;

            //cout << left[l1] << ' ' << right[r1] << endl;

            s.erase({-(l1 - left[l1] + 1), left[l1], l1});
            s.erase({-(right[r1] - r1 + 1), r1, right[r1]});
            s.insert({-(right[r1] - left[l1] + 1), left[l1], right[r1]});

            left[right[r1]] = left[l1];
            right[left[l1]] = right[r1];
        }
    }

    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define int long long
#define pii pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, x) for(int i = 0; i < x; i++)
#define rforn(i, x) for(int i = x - 1; i >= 0; i--)
#define printp(x) for(int i = 0; i < (x).size(); i++) cout << (x)[i] + 1 << " "; cout << endl;
#define print(x) for(int i = 0; i < (x).size(); i++) cout << (x)[i] << " "; cout << endl;

using namespace std;

vector<int> p, ranks;
vector<pii> root;

int get(int a)
{
    if (p[a] == a)
        return a;
    return p[a] = get(p[a]);
}

void unite(int a, int b, int l, int r)
{
    a = get(a);
    b = get(b);
    if (a != b)
    {
        if (ranks[a] > ranks[b])
            swap(a, b);
        p[a] = b;
        root[b] = {l, r};
        if (ranks[a] == ranks[b])
            ranks[b]++;
    }
}

signed main()
{
    //freopen("test.txt", "r", stdin);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);

    forn (i, n)
        cin >> a[i];

    p.resize(n);
    ranks.resize(n);
    root.resize(n);
    forn (i, n)
    {
        root[i] = {-1, -1};
        p[i] = i;
        ranks[i] = 1;
    }

    multiset<vector<int> > s;

    vector<int> left(n), right(n);

    int last = 0;
    forn (i, n)
    {
        if (a[i] != a[last])
        {
            s.insert({-(i - last), last, i - 1});
            //cout << -(i - last) << ' ' << last << ' ' << i - 1 << endl;
            left[i] = last;
            right[last] = i - 1;
            last = i;
        }
    }
    s.insert({-(n - 1 - last + 1), last, n - 1});

    //cout << -(n - 1 - last + 1) << ' ' << last << ' ' << n - 1 << endl;
    //cout << endl;

    left[n - 1] = last;
    right[last] = n - 1;

    int ans = 0;
    while (s.size())
    {
        ans++;

        int l = (*s.begin())[1], r = (*s.begin())[2];
        s.erase(s.begin());

        //cout << l << ' ' << r << endl;

        int prev_seg = l - 1;
        int next_seg = r + 1;

        unite(l, r, l, r);

        if (prev_seg < 0 || next_seg >= n)
            continue;

        prev_seg = get(prev_seg);
        next_seg = get(next_seg);

        int l1 = root[prev_seg].ff, r1 = root[next_seg].ss;

        int l0 = l;

        int final_l = l, final_r = r;

        if (l1 != -1)
        {
            unite(prev_seg, l, l1, r);
            l0 = l1;
            final_l = l1;
        }
        if (r1 != -1)
        {
            unite(next_seg, l, l0, r1);
            final_r = r1;
        }

        l1 = final_l;
        r1 = final_r;

        l1--;
        r1++;

        //cout << l1 << ' ' << r1 << endl;

        //cout << endl << endl;

        if (l1 < 0 || r1 >= n)
            continue;

        if (a[l1] == a[r1])
        {
            //cout << -(l1 - left[l1] + 1) << ' ' << left[l1] << ' ' <<  l1 << endl;
            //cout << -(right[r1] - r1 + 1) << ' ' << r1 << ' ' << right[r1] << endl;
            //cout << -(right[r1] - left[l1] - (r1 - l1 - 1) + 1) << ' ' << left[l1] << ' ' << right[r1] << endl;

            //cout << left[l1] << ' ' << right[r1] << endl;

            s.erase(s.find({-(l1 - left[l1] + 1), left[l1], l1}));
            s.erase(s.find({-(right[r1] - r1 + 1), r1, right[r1]}));
            s.insert({-(right[r1] - left[l1] + 1), left[l1], right[r1]});

            left[right[r1]] = left[l1];
            right[left[l1]] = right[r1];
        }
    }

    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define pii pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, x) for(int i = 0; i < x; i++)
#define rforn(i, x) for(int i = x - 1; i >= 0; i--)
#define printp(x) for(int i = 0; i < (x).size(); i++) cout << (x)[i] + 1 << " "; cout << endl;
#define print(x) for(int i = 0; i < (x).size(); i++) cout << (x)[i] << " "; cout << endl;

using namespace std;

vector<int> p, ranks;
vector<pii> root;

int get(int a)
{
    if (p[a] == a)
        return a;
    return p[a] = get(p[a]);
}

void unite(int a, int b, int l, int r)
{
    a = get(a);
    b = get(b);
    if (a != b)
    {
        if (ranks[a] > ranks[b])
            swap(a, b);
        p[a] = b;
        root[b] = {l, r};
        if (ranks[a] == ranks[b])
            ranks[b]++;
    }
}

signed main()
{
    //freopen("test.txt", "r", stdin);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);

    forn (i, n)
        cin >> a[i];

    p.resize(n);
    ranks.resize(n);
    root.resize(n);
    forn (i, n)
    {
        root[i] = {-1, -1};
        p[i] = i;
        ranks[i] = 1;
    }

    set<vector<int> > s;

    vector<int> left(n), right(n);

    int last = 0;
    forn (i, n)
    {
        if (a[i] != a[last])
        {
            s.insert({-(i - last), last, i - 1});
            //cout << -(i - last) << ' ' << last << ' ' << i - 1 << endl;
            left[i - 1] = last;
            right[last] = i - 1;
            last = i;
        }
    }
    s.insert({-(n - 1 - last + 1), last, n - 1});

    //cout << -(n - 1 - last + 1) << ' ' << last << ' ' << n - 1 << endl;
    //cout << endl;

    left[n - 1] = last;
    right[last] = n - 1;

    int ans = 0;
    while (s.size())
    {
        ans++;

        int l = (*s.begin())[1], r = (*s.begin())[2];
        s.erase(s.begin());

        //cout << l << ' ' << r << endl;

        int prev_seg = l - 1;
        int next_seg = r + 1;

        unite(l, r, l, r);

        if (prev_seg < 0 || next_seg >= n)
            continue;

        prev_seg = get(prev_seg);
        next_seg = get(next_seg);

        int l1 = root[prev_seg].ff, r1 = root[next_seg].ss;

        int l0 = l;

        int final_l = l, final_r = r;

        if (l1 != -1)
        {
            unite(prev_seg, l, l1, r);
            l0 = l1;
            final_l = l1;
        }
        if (r1 != -1)
        {
            unite(next_seg, l, l0, r1);
            final_r = r1;
        }

        l1 = final_l;
        r1 = final_r;

        l1--;
        r1++;

        //cout << l1 << ' ' << r1 << endl;

        //cout << endl << endl;

        if (l1 < 0 || r1 >= n)
            continue;

        if (a[l1] == a[r1])
        {
            //cout << -(l1 - left[l1] + 1) << ' ' << left[l1] << ' ' <<  l1 << endl;
            //cout << -(right[r1] - r1 + 1) << ' ' << r1 << ' ' << right[r1] << endl;
            //cout << -(right[r1] - left[l1] - (r1 - l1 - 1) + 1) << ' ' << left[l1] << ' ' << right[r1] << endl;

            //cout << left[l1] << ' ' << right[r1] << endl;

            s.erase({-(l1 - left[l1] + 1), left[l1], l1});
            s.erase({-(right[r1] - r1 + 1), r1, right[r1]});
            s.insert({-(right[r1] - left[l1] + 1), left[l1], right[r1]});

            left[right[r1]] = left[l1];
            right[left[l1]] = right[r1];
        }
    }

    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define pii pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, x) for(int i = 0; i < x; i++)
#define rforn(i, x) for(int i = x - 1; i >= 0; i--)
#define printp(x) for(int i = 0; i < (x).size(); i++) cout << (x)[i] + 1 << " "; cout << endl;
#define print(x) for(int i = 0; i < (x).size(); i++) cout << (x)[i] << " "; cout << endl;

using namespace std;

vector<int> p, ranks;
vector<pii> root;

int get(int a)
{
    if (p[a] == a)
        return a;
    return p[a] = get(p[a]);
}

void unite(int a, int b, int l, int r)
{
    a = get(a);
    b = get(b);
    if (a != b)
    {
        if (ranks[a] > ranks[b])
            swap(a, b);
        p[a] = b;
        root[b] = {l, r};
        if (ranks[a] == ranks[b])
            ranks[b]++;
    }
}

signed main()
{
    //freopen("test.txt", "r", stdin);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);

    forn (i, n)
        cin >> a[i];

    p.resize(n);
    ranks.resize(n);
    root.resize(n);
    forn (i, n)
    {
        root[i] = {-1, -1};
        p[i] = i;
        ranks[i] = 1;
    }

    set<vector<int> > s;

    vector<int> left(n), right(n);

    int last = 0;
    forn (i, n)
    {
        if (a[i] != a[last])
        {
            s.insert({-(i - last), last, i - 1});
            //cout << -(i - last) << ' ' << last << ' ' << i - 1 << endl;
            left[i] = last;
            right[last] = i - 1;
            last = i;
        }
    }
    s.insert({-(n - 1 - last + 1), last, n - 1});

    //cout << -(n - 1 - last + 1) << ' ' << last << ' ' << n - 1 << endl;
    //cout << endl;

    left[n - 1] = last;
    right[last] = n - 1;

    int ans = 0;
    while (s.size())
    {
        ans++;

        int l = (*s.begin())[1], r = (*s.begin())[2];
        s.erase(s.begin());

        //cout << l << ' ' << r << endl;

        int prev_seg = l - 1;
        int next_seg = r + 1;

        unite(l, r, l, r);

        if (prev_seg < 0 || next_seg >= n)
            continue;

        prev_seg = get(prev_seg);
        next_seg = get(next_seg);

        int l1 = root[prev_seg].ff, r1 = root[next_seg].ss;

        int l0 = l;

        int final_l = l, final_r = r;

        if (l1 != -1)
        {
            unite(prev_seg, l, l1, r);
            l0 = l1;
            final_l = l1;
        }
        if (r1 != -1)
        {
            unite(next_seg, l, l0, r1);
            final_r = r1;
        }

        l1 = final_l;
        r1 = final_r;

        l1--;
        r1++;

        //cout << l1 << ' ' << r1 << endl;

        //cout << endl << endl;

        if (l1 < 0 || r1 >= n)
            continue;

        if (a[l1] == a[r1])
        {
            //cout << -(l1 - left[l1] + 1) << ' ' << left[l1] << ' ' <<  l1 << endl;
            //cout << -(right[r1] - r1 + 1) << ' ' << r1 << ' ' << right[r1] << endl;
            //cout << -(right[r1] - left[l1] - (r1 - l1 - 1) + 1) << ' ' << left[l1] << ' ' << right[r1] << endl;

            //cout << left[l1] << ' ' << right[r1] << endl;

            s.erase({-(l1 - left[l1] + 1), left[l1], l1});
            s.erase({-(right[r1] - r1 + 1), r1, right[r1]});
            s.insert({-(right[r1] - left[l1] + 1), left[l1], right[r1]});

            left[right[r1]] = left[l1];
            right[left[l1]] = right[r1];
        }
    }

    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define int long long
#define pii pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, x) for(int i = 0; i < x; i++)
#define rforn(i, x) for(int i = x - 1; i >= 0; i--)
#define printp(x) for(int i = 0; i < (x).size(); i++) cout << (x)[i] + 1 << " "; cout << endl;
#define print(x) for(int i = 0; i < (x).size(); i++) cout << (x)[i] << " "; cout << endl;

using namespace std;

signed main()
{
    //freopen("test.txt", "r", stdin);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);
    forn (i, n)
        cin >> a[i];

    set<pii> s1, s2;

    int last = 0;
    forn (i, n)
    {
        if (a[i] == a[last])
            continue;
        else
        {
            s2.insert(pii(last, i - last));
            s1.insert(pii(last - i, last));
            last = i;
        }
    }
    s2.insert(pii(last, n - last));
    s1.insert(pii(last - n, last));

    int ans = 0;
    while (sz(s1))
    {
        ans++;
        pii v = *s1.begin();
        s1.erase(s1.begin());

        s2.erase(pii(v.ss, -v.ff));

        auto it1 = s2.lower_bound(pii(v.ss, -100));
        if (it1 == s2.begin() || it1 == s2.end())
            continue;

        auto it2 = it1;
        it2--;

        pii v2 = *it1, v1 = *it2;

        if (a[v2.ff] == a[v1.ff])
        {
            s2.erase(v1);
            s2.erase(v2);
            s1.erase(pii(-v1.ss, v1.ff));
            s1.erase(pii(-v2.ss, v2.ff));

            s1.insert(pii(-(v1.ss + v2.ss), v1.ff));
            s2.insert(pii(v1.ff, v1.ss + v2.ss));
        }
    }

    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define pii pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, x) for(int i = 0; i < x; i++)
#define rforn(i, x) for(int i = x - 1; i >= 0; i--)
#define printp(x) for(int i = 0; i < (x).size(); i++) cout << (x)[i] + 1 << " "; cout << endl;
#define print(x) for(int i = 0; i < (x).size(); i++) cout << (x)[i] << " "; cout << endl;

using namespace std;

vector<int> p, ranks;
vector<pii> root;

int get(int a)
{
    if (p[a] == a)
        return a;
    return p[a] = get(p[a]);
}

void unite(int a, int b, int l, int r)
{
    a = get(a);
    b = get(b);
    if (a != b)
    {
        if (ranks[a] > ranks[b])
            swap(a, b);
        p[a] = b;
        root[b] = {l, r};
        if (ranks[a] == ranks[b])
            ranks[b]++;
    }
}

signed main()
{
    //freopen("test.txt", "r", stdin);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);

    forn (i, n)
        cin >> a[i];

    p.resize(n);
    ranks.resize(n);
    root.resize(n);
    forn (i, n)
    {
        root[i] = {-1, -1};
        p[i] = i;
        ranks[i] = 1;
    }

    set<vector<int> > s;

    vector<int> left(n), right(n);

    int last = 0;
    forn (i, n)
    {
        if (a[i] != a[last])
        {
            s.insert({-(i - last), last, i - 1});
            //cout << -(i - last) << ' ' << last << ' ' << i - 1 << endl;
            left[i - 1] = last;
            right[last] = i - 1;
            last = i;
        }
    }
    s.insert({-(n - 1 - last + 1), last, n - 1});

    //cout << -(n - 1 - last + 1) << ' ' << last << ' ' << n - 1 << endl;
    //cout << endl;

    left[n - 1] = last;
    right[last] = n - 1;

    int ans = 0;
    while (s.size())
    {
        ans++;

        int l = (*s.begin())[1], r = (*s.begin())[2];
        s.erase(s.begin());

        //cout << l << ' ' << r << endl;

        int prev_seg = l - 1;
        int next_seg = r + 1;

        unite(l, r, l, r);

        if (prev_seg < 0 || next_seg >= n)
            continue;

        int l0 = l;
        int final_l = l, final_r = r;

        if (prev_seg >= 0)
        {
            prev_seg = get(prev_seg);

            int l1 = root[prev_seg].ff;

            if (l1 != -1)
            {
                unite(prev_seg, l, l1, r);
                l0 = l1;
                final_l = l1;
            }
        }

        if (next_seg < n)
        {
            next_seg = get(next_seg);

            int r1 = root[next_seg].ss;
            if (r1 != -1)
            {
                unite(next_seg, l, l0, r1);
                final_r = r1;
            }
        }

        int l1 = final_l;
        int r1 = final_r;

        l1--;
        r1++;

        //cout << l1 << ' ' << r1 << endl;

        //cout << endl << endl;

        if (l1 < 0 || r1 >= n)
            continue;

        if (a[l1] == a[r1])
        {
            //cout << -(l1 - left[l1] + 1) << ' ' << left[l1] << ' ' <<  l1 << endl;
            //cout << -(right[r1] - r1 + 1) << ' ' << r1 << ' ' << right[r1] << endl;
            //cout << -(right[r1] - left[l1] - (r1 - l1 - 1) + 1) << ' ' << left[l1] << ' ' << right[r1] << endl;

            //cout << left[l1] << ' ' << right[r1] << endl;

            s.erase({-(l1 - left[l1] + 1), left[l1], l1});
            s.erase({-(right[r1] - r1 + 1), r1, right[r1]});
            s.insert({-(right[r1] - left[l1] - (r1 - l1 - 1) + 1), left[l1], right[r1]});

            left[right[r1]] = left[l1];
            right[left[l1]] = right[r1];
        }
    }

    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
#define clr(a) memset(a,0,sizeof(a))
#define ll long long
#define INF 10000
#define endl '\n'
//#pragma  warning(disable: 4996)
using namespace std;
const int N = 2e5+7;
typedef  pair<int, int>pii;
int dx[] = { 1,0,-1,0,1,1,-1,-1 };
int dy[] = { 0,1,0,-1,1,-1,1,-1 };
ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll powm(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b % 2)res *= a;
        a *= a;
        b /= 2;

    }
    return res;
}
int main()
{
    // freopen("chief.in", "r", stdin);
     // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector<int>v(n);
    for (auto& i : v)cin >> i;
    ll cnt = 0;
    for (int i = 1; i < n; i++) {
        if (v[i - 1] != v[i])
            cnt++;
    }
    if (v[0] == v.back())
        cout << cnt;
    else
        cout << cnt + 1;
   // cout << endl;
  //  system("pause");
    return 0;
}


#include<bits/stdc++.h>
#define clr(a) memset(a,0,sizeof(a))
#define ll long long
#define INF 10000
#define endl '\n'
//#pragma  warning(disable: 4996)
using namespace std;
const int N = 2e5+7;
typedef  pair<int, int>pii;
int dx[] = { 1,0,-1,0,1,1,-1,-1 };
int dy[] = { 0,1,0,-1,1,-1,1,-1 };
ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll powm(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b % 2)res *= a;
        a *= a;
        b /= 2;

    }
    return res;
}
int main()
{
    // freopen("chief.in", "r", stdin);
     // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector<int>v(n);
    for (auto& i : v)cin >> i;
    ll cnt = 1;
    for (int i = 1; i < n; i++) {
        if (v[i - 1] != v[i])
            cnt++;
    }
    if (v[0] == v.back())
        cout << cnt-1;
    else
        cout << cnt;

    return 0;
}


#include<bits/stdc++.h>
#define clr(a) memset(a,0,sizeof(a))
#define ll long long
#define INF 900000009
#define endl '\n'
//#pragma  warning(disable: 4996)
using namespace std;
const int N = 2e3+ 7;
typedef  pair<int, int>pii;
int dx[] = { 1,0,-1,0,1,1,-1,-1 };
int dy[] = { 0,1,0,-1,1,-1,1,-1 };
ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll powm(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b % 2)res *= a;
        a *= a;
        b /= 2;

    }
    return res;
}

int main()
{
    // freopen("chief.in", "r", stdin);
     // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0); cout.tie(0);
    set<int> st[200010];
	int n;
	int a[200010];

		//write; read;
	cin >> n;
	for (int i = 0; i < n;i++)cin>>a[i];
		multiset<int> mst;
		int k = 0;
		set<pair<int, pii> > S;

		for (int i = 0; i < n; i++) {
			int cnt = 0;
			int j = i;
			while (j < n && a[j] == a[i])
				cnt++, j++;
			st[cnt].insert(k);
			mst.insert(cnt);
			S.insert(make_pair(k, make_pair(cnt, a[i])));

			i = j - 1;
			k++;
		}
		int res = 0;
		while (S.size() > 0) {
			res++;
			int c = *mst.rbegin();
			int k = *st[c].begin();
			st[c].erase(k);
			mst.erase(mst.find(c));
			set<pair<int, pii> >::iterator it = S.lower_bound(make_pair(k, make_pair(0, 0)));
			set<pair<int, pii> >::iterator it1 = it, it2 = it;
			it2++;
			if (it == S.begin() || it2 == S.end()) {
				S.erase(it);
				continue;
			}
			it1--;
			if (it1->second.second == it2->second.second) {
				pair<int, pii> p = make_pair(it1->first, make_pair(it1->second.first + it2->second.first, it1->second.second));
				st[it1->second.first].erase(it1->first);
				st[it2->second.first].erase(it2->first);
				mst.erase(mst.find(it1->second.first));
				mst.erase(mst.find(it2->second.first));
				S.erase(it1);
				S.erase(it2);
				S.erase(it);
				S.insert(p);
				mst.insert(p.second.first);
				st[p.second.first].insert(p.first);
			}
			else {
				S.erase(it);
			}
		}
		cout << res;

    return 0;
}


#include<bits/stdc++.h>
#define clr(a) memset(a,0,sizeof(a))
#define ll long long
#define INF 10000
#define endl '\n'
//#pragma  warning(disable: 4996)
using namespace std;
const int N = 2e5+7;
typedef  pair<int, int>pii;
int dx[] = { 1,0,-1,0,1,1,-1,-1 };
int dy[] = { 0,1,0,-1,1,-1,1,-1 };
ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll powm(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b % 2)res *= a;
        a *= a;
        b /= 2;

    }
    return res;
}
int main()
{
    // freopen("chief.in", "r", stdin);
     // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector<int>v(n);
    for (auto& i : v)cin >> i;
    ll cnt = 0;
    for (int i = 1; i < n; i++) {
        if (v[i - 1] != v[i])
            cnt++;
    }
    if (v[0] == v.back() && cnt == 0)
        cout <<"1";
    else if (v[0] == v.back())
        cout <<cnt;
    else
        cout << cnt+1;

    return 0;
}


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

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

struct event
{
    int sz, l, r;
    bool operator < (const event& o) const
    {
        if(sz == o.sz) return l < o.l;
        return sz > o.sz;
    }
};

const int N = 2e5 + 10;
int a[N];
set<event> st;
int lft[N], rgh[N];
int x[N], y[N];

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

    int n; cin >> n;

    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        lft[i] = i - 1;
        rgh[i] = i + 1;
    }
    rgh[n] = 0;

    x[1] = 1;
    for(int i = 2; i <= n; i++)
        if(a[i] == a[i - 1]) x[i] = x[i - 1];
        else x[i] = i;

    y[n] = n;
    for(int i = n - 1; i > 0; i--)
        if(a[i] == a[i + 1]) y[i] = y[i + 1];
        else y[i] = i;

    for(int i = 1; i <= n; i++)
        st.insert({y[i] - x[i] + 1, x[i], y[i]});

    int ans = 0;
    while(!empty(st))
    {
        auto [sz, l, r] = *st.begin();
        st.erase(*st.begin());

        // cout << sz << " " << l << " " << r << ": " << a[l] << endl;

        ans++;

        if(lft[l] && rgh[r] && a[lft[l]] == a[rgh[r]])
        {
            int i, j;
            i = x[lft[l]];
            j = y[rgh[r]];
            st.erase({j - rgh[r] + 1, rgh[r], j});
            st.erase({lft[l] - i + 1, i, lft[l]});
            st.insert({j - i + 1, i, j});
            x[j] = i;
            y[i] = j;
        }

        if(rgh[r]) lft[rgh[r]] = lft[l];
        if(lft[l]) rgh[lft[l]] = rgh[r];
    }

    cout << ans << endl;

    return 0;
}


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

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

struct event
{
    int sz, l, r;
    bool operator < (const event& o) const
    {
        if(sz == o.sz) return l < o.l;
        return sz > o.sz;
    }
};

const int N = 2e5 + 10;
int a[N];
set<event> st;
int lft[N], rgh[N];
int x[N], y[N];

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

    int n; cin >> n;

    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        lft[i] = i - 1;
        rgh[i] = i + 1;
    }
    rgh[n] = 0;

    x[1] = 1;
    for(int i = 2; i <= n; i++)
        if(a[i] == a[i - 1]) x[i] = x[i - 1];
        else x[i] = i;

    y[n] = n;
    for(int i = n - 1; i > 0; i--)
        if(a[i] == a[i + 1]) y[i] = y[i + 1];
        else y[i] = i;

    for(int i = 1; i <= n; i++)
        st.insert({y[i] - x[i] + 1, x[i], y[i]});

    int ans = 0;
    while(!empty(st))
    {
        auto [sz, l, r] = *st.begin();
        st.erase(*st.begin());

        cerr << sz << " " << l << " " << r << ": " << a[l] << endl;

        if(lft[l] && rgh[r] && a[lft[l]] == a[rgh[r]])
        {
            int i, j;
            i = x[lft[l]];
            j = y[rgh[r]];
            assert(x[rgh[r]] == rgh[r]);
            assert(y[lft[l]] == lft[l]);
            st.erase({j - rgh[r] + 1, rgh[r], j});
            st.erase({lft[l] - i + 1, i, lft[l]});
            st.insert({j - i + 1, i, j});
            x[j] = i;
            y[i] = j;
        }

        if(rgh[r]) lft[rgh[r]] = lft[l];
        if(lft[l]) rgh[lft[l]] = rgh[r];

        lft[l] = rgh[r] = 0;

        ans++;
    }

    cout << ans << endl;

    return 0;
}


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

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

struct event
{
    int sz, l, r;
    bool operator < (const event& o) const
    {
        if(sz == o.sz) return l < o.l;
        return sz > o.sz;
    }
};

const int N = 2e5 + 10;
int a[N];
set<event> st;
int lft[N], rgh[N];
int x[N], y[N];

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

    int n; cin >> n;

    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        lft[i] = i - 1;
        rgh[i] = i + 1;
    }
    rgh[n] = 0;

    x[1] = 1;
    for(int i = 2; i <= n; i++)
        if(a[i] == a[i - 1]) x[i] = x[i - 1];
        else x[i] = i;

    y[n] = n;
    for(int i = n - 1; i > 0; i--)
        if(a[i] == a[i + 1]) y[i] = y[i + 1];
        else y[i] = i;

    for(int i = 1; i <= n; i++)
        st.insert({y[i] - x[i] + 1, x[i], y[i]});

    int ans = 0;
    while(!empty(st))
    {
        auto [sz, l, r] = *st.begin();
        st.erase(*st.begin());

        cerr << sz << " " << l << " " << r << ": " << a[l] << endl;

        ans++;

        if(lft[l] && rgh[r] && a[lft[l]] == a[rgh[r]])
        {
            int i, j;
            i = x[lft[l]];
            j = y[rgh[r]];
            st.erase({j - rgh[r] + 1, rgh[r], j});
            st.erase({lft[l] - i + 1, i, lft[l]});
            st.insert({j - i + 1, i, j});
            x[j] = i;
            y[i] = j;
        }

        if(rgh[r]) lft[rgh[r]] = lft[l];
        if(lft[l]) rgh[lft[l]] = rgh[r];

        lft[l] = rgh[r] = 0;
    }

    cout << ans << endl;

    return 0;
}


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

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

struct dsu
{
    vector<int> p, sz;
    int n;
    dsu(){}
    dsu(int t)
    {
        n = t;
        sz.assign(n, 1);
        p.resize(n);
        for(int i = 0; i < n; i++) p[i] = i;
    }
    int find(int i)
    {
        return (p[i] == i ? i : p[i] = find(p[i]));
    }
    bool same(int i, int j)
    {
        return find(i) == find(j);
    }
    bool merge(int i, int j)
    {
        if(!same(i, j))
        {
            i = find(i);
            j = find(j);
            if(sz[i] > sz[j])
                swap(i, j);
            p[i] = j;
            sz[j] += sz[i];
            return true;
        }
        return false;
    }
};

struct event
{
    int sz, l, r;
    bool operator < (const event& o) const
    {
        if(sz == o.sz) return l < o.l;
        return sz > o.sz;
    }
};

const int N = 2e5 + 10;
int a[N];
set<event> st;
int lft[N], rgh[N];
int x[N], y[N];

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

    int n; cin >> n;
    dsu uf(n + 1);

    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        lft[i] = i - 1;
        rgh[i] = i + 1;
    }
    rgh[n] = 0;

    x[1] = 1;
    for(int i = 2; i <= n; i++)
        if(a[i] == a[i - 1]) x[i] = x[i - 1], uf.merge(i, i - 1);
        else x[i] = i;

    y[n] = n;
    for(int i = n - 1; i > 0; i--)
        if(a[i] == a[i + 1]) y[i] = y[i + 1];
        else y[i] = i;

    for(int i = 1; i <= n; i++)
        st.insert({y[i] - x[i] + 1, x[i], y[i]});

    int ans = 0;
    while(!empty(st))
    {
        auto [sz, l, r] = *st.begin();
        st.erase(*st.begin());

        // cerr << sz << " " << l << " " << r << ": " << a[l] << endl;

        if(lft[l] && rgh[r] && a[lft[l]] == a[rgh[r]])
        {
            int i, j;
            i = x[lft[l]];
            j = y[rgh[r]];
            int s1 = uf.sz[uf.find(lft[l])];
            int s2 = uf.sz[uf.find(rgh[r])];
            st.erase({s1, i, lft[l]});
            st.erase({s2, rgh[r], j});
            st.insert({s1 + s2, i, j});
            uf.merge(lft[l], rgh[r]);
            x[j] = i;
            y[i] = j;
        }

        if(rgh[r]) lft[rgh[r]] = lft[l];
        if(lft[l]) rgh[lft[l]] = rgh[r];

        lft[l] = rgh[r] = 0;

        ans++;
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
#define N 200005
#define M 2000
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N

using namespace std;
int ar[N],n;
set< int  > s;
set< pair< int , int > > q;
map< int , int > ma;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    int cur = ar[0]; int len = 1;
    for(int i=1;i<n;i++){
        if(ar[i]==cur)len++;
        else{
            s.insert(i-1);
            q.insert({-len,i-1});
            cur = ar[i];
            ma[i-1] = -len;
            len = 1;

        }
    }
    s.insert(n-1); q.insert({-len,n-1});
    ma[n-1] = -len;
    int ans = 0;
    while(!q.empty()){
        ans++;
        set< pair< int , int > > :: iterator it = q.begin();
        int in = it->second;
        int len =it->first;
      //  cout<<in<<" "<<len<<"\n";
        set< int > :: iterator it1 = s.find(in),it2,it3;
        it2 = it1; it2++;
        if(it1==s.begin()||it2==s.end()){
            s.erase(it1);
            q.erase(q.begin());
            ma[in] = 0;
            continue;
        }
        it3 = it1; it3--;
        if(ar[*it2]==ar[*it3]){
            int bef = ma[*it2];
            ma[*it2] += ma[*it3];
            int jn = *it3;
            q.erase({ma[jn],jn});
            q.erase({bef,*it2});
            q.insert({ma[*it2],*it2});
            s.erase(jn);
            s.erase(in);
            q.erase(q.begin());
            ma[in] = 0;
            ma[jn] = 0;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
#define N 200005
#define M 2000
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N

using namespace std;
int ar[N],n;
set< int  > s;
set< pair< int , int > > q;
map< int , int > ma;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    int cur = ar[0]; int len = 1;
    for(int i=1;i<n;i++){
        if(ar[i]==cur)len++;
        else{
            s.insert(i-1);
            q.insert({-len,i-1});
            cur = ar[i];
            ma[i-1] = -len;
            len = 1;

        }
    }
    s.insert(n-1); q.insert({-len,n-1});
    ma[n-1] = -len;
    int ans = 0;
    while(!q.empty()){
        ans++;
        set< pair< int , int > > :: iterator it = q.begin();
        int in = it->second;
        int len =it->first;
      //  cout<<in<<" "<<len<<"\n";
        set< int > :: iterator it1 = s.find(in),it2,it3;
        if(it1==s.end()){
            cout<<in<<" yolo "<<sz(s);
            return 0;
        }
        it2 = it1; it2++;
        if(it1==s.begin()||it2==s.end()){
            s.erase(it1);
            q.erase(q.begin());
            ma[in] = 0;
            continue;
        }
        it3 = it1; it3--;
        if(ar[*it2]==ar[*it3]){
            int bef = ma[*it2];
            ma[*it2] += ma[*it3];
            int jn = *it3;
            q.erase({ma[jn],jn});
            q.erase({bef,*it2});
            q.insert({ma[*it2],*it2});
            s.erase(jn);
            s.erase(in);
            q.erase(q.begin());
            ma[in] = 0;
            ma[jn] = 0;
        }
        else{
            s.erase(in);
            q.erase(q.begin());
            ma[in] = 0;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
#define N 200005
#define M 2000
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N

using namespace std;
int ar[N],n;
set< int  > s;
set< pair< int , int > > q;
map< int , int > ma;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    int cur = ar[0]; int len = 1;
    for(int i=1;i<n;i++){
        if(ar[i]==cur)len++;
        else{
            s.insert(i-1);
            q.insert({-len,i-1});
            cur = ar[i];
            len = 1;
            ma[i-1] = -len;
        }
    }
    s.insert(n-1); q.insert({-len,n-1});
    ma[n-1] = -len;
    int ans = 0;
    while(!q.empty()){
        ans++;
        set< pair< int , int > > :: iterator it = q.begin();
        int in = it->second;
        int len =it->first;
      //  cout<<in<<" "<<len<<"\n";
        set< int > :: iterator it1 = s.find(in),it2,it3;
        it2 = it1; it2++;
        if(it1==s.begin()||it2==s.end()){
            s.erase(it1);
            q.erase(q.begin());
            ma[in] = 0;
            continue;
        }
        it3 = it1; it3--;
        if(ar[*it2]==ar[*it3]){
            int bef = ma[*it2];
            ma[*it2] += ma[*it3];
            int jn = *it3;
            q.erase({ma[jn],jn});
            q.erase({bef,*it2});
            q.insert({ma[*it2],*it2});
            s.erase(jn);
            s.erase(in);
            q.erase(q.begin());
            ma[in] = 0;
            ma[jn] = 0;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
#define N 200005
#define M 2000
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N

using namespace std;
int ar[N],n;
set< int  > s;
set< pair< int , int > > q;
map< int , int > ma;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    int cur = ar[0]; int len = 1;
    for(int i=1;i<n;i++){
        if(ar[i]==cur)len++;
        else{
            s.insert(i-1);
            q.insert({-len,i-1});
            cur = ar[i];
            ma[i-1] = -len;
            len = 1;

        }
    }
    s.insert(n-1); q.insert({-len,n-1});
    ma[n-1] = -len;
    int ans = 0;
    while(!q.empty()){
        ans++;
        set< pair< int , int > > :: iterator it = q.begin();
        int in = it->second;
        int len =it->first;
      //  cout<<in<<" "<<len<<"\n";
        set< int > :: iterator it1 = s.find(in),it2,it3;
        if(it1==s.end()){
            cout<<" yolo";
            return 0;
        }
        it2 = it1; it2++;
        if(it1==s.begin()||it2==s.end()){
            s.erase(in);
            q.erase(q.begin());
            ma[in] = 0;
            continue;
        }
        it3 = it1; it3--;
        if(ar[*it2]==ar[*it3]){
            int bef = ma[*it2];
            ma[*it2] += ma[*it3];
            int jn = *it3;
            q.erase(q.begin());
            q.erase({ma[jn],jn});
            q.erase({bef,*it2});
            q.insert({ma[*it2],*it2});
            s.erase(jn);
            s.erase(in);

            ma[in] = 0;
            ma[jn] = 0;
        }
        else{
            s.erase(in);
            q.erase(q.begin());
            ma[in] = 0;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
#define N 200005
#define M 2000
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N

using namespace std;
int ar[N],n;
set< int  > s;
set< pair< int , int > > q;
map< int , int > ma;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    int cur = ar[0]; int len = 1;
    for(int i=1;i<n;i++){
        if(ar[i]==cur)len++;
        else{
            s.insert(i-1);
            q.insert({-len,i-1});
            cur = ar[i];
            len = 1;
            ma[i-1] = -len;
        }
    }
    s.insert(n-1); q.insert({-len,n-1});
    ma[n-1] = -len;
    int ans = 0;
    while(!q.empty()){
        ans++;
        set< pair< int , int > > :: iterator it = q.begin();
        int in = it->second;
        int len =it->first;
      //  cout<<in<<" "<<len<<"\n";
        set< int > :: iterator it1 = s.find(in),it2,it3;
        it2 = it1; it2++;
        if(it1==s.begin()||it2==s.end()){
            s.erase(it1);
            q.erase(q.begin());
            ma[in] = 0;
            continue;
        }
        it3 = it1; it3--;
        if(ar[*it2]==ar[*it3]){
            int bef = ma[*it2];
            ma[*it2] += ma[*it3];
            int jn = *it3;
            q.erase({ma[jn],jn});
            q.erase({bef,*it2});
            q.insert({ma[*it2],*it2});
            s.erase(jn);
            s.erase(in);
            q.erase(q.begin());
            ma[in] = 0;
            ma[jn] = 0;
        }
        else{
            s.erase(in);
            q.erase(q.begin());
            ma[in] = 0;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
#define N 200005
#define M 2000
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N

using namespace std;
int ar[N],n;
set< int  > s;
set< pair< int , int > > q;
map< int , int > ma;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    int cur = ar[0]; int len = 1;
    for(int i=1;i<n;i++){
        if(ar[i]==cur)len++;
        else{
            s.insert(i-1);
            q.insert({-len,i-1});
            cur = ar[i];
            ma[i-1] = -len;
            len = 1;

        }
    }
    s.insert(n-1); q.insert({-len,n-1});
    ma[n-1] = -len;
    int ans = 0;
    while(!q.empty()){
        ans++;
        set< pair< int , int > > :: iterator it = q.begin();
        int in = it->second;
        int len =it->first;
      //  cout<<in<<" "<<len<<"\n";
        set< int > :: iterator it1 = s.find(in),it2,it3;
        if(it1==s.end()){
            cout<<" yolo";
            return 0;
        }
        it2 = it1; it2++;
        if(it1==s.begin()||it2==s.end()){
            s.erase(it1);
            q.erase(q.begin());
            ma[in] = 0;
            continue;
        }
        it3 = it1; it3--;
        if(ar[*it2]==ar[*it3]){
            int bef = ma[*it2];
            ma[*it2] += ma[*it3];
            int jn = *it3;
            q.erase({ma[jn],jn});
            q.erase({bef,*it2});
            q.insert({ma[*it2],*it2});
            s.erase(jn);
            s.erase(in);
            q.erase(q.begin());
            ma[in] = 0;
            ma[jn] = 0;
        }
        else{
            s.erase(in);
            q.erase(q.begin());
            ma[in] = 0;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
#define N 200005
#define M 2000
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N

using namespace std;
int ar[N],n;
set< int  > s;
set< pair< int , int > > q;
map< int , int > ma;
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    int cur = ar[0]; int len = 1;
    for(int i=1;i<n;i++){
        if(ar[i]==cur)len++;
        else{
            s.insert(i-1);
            q.insert({-len,i-1});
            cur = ar[i];
            ma[i-1] = -len;
            len = 1;

        }
    }
    s.insert(n-1); q.insert({-len,n-1});
    ma[n-1] = -len;
    int ans = 0;
    while(!q.empty()){
        ans++;
        set< pair< int , int > > :: iterator it = q.begin();
        int in = it->second;
        int len =it->first;
      //  cout<<in<<" "<<len<<"\n";
        set< int > :: iterator it1 = s.find(in),it2,it3;
        it2 = it1; it2++;
        if(it1==s.begin()||it2==s.end()){
            s.erase(it1);
            q.erase(q.begin());
            ma[in] = 0;
            continue;
        }
        it3 = it1; it3--;
        if(ar[*it2]==ar[*it3]){
            int bef = ma[*it2];
            ma[*it2] += ma[*it3];
            int jn = *it3;
            q.erase({ma[jn],jn});
            q.erase({bef,*it2});
            q.insert({ma[*it2],*it2});
            s.erase(jn);
            s.erase(in);
            q.erase(q.begin());
            ma[in] = 0;
            ma[jn] = 0;
        }
        else{
            s.erase(in);
            q.erase(q.begin());
            ma[in] = 0;
        }
    }
    cout<<ans;
}


//899E
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+5;
struct node
{
	int x,y,id;
}st[4*N];
vector<pair<int,int> >vp;
int a[N];
int stmn[4*N],stmx[4*N];

void build(int node, int L, int R)
{
    if(L==R)
    {
        st[node].x=vp[L-1].ff;
        st[node].y=vp[L-1].ss;
        st[node].id=L;
        return;
    }
    int M=(L+R)/2;
    build(node*2, L, M);
    build(node*2+1, M+1, R);
    if(st[node*2].x>=st[2*node+1].x)
    {
    	st[node].x=st[2*node].x;
    	st[node].y=st[2*node].y;
    	st[node].id=st[2*node].id;
    }
    else
    {
    	st[node].x=st[2*node+1].x;
    	st[node].y=st[2*node+1].y;
    	st[node].id=st[2*node+1].id;
    }
}
void update(int node, int L, int R, int pos, int val,int flag)
{
    if(L==R)
    {
    	if(flag)
    	{
    		st[node].x+=val;
    	}
    	else
    	{
	        st[node].x=0;
	        st[node].y=0;
	        st[node].id=0;
	    }
        return;
    }
    int M=(L+R)/2;
    if(pos<=M)
        update(node*2, L, M, pos, val,flag);
    else
        update(node*2 + 1, M+1, R, pos, val,flag);
   	if(st[node*2].x>=st[2*node+1].x)
    {
    	st[node].x=st[2*node].x;
    	st[node].y=st[2*node].y;
    	st[node].id=st[2*node].id;
    }
    else
    {
    	st[node].x=st[2*node+1].x;
    	st[node].y=st[2*node+1].y;
    	st[node].id=st[2*node+1].id;
    }
}
void buildmx(int node, int L, int R)
{
    if(L==R)
    {
        stmx[node]=L;
        stmn[node]=L;
        return;
    }
    int M=(L+R)/2;
    buildmx(node*2, L, M);
    buildmx(node*2+1, M+1, R);
    stmx[node]=max(stmx[2*node],stmx[2*node+1]);
    stmn[node]=min(stmn[2*node],stmn[2*node+1]);
}
void update_mn(int node, int L, int R, int pos, int val)
{
    if(L==R)
    {
        stmn[node]=val;
        return;
    }
    int M=(L+R)/2;
    if(pos<=M)
        update_mn(node*2, L, M, pos, val);
    else
        update_mn(node*2 + 1, M+1, R, pos, val);
    stmn[node]=min(stmn[node*2], stmn[node*2 + 1]);
}
void update_mx(int node, int L, int R, int pos, int val)
{
    if(L==R)
    {
        stmx[node]=val;
        return;
    }
    int M=(L+R)/2;
    if(pos<=M)
        update_mx(node*2, L, M, pos, val);
    else
        update_mx(node*2 + 1, M+1, R, pos, val);
    stmx[node]=max(stmx[node*2], stmx[node*2 + 1]);
}

int query_mn(int node, int L, int R, int i, int j)
{
    if(j<L || i>R)
        return 1e9;
    if(i<=L && R<=j)
        return stmn[node];
    int M=(L+R)/2;
    int left=query_mn(node*2, L, M, i, j);
    int right=query_mn(node*2 + 1, M+1, R, i, j);
    return min(left, right);
}
int query_mx(int node, int L, int R, int i, int j)
{
    if(j<L || i>R)
        return 0;
    if(i<=L && R<=j)
        return stmx[node];
    int M=(L+R)/2;
    int left=query_mx(node*2, L, M, i, j);
    int right=query_mx(node*2 + 1, M+1, R, i, j);
    return max(left, right);
}
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
    	int k=i;
    	int cnt=0;
    	while(a[i]==a[k]&&k<=n)
    	{
    		cnt++;
    		k++;
    	}
    	vp.pb({cnt,a[i]});
    	i=k-1;
    }
    n=vp.size();

    build(1,1,n);
    buildmx(1,1,n);
    int cnt=0;
    while(st[1].x>0)
    {
    	int ind=st[1].id;
    	int left=query_mx(1,1,n,1,ind-1);
    	int right=query_mn(1,1,n,ind+1,n);
    	//	cout<<ind<<" "<<" "<<left<<" "<<right<<endl;
    	//return 0;
	    	if(left>=1&&right<=n&&vp[left-1].ss==vp[right-1].ss&&vp[right-1].ss>0)
	    	{
	    		update_mn(1,1,n,right,1e9);
	    		update_mx(1,1,n,right,0);
	    		update_mx(1,1,n,ind,0);
	    		update_mn(1,1,n,ind,1e9);
	    		update(1,1,n,ind,0,0);
	    		update(1,1,n,right,0,0);
	    		update(1,1,n,left,vp[right-1].ff,1);
	    		vp[left-1].ff+=vp[right-1].ff;
	    		vp[right-1].ff=0;
	    		vp[ind-1].ff=0;
	    		vp[right-1].ss=0;
	    		vp[ind-1].ss=0;
	    	}
	    	else
	    	{
	    		update(1,1,n,ind,0,0);
	    		update_mx(1,1,n,ind,0);
	    		update_mn(1,1,n,ind,1e9);
	    		vp[ind-1].ff=0;
	    		vp[ind-1].ss=0;
	    	}
	    	cnt++;

    }
    cout<<cnt<<endl;

}


//899E
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+5;
struct node
{
	int x,y,id;
}st[4*N];
vector<pair<int,int> >vp;
int a[N];
int stmn[4*N],stmx[4*N];

void build(int node, int L, int R)
{
    if(L==R)
    {
        st[node].x=vp[L-1].ff;
        st[node].y=vp[L-1].ss;
        st[node].id=L;
        return;
    }
    int M=(L+R)/2;
    build(node*2, L, M);
    build(node*2+1, M+1, R);
    if(st[node*2].x>=st[2*node+1].x)
    {
    	st[node].x=st[2*node].x;
    	st[node].y=st[2*node].y;
    	st[node].id=st[2*node].id;
    }
    else
    {
    	st[node].x=st[2*node+1].x;
    	st[node].y=st[2*node+1].y;
    	st[node].id=st[2*node+1].id;
    }
}
void update(int node, int L, int R, int pos, int val,int flag)
{
    if(L==R)
    {
    	if(flag)
    	{
    		st[node].x+=val;
    	}
    	else
    	{
	        st[node].x=0;
	        st[node].y=0;
	        st[node].id=0;
	    }
        return;
    }
    int M=(L+R)/2;
    if(pos<=M)
        update(node*2, L, M, pos, val,flag);
    else
        update(node*2 + 1, M+1, R, pos, val,flag);
   	if(st[node*2].x>=st[2*node+1].x)
    {
    	st[node].x=st[2*node].x;
    	st[node].y=st[2*node].y;
    	st[node].id=st[2*node].id;
    }
    else
    {
    	st[node].x=st[2*node+1].x;
    	st[node].y=st[2*node+1].y;
    	st[node].id=st[2*node+1].id;
    }
}
void buildmx(int node, int L, int R)
{
    if(L==R)
    {
        stmx[node]=L;
        stmn[node]=L;
        return;
    }
    int M=(L+R)/2;
    buildmx(node*2, L, M);
    buildmx(node*2+1, M+1, R);
    stmx[node]=max(stmx[2*node],stmx[2*node+1]);
    stmn[node]=max(stmn[2*node],stmn[2*node+1]);
}
void update_mn(int node, int L, int R, int pos, int val)
{
    if(L==R)
    {
        stmn[node]=val;
        return;
    }
    int M=(L+R)/2;
    if(pos<=M)
        update_mn(node*2, L, M, pos, val);
    else
        update_mn(node*2 + 1, M+1, R, pos, val);
    stmn[node]=min(stmn[node*2], stmn[node*2 + 1]);
}
void update_mx(int node, int L, int R, int pos, int val)
{
    if(L==R)
    {
        stmx[node]=val;
        return;
    }
    int M=(L+R)/2;
    if(pos<=M)
        update_mx(node*2, L, M, pos, val);
    else
        update_mx(node*2 + 1, M+1, R, pos, val);
    stmx[node]=max(stmx[node*2], stmx[node*2 + 1]);
}

int query_mn(int node, int L, int R, int i, int j)
{
    if(j<L || i>R)
        return 1e9;
    if(i<=L && R<=j)
        return stmn[node];
    int M=(L+R)/2;
    int left=query_mn(node*2, L, M, i, j);
    int right=query_mn(node*2 + 1, M+1, R, i, j);
    return min(left, right);
}
int query_mx(int node, int L, int R, int i, int j)
{
    if(j<L || i>R)
        return 0;
    if(i<=L && R<=j)
        return stmx[node];
    int M=(L+R)/2;
    int left=query_mx(node*2, L, M, i, j);
    int right=query_mx(node*2 + 1, M+1, R, i, j);
    return max(left, right);
}
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
    	int k=i;
    	int cnt=0;
    	while(a[i]==a[k]&&k<=n)
    	{
    		cnt++;
    		k++;
    	}
    	vp.pb({cnt,a[i]});
    	i=k-1;
    }
    n=vp.size();
    if(n==1)
    {
    	cout<<1<<endl;
    	return 0;
    }
    build(1,1,n);
    buildmx(1,1,n);
    int cnt=0;
    while(st[1].x>0)
    {
    	int ind=st[1].id;
    	int left=query_mx(1,1,n,1,ind-1);
    	int right=query_mn(1,1,n,ind+1,n);
    	//cout<<ind<<" "<<" "<<left<<" "<<right<<endl;
    	//return 0;
	    	if(left>=1&&right<=n&&vp[left-1].ss==vp[right-1].ss)
	    	{
	    		update_mn(1,1,n,right,0);
	    		update(1,1,n,ind,0,0);
	    		update(1,1,n,right,0,0);
	    		update(1,1,n,left,vp[right-1].ff,1);
	    		vp[left-1].ff+=vp[right-1].ff;
	    		vp[right-1].ff=0;
	    	}
	    	else
	    	{
	    		update(1,1,n,ind,0,0);
	    		vp[ind-1].ff=0;
	    	}
	    	cnt++;

    }
    cout<<cnt<<endl;

}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
int n,head[1005],cnt;
char s[100];
vector<int>v;
struct Node
{
	int nxt,to;
}Edges[5005];
void addedge(int u,int v)
{
	Edges[++cnt].nxt=head[u];
	head[u]=cnt;
	Edges[cnt].to=v;
}
void dfs(int u,int f,int d)
{
	if(d==0){v.push_back(u);return;}
	for(int i=head[u];~i;i=Edges[i].nxt)
	{
		int v=Edges[i].to;
		if(v!=f)dfs(v,u,d-1);
	}
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		memset(head,-1,sizeof(head));
		cnt=0;
		for(int i=1;i<n;i++)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			addedge(u,v),addedge(v,u);
		}
		printf("? %d ",n);
		for(int i=1;i<=n;i++)printf("%d ",i);
		puts(""),fflush(stdout);
		int x0,d0,x,d;
		scanf("%d%d",&x0,&d0);
		int l=d0/2,r=d0,ans1=x0;
		while(l<=r)
		{
			v.clear();
			int mid=(l+r)>>1;
			dfs(x0,0,mid);
			if(v.size()==0){r=mid-1;continue;}
			printf("? %d ",v.size());
			for(int i=0;i<v.size();i++)printf("%d ",v[i]);
			puts(""),fflush(stdout);
			scanf("%d%d",&x,&d);
			if(d==d0)ans1=x,l=mid+1;
			else r=mid-1;
		}
		v.clear();
		dfs(ans1,0,d0);
		printf("? %d ",v.size());
		for(int i=0;i<v.size();i++)printf("%d ",v[i]);
		puts(""),fflush(stdout);
		scanf("%d%d",&x,&d);
		printf("! %d %d\n",ans1,x);
		cin>>s;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
int n,head[1005],cnt;
char s[100];
vector<int>v;
struct Node
{
	int nxt,to;
}Edges[5005];
void addedge(int u,int v)
{
	Edges[++cnt].nxt=head[u];
	head[u]=cnt;
	Edges[cnt].to=v;
}
void dfs(int u,int f,int d)
{
	if(d==0){v.push_back(u);return;}
	for(int i=head[u];~i;i=Edges[i].nxt)
	{
		int v=Edges[i].to;
		if(v!=f)dfs(v,u,d-1);
	}
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		memset(head,-1,sizeof(head));
		cnt=0;
		for(int i=1;i<n;i++)
		{
			int u,v;
			scanf("%d%d",&u,&v);
			addedge(u,v),addedge(v,u);
		}
		printf("? %d ",n);
		for(int i=1;i<=n;i++)printf("%d ",i);
		puts(""),fflush(stdout);
		int x0,d0,x,d;
		scanf("%d%d",&x0,&d0);
		int l=1,r=d0,ans1=x0;
		while(l<=r)
		{
			v.clear();
			int mid=(l+r)>>1;
			dfs(x0,0,mid);
			if(v.size()==0){r=mid-1;continue;}
			printf("? %d ",v.size());
			for(int i=0;i<v.size();i++)printf("%d ",v[i]);
			puts(""),fflush(stdout);
			scanf("%d%d",&x,&d);
			if(d==d0)ans1=x,l=mid+1;
			else r=mid-1;
		}
		v.clear();
		dfs(ans1,0,d0);
		printf("? %d ",v.size());
		for(int i=0;i<v.size();i++)printf("%d ",v[i]);
		puts(""),fflush(stdout);
		scanf("%d%d",&x,&d);
		printf("! %d %d\n",ans1,x);
		cin>>s;
	}
	return 0;
}


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

#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()

using ll = long long;
using ld = long double;

vector<vector<ll>> adj;

pair<ll ,ll> query(vector<ll> in) {
	if (in.empty()) for (ll x = 0; x < sz(adj); x++) in.push_back(x);
	cout << "? " << sz(in);
	for (ll x : in) cout << " " << x+1;
	cout << endl;
	ll x, d;
	cin >> x >> d;
	x--;
	if (x < 0) exit(0);
	return {x, d};
}

void solve(ll x, ll y) {
	cout << "! " << x+1 << " " << y+1 << endl;
	string res;
	cin >> res;
	if (res == "Incorrect") exit(0);
}

vector<ll> todo;

void findDist(ll c, ll gd, ll p = -1, ll cd = 0) {
	if (cd == gd) {
		todo.push_back(c);
	} else if (cd < gd) {
		for (ll x : adj[c]) {
			if (x == p) continue;
			findDist(x, gd, c, cd + 1);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	ll t;
	cin >> t;
	for (ll i = 0; i < t; i++) {
		ll n;
		cin >> n;
		adj.assign(n, {});
		for (ll j = 1; j < n; j++) {
			ll a, b;
			cin >> a >> b;
			a--;
			b--;
			adj[a].push_back(b);
			adj[b].push_back(a);
		}
		if (n == 2) {
			solve(0, 1);
			continue;
		}
		auto mid = query({});
		auto border = mid;
		ll l = max(0ll, mid.second/2-1);
		ll r = mid.second + 1;
		while (l + 1 < r) {
			ll m = (l + r) / 2;
			todo.clear();
			findDist(mid.first, m);

			if (todo.empty()) {
				r = m;
			} else {
				auto ans = query(todo);
				if (ans.second != mid.second) {
					r = m;
				} else {
					border = ans;
					l = m;
				}
			}
		}
		ll firstAns = border.first;
		todo.clear();
		findDist(firstAns, mid.second);
		auto other = query(todo);
		solve(firstAns, other.first);
	}
}


#include <bits/stdc++.h>
#define inf 10000000
#define pb push_back
using namespace std;
ifstream f("shiftright.in");
ofstream g("shiftright.out");
vector<int> tree[1005];
vector<int> depth[1005];
int node,dist;
void dfs(int node,int dad,int v)
{
    depth[v].pb(node);
    for(int i=0;i<tree[node].size();i++)
    {
        if(tree[node][i]!=dad)
        {
            dfs(tree[node][i],dad,v+1);
        }
    }
}
int query(vector<int> v)
{
    cout<<'?'<<" "<<v.size()<<" ";
    for(int i=0;i<v.size();i++) cout<<v[i]<<" ";
    cout.flush();
    cout<<'\n';
    int node1,dist1;
    cin>>node1>>dist1;
    return dist1;
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            int x,y;
            cin>>x>>y;
            tree[x].pb(y);
            tree[y].pb(x);
        }
        cout<<'?'<<" ";
        for(int i=1;i<=n;i++) cout<<i<<" ";
        cout<<'\n';
        cout.flush();
        cin>>node>>dist;
        dfs(node,0,0);
        int st=0,dr=(dist+1)/2;
        int rasp=0;
        while(st<=dr)
        {
            int mij=(st+dr)/2;
            vector<int> v;
            for(int j=mij;j<=(dist+1)/2;j++)
            {
                for(int d=0;d<depth[j].size();d++)
                {
                    v.pb(depth[j][d]);
                }
            }
            if(query(v)==dist)
            {
                rasp=mij;
                st=mij+1;
            }
            else dr=mij-1;

        }
        int rasp2=dist-rasp,node1,node2,dist2;
        cout<<'?'<<" ";
        cout<<depth[rasp].size()<<" ";
        for(int i=0;i<depth[rasp].size();i++)
        {
            cout<<depth[rasp][i]<<" ";
        }
        cout.flush();
        cout<<'\n';
        cin>>node1>>dist2;
         cout<<'?'<<" ";
        cout<<depth[rasp2].size()<<" ";
        for(int i=0;i<depth[rasp2].size();i++)
        {
            cout<<depth[rasp2][i]<<" ";
        }
        cout.flush();
        cout<<'\n';
        cin>>node2>>dist2;
        cout<<node1<<" "<<node2<<'\n';
        cout.flush();
        string s;
        cin>>s;

    }

}


#include <bits/stdc++.h>
#define inf 10000000
#define pb push_back
using namespace std;
ifstream f("shiftright.in");
ofstream g("shiftright.out");
vector<int> tree[1005];
vector<int> depth[1005];
int node,dist;
void dfs(int node,int dad,int v)
{
    depth[v].pb(node);
    for(int i=0;i<tree[node].size();i++)
    {
        if(tree[node][i]!=dad)
        {
            dfs(tree[node][i],dad,v+1);
        }
    }
}
int query(vector<int> v)
{
    cout<<'?'<<" "<<v.size()<<" ";
    for(int i=0;i<v.size();i++) cout<<v[i]<<" ";
    cout.flush();
    cout<<'\n';
    int node1,dist1;
    cin>>node1>>dist1;
    return dist1;
}
int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        for(int i=1;i<n;i++)
        {
            int x,y;
            cin>>x>>y;
            tree[x].pb(y);
            tree[y].pb(x);
        }
        cout<<'?'<<" ";
        for(int i=1;i<=n;i++) cout<<i<<" ";
        cout<<'\n';
        cout.flush();
        cin>>node>>dist;
        dfs(node,0,0);
        int st=0,dr=(dist+1)/2;
        int rasp=0;
        while(st<=dr)
        {
            int mij=(st+dr)/2;
            vector<int> v;
            for(int j=mij;j<=(dist+1)/2;j++)
            {
                for(int d=0;d<depth[j].size();d++)
                {
                    v.pb(depth[j][d]);
                }
            }
            if(query(v)==dist)
            {
                rasp=mij;
                st=mij+1;
            }
            else dr=mij-1;

        }
        int rasp2=dist-rasp,node1,node2,dist2;
        cout<<'?'<<" ";
        cout<<depth[rasp].size()<<" ";
        for(int i=0;i<depth[rasp].size();i++)
        {
            cout<<depth[rasp][i]<<" ";
        }
        cout.flush();
        cout<<'\n';
        cin>>node1>>dist2;
         cout<<'?'<<" ";
        cout<<depth[rasp2].size()<<" ";
        for(int i=0;i<depth[rasp2].size();i++)
        {
            cout<<depth[rasp2][i]<<" ";
        }
        cout.flush();
        cout<<'\n';
        cin>>node2>>dist2;
        cout<<node1<<" "<<node2<<'\n';
        cout.flush();
        string s;
        cin>>s;

    }

}


#include <cctype>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define pll pair<long long, long long>
#define P pair<int, int>
#define PP pair<P, P>
#define eps 1e-10
#define PI acos(-1)
#define It set<node>::iterator
using namespace std;
const int maxn=1e3+10;
vector<int> G[maxn];
int Max,dis[maxn],f[maxn];
char buf[maxn];
void dfs(int u, int fa) {
	f[u]=fa;
	Max=max(Max,dis[u]);
	for (int i=0; i<G[u].size(); i++) {
		int v=G[u][i];
		if (v==fa) continue;
		dis[v]=dis[u]+1;
		dfs(v,u);
	}
}
vector<int> g;
void solve(int u, int m) {
	if (dis[u]==m) {
		g.push_back(u);
		return;
	}
	for (int i=0; i<G[u].size(); i++) {
		int v=G[u][i];
		if (v==f[u]) continue;
		solve(v,m);
	}
}
void dfs1(int u, int fa, int val, int d) {
	if (val==d) {
		g.push_back(u);
		return;
	}
	for (int i=0; i<G[u].size(); i++) {
		int v=G[u][i];
		if (v==fa) continue;
		dfs1(v,u,val+1,d);
	}
}
int main() {
	int t;
	scanf("%d",&t);
	while (t--) {
		int n;
		scanf("%d",&n);
		for (int i=1; i<=n; i++) G[i].clear();
		memset(dis,0,sizeof(dis));
		memset(f,0,sizeof(f));
		for (int i=1; i<n; i++) {
			int u,v;
			scanf("%d%d",&u,&v);
			G[u].push_back(v);
			G[v].push_back(u);
		}
		printf("? %d ",n);
		for (int i=1; i<=n; i++) printf("%d ",i);
		printf("\n");
		fflush(stdout);
		int root,val;
		scanf("%d%d",&root,&val);
		Max=0;
		dfs(root,0);
		int L=1,R=Max;
		int idx=root,idx2;
		bool ok=false;
		while (L<=R) {
			int m=L+(R-L+1)/2;
			g.clear();
			solve(idx,m);
			if (g.empty()) R=m-1;
			else {
				printf("? %d ",g.size());
				for (int i=0; i<g.size(); i++) {
					printf("%d ",g[i]);
				}
				printf("\n");
				fflush(stdout);
				int node,len;
				scanf("%d %d",&node,&len);
				if (len==val&&val==dis[node]) {
					ok=true;
					idx=root,idx2=node;
					break;
				}
				if (len>val) R=m-1;
				else idx=node,L=m+1;
			}
		}
		g.clear();
		if (!ok) {
			dfs1(idx,0,0,val);
			if (g.size()>=2) {
				printf("? %d ",g.size());
				for (int i=0; i<g.size(); i++) {
					printf("%d ",g[i]);
				}
				printf("\n");
				fflush(stdout);
				scanf("%d%d",&idx2,&val);
			} else idx2=g[0];
		}
		printf("! %d %d\n",idx,idx2);
		fflush(stdout);
		scanf("%s",buf);
	}
    return 0;
}


#include <cctype>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define pll pair<long long, long long>
#define P pair<int, int>
#define PP pair<P, P>
#define eps 1e-10
#define PI acos(-1)
#define It set<node>::iterator
using namespace std;
const int maxn=1e3+10;
vector<int> G[maxn];
int Max,dis[maxn],f[maxn];
char buf[maxn];
void dfs(int u, int fa) {
	f[u]=fa;
	Max=max(Max,dis[u]);
	for (int i=0; i<G[u].size(); i++) {
		int v=G[u][i];
		if (v==fa) continue;
		dis[v]=dis[u]+1;
		dfs(v,u);
	}
}
vector<int> g;
void solve(int u, int m) {
	if (dis[u]==m) {
		g.push_back(u);
		return;
	}
	for (int i=0; i<G[u].size(); i++) {
		int v=G[u][i];
		if (v==f[u]) continue;
		solve(v,m);
	}
}
void dfs1(int u, int fa, int val, int d) {
	if (val==d) {
		g.push_back(u);
		return;
	}
	for (int i=0; i<G[u].size(); i++) {
		int v=G[u][i];
		if (v==fa) continue;
		dfs1(v,u,val+1,d);
	}
}
int main() {
	int t;
	scanf("%d",&t);
	while (t--) {
		int n;
		scanf("%d",&n);
		for (int i=1; i<=n; i++) G[i].clear();
		memset(dis,0,sizeof(dis));
		memset(f,0,sizeof(f));
		for (int i=1; i<n; i++) {
			int u,v;
			scanf("%d%d",&u,&v);
			G[u].push_back(v);
			G[v].push_back(u);
		}
		printf("? %d ",n);
		for (int i=1; i<=n; i++) printf("%d ",i);
		printf("\n");
		fflush(stdout);
		int root,val;
		scanf("%d%d",&root,&val);
		dis[root]=0;
		Max=0;
		dfs(root,0);
		int L=1,R=Max;
		int idx=root;
		while (L<=R) {
			int m=L+(R-L+1)/2;
			g.clear();
			solve(idx,m);
			if (g.empty()) R=m-1;
			else {
				printf("? %d ",g.size());
				for (int i=0; i<g.size(); i++) {
					printf("%d ",g[i]);
				}
				printf("\n");
				fflush(stdout);
				int node,len;
				scanf("%d %d",&node,&len);
				if (len>val) R=m-1;
				else idx=node,L=m+1;
			}
		}
		g.clear();
		int idx2;
		if (g.size()>=2) {
			dfs1(idx,0,0,val);
			printf("? %d ",g.size());
			for (int i=0; i<g.size(); i++) {
				printf("%d ",g[i]);
			}
			printf("\n");
			fflush(stdout);
			scanf("%d%d",&idx2,&val);
		} else idx2=g[0];
		printf("! %d %d\n",idx,idx2);
		fflush(stdout);
		scanf("%s",buf);
	}
    return 0;
}


#include <cctype>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define pll pair<long long, long long>
#define P pair<int, int>
#define PP pair<P, P>
#define eps 1e-10
#define PI acos(-1)
#define It set<node>::iterator
using namespace std;
const int maxn=1e3+10;
vector<int> G[maxn];
int dep[maxn];
char buf[maxn];
void dfs(int u, int fa) {
	for (int i=0; i<G[u].size(); i++) {
		int v=G[u][i];
		if (v==fa) continue;
		dep[v]=dep[u]+1;
		dfs(v,u);
	}
}
vector<int> g;
void dfs1(int u, int fa, int val, int d) {
	if (val==d) {
		g.push_back(u);
		return;
	}
	for (int i=0; i<G[u].size(); i++) {
		int v=G[u][i];
		if (v==fa) continue;
		dfs1(v,u,val+1,d);
	}
}
int main() {
	int t;
	scanf("%d",&t);
	while (t--) {
		int n;
		scanf("%d",&n);
		for (int i=0; i<maxn; i++) G[i].clear();
		for (int i=1; i<n; i++) {
			int u,v;
			scanf("%d%d",&u,&v);
			G[u].push_back(v);
			G[v].push_back(u);
		}
		printf("? %d ",n);
		for (int i=1; i<=n; i++) printf("%d ",i);
		printf("\n");
		fflush(stdout);
		int root,val;
		scanf("%d%d",&root,&val);
		dep[root]=0;
		dfs(root,0);
		int L=0,R=(val+1)/2;
		int idx=root;
		while (L<=R) {
			int m=L+(R-L+1)/2;
			g.clear();
			for (int i=1; i<=n; i++) if (dep[i]==m) g.push_back(i);
			if (g.empty()) R=m-1;
			else {
				printf("? %d ",g.size());
				for (int i=0; i<g.size(); i++) {
					printf("%d ",g[i]);
				}
				printf("\n");
				fflush(stdout);
				int node,len;
				scanf("%d %d",&node,&len);
				if (len>val) R=m-1;
				else idx=node,L=m+1;
			}
		}
		g.clear();
		dfs1(idx,0,0,val);
		printf("? %d ",g.size());
		for (int i=0; i<g.size(); i++) {
			printf("%d ",g[i]);
		}
		printf("\n");
		fflush(stdout);
		int idx2;
		scanf("%d%d",&idx2,&val);
		printf("! %d %d\n",idx,idx2);
		fflush(stdout);
		scanf("%s",buf);
	}
    return 0;
}