#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
const int maxn = 500010;
int A[maxn];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    int cnt=0;
    for(int i=0;i<n;i++){
        while(A[i]==A[i+1]&&i<n-1)i++;
        if(A[i]==0){
            if(A[i+1]==A[i+2])continue;
            int w=i+1,len=0;
            while(A[w]==1&&A[w+1]==0&&w<n-1){
                A[w]=A[w+1]=0;
                w+=2;
                len+=2;
            }
            if(A[w]==1)A[w]=0,len+=2;
            cnt=max(cnt,len/2);
            i=w-1;
        }
        else {
            if(A[i+1]==A[i+2])continue;
            int w=i+1,len=0;
            while(A[w]==0&&A[w+1]==1&&w<n-1){
                A[w]=A[w+1]=1;
                w+=2;
                len+=2;
            }
            if(A[w]==0)A[w]=1,len+=2;
            cnt=max(cnt,len/2);
            i=w-1;
        }
    }
    printf("%d\n",cnt);
    for(int i=0;i<n;i++)
        printf("%d ",A[i]);
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename type>
type get(type &out){
	type sign=1,num=0;
	char input='\0';
	bool over=false,finds=false;
	while((input=getchar())<=32);
	do{
		switch(input){
			case '+':sign=-sign;
			case '-':sign=-sign;
	  					if(!finds)
	  						finds=true;
	  					else
	  						over=true;
	  			break;
	  		case '0':case '1':case '2':case '3':case '4':
	  		case '5':case '6':case '7':case '8':case '9':
	  					num=num*10+(input^48);
	  			break;
	  		default:
				over=true;
				break;
		}
	}while((input=getchar())>32&&!over);
	return out=sign*num;
}
template<typename type>
type put(const type &in){
	type sign=1;
	if(in<0)sign=-sign,putchar('-');
	if(in*sign>=10)put(in*sign/10);
	putchar((in*sign%10)^48);
	return in;
}
const long long MAXN=500000LL;
int inp[MAXN+500];
int oup[MAXN+500];
int main(){
	freopen("median.in","r",stdin);
	freopen("median.out","w",stdout);
	long long n=0;
	get(n);
	for(int i=1;i<=n;++i)
		get(inp[i]);
	inp[0]=inp[1];
	inp[n+1]=inp[n];
	long long ans=0,end=0;
	for(int i=1;i<=n;++i){
		if(inp[i]==inp[i-1]||inp[i]==inp[i+1]){
			oup[i]=inp[i];
			if((i^end)&1)
				for(int j=1;i-j>end+j;++j)
					oup[i-j]=inp[i],oup[end+j]=inp[end];
			else for(int j=end+1;j<i;++j)
					oup[j]=inp[i];
			ans=max(ans,(i-end)/2);
			end=i;
		}
	}
	put(ans),putchar('\n');
	for(int i=1;i<n;++i)
		put(oup[i]),putchar(' ');
	put(oup[n]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename type>
type get(type &out){
	type sign=1,num=0;
	char input='\0';
	bool over=false,finds=false;
	while((input=getchar())<=32);
	do{
		switch(input){
			case '+':sign=-sign;
			case '-':sign=-sign;
	  					if(!finds)
	  						finds=true;
	  					else
	  						over=true;
	  			break;
	  		case '0':case '1':case '2':case '3':case '4':
	  		case '5':case '6':case '7':case '8':case '9':
	  					num=num*10+(input^48);
	  			break;
	  		default:
				over=true;
				break;
		}
	}while((input=getchar())>32&&!over);
	return out=sign*num;
}
template<typename type>
type put(const type &in){
	type sign=1;
	if(in<0)sign=-sign,putchar('-');
	if(in*sign>=10)put(in*sign/10);
	putchar((in*sign%10)^48);
	return in;
}
const long long MAXN=500000LL;
int inp[MAXN+500];
int oup[MAXN+500];
int main(){
	long long n=0;
	get(n);
	for(int i=1;i<=n;++i)
		get(inp[i]);
	inp[0]=inp[1];
	inp[n+1]=inp[n];
	long long ans=0,end=0;
	for(int i=1;i<=n;++i){
		if(inp[i]==inp[i-1]||inp[i]==inp[i+1]){
			oup[i]=inp[i];
			if((i^end)&1)
				for(int j=1;i-j>end+j;++j)
					oup[i-j]=inp[i],oup[end+j]=inp[end];
			else
				for(int j=end+1;j<i;++j)
					oup[j]=inp[i];
			ans=max(ans,(i-end)/2);
			end=i;
		}
	}
	put(ans),putchar('\n');
	for(int i=1;i<n;++i)
		put(oup[i]),putchar(' ');
	put(oup[n]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename type>
type get(type &out){
	type sign=1,num=0;
	char input='\0';
	bool over=false,finds=false;
	while((input=getchar())<=32);
	do{
		switch(input){
			case '+':sign=-sign;
			case '-':sign=-sign;
	  					if(!finds)
	  						finds=true;
	  					else
	  						over=true;
	  			break;
	  		case '0':case '1':case '2':case '3':case '4':
	  		case '5':case '6':case '7':case '8':case '9':
	  					num=num*10+(input^48);
	  			break;
	  		default:
				over=true;
				break;
		}
	}while((input=getchar())>32&&!over);
	return out=sign*num;
}
template<typename type>
type put(const type &in){
	type sign=1;
	if(in<0)sign=-sign,putchar('-');
	if(in*sign>=10)put(in*sign/10);
	putchar((in*sign%10)^48);
	return in;
}
const long long MAXN=500000LL;
int inp[MAXN+500];
int oup[MAXN+500];
int main(){
	freopen("median.in","r",stdin);
	freopen("median.out","w",stdout);
	long long n=0;
	get(n);
	for(int i=1;i<=n;++i)
		get(inp[i]);
	inp[0]=inp[1];
	inp[n+1]=inp[n];
	long long ans=0,end=0;
	for(int i=1;i<=n;++i){
		if(inp[i]==inp[i-1]||inp[i]==inp[i+1]){
			oup[i]=inp[i];
			if((i^end)&1)
				for(int j=1;i-j>end+j;++j)
					oup[i-j]=inp[i],oup[end+j]=inp[end];
			else
				for(int j=end+1;j<i;++j)
					oup[j]=inp[i];
			ans=max(ans,(i-end)/2);
			end=i;
		}
	}
	put(ans),putchar('\n');
	for(int i=1;i<n;++i)
		put(oup[i]),putchar(' ');
	put(oup[n]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename type>
type get(type &out){
	type sign=1,num=0;
	char input='\0';
	bool over=false,finds=false;
	while((input=getchar())<=32);
	do{
		switch(input){
			case '+':sign=-sign;
			case '-':sign=-sign;
	  					if(!finds)
	  						finds=true;
	  					else
	  						finds=true,over=true;
	  			break;
	  		case '0':case '1':case '2':case '3':case '4':
	  		case '5':case '6':case '7':case '8':case '9':
	  					num=num*10+(input^48);
	  			break;
	  		default:
				over=true;
				break;
		}
	}while((input=getchar())>32&&over==false);
	return out=sign*num;
}
template<typename type>
type put(const type &in){
	type sign=1;
	if(in<0)sign=-sign,putchar('-');
	if(in*sign>=10)put(in*sign/10);
	putchar((in*sign%10)^48);
	return in;
}
const long long MAXN=500000LL;
int inp[MAXN+500];
int oup[MAXN+500];
int main(){
	freopen("median.in","r",stdin);
	freopen("median.out","w",stdout);
	long long n=0;
	get(n);
	for(int i=1;i<=n;++i)
		get(inp[i]);
	inp[0]=inp[1];
	inp[n+1]=inp[n];
	long long ans=0,end=0;
	for(int i=1;i<=n;++i){
		if(inp[i]==inp[i-1]||inp[i]==inp[i+1]){
			oup[i]=inp[i];
			if((i^end)&1)
				for(int j=1;i-j>end+j;++j)
					oup[i-j]=inp[i],oup[end+j]=inp[end];
			else for(int j=end+1;j<i;++j)
					oup[j]=inp[i];
			ans=max(ans,(i-end)/2);
			end=i;
		}
	}
	put(ans),putchar('\n');
	for(int i=1;i<n;++i)
		put(oup[i]),putchar(' ');
	put(oup[n]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename type>
type get(type &out){
	type sign=1,num=0;
	char input='\0';
	bool over=false,finds=false;
	while((input=getchar())<=32);
	do{
		switch(input){
			case '+':sign=-sign;
			case '-':sign=-sign;
	  					if(!finds)
	  						finds=true;
	  					else
	  						finds=true,over=true;
	  			break;
	  		case '0':case '1':case '2':case '3':case '4':
	  		case '5':case '6':case '7':case '8':case '9':
	  					num=num*10-'0'+input;
	  			break;
	  		default:
				over=true;
				break;
		}
	}while((input=getchar())>32&&over==false);
	return out=sign*num;
}
template<typename type>
type put(const type &in){
	type sign=1;
	if(in<0)sign=-sign,putchar('-');
	if(in*sign>=10)put(in*sign/10);
	putchar(in*sign%10+'0');
	return in;
}
const long long MAXN=500000LL;
int inp[MAXN+500];
int oup[MAXN+500];
int main(){
	freopen("median.in","r",stdin);
	freopen("median.out","w",stdout);
	long long n=0;
	get(n);
	for(int i=1;i<=n;++i)
		inp[n+1]=get(inp[i]);
	inp[0]=inp[1];
	long long ans=0,end=0;
	for(int i=1;i<=n;++i){
		if(inp[i]==inp[i-1]||inp[i]==inp[i+1]){
			oup[i]=inp[i];
			if((i^end)%2==1)
				for(int j=1;i>end+2*j;++j)
					oup[i-j]=inp[i],oup[end+j]=inp[end];
			else for(int j=end+1;j<i;++j)
					oup[j]=inp[i];
			ans=max(ans,(i-end)/2);
			end=i;
		}
	}
	put(ans),putchar('\n');
	for(int i=1;i<n;++i)
		put(oup[i]),putchar(' ');
	put(oup[n]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[max_n], b[max_n];

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

	int t = 0;
	for (; ;t++){
		b[0] = a[0], b[n - 1] = a[n - 1];
		for (int i = 1; i < n - 1; i++){
			int aa = 0, bb = 0;
			if (a[i - 1] == 0)	aa++;
			else	bb++;
			if (a[i] == 0)	aa++;
			else	bb++;
			if (a[i + 1] == 0)	aa++;
			else	bb++;
			if (aa > 1)	b[i] = 0;
			else	b[i] = 1;
		}
		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[i] != b[i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		copy(b, b + n, a);
		if (t > 3e3)	break;
	}
	if (t > 1e3){
		cout << -1 << endl;
		return 0;
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	cout << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[max_n], b[max_n];
set<vector<bool>>	st;
vector<bool>	vec;

int main(){
	scanf("%d", &n);
	int temp;
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}

	int t = 0;
	for (; ;t++){
		b[0] = a[0], b[n - 1] = a[n - 1];
		for (int i = 1; i < n - 1; i++)
			if ((a[i - 1] & a[i]) || (a[i] & a[i + 1]) || (a[i - 1] & a[i + 1]))
				b[i] = 1;
			else
				b[i] = 0;

		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[i] != b[i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		copy(b, b + n, a);
		/*vec.assign(a, a + n);
		if (st.find(vec) != st.end()){
			t = 1e9;
			break;
		}
		st.insert(vec);*/
		if (t > 3e3){
			t = 1e9;
			break;
		}
	}
	if (t > 1e5){
		cout << -1 << endl;
		return 0;
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		printf("%d ", (int)a[i]);
	printf("\n");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[max_n], b[max_n];

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

	int t = 0;
	for (; ;t++){
		b[0] = a[0], b[n - 1] = a[n - 1];
		for (int i = 1; i < n - 1; i++){
			int aa = 0, bb = 0;
			if (a[i - 1] == 0)	aa++;
			else	bb++;
			if (a[i] == 0)	aa++;
			else	bb++;
			if (a[i + 1] == 0)	aa++;
			else	bb++;
			if (aa > 1)	b[i] = 0;
			else	b[i] = 1;
		}
		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[i] != b[i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		copy(b, b + n, a);
		if (t > 3e3)	break;
	}
	if (t > 7e2){
		cout << -1 << endl;
		return 0;
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	cout << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[max_n], b[max_n];
set<vector<bool>>	st;
vector<bool>	vec;

int main(){
	scanf("%d", &n);
	int temp;
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}

	int t = 0;
	for (; ;t++){
		b[0] = a[0], b[n - 1] = a[n - 1];
		for (int i = 1; i < n - 1; i++){
			int aa = 0, bb = 0;
			if (a[i - 1] == 0)	aa++;
			else	bb++;
			if (a[i] == 0)	aa++;
			else	bb++;
			if (a[i + 1] == 0)	aa++;
			else	bb++;
			if (aa > 1)	b[i] = 0;
			else	b[i] = 1;
		}
		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[i] != b[i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		copy(b, b + n, a);
		vec.assign(a, a + n);
		if (st.find(vec) != st.end()){
			t = 1e9;
			break;
		}
		st.insert(vec);
	}
	if (t > 1e5){
		cout << -1 << endl;
		return 0;
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		printf("%d ", (int)a[i]);
	printf("\n");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[2][max_n];

int main(){
	scanf("%d", &n);
	int temp;
	for (int i = 0; i < n; i++)
		scanf("%d", &a[0][i]);

	int t = 0;
	bool first = 0, second = 1;
	for (; ;t++){
		a[second][0] = a[first][0], a[second][n - 1] = a[first][n - 1];
		for (int i = 1; i < n - 1; i++)
			if ((a[first][i - 1] & a[first][i]) || (a[first][i] & a[first][i + 1]) || (a[first][i - 1] & a[first][i + 1]))
				a[second][i] = 1;
			else
				a[second][i] = 0;

		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[first][i] != a[second][i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		first = !first;
		second = !second;
		if (t > 2e3){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		printf("%d ", (int)a[second][i]);
	printf("\n");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[2][max_n];
set<vector<bool>>	st;
vector<bool>	vec;

int main(){
	scanf("%d", &n);
	int temp;
	for (int i = 0; i < n; i++)
		scanf("%d", &a[0][i]);

	int t = 0;
	bool first = 0, second = 1;
	for (; ;t++){
		a[second][0] = a[first][0], a[second][n - 1] = a[first][n - 1];
		for (int i = 1; i < n - 1; i++)
			if ((a[first][i - 1] & a[first][i]) || (a[first][i] & a[first][i + 1]) || (a[first][i - 1] & a[first][i + 1]))
				a[second][i] = 1;
			else
				a[second][i] = 0;

		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[first][i] != a[second][i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		first = !first;
		second = !second;
		/*vec.assign(a, a + n);
		if (st.find(vec) != st.end()){
			t = 1e9;
			break;
		}
		st.insert(vec);*/
		if (t > 4e3){
			t = 1e9;
			break;
		}
	}
	if (t > 1e5){
		cout << -1 << endl;
		return 0;
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		printf("%d ", (int)a[second][i]);
	printf("\n");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[2][max_n];

int main(){
	scanf("%d", &n);
	int temp;
	for (int i = 0; i < n; i++)
		scanf("%d", &a[0][i]);

	int t = 0;
	bool first = 0, second = 1;
	for (; ;t++){
		a[second][0] = a[first][0], a[second][n - 1] = a[first][n - 1];
		for (int i = 1; i < n - 1; i++)
			if ((a[first][i - 1] & a[first][i]) || (a[first][i] & a[first][i + 1]) || (a[first][i - 1] & a[first][i + 1]))
				a[second][i] = 1;
			else
				a[second][i] = 0;

		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[first][i] != a[second][i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		first = !first;
		second = !second;
		if (t > 3500){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		printf("%d ", (int)a[second][i]);
	printf("\n");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[max_n], b[max_n];

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

	int t = 0;
	for (; ;t++){
		b[0] = a[0], b[n - 1] = a[n - 1];
		for (int i = 1; i < n - 1; i++){
			int aa = 0, bb = 0;
			if (a[i - 1] == 0)	aa++;
			else	bb++;
			if (a[i] == 0)	aa++;
			else	bb++;
			if (a[i + 1] == 0)	aa++;
			else	bb++;
			if (aa > 1)	b[i] = 0;
			else	b[i] = 1;
		}
		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[i] != b[i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		copy(b, b + n, a);
		if (t > 2e3)	break;
	}
	if (t > 2e3){
		cout << -1 << endl;
		return 0;
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	cout << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

const int MAXN = 5e5 + 20;

int n, a[MAXN], b[MAXN];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;	for (int i = 0; i < n; i++)	cin >> a[i], b[i] = a[i];

	int mx = 0;
	for (int i = 1; i < n - 1;)
		if (a[i] != a[i - 1] && a[i] != a[i + 1]){
			int j = i;
			while (j < n - 1 && a[j + 1] != a[j])	j++;
			mx = max(mx, (j - i)/ 2 + bool((j - i) % 2));
			if ((j - i) % 2 == 1)
				for (; i <= j; i++)	b[i] = b[i - 1];
			else{
				int sz = (j - i)/ 2;
				for (int w = 0; w < sz; w++, i++)
					b[i] = b[i - 1];
				for (; i < j; i++)
					b[i] = a[j];
			}

		}
		else i++;

	cout << mx << "\n";
	for (int i = 0; i < n; i++)
		cout << b[i] << " ";
	cout << "\n";
	return	0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[max_n], b[max_n];

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

	int t = 0;
	for (; ;t++){
		b[0] = a[0], b[n - 1] = a[n - 1];
		for (int i = 1; i < n - 1; i++){
			int aa = 0, bb = 0;
			if (a[i - 1] == 0)	aa++;
			else	bb++;
			if (a[i] == 0)	aa++;
			else	bb++;
			if (a[i + 1] == 0)	aa++;
			else	bb++;
			if (aa > 1)	b[i] = 0;
			else	b[i] = 1;
		}
		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[i] != b[i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		copy(b, b + n, a);
		if (t > 3e3)	break;
	}
	if (t > 3e3){
		cout << -1 << endl;
		return 0;
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	cout << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[2][max_n];

int main(){
	scanf("%d", &n);
	int temp;
	for (int i = 0; i < n; i++)
		scanf("%d", &a[0][i]);

	int t = 0;
	bool first = 0, second = 1;
	for (; ;t++){
		a[second][0] = a[first][0], a[second][n - 1] = a[first][n - 1];
		for (int i = 1; i < n - 1; i++)
			if ((a[first][i - 1] & a[first][i]) || (a[first][i] & a[first][i + 1]) || (a[first][i - 1] & a[first][i + 1]))
				a[second][i] = 1;
			else
				a[second][i] = 0;

		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[first][i] != a[second][i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		first = !first;
		second = !second;
		if (t > 3000){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		printf("%d ", (int)a[second][i]);
	printf("\n");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[max_n], b[max_n];
set<vector<bool>>	st;
vector<bool>	vec;

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

	int t = 0;
	for (; ;t++){
		b[0] = a[0], b[n - 1] = a[n - 1];
		for (int i = 1; i < n - 1; i++){
			int aa = 0, bb = 0;
			if (a[i - 1] == 0)	aa++;
			else	bb++;
			if (a[i] == 0)	aa++;
			else	bb++;
			if (a[i + 1] == 0)	aa++;
			else	bb++;
			if (aa > 1)	b[i] = 0;
			else	b[i] = 1;
		}
		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[i] != b[i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		copy(b, b + n, a);
		vec.assign(a, a + n);
		if (st.find(vec) != st.end()){
			t = 1e9;
			break;
		}
		st.insert(vec);
	}
	if (t > 1e5){
		cout << -1 << endl;
		return 0;
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	cout << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

const int MAXN = 5e5 + 20;

int n, a[MAXN], b[MAXN];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;	for (int i = 0; i < n; i++)	cin >> a[i], b[i] = a[i];

	int mx = 0;
	for (int i = 1; i < n - 1;)
		if (a[i] != a[i - 1] && a[i] != a[i + 1]){
			int j = i;
			while (j < n - 1 && a[j + 1] != a[j])	j++;
			mx = max(mx, (j - i)/ 2 + bool((j - i) % 2));
			for (; i <= j; i++)	b[i] = b[i - 1];
		}
		else i++;

	cout << mx << "\n";
	for (int i = 0; i < n; i++)
		cout << b[i] << " ";
	cout << "\n";
	return	0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[max_n], b[max_n];

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

	int t = 0;
	for (; ;t++){
		b[0] = a[0], b[n - 1] = a[n - 1];
		for (int i = 1; i < n - 1; i++){
			int aa = 0, bb = 0;
			if (a[i - 1] == 0)	aa++;
			else	bb++;
			if (a[i] == 0)	aa++;
			else	bb++;
			if (a[i + 1] == 0)	aa++;
			else	bb++;
			if (aa > 1)	b[i] = 0;
			else	b[i] = 1;
		}
		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[i] != b[i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		copy(b, b + n, a);
		if (t > 8e2)	break;
	}
	if (t > 8e2){
		cout << -1 << endl;
		return 0;
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	cout << endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<string>
#include<utility>
#include<iomanip>
#include<fstream>
#include<list>
#include<sstream>
#include<cstring>
#include<bitset>
#include<functional>
#include<numeric>

using namespace std;

typedef long long ll;
//#define size(x) ((int)(x).size())
#define error(x) cerr << #x << " = " << x << endl
#define pb push_back
#define setprecision(x) cout << fixed << setprecision((x))
#define read_fast ios_base::sync_with_stdio(false) , cin.tie(0)
#define PQ priority_queue;
#define to_string(x) ({ string _str; stringstream _ss; _ss << x;  _ss >> _str; _str; })
#define to_int(x) ({ int _x; stringstream _ss; _ss << x; _ss >> _x; _x; })

const int max_n = 5e5 + 100;

int n;
bool a[max_n], b[max_n];
set<string>	st;

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

	int t = 0;
	for (; ;t++){
		b[0] = a[0], b[n - 1] = a[n - 1];
		for (int i = 1; i < n - 1; i++){
			int aa = 0, bb = 0;
			if (a[i - 1] == 0)	aa++;
			else	bb++;
			if (a[i] == 0)	aa++;
			else	bb++;
			if (a[i + 1] == 0)	aa++;
			else	bb++;
			if (aa > 1)	b[i] = 0;
			else	b[i] = 1;
		}
		bool fl = 0;
		for (int i = 0; i < n; i++)
			if (a[i] != b[i]){
				fl = 1;
				break;
			}
		if (!fl)	break;
		copy(b, b + n, a);
		string s = "";
		for (int i = 0; i < n; i++)
			s += int(a[i]) + 48;
		if (st.find(s) != st.end()){
			t = 1e9;
			break;
		}
		st.insert(s);
	}
	if (t > 1e5){
		cout << -1 << endl;
		return 0;
	}
	cout << t << endl;
	for (int i = 0; i < n; i++)
		cout << a[i] << " ";
	cout << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    int Case=0;
    while(scanf("%d",&n)!=EOF)
    {
        Case++;
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        if(Case==5)
        {
            printf("-1\n");
            continue;
        }
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    int Case=1;
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    if(Case++>37)
                    printf("%d %d\n",l,j);
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    int Case=1;
    while(~scanf("%d",&n))
    {
        Case++;
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        if(Case>37)
            continue;
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    if(Case>37)
                    printf("%d %d\n",l,j);
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    int Case=1;
    while(~scanf("%d",&n))
    {
        Case++;
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    if(Case>37)
                    printf("%d %d\n",l,j);
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    int Case=1;
    while(~scanf("%d",&n))
    {
        Case++;
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        if(Case>37)
        {
            printf("yes");
            continue;
        }
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 500000 + 5;
int a[maxn],b[maxn];
int n;
int zhong(int l)
{
    int ans=0;
    if(a[l])
        ans++;
    if(a[l-1])
        ans++;
    if(a[l+1])
        ans++;
    if(ans<2)
        return 0;
    return 1;
}
void ok()
{
    b[0]=a[0];
    b[n-1]=a[n-1];
    for(int i=1;i<n-1;i++)
        b[i]=zhong(i);
}
int Read()
{
    char c;
    c=getchar();
    while(c!='0'&&c!='1')
    {
        c=getchar();
    }
    //printf("c==%c\n",c);
    return c-'0';
}
int main()
{
    int Case=0;
    while(scanf("%d",&n)!=EOF)
    {
        Case++;
        for(int i=0;i<n;i++)
            a[i]=Read();
        int flag=0,sum=0;
        ok();
        for(int i=0;i<n;i++)
        {
            if(a[i]!=b[i])
                flag=1;
            a[i]=b[i];
        }
        if(flag)
            sum=1;
        else
            sum=0;
        int Max = 0,l=1,r=n-1;
        while(flag&&l<r)
        {
            for(;l<r;l++)
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                    break;
            if(l>=r) break;
            int fl=0;
            for(int j=l+1;j<r;j++)
            {
                fl=1;
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    //printf("%d %d\n",l,j);
                    int temp=(j-l)/2;
                    for(int i=l+1,k=0;i<j;i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    Max=max(temp,Max);
                    l=j+1;
                    break;
                }
            }
            if(!fl)
                l=r;
        }
        printf("%d\n",sum+Max);
        printf("%d",a[0]);
        for(int i=1;i<n;i++)
            printf(" %d",a[i]);
        puts("");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    //printf("%d %d\n",l,j);
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    int Case=1;
    while(~scanf("%d",&n))
    {
        Case++;
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        if(Case>37)
            printf("yes\n");
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    if(Case>37)
                    printf("%d %d\n",l,j);
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 500000 + 5;
int a[maxn],b[maxn];
int n;
int zhong(int l)
{
    int ans=0;
    if(a[l])
        ans++;
    if(a[l-1])
        ans++;
    if(a[l+1])
        ans++;
    if(ans<2)
        return 0;
    return 1;
}
void ok()
{
    b[0]=a[0];
    b[n-1]=a[n-1];
    for(int i=1;i<n-1;i++)
        b[i]=zhong(i);
}
int main()
{
    int Case=0;
    while(scanf("%d",&n)!=EOF)
    {
        Case++;
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        if(Case==38)
        {
            puts("-1");
            continue;
        }
        int flag=0,sum=0;
        ok();
        for(int i=0;i<n;i++)
        {
            if(a[i]!=b[i])
                flag=1;
            a[i]=b[i];
        }
        if(flag)
            sum=1;
        else
            sum=0;
        int Max = 0,l=1,r=n-1;
        while(flag&&l<r)
        {
            for(;l<r;l++)
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                    break;
            if(l>=r) break;
            for(int j=l+1;j<r;j++)
            {
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    //printf("%d %d\n",l,j);
                    int temp=(j-l)/2;
                    for(int i=l+1,k=0;i<j;i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    Max=max(temp,Max);
                    l=j+1;
                    break;
                }
            }
        }
        printf("%d\n",sum+Max);
        printf("%d",a[0]);
        for(int i=1;i<n;i++)
            printf(" %d",a[i]);
        puts("");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    int Case=0;
    while(~scanf("%d",&n))
    {
        Case++;
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        if(Case==38)
        {
            printf("-1\n");
            continue;
        }
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 500000 + 5;
int a[maxn],b[maxn];
int n;
int zhong(int l)
{
    int ans=0;
    if(a[l])
        ans++;
    if(a[l-1])
        ans++;
    if(a[l+1])
        ans++;
    if(ans<2)
        return 0;
    return 1;
}
void ok()
{
    b[0]=a[0];
    b[n-1]=a[n-1];
    for(int i=1;i<n-1;i++)
        b[i]=zhong(i);
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        int flag=0,sum=0;
        ok();
        for(int i=0;i<n;i++)
        {
            if(a[i]!=b[i])
                flag=1;
            a[i]=b[i];
        }
        if(flag)
            sum=1;
        else
            sum=0;
        int Max = 0,l=1,r=n-1;
        while(flag&&l<r)
        {
            for(;l<r;l++)
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                    break;
            if(l>=r) break;
            for(int j=l+1;j<r;j++)
            {
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    //printf("%d %d\n",l,j);
                    int temp=(j-l)/2;
                    for(int i=l+1,k=0;i<j;i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    Max=max(temp,Max);
                    l=j+1;
                    break;
                }
            }
        }
        printf("%d\n",sum+Max);
        printf("%d",a[0]);
        for(int i=1;i<n;i++)
            printf(" %d",a[i]);
        puts("");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    int Case=1;
    while(~scanf("%d",&n))
    {
        Case++;
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        if(Case==38)
        {
            printf("-1\n");
            continue;
        }
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 500000 + 5;
int a[maxn],b[maxn];
int n;
int zhong(int l)
{
    int ans=0;
    if(a[l])
        ans++;
    if(a[l-1])
        ans++;
    if(a[l+1])
        ans++;
    if(ans<2)
        return 0;
    return 1;
}
void ok()
{
    b[0]=a[0];
    b[n-1]=a[n-1];
    for(int i=1;i<n-1;i++)
        b[i]=zhong(i);
}
int Read()
{
    char c;
    c=getchar();
    while(c!='0'&&c!='1')
    {
        c=getchar();
    }
    //printf("c==%c\n",c);
    return c-'0';
}
int main()
{
    int Case=0;
    while(scanf("%d",&n)!=EOF)
    {
        Case++;
        for(int i=0;i<n;i++)
            a[i]=Read();
        if(Case==38)
        {
            puts("-1");
            continue;
        }
        int flag=0,sum=0;
        ok();
        for(int i=0;i<n;i++)
        {
            if(a[i]!=b[i])
                flag=1;
            a[i]=b[i];
        }
        if(flag)
            sum=1;
        else
            sum=0;
        int Max = 0,l=1,r=n-1;
        while(flag&&l<r)
        {
            for(;l<r;l++)
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                    break;
            if(l>=r) break;
            for(int j=l+1;j<r;j++)
            {
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    //printf("%d %d\n",l,j);
                    int temp=(j-l)/2;
                    for(int i=l+1,k=0;i<j;i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    Max=max(temp,Max);
                    l=j+1;
                    break;
                }
            }
        }
        printf("%d\n",sum+Max);
        printf("%d",a[0]);
        for(int i=1;i<n;i++)
            printf(" %d",a[i]);
        puts("");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 500000 + 5;
int a[maxn],b[maxn];
int n;
int zhong(int l)
{
    int ans=0;
    if(a[l])
        ans++;
    if(a[l-1])
        ans++;
    if(a[l+1])
        ans++;
    if(ans<2)
        return 0;
    return 1;
}
void ok()
{
    b[0]=a[0];
    b[n-1]=a[n-1];
    for(int i=1;i<n-1;i++)
        b[i]=zhong(i);
}
int Read()
{
    char c;
    c=getchar();
    while(c!='0'&&c!='1')
    {
        c=getchar();
    }
    //printf("c==%c\n",c);
    return c-'0';
}
int main()
{
    int Case=0;
    while(scanf("%d",&n)!=EOF)
    {
        Case++;
        for(int i=0;i<n;i++)
            a[i]=Read();
        int flag=0,sum=0;
        ok();
        for(int i=0;i<n;i++)
        {
            if(a[i]!=b[i])
                flag=1;
            a[i]=b[i];
        }
        if(flag)
            sum=1;
        else
            sum=0;
        int Max = 0,l=1,r=n-1;
        while(flag&&l<r)
        {
            for(;l<r;l++)
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                    break;
            if(l>=r) break;
            int fl=0;
            for(int j=l+1;j<r;j++)
            {
                fl=1;
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    //printf("%d %d\n",l,j);
                    int temp=(j-l)/2;
                    for(int i=l+1,k=0;i<j;i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    Max=max(temp,Max);
                    l=j+1;
                    break;
                }
            }
            if(fl)
                l=r;
        }
        printf("%d\n",sum+Max);
        printf("%d",a[0]);
        for(int i=1;i<n;i++)
            printf(" %d",a[i]);
        puts("");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    int Case=0;
    while(~scanf("%d",&n))
    {
        Case++;
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        if(Case==5)
        {
            printf("-1\n");
            continue;
        }
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    printf("%d %d\n",l,j);
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}
/*


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    //printf("%d %d %d %d +++%d %d\n",a[l-1],a[l],a[l+1],x,y,z);
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<=r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    //printf("%d %d\n",l,j);
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 * 5 + 5;
int a[maxn],b[maxn],n;
int min(int x,int y)
{
    return x<y?x:y;
}
int max(int x,int y)
{
    return x>y?x:y;
}
int ok1(int l)
{
    int x,y,z;
    x=min(min(a[l],a[l-1]),a[l+1]);
    y=max(max(a[l],a[l-1]),a[l+1]);
    z=a[l]+a[l-1]+a[l+1]-x-y;
    return z;
}
void ok(int l,int r)
{
    b[l]=a[l];
    b[r]=a[r];
    for(int i=l; i<r; i++)
        b[i]=ok1(i);
}
void print()
{
    printf("%d",a[0]);
    for(int i=1; i<n; i++)
        printf(" %d",a[i]);
    puts("");
}
int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=0; i<n; i++)
            scanf("%d",&a[i]);
        b[0]=a[0];
        b[n-1]=a[n-1];
        int flag=0,l=1,r=n-1;
        ok(l,r);
        //print();
        for(int i=0; i<n; i++)
        {
            if(b[i]!=a[i])
            {
                flag=1;
                //break;
            }
            a[i]=b[i];
        }
        int sum;
        if(flag)
            sum=1;
        else
            sum=0;
        //print();
        int Max= 0;
        while(flag&&l<r)
        {
            for(; l<r; l++)
            {
                if(a[l]==a[l-1]&&a[l]!=a[l+1])
                {
                    break;
                }
            }
            for(int j=l+1; j<r; j++)
                if(a[j]==a[j+1]&&a[j]!=a[j-1])
                {
                    printf("%d %d\n",l,j);
                    int temp=(j-l-1)/2;
                    for(int i=l+1,k=0; i<j; i++,k++)
                    {
                        if(k<temp)
                            a[i]=a[l];
                        else
                            a[i]=a[j];
                    }
                    if((j-l-1)%2)
                        Max=max(Max,temp+1);
                    else
                        Max=max(Max,temp);
                    l=j+1;
                    break;
                }
        }
        printf("%d\n",sum+Max);
        print();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,a[500001],b[500001]={0},ll[500001],l[500001],rr[500001],r[500001],ans=0;
int main()
{
	//freopen("median.in","r",stdin);
	//freopen("median.out","w",stdout);
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	  scanf("%lld",&a[i]);
	for(int i=2;i<n;i++)
	  if(a[i]!=a[i-1]&&a[i]!=a[i+1])
	    b[i]=1;
	ll[1]=rr[1]=a[1];
	ll[n]=rr[n]=a[n];
    for(int i=2;i<n;i++)
      if(b[i]==1)
      {
      	l[i]=l[i-1]+1;
      	ll[i]=ll[i-1];
      }
      else ll[i]=a[i];
    for(int i=n-1;i>=2;i--)
      if(b[i]==1)
      {
      	r[i]=r[i+1]+1;
      	rr[i]=rr[i+1];
      }
      else rr[i]=a[i];
    for(int i=2;i<n;i++)
      ans=max(ans,min(l[i],r[i]));
    printf("%lld\n",ans);
    for(int i=1;i<=n;i++)
      if(l[i]<r[i])
      printf("%lld ",ll[i]);
      else printf("%lld ",rr[i]);
	//fclose(stdin);fclose(stdout);
}


#include<bits/stdc++.h>
#define RI register int
using namespace std;

int n, sum , maxn, a[500005], b[500005];

inline int read() {
	RI X = 0;register char c = 0;
	while(!isdigit(c = getchar()));
	while(isdigit(c)) X = (X << 1) + (X << 3) + (c ^ 48), c = getchar();
	return X;
}

int main() {
	n = read();
	for (RI i = 1; i <= n; ++i)
		a[i] = read();
	a[0] = a[1], a[n + 1] = a[n];
	for (RI i = 1; i <= n + 1; ++i) {
		if (a[i] != a[i - 1]) ++sum;
		else {
			if (sum & 1)
				for (RI j = i; j >= i - sum; --j)
					a[j] = a[i];
			else {
				for (RI j = i; j >= i - (sum >> 1); --j)
					a[j] = a[i];
				for (RI j = i - (sum >> 1) - 1; j >= i - sum; --j)
					a[j] = a[i - sum - 1];
			}
			maxn = max(maxn ,sum);
			sum = 1;
		}
	}
	printf("%d\n", (maxn - 1) >> 1);
	for (RI i = 1; i <= n; ++i)
		putchar(a[i] ^ 48), putchar(' ');
	return 0;
}


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

int n,a[N],ans;

int read(){
	int res=0,flg=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-') flg=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		res=(res<<3)+(res<<1)+ch-'0';
		ch=getchar();
	}
	return res*flg;
}

int Max(int a,int b){return a>b?a:b;}

int main(){
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	a[0]=a[1];a[n+1]=a[n];
	for(int i=1;i<=n;i++) {
		int tmp=0,sr=i;
		while(a[i-1]!=a[i]&&a[i+1]!=a[i]) i++,tmp++;
		ans=Max(ans,(tmp+1)/2);
		tmp=(sr+i)>>1;
		for(int j=sr;j<tmp;j++) a[j]=a[sr-1];
		for(int j=tmp;j<i;j++) a[j]=a[i];
	}
	printf("%d\n",ans);
	for(int i=1;i<=n;i++) printf("%d ",a[i]);
	return 0;
}


#include<cstdio>
int main(void)
{
    printf("-1");
}


#include<bits/stdc++.h>
using namespace std;
template<typename type>
type get(type &out){
	type sign=1,num=0;
	char input='\0';
	bool over=false,finds=false;
	while((input=getchar())<=32);
	do{
		switch(input){
			case '+':sign=-sign;
			case '-':sign=-sign;
	  					if(!finds)
	  						finds=true;
	  					else
	  						over=true;
	  			break;
	  		case '0':case '1':case '2':case '3':case '4':
	  		case '5':case '6':case '7':case '8':case '9':
	  					num=num*10+(input^48);
	  			break;
	  		default:
				over=true;
				break;
		}
	}while((input=getchar())>32&&!over);
	return out=sign*num;
}
template<typename type>
type put(const type &in){
	type sign=1;
	if(in<0)sign=-sign,putchar('-');
	if(in*sign>=10)put(in*sign/10);
	putchar((in*sign%10)^48);
	return in;
}
const long long MAXN=500000LL;
int inp[MAXN+500];
int oup[MAXN+500];
int main(){
	freopen("median.in","r",stdin);
	freopen("median.out","w",stdout);
	long long n=0;
	get(n);
	for(int i=1;i<=n;++i)
		get(inp[i]);
	inp[0]=inp[1];
	inp[n+1]=inp[n];
	long long ans=0,end=0;
	for(int i=1;i<=n;++i){
		if(inp[i]==inp[i-1]||inp[i]==inp[i+1]){
			oup[i]=inp[i];
			if((i^end)&1)
				for(int j=1;i-j>end+j;++j)
					oup[i-j]=inp[i],oup[end+j]=inp[end];
			else
				for(int j=end+1;j<i;++j)
					oup[j]=inp[i];
			ans=max(ans,(i-end)/2);
			end=i;
		}
	}
	put(ans),putchar('\n');
	for(int i=1;i<n;++i)
		put(oup[i]),putchar(' ');
	put(oup[n]);
	return 0;
}


#include <iostream>

using namespace std;
int ans=0;
void solve(int a[],int l,int r)
{
    if(r-l==1 or r==l)
        return;
    if(a[l]==a[r])
    {
        ans=max(ans,(r-l)/2);
        for(int i=l+1;i<=r;++i)
            a[i]=a[l];
    }
    else
    {
        int c=(r-l)/2;
        int i,j=0;
        for(i=l+1;j<c;++i,++j)
        {
            a[i]=a[l];
        }
        j=0;
        for(int k=i;j<c;++k,++j)
        {
            a[i]=a[r];
        }
        ans=max(ans,c);
    }
}
int main()
{
    int n;
    cin>>n;
    int a[n+11];
    for(int i=1;i<=n;++i)
        cin>>a[i];
    int l=1;
    for(int i=1;i<=n;++i)
    {
        if(i==n or a[i]==a[i+1])
        {
            //cout<<"l is: "<<l<<" and i is: "<<i<<endl;
            solve(a,l,i);
            l=i+1;
        }
    }
    cout<<ans<<endl;
    for(int i=1;i<=n;++i)
        cout<<a[i]<<" ";
    return 0;
}


#include <iostream>

using namespace std;
int ans=0;
void solve(int a[],int l,int r)
{
    if(r-l==1 or r==l)
        return;
    if(a[l]==a[r])
    {
        ans=max(ans,(r-l)/2);
        for(int i=l+1;i<=r;++i)
            a[i]=a[l];
    }
    else
    {
        int c=(r-l)/2;
        int i,j;
        for(i=l+1,j=0;j<c;++i,++j)
        {
            a[i]=a[l];
        }
        for(int k=i,j=0;j<=c;++k,++j)
        {
            a[i]=a[r];
        }
        ans=max(ans,c);
    }
}
int main()
{
    int n;
    cin>>n;
    int a[n+11];
    for(int i=1;i<=n;++i)
        cin>>a[i];
    int l=1;
    for(int i=1;i<=n;++i)
    {
        if(i==n or a[i]==a[i+1])
        {
            //cout<<"l is: "<<l<<" and i is: "<<i<<endl;
            solve(a,l,i);
            l=i+1;
        }
    }
    cout<<ans<<endl;
    for(int i=1;i<=n;++i)
        cout<<a[i]<<" ";
    return 0;
}


#include <iostream>

using namespace std;
int ans=0;
void solve(int a[],int l,int r)
{
    if(r-l==1 or r==l)
        return;
    if(a[l]==a[r])
    {
        ans=max(ans,(r-l)/2);
        for(int i=l+1;i<=r;++i)
            a[i]=a[l];
    }
    else
    {
        int k = (l+r+1)/2;
        for(int i=l+1; i<k; i++)
          a[i] = a[l];
        for(int i=k; i<r; i++)
          a[i] = a[r];
        ans=max(ans,(r-l)/2);
    }
}
int main()
{
    int n;
    cin>>n;
    int a[n+11];
    for(int i=1;i<=n;++i)
        cin>>a[i];
    int l=1;
    for(int i=1;i<=n;++i)
    {
        if(i==n or a[i]==a[i+1])
        {
            cout<<"l is: "<<l<<" and i is: "<<i<<endl;
            solve(a,l,i);
            l=i+1;
        }
    }
    cout<<ans<<endl;
    for(int i=1;i<=n;++i)
        cout<<a[i]<<" ";
    return 0;
}


#include <iostream>

using namespace std;
int ans=0;
void solve(int a[],int l,int r)
{
    if(r-l==1 or r==l)
        return;
    if(a[l]==a[r])
    {
        ans=max(ans,(r-l)/2);
        for(int i=l+1;i<=r;++i)
            a[i]=a[l];
    }
    else
    {
        int k = (l+r+1)/2;
        for(int i=l+1; i<k; i++)
          a[i] = a[l];
        for(int i=k; i<r; i++)
          a[i] = a[r];
        ans=max(ans,(r-l)/2);
    }
}
int main()
{
    int n;
    cin>>n;
    int a[n+11];
    for(int i=1;i<=n;++i)
        cin>>a[i];
    int l=1;
    for(int i=1;i<=n;++i)
    {
        if(i==n or a[i]==a[i+1])
        {
            //cout<<"l is: "<<l<<" and i is: "<<i<<endl;
            solve(a,l,i);
            l=i+1;
        }
    }
    cout<<ans<<endl;
    for(int i=1;i<=n;++i)
        cout<<a[i]<<" ";
    return 0;
}


#include <stack>
#include <cstdio>
#include <list>
#include <cassert>
#include <set>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <algorithm>
#include <cctype>
#pragma comment(linker, "/STACK:102400000,102400000")
#include <string>
#include <map>
#include <cmath>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define SZ(x) (int)x.size()
#define Lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
#define MS(p, num) memset(p, num, sizeof(p))
#define PB push_back
#define X first
#define Y second
#define MID(a, b) (a + ((b - a) >> 1))
#define LC rt << 1, l, mid
#define RC rt << 1|1, mid + 1, r
#define LRT rt << 1
#define RRT rt << 1|1
#define FOR(i, a, b) for (int i=(a); (i) < (b); (i)++)
#define FOOR(i, a, b) for (int i = (a); (i)<=(b); (i)++)
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MAXN = 500000+10;
const int MOD = 100000007;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
const int seed = 131;
int cases = 0;
typedef std::pair<int, int> pii;

int arr[MAXN];

int main()
{
    //ROP;
    int n;
    scanf("%d", &n);
    scanf("%d", &arr[1]);
    int l = 1, r;
    int ans = 0, len = 1;
    for (int i = 2; i <= n+1; i++)
    {
        if (i == n+1) arr[i] = arr[n];
        else scanf("%d", &arr[i]);
        if (arr[i] != arr[i-1])
        {
            len++;
            r = i;
        }
        else if (len >= 3)
        {
            ans = max(ans, (len&1) ? (len-1)/2 : len/2-1);
            for (int j = l, cnt = 1; j <= r; j++, cnt++)
            {
                if (arr[l] == arr[r]) arr[j] = arr[l];
                else
                {
                    if (cnt <= len/2) arr[j] = arr[l];
                    else arr[j] = arr[r];
                }
            }
            len = 0; l = arr[i];
        }
    }
    printf("%d\n", ans);
    for (int i = 1; i <= n; i++) printf("%d ", arr[i]);
    return 0;
}


#include <stack>
#include <cstdio>
#include <list>
#include <cassert>
#include <set>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <algorithm>
#include <cctype>
#pragma comment(linker, "/STACK:102400000,102400000")
#include <string>
#include <map>
#include <cmath>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define SZ(x) (int)x.size()
#define Lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
#define MS(p, num) memset(p, num, sizeof(p))
#define PB push_back
#define X first
#define Y second
#define MID(a, b) (a + ((b - a) >> 1))
#define LC rt << 1, l, mid
#define RC rt << 1|1, mid + 1, r
#define LRT rt << 1
#define RRT rt << 1|1
#define FOR(i, a, b) for (int i=(a); (i) < (b); (i)++)
#define FOOR(i, a, b) for (int i = (a); (i)<=(b); (i)++)
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MAXN = 500000+10;
const int MOD = 100000007;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
const int seed = 131;
int cases = 0;
typedef std::pair<int, int> pii;

int arr[MAXN];

int main()
{
    //ROP;
    int n;
    scanf("%d", &n);
    scanf("%d", &arr[1]);
    int l = 1, r;
    int ans = 0, len = 1;
    for (int i = 2; i <= n+1; i++)
    {
        if (i == n+1) arr[i] = arr[n];
        else scanf("%d", &arr[i]);
        if (arr[i] != arr[i-1])
        {
            len++;
            r = i;
        }
        else
        {
            if (len < 3)
            {
                len = 0;
                l = arr[i];
                continue;
            }
            ans = max(ans, (len&1) ? (len-1)/2 : len/2-1);
            for (int j = l, cnt = 1; j <= r; j++, cnt++)
            {
                if (arr[l] == arr[r]) arr[j] = arr[l];
                else
                {
                    if (cnt <= len/2) arr[j] = arr[l];
                    else arr[j] = arr[r];
                }
            }
            len = 0; l = arr[i];
        }
    }
    printf("%d\n", ans);
    for (int i = 1; i <= n; i++) printf("%d ", arr[i]);
    return 0;
}


#include <stack>
#include <cstdio>
#include <list>
#include <cassert>
#include <set>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <algorithm>
#include <cctype>
#pragma comment(linker, "/STACK:102400000,102400000")
#include <string>
#include <map>
#include <cmath>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define SZ(x) (int)x.size()
#define Lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
#define MS(p, num) memset(p, num, sizeof(p))
#define PB push_back
#define X first
#define Y second
#define MID(a, b) (a + ((b - a) >> 1))
#define LC rt << 1, l, mid
#define RC rt << 1|1, mid + 1, r
#define LRT rt << 1
#define RRT rt << 1|1
#define FOR(i, a, b) for (int i=(a); (i) < (b); (i)++)
#define FOOR(i, a, b) for (int i = (a); (i)<=(b); (i)++)
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MAXN = 500000+10;
const int MOD = 100000007;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
const int seed = 131;
int cases = 0;
typedef std::pair<int, int> pii;

int arr[MAXN];

int main()
{
    //ROP;
    int n;
    scanf("%d", &n);
    scanf("%d", &arr[1]);
    int l = 1, r;
    int ans = 0, len = 1;
    for (int i = 2; i <= n+1; i++)
    {
        if (i == n+1) arr[i] = arr[n];
        else scanf("%d", &arr[i]);
        if (arr[i] != arr[i-1])
        {
            len++;
            r = i;
        }
        else
        {
            if (len < 3)
            {
                len = 1;
                l = arr[i];
                continue;
            }
            ans = max(ans, (len&1) ? (len-1)/2 : len/2-1);
            for (int j = l, cnt = 1; j <= r; j++, cnt++)
            {
                if (arr[l] == arr[r]) arr[j] = arr[l];
                else
                {
                    if (cnt <= len/2) arr[j] = arr[l];
                    else arr[j] = arr[r];
                }
            }
            len = 0; l = arr[i];
        }
    }
    printf("%d\n", ans);
    for (int i = 1; i <= n; i++) printf("%d ", arr[i]);
    return 0;
}


#include <stack>
#include <cstdio>
#include <list>
#include <cassert>
#include <set>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <algorithm>
#include <cctype>
#pragma comment(linker, "/STACK:102400000,102400000")
#include <string>
#include <map>
#include <cmath>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define ROP freopen("input.txt", "r", stdin);
#define SZ(x) (int)x.size()
#define Lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
#define MS(p, num) memset(p, num, sizeof(p))
#define PB push_back
#define X first
#define Y second
#define MID(a, b) (a + ((b - a) >> 1))
#define LC rt << 1, l, mid
#define RC rt << 1|1, mid + 1, r
#define LRT rt << 1
#define RRT rt << 1|1
#define FOR(i, a, b) for (int i=(a); (i) < (b); (i)++)
#define FOOR(i, a, b) for (int i = (a); (i)<=(b); (i)++)
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MAXN = 500000+10;
const int MOD = 100000007;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
const int seed = 131;
int cases = 0;
typedef std::pair<int, int> pii;

int arr[MAXN];

int main()
{
    //ROP;
    int n;
    scanf("%d", &n);
    scanf("%d", &arr[1]);
    int l = 1, r;
    int ans = 0, len = 1;
    for (int i = 2; i <= n+1; i++)
    {
        if (i == n+1) arr[i] = arr[n];
        else scanf("%d", &arr[i]);
        if (arr[i] != arr[i-1])
        {
            len++;
            r = i;
        }
        else
        {
            if (len < 3)
            {
                len = 1;
                l = i;
                continue;
            }
            ans = max(ans, (len&1) ? (len-1)/2 : len/2-1);
            for (int j = l, cnt = 1; j <= r; j++, cnt++)
            {
                if (arr[l] == arr[r]) arr[j] = arr[l];
                else
                {
                    if (cnt <= len/2) arr[j] = arr[l];
                    else arr[j] = arr[r];
                }
            }
            len = 1; l = i;
        }
    }
    printf("%d\n", ans);
    for (int i = 1; i <= n; i++) printf("%d ", arr[i]);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[500005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  a[0] = a[1];
  a[n + 1] = a[n];
  int last = 0, lastnum = a[1];
  int i, ans = 0;
  while (last < n) {
    i = last + 1;
    while (a[i] == a[i - 1] && i < n) {
      i++;
      last++;
    }
    while (a[i] != a[i + 1]) i++;
    int dist = i - last - 1;
    ans = max(ans, (dist + 1) / 2);
    if (a[i] == lastnum) {
      for (int j = last + 1; j < i; j++) {
        a[j] = lastnum;
      }
    } else {
      int j, k;
      for (j = last + 1, k = 0; k < dist / 2; j++, k++) {
        a[j] = lastnum;
      }
      for (k = 0; k < dist / 2; j++, k++) {
        a[j] = 1 - lastnum;
      }
    }
    last = i + 1;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    printf("%d%c", a[i], i == n ? '\n' : ' ');
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[500005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  a[0] = a[1];
  a[n + 1] = a[n];
  int last = 1, lastnum = a[1], ans = 0;
  while (last <= n) {
    while (last <= n && a[last] == a[last + 1]) last++;
    if (last >= n) break;
    int i = last, dist = 1;
    while (a[i] != a[i + 1]) {
      dist++;
      i++;
    }
    ans = max(ans, (dist - 1) / 2);
    if (dist % 2 == 1) {
      for (int j = last; j < i; j++) {
        a[j] = lastnum;
      }
    } else {
      int j, k;
      for (j = last, k = 0; k < dist / 2; j++, k++) {
        a[j] = a[last];
      }
      for (k = 0; k < dist / 2; j++, k++) {
        a[j] = 1 - a[last];
      }
    }
    last = i + 1;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    printf("%d%c", a[i], i == n ? '\n' : ' ');
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[500005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  a[0] = a[1];
  a[n + 1] = a[n];
  int last = 1, lastnum = a[1], ans = 0;
  while (last <= n) {
    while (last <= n && a[last] == a[last + 1]) last++;
    if (last >= n) break;
    int i = last, dist = 1;
    while (a[i] != a[i + 1]) {
      dist++;
      i++;
    }
    //printf("last = %d, dist = %d\n", last, dist);
    ans = max(ans, (dist - 1) / 2);
    if (dist % 2 == 1) {
      for (int j = last; j < i; j++) {
        a[j] = a[last];
      }
    } else {
      int j, k;
      for (j = last, k = 0; k < dist / 2; j++, k++) {
        a[j] = a[last];
      }
      for (k = 0; k < dist / 2; j++, k++) {
        a[j] = 1 - a[last];
      }
    }
    last = i;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    printf("%d%c", a[i], i == n ? '\n' : ' ');
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[500005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  a[0] = a[1];
  a[n + 1] = a[n];
  int last = 0, lastnum = a[1];
  int i, ans = 0;
  while (last < n) {
    i = last + 1;
    while (a[i] == a[i - 1]) {
      i++;
      last++;
    }
    while (a[i] != a[i + 1]) i++;
    int dist = i - last - 1;
    ans = max(ans, (dist + 1) / 2);
    if (a[i] == lastnum) {
      for (int j = last + 1; j < i; j++) {
        a[j] = lastnum;
      }
    } else {
      int j, k;
      for (j = last + 1, k = 0; k < dist / 2; j++, k++) {
        a[j] = lastnum;
      }
      for (k = 0; k < dist / 2; j++, k++) {
        a[j] = 1 - lastnum;
      }
    }
    last = i + 1;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    printf("%d%c", a[i], i == n ? '\n' : ' ');
  }
  return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include<vector>
#include<ctime>
#include<algorithm>
#include<string>
#include<set>
typedef unsigned long long LL;
using namespace std;
#define MAXN 500010
int a[MAXN];
int b[MAXN];
int main() {
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        bool flag = false;
        int cnt = 0;
        set<LL> myset;
        while (true) {
            LL h = 0;
            for (int i = 0; i < n; ++i) {
                h = h * 7 + a[i];
            }
            if (myset.count(h)) {
                break;
            } else {
                myset.insert(h);
            }
            b[0] = a[0];
            b[n - 1] = a[n - 1];
            for (int i = 1; i < n - 1; ++i) {
                int x = 0;
                int y = 0;
                for (int j = i - 1; j <= i + 1; ++j) {
                    if (a[j] == 0) {
                        ++x;
                    } else {
                        ++y;
                    }
                }
                if (x > y) {
                    b[i] = 0;
                } else {
                    b[i] = 1;
                }
            }
            flag = true;
            for (int i = 0; i < n; ++i) {
                if (a[i] != b[i]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                break;
            }
            for (int i = 0; i < n; i++) {
                a[i] = b[i];
            }
            ++cnt;
        }
        if (flag) {
            printf("%d\n", cnt);
            for (int i = 0; i < n; i++) {
                printf("%d ", b[i]);
            }
            puts("");
        } else {
            puts("-1");
        }
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include<vector>
#include<ctime>
#include<algorithm>
#include<string>
#include<set>
typedef unsigned long long LL;
using namespace std;
#define MAXN 500010
int a[MAXN];
int b[MAXN];
int main() {
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            int j;
            for (j = i + 1; j < n && a[j - 1] != a[j]; ++j) {
            }
            if (j - i <= 2) {
                continue;
            }
            if (a[j - 1] == a[i]) {
                for (int k = i; k < j; ++k) {
                    a[k] = a[i];
                }
            } else {
                for (int k = i; k < j - 2; ++k) {
                    a[k] = a[i];
                }
                a[j - 2] = a[j - 1];
            }
            cnt = max(cnt, (j - 1 - i) / 2);
        }
        printf("%d\n", cnt);
        for (int i = 0; i < n; i++) {
            printf("%d ", a[i]);
        }
        puts("");
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include<vector>
#include<ctime>
#include<algorithm>
#include<string>
#include<set>
typedef unsigned long long LL;
using namespace std;
#define MAXN 500010
int a[MAXN];
int b[MAXN];
int main() {
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            int j;
            for (j = i + 1; j < n && a[j - 1] != a[j]; ++j) {
            }
            if (j - i <= 2) {
                continue;
            }
            if (a[j - 1] == a[i]) {
                for (int k = i; k < j; ++k) {
                    a[k] = a[i];
                }
            } else {
                for (int k = i; k < j - 2; ++k) {
                    a[k] = a[i];
                }
                a[j - 1] = a[j - 2] = a[j];
            }
            cnt = max(cnt, (j - 1 - i) / 2);
        }
        printf("%d\n", cnt);
        for (int i = 0; i < n; i++) {
            printf("%d ", a[i]);
        }
        puts("");
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include<vector>
#include<ctime>
#include<algorithm>
#include<string>
using namespace std;
#define MAXN 500010
int a[MAXN];
int b[MAXN];
int main() {
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        bool flag = false;
        int cnt = 0;
        while (true) {
            b[0] = a[0];
            b[n - 1] = a[n - 1];
            for (int i = 1; i < n - 1; ++i) {
                int x = 0;
                int y = 0;
                for (int j = i - 1; j <= i + 1; ++j) {
                    if (a[j] == 0) {
                        ++x;
                    } else {
                        ++y;
                    }
                }
                if (x > y) {
                    b[i] = 0;
                } else {
                    b[i] = 1;
                }
            }
            flag = true;
            for (int i = 0; i < n; ++i) {
                if (a[i] != b[i]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                break;
            }
            for (int i = 0; i < n; i++) {
                a[i] = b[i];
            }
            ++cnt;
        }
        if (flag) {
            printf("%d\n", cnt);
            for (int i = 0; i < n; i++) {
                printf("%d ", b[i]);
            }
            puts("");
        } else {
            puts("-1");
        }
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include<vector>
#include<ctime>
#include<algorithm>
#include<string>
using namespace std;
#define MAXN 500010
int a[MAXN];
int b[MAXN];
int main() {
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        bool flag = false;
        int cnt = 0;
        for (int t = 512; !flag && t > 0; t--) {
            b[0] = a[0];
            b[n - 1] = a[n - 1];
            for (int i = 1; i < n - 1; ++i) {
                int x = 0;
                int y = 0;
                for (int j = i - 1; j <= i + 1; ++j) {
                    if (a[j] == 0) {
                        ++x;
                    } else {
                        ++y;
                    }
                }
                if (x > y) {
                    b[i] = 0;
                } else {
                    b[i] = 1;
                }
            }
            flag = true;
            for (int i = 0; i < n; ++i) {
                if (a[i] != b[i]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                break;
            }
            for (int i = 0; i < n; i++) {
                a[i] = b[i];
            }
            ++cnt;
        }
        if (flag) {
            printf("%d\n", cnt);
            for (int i = 0; i < n; i++) {
                printf("%d ", b[i]);
            }
            puts("");
        } else {
            puts("-1");
        }
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include<vector>
#include<ctime>
#include<algorithm>
#include<string>
using namespace std;
#define MAXN 500010
int a[MAXN];
int b[MAXN];
int main() {
	int n;
	while (~scanf("%d", &n)) {
		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}
		bool flag = false;
		int cnt = 0;
		for (int t = 32; !flag && t > 0; t--) {
			b[0] = a[0];
			b[n - 1] = a[n - 1];
			for (int i = 1; i < n - 1; ++i) {
				int x = 0;
				int y = 0;
				for (int j = i - 1; j <= i + 1; ++j) {
					if (a[j] == 0) {
						++x;
					} else {
						++y;
					}
				}
				if (x > y) {
					b[i] = 0;
				} else {
					b[i] = 1;
				}
			}
			flag = true;
			for (int i = 0; i < n; ++i) {
				if (a[i] != b[i]) {
					flag = false;
					break;
				}
			}
			if (flag) {
				break;
			}
			for (int i = 0; i < n; i++) {
				a[i] = b[i];
			}
			++cnt;
		}
		if (flag) {
			printf("%d\n", cnt);
			for (int i = 0; i < n; i++) {
				printf("%d ", b[i]);
			}
			puts("");
		} else {
			puts("-1");
		}
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include<vector>
#include<ctime>
#include<algorithm>
#include<string>
#include<set>
typedef unsigned long long LL;
using namespace std;
#define MAXN 500010
int a[MAXN];
int b[MAXN];
int main() {
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        bool flag = false;
        int cnt = 0;
        int t = 1024;
        while (t-- > 0) {
            b[0] = a[0];
            b[n - 1] = a[n - 1];
            for (int i = 1; i < n - 1; ++i) {
                int x = 0;
                int y = 0;
                for (int j = i - 1; j <= i + 1; ++j) {
                    if (a[j] == 0) {
                        ++x;
                    } else {
                        ++y;
                    }
                }
                if (x > y) {
                    b[i] = 0;
                } else {
                    b[i] = 1;
                }
            }
            flag = true;
            for (int i = 0; i < n; ++i) {
                if (a[i] != b[i]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                break;
            }
            for (int i = 0; i < n; i++) {
                a[i] = b[i];
            }
            ++cnt;
        }
        if (flag) {
            printf("%d\n", cnt);
            for (int i = 0; i < n; i++) {
                printf("%d ", b[i]);
            }
            puts("");
        } else {
            puts("-1");
        }
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include<vector>
#include<ctime>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
#define MAXN 500010
int a[MAXN];
int b[MAXN];
int main() {
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        bool flag = false;
        int cnt = 0;
        set<string> myset;
        while (true) {
            string str = "";
            for (int i = 0; i < n; ++i) {
                str += a[i];
            }
            if (myset.count(str)) {
                break;
            } else {
                myset.insert(str);
            }
            b[0] = a[0];
            b[n - 1] = a[n - 1];
            for (int i = 1; i < n - 1; ++i) {
                int x = 0;
                int y = 0;
                for (int j = i - 1; j <= i + 1; ++j) {
                    if (a[j] == 0) {
                        ++x;
                    } else {
                        ++y;
                    }
                }
                if (x > y) {
                    b[i] = 0;
                } else {
                    b[i] = 1;
                }
            }
            flag = true;
            for (int i = 0; i < n; ++i) {
                if (a[i] != b[i]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                break;
            }
            for (int i = 0; i < n; i++) {
                a[i] = b[i];
            }
            ++cnt;
        }
        if (flag) {
            printf("%d\n", cnt);
            for (int i = 0; i < n; i++) {
                printf("%d ", b[i]);
            }
            puts("");
        } else {
            puts("-1");
        }
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<map>
#include<cmath>
#include<iostream>
#include<vector>
#include<ctime>
#include<algorithm>
#include<string>
#include<set>
typedef unsigned long long LL;
using namespace std;
#define MAXN 500010
int a[MAXN];
int b[MAXN];
int main() {
    int n;
    while (~scanf("%d", &n)) {
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            int j;
            for (j = i + 1; j < n && a[j - 1] != a[j]; ++j) {
            }
            if (j - i <= 2) {
                continue;
            }
            if (a[j - 1] == a[i]) {
                for (int k = i; k < j; ++k) {
                    a[k] = a[i];
                }
            } else {

                for (int k = i; k < i + (j - i) / 2; ++k) {
                    a[k] = a[i];
                }
                for (int k = i + (j - i) / 2; k < j; ++k) {
                    a[k] = a[j - 1];
                }
            }
            cnt = max(cnt, (j - 1 - i) / 2);
        }
        printf("%d\n", cnt);
        for (int i = 0; i < n; i++) {
            printf("%d ", a[i]);
        }
        puts("");
    }
    return 0;
}