#include <iostream>
#include <vector>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <tuple>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <stdio.h>

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl

typedef long long tint;
typedef unsigned long long utint;
typedef long double ldouble;

using namespace std;

void imprimirVector (vector<tint> v)
{
	if (!v.empty())
	{
		int p = v.size();
		cout << "[";
		forn(i,p-1)
			cout << v[i] << ",";
		cout << v[p-1] << "]" << endl;
	}
	else
		cout << "[]" << endl;
}

tint toNumber (string s)
{
	tint Number;
	if ( ! (istringstream(s) >> Number) ) Number = 0; // el string vacio lo manda al cero
	return Number;
}

string toString (tint number)
{
    ostringstream ostr;
    ostr << number;
    return  ostr.str();
}

struct Station
{
	tint inicio,fin,color;
	Station(tint ii, tint ff, tint cc)
	{
		inicio = ii;
		fin = ff;
		color = cc;
	}
};

int main()
{
	ios_base::sync_with_stdio(0);
	#ifdef ACMTUYO
		if (!freopen("Cnew.in", "r", stdin))
			return 1;
	#endif
	tint n;
	while(cin >> n)
	{
		vector<tint> a (n);
		forn(i,n)
			cin >> a[i];
		vector<Station> p;
		tint comienzo = 0;
		tint fin  = 0;
		tint i = 1;
		bool abierto = true;
		while (i < n)
		{
			if (!abierto && a[i] == a[i-1])
			{
				abierto = true;
				comienzo = i-1;
			}
			else if (abierto && a[i] != a[i-1])
			{
				abierto = false;
				fin = i-1;
				p.push_back(Station(comienzo, fin, a[i-1]));
			}
			i++;
		}
		i = n-2;
		while (i >= 0 && a[i] == a[n-1])
			i--;
		p.push_back(Station(i+1,n-1,a[n-1]));
		Station anterior = p[0];
		tint maxPasos = 0;
		vector<tint> risposta (n);
		forsn(r,anterior.inicio,anterior.fin + 1)
			risposta[r] = anterior.color;
		forsn(j,1,p.size())
		{
			maxPasos = max(maxPasos,(p[j].inicio - anterior.fin)/2);
			if (anterior.color == p[j].color)
			{
				forsn(r,anterior.fin+1,p[j].inicio)
					risposta[r] = anterior.color;
			}
			else
			{
				forsn(r,anterior.fin+1, (p[j].inicio + anterior.fin)/2 + 1)
					risposta[r] = anterior.color;
				forsn(r,(p[j].inicio + anterior.fin)/2 + 1, p[j].inicio + 1)
					risposta[r] = p[j].color;

			}
			forsn(r,p[j].inicio,p[j].fin + 1)
				risposta[r] = p[j].color;
			anterior = p[j];
		}
		cout << maxPasos << endl;
		forn(r,n)
		{
			if (r)
				cout << " ";
			cout << risposta[r];
		}
		cout << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <tuple>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <stdio.h>

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl

typedef long long tint;
typedef unsigned long long utint;

using namespace std;

void imprimirVector (vector<int> v)
{
	if (!v.empty())
	{
		int p = v.size();
		cout << "[";
		forn(i,p-1)
			cout << v[i] << ",";
		cout << v[p-1] << "]" << endl;
	}
	else
		cout << "[]" << endl;
}

int toNumber (string s)
{
	int Number;
	if ( ! (istringstream(s) >> Number) ) Number = 0; // el string vacio lo manda al cero
	return Number;
}

string toString (int number)
{
    ostringstream ostr;
    ostr << number;
    return  ostr.str();
}

int main()
{
	ios_base::sync_with_stdio(0);
	tint n;
	cin >> n;
	vector<int> p (n);
	forn(i,n)
		cin >> p[i];
	int cavegol = p[0];
	int i = 1;
	int total = 0;
	int maxTotal = 0;
	while (i < n)
	{

		while(i < n-1 && p[i] != p[i+1])
		{
			p[i] = cavegol;
			i++;
			total++;
		}
		maxTotal = max(maxTotal, total);
		total = 0;
		cavegol = p[i];
		i++;

	}
	maxTotal = max(0,maxTotal - 1);
	cout << maxTotal << endl;
	forn(j,n)
	{
		if (j)
			cout << " ";
		cout << p[j];
	}
	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <tuple>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <stdio.h>

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl

typedef long long tint;
typedef unsigned long long utint;

using namespace std;

void imprimirVector (vector<tint> v)
{
	if (!v.empty())
	{
		int p = v.size();
		cout << "[";
		forn(i,p-1)
			cout << v[i] << ",";
		cout << v[p-1] << "]" << endl;
	}
	else
		cout << "[]" << endl;
}

int toNumber (string s)
{
	int Number;
	if ( ! (istringstream(s) >> Number) ) Number = 0; // el string vacio lo manda al cero
	return Number;
}

string toString (int number)
{
    ostringstream ostr;
    ostr << number;
    return  ostr.str();
}

void op (vector<tint> &p)
{
	tint n = p.size();
	tint anterior = p[0];
	forsn(i,1,n-1)
	{
		vector<tint> aux = {anterior,p[i],p[i+1]};
		anterior = p[i];
		sort(aux.begin(),aux.end());
		p[i] = aux[1];
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	tint n;
	cin >> n;
	vector<tint> p (n);
	forn(i,n)
		cin >> p[i];
	vector<tint> anterior = p;
	op(p);
	tint ans = 0;
	while (p != anterior)
	{
		ans++;
		anterior = p;
		op(p);
	}
	cout << ans << endl;
	forn(i,n)
	{
		if (i)
			cout << " ";
		cout << p[i];
	}
	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <tuple>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <stdio.h>

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl

typedef long long tint;
typedef unsigned long long utint;

using namespace std;

void imprimirVector (vector<int> v)
{
	if (!v.empty())
	{
		int p = v.size();
		cout << "[";
		forn(i,p-1)
			cout << v[i] << ",";
		cout << v[p-1] << "]" << endl;
	}
	else
		cout << "[]" << endl;
}

int toNumber (string s)
{
	int Number;
	if ( ! (istringstream(s) >> Number) ) Number = 0; // el string vacio lo manda al cero
	return Number;
}

string toString (int number)
{
    ostringstream ostr;
    ostr << number;
    return  ostr.str();
}

int main()
{
	ios_base::sync_with_stdio(0);
	tint n;
	cin >> n;
	vector<int> p (n);
	forn(i,n)
		cin >> p[i];
	int cavegol = p[0];
	int i = 1;
	int total = 0;
	int maxTotal = 0;
	while (i < n)
	{

		while(i < n-1 && p[i] != p[i+1])
		{
			p[i] = cavegol;
			i++;
			total++;
		}
		maxTotal = max(maxTotal, total);
		//debug(p[i]);
		//debug(i);
		//debug(total);
		//cout << "---" << endl;
		total = 0;
		cavegol = p[i];
		i++;

	}
	if (p[n-1] == p[n-2] && maxTotal != 0)
		maxTotal--;
	cout << maxTotal << endl;
	forn(j,n)
	{
		if (j)
			cout << " ";
		cout << p[j];
	}
	cout << endl;

	return 0;
}


#include<iostream>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn];

int mi(int x,int y,int z){
	if (x>y){
		int t=x;x=y;y=t;
	}
	if (x>z){
		int t=x;x=z;z=t;
	}
	if (y>z){
		int t=y;y=z;z=t;
	}
	return y;
}

int main(){
	cin >> n;
	for (int i=1;i<=n;i++) cin >> a[i];
	int flag=1,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		for (int i=2;i<=n-1;i++){
			b[i]=a[i];
			int t=mi(a[i-1],a[i],a[i+1]);
			if (a[i]!=t) {
				b[i]=t;
				not_stable=1;
			}
		}
		if (!not_stable) flag=0;
		for (int i=1;i<=n;i++) a[i]=b[i];
		if (count>1000000) break;
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#include<iostream>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn];

int mi(int x,int y,int z){
	if (x>y){
		int t=x;x=y;y=t;
	}
	if (x>z){
		int t=x;x=z;z=t;
	}
	if (y>z){
		int t=y;y=z;z=t;
	}
	return y;
}

int main(){
	cin >> n;
	for (int i=1;i<=n;i++) cin >> a[i];
	int flag=1,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		for (int i=2;i<=n-1;i++){
			b[i]=a[i];
			int t=mi(a[i-1],a[i],a[i+1]);
			if (a[i]!=t) {
				b[i]=t;
				not_stable=1;
			}
		}
		if (!not_stable) flag=0;
		for (int i=1;i<=n;i++) a[i]=b[i];
		if (count>100) break;
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<fstream>
#include<cmath>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn],c[maxn];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int flag=1,flag2=0,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		if (count %2==1)
			for (int i=2;i<=n-1;i++){
				b[i]=a[i];
				int t=floor((a[i-1]+a[i]+a[i+1])/2);
				if (a[i]!=t) {
					b[i]=t;
					not_stable=1;
				}
			}
		if (count %2==0)
			for (int i=2;i<=n-1;i++){
				a[i]=b[i];
				int t=floor((b[i-1]+b[i]+b[i+1])/2);
				if (b[i]!=t) {
					a[i]=t;
					not_stable=1;
				}
			}
		if (!not_stable) flag=0;
		if (count>1400) break;
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<fstream>
#include<cmath>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn],c[maxn];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int flag=1,flag2=0,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		if (count %2==1)
			for (int i=2;i<=n-1;i++){
				b[i]=a[i];
				int t=floor((a[i-1]+a[i]+a[i+1])/2);
				if (a[i]!=t) {
					b[i]=t;
					not_stable=1;
				}
			}
		if (count %2==0)
			for (int i=2;i<=n-1;i++){
				a[i]=b[i];
				int t=floor((b[i-1]+b[i]+b[i+1])/2);
				if (b[i]!=t) {
					a[i]=t;
					not_stable=1;
				}
			}
		if (!not_stable) flag=0;
		if (count>1000) break;
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#include<iostream>
using namespace std;

const int maxn=500000+1000;

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

int main(){
	cin >> n;
	for (int i=1;i<=n;i++) cin >> a[i];
	b[1]=b[n]=0;
	for (int i=2;i<n;i++){
		if (a[i]!=a[i-1] && a[i]!=a[i+1]) b[i]=1;
		else b[i]=0;
	}
	int s=0,e,cnt=0;
	for (int i=1;i<=n;i++){
		if (!s && b[i]) s=i;
		if (s && !b[i]){
			e=i;
			cnt=max(cnt,(e-s+1)/2);
			for (int j=s;j<e;j++){
				if (j<(s+e)/2) a[j]=a[s-1];
				else a[j]=a[e];
			}
			s=-1;
		}
	}
	cout << cnt << endl;
	for (int i=1;i<n;i++) cout << a[i] << " ";
	cout << a[n] << endl;
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn],c[maxn];

int mi(int x,int y,int z){
	if (x>y){
		int t=x;x=y;y=t;
	}
	if (x>z){
		int t=x;x=z;z=t;
	}
	if (y>z){
		int t=y;y=z;z=t;
	}
	return y;
}

int main(){
	cin >> n;
	for (int i=1;i<=n;i++) cin >> a[i];
	int flag=1,flag2=0,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		for (int i=2;i<=n-1;i++){
			b[i]=a[i];
			int t=mi(a[i-1],a[i],a[i+1]);
			if (a[i]!=t) {
				b[i]=t;
				not_stable=1;
			}
		}
		if (count > 500) break;
		if (!not_stable) flag=0;
		for (int i=1;i<=n;i++) a[i]=b[i];
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<fstream>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn],c[maxn];

int mi(int x,int y,int z){
	if (x>y){
		int t=x;x=y;y=t;
	}
	if (x>z){
		int t=x;x=z;z=t;
	}
	if (y>z){
		int t=y;y=z;z=t;
	}
	return y;
}

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int flag=1,flag2=0,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		for (int i=2;i<=n-1;i++){
			b[i]=a[i];
			int t=mi(a[i-1],a[i],a[i+1]);
			if (a[i]!=t) {
				b[i]=t;
				not_stable=1;
			}
		}
		if (count > 800) break;
		if (!not_stable) flag=0;
		for (int i=1;i<=n;i++) a[i]=b[i];
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<fstream>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn],c[maxn];

int mi(int x,int y,int z){
	if (x>y){
		int t=x;x=y;y=t;
	}
	if (x>z){
		int t=x;x=z;z=t;
	}
	if (y>z){
		int t=y;y=z;z=t;
	}
	return y;
}

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int flag=1,flag2=0,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		for (int i=2;i<=n-1;i++){
			b[i]=a[i];
			int t=mi(a[i-1],a[i],a[i+1]);
			if (a[i]!=t) {
				b[i]=t;
				not_stable=1;
			}
		}
		if (count > 250) break;
		if (!not_stable) flag=0;
		for (int i=1;i<=n;i++) a[i]=b[i];
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#include<iostream>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn];

int mi(int x,int y,int z){
	if (x>y){
		int t=x;x=y;y=t;
	}
	if (x>z){
		int t=x;x=z;z=t;
	}
	if (y>z){
		int t=y;y=z;z=t;
	}
	return y;
}

int main(){
	cin >> n;
	for (int i=1;i<=n;i++) cin >> a[i];
	int flag=1,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		for (int i=2;i<=n-1;i++){
			b[i]=a[i];
			int t=mi(a[i-1],a[i],a[i+1]);
			if (a[i]!=t) {
				b[i]=t;
				not_stable=1;
			}
		}
		if (!not_stable) flag=0;
		for (int i=1;i<=n;i++) a[i]=b[i];
		if (count>10000) break;
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<fstream>
#include<cmath>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn],c[maxn];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int flag=1,flag2=0,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		if (count %2==1)
			for (int i=2;i<=n-1;i++){
				b[i]=a[i];
				int t=floor((a[i-1]+a[i]+a[i+1])/2);
				if (a[i]!=t) {
					b[i]=t;
					not_stable=1;
				}
			}
		if (count %2==0)
			for (int i=2;i<=n-1;i++){
				a[i]=b[i];
				int t=floor((b[i-1]+b[i]+b[i+1])/2);
				if (b[i]!=t) {
					a[i]=t;
					not_stable=1;
				}
			}
		if (!not_stable) flag=0;
		if (count>1200) break;
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#include<iostream>
using namespace std;

const int maxn=500000+1000;

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

int main(){
	cin >> n;
	for (int i=1;i<=n;i++) cin >> a[i];
	b[1]=b[n]=0;
	for (int i=2;i<n;i++){
		if (a[i]!=a[i-1] && a[i]!=a[i+1]) b[i]=1;
		else b[i]=0;
	}
	int s=0,e,cnt=0;
	for (int i=1;i<=n;i++){
		if (!s && b[i]) s=i;
		if (s && !b[i]){
			e=i;
			cnt=max(cnt,(e-s+1)/2);
			for (int j=s;j<e;j++){
				if (j<(s+e)/2) a[j]=a[s-1];
				else a[j]=a[e];
			}
			s=0;
		}
	}
		for (int i=1;i<n;i++) cout << b[i] << " ";
	cout << b[n] << endl;
	cout << cnt << endl;
	for (int i=1;i<n;i++) cout << a[i] << " ";
	cout << a[n] << endl;
    return 0;
}


#include<iostream>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn];

int mi(int x,int y,int z){
	if (x>y){
		int t=x;x=y;y=t;
	}
	if (x>z){
		int t=x;x=z;z=t;
	}
	if (y>z){
		int t=y;y=z;z=t;
	}
	return y;
}

int main(){
	cin >> n;
	for (int i=1;i<=n;i++) cin >> a[i];
	int flag=1,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		for (int i=2;i<=n-1;i++){
			b[i]=a[i];
			int t=mi(a[i-1],a[i],a[i+1]);
			if (a[i]!=t) {
				b[i]=t;
				not_stable=1;
			}
		}
		if (!not_stable) flag=0;
		for (int i=1;i<=n;i++) a[i]=b[i];
		if (count>1000) break;
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#include<iostream>
using namespace std;

const int maxn=500000+1000;

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

int main(){
	cin >> n;
	for (int i=1;i<=n;i++) cin >> a[i];
	b[1]=b[n]=0;
	for (int i=2;i<n;i++){
		if (a[i]!=a[i-1] && a[i]!=a[i+1]) b[i]=1;
		else b[i]=0;
	}
	int s=0,e,cnt=0;
	for (int i=1;i<=n;i++){
		if (!s && b[i]) s=i;
		if (s && !b[i]){
			e=i;
			cnt=max(cnt,(e-s+1)/2);
			for (int j=s;j<e;j++){
				if (j<(s+e)/2) a[j]=a[s-1];
				else a[j]=a[e];
			}
			s=0;
		}
	}
	cout << cnt << endl;
	for (int i=1;i<n;i++) cout << a[i] << " ";
	cout << a[n] << endl;
    return 0;
}


#include<cstdio>
#include<cstring>
#include<fstream>
#include<cmath>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn],c[maxn];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int flag=1,flag2=0,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		if (count %2==1)
			for (int i=2;i<=n-1;i++){
				b[i]=a[i];
				int t=floor((a[i-1]+a[i]+a[i+1])/2);
				if (a[i]!=t) {
					b[i]=t;
					not_stable=1;
				}
			}
		if (count %2==0)
			for (int i=2;i<=n-1;i++){
				a[i]=b[i];
				int t=floor((b[i-1]+b[i]+b[i+1])/2);
				if (b[i]!=t) {
					a[i]=t;
					not_stable=1;
				}
			}
		if (!not_stable) flag=0;
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<fstream>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn],c[maxn];

int mi(int x,int y,int z){
	if (x>y){
		int t=x;x=y;y=t;
	}
	if (x>z){
		int t=x;x=z;z=t;
	}
	if (y>z){
		int t=y;y=z;z=t;
	}
	return y;
}

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int flag=1,flag2=0,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		for (int i=2;i<=n-1;i++){
			b[i]=a[i];
			int t=mi(a[i-1],a[i],a[i+1]);
			if (a[i]!=t) {
				b[i]=t;
				not_stable=1;
			}
		}
		if (count > 2000) break;
		if (!not_stable) flag=0;
		for (int i=1;i<=n;i++) a[i]=b[i];
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#include<iostream>
using namespace std;
const int maxn=500000+1000;
int n,a[maxn],b[maxn],c[maxn];

int mi(int x,int y,int z){
	if (x>y){
		int t=x;x=y;y=t;
	}
	if (x>z){
		int t=x;x=z;z=t;
	}
	if (y>z){
		int t=y;y=z;z=t;
	}
	return y;
}

int main(){
	cin >> n;
	for (int i=1;i<=n;i++) cin >> a[i];
	int flag=1,flag2=0,count=0;
	b[1]=a[1];b[n]=a[n];
	while (flag){
		++count;
		int not_stable=0;
		for (int i=2;i<=n-1;i++){
			b[i]=a[i];
			int t=mi(a[i-1],a[i],a[i+1]);
			if (a[i]!=t) {
				++c[i];
				if (c[i]>4) {
					flag2=1;
					break;
				}
				b[i]=t;
				not_stable=1;
			}
		}
		if (flag2) break;
		if (!not_stable) flag=0;
		for (int i=1;i<=n;i++) a[i]=b[i];
	}
	if (!flag) {
		printf("%d\n",--count);
		for (int i=1;i<=n-1;i++) printf("%d ",a[i]);
		printf("%d\n",a[n]);
	}
	if (flag) printf("%d\n",-1);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:100000000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <time.h>
#include <memory.h>
#include <cassert>

#define ll long long
#define ld long double
#define mp make_pair
#define pii pair<int, int>
#define pi 3.141592653589793238462643383279

ll gcd(ll a, ll b) {
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return (((a*b) / gcd(a, b))); }

ll phi(ll n){
	ll result = n;
	for (ll i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) n /= i;
			result -= result / i;
		}
	}
	if (n > 1) result -= result / n;
	return result;
}

ll binpow(ll a, ll n, ll c) {
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		res %= c;
		a *= a;
		a %= c;
		n >>= 1;
	}
	res = (res + c) % c;
	return res;
}
#define inf 100000007

#define eps 0.0001
#define ls (v << 1)
#define rs ((v << 1)+1)

void nxi(int& n){
	bool min = 0; char c; n = 0;
	while ((c = getc(stdin)) && c <= 32);
	if (c == '-') min = 1; else n = c - 48;
	while ((c = getc(stdin)) && c>32) n = (n << 3) + (n << 1) + c - 48;
	if (min) n = -n;
}

void prl(int n){
	if (n == 0) { puts("0"); return; }
	if (n<0) { putchar('-'); n = -n; }
	static int s[10];
	int top = 0;
	while (n>0) s[top++] = n % 10, n /= 10;
	while (top--) putchar(s[top] + 48);
	puts("");
}

#define x1 first
#define y1 second
#define x0 privet
#define y0 pak
#define pll pair<ll, ll>
#define X first
#define Y second
#define vi vector<ll>
#define matrix vector<vi>
#define try freagoijf

#define rank ranggggg
#define in(n) scanf("%d",&(n));
#define in2(n,m) scanf("%d %d",&(n),&(m));
#define in3(n,m,k) scanf("%d %d %d",&(n),&(m),&(k));
using namespace std;

const int nmax = 1000010;

int n, m, a[nmax], last=1, ans;

int main()
{
   //ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
   freopen("i.in", "r", stdin); //freopen("o.out", "w", stdout);
#endif
   cin.tie(NULL);
   cin >> n;
   for (int i=1; i<=n; i++) cin >> a[i];
   a[n+1]=a[n];
   for (int i=2; i<=n+1; i++){
     if (a[i]==a[i-1]){
       ans = max(ans, (i-last-1)/2);
       int l = last, r = i-1;
       while (l<r){
         a[l++] = a[last];
         a[r--] = a[i];
       }

       last = i;
     }
   }
   cout << ans << endl;
   for (int i=1; i<=n; i++) cout << a[i] << " ";
   cout << endl;

   return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:100000000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <time.h>
#include <memory.h>
#include <cassert>

#define ll long long
#define ld long double
#define mp make_pair
#define pii pair<int, int>
#define pi 3.141592653589793238462643383279

ll gcd(ll a, ll b) {
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return (((a*b) / gcd(a, b))); }

ll phi(ll n){
	ll result = n;
	for (ll i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) n /= i;
			result -= result / i;
		}
	}
	if (n > 1) result -= result / n;
	return result;
}

ll binpow(ll a, ll n, ll c) {
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		res %= c;
		a *= a;
		a %= c;
		n >>= 1;
	}
	res = (res + c) % c;
	return res;
}
#define inf 100000007

#define eps 0.0001
#define ls (v << 1)
#define rs ((v << 1)+1)

void nxi(int& n){
	bool min = 0; char c; n = 0;
	while ((c = getc(stdin)) && c <= 32);
	if (c == '-') min = 1; else n = c - 48;
	while ((c = getc(stdin)) && c>32) n = (n << 3) + (n << 1) + c - 48;
	if (min) n = -n;
}

void prl(int n){
	if (n == 0) { puts("0"); return; }
	if (n<0) { putchar('-'); n = -n; }
	static int s[10];
	int top = 0;
	while (n>0) s[top++] = n % 10, n /= 10;
	while (top--) putchar(s[top] + 48);
	puts("");
}

#define x1 first
#define y1 second
#define x0 privet
#define y0 pak
#define pll pair<ll, ll>
#define X first
#define Y second
#define vi vector<ll>
#define matrix vector<vi>
#define try freagoijf

#define rank ranggggg
#define in(n) scanf("%d",&(n));
#define in2(n,m) scanf("%d %d",&(n),&(m));
#define in3(n,m,k) scanf("%d %d %d",&(n),&(m),&(k));
using namespace std;

const int nmax = 1000010;

int n, m, a[nmax], last=1, ans;

int main()
{
   //ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
   freopen("i.in", "r", stdin); //freopen("o.out", "w", stdout);
#endif
   cin.tie(NULL);
   cin >> n;
   for (int i=1; i<=n; i++) cin >> a[i];
   a[n+1]=a[n];
   for (int i=2; i<=n+1; i++){
     if (a[i]==a[i-1]){
       ans = max(ans, (i-last)/2);
       int l = last, r = i;
       while (l<=r){
         a[l++] = a[last];
         a[r--] = a[i];
       }

       last = i-1;
     }
   }
   cout << ans << endl;
   for (int i=1; i<=n; i++) cout << a[i] << " ";
   cout << endl;

   return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:100000000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <time.h>
#include <memory.h>
#include <cassert>

#define ll long long
#define ld long double
#define mp make_pair
#define pii pair<int, int>
#define pi 3.141592653589793238462643383279

ll gcd(ll a, ll b) {
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return (((a*b) / gcd(a, b))); }

ll phi(ll n){
	ll result = n;
	for (ll i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) n /= i;
			result -= result / i;
		}
	}
	if (n > 1) result -= result / n;
	return result;
}

ll binpow(ll a, ll n, ll c) {
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		res %= c;
		a *= a;
		a %= c;
		n >>= 1;
	}
	res = (res + c) % c;
	return res;
}
#define inf 100000007

#define eps 0.0001
#define ls (v << 1)
#define rs ((v << 1)+1)

void nxi(int& n){
	bool min = 0; char c; n = 0;
	while ((c = getc(stdin)) && c <= 32);
	if (c == '-') min = 1; else n = c - 48;
	while ((c = getc(stdin)) && c>32) n = (n << 3) + (n << 1) + c - 48;
	if (min) n = -n;
}

void prl(int n){
	if (n == 0) { puts("0"); return; }
	if (n<0) { putchar('-'); n = -n; }
	static int s[10];
	int top = 0;
	while (n>0) s[top++] = n % 10, n /= 10;
	while (top--) putchar(s[top] + 48);
	puts("");
}

#define x1 first
#define y1 second
#define x0 privet
#define y0 pak
#define pll pair<ll, ll>
#define X first
#define Y second
#define vi vector<ll>
#define matrix vector<vi>
#define try freagoijf

#define rank ranggggg
#define in(n) scanf("%d",&(n));
#define in2(n,m) scanf("%d %d",&(n),&(m));
#define in3(n,m,k) scanf("%d %d %d",&(n),&(m),&(k));
using namespace std;

const int nmax = 1000010;

int n, m, a[nmax], last=1, ans;

int main()
{
   //ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
   freopen("i.in", "r", stdin); //freopen("o.out", "w", stdout);
#endif
   cin.tie(NULL);
   cin >> n;
   for (int i=1; i<=n; i++) cin >> a[i];
   a[n+1]=a[n];
   for (int i=2; i<=n+1; i++){
     if (a[i]==a[i-1]){
       ans = max(ans, (i-last-1)/2);
       int l = last, r = i;
       while (l<r){
         a[l++] = a[last];
         a[r--] = a[i];
       }

       last = i;
     }
   }
   cout << ans << endl;
   for (int i=1; i<=n; i++) cout << a[i] << " ";
   cout << endl;

   return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:100000000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <time.h>
#include <memory.h>
#include <cassert>

#define ll long long
#define ld long double
#define mp make_pair
#define pii pair<int, int>
#define pi 3.141592653589793238462643383279

ll gcd(ll a, ll b) {
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return (((a*b) / gcd(a, b))); }

ll phi(ll n){
	ll result = n;
	for (ll i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) n /= i;
			result -= result / i;
		}
	}
	if (n > 1) result -= result / n;
	return result;
}

ll binpow(ll a, ll n, ll c) {
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		res %= c;
		a *= a;
		a %= c;
		n >>= 1;
	}
	res = (res + c) % c;
	return res;
}
#define inf 100000007

#define eps 0.0001
#define ls (v << 1)
#define rs ((v << 1)+1)

void nxi(int& n){
	bool min = 0; char c; n = 0;
	while ((c = getc(stdin)) && c <= 32);
	if (c == '-') min = 1; else n = c - 48;
	while ((c = getc(stdin)) && c>32) n = (n << 3) + (n << 1) + c - 48;
	if (min) n = -n;
}

void prl(int n){
	if (n == 0) { puts("0"); return; }
	if (n<0) { putchar('-'); n = -n; }
	static int s[10];
	int top = 0;
	while (n>0) s[top++] = n % 10, n /= 10;
	while (top--) putchar(s[top] + 48);
	puts("");
}

#define x1 first
#define y1 second
#define x0 privet
#define y0 pak
#define pll pair<ll, ll>
#define X first
#define Y second
#define vi vector<ll>
#define matrix vector<vi>
#define try freagoijf

#define rank ranggggg
#define in(n) scanf("%d",&(n));
#define in2(n,m) scanf("%d %d",&(n),&(m));
#define in3(n,m,k) scanf("%d %d %d",&(n),&(m),&(k));
using namespace std;

const int nmax = 1000010;

int n, m, a[nmax], last=1, ans;

int main()
{
   //ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
   freopen("i.in", "r", stdin); //freopen("o.out", "w", stdout);
#endif
   cin.tie(NULL);
   cin >> n;
   for (int i=1; i<=n; i++) cin >> a[i];
   a[n+1]=a[n];
   for (int i=2; i<=n+1; i++){
     if (a[i]==a[i-1]){
       ans = max(ans, (i-last-1)/2);
       int l = last+1, r = i-2;
       while (l<=r){
         a[l++] = a[last];
         a[r--] = a[i];
       }

       last = i;
     }
   }
   cout << ans << endl;
   for (int i=1; i<=n; i++) cout << a[i] << " ";
   cout << endl;

   return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:100000000")
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <time.h>
#include <memory.h>
#include <cassert>

#define ll long long
#define ld long double
#define mp make_pair
#define pii pair<int, int>
#define pi 3.141592653589793238462643383279

ll gcd(ll a, ll b) {
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return (((a*b) / gcd(a, b))); }

ll phi(ll n){
	ll result = n;
	for (ll i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) n /= i;
			result -= result / i;
		}
	}
	if (n > 1) result -= result / n;
	return result;
}

ll binpow(ll a, ll n, ll c) {
	ll res = 1;
	while (n) {
		if (n & 1)
			res *= a;
		res %= c;
		a *= a;
		a %= c;
		n >>= 1;
	}
	res = (res + c) % c;
	return res;
}
#define inf 100000007

#define eps 0.0001
#define ls (v << 1)
#define rs ((v << 1)+1)

void nxi(int& n){
	bool min = 0; char c; n = 0;
	while ((c = getc(stdin)) && c <= 32);
	if (c == '-') min = 1; else n = c - 48;
	while ((c = getc(stdin)) && c>32) n = (n << 3) + (n << 1) + c - 48;
	if (min) n = -n;
}

void prl(int n){
	if (n == 0) { puts("0"); return; }
	if (n<0) { putchar('-'); n = -n; }
	static int s[10];
	int top = 0;
	while (n>0) s[top++] = n % 10, n /= 10;
	while (top--) putchar(s[top] + 48);
	puts("");
}

#define x1 first
#define y1 second
#define x0 privet
#define y0 pak
#define pll pair<ll, ll>
#define X first
#define Y second
#define vi vector<ll>
#define matrix vector<vi>
#define try freagoijf

#define rank ranggggg
#define in(n) scanf("%d",&(n));
#define in2(n,m) scanf("%d %d",&(n),&(m));
#define in3(n,m,k) scanf("%d %d %d",&(n),&(m),&(k));
using namespace std;

const int nmax = 1000010;

int n, m, a[nmax], last=1, ans;

int main()
{
   //ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
   freopen("i.in", "r", stdin); //freopen("o.out", "w", stdout);
#endif
   cin.tie(NULL);
   cin >> n;
   for (int i=1; i<=n; i++) cin >> a[i];
   a[n+1]=a[n];
   for (int i=2; i<=n+1; i++){
     if (a[i]==a[i-1]){
       ans = max(ans, (i-last-1)/2);
       int l = last, r = i;
       while (l<=r){
         a[l++] = a[last];
         a[r--] = a[i];
       }

       last = i-1;
     }
   }
   cout << ans << endl;
   for (int i=1; i<=n; i++) cout << a[i] << " ";
   cout << endl;

   return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

const ll mod1 = 13;
int hsh(vector<int> & v) {
	int h = 0;
	for (int c : v)
		h = (h*mod1 + c + 1) % mod;
	return h;
}

void nxt(vi& g1, vi& g2) {
	g2[0] = g1[0];
	int n = g2.size();
	g2[n - 1] = g1[n - 1];
	for (int i = 1; i+1 < n; i++) {
		int sum = g1[i] + g1[i - 1] + g1[i + 1];
		g2[i] = sum > 1;
	}
}

int main() {

	set<int> st;
	DI(n);
	vector<int> g1(n), g2(n);
	FI(n) {
		DI(x); g1[i] = x;
	}

	int h;
	st.insert(h = hsh(g1));
	nxt(g1, g2);
	h = hsh(g2);
	int step = 0;
	while (st.find(h) == st.end()) {
		st.insert(h);
		swap(g2, g1);
		nxt(g1, g2);
		h = hsh(g2);
		step++;
		if (clock() > 900) break;
	}
	bool y = hsh(g1) == h;
	PIN( (y) ? step : -1);
	if (y) {
		FI(n)
			PIS(g1[i]);
		cout << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

const ll mod1 = 13;

void nxt(vi& g1, vi& g2, int&l, int& r) {
	g2[0] = g1[0];
	int n = g2.size();
	g2[n - 1] = g1[n - 1];
	for (int i = l; i <= r; i++) {
		int sum = g1[i] + g1[i - 1] + g1[i + 1];
		g2[i] = sum > 1;
	}
	while (l <= r && g2[l] == g1[l]) l++;
	while (r >= l && g2[r] == g1[r]) r--;
}

int main() {

	DI(n);
	vector<int> _g1(n), _g2(n);
	vi* g1 = &_g1, *g2 = &_g2;
	FI(n) {
		DI(x); (*g1)[i] = x;
	}

	int step = 0;
	int l = 1, r = n - 2;
	while (l <= r) {
		step++;
		nxt(*g1, *g2, l, r);
		swap(g1, g2);
		if (clock() > 1900) {
			break;
		}
	}

	bool y = l>r;
	PIN( (y) ? step-1 : -1);
	if (y) {
		FI(n)
			PIS((*g1)[i]);
		cout << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

const ll mod1 = 13;
int hsh(vector<int> & v) {
	int h = 0;
	for (int c : v)
		h = (h*mod1 + c + 1) % mod;
	return h;
}

void nxt(vi& g1, vi& g2) {
	g2[0] = g1[0];
	int n = g2.size();
	g2[n - 1] = g1[n - 1];
	for (int i = 1; i+1 < n; i++) {
		int sum = g1[i] + g1[i - 1] + g1[i + 1];
		g2[i] = sum > 1;
	}
}

int main() {

	set<int> st;
	DI(n);
	vector<int> _g1(n), _g2(n);
	vi* g1 = &_g1, *g2 = &_g2;
	FI(n) {
		DI(x); (*g1)[i] = x;
	}

	int step = 0;
	int h, h2;
	h = hsh(*g1);
	while (st.find(h) == st.end()) {
		st.insert(h);
		h2 = h;
		step++;
		nxt(*g1, *g2);
		swap(g1, g2);
		h = hsh(*g1);
	}

	bool y = h2 == h;
	PIN( (y) ? step-1 : -1);
	if (y) {
		FI(n)
			PIS((*g1)[i]);
		cout << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

const ll mod1 = 13;
int hsh(vector<int> & v) {
	int h = 0;
	for (int c : v)
		h = (h*mod1 + c + 1) % mod;
	return h;
}

void nxt(vi& g1, vi& g2) {
	g2[0] = g1[0];
	int n = g2.size();
	g2[n - 1] = g1[n - 1];
	for (int i = 1; i+1 < n; i++) {
		int sum = g1[i] + g1[i - 1] + g1[i + 1];
		g2[i] = sum > 1;
	}
}

int main() {

	set<int> st;
	DI(n);
	vector<int> g1(n), g2(n);
	FI(n) {
		DI(x); g1[i] = x;
	}

	int h;
	st.insert(h = hsh(g1));
	nxt(g1, g2);
	h = hsh(g2);
	int step = 0;
	bool br = false;
	while (st.find(h) == st.end()) {
		st.insert(h);
		swap(g2, g1);
		nxt(g1, g2);
		h = hsh(g2);
		step++;
		if (clock() > 1800) {
			br = true;
			break;
		}
	}
	bool y = !br && hsh(g1) == h;
	PIN( (y) ? step : -1);
	if (y) {
		FI(n)
			PIS(g1[i]);
		cout << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

const ll mod1 = 13;
int hsh(vector<int> & v) {
	int h = 0;
	for (int c : v)
		h = (h*mod1 + c + 1) % mod;
	return h;
}

void nxt(vi& g1, vi& g2) {
	g2[0] = g1[0];
	int n = g2.size();
	g2[n - 1] = g1[n - 1];
	for (int i = 1; i+1 < n; i++) {
		int sum = g1[i] + g1[i - 1] + g1[i + 1];
		g2[i] = sum > 1;
	}
}

int main() {

	set<int> st;
	DI(n);
	vector<int> g1(n), g2(n);
	FI(n) {
		DI(x); g1[i] = x;
	}

	int step = 0;
	int h;
	st.insert(h = hsh(g1));
	nxt(g1, g2);
	h = hsh(g2);
	if (st.find(h) == st.end()) {
		step++;
		st.insert(h);
		nxt(g2, g1);
		h = hsh(g1);
		if (st.find(h) == st.end()) {
			step++;
			st.insert(h);
		}
	}
	nxt(g1, g2);

	bool y = hsh(g2) == h;
	PIN( (y) ? step : -1);
	if (y) {
		FI(n)
			PIS(g1[i]);
		cout << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

const ll mod1 = 13;
int hsh(vector<int> & v) {
	int h = 0;
	for (int c : v)
		h = (h*mod1 + c + 1) % mod;
	return h;
}

void nxt(vi& g1, vi& g2) {
	g2[0] = g1[0];
	int n = g2.size();
	g2[n - 1] = g1[n - 1];
	for (int i = 1; i+1 < n; i++) {
		int sum = g1[i] + g1[i - 1] + g1[i + 1];
		g2[i] = sum > 1;
	}
}

int main() {

	set<int> st;
	DI(n);
	vector<int> g1(n), g2(n);
	FI(n) {
		DI(x); g1[i] = x;
	}

	int step = 0;
	int h, h2;
	st.insert(h2 = hsh(g1));
	nxt(g1, g2);
	h = hsh(g2);
	if (st.find(h) == st.end()) {
		step++;
		st.insert(h);
		nxt(g2, g1);
		h2 = h;
		h = hsh(g1);
		if (st.find(h) == st.end()) {
			step++;
			st.insert(h);

			nxt(g1, g2);
			h2 = h;
			h = hsh(g2);
			if (st.find(h) == st.end()) {
				step++;
				st.insert(h);
			}
		}
	}

	bool y = h2 == h;
	PIN( (y) ? step : -1);
	if (y) {
		FI(n)
			PIS(g1[i]);
		cout << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

int a[N];
pii r[N];
pii q[N];
int len = 0;
int main() {

	DI(n);
	FI(n)  SI(a[i]);

	int f = 0;
	int c = a[0] != a[1];
	int mx = 0;
	for (int i = 1; i < n; i++) {
		if ((a[i] == a[i + 1] || i == n - 1) && c) {
			r[len++] = pii(f, i);
			f = i;
			c = 0;
		}
		else {
			if (a[i] != a[i + 1]) {
				//DB(len); DBN(i);
				c++;
				q[len].first += a[i];
				q[len].second += !a[i];
			}
			else {
				c = 0;
				f = i;
			}
			mx = max(mx, c);
		}
	}

	if (mx > 0)
		mx -= 1;

	for (int i = 0; i < len; i++) {
		int st = r[i].x, fn = r[i].y;
		//DB(st); DBN(fn);
		//DB(a[st]); DBN(a[fn]);
		if (a[st] == a[fn]) {
			for (int i = st; i <= fn; i++)
				a[i] = a[st];
		}
		else {
			int cf = q[i].x + 1, cs = q[i].y + 1;
			//DB(cf); DBN(cs);
			if (a[fn]) swap(cf, cs);
			FI(cf) a[st + i] = a[st];
			FI(cs) a[fn - i] = a[fn];
		}

	}

	cout << (mx - mx / 2) << endl;
	FI(n)
		PIS(a[i]);

	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

int a[N];
int main() {

	DI(n);
	FI(n)  SI(a[i]);

	int mx = 0, c = 0;
	int f = a[0];
	for (int i = 0; i + 1 < n; i++) {
		if (a[i] != a[i + 1]) c++;
		mx = max(mx, c);
		if (a[i] != f && a[i] == a[i + 1]) {
			f = a[i + 1];
		}
		else {
			a[i] = f;
		}
	}
	cout << (mx+1) / 2 << endl;
	FI(n) PIS(a[i]);
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

const ll mod1 = 13;
int hsh(vector<int> & v) {
	int h = 0;
	for (int c : v)
		h = (h*mod1 + c + 1) % mod;
	return h;
}

void nxt(vi& g1, vi& g2, int&l, int& r) {
	g2[0] = g1[0];
	int n = g2.size();
	g2[n - 1] = g1[n - 1];
	for (int i = l; i <= r; i++) {
		int sum = g1[i] + g1[i - 1] + g1[i + 1];
		g2[i] = sum > 1;
	}
	while (l < n && g2[l] == g1[l]) l++;
	while (r && g2[r] == g1[r]) r--;
}

int main() {

	set<int> st;
	DI(n);
	vector<int> _g1(n), _g2(n);
	vi* g1 = &_g1, *g2 = &_g2;
	FI(n) {
		DI(x); (*g1)[i] = x;
	}

	int step = 0;
	int h, h2;
	h = hsh(*g1);
	int l = 1, r = n - 2;
	while (st.find(h) == st.end()) {
		st.insert(h);
		h2 = h;
		step++;
		nxt(*g1, *g2, l, r);
		swap(g1, g2);
		h = hsh(*g1);
	}

	bool y = h2 == h;
	PIN( (y) ? step-1 : -1);
	if (y) {
		FI(n)
			PIS((*g1)[i]);
		cout << endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

int a[N];
int main() {

	DI(n);
	FI(n)  SI(a[i]);

	int mx = 0, c = 0;
	int f = a[0];
	for (int i = 0; i + 1 < n; i++) {
		if (a[i] != a[i + 1]) c++;
		mx = max(mx, c);
		if (a[i] != f && a[i] == a[i + 1]) {
			f = a[i + 1];
		}
		else {
			a[i] = f;
		}
	}
	cout << mx / 2 << endl;
	FI(n) PIS(a[i]);
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

int a[N];
int main() {

	DI(n);
	FI(n)  SI(a[i]);

	int mx = 0, c = 0;
	int f = a[0];
	for (int i = 0; i + 1 < n; i++) {
		if (a[i] != a[i + 1]) c++;
		mx = max(mx, c);
		if (a[i] != f && a[i] == a[i + 1]) {
			f = a[i + 1];
		}
		else {
			a[i] = f;
		}
	}
	cout << (mx+1-mx%2) / 2 << endl;
	FI(n) PIS(a[i]);
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 500101;

int a[N];
pii r[N];
pii q[N];
int len = 0;
int main() {

	DI(n);
	FI(n)  SI(a[i]);

	int f = 0;
	int c = a[0] != a[1];
	int mx = 0;
	for (int i = 1; i < n; i++) {
		if ((a[i] == a[i + 1] || i == n - 1) && c) {
			r[len++] = pii(f, i);
			f = i;
			c = 0;
		}
		else {
			if (a[i] != a[i + 1]) {
				//DB(len); DBN(i);
				c++;
				q[len].first += a[i];
				q[len].second += !a[i];
			}
			else {
				c = 0;
				f = i;
			}
			mx = max(mx, c);
		}
	}

	if (mx > 0)
		mx -= 1;

	for (int i = 0; i < len; i++) {
		int st = r[i].x, fn = r[i].y;
		//DB(st); DBN(fn);
		//DB(a[st]); DBN(a[fn]);
		if (a[st] == a[fn]) {
			for (int i = st; i <= fn; i++)
				a[i] = a[st];
		}
		else {
			int cf = q[i].x + 1, cs = q[i].y + 1;
			//DB(cf); DBN(cs);
			if (a[fn]) swap(cf, cs);
			FI(cf) a[st + i] = a[st];
			FI(cs) a[fn - i] = a[fn];
		}

	}

	cout << (mx - mx / 2) << endl;
	FI(n)
		PIS(a[i]);

	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

int a[N];
int main() {

	DI(n);
	FI(n)  SI(a[i]);

	int mx = 0, c = 0;
	int f = a[0];
	for (int i = 0; i + 1 < n; i++) {
		if (a[i] != a[i + 1]) c++;
		else c = 0;
		mx = max(mx, c);
		if (a[i] != f && a[i] == a[i + 1]) {
			f = a[i + 1];
		}
		else {
			a[i] = f;
		}
	}
	cout << (mx + 1 - mx % 2) / 2 << endl;
	FI(n) PIS(a[i]);
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <vector>
#include <ctime>
#include <cstring>
#include <sstream>

//#include <unordered_map>

using namespace std;

//types
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<pii> vpii;

// for
#define FI(n) for(int i=0; i<n; i++)
#define FI1(n) for(int i=1; i<=n; i++)
#define FJ(n) for(int j=0; j<n; j++)
#define FJ1(n) for(int j=1; j<=n; j++)
#define FK(n) for(int k=0; k<n; k++)
#define FU(i, n) for (int i=0; i<n; i++)
#define F(i, s, e) for (int i=s; i<=e; i++)

//scanf types
#define SI(x) scanf("%d", &x)
#define SII(x, y) scanf("%d %d", &x, &y)
#define SIII(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define SIIII(x, y, z, t) scanf("%d %d %d %d", &x, &y, &z, &t)
#define SD(x) scanf("%lf", &x)
#define SP(x) scanf("%d %d", &x.first, &x.second)
#define SS(x) scanf("%s", &x)
#define SA(x, n) FI(n) SI(x[i])
#define SAA(x, n, m) FI(n) FJ(m) SI(x[i][j])

#define Tests(t) int t; SI(t); for(int test=1; test<=t; test++)
#define WS(n) int n; while(SI(n) != EOF)

//scanf with def
#define DI(x) int x; SI(x)
#define DII(x, y) int x, y; SII(x, y);
#define DIII(x, y, z) int x, y, z; SIII(x, y, z);
#define DD(x) double x; SD(x)
#define DS(x) string s; cin>>s
#define DA(a, n) int n; SI(n); SA(a, n);
#define DA2(a, n) int n; SI(n); SAA(a, n, n)
#define DAA(a, n, m) int n, m; SII(n, m); SAA(a, n, m)
#define TESTS DI(tests); FU(test, tests)

//input & files
#define FR(x) freopen(x, "rt", stdin)
#define FW(x) freopen(x, "wt", stdout)
#define FRW(x, y) FR(x); FW(y)
#define UNSYNC() ios::sync_with_stdio(false)

//output && db
#define DB(x) cout<<#x<<" = "<<(x)<<" ";
#define DBN(x) cout<<#x<<" = "<<(x)<<"\n";
#define DBA(x, n) {cout<<#x<<" = [ "; FI(n) cout<<x[i]<<((i+1==n)?" ]":", ");}
#define DS(x) {cout<<#x<<" = [ "; int i = 0, n = x.size(); for(auto x:c) { cout<<x[i]<<((i+1==n)?" ]":", "); i++;}}

#define PI(x) printf("%d", x)
#define PIS(x) printf("%d ", x)
#define PIN(x) printf("%d\n", x)
#define PA(x, n) {FI(n) if (i+1==n) PIN(x[i]); else PIS(x[i]);}
#define PS(x) for (auto it: x) cout<<it<<" ";
#define PLN() putchar('\n');

#define D_EQ(l, r, p) (r-l <= p)
#define D_EQ6(l, r) D_EQ(l, r, 1e-6)
#define D_EQ9(l, r) D_EQ(l, r, 1e-9)

//consts
const int INF = 1000001000;
const int mod = 1000 * 1000 * 1000 + 7;
const double PI = 3.1415926535897932;

//pair
#define x first
#define y second

//functions
double sqr(double x) { return x*x; };
ld sqr(ld x) { return x*x; };
ll sqr(ll x) { return x*x; };
ll sqr(int x) { return x * 1LL * x; };

//functions
ll gcd(ll a, ll b) { while (b) a %= b, swap(a, b); return a; }
ll bpm(ll a, ll n = -2, ll m = mod) { n = n >= 0 ? n : m + n; ll r = 1; while (n) { if (n & 1) r = (r*a) % m; a = (a*a) % m; n >>= 1; } return r; }

//operators
std::ostream& operator << (std::ostream& os, pii p) {
	return os << "{" << p.x << " " << p.y << "}";
}

const int N = 100101;

const ll mod1 = 13;
int hsh(vector<int> & v) {
	int h = 0;
	for (int c : v)
		h = (h*mod1 + c + 1) % mod;
	return h;
}

void nxt(vi& g1, vi& g2) {
	g2[0] = g1[0];
	int n = g2.size();
	g2[n - 1] = g1[n - 1];
	for (int i = 1; i+1 < n; i++) {
		int sum = g1[i] + g1[i - 1] + g1[i + 1];
		g2[i] = sum > 1;
	}
}

int main() {

	set<int> st;
	DI(n);
	vector<int> g1(n), g2(n);
	FI(n) {
		DI(x); g1[i] = x;
	}

	int h;
	st.insert(h = hsh(g1));
	nxt(g1, g2);
	h = hsh(g2);
	int step = 0;
	while (st.find(h) == st.end()) {
		st.insert(h);
		swap(g2, g1);
		nxt(g1, g2);
		h = hsh(g2);
		step++;
	}
	bool y = hsh(g1) == h;
	PIN( (y) ? step : -1);
	if (y) {
		FI(n)
			PIS(g1[i]);
		cout << endl;
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int q[500005];
int qwe(int l, int r)
{
    int len=r-l+1;
    if(len<3) return 0;
    int mid=(l+r)/2;
    for(int i=l+1;i<=mid;i++) q[i]=q[l];
    for(int i=mid+1;i<r;i++) q[i]=q[r];
    return (len-1)/2;
}
int main()
{
    int n,i,j,k;
    while(~scanf("%d",&n))
    {
        int ans=0;
        for(i=1;i<=n;i++) scanf("%d",&q[i]);
        k=1;
        for(j=1;j<n;j++)
        {
            if(q[j]==q[j+1])
            {
                ans=max(ans,qwe(k,j));
                //cout<<ans<<endl;
                k=j+1;
            }
        }
        ans=max(ans,qwe(k,n));
        //cout<<qwe(1,n)<<endl;
        //cout<<ans<<endl;
        printf("%d\n",ans);
        for(i=1;i<=n;i++) printf("%d ",q[i]);
        puts("");
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int q[500005];
int qwe(int l, int r)
{
    int len=r-l+1;
    if(len<3) return 0;
    int mid=(l+r)/2;
    for(int i=l+1;i<=mid;i++) q[i]=q[l];
    for(int i=mid+1;i<r;i++) q[i]=q[r];
    return (len-1)/2;
}
int main()
{
    int n,i,j,k;
    while(~scanf("%d",&n))
    {
        int ans=0;
        for(i=1;i<=n;i++) scanf("%d",&q[i]);
        k=1;
        for(j=1;j<n;j++)
        {
            if(q[j]==q[j+1])
            {
                ans=max(ans,qwe(k,j));
                k=j+1;
            }
        }
        ans=max(ans,qwe(1,n));
        printf("%d\n",ans);
        for(i=1;i<=n;i++) printf("%d ",q[i]);
        puts("");
    }
    return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define f first
#define s second

const int MOD = 1000000007;
const int MAX = 10000005;

struct clump {
	int begin, end, num;
};

vector<clump> ca;
int n, sequence[500002], max1;

int main() {
	cin >> n >> sequence[0];
	sequence[1] = sequence[0];
	FOR(i,2,n+1) cin >> sequence[i];
	sequence[n+1] = sequence[n];
	F0R(i,n+1) {
		if (sequence[i] == sequence[i+1]) {
			clump asdf;
			asdf.begin = i;
			asdf.num = sequence[i];
			while (sequence[i+1] == sequence[i] && i <= n) i++;
			asdf.end = i;
			ca.pb(asdf);
		}
	}

	F0R(i, ca.size()-1) if ((ca[i+1].begin-ca[i].end-1)>max1) max1 = (ca[i+1].begin-ca[i].end-1);
	max1 = (max1+1)/2;
	for (int i = ca.size()-1; i>0; --i) {
		if (ca[i].num == ca[i-1].num) {
			ca[i-1].end = ca[i].end;
			ca.erase(ca.begin()+i);
		}
	}

	F0R(i, ca.size()-1) {
		int x = ca[i].end;
		ca[i].end = (ca[i].end+ca[i+1].begin)/2;
		ca[i+1].begin = (x+ca[i+1].begin)/2+1;
	}
	ca[0].begin = 1;
	ca[ca.size()-1].end = n;
	cout << max1 << endl;
	F0R(i, ca.size()) FOR(j,ca[i].begin, ca[i].end+1) printf("%d ",ca[i].num);
	return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define f first
#define s second

const int MOD = 1000000007;
const int MAXN = 505050;

int N, arr[MAXN];

int modify(int l, int r) {
  if(l == r) return 0;
  if(arr[l] == arr[r]) {
    for(int i=l+1; i<r; i++)
      arr[i] = arr[l];
    return (r-l)/2;
  } else {
    int m = (l+r+1)/2;
    FOR(i,l+1,m) arr[i] = arr[l];
    FOR(i,m,r) arr[i] = arr[r];
    return (r-l-1)/2;
  }
}

int main() {
  cin>>N;
  F0R(i,N) cin>>arr[i];

  int ans = 0, lb = 0;
  F0R(i,N) {
    if(i == N-1 || arr[i] == arr[i+1]) {
      ans = max(ans, modify(lb, i));
      lb = i+1;
    }
  }
  cout<<ans<<"\n";
  F0R(i,N)  cout<<arr[i]<<(i==N-1 ? "\n" : " ");
  return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define f first
#define s second

const int MOD = 1000000007;
const int MAX = 10000005;

struct clump {
	int begin, end, num;
};

vector<clump> ca;
int n, sequence[500002];

int main() {
	cin >> n >> sequence[0];
	sequence[1] = sequence[0];
	FOR(i,2,n+1) cin >> sequence[i];
	sequence[n+1] = sequence[n];
	F0R(i,n+1) {
		if (sequence[i] == sequence[i+1]) {
			clump asdf;
			asdf.begin = i;
			asdf.num = sequence[i];
			while (sequence[i+1] == sequence[i] && i <= n) i++;
			asdf.end = i;
			ca.pb(asdf);
		}
	}

	int max1 = 0;
	F0R(i, ca.size()-1) if ((ca[i+1].begin-ca[i].end-1)>max1) max1 = (ca[i+1].begin-ca[i].end-1);
	max1 = (max1+1)/2;
	// cout << max1 << endl;
	for (int i = ca.size()-1; i>0; --i) {
		if (ca[i].num == ca[i-1].num) {
			ca[i-1].end = ca[i].end;
			ca.erase(ca.begin()+i);
		}
	}

	F0R(i, ca.size()-1) {
		int x = ca[i].end;
		ca[i].end = (ca[i].end+ca[i+1].begin)/2;
		ca[i+1].begin = (x+ca[i+1].begin)/2+1;
	}
	ca[0].begin = 1;
	ca[ca.size()-1].end = n;
	// cout << ca[0].begin << " " << ca[0].end << " " << ca[1].begin << " " << ca[1].end << " " << ca[2].begin << " " << ca[2].end;
	F0R(i, ca.size()) FOR(j,ca[i].begin, ca[i].end+1) cout << ca[i].num << " ";
	return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define f first
#define s second

const int MOD = 1000000007;
const int MAX = 505050;

int N;, arr[MAXN];

int modify(int l, int r) {
  if(l == r) return 0;
  if(arr[l] == arr[r]) {
    for(int i=l+1; i<r; i++)
      arr[i] = arr[l];
    return (r-l)/2;
  } else {
    int m = (l+r+1)/2;
    FOR(i,l+1,m) arr[i] = arr[l];
    FOR(i,m,r) arr[i] = arr[r];
    return (r-l-1)/2;
  }
}

int main() {
  cin>>N;
  F0R(i,n) cin>>arr[i];

  int ans = 0, lb = 0;
  F0R(i,n) {
    if(i == N-1 || arr[i] == arr[i+1]) {
      ans = max(ans, modify(lb, i));
      lb = i+1;
    }
  }
  cout<<ans<<"\n";
  F0R(i,n)  cout<<arr[i]<<(i==N-1 ? "\n" : " ");
  return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define f first
#define s second

const int MOD = 1000000007;
const int MAX = 10000005;

struct clump {
	int begin, end, num;
};

vector<clump> ca;
int n, sequence[500002];

int main() {
	cin >> n >> sequence[0];
	sequence[1] = sequence[0];
	FOR(i,2,n+1) cin >> sequence[i];
	sequence[n+1] = sequence[n];
	F0R(i,n+1) {
		if (sequence[i] == sequence[i+1]) {
			clump asdf;
			asdf.begin = i;
			asdf.num = sequence[i];
			while (sequence[i+1] == sequence[i] && i <= n) i++;
			asdf.end = i;
			ca.pb(asdf);
		}
	}

	int max1 = 0;
	F0R(i, ca.size()-1) if ((ca[i+1].begin-ca[i].end-1)>max1) max1 = (ca[i+1].begin-ca[i].end-1);
	max1 = (max1+1)/2;
	cout << max1 << endl;
	for (int i = ca.size()-1; i>0; --i) {
		if (ca[i].num == ca[i-1].num) {
			ca[i-1].end = ca[i].end;
			ca.erase(ca.begin()+i);
		}
	}

	F0R(i, ca.size()-1) {
		ca[i].end = (ca[i].end+ca[i+1].begin)/2;
		ca[i+1].begin = (ca[i].end+ca[i+1].begin)/2+1;
	}
	ca[0].begin = 1;
	ca[ca.size()-1].end = n;
	F0R(i, ca.size()) FOR(j,ca[i].begin, ca[i].end+1) cout << ca[i].num << " ";
	return 0;
}


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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define vi vector<int>

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define f first
#define s second

const int MOD = 1000000007;
const int MAX = 505050;

int N, arr[MAXN];

int modify(int l, int r) {
  if(l == r) return 0;
  if(arr[l] == arr[r]) {
    for(int i=l+1; i<r; i++)
      arr[i] = arr[l];
    return (r-l)/2;
  } else {
    int m = (l+r+1)/2;
    FOR(i,l+1,m) arr[i] = arr[l];
    FOR(i,m,r) arr[i] = arr[r];
    return (r-l-1)/2;
  }
}

int main() {
  cin>>N;
  F0R(i,n) cin>>arr[i];

  int ans = 0, lb = 0;
  F0R(i,n) {
    if(i == N-1 || arr[i] == arr[i+1]) {
      ans = max(ans, modify(lb, i));
      lb = i+1;
    }
  }
  cout<<ans<<"\n";
  F0R(i,n)  cout<<arr[i]<<(i==N-1 ? "\n" : " ");
  return 0;
}


// Author : Naresh Bharasagar
// Instt. : Indian Institute of Technology Guwahati

//--------------------------------------------------------------------------------------------------------------------------------

#include<bits/stdc++.h>
using namespace std;
typedef long long int loo;
typedef long double ld;

#pragma GCC target ("sse4.2")
#define loop(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define loopset(it,val,dtype) for(set<dtype>::iterator it=val.begin(); it!=val.end(); it++)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vloo vector<loo>
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
#define ploo pair<loo,loo>
#define fillz(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define outa(a,n) loop(i,0,n) cout << a[i] << " ";
#define pr(a) cout << a << "\n";
#define pb(l) push_back(l)
#define ff first
#define ss second
#define input(a) for(auto &i: a) cin >> i;
#define deb(i) cout << "[" << #i << "=" << i << "]" << endl;
#define nl cout << "\n";
#define INF 1000000000
#define M 1000000007

loo power(loo x, loo y, loo p) {
    loo res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1) res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

bool sortbysec(const pair<loo,loo> &a, const pair<loo,loo> &b) {
    return (a.second > b.second);
}

string decToBin(loo n) {
	string s = "0";
	if(n == 0) return s;
	s = "";
    while (n > 0) {
        s += (n % 2) + '0';
        n = n / 2;
    }
    reverse(s.begin(), s.end());
    return s;
}

loo binToDec(string s) {
    loo ans = 0;
    reverse(s.begin(), s.end());
    loop(i, 0, s.size()) ans += pow(2, i)*(s[i] - '0');
    return ans;
}

loo nCr(loo n, loo r) {
    loo p = 1, k = 1;
    if (n - r < r)
        r = n - r;
    if (r != 0) {
        while (r) {
            p *= n;
            k *= r;
            loo m = __gcd(p, k);
            p /= m;
            k /= m;
            n--;
            r--;
        }
    }
    else p = 1;
    return p;
}

// vector<int> dist;
vector<bool> vis(100001,false);
void dfs(vector<loo> adj[], loo src) {
    vis[src]=true;
    loop(i,0,adj[src].size()) {
        loo x = adj[src][i];
        if(vis[x]==false) {
            vis[x]=true;
            // dist[x] = dist[src]+1;
            dfs(adj,x);
        }
    }
}

// vector<loo> sg(100001,-1); //prev
void bfs(vector<loo> adj[], loo src) {
    list<loo> ql;
    vis[src]=true;
    ql.pb(src);
    while(!(ql.empty())) {
        src = ql.front();
        // cout << src << " ";
        ql.pop_front();

        loop(i,0,adj[src].size()) {
            if(!vis[adj[src][i]]) {
                vis[adj[src][i]]=true;
                // sg[adj[src][i]]=src;
                ql.pb(adj[src][i]);
            }
        }
    }
}

// ----------------------------------------------------------------
vloo prf(10000), suf(10000), res(10000);
void solve() {
    loo n,m;
    cin >> n >> m;
    loop(i,0,n) {
        bitset<10000> grid,igrid;
        cin >> grid;
        if(grid.none()) {
            cout << -1 << "\n";
            return;
        }
        loo prev=-1;
        loop(k,0,2*m) {
            if(grid[k%m]==1) prev=k%m,prf[k%m]=0;
            else if(prev!=-1) prf[k%m]=((k%m)-prev+m)%m;
        }
        loop(j,0,m) igrid[m-j-1]=grid[j];
        prev=-1;
        loop(k,0,2*m) {
            if(igrid[k%m]==1) prev=k%m,suf[k%m]=0;
            else if(prev!=-1) suf[k%m]=((k%m)-prev+m)%m;
        }
        loop(j,0,m) res[j]+=min(prf[j],suf[m-j-1]);
    }
    loo mn = res[0];
    loop(i,1,m) mn=min(mn,res[i]);
    pr(mn);
}

int main() {
	fast_io

    // freopen("validation_input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

    loo q = 1;
    // cin >> q;
    while(q--) {
        solve();
    }

    return 0;
}