This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC optimize("O3,Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
const double EPS = 0.00001;
const int INF = 1e7;
const int N = 3e5+5;
const int ALPH = 26;
const int LGN = 25;
constexpr int MOD = 1e9+7;
int n = 5,m,q;
vector<vector<int> > valid;
bool shorten(vector<int> &x) {
    for(int i = 1; i < x.size(); i++) { 
        int j1 = i, j2 = i - 1;
        bool f1 = 1;
        while(j1 < x.size() && j2 >= 0) {
            if(x[j1] != x[j2]) {
                f1 = 0;
                break;
            } 
            j1++; j2--;
        }
        if(f1) {
            // cout << "wtf:" << i << " " << j1 << " " << j2 <<  "\n";
            if(j1 == x.size()) {
                while((int)x.size() > i) {
                    x.pop_back();
                }
                return 1;
            }
            else {
                vector<int> tmp;
                for(int j = i; j < x.size(); j++) {
                    tmp.pb(x[j]);
                }
                swap(tmp, x);
                return 1;
            }
        }
    }
    return 0;
}
void answer(vector<int> ar) {
    vector<int> tmp = ar;
    while(shorten(ar)) {}
    if(ar.size() <= 2) {
        valid.pb(tmp);
    }
}
void gen_arr(int ind, vector<int> &ar) {
    if(ind == n) {
        answer(ar);
        return;
    }
    REP(i, 2) {
        ar[ind] = i;
        gen_arr(ind + 1, ar);
    }
}
vector<int> a;
int get_cost(array<int,2> x) {
    int cost = INF;
    for(auto &arr : valid) {
        int ret = 0;
        for(int i = 0; i < n; i++) {
            if(a[i] != x[arr[i]]) ret++;
        }
        cost = min(cost, ret);
        ret  = 0;
        for(int i = 0; i < n; i++) {
            if(a[i] != x[!arr[i]]) ret++;
        }
        cost = min(cost, ret);
    }
    return cost;
}
inline void solve() {
    cin >> n >> m;
    vector<int> ar;
    ar.resize(n);
    a.resize(n);
    gen_arr(0, ar);
    REP(i, n) cin >> a[i];
    vector<int> res(m + 1, INF);
    for(int i = 1; i <= m; i++) {
        for(int j = i; j <= m; j++) {
            int cur = get_cost({i, j});
            res[i] = min(res[i], cur);
            res[j] = min(res[j], cur);
        } 
    }
    for(int i = 1; i<=m; i++) {
        cout << res[i] << "\n";
    }
}
 
signed main() {
    fastio();
    int test = 1;
    //cin>>test;
    while(test--) {
        solve();
    }
    
}
Compilation message (stderr)
rope.cpp: In function 'bool shorten(std::vector<int>&)':
rope.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i = 1; i < x.size(); i++) {
      |                    ~~^~~~~~~~~~
rope.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         while(j1 < x.size() && j2 >= 0) {
      |               ~~~^~~~~~~~~~
rope.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |             if(j1 == x.size()) {
      |                ~~~^~~~~~~~~~~
rope.cpp:51:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |                 for(int j = i; j < x.size(); j++) {
      |                                ~~^~~~~~~~~~| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |