A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya liked the idea of the method very much, and he decided to try it in practice.

Applying the simplest variant of median smoothing to the sequence of numbers a_1, a_2, ..., a_{n} will result a new sequence b_1, b_2, ..., b_{n} obtained by the following algorithm:  b_1 = a_1, b_{n} = a_{n}, that is, the first and the last number of the new sequence match the corresponding numbers of the original sequence.  For i = 2, ..., n - 1 value b_{i} is equal to the median of three values a_{i} - 1, a_{i} and a_{i} + 1. 

The median of a set of three numbers is the number that goes on the second place, when these three numbers are written in the non-decreasing order. For example, the median of the set 5, 1, 2 is number 2, and the median of set 1, 0, 1 is equal to 1.

In order to make the task easier, Vasya decided to apply the method to sequences consisting of zeros and ones only.

Having made the procedure once, Vasya looked at the resulting sequence and thought: what if I apply the algorithm to it once again, and then apply it to the next result, and so on? Vasya tried a couple of examples and found out that after some number of median smoothing algorithm applications the sequence can stop changing. We say that the sequence is stable, if it does not change when the median smoothing is applied to it.

Now Vasya wonders, whether the sequence always eventually becomes stable. He asks you to write a program that, given a sequence of zeros and ones, will determine whether it ever becomes stable. Moreover, if it ever becomes stable, then you should determine what will it look like and how many times one needs to apply the median smoothing algorithm to initial sequence in order to obtain a stable one.


-----Input-----

The first input line of the input contains a single integer n (3 ≤ n ≤ 500 000) — the length of the initial sequence.

The next line contains n integers a_1, a_2, ..., a_{n} (a_{i} = 0 or a_{i} = 1), giving the initial sequence itself.


-----Output-----

If the sequence will never become stable, print a single number  - 1.

Otherwise, first print a single integer — the minimum number of times one needs to apply the median smoothing algorithm to the initial sequence before it becomes is stable. In the second line print n numbers separated by a space  — the resulting sequence itself.


-----Examples-----
Input
4
0 0 1 1

Output
0
0 0 1 1

Input
5
0 1 0 1 0

Output
2
0 0 0 0 0



-----Note-----

In the second sample the stabilization occurs in two steps: $01010 \rightarrow 00100 \rightarrow 00000$, and the sequence 00000 is obviously stable.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Implementation


Solutions:
n = int(input())
a = list(map(int, input().split()))
steps = 0
i = 0
b = [None] * n
while i < n - 1:
	j = i
	while j < n - 1 and a[j] != a[j + 1]:
		j += 1
	span = j - i + 1
	half_span = span // 2
	for k in range(i, i + half_span):
		b[k] = a[i]
	for k in range(i + half_span, i + span):
		b[k] = a[j]
	steps = max(steps, (span - 1) // 2)
	i = j + 1
	if i == n - 1:
		b[i] = a[i]
print(steps)
print(' '.join(map(str, b)))


from sys import stdin
n = int(stdin.readline())
seq = stdin.readline().split()
carry = seq[0]
result = [carry]
mark = False
cur_len = 0
max_len = 0
i = 1
while i < len(seq) - 1:
	if mark:
		if seq[i] != seq[i + 1]:
			cur_len += 1
		else:
			if cur_len > max_len:
				max_len = cur_len
			if seq[i] == carry:
				result.extend([carry] * cur_len)
			else:
				result.extend([carry] * (cur_len // 2))
				result.extend([seq[i]] * (cur_len // 2))
			result.append(seq[i])
			mark = False
			cur_len = 0
	elif seq[i] != seq[i - 1] and seq[i] != seq[i + 1]:
		mark = True
		cur_len = 1
		carry = seq[i - 1]
	else:
		result.append(seq[i])
	i += 1
if mark:
	if cur_len > max_len:
		max_len = cur_len
	if seq[i] == carry:
		result.extend([carry] * cur_len)
	else:
		result.extend([carry] * (cur_len // 2))
		result.extend([seq[i]] * (cur_len // 2))
result.append(seq[i])
print((max_len + 1) // 2)
for x in result:
	print(x, end=' ')


import itertools as it
import functools
import operator
import collections
import math
import sys

def reduce_consec(xs):
	result = []
	stack = []
	for x in xs:
		if stack:
			if stack[-1] + 1 == x:
				stack.append(x)
			else:
				result.append((stack[0], len(stack)))
				stack = [x]
		else:
			stack.append(x)
	if stack:
		result.append((stack[0], len(stack)))
	return result

def solve(xs, n):
	zigzag = []
	for (i, x) in enumerate(xs):
		if i == 0 or i == n - 1:
			continue
		if xs[i - 1] != x and xs[i + 1] != x:
			zigzag.append(i)
	zigzag_start_length_pairs = reduce_consec(zigzag)
	count = 0
	result = xs[:]
	for (i, n) in zigzag_start_length_pairs:
		nHalf = n // 2
		count = max(count, (n + 1) // 2)
		if n % 2 == 0:
			for j in range(i, i + nHalf):
				result[j] = xs[i - 1]
			for j in range(i + nHalf, i + n):
				result[j] = 1 - xs[i - 1]
		else:
			for j in range(i, i + n):
				result[j] = xs[i - 1]
	return (count, result)

def solve0(xs, n):

	def transform(ps):
		result = []
		for i in range(n):
			if i == 0 or i == n - 1:
				result.append(ps[i])
			else:
				median = int(sum(ps[i - 1:i + 2]) >= 2)
				result.append(median)
		return tuple(result)
	xs = tuple(xs)
	seen = set()
	seen.add(xs)
	ys = transform(xs)
	count = 0
	while ys != xs:
		if ys in seen:
			return (-1, xs)
		xs = ys
		seen.add(xs)
		count += 1
		ys = transform(xs)
	return (count, xs)

def print_stderr(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def main():
	n = int(input())
	xs = [int(i) for i in input().strip().split()]
	(count, seq) = solve(xs, n)
	print(count)
	print(' '.join((str(n) for n in seq)))
main()


n = int(input())
a = list(map(int, input().split()))
cnt = 0
cur = a[0]
ind = []
i = 0
ind.append((0, 0))
while i < len(a):
	left = i
	right = i
	while i + 1 < len(a) and cur != a[i + 1]:
		cur = a[i + 1]
		i += 1
		right += 1
	ind.append((left, right))
	i += 1
maxn = 0
ind.append((len(a) - 1, len(a) - 1))
for i in range(len(ind)):
	if (ind[i][1] - ind[i][0]) // 2 > maxn:
		maxn = (ind[i][1] - ind[i][0]) // 2
print(maxn)
for i in range(1, len(ind) - 1):
	if a[ind[i - 1][1]] == a[ind[i + 1][0]]:
		for j in range(ind[i][0], ind[i][1] + 1):
			print(a[ind[i - 1][1]], end=' ')
	else:
		for j in range(ind[i][0], (ind[i][0] + ind[i][1] + 1) // 2):
			print(a[ind[i - 1][1]], end=' ')
		for j in range((ind[i][0] + ind[i][1] + 1) // 2, ind[i][1] + 1):
			print(a[ind[i + 1][0]], end=' ')


n = int(input())
b = [int(t) for t in input().strip().split()]
a = b + [b[-1]]
current = 1
is_alternating = False
break_points = []
for current in range(1, len(a)):
	if a[current] != a[current - 1] and is_alternating == False:
		break_points.append(current - 1)
		is_alternating = True
	elif a[current] == a[current - 1] and is_alternating == True:
		break_points.append(current - 1)
		is_alternating = False
k = 0
for i in range(len(break_points) // 2):
	p = break_points[2 * i]
	q = break_points[2 * i + 1]
	if a[p] == a[q]:
		k = max([k, (q - p + 1 - 1) // 2])
		for j in range(p, q):
			a[j] = a[p]
	elif a[p] != a[q]:
		k = max([k, (q - p + 1 - 2) // 2])
		for j in range(p, (p + q + 1) // 2):
			a[j] = a[p]
		for j in range((p + q + 1) // 2, q):
			a[j] = a[q]
print(k)
print(' '.join([str(t) for t in a[:-1]]))


def solve():
	N = int(input())
	A = list(map(int, input().split()))
	A.append(A[-1])
	ma = 0
	s = p = 0
	for i in range(1, len(A)):
		if A[i] != A[p]:
			p = i
			continue
		else:
			e = p
			ma = max(ma, (p - s) // 2)
			if A[s] == A[e]:
				for j in range(s, e):
					A[j] = A[s]
			else:
				l = (p - s + 1) // 2
				for j in range(1, l):
					A[s + j] = A[s]
					A[e - j] = A[e]
			s = i
	A.pop()
	print(ma)
	print(' '.join(map(str, A)))
solve()


def modinv(n, p):
	return pow(n, p - 2, p)
import math

def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	temp = [1] * n
	for i in range(1, n):
		if a[i] != a[i - 1]:
			temp[i] = temp[i - 1] + 1
		else:
			temp[i] = 1
	print((max(temp) - 1) // 2)
	temp2 = [-1] * n
	i = 0
	while i < n:
		if a[i] == 0:
			j = i
			while j + 2 < n and a[j + 1] == 1 and (a[j + 2] == 0):
				j += 2
			if j == n - 1 or a[j + 1] == 0:
				while i <= j:
					temp2[i] = 0
					i += 1
			else:
				l = j - i + 1
				m = i + l // 2
				while i <= m:
					temp2[i] = 0
					i += 1
				while i <= j:
					temp2[i] = 1
					i += 1
		else:
			j = i
			while j + 2 < n and a[j + 1] == 0 and (a[j + 2] == 1):
				j += 2
			if j == n - 1 or a[j + 1] == 1:
				while i <= j:
					temp2[i] = 1
					i += 1
			else:
				l = j - i + 1
				m = i + l // 2
				while i <= m:
					temp2[i] = 1
					i += 1
				while i <= j:
					temp2[i] = 0
					i += 1
	print(*temp2)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
a = list(map(int, input().split()))
a = [a[0]] + a[:] + [a[-1]]
b = a[:]
cur = 0
ans = 0
c1 = c2 = -1
for i in range(1, n + 2):
	if a[i] != a[i - 1]:
		if cur == 0:
			c1 = a[i - 1]
		cur += 1
		ans = max(ans, cur // 2)
	elif cur:
		c2 = a[i - 1]
		if cur % 2 == 0:
			for j in range(i - cur, i - 1):
				b[j] = c1
		else:
			mid = i - cur // 2 - 1
			for j in range(i - cur, i - 1):
				b[j] = c1 if j < mid else c2
		cur = 0
print(ans)
print(*b[1:-1])


from math import ceil
n = int(input())
arr = list(map(int, input().split()))
narr = [True]
for i in range(1, n - 1):
	x = arr[i]
	narr.append(x == arr[i - 1] or x == arr[i + 1])
narr.append(True)
cnt = 0
mc = 0
for x in narr:
	if not x:
		cnt += 1
	if x and cnt:
		mc = max(mc, cnt)
		cnt = 0
if cnt:
	mc = max(mc, cnt)
print(ceil(mc / 2))
ss = None
for (i, x) in enumerate(arr):
	if not narr[i]:
		if ss is None:
			ss = i
	elif ss is not None:
		if arr[ss - 1] == x:
			for j in range(ss, i):
				arr[j] = x
		else:
			for j in range(ss, i):
				arr[j] = arr[ss - 1] if j < (i + ss) / 2 else x
		ss = None
print(*arr)


def main():
	(n, l) = (int(input()), input().split())
	(x, a) = ([False] * n, l[0])
	for (i, b) in enumerate(l):
		if a == b:
			x[i] = x[i - 1] = True
		a = b
	b = 0
	for (i, a) in enumerate(x):
		if a:
			if b:
				if b & 1:
					a = l[i]
					for j in range(i - b, i):
						l[j] = a
				else:
					a = l[i - 1]
					for j in range(i - b, i - b // 2 + 1):
						l[j] = a
					a = l[i]
					for j in range(j, i):
						l[j] = a
				b = 0
		else:
			b += 1
		x[i] = b
	print((max(x) + 1) // 2)
	print(' '.join(l))
main()


def reduce_consec(iterable):
	stack = []
	for x in iterable:
		if stack:
			if stack[-1] + 1 == x:
				stack.append(x)
			else:
				yield (stack[0], len(stack))
				stack = [x]
		else:
			stack.append(x)
	if stack:
		yield (stack[0], len(stack))

def alternating_indices(xs):
	for (i, x) in enumerate(xs):
		if i == 0 or i == len(xs) - 1:
			continue
		if xs[i - 1] != x and xs[i + 1] != x:
			yield i

def solve(xs, n):
	zigzag = alternating_indices(xs)
	zigzag_start_length_pairs = reduce_consec(zigzag)
	count = 0
	result = xs[:]
	for (i, n) in zigzag_start_length_pairs:
		n_half = n // 2
		count = max(count, (n + 1) // 2)
		if n % 2 == 0:
			for j in range(i, i + n_half):
				result[j] = xs[i - 1]
			for j in range(i + n_half, i + n):
				result[j] = 1 - xs[i - 1]
		else:
			for j in range(i, i + n):
				result[j] = xs[i - 1]
	return (count, result)

def solve_bruteforce(xs, n):

	def transform(ps):
		result = []
		for i in range(n):
			if i == 0 or i == n - 1:
				result.append(ps[i])
			else:
				median = int(sum(ps[i - 1:i + 2]) >= 2)
				result.append(median)
		return tuple(result)
	xs = tuple(xs)
	seen = set()
	seen.add(xs)
	ys = transform(xs)
	count = 0
	while ys != xs:
		if ys in seen:
			return (-1, xs)
		xs = ys
		seen.add(xs)
		count += 1
		ys = transform(xs)
	return (count, xs)

def main():
	n = int(input())
	xs = [int(i) for i in input().strip().split()]
	(count, seq) = solve(xs, n)
	print(count)
	print(' '.join((str(n) for n in seq)))
main()


n = int(input())
a = [i for i in input().split()]

def change(l, r):
	global a
	if l == r:
		return 0
	if a[l] == a[r]:
		for i in range(l + 1, r):
			a[i] = a[l]
		return (r - l) // 2
	else:
		m = (l + r + 1) // 2
		for i in range(l + 1, m):
			a[i] = a[l]
		for i in range(m, r):
			a[i] = a[r]
		return (r - l - 1) // 2
answ = 0
current = 0
for i in range(n):
	if i == n - 1 or a[i] == a[i + 1]:
		answ = max(answ, change(current, i))
		current = i + 1
print(answ)
print(' '.join(a))


import sys
lines = sys.stdin.readlines()
n = int(lines[0].strip())
arr = list(map(int, lines[1].strip().split(' ')))
arr.append(arr[-1])
res = []
maxChange = 0
left = 0
for i in range(1, n + 1):
	if arr[i] == arr[i - 1]:
		L = i - left
		res += [arr[left]] * (L // 2) + [arr[i - 1]] * (L - L // 2)
		maxChange = max(maxChange, (L - 1) // 2)
		left = i
print(maxChange)
print(' '.join(map(str, res)))


n = int(input())
sequence = input().split()
fence = n
previousFence = 0
largestCount = 0
for i in range(1, n):
	if sequence[i] == sequence[i - 1]:
		fence = i
		if fence - previousFence > 2:
			if (fence - previousFence) % 2 == 1:
				for j in range(previousFence + 1, fence - 1):
					sequence[j] = sequence[previousFence]
			else:
				for j in range(previousFence + 1, int((previousFence + fence) / 2)):
					sequence[j] = sequence[previousFence]
				for j in range(int((previousFence + fence) / 2), fence - 1):
					sequence[j] = sequence[fence]
			if int((fence - previousFence - 1) / 2) > largestCount:
				largestCount = int((fence - previousFence - 1) / 2)
		previousFence = fence
fence = n
if fence - previousFence > 2:
	if (fence - previousFence) % 2 == 1:
		for j in range(previousFence + 1, fence - 1):
			sequence[j] = sequence[previousFence]
	else:
		for j in range(previousFence + 1, int((previousFence + fence) / 2)):
			sequence[j] = sequence[previousFence]
		for j in range(int((previousFence + fence) / 2), fence - 1):
			sequence[j] = sequence[fence - 1]
	if int((fence - previousFence - 1) / 2) > largestCount:
		largestCount = int((fence - previousFence - 1) / 2)
print(largestCount)
print(' '.join(sequence))


from sys import stdin
n = int(stdin.readline().strip())
s = list(map(int, stdin.readline().strip().split()))
l = 0
flag = True
x = 0
for i in range(1, n):
	if s[i] != s[i - 1]:
		if flag:
			flag = False
			l = i - 1
	else:
		r = i - 1
		if not flag:
			y = 0
			yy = r - 1
			for j in range(l + 1, r):
				s[j] = s[j - 1]
				y += 1
				s[yy] = s[yy + 1]
				yy -= 1
				if yy <= j:
					break
			x = max(x, y)
		flag = True
if True:
	if True:
		if not flag:
			y = 0
			yy = n - 2
			r = n - 1
			for j in range(l + 1, r):
				s[j] = s[j - 1]
				y += 1
				s[yy] = s[yy + 1]
				yy -= 1
				if yy <= j:
					break
			x = max(x, y)
print(x)
print(*s)


import sys
import math
import random
import copy
MAXNUM = math.inf
MINNUM = -1 * math.inf
ASCIILOWER = 97
ASCIIUPPER = 65

def getInt():
	return int(sys.stdin.readline().rstrip())

def getInts():
	return map(int, sys.stdin.readline().rstrip().split(' '))

def getString():
	return sys.stdin.readline().rstrip()

def printOutput(ans):
	(a, b) = ans
	sys.stdout.write(str(a) + '\n')
	for ele in b:
		sys.stdout.write(str(ele) + ' ')
	sys.stdout.write('\n')

def solve(seq):
	curPos = 0
	total = 0
	for i in range(0, len(seq) - 1):
		if seq[i] == seq[i + 1]:
			if i - curPos >= 2:
				ln = i - curPos + 1
				total = max(total, (ln - 1) // 2)
				if ln % 2 == 1:
					for j in range(curPos + 1, i):
						seq[j] = seq[curPos]
				else:
					for j in range(curPos + 1, i):
						if abs(j - curPos) < abs(i - j):
							seq[j] = seq[curPos]
						else:
							seq[j] = seq[i]
			curPos = i + 1
	if curPos != len(seq) - 1:
		if len(seq) - 1 - curPos >= 2:
			ln = len(seq) - 1 - curPos + 1
			total = max(total, (ln - 1) // 2)
			if ln % 2 == 1:
				for j in range(curPos + 1, len(seq) - 1):
					seq[j] = seq[curPos]
			else:
				for j in range(curPos + 1, len(seq) - 1):
					if abs(j - curPos) < abs(len(seq) - 1 - j):
						seq[j] = seq[curPos]
					else:
						seq[j] = seq[-1]
	return (total, seq)

def readinput():
	length = getInt()
	seq = list(getInts())
	printOutput(solve(seq))

def brute(seq):
	nxt = [i for i in seq]
	while True:
		isFinished = True
		for i in range(1, len(seq) - 1):
			if seq[i - 1] != seq[i] and seq[i] != seq[i + 1]:
				isFinished = False
				nxt[i] = seq[i - 1]
		seq = nxt
		nxt = [i for i in seq]
		if isFinished:
			break
	return seq

def test():
	print('STARTED')
	for i in range(5000):
		k = random.randint(1, 50)
		seq = [random.randint(0, 1) for _ in range(k)]
		cp = copy.copy(seq)
		cp2 = copy.copy(seq)
		ans = brute(seq)
		ans2 = solve(seq)[1]
		if ans != ans2:
			print(cp)
			print(ans)
			print(ans2)
		for j in range(1, len(ans)):
			continue
			if ans[1][j] == ans[1][j - 1]:
				print('hi', cur)
				if j - cur > 2:
					print(ans)
					print(orig)
					print(cur)
					assert True == False
				cur = j

def test2():
	seq = [0, 1, 0, 1, 0, 1]
	print(solve(seq))
readinput()


import os, io
from sys import stdout
import collections
import math
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import Counter

def primes(n):
	sieve = [True] * n
	for i in range(3, int(n ** 0.5) + 1, 2):
		if sieve[i]:
			sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
	return [2] + [i for i in range(3, n, 2) if sieve[i]]

def binomial_coefficient(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def powerOfK(k, max):
	if k == 1:
		return [1]
	if k == -1:
		return [-1, 1]
	result = []
	n = 1
	while n <= max:
		result.append(n)
		n *= k
	return result

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def divisors(n):
	i = 1
	result = []
	while i * i <= n:
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
		i += 1
	return result

def kadane(a, size):
	max_so_far = 0
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def digitsSum(n):
	if n == 0:
		return 0
	r = 0
	while n > 0:
		r += n % 10
		n //= 10
	return r

def print_grid(grid):
	for line in grid:
		print(''.join(line))
n = int(input())
l = list(map(int, input().split()))
i = 1
s = 0
e = None
res = 0
while i <= len(l):
	if i == len(l) or l[i] == l[i - 1]:
		if i - s > 2:
			e = i
			seq = l[s:e]
			if len(seq) % 2 == 0:
				res = max(res, len(seq) // 2 - 1)
			else:
				res = max(res, len(seq) // 2)
			if seq[0] == 1 and seq[-1] == 1:
				for k in range(s, e):
					l[k] = 1
			elif seq[0] == 0 and seq[-1] == 0:
				for k in range(s, e):
					l[k] = 0
			elif seq[0] == 0 and seq[-1] == 1:
				for k in range(s, e):
					if k < s + len(seq) // 2:
						l[k] = 0
					else:
						l[k] = 1
			elif seq[0] == 1 and seq[-1] == 0:
				for k in range(s, e):
					if k < s + len(seq) // 2:
						l[k] = 1
					else:
						l[k] = 0
		s = i
	i += 1
print(res)
print(' '.join(map(str, l)))


import sys
fin = sys.stdin
fout = sys.stdout
n = int(fin.readline())
a = fin.readline().split()
leftStableIdx = [0] * n
currLeftStableIdx = 0
for i in range(1, n - 1):
	if a[i - 1] == a[i] or a[i] == a[i + 1]:
		currLeftStableIdx = i
	leftStableIdx[i] = currLeftStableIdx
leftStableIdx[n - 1] = n - 1
result = [0] * n
currRightStableIdx = n - 1
nIterations = 0
for i in reversed(range(0, n)):
	if leftStableIdx[i] == i:
		result[i] = a[i]
		currRightStableIdx = i
	else:
		d1 = i - leftStableIdx[i]
		d2 = currRightStableIdx - i
		result[i] = a[leftStableIdx[i]] if d1 < d2 else a[currRightStableIdx]
		nIterations = max(nIterations, min(d1, d2))
fout.write(str(nIterations) + '\n')
fout.write(' '.join(map(str, result)) + '\n')
fin.close()
fout.close()


def main():
	n = int(input())
	seq = [int(c) for c in input().split()]
	alt = [[0, 0]]
	prev = seq[0]
	for (i, e) in enumerate(seq):
		if e != prev:
			alt[-1][1] += 1
		else:
			alt.append([i, i])
		prev = e
	alt = [e for e in alt if e[1] - e[0] + 1 > 2]
	steps = 0
	for (a, b) in alt:
		length = b - a + 1
		steps = max(steps, (length + 1) // 2 - 1)
		if length % 2 == 1:
			for i in range(a, b + 1):
				seq[i] = seq[a]
		else:
			for i in range(a, a + length // 2):
				seq[i] = seq[a]
			for i in range(a + length // 2, b + 1):
				seq[i] = seq[b]
	print(steps)
	print(*seq)
main()


n = int(input())
A = list(map(int, input().split()))
left = 0
ans = [A[0]]
count = 0
while left + 1 < n:
	right = left + 1
	while right + 1 < n:
		if A[right] != A[right + 1]:
			right += 1
			continue
		else:
			break
	mid = right - left
	if A[left] == A[left + 1]:
		count = max(count, (mid - 1) // 2)
	else:
		count = max(count, mid // 2)
	ans += [A[left]] * (mid // 2)
	if A[left] != A[right]:
		ans += [A[right]] * (mid // 2) + [A[right]] * (mid % 2)
	else:
		ans += [A[left]] * (mid // 2) + [A[left]] * (mid % 2)
	left = right
print(count)
print(' '.join(map(str, ans)))


import math
n = int(input())
a = list(map(int, input().split()))
segs = []
st = -1
for i in range(n):
	iso = False if i == 0 or i == n - 1 else a[i - 1] == a[i + 1] and a[i] != a[i - 1]
	if iso and st == -1:
		st = i
	elif not iso and st != -1:
		segs.append((st, i - 1))
		st = -1
ans = 0
for (l, r) in segs:
	span = r - l + 1
	ans = max(ans, span)
	for i in range(span // 2):
		a[l + i] = a[l - 1]
		a[r - i] = a[r + 1]
	if span % 2:
		j = l + span // 2
		a[j] = sorted([a[j - 1], a[j], a[j + 1]])[1]
print(math.ceil(ans / 2))
print(*a)


n = int(input())
a = list(map(int, input().split()))
(r, b, c) = (0, [a[0]], 0)
for (x, y, z) in zip(a, a[1:], a[2:]):
	if x != y != z:
		c += 1
		r = max(r, (c + 1) // 2)
		continue
	if c % 2 == 1:
		b.extend([y] * (c + 1))
	else:
		b.extend([1 - y] * (c // 2) + [y] * (c // 2 + 1))
	c = 0
y = a[-1]
if c % 2 == 1:
	b.extend([y] * (c + 1))
else:
	b.extend([1 - y] * (c // 2) + [y] * (c // 2 + 1))
print(r)
print(*b)


def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	flag = 0
	now_begin = 0
	kek = 0
	ans = [[-1] * 2 for i in range(n)]
	for i in range(1, n - 1):
		if a[i] != a[i - 1] and a[i] != a[i + 1]:
			kek += 1
		else:
			flag = max((kek + 1) // 2, flag)
			now_end = i
			if a[now_begin] == a[now_end]:
				ans[now_begin + 1][0] = a[now_begin]
				ans[now_begin + 1][1] = kek
			else:
				ans[now_begin + 1][0] = a[now_begin]
				ans[now_begin + 1][1] = kek // 2
				ans[now_begin + 1 + kek // 2][0] = a[now_end]
				ans[now_begin + 1 + kek // 2][1] = kek // 2
			now_begin = now_end
			kek = 0
	flag = max((kek + 1) // 2, flag)
	print(flag)
	now_end = n - 1
	if a[now_begin] == a[now_end]:
		ans[now_begin + 1][0] = a[now_begin]
		ans[now_begin + 1][1] = kek
	else:
		ans[now_begin + 1][0] = a[now_begin]
		ans[now_begin + 1][1] = kek // 2
		ans[now_begin + 1 + kek // 2][0] = a[now_end]
		ans[now_begin + 1 + kek // 2][1] = kek // 2
	g = 0
	what = 0
	for i in range(n):
		if ans[i].count(-1) != 2:
			what = ans[i][0]
			g = ans[i][1]
		if g <= 0:
			what = a[i]
		a[i] = what
		g -= 1
	for i in range(n):
		a[i] = str(a[i])
	print(' '.join(a))
main()


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
d = []
e = []
for i in range(1, n - 1):
	if a[i] != a[i - 1] and a[i] != a[i + 1]:
		e.append([a[i], i])
	elif e != []:
		d.append(e)
		e = []
if e != []:
	d.append(e)
if len(d) == 0:
	print(0)
	print(*a)
else:
	e = []
	for i in range(len(d)):
		if d[i][0][0] == 0:
			if len(d[i]) % 2 == 0:
				m = len(d[i])
				e.append(m // 2)
				for j in range(m // 2):
					a[d[i][j][1]] = 1
					a[d[i][m - j - 1][1]] = 0
			else:
				m = len(d[i])
				e.append(m // 2 + 1)
				for j in range(m):
					a[d[i][j][1]] = 1
		if d[i][0][0] == 1:
			if len(d[i]) % 2 == 0:
				m = len(d[i])
				e.append(m // 2)
				for j in range(m // 2):
					a[d[i][j][1]] = 0
					a[d[i][m - j - 1][1]] = 1
			else:
				m = len(d[i])
				e.append(m // 2 + 1)
				for j in range(m):
					a[d[i][j][1]] = 0
	print(max(e))
	print(*a)


N = int(input())
seq = [int(i) for i in input().split()]

def end_lst(i):
	while i < N - 1 and seq[i] != seq[i + 1]:
		i = i + 1
	return i

def reorder(lst, start, end):
	if start == end - 1:
		return 0
	if lst[start] == lst[end]:
		for i in range(start, end + 1):
			lst[i] = lst[start]
		return (end - start) // 2
	mid = (start + end) // 2
	for i in range(start, mid + 1):
		lst[i] = lst[start]
	for i in range(mid + 1, end + 1):
		lst[i] = lst[end]
	return (end - start + 1) // 2 - 1
(i, ans) = (0, 0)
while i < N - 1:
	if seq[i] != seq[i + 1]:
		end = end_lst(i)
		ans = max(reorder(seq, i, end), ans)
		i = end
	else:
		i += 1
print(ans)
seq = list(map(str, seq))
print(' '.join(seq))


def mp():
	return map(int, input().split())

def lt():
	return list(map(int, input().split()))

def pt(x):
	print(x)
n = int(input())
L = lt()
count = 0
i = 0
c = [None for i in range(n)]
while i < n - 1:
	j = i
	while j < n - 1 and L[j] != L[j + 1]:
		j += 1
	span = j - i + 1
	for k in range(i, i + span // 2):
		c[k] = L[i]
	for k in range(i + span // 2, j + 1):
		c[k] = L[j]
	count = max(count, (span - 1) // 2)
	i = j + 1
	if i == n - 1:
		c[i] = L[i]
print(count)
print(' '.join([str(r) for r in c]))


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
MOD = 1000000007

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
a = array()
steps = 0
ans = set()
l = 1
r = 0
for i in range(1, n - 1):
	if a[i - 1] == a[i + 1] and a[i - 1] != a[i]:
		steps += 1
		r += 1
	else:
		if l <= r:
			ans.add((l, r))
		l = i + 1
		r = i
		steps = 0
if l <= r:
	ans.add((l, r))
steps = 0
b = a
for (l, r) in ans:
	tot = r - l + 1
	steps = max(tot, steps)
	if tot % 2:
		b[l:r + 1] = [a[l - 1]] * tot
	else:
		b[l:l + tot // 2] = [a[l - 1]] * (tot // 2)
		b[l + tot // 2:r + 1] = [a[r + 1]] * (tot // 2)
print(ceil(steps / 2))
print(*b)


n = int(input())
arr = [int(x) for x in input().split()]
stable = [True] * n
for i in range(1, n - 1):
	if arr[i] == 0 and arr[i + 1] * arr[i - 1] == 1:
		stable[i] = False
	elif arr[i] == 1 and (arr[i + 1] == 0 and arr[i - 1] == 0):
		stable[i] = False
val = [0] * n
ans = [i for i in arr]
dist = 0
idx = 0
for i in range(n):
	if stable[i]:
		idx = i
	else:
		val[i] = i - idx
for i in range(n - 1, -1, -1):
	if stable[i]:
		idx = i
	elif idx - i <= val[i]:
		ans[i] = arr[i + idx - i]
		val[i] = idx - i
	else:
		ans[i] = arr[i - val[i]]
print(max(val))
print(*ans)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
d = defaultdict(list)
n = I()
a = L()

def solve(l, r):
	if l == r:
		return 0
	if a[l] == a[r]:
		for i in range(l + 1, r):
			a[i] = a[l]
		return (r - l) // 2
	else:
		m = (l + r + 1) // 2
		for i in range(l + 1, m):
			a[i] = a[l]
		for i in range(m, r):
			a[i] = a[r]
		return (r - l - 1) // 2
left = 0
ans = 0
for i in range(n):
	if i == n - 1 or a[i] == a[i + 1]:
		ans = max(ans, solve(left, i))
		left = i + 1
print(ans)
print(*a)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n
avl = AvlTree()

class SegmentTree1:

	def __init__(self, data, default='z', func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
l = list(map(int, input().split()))
ans = 0
cur = 0
st = -1
for i in range(1, n - 1):
	if l[i] != l[i - 1]:
		if st == -1:
			st = i
	else:
		if st == -1:
			continue
		for j in range(st, i - 1):
			if j > i - 2 - j + st:
				break
			rt = l[j]
			l[j] = l[j - 1]
			l[i - 2 - (j - st)] = l[i - 1 - j + st]
			cur += 1
		ans = max(ans, cur)
		cur = 0
		st = -1
if st != -1:
	i = n - 1
	if l[-1] != l[-2]:
		i += 1
	for j in range(st, i - 1):
		if j > i - 2 - j + st:
			break
		rt = l[j]
		l[j] = l[j - 1]
		l[i - 2 - (j - st)] = l[i - 1 - j + st]
		cur += 1
		ans = max(ans, cur)
print(ans)
print(*l)


import sys
import re
read = lambda : list(map(int, sys.stdin.readline().split()))
_ = read()
s = sys.stdin.readline().strip().replace(' ', '')
s = s[0] + s + s[-1]
segs = re.findall('(.*?)(0{2,}|1{2,})', s)
time = 0
res = [segs[0][1]]
for i in range(1, len(segs)):
	length = len(segs[i][0])
	time = max(time, length)
	(a, b) = (segs[i - 1][1][0], segs[i][1][0])
	if a == b:
		res.append(a * length)
	else:
		res.append(a * (length // 2))
		res.append(b * (length // 2))
	res.append(segs[i][1])
print((time + 1) // 2)
print(' '.join((c for c in ''.join(res)[1:-1])))


input()
seq = list(map(int, input().split()))

def make_ans(seq):
	ans = 0

	def is_fixed(ind):
		return seq[ind - 1] == seq[ind] or seq[ind] == seq[ind + 1]

	def set_res(left, right):
		left_begin = left
		if left == right:
			return 0
		left_res = seq[left - 1]
		right_res = seq[right]
		right -= 1
		while left <= right:
			seq[left] = left_res
			seq[right] = right_res
			left += 1
			right -= 1
		return left - left_begin
	left = 1
	right = 1
	for i in range(1, len(seq) - 1):
		if not is_fixed(i):
			right += 1
		elif left == right:
			left += 1
			right += 1
		else:
			ans = max(ans, set_res(left, right))
			left = right = i + 1
	ans = max(ans, set_res(left, right))
	return (ans, seq)

def calc(seq):
	n = 0

	def is_fixed(ind):
		return seq[ind - 1] == seq[ind] or seq[ind] == seq[ind + 1]

	def up(seq):
		seq_copy = seq[:]
		for i in range(1, len(seq) - 1):
			if not is_fixed(i):
				seq_copy[i] = 1 - seq_copy[i]
		return seq_copy
	while up(seq) != seq:
		seq = up(seq)
		n += 1
	return (n, seq)
(ans, seq) = make_ans(seq)
print(ans)
print(' '.join(map(str, seq)))