#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

const int N = 5000;
const int INF = 0x3f3f3f3f;

struct Edge {
	int to, flow;
	pii cst;
};

pii operator +(const pii &p1, const pii &p2) { return { p1.fi + p2.fi, p1.se + p2.se }; }
pii operator -(const pii &p1, const pii &p2) { return { p1.fi - p2.fi, p1.se - p2.se }; }
pii& operator +=(pii &p1, const pii &p2) { p1.fi += p2.fi; p1.se += p2.se; return p1; }
pii operator *(int x, const pii &p1) { return { x * p1.fi, x * p1.se }; }
pii operator -(const pii &p1) { return { -p1.fi, -p1.se }; }

int source, sink;
int v[N], prv[N], vis[N], nBits[N], prvSol[N];
bool st[N];
vector<int> ans;
pii reald[N], newd[N], d[N];
vector<int> adj[N];
vector<Edge> edges;

void addEdge(int a, int b, int cap, pii cst) {
	//dbg(a, b, cst);
	adj[a].push_back(edges.size());
	edges.push_back({b, cap, cst});

	adj[b].push_back(edges.size());
	edges.push_back({a, 0, -cst});
}

void bellman() {
	priority_queue<pair<pii, int>> q;
	memset(d, INF, sizeof d);

	for(d[source] = { 0, 0 }, q.push({-d[source], source}); !q.empty(); ) {
		pii dst = -q.top().fi;
		int v = q.top().se;
		q.pop();

		if(dst != d[v]) continue;

		for(auto id : adj[v]) {
			int u = edges[id].to;
			if(edges[id].flow && d[v] + edges[id].cst < d[u]) {
				d[u] = d[v] + edges[id].cst;
				q.push({-d[u], u});
			}
		}
	}
}

bool dijkstra() {
	priority_queue<pair<pii, int>> q;
	memset(newd, INF, sizeof newd);
	memset(vis, 0, sizeof vis);

	for(reald[source] = newd[source] = { 0, 0 }, q.push({-d[source], source}); !q.empty(); ) {
		pii dst = -q.top().fi;
		int v = q.top().se;
		q.pop();

		if(vis[v]) continue;
		vis[v] = true;

		for(auto id : adj[v]) {
			int u = edges[id].to;
			pii w = d[v] + edges[id].cst - d[u];
			if(edges[id].flow && newd[v] + w < newd[u]) {
				newd[u] = newd[v] + w;
				reald[u] = reald[v] + edges[id].cst;
				prv[u] = id;
				q.push({-newd[u], u});
			}
		}
	}

	return newd[sink].fi < INF;
}

pii getFlow() {
	int flow = 0;
	pii cst;

	bellman();

	for(cst = { 0, 0 }; dijkstra(); ) {
		int pushed = INF;
		pii currCst = { 0, 0 };
		for(int v = sink; v != source; v = edges[prv[v] ^ 1].to) {
			pushed = min(pushed, edges[prv[v]].flow);
			currCst += pushed * edges[prv[v]].cst;
		}

		if(currCst.fi == 0 && currCst.se > 0) break;
		//dbg(currCst);
		cst += currCst;

		flow += pushed;
		for(int v = sink; v != source; v = edges[prv[v] ^ 1].to) {
			edges[prv[v]].flow -= pushed;
			edges[prv[v] ^ 1].flow += pushed;
		}

		memcpy(d, reald, sizeof reald);
	}

	return { flow, cst.se };
}

int convert(const string &s) {
	int x = 0;
	for(int i = 0; i < s.length(); ++i) if(s[i] == '1') x |= 1 << i;
	return x;
}

void doo(int x, int d){
  if (prvSol[x]){
    doo(prvSol[x], d);
  }
 
  int y = v[x] ^ v[prvSol[x]];
  for (int j=0;j<d;j++){
    if (y & (1<<j)){
      ans.push_back(j);
    }
  }
}

int main()
{
	ios_base::sync_with_stdio(false);
	
	int d, n;
	string s;

	cin >> d >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> s;
		v[i] = convert(s);
		nBits[i] = __builtin_popcount(v[i]);
	}

	source = 0;
	sink = 2 * n + 1;
	for(int i = 1; i <= n; ++i) {
		addEdge(source, 2 * i - 1, 1, make_pair(0, nBits[i]));
		addEdge(2 * i - 1, 2 * i, 1, make_pair(-1, 0));
		addEdge(2 * i, sink, 1, make_pair(0, 0));

		for(int j = 1; j <= n; ++j)
			if(i != j && (v[i] & v[j]) == v[i])
				addEdge(2 * i, 2 * j - 1, 1, make_pair(0, nBits[j] - nBits[i]));
	}


	pii cst = getFlow();
	//cout << cst.fi + cst.se - 1 << '\n';

	//for(int id : adj[2]) dbg(edges[id].to, edges[id].flow);
	for(int i = 1; i <= n; ++i) st[i] = true;
	for(int i = 1; i <= n; ++i)
		for(auto id : adj[2 * i]) {
			if(id & 1) continue;
			if(edges[id].flow) continue;
			if(edges[id].to == sink) continue;

			prvSol[edges[id].to / 2 + 1] = i;
			st[i] = false;
		}
	bool first = true;
	for(int i = 1; i <= n; ++i)
		if(st[i]) {
			if(!first) ans.push_back(-1);
			doo(i, d);
			first = false;
		}

	cout << ans.size() << '\n';
  for (auto it : ans){
    if (it != -1){
      cout << it << ' ';
    }
    else{
      cout << "R ";
    }
  }
  cout << '\n';

	return 0;
}

### Prompt

Construct a cpp code solution to the problem outlined:

You are standing in front of the room with great treasures. The only thing stopping you is the door with a push-button combination lock. This lock has d buttons with digits from 0 to d - 1. Whenever you press a button, it stays pushed down. You can not pop back up just one button, but there is a "RESET" button — pressing it pops up all other buttons. Initially, no buttons are pushed down.

The door instantly opens when some specific set of digits is pushed down. Sadly, you don't know the password for it. Having read the documentation for this specific lock, you found out that there are n possible passwords for this particular lock. 

Find the shortest sequence of button presses, such that all possible passwords appear at least once during its execution. Any shortest correct sequence of button presses will be accepted.

Input

The first line contains two integers d and n (1 ≤ d ≤ 10; 1 ≤ n ≤ 2^d - 1). Next n lines describe possible passwords. Each line contains a string s_i of d zeros and ones: for all j from 1 to d the j-th character is 1 iff the button with the digit j - 1 must be pushed down.

All strings s_i are different, and each string contains at least one 1.

Output

On the first line, print the number k — the minimum number of button presses. On the second line, print k tokens, describing the sequence. Whenever you press a button with a digit, print that digit. Whenever you press "RESET", print "R".

Examples

Input


2 2
10
11


Output


2
0 1 


Input


3 4
001
111
101
011


Output


6
2 0 R 1 2 0 

Note

In the second example, the sequence 1 2 R 2 0 1 is also possible.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

const int N = 5000;
const int INF = 0x3f3f3f3f;

struct Edge {
	int to, flow;
	pii cst;
};

pii operator +(const pii &p1, const pii &p2) { return { p1.fi + p2.fi, p1.se + p2.se }; }
pii operator -(const pii &p1, const pii &p2) { return { p1.fi - p2.fi, p1.se - p2.se }; }
pii& operator +=(pii &p1, const pii &p2) { p1.fi += p2.fi; p1.se += p2.se; return p1; }
pii operator *(int x, const pii &p1) { return { x * p1.fi, x * p1.se }; }
pii operator -(const pii &p1) { return { -p1.fi, -p1.se }; }

int source, sink;
int v[N], prv[N], vis[N], nBits[N], prvSol[N];
bool st[N];
vector<int> ans;
pii reald[N], newd[N], d[N];
vector<int> adj[N];
vector<Edge> edges;

void addEdge(int a, int b, int cap, pii cst) {
	//dbg(a, b, cst);
	adj[a].push_back(edges.size());
	edges.push_back({b, cap, cst});

	adj[b].push_back(edges.size());
	edges.push_back({a, 0, -cst});
}

void bellman() {
	priority_queue<pair<pii, int>> q;
	memset(d, INF, sizeof d);

	for(d[source] = { 0, 0 }, q.push({-d[source], source}); !q.empty(); ) {
		pii dst = -q.top().fi;
		int v = q.top().se;
		q.pop();

		if(dst != d[v]) continue;

		for(auto id : adj[v]) {
			int u = edges[id].to;
			if(edges[id].flow && d[v] + edges[id].cst < d[u]) {
				d[u] = d[v] + edges[id].cst;
				q.push({-d[u], u});
			}
		}
	}
}

bool dijkstra() {
	priority_queue<pair<pii, int>> q;
	memset(newd, INF, sizeof newd);
	memset(vis, 0, sizeof vis);

	for(reald[source] = newd[source] = { 0, 0 }, q.push({-d[source], source}); !q.empty(); ) {
		pii dst = -q.top().fi;
		int v = q.top().se;
		q.pop();

		if(vis[v]) continue;
		vis[v] = true;

		for(auto id : adj[v]) {
			int u = edges[id].to;
			pii w = d[v] + edges[id].cst - d[u];
			if(edges[id].flow && newd[v] + w < newd[u]) {
				newd[u] = newd[v] + w;
				reald[u] = reald[v] + edges[id].cst;
				prv[u] = id;
				q.push({-newd[u], u});
			}
		}
	}

	return newd[sink].fi < INF;
}

pii getFlow() {
	int flow = 0;
	pii cst;

	bellman();

	for(cst = { 0, 0 }; dijkstra(); ) {
		int pushed = INF;
		pii currCst = { 0, 0 };
		for(int v = sink; v != source; v = edges[prv[v] ^ 1].to) {
			pushed = min(pushed, edges[prv[v]].flow);
			currCst += pushed * edges[prv[v]].cst;
		}

		if(currCst.fi == 0 && currCst.se > 0) break;
		//dbg(currCst);
		cst += currCst;

		flow += pushed;
		for(int v = sink; v != source; v = edges[prv[v] ^ 1].to) {
			edges[prv[v]].flow -= pushed;
			edges[prv[v] ^ 1].flow += pushed;
		}

		memcpy(d, reald, sizeof reald);
	}

	return { flow, cst.se };
}

int convert(const string &s) {
	int x = 0;
	for(int i = 0; i < s.length(); ++i) if(s[i] == '1') x |= 1 << i;
	return x;
}

void doo(int x, int d){
  if (prvSol[x]){
    doo(prvSol[x], d);
  }
 
  int y = v[x] ^ v[prvSol[x]];
  for (int j=0;j<d;j++){
    if (y & (1<<j)){
      ans.push_back(j);
    }
  }
}

int main()
{
	ios_base::sync_with_stdio(false);
	
	int d, n;
	string s;

	cin >> d >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> s;
		v[i] = convert(s);
		nBits[i] = __builtin_popcount(v[i]);
	}

	source = 0;
	sink = 2 * n + 1;
	for(int i = 1; i <= n; ++i) {
		addEdge(source, 2 * i - 1, 1, make_pair(0, nBits[i]));
		addEdge(2 * i - 1, 2 * i, 1, make_pair(-1, 0));
		addEdge(2 * i, sink, 1, make_pair(0, 0));

		for(int j = 1; j <= n; ++j)
			if(i != j && (v[i] & v[j]) == v[i])
				addEdge(2 * i, 2 * j - 1, 1, make_pair(0, nBits[j] - nBits[i]));
	}


	pii cst = getFlow();
	//cout << cst.fi + cst.se - 1 << '\n';

	//for(int id : adj[2]) dbg(edges[id].to, edges[id].flow);
	for(int i = 1; i <= n; ++i) st[i] = true;
	for(int i = 1; i <= n; ++i)
		for(auto id : adj[2 * i]) {
			if(id & 1) continue;
			if(edges[id].flow) continue;
			if(edges[id].to == sink) continue;

			prvSol[edges[id].to / 2 + 1] = i;
			st[i] = false;
		}
	bool first = true;
	for(int i = 1; i <= n; ++i)
		if(st[i]) {
			if(!first) ans.push_back(-1);
			doo(i, d);
			first = false;
		}

	cout << ans.size() << '\n';
  for (auto it : ans){
    if (it != -1){
      cout << it << ' ';
    }
    else{
      cout << "R ";
    }
  }
  cout << '\n';

	return 0;
}

```