#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
bool was[100001];
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	    if (a[i] > 0)
	        was[(a[i] & 1)] = 1;
	}

	if (used[1]) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[1] && (k % 2 == 0)) {

	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && (k & 1)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && was[1]) {
	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it <= 4; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
vector < int > ans;

int main () {
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	}
	for (int it = 1; it <= 100; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            ans.emplace_back(i % k);
	        }
	    }
	    random_shuffle(a + 1, a + n + 1);
	}

	sort(every(ans));
	ans.resize(unique(every(ans)) - ans.begin());

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
bool was[100001];
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	    was[(a[i] & 1)] = 1;
	}
	if (min(n, k) <= 3000) {
	    sort(a + 1, a + n + 1);

	for (int it = 1; it <= 15; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';
	    exit(0);
	}

	if (used[1]) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[1] && (k % 2 == 0)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && (k & 1)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && was[1]) {
	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);

	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it <= 4; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
bool was[100001];
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	    was[(a[i] & 1)] = 1;
	}
	if (used[1]) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[1] && (k % 2 == 0)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (used[2] && (k & 1)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (used[2] && was[1]) {
	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);

	}
	if (min(n, k) <= 3000) {
	    sort(a + 1, a + n + 1);

	for (int it = 1; it <= 15; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';
	    exit(0);
	}

	if (used[1]) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[1] && (k % 2 == 0)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && (k & 1)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && was[1]) {
	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);

	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it <= 4; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
bool was[100001];
int gcd;
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	    if (a[i] > 0)
	        was[(a[i] & 1)] = 1;
	    gcd = __gcd(gcd, a[i]);
	}

	if (gcd == 1) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (used[1]) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[1] && (k % 2 == 0)) {

	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && (k & 1)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && was[1]) {
	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it <= 4; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
bool was[100001];
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	    was[a[i] & 1] = 1;
	}

	if (used[1]) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (used[2] && (k & 1)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (used[2] && was[1]) {

	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);

	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it <= 4; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	}

	if (used[1]) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it <= 5; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	}

	if (used[1]) {
	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it < 5; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
bool was[100001];
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	    if (a[i] > 0)
	        was[(a[i] & 1)] = 1;
	}
	if (min(n, k) <= 1000) {
	    sort(a + 1, a + n + 1);

	for (int it = 1; it <= 10; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';
	    exit(0);
	}

	if (used[1]) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[1] && (k % 2 == 0)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && (k & 1)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && was[1]) {
	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);

	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it <= 4; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
vector < int > ans;

int main () {
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	}
	for (int it = 1; it <= 20; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            ans.emplace_back(i % k);
	        }
	    }
	    random_shuffle(a + 1, a + n + 1);
	}

	sort(every(ans));
	ans.resize(unique(every(ans)) - ans.begin());

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
bool was[100001];
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	    if (a[i] > 0)
	        was[(a[i] & 1)] = 1;
	}

	if (used[1]) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[1] && (k % 2 == 0)) {

	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && (k & 1)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it <= 4; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
vector < int > ans;

int main () {
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	}
	sort(a + 1, a + n + 1);
	for (int it = 1; it <= 5; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            ans.emplace_back(i % k);
	        }
	    }
	    random_shuffle(a + 1, a + n + 1);
	}

	sort(every(ans));
	ans.resize(unique(every(ans)) - ans.begin());

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++)
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;
const int PRI = 555557;
const int pri = 997;
const int Magic = 2101;

//const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
//const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};

inline void randomizer3000 () {}

int n, m, k;
int a[N];
string s;
bitset < 100001 > st;
bool used[100001];
bool was[100001];
vector < int > ans;

int main () {
    SpeedForce;
	cin >> n >> k;
	For (i, 1, n) {
	    cin >> a[i];
	    a[i] %= k;
	    used[a[i]] = 1;
	    if (a[i] > 0)
	        was[a[i] & 1] = 1;
	}

	if (used[1]) {
	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && (k & 1)) {

	    For (i, 0, k - 1) {
//	    if (used[i])
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);
	}

	if (was[0] && was[1]) {
	    For (i, 0, k - 1) {
	        ans.pb(i);
    	}

	    cout << ans.size() << '\n';
	    for (auto to : ans)
	        cout << to << ' ';
	    exit(0);

	}

	sort(a + 1, a + n + 1);

	for (int it = 1; it <= 4; it ++) {
	    st.reset();
	    For (i, 1, n) {
	        st[a[i]] = 1;
	        st |= (st << a[i]);
	    }

	    For (i, 0, k) {
	        if (st[i]) {
	            used[i % k] = 1;
	        }
	    }
	    random_shuffle(a + 1 , a + n + 1);
	}

	For (i, 0, k - 1) {
	    if (used[i])
	        ans.pb(i);
	}

	cout << ans.size() << '\n';
	for (auto to : ans)
	    cout << to << ' ';

	return Accepted;
}

// Coded By OB


#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 7;

int a[maxn];
bool visable[maxn];

int main() {
    #ifdef local
        freopen("in.txt", "r", stdin);
    #endif // local

    int n, k;
    cin >> n >> k;
    bool flag = false;
    int st = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] %= k;
        if(!a[i])continue;
        if(!flag) st = a[i];
        else st = __gcd(st, a[i]);
    }
    int cnt = 1;
    if(st) {
        for(int i = st; i < k; i += st) visable[i] = true, cnt++;
    }
    cout << cnt << endl; cout << 0;
    for(int i = 0; i < k; i++) if(visable[i])cout << ' ' << i;
    cout << endl;
    return 0;
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
typedef priority_queue<int> pqi;
typedef priority_queue< pii > pqii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define memo(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define fast_io ios_base::sync_with_stdio(0);
#define accuracy  int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
ll MOD=1e9+7;
ll MAX=1e17;
vi v;
bool check(){
	for(int i=1;i<v.size()-1;i++){
		if(v[i-1]==v[i+1] and v[i-1]!=v[i]) return false;
	}
	return true;
}
int work(){
	vi res;
	int cnt=0,ans=0;
	rep(i,v.size()) res.pb(v[i]);
	int now=0,last=0;
	while(true){
	    //cout<<last<<" ";
		now=last;
		while(res[last]==res[now] and last<(int) v.size()) last++;
		//cout<<last<<" ";
		if(last==0) last++;
		if(last==res.size() or last==res.size()-1) return ans;
		if(res[last+1]==res[last]) continue;
		else{
			cnt=0;
			int rem=v[last-1];
			while(res[last+1]!=res[last] and last<res.size()-1){
				v[last]=rem;
				cnt++;
				last++;
			}
			ans=max(ans,1+((cnt-1)/2));
		}
	}
	return ans;
}
int main(){
	fast_io;//accuracy;
	int n;cin>>n;
	rep(i,n){
		int x;cin>>x;
		v.pb(x);
	}
	int ans=0;
	if(!check()){
		ans=work();
	}
	cout<<ans<<endl;
	rep(i,n) cout<<v[i]<<" ";
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
typedef priority_queue<int> pqi;
typedef priority_queue< pii > pqii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define memo(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define fast_io ios_base::sync_with_stdio(0);
#define accuracy  int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
ll MOD=1e9+7;
ll MAX=1e17;
vi v;
bool check(){
	for(int i=1;i<v.size()-1;i++){
		if(v[i-1]==v[i+1] and v[i-1]!=v[i]) return false;
	}
	return true;
}
void work(){
	vi res;
	rep(i,v.size()) res.pb(v[i]);
	for(int i=1;i<v.size()-1;i++){
		vi temp;
		temp.pb(res[i-1]);temp.pb(res[i]);temp.pb(res[i+1]);
		sort(all(temp));
		v[i]=temp[1];
	}
}
int main(){
	fast_io;//accuracy;
	int n;cin>>n;
	rep(i,n){
		int x;cin>>x;
		v.pb(x);
	}
	int count=0;
	while(!check()){
		count++;
		work();
	}
	cout<<count<<endl;
	rep(i,n) cout<<v[i]<<" ";
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
typedef priority_queue<int> pqi;
typedef priority_queue< pii > pqii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define memo(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define fast_io ios_base::sync_with_stdio(0);
#define accuracy  int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
ll MOD=1e9+7;
ll MAX=1e17;
vi v;
bool check(){
	for(int i=1;i<v.size()-1;i++){
		if(v[i-1]==v[i+1] and v[i-1]!=v[i]) return false;
	}
	return true;
}
int work(){
	vi res;
	int cnt=0,ans=0;
	rep(i,v.size()) res.pb(v[i]);
	int now=0,last=0;
	while(true){
		now=last;
		while(res[last]==res[now] and last<v.size()) last++;
		if(last==0) last++;
		if(last==res.size() or last==res.size()-1) return ans;
		if(res[last+1]==res[last]) continue;
		else{
			cnt=0;
			int rem=v[last-1];
			while(res[last+1]!=res[last]){
				v[last]=rem;
				cnt++;
				last++;
			}
			ans=max(ans,1+((cnt-1)/2));
		}
	}
	return ans;
}
int main(){
	fast_io;//accuracy;
	int n;cin>>n;
	rep(i,n){
		int x;cin>>x;
		v.pb(x);
	}
	int ans=0;
	if(!check()){
		ans=work();
	}
	cout<<ans<<endl;
	rep(i,n) cout<<v[i]<<" ";
}


//      ******************************************************
//
//		   everything is part of a bigger plan
//
//      ******************************************************
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector< vector<pii> > vvii;
typedef vector<pii> vii;
typedef set<int> si;
typedef set< pii> sii;
typedef unordered_map<int,int> umii;
typedef map<int,int> mii;
typedef priority_queue<int> pqi;
typedef priority_queue< pii > pqii;
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define pres(a,x) x.find(a)!=x.end()
#define cpres(a,x) find(all(x),a)!=x.end()
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define memo(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(int i=0;i<n;i++)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>b;i--)
#define tr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define rtr(it,x) for(auto it=x.rbegin();it!=x.rend();it++)
#define fast_io ios_base::sync_with_stdio(0);
#define accuracy  int precision = numeric_limits<double>::digits10;cout<<setprecision(precision);
ll MOD=1e9+7;
ll MAX=1e17;
vi v;
bool check(){
	for(int i=1;i<v.size()-1;i++){
		if(v[i-1]==v[i+1] and v[i-1]!=v[i]) return false;
	}
	return true;
}
int work(){
	vi res;
	int cnt=0,ans=0;
	rep(i,v.size()) res.pb(v[i]);
	int now=0,last=0;
	while(true){
	    //cout<<last<<" ";
		now=last;
		while(res[last]==res[now] and last<(int) v.size()) last++;
		//cout<<last<<" ";
		if(last==0) last++;
		if(last==res.size() or last==res.size()-1) return ans;
		if(res[last+1]==res[last]) continue;
		else{
			cnt=0;
			int rem=v[last-1];
			int fuck=last-1;
			while(res[last+1]!=res[last] and last<res.size()-1){
				cnt++;
				last++;
			}
			int i=0;
			while(i+fuck<last-i){
				v[last-i]=v[last];
				v[i+fuck]=v[fuck];
				i++;
			}
			ans=max(ans,1+((cnt-1)/2));
		}
	}
	return ans;
}
int main(){
	fast_io;//accuracy;
	int n;cin>>n;
	rep(i,n){
		int x;cin>>x;
		v.pb(x);
	}
	int ans=0;
	if(!check()){
		ans=work();
	}
	cout<<ans<<endl;
	rep(i,n) cout<<v[i]<<" ";
}


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

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()

using namespace std;

int median(int x, int y, int z) {
    return (x + y + z) / 2;
}

vector<int> next(const vector<int>& a) {
    auto b = a;
    for (int i = 1; i < sz(a) - 1; ++i)
        b[i] = median(a[i - 1], a[i], a[i + 1]);
    return b;
}

void updateValues(const vector<int>& a, vector<int>& b, int begin, int end) {
    if ((end - begin) % 2 == 0) {
        int value = 1 - a[begin];
        for (int i = begin; i <= end; ++i) {
            b[i] = value;
        }
    } else {
        int value = 1 - a[begin];
        for (int i = begin; i < begin + (end - begin) / 2; ++i) {
            b[i] = value;
        }
        for (int i = begin + (end - begin) / 2; i <= end; ++i) {
            b[i] = a[begin];
        }
    }
}

// 0123456789
// 01010101010

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

    vector<int> b(n, -1);
    b[0] = a[0];
    b[n - 1] = a[n - 1];

    for (int i = 1; i < n - 1; ++i) {
        if (a[i] == median(a[i -1], a[i], a[i + 1])) {
            b[i] = a[i];
        }
    }
    for (const auto& v : b) {
        cout << v << " ";
    }
    cout << endl;

    int ind = 1;
    int maxIterNum = 0;
    while (ind < n - 1) {
        if (b[ind] < 0) {
            int begin = ind;
            int end = ind;
            ++ind;
            while (b[ind] < 0) {
                ++end;
                ++ind;
            }
            updateValues(a, b, begin, end);
            std::cout << begin << " " << end << endl;
            maxIterNum = max(maxIterNum, (end - begin) / 2 + 1);
        } else {
            ++ind;
        }
    }
    cout << maxIterNum << endl;
    for (const auto& v : b) {
        cout << v << " ";
    }
    return 0;
}


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

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()

using namespace std;

int median(int x, int y, int z) {
    return (x + y + z) / 2;
}

void updateValues(const vector<int>& a, vector<int>& b, int begin, int end) {
    if ((end - begin) % 2 == 0) {
        int value = 1 - a[begin];
        for (int i = begin; i <= end; ++i) {
            b[i] = value;
        }
    } else {
        int value = 1 - a[begin];
        for (int i = begin; i < begin + (end - begin + 1) / 2; ++i) {
            b[i] = value;
        }
        for (int i = begin + (end - begin + 1) / 2; i <= end; ++i) {
            b[i] = a[begin];
        }
    }
}

// 0123456789
// 01010101010

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

    vector<int> b(n, -1);
    b[0] = a[0];
    b[n - 1] = a[n - 1];

    for (int i = 1; i < n - 1; ++i) {
        if (a[i] == median(a[i -1], a[i], a[i + 1])) {
            b[i] = a[i];
        }
    }
    // for (const auto& v : b) {
    //     cout << v << " ";
    // }
    // cout << endl;

    int ind = 1;
    int maxIterNum = 0;
    while (ind < n - 1) {
        if (b[ind] < 0) {
            int begin = ind;
            int end = ind;
            ++ind;
            while (b[ind] < 0) {
                ++end;
                ++ind;
            }
            updateValues(a, b, begin, end);
            // std::cout << begin << " " << end << endl;
            maxIterNum = max(maxIterNum, (end - begin) / 2 + 1);
        } else {
            ++ind;
        }
    }
    cout << maxIterNum << endl;
    for (const auto& v : b) {
        cout << v << " ";
    }
    return 0;
}


#include <iostream>
#include <vector>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()

using namespace std;

int median(int x, int y, int z) {
    vector<int> a {x, y, z};
    sort(all(a));
    return a[1];
}

vector<int> next(const vector<int>& a) {
    auto b = a;
    for (int i = 1; i < sz(a) - 1; ++i)
        b[i] = median(a[i - 1], a[i], a[i + 1]);
    return b;
}

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    int cnt = 0;
    while (true) {
        auto b = next(a);
        if (a == b) break;
        ++cnt;
        a = b;
    }
    printf("%d\n", cnt);
    for (int i = 0; i < n; ++i) printf("%d ", a[i]);
    return 0;
}


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

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()

using namespace std;

int median(int x, int y, int z) {
    return (x + y + z) / 2;
}

void updateValues(const vector<int>& a, vector<int>& b, int begin, int end) {
    if ((end - begin) % 2 == 0) {
        int value = 1 - a[begin];
        for (int i = begin; i <= end; ++i) {
            b[i] = value;
        }
    } else {
        int value = 1 - a[begin];
        for (int i = begin; i < begin + (end - begin + 1) / 2; ++i) {
            b[i] = value;
        }
        for (int i = begin + (end - begin + 1) / 2; i <= end; ++i) {
            b[i] = a[begin];
        }
    }
}

// 0123456789
// 01010101010

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

    vector<int> b(n, -1);
    b[0] = a[0];
    b[n - 1] = a[n - 1];

    for (int i = 1; i < n - 1; ++i) {
        if (a[i] == median(a[i -1], a[i], a[i + 1])) {
            b[i] = a[i];
        }
    }
    for (const auto& v : b) {
        cout << v << " ";
    }
    cout << endl;

    int ind = 1;
    int maxIterNum = 0;
    while (ind < n - 1) {
        if (b[ind] < 0) {
            int begin = ind;
            int end = ind;
            ++ind;
            while (b[ind] < 0) {
                ++end;
                ++ind;
            }
            updateValues(a, b, begin, end);
            std::cout << begin << " " << end << endl;
            maxIterNum = max(maxIterNum, (end - begin) / 2 + 1);
        } else {
            ++ind;
        }
    }
    cout << maxIterNum << endl;
    for (const auto& v : b) {
        cout << v << " ";
    }
    return 0;
}


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

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()

using namespace std;

int median(int x, int y, int z) {
    return (x + y + z) / 2;
}

void updateValues(const vector<int>& a, vector<int>& b, int begin, int end) {
    if ((end - begin) % 2 == 0) {
        int value = 1 - a[begin];
        for (int i = begin; i <= end; ++i) {
            b[i] = value;
        }
    } else {
        int value = 1 - a[begin];
        for (int i = begin; i < begin + (end - begin) / 2; ++i) {
            b[i] = value;
        }
        for (int i = begin + (end - begin) / 2; i <= end; ++i) {
            b[i] = a[begin];
        }
    }
}

// 0123456789
// 01010101010

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

    vector<int> b(n, -1);
    b[0] = a[0];
    b[n - 1] = a[n - 1];

    for (int i = 1; i < n - 1; ++i) {
        if (a[i] == median(a[i -1], a[i], a[i + 1])) {
            b[i] = a[i];
        }
    }

    int ind = 1;
    int maxIterNum = 0;
    while (ind < n - 1) {
        if (b[ind] < 0) {
            int begin = ind;
            int end = ind;
            ++ind;
            while (b[ind] < 0) {
                ++end;
                ++ind;
            }
            updateValues(a, b, begin, end);
            maxIterNum = max(maxIterNum, (end - begin) / 2 + 1);
        } else {
            ++ind;
        }
    }
    cout << maxIterNum << endl;
    for (const auto& v : b) {
        cout << v << " ";
    }
    return 0;
}


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

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()

using namespace std;

int median(int x, int y, int z) {
    vector<int> a {x, y, z};
    sort(all(a));
    return a[1];
}

vector<int> next(const vector<int>& a) {
    auto b = a;
    for (int i = 1; i < sz(a) - 1; ++i)
        b[i] = median(a[i - 1], a[i], a[i + 1]);
    return b;
}

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    int cnt = 0;
    while (true) {
        auto b = next(a);
        if (a == b) break;
        ++cnt;
        a = b;
    }
    printf("%d\n", cnt);
    for (int i = 0; i < n; ++i) printf("%d ", a[i]);
    return 0;
}


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

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()

using namespace std;

int median(int x, int y, int z) {
    // vector<int> a {x, y, z};
    // sort(all(a));

    int s = x + y + z;
    if (s == 0 || s == 1) {
        return 0;
    } else  {
        return 1;
    }
}

vector<int> next(const vector<int>& a) {
    auto b = a;
    for (int i = 1; i < sz(a) - 1; ++i)
        b[i] = median(a[i - 1], a[i], a[i + 1]);
    return b;
}

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    int cnt = 0;
    while (true) {
        auto b = next(a);
        if (a == b) break;
        ++cnt;
        a = b;
    }
    printf("%d\n", cnt);
    for (int i = 0; i < n; ++i) printf("%d ", a[i]);
    return 0;
}


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

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()

using namespace std;

int median(int x, int y, int z) {
    return (x + y + z) / 2;
}

void updateValues(const vector<int>& a, vector<int>& b, int begin, int end) {
    if ((end - begin) % 2 == 0) {
        int value = 1 - a[begin];
        for (int i = begin; i <= end; ++i) {
            b[i] = value;
        }
    } else {
        int value = 1 - a[begin];
        for (int i = begin; i < begin + (end - begin) / 2; ++i) {
            b[i] = value;
        }
        for (int i = begin + (end - begin) / 2; i <= end; ++i) {
            b[i] = a[begin];
        }
    }
}

// 0123456789
// 01010101010

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

    vector<int> b(n, -1);
    b[0] = a[0];
    b[n - 1] = a[n - 1];

    for (int i = 1; i < n - 1; ++i) {
        if (a[i] == median(a[i -1], a[i], a[i + 1])) {
            b[i] = a[i];
        }
    }

    int ind = 1;
    int maxIterNum = 0;
    while (ind < n - 1) {
        if (b[ind] < 0) {
            int begin = ind;
            int end = ind;
            ++ind;
            while (b[ind] < 0) {
                ++end;
                ++ind;
            }
            updateValues(a, b, begin, end);
            std::cout << begin << " " << end << endl;
            maxIterNum = max(maxIterNum, (end - begin) / 2 + 1);
        } else {
            ++ind;
        }
    }
    cout << maxIterNum << endl;
    for (const auto& v : b) {
        cout << v << " ";
    }
    return 0;
}


/*
  /\     /\
  | ).|.( |
  |  >-<  |
  =========
It's AdilkhanKo miaaaaaau
*/
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define endl "\n"
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define mp make_pair
#define f first
#define s second
#define name ""
#define _ ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

const int MaxN = int (2e6) + 256;
const int INF = int(1e9);
const int mod = (int)(1e9) + 7;
const double pi = 3.1415926535897932384626433832795;
ll n, m, t, ans, a[MaxN], b[MaxN], ans1 = 0;
vector<pair<int, int> > v;

int main () { _
	#ifdef ONLINE_JUDGE
//		freopen (name".in","r",stdin);
//		freopen (name".out","w",stdout);
	#else
		freopen (".in","r",stdin);
		freopen (".out","w",stdout);
	#endif
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		b[i] = a[i];
	}
	bool change = 0;
	for(int i = 2; i < n; i++){
		if(a[i] != a[i - 1] && a[i] != a[i + 1]){ans++;}
		else if(ans){
			change = 1;
			v.pb(mp((ans + 1) / 2, (ans % 2)));
			ans1 = max((ans + 1) / 2, ans1);
			ans = 0;
		}
	}
	if(ans){
		change = 1;
		v.pb(mp((ans + 1) / 2, (ans % 2)));
		ans1 = (ans + 1) / 2 * ans1;
		ans = 0;
	}
	cout << ans1 << endl;
	int j = 0;
	if(v.size() == 0){
		for(int i = 1; i <= n; i++)
			cout << b[i] << " ";
		return 0;
	}
	int ans = v[j].first;
	int even = v[j].second;
	int cnt = 1;
	bool ok1 = 0, ok = 0;;
	for(int i = 2; j != v.size() && i < n; i++){
		if(a[i] != a[i - 1] && a[i] != a[i + 1]){
			ok1 = 1;
			//cout << i << " " << a[i] << " " << cnt << " " << even << endl;
			b[i] = (a[i] + cnt) % 2;
			if(!ok){
				cnt ++;
				if(cnt > ans){
					if(!even){
						cnt = ans;
						ok = 1;
					}else{
						cnt = ans - 1;
					}
				}
			}else cnt--;
		}else{
			if(ok1){
				j++;
				if(j == v.size())break;
				ans = v[j].first;
				cnt = 1;
				ok = 0;
				even = v[j].second;
				ok1 = 0;
			}
		}
	}
	for(int i = 1; i <= n; i++)
		cout << b[i] << " ";
return 0;
}


/*
  /\     /\
  | ).|.( |
  |  >-<  |
  =========
It's AdilkhanKo miaaaaaau
*/
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define endl "\n"
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define mp make_pair
#define f first
#define s second
#define name ""
#define _ ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

const int MaxN = int (2e6) + 256;
const int INF = int(1e9);
const int mod = (int)(1e9) + 7;
const double pi = 3.1415926535897932384626433832795;
ll n, m, t, ans, a[MaxN], b[MaxN], ans1 = 1;
vector<pair<int, int> > v;

int main () { _
	#ifdef ONLINE_JUDGE
//		freopen (name".in","r",stdin);
//		freopen (name".out","w",stdout);
	#else
		freopen (".in","r",stdin);
		freopen (".out","w",stdout);
	#endif
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		b[i] = a[i];
	}
	bool change = 0;
	for(int i = 2; i < n; i++){
		if(a[i] != a[i - 1] && a[i] != a[i + 1]){ans++;}
		else if(ans){
			change = 1;
			v.pb(mp((ans + 1) / 2, (ans % 2)));
			ans1 = (ans + 1) / 2 * ans1;
			ans = 0;
		}
	}
	if(ans){
		change = 1;
		v.pb(mp((ans + 1) / 2, (ans % 2)));
		ans1 = (ans + 1) / 2 * ans1;
		ans = 0;
	}
	if(change == 0)ans1 = 0;
	cout << ans1 << endl;
	int j = 0;
	if(v.size() == 0){
		for(int i = 1; i <= n; i++)
			cout << b[i] << " ";
		return 0;
	}
	int ans = v[j].first;
	int even = v[j].second;
	int cnt = 1;
	bool ok1 = 0, ok = 0;;
	for(int i = 2; j != v.size() && i < n; i++){
		if(a[i] != a[i - 1] && a[i] != a[i + 1]){
			ok1 = 1;
			//cout << i << " " << a[i] << " " << cnt << " " << even << endl;
			b[i] = (a[i] + cnt) % 2;
			if(!ok){
				cnt ++;
				if(cnt > ans){
					if(!even){
						cnt = ans;
						ok = 1;
					}else{
						cnt = ans - 1;
					}
				}
			}else cnt--;
		}else{
			if(ok1){
				j++;
				if(j == v.size())break;
				ans = v[j].first;
				cnt = 1;
				ok = 0;
				even = v[j].second;
				ok1 = 0;
			}
		}
	}
	for(int i = 1; i <= n; i++)
		cout << b[i] << " ";
return 0;
}


/*
  /\     /\
  | ).|.( |
  |  >-<  |
  =========
It's AdilkhanKo miaaaaaau
*/
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define endl "\n"
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define mp make_pair
#define f first
#define s second
#define name ""
#define _ ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

const int MaxN = int (2e6) + 256;
const int INF = int(1e9);
const int mod = (int)(1e9) + 7;
const double pi = 3.1415926535897932384626433832795;
ll n, m, t, ans, a[MaxN], b[MaxN], ans1 = 0;
vector<pair<int, int> > v;

int main () { _
	#ifdef ONLINE_JUDGE
//		freopen (name".in","r",stdin);
//		freopen (name".out","w",stdout);
	#else
		freopen (".in","r",stdin);
		freopen (".out","w",stdout);
	#endif
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		b[i] = a[i];
	}
	bool change = 0;
	for(int i = 2; i < n; i++){
		if(a[i] != a[i - 1] && a[i] != a[i + 1]){ans++;}
		else if(ans){
			change = 1;
			v.pb(mp((ans + 1) / 2, (ans % 2)));
			ans1 = max((ans + 1) / 2, ans1);
			ans = 0;
		}
	}
	if(ans){
		change = 1;
		v.pb(mp((ans + 1) / 2, (ans % 2)));
		ans1 = max((ans + 1) / 2, ans1);
		ans = 0;
	}
	cout << ans1 << endl;
	int j = 0;
	if(v.size() == 0){
		for(int i = 1; i <= n; i++)
			cout << b[i] << " ";
		return 0;
	}
	int ans = v[j].first;
	int even = v[j].second;
	int cnt = 1;
	bool ok1 = 0, ok = 0;;
	for(int i = 2; j != v.size() && i < n; i++){
		if(a[i] != a[i - 1] && a[i] != a[i + 1]){
			ok1 = 1;
			//cout << i << " " << a[i] << " " << cnt << " " << even << endl;
			b[i] = (a[i] + cnt) % 2;
			if(!ok){
				cnt ++;
				if(cnt > ans){
					if(!even){
						cnt = ans;
						ok = 1;
					}else{
						cnt = ans - 1;
					}
				}
			}else cnt--;
		}else{
			if(ok1){
				j++;
				if(j == v.size())break;
				ans = v[j].first;
				cnt = 1;
				ok = 0;
				even = v[j].second;
				ok1 = 0;
			}
		}
	}
	for(int i = 1; i <= n; i++)
		cout << b[i] << " ";
return 0;
}


/*
  /\     /\
  | ).|.( |
  |  >-<  |
  =========
It's AdilkhanKo miaaaaaau
*/
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define endl "\n"
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define mp make_pair
#define f first
#define s second
#define name ""
#define _ ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

const int MaxN = int (2e6) + 256;
const int INF = int(1e9);
const int mod = (int)(1e9) + 7;
const double pi = 3.1415926535897932384626433832795;
ll n, m, t, ans, a[MaxN], b[MaxN];

int main () { _
	#ifdef ONLINE_JUDGE
//		freopen (name".in","r",stdin);
//		freopen (name".out","w",stdout);
	#else
		freopen (".in","r",stdin);
		freopen (".out","w",stdout);
	#endif
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i = 2; i < n; i++){
		if(a[i] != a[i - 1] && a[i] != a[i + 1])ans++;
	}
	bool even = 0;
	if(ans % 2 == 0)
		even = 1;
	ans = (ans + 1) / 2;
	int cnt = 1;
	bool ok = 0;
	cout << ans << endl;
	for(int i = 2; i < n; i++){
			if(a[i] != a[i - 1] && a[i] != a[i + 1]){
				b[i] = (a[i] + cnt) % 2;
				if(!ok){
					cnt ++;
					if(cnt > ans){
						if(even){
							cnt = ans;
							ok = 1;
						}
					}
				}else cnt--;
			}
	}
	for(int i = 1; i <= n; i++)
		cout << b[i] << " ";
return 0;
}


/*
  /\     /\
  | ).|.( |
  |  >-<  |
  =========
It's AdilkhanKo miaaaaaau
*/
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define endl "\n"
#define foreach(it, S) for(__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define mp make_pair
#define f first
#define s second
#define name ""
#define _ ios_base::sync_with_stdio(false);cin.tie(0);

using namespace std;

const int MaxN = int (2e6) + 256;
const int INF = int(1e9);
const int mod = (int)(1e9) + 7;
const double pi = 3.1415926535897932384626433832795;
ll n, m, t, ans, a[MaxN], b[MaxN];

int main () { _
	#ifdef ONLINE_JUDGE
//		freopen (name".in","r",stdin);
//		freopen (name".out","w",stdout);
	#else
		freopen (".in","r",stdin);
		freopen (".out","w",stdout);
	#endif
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		b[i] = a[i];
	}
	for(int i = 2; i < n; i++){
		if(a[i] != a[i - 1] && a[i] != a[i + 1])ans++;
	}
	bool even = 0;
	if(ans % 2 == 0)
		even = 1;
	ans = (ans + 1) / 2;
	int cnt = 1;
	bool ok = 0;
	cout << ans << endl;
	for(int i = 2; i < n; i++){
		if(a[i] != a[i - 1] && a[i] != a[i + 1]){
			b[i] = (a[i] + cnt) % 2;
			if(!ok){
				cnt ++;
				if(cnt > ans){
					if(even){
						cnt = ans;
						ok = 1;
					}else{
						cnt = ans - 1;
					}
				}
			}else cnt--;
		}
	}
	for(int i = 1; i <= n; i++)
		cout << b[i] << " ";
return 0;
}


/*
 * Problem:
 * Author:  SHJWUDP
 * Created Time:  2015/10/25 星期日 17:04:57
 * File Name: 1001.cpp
 * State:
 * Memo:
 */
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

int n, m;
bool judge(vector<int> & arr) {
    int lt=arr[0];
    bool flag=0;
    for(int i=1; i<n-1; ++i) {
        int x;
        if(lt==arr[i] || arr[i]==arr[i+1]) x=arr[i];
        else x=lt;
        lt=arr[i];
        if(x!=arr[i]) flag=1;
        arr[i]=x;
    }
    for(auto x : arr) cout<<x<<" ";
    cout<<endl;
    return flag;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    while(cin>>n) {
        vector<int> arr(n);
        for(int i=0; i<n; ++i) cin>>arr[i];
        int ret=0, cnt=0;
        vector<int> ans(arr.begin(), arr.end());
        int color;
        for(int i=1; i<n-1; ++i) {
            if(arr[i-1]==arr[i] || arr[i]==arr[i+1]) {
                ret=max(ret, (cnt+1)>>1);
                cnt=0;
                continue;
            }
            if(cnt==0) {
                color=arr[i-1];
            }
            ans[i]=color;
            ++cnt;
        }
        if(cnt & 1) {
            ret=max(ret, (cnt+1)>>1);
        } else if(cnt!=0) {
            ret=cnt>>1;
            int mid=n>>1;
            for(int i=1; i<mid; ++i) ans[i]=ans[0];
            for(int i=mid; i<n; ++i) ans[i]=ans[n-1];
        }
        cout<<ret<<endl;
        for(int i=0; i<n; ++i) cout<<ans[i]<<" \n"[i==n-1];
    }
    return 0;
}


/*
 * Problem:
 * Author:  SHJWUDP
 * Created Time:  2015/10/25 星期日 17:04:57
 * File Name: 1001.cpp
 * State:
 * Memo:
 */
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

int n, m;
bool judge(vector<int> & arr) {
    int lt=arr[0];
    bool flag=0;
    for(int i=1; i<n-1; ++i) {
        int x;
        if(lt==arr[i] || arr[i]==arr[i+1]) x=arr[i];
        else x=lt;
        lt=arr[i];
        if(x!=arr[i]) flag=1;
        arr[i]=x;
    }
    for(auto x : arr) cout<<x<<" ";
    cout<<endl;
    return flag;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    while(cin>>n) {
        vector<int> arr(n);
        for(int i=0; i<n; ++i) cin>>arr[i];
        int ret=0, cnt=0;
        vector<int> ans(arr.begin(), arr.end());
        int color;
        for(int i=1; i<n-1; ++i) {
            if(arr[i-1]==arr[i] || arr[i]==arr[i+1]) {
                ret=max(ret, (cnt+1)>>1);
                cnt=0;
                continue;
            }
            if(cnt==0) {
                color=arr[i-1];
            }
            ans[i]=color;
            ++cnt;
        }
        if(cnt & 1) {
            ret=max(ret, (cnt+1)>>1);
        } else if(cnt==0) {
            ret=cnt>>1;
            int mid=n>>1;
            for(int i=1; i<mid; ++i) ans[i]=ans[0];
            for(int i=mid; i<n; ++i) ans[i]=ans[n-1];
        }
        cout<<ret<<endl;
        for(int i=0; i<n; ++i) cout<<ans[i]<<" \n"[i==n-1];
    }
    return 0;
}


/*
 * Problem:
 * Author:  SHJWUDP
 * Created Time:  2015/10/25 星期日 17:04:57
 * File Name: 1001.cpp
 * State:
 * Memo:
 */
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

int n, m;
bool judge(vector<int> & arr) {
    int lt=arr[0];
    bool flag=0;
    for(int i=1; i<n-1; ++i) {
        int x;
        if(lt==arr[i] || arr[i]==arr[i+1]) x=arr[i];
        else x=lt;
        lt=arr[i];
        if(x!=arr[i]) flag=1;
        arr[i]=x;
    }
    for(auto x : arr) cout<<x<<" ";
    cout<<endl;
    return flag;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    while(cin>>n) {
        vector<int> arr(n);
        for(int i=0; i<n; ++i) cin>>arr[i];
        int ret=0, cnt=0;
        vector<int> ans(arr.begin(), arr.end());
        int color;
        for(int i=1; i<n-1; ++i) {
            if(arr[i-1]==arr[i] || arr[i]==arr[i+1]) {
                if(cnt & 1) {
                    ret=max(ret, (cnt+1)>>1);
                } else if(cnt!=0) {
                //  cout<<"??"<<endl;
                    ret=max(ret, cnt>>1);
                    int pos=i-1;
                //  cout<<"mid: "<<mid<<endl;
                    int mid=pos-cnt+(cnt>>1);
                    for(int j=pos-cnt+1; j<=mid; ++j) ans[j]=arr[pos-cnt];
                    for(int j=mid+1; j<=pos; ++j) ans[j]=arr[pos+1];
                }
                cnt=0;
                continue;
            }
            if(cnt==0) {
                color=arr[i-1];
            }
            ans[i]=color;
            ++cnt;
        }
        if(cnt & 1) {
            ret=max(ret, (cnt+1)>>1);
        } else if(cnt!=0) {
            ret=max(ret, cnt>>1);
            int pos=n-2;
            int mid=pos-cnt+(cnt>>1);
            for(int j=pos-cnt+1; j<=mid; ++j) ans[j]=arr[pos-cnt];
            for(int j=mid+1; j<=pos; ++j) ans[j]=arr[pos+1];
        }
        cout<<ret<<endl;
        for(int i=0; i<n; ++i) cout<<ans[i]<<" \n"[i==n-1];
    }
    return 0;
}


/*
 * Problem:
 * Author:  SHJWUDP
 * Created Time:  2015/10/25 星期日 17:04:57
 * File Name: 1001.cpp
 * State:
 * Memo:
 */
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

int n, m;
bool judge(vector<int> & arr) {
    int lt=arr[0];
    bool flag=0;
    for(int i=1; i<n-1; ++i) {
        int x;
        if(lt==arr[i] || arr[i]==arr[i+1]) x=arr[i];
        else x=lt;
        lt=arr[i];
        if(x!=arr[i]) flag=1;
        arr[i]=x;
    }
    for(auto x : arr) cout<<x<<" ";
    cout<<endl;
    return flag;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    while(cin>>n) {
        vector<int> arr(n);
        for(int i=0; i<n; ++i) scanf("%d", &arr[i]);
        int ret=0, cnt=0;
        vector<int> ans(arr.begin(), arr.end());
        int color;
        for(int i=1; i<n-1; ++i) {
            if(arr[i-1]==arr[i] || arr[i]==arr[i+1]) {
                if(cnt & 1) {
                    ret=max(ret, (cnt+1)>>1);
                } else if(cnt!=0) {
                    ret=max(ret, cnt>>1);
                    int pos=i-1;
                    int mid=pos-cnt+(cnt>>1);
                    for(int j=pos-cnt+1; j<=mid; ++j) ans[j]=arr[pos-cnt];
                    for(int j=mid+1; j<=pos; ++j) ans[j]=arr[pos+1];
                }
                cnt=0;
                continue;
            }
            if(cnt==0) {
                color=arr[i-1];
            }
            ans[i]=color;
            ++cnt;
        }
        if(cnt & 1) {
            ret=max(ret, (cnt+1)>>1);
        } else if(cnt!=0) {
            ret=max(ret, cnt>>1);
            int pos=n-2;
            int mid=pos-cnt+(cnt>>1);
            for(int j=pos-cnt+1; j<=mid; ++j) ans[j]=arr[pos-cnt];
            for(int j=mid+1; j<=pos; ++j) ans[j]=arr[pos+1];
        }
        cout<<ret<<endl;
        for(int i=0; i<n; ++i) cout<<ans[i]<<" \n"[i==n-1];
    }
    return 0;
}


/*
 * Problem:
 * Author:  SHJWUDP
 * Created Time:  2015/10/25 星期日 17:04:57
 * File Name: 1001.cpp
 * State:
 * Memo:
 */
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

int n, m;
bool judge(vector<int> & arr) {
    int lt=arr[0];
    bool flag=0;
    for(int i=1; i<n-1; ++i) {
        int x;
        if(lt==arr[i] || arr[i]==arr[i+1]) x=arr[i];
        else x=lt;
        lt=arr[i];
        if(x!=arr[i]) flag=1;
        arr[i]=x;
    }
    for(auto x : arr) cout<<x<<" ";
    cout<<endl;
    return flag;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    while(cin>>n) {
        vector<int> arr(n);
        for(int i=0; i<n; ++i) cin>>arr[i];
        int ret=0, cnt=0;
        vector<int> ans(arr.begin(), arr.end());
        int color;
        for(int i=1; i<n-1; ++i) {
            if(arr[i-1]==arr[i] || arr[i]==arr[i+1]) {
                ret=max(ret, (cnt+1)>>1);
                cnt=0;
                continue;
            }
            if(cnt==0) {
                color=arr[i-1];
            }
            ans[i]=color;
            ++cnt;
        }
        ret=max(ret, (cnt+1)>>1);
        cout<<ret<<endl;
        for(int i=0; i<n; ++i) cout<<ans[i]<<" \n"[i==n-1];
    }
    return 0;
}


/*
 * Problem:
 * Author:  SHJWUDP
 * Created Time:  2015/10/25 星期日 17:04:57
 * File Name: 1001.cpp
 * State:
 * Memo:
 */
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

int n, m;
bool judge(vector<int> & arr) {
    int lt=arr[0];
    bool flag=0;
    for(int i=1; i<n-1; ++i) {
        int x;
        if(lt==arr[i] || arr[i]==arr[i+1]) x=arr[i];
        else x=lt;
        lt=arr[i];
        if(x!=arr[i]) flag=1;
        arr[i]=x;
    }
    for(auto x : arr) cout<<x<<" ";
    cout<<endl;
    return flag;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    while(cin>>n) {
        vector<int> arr(n);
        for(int i=0; i<n; ++i) cin>>arr[i];
        int ret=0, cnt=0;
        vector<int> ans(arr.begin(), arr.end());
        int color;
        for(int i=1; i<n-1; ++i) {
            if(arr[i-1]==arr[i] || arr[i]==arr[i+1]) {
                if(cnt & 1) {
                    ret=max(ret, (cnt+1)>>1);
                } else if(cnt!=0) {
                    //cout<<"??"<<endl;
                    ret=max(ret, cnt>>1);
                    int mid=i-cnt+(cnt>>1);
                    for(int j=i-cnt+1; j<=mid; ++j) ans[j]=arr[i-cnt];
                    for(int j=mid+1; j<=i; ++j) ans[j]=arr[i+1];
                }
                cnt=0;
                continue;
            }
            if(cnt==0) {
                color=arr[i-1];
            }
            ans[i]=color;
            ++cnt;
        }
        if(cnt & 1) {
            ret=max(ret, (cnt+1)>>1);
        } else if(cnt!=0) {
            ret=max(ret, cnt>>1);
            int i=n-2;
            int mid=i-cnt+(cnt>>1);
            for(int j=i-cnt+1; j<=mid; ++j) ans[j]=arr[i-cnt];
            for(int j=mid+1; j<=i; ++j) ans[j]=arr[i+1];
        }
        cout<<ret<<endl;
        for(int i=0; i<n; ++i) cout<<ans[i]<<" \n"[i==n-1];
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int t, n, m, k, a[500010], q, l, r;
int lt[500010], rt[500010];

int b[500010];

int32_t main(){
INIT
cin>>n;
for(int i=1; i<=n; i++){char c; cin>>c; a[i]=(c-'0');}

int ln=0;
int lmax=0;

for(int i=1; i<=n; i++){
   if(a[i]==((ln%2))){
    ln++;
   }
   else{
        ln=0;
   }
   if( (ln>0) ){
    lt[i]=(ln)/2;
   }
   lmax=max(lmax, (ln-1)/2);
}
ln=0;
for(int i=n; i>=0; i--){
    if(a[i]==((ln%2))){
        ln++;
    }
    else{
        ln=0;
    }

   if( (ln>0) ){
        rt[i]=(ln)/2;
   }
}

ln=0;
for(int i=1; i<=n; i++){
    if(a[i]==1){
        ln++;
    }
    else{
        if( (ln>1) || ( (i==2) && (ln==1) ) ){
            for(int j=i; j<=(i+rt[i]-1); j++){
                b[j]=1;
            }
        }
        ln=0;
    }
    if(ln>1){
        b[i-1]=1; b[i]=1;
    }
}

ln=0;
for(int i=n; i>=1; i--){
    if(a[i]==1){
        ln++;
    }
    else{
        if( (ln>1) || ( (i==(n-1) )&&(ln==1)) ){
            for(int j=i;  (j>0) && (j>=(i-lt[i]+1)); j-- ){
                b[j]=1;
            }
        }
    ln=0;
    }
    if(ln>1){
        b[i]=1; b[i+1]=1;
    }
}

b[1]=a[1]; b[n]=a[n];

for(int i=1; i<=n; i++){
    a[i]=b[i];
}

int l2=lmax;
for(int i=2; i<n; i++){
    if( (a[i]+a[i+1]+a[i-1]>=2) ){
        if( (b[i]==0) && (l2==lmax) ){
            l2++;
        }
        b[i]=1;
    }
    else{
        if( (b[i]==1) && (l2==lmax) ){
            l2++;
        }
        b[i]=0;
    }
}

cout<<l2<<"\n";
for(int i=1; i<=n; i++){
    cout<<b[i]<<" ";
}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int t, n, m, k, a[500010], q, l, r;
int lt[500010], rt[500010];

int b[500010];

int32_t main(){
INIT
cin>>n;
for(int i=1; i<=n; i++){char c; cin>>c; a[i]=(c-'0');}

int ln=0;
int lmax=0;

for(int i=1; i<=n; i++){
   if(a[i]==((ln%2))){
    ln++;
   }
   else{
        ln=0;
   }
   if( (ln>0) ){
    lt[i]=(ln-1)/2;
   }
   lmax=max(lmax, (ln-1)/2);
}
ln=0;
for(int i=n; i>=0; i--){
    if(a[i]==((ln%2))){
        ln++;
    }
    else{
        ln=0;
    }

   if( (ln>0) ){
        rt[i]=(ln-1)/2;
   }
}

ln=0;
for(int i=1; i<=n; i++){
    if(a[i]==1){
        ln++;
    }
    else{
        if( (ln>1) || ( (i==2) && (ln==1) ) ){
            for(int j=i; j<=(i+rt[i]-1); j++){
                b[j]=1;
            }
        }
        ln=0;
    }
    if(ln>1){
        b[i-1]=1; b[i]=1;
    }
}

ln=0;
for(int i=n; i>=1; i--){
    if(a[i]==1){
        ln++;
    }
    else{
        if( (ln>1) || ( (i==(n-1) )&&(ln==1)) ){
            for(int j=i;  (j>0) && (j>=(i-lt[i]+1)); j-- ){
                b[j]=1;
            }
        }
    ln=0;
    }
    if(ln>1){
        b[i]=1; b[i+1]=1;
    }
}

b[1]=a[1]; b[n]=a[n];

for(int i=1; i<=n; i++){
    a[i]=b[i];
}

int l2=lmax;
for(int i=2; i<n; i++){
    if( (a[i]+a[i+1]+a[i-1]>=2) ){
        if( (b[i]==0) && (l2==lmax) ){
            l2++;
        }
        b[i]=1;
    }
    else{
        if( (b[i]==1) && (l2==lmax) ){
            l2++;
        }
        b[i]=0;
    }
}

cout<<l2<<"\n";
for(int i=1; i<=n; i++){
    cout<<b[i]<<" ";
}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int t, n, m, k, a[500010], q, l, r;
int lt[500010], rt[500010];

int b[500010];

int32_t main(){
INIT
cin>>n;
for(int i=1; i<=n; i++){char c; cin>>c; a[i]=(c-'0');}

int ln=0;
int lmax=0;

for(int i=1; i<=n; i++){
   if(a[i]==((ln%2))){
    ln++;
   }
   else{
        ln=0;
   }
   if( (ln>0) ){
    lt[i]=(ln-1)/2;
   }
   lmax=max(lmax, (ln-1)/2);
}
ln=0;
for(int i=n; i>=0; i--){
    if(a[i]==((ln%2))){
        ln++;
    }
    else{
        ln=0;
    }

   if( (ln>0) ){
        rt[i]=(ln-1)/2;
   }
}

ln=0;
for(int i=1; i<=n; i++){
    if(a[i]==1){
        ln++;
    }
    else{
        if( (ln>1) || ( (i==2) && (ln==1) ) ){
            for(int j=i; j<=(i+rt[i]-1); j++){
                b[j]=1;
            }
        }
        ln=0;
    }
    if(ln>1){
        b[i-1]=1; b[i]=1;
    }
}

ln=0;
for(int i=n; i>=1; i--){
    if(a[i]==1){
        ln++;
    }
    else{
        if( (ln>1) || ( (i==(n-1) )&&(ln==1)) ){
            for(int j=i;  (j>0) && (j>=(i-lt[i]+1)); j-- ){
                b[j]=1;
            }
        }
    ln=0;
    }
    if(ln>1){
        b[i]=1; b[i+1]=1;
    }
}

b[1]=a[1]; b[n]=a[n];

for(int i=1; i<=n; i++){
    a[i]=b[i];
}

int l2=lmax;
for(int i=2; i<n; i++){
    if( (a[i]+a[i+1]+a[i-1]>=2) ){
        if( (b[i]==0) && (l2==lmax) ){
            l2++;
        }
        b[i]=1;
    }
    else{
        b[i]=0;
    }
}

cout<<l2<<"\n";
for(int i=1; i<=n; i++){
    cout<<b[i]<<" ";
}

return 0;
}


#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T> inline void gmax(T &a,T b){if(b>a)a=b;}
template <class T> inline void gmin(T &a,T b){if(b<a)a=b;}
const int N=5e5+10,M=0,Z=1e9+7,ms63=1061109567;
int n;
int a[N];
int cnt(int l,int r)
{
    int len=r-l+1;
    if(len<3)return 0;
    /*接下来的判断可以省略if(a[l]==a[r])
    {
        for(int i=l+1;i<r;i++)a[i]=a[l];
    }
    else*/
    {
        int half=(l+r)>>1;
        for(int i=l+1;i<=half;i++)a[i]=a[l];
        for(int i=half+1;i<r;i++)a[i]=a[r];
    }
    return (len-1)/2;
}
int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        int ans=0;
        int l=1;
        for(int i=1;i<n;i++)
        {
            if(a[i]==a[i+1])
            {
                gmax(ans,cnt(l,i));
                l=i+1;
            }
        }
        gmax(ans,cnt(l,n));
        printf("%d\n",ans);
        for(int i=1;i<=n;i++)printf("%d ",a[i]);
        puts("");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int s[500010];
int c[26];
int main() {
	int n;
	while(~scanf("%d", &n)) {
		for(int i = 1; i <= n; i++) scanf("%d", &s[i]);
		int ans = 0;
		int flag = 0;
		for(int i = 2; i < n; i++) {
			int cnt0, cnt1;
			cnt0 = cnt1 = 0;
			for(int j = -1; j <= 1; j++)
				if(s[i + j] == 1) cnt1++;
				else cnt0++;
			if(cnt1 > cnt0 && s[i] == 0) flag = 1;
			if(cnt0 > cnt1 && s[i] == 1) flag = 1;
			if(s[i] == 0 && s[i - 1] == 1 && s[i + 1] == 1 && s[i + 2] == 0 && s[i - 2] == 0) ans++;
		}
		if(flag) ans++;
		printf("%d\n", ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ii pair<ll,ll>
#define vi vector<ll>
#define N int(1e6)
#define vii vector<ii>
int ans[N];
int a[N];
bool is[N];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=1;i<n;i++){
        if(a[i]!=a[i-1]){
            is[i]=1;
        }
    }
    for(int i=0;i<n;i++){
        if(!is[i])
            ans[i]=a[i];
    }
    int fst,lst,cnt=0;
    int an=0;
    for(int i=0;i<n;i++){
        if(!is[i]&&i+1==n)  break;
        if(!is[i]&&a[i+1]!=a[i]){
            cnt=0;
            fst=a[i];
            int j=i;
            while(is[j+1]&&j+1<n)
                j++;
            lst=a[j];
            if(fst==lst){
                cnt+=(j-i)/2;
                for(int k=i;k<=j;k++)
                    ans[k]=fst;
            }
            else{
              //  cout<<j<<" "<<i<<endl;
                cnt+=(j-i)/2;
                ans[i]=fst;
                ans[j]=lst;
                for(int k=i+1;k<j+i;k++){
                    if(k<=(i+j)/2)  ans[k]=fst;
                    else            ans[k]=lst;
                }
            }
            an=max(an,cnt);
        }
    }
    cout<<an<<endl;
    for(int i=0;i<n;i++)
        cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ii pair<ll,ll>
#define vi vector<ll>
#define N int(1e6)
#define vii vector<ii>
int ans[N];
int a[N];
bool is[N];
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=1;i<n;i++){
        if(a[i]!=a[i-1]){
            is[i]=1;
        }
    }
    for(int i=0;i<n;i++){
        if(!is[i])
            ans[i]=a[i];
    }
    int fst,lst,cnt=0;
    for(int i=0;i<n;i++){
        if(!is[i]&&i+1==n)  break;
        if(!is[i]&&a[i+1]!=a[i]){
            fst=a[i];
            int j=i;
            while(is[j+1]&&j+1<n)
                j++;
            lst=a[j];
            if(fst==lst){
                cnt+=(j-i)/2;
                for(int k=i;k<=j;k++)
                    ans[k]=fst;
            }
            else{
              //  cout<<j<<" "<<i<<endl;
                cnt+=(j-i)/2;
                ans[i]=fst;
                ans[j]=lst;
                for(int k=i+1;k<j+i;k++){
                    if(k<=(i+j)/2)  ans[k]=fst;
                    else            ans[k]=lst;
                }
            }
        }
    }
    cout<<cnt<<endl;
    for(int i=0;i<n;i++)
        cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ii pair<ll,ll>
#define vi vector<ll>
#define N int(1e6)
#define vii vector<ii>
int ans[N];
int a[N];
bool is[N];
int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=1;i<n;i++){
        if(a[i]!=a[i-1]){
            is[i]=1;
        }
    }
    for(int i=0;i<n;i++){
        if(!is[i])
            ans[i]=a[i];
    }
    int fst,lst,cnt=0;
    int an=0;
    for(int i=0;i<n;i++){
        if(!is[i]&&i+1==n)  break;
        if(!is[i]&&a[i+1]!=a[i]){
            cnt=0;
            fst=a[i];
            int j=i;
            while(is[j+1]&&j+1<n)
                j++;
            lst=a[j];
            if(fst==lst){
                cnt+=(j-i)/2;
                for(int k=i;k<=j;k++)
                    ans[k]=fst;
            }
            else{
              //  cout<<j<<" "<<i<<endl;
                cnt+=(j-i)/2;
                ans[i]=fst;
                ans[j]=lst;
                for(int k=i+1;k<j+i;k++){
                    if(k<=(i+j)/2)  ans[k]=fst;
                    else            ans[k]=lst;
                }
            }
            an=max(an,cnt);
        }
    }
    cout<<an<<endl;
    for(int i=0;i<n;i++)
        cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ii pair<ll,ll>
#define vi vector<ll>
#define N int(1e6)
#define vii vector<ii>
int ans[N];
int a[N];
bool is[N];
int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=1;i<n;i++){
        if(a[i]!=a[i-1]){
            is[i]=1;
        }
    }
    for(int i=0;i<n;i++){
        if(!is[i])
            ans[i]=a[i];
    }
    int fst,lst,cnt=0;
    int an=0;
    for(int i=0;i<n;i++){
        if(!is[i]&&i+1==n)  break;
        if(!is[i]&&a[i+1]!=a[i]){
            cnt=0;
            fst=a[i];
            int j=i;
            while(is[j+1]&&j+1<n)
                j++;
            lst=a[j];
            if(fst==lst){
                cnt+=(j-i)/2;
                for(int k=i;k<=j;k++)
                    ans[k]=fst;
            }
            else{
              //  cout<<j<<" "<<i<<endl;
                cnt+=(j-i)/2;
                ans[i]=fst;
                ans[j]=lst;
                for(int k=i+1;k<j+i;k++){
                    if(k<=(i+j)/2)  ans[k]=fst;
                    else            ans[k]=lst;
                }
            }
            i=j;
            an=max(an,cnt);
        }
    }
    cout<<an<<endl;
    for(int i=0;i<n;i++)
        cout<<ans[i]<<" ";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ii pair<ll,ll>
#define vi vector<ll>
#define N int(1e6)
#define vii vector<ii>
int ans[N];
int a[N];
bool is[N];
int main(){
  //  freopen("in.txt","r",stdin);
   // ios_base::sync_with_stdio(false);
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int nn;

    for(int i=1;i<n;i++){
        if(a[i]!=a[i-1]){
            is[i]=1;
        }
    }
    for(int i=0;i<n;i++){
        if(!is[i])
            ans[i]=a[i];
    }
    int fst,lst,cnt=0;
    int an=0;
    for(int i=0;i<n;i++){
        if(is[i])   continue;
       // system("pause");
        if(!is[i]&&i+1==n)  break;
        if(!is[i]&&a[i+1]!=a[i]){
            cnt=0;
            fst=a[i];
            int j=i;
            while(j+1<n&&is[j+1])
                j++;
            lst=a[j];
            if(fst==lst){
                cnt+=(j-i)/2;
                for(int k=i;k<=j;k++)
                    ans[k]=fst;
            }
            else{
              //  cout<<j<<" "<<i<<endl;
                cnt+=(j-i)/2;
                ans[i]=fst;
                ans[j]=lst;
                for(int k=i+1;k<j;k++){
                    if(k<=(i+j)/2)  ans[k]=fst;
                    else            ans[k]=lst;
                }
            }
          //  cout<<i<<" "<<j<<endl;
            i=j;
            an=max(an,cnt);
        }
    }
    printf("%d\n",an);
    for(int i=0;i<n;i++)
        printf("%d ",ans[i]);
    printf("\n");
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ii pair<ll,ll>
#define vi vector<ll>
#define N int(1e6)
#define vii vector<ii>
int ans[N];
int a[N];
bool is[N];
int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];

    for(int i=1;i<n;i++){
        if(a[i]!=a[i-1]){
            is[i]=1;
        }
    }
    for(int i=0;i<n;i++){
        if(!is[i])
            ans[i]=a[i];
    }
    int fst,lst,cnt=0;
    int an=0;
    for(int i=0;i<n;i++){
        if(!is[i]&&i+1==n)  break;
        if(!is[i]&&a[i+1]!=a[i]){
            cnt=0;
            fst=a[i];
            int j=i;
            while(j+1<n&&is[j+1])
                j++;
            lst=a[j];
            if(fst==lst){
                cnt+=(j-i)/2;
                for(int k=i;k<=j;k++)
                    ans[k]=fst;
            }
            else{
              //  cout<<j<<" "<<i<<endl;
                cnt+=(j-i)/2;
                ans[i]=fst;
                ans[j]=lst;
                for(int k=i+1;k<j+i;k++){
                    if(k<=(i+j)/2)  ans[k]=fst;
                    else            ans[k]=lst;
                }
            }
            i=j;
            an=max(an,cnt);
        }
    }
    cout<<an<<endl;
    for(int i=0;i<n;i++)
        cout<<ans[i]<<" ";
    cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int n,a[500100],b[500100];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    b[1]=a[1]; b[n]=a[n];
    int cnt=0,l=2,r=n-1;
    int flag=1;
    while(flag)
    {
        flag=0; cnt++;
        for(int i=l;i<=r;i++)
        {
            if((a[i]-a[i-1])*(a[i]-a[i+1])<=0)
            {
                b[i]=a[i];
                continue;
            }
            else
            {
                if((a[i-1]-a[i])*(a[i-1]-a[i+1])<=0)
                {
                    flag=1;
                    b[i]=a[i-1];
                    continue;
                }
                else
                {
                    flag=1;
                    b[i]=a[i+1];
                    continue;
                }
            }
        }
        int fuck=0;
        while(a[l]==b[l]) {l++; fuck=1;}
        while(a[r]==b[r]) {r--; fuck=1;}
        if(!fuck&&cnt>3) {cnt=-1; break;}
        for(int i=1;i<=n;i++) { a[i]=b[i];}
    }
    if(cnt<0) {cout<<cnt<<endl; return 0;}
    cout<<cnt-1<<endl;
    for(int i=1;i<=n;i++)
        printf("%d%c",a[i],i==n?'\n':' ');
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,a[500100],b[500100];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    b[1]=a[1]; b[n]=a[n];
    int cnt=0,l=2,r=n-1;
    int flag=1;
    while(flag)
    {
        flag=0; cnt++;
        for(int i=l;i<=r;i++)
        {
            if((a[i]-a[i-1])*(a[i]-a[i+1])<=0)
            {
                b[i]=a[i];
                continue;
            }
            else
            {
                if((a[i-1]-a[i])*(a[i-1]-a[i+1])<=0)
                {
                    flag=1;
                    b[i]=a[i-1];
                    continue;
                }
                else
                {
                    flag=1;
                    b[i]=a[i+1];
                    continue;
                }
            }
        }
        int fuck=0;
        while(a[l]==b[l]) {l++; fuck=1;}
        while(a[r]==b[r]) {r--; fuck=1;}
        if(!fuck&&cnt>3) {cnt=-1; break;}
        for(int i=l;i<=r;i++) { a[i]=b[i];}
    }
    if(cnt<0) {cout<<cnt<<endl; return 0;}
    cout<<cnt-1<<endl;
    for(int i=1;i<=n;i++)
        printf("%d%c",a[i],i==n?'\n':' ');
    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;
	while (i < n)
	{

		while(i < n-1 && p[i] != p[i+1])
		{
			p[i] = cavegol;
			i++;
		}
		cavegol = p[i];
		i++;
	}

	forn(j,n)
	{
		if (j)
			cout << " ";
		cout << p[j];
	}
	cout << endl;

	return 0;
}