inputs: I found an interesting problem on https://codeforces.com/problemset/problem/590/A:
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 ≤...

I tried it in Python, but could not do it. Can you solve it?
targets: 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])
    else:
        if 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)