module main;

import core.stdc.stdio;

int main()
{
	int n;
	scanf("%d", &n);
	int [] a = new int[n];
	int [] b = new int [n];
	int k = 1, id = 0;
	a[0]=-1;
	for(int i = 1; i <= n; i ++)
	{
		scanf("%d", &a[i]);
		if(a[i] == a[i - 1])
			k ++;
		else
		{
		    if(i != 1) {
			id ++;
			b[id] = k;
			k = 1;
			}
		}
	}
	id ++;
	b[id] = k;
	k = 1;
	int t = 0;
	for(int i = 2; i <= id; i ++)
	{
		if(b[i] != b[i - 1])
			t = 1;
	}
	if(t == 1)
		printf("NO");
	else
		printf("YES");
	return 0;
}