#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define lowbit(x) x&-x
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define UNI(x) sort(ALL(x)),x.resize(unique(ALL(x))-x.begin())
#define GETPOS(c,x) (lower_bound(ALL(c),x)-c.begin())
#define LEN(x) strlen(x)
#define MS0(x) memset((x),0,sizeof((x)))
#define Rint register int
#define ls (u<<1)
#define rs (u<<1|1)
typedef unsigned int unit;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<pii> Vpii;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(ull &x) { scanf("%llu", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.fi);putchar(' '); _W(x.se);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const int MOD=1e9+7,mod=998244353;
ll qpow(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
const int MAXN=1e4+10,MAXM=8e6+10;
const int INF=INT_MAX,SINF=0x3f3f3f3f;
const ll llINF=LLONG_MAX,SLINF=0x3f3f3f3f3f3f3f3f;
const int inv2=(MOD+1)/2;
const int Lim=1<<20;

struct MCMF
{
    struct Edge
    {
        int to,nxt,flow,cost;
    }e[MAXM];
    int head[MAXN],ecnt=-1,dis[MAXN],cur[MAXN];
    void add_edge(int u,int v,int f,int c)
    {
        e[++ecnt]={v,head[u],f,c};head[u]=ecnt;
        e[++ecnt]={u,head[v],0,-c};head[v]=ecnt;
    }
    int n,m,s,t,total;
    bool vis[MAXN];
    bool spfa()
    {
        memset(dis,0x3f,(n+5)*sizeof(int));
        memset(vis,0,(n+5));
        queue<int> q;
        dis[s]=1;
        q.push(s);
        while(!q.empty())
        {
            int u=q.front();q.pop();
            vis[u]=0;
            for(int i=head[u];~i;i=e[i].nxt)
            {
                int v=e[i].to;
                if(dis[v]>dis[u]+e[i].cost&&e[i].flow>0)
                {
                    dis[v]=dis[u]+e[i].cost;
                    if(!vis[v])q.push(v);
                    vis[v]=1;
                }
            }
        }
        return dis[t]!=SINF;
    }
    int dfs(int u,int flow)
    {
        if(u==t)return flow;
        int nowflow=0;
        vis[u]=1;
        for(int &i=cur[u];~i;i=e[i].nxt)
        {
            int v=e[i].to;
            if(dis[v]==dis[u]+e[i].cost&&e[i].flow>0&&!vis[v])
            {
                int tmp=dfs(v,min(flow,e[i].flow));
                e[i].flow-=tmp;
                e[i^1].flow+=tmp;
                flow-=tmp;
                nowflow+=tmp;
                total+=tmp*e[i].cost;
                if(!flow)break;
            }
        }
        return nowflow;
    }
    pii solve()
    {
        int ans=0;
        while(spfa())
        {
            memcpy(cur,head,(n+5)*sizeof(int));
            vis[t]=1;
            while(vis[t])
            {
                memset(vis,0,(n+5));
                ans+=dfs(s,INF);
            }
        }
        return {total,ans};
    }
    void init()
    {
        ecnt=-1;
        total=0;
        memset(head,-1,sizeof(head));
    }
}G;
// This is a Maxcost version. remember to init the s,t,n
// If you want to get a Mincost version, you can simply change the memset and < in Dijkstra and BellmanFord and the priority_queue

int d,n,s,s2,t;
int a[MAXN],indo[MAXN];
int nd;
Vpii g[MAXN];
bool tp[MAXM];
Vi ans;
void dfs(int u)
{
    if(u!=s)
    {
        if(ans.back()==-1)return;
    }
    while(!g[u].empty()&&!G.e[g[u].back().fi].flow)g[u].pop_back();
    assert(!g[u].empty());
    auto p=g[u].back();
    if(tp[p.fi])
    {
        tp[p.fi]=0;
        ans.pb(-1);
        g[u].pop_back();
        return;
    }
    assert(G.e[p.fi].flow>0);
    G.e[p.fi].flow--;
    int p1=u,p2=p.se;
    if(u==s)p1=0;
    p2-=p1;
    for(int j=0;j<d;j++)
        if(p2&(1<<j))ans.pb(j);
    dfs(p.se);
}

void solve()
{
    R(d,n);
    G.init();
    int all=(1<<d);
    for(int i=1;i<=n;i++)
    {
        char s[20];R(s);
        for(int j=0;j<d;j++)a[i]+=(s[j]-'0')*(1<<j);
    }
    for(int i=1;i<all;i++)
    {
        G.add_edge(i*2-1,i*2,SINF,1);
    }
    nd=(all-1)*2;
    s=++nd,t=++nd;
    G.s=++nd;G.t=++nd;
    G.n=nd;
    for(int i=1;i<=n;i++)
    {
        G.add_edge(a[i]*2,t,1,0);
        tp[G.ecnt]=1;
        g[a[i]].pb({G.ecnt,t});
        G.add_edge(G.s,a[i]*2,1,0);
        G.add_edge(a[i]*2-1,G.t,1,0);
    }
    for(int i=1;i<all;i++)if(__builtin_popcount(i)==1)
    {
        G.add_edge(s,i*2-1,SINF,0);
        g[s].pb({G.ecnt,i});
    }
    for(int i=1;i<all;i++)
        for(int j=0;j<d;j++)
        {
            if(((1<<j)&i)==0)
            {
                int p=i|(1<<j);
                G.add_edge(i*2,p*2-1,SINF,0);
                g[i].pb({G.ecnt,p});
            }
        }
    G.add_edge(t,s,SINF,1);
    auto p=G.solve();
    W(p.fi+n-1);
    while(SZ(g[s]))
    {
        dfs(s);
        while(!g[s].empty()&&!G.e[g[s].back().fi].flow)g[s].pop_back();
    }
    ans.pop_back();
    for(auto j:ans)
    {
        if(j!=-1)printf("%d ",j);
        else printf("R ");
    }
    W("");
}

int main()
{
    int T=1;
    //scanf("%d",&T);
    for(int kase=1;kase<=T;kase++)
    {
        //printf("Case #%d: ",kase);
        solve();
    }
    return 0;
}

### Prompt

Your challenge is to write a CPP solution to the following problem:

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;
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define lowbit(x) x&-x
#define pb push_back
#define ALL(x) (x).begin(),(x).end()
#define UNI(x) sort(ALL(x)),x.resize(unique(ALL(x))-x.begin())
#define GETPOS(c,x) (lower_bound(ALL(c),x)-c.begin())
#define LEN(x) strlen(x)
#define MS0(x) memset((x),0,sizeof((x)))
#define Rint register int
#define ls (u<<1)
#define rs (u<<1|1)
typedef unsigned int unit;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<pii> Vpii;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(ull &x) { scanf("%llu", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.fi);putchar(' '); _W(x.se);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const int MOD=1e9+7,mod=998244353;
ll qpow(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
const int MAXN=1e4+10,MAXM=8e6+10;
const int INF=INT_MAX,SINF=0x3f3f3f3f;
const ll llINF=LLONG_MAX,SLINF=0x3f3f3f3f3f3f3f3f;
const int inv2=(MOD+1)/2;
const int Lim=1<<20;

struct MCMF
{
    struct Edge
    {
        int to,nxt,flow,cost;
    }e[MAXM];
    int head[MAXN],ecnt=-1,dis[MAXN],cur[MAXN];
    void add_edge(int u,int v,int f,int c)
    {
        e[++ecnt]={v,head[u],f,c};head[u]=ecnt;
        e[++ecnt]={u,head[v],0,-c};head[v]=ecnt;
    }
    int n,m,s,t,total;
    bool vis[MAXN];
    bool spfa()
    {
        memset(dis,0x3f,(n+5)*sizeof(int));
        memset(vis,0,(n+5));
        queue<int> q;
        dis[s]=1;
        q.push(s);
        while(!q.empty())
        {
            int u=q.front();q.pop();
            vis[u]=0;
            for(int i=head[u];~i;i=e[i].nxt)
            {
                int v=e[i].to;
                if(dis[v]>dis[u]+e[i].cost&&e[i].flow>0)
                {
                    dis[v]=dis[u]+e[i].cost;
                    if(!vis[v])q.push(v);
                    vis[v]=1;
                }
            }
        }
        return dis[t]!=SINF;
    }
    int dfs(int u,int flow)
    {
        if(u==t)return flow;
        int nowflow=0;
        vis[u]=1;
        for(int &i=cur[u];~i;i=e[i].nxt)
        {
            int v=e[i].to;
            if(dis[v]==dis[u]+e[i].cost&&e[i].flow>0&&!vis[v])
            {
                int tmp=dfs(v,min(flow,e[i].flow));
                e[i].flow-=tmp;
                e[i^1].flow+=tmp;
                flow-=tmp;
                nowflow+=tmp;
                total+=tmp*e[i].cost;
                if(!flow)break;
            }
        }
        return nowflow;
    }
    pii solve()
    {
        int ans=0;
        while(spfa())
        {
            memcpy(cur,head,(n+5)*sizeof(int));
            vis[t]=1;
            while(vis[t])
            {
                memset(vis,0,(n+5));
                ans+=dfs(s,INF);
            }
        }
        return {total,ans};
    }
    void init()
    {
        ecnt=-1;
        total=0;
        memset(head,-1,sizeof(head));
    }
}G;
// This is a Maxcost version. remember to init the s,t,n
// If you want to get a Mincost version, you can simply change the memset and < in Dijkstra and BellmanFord and the priority_queue

int d,n,s,s2,t;
int a[MAXN],indo[MAXN];
int nd;
Vpii g[MAXN];
bool tp[MAXM];
Vi ans;
void dfs(int u)
{
    if(u!=s)
    {
        if(ans.back()==-1)return;
    }
    while(!g[u].empty()&&!G.e[g[u].back().fi].flow)g[u].pop_back();
    assert(!g[u].empty());
    auto p=g[u].back();
    if(tp[p.fi])
    {
        tp[p.fi]=0;
        ans.pb(-1);
        g[u].pop_back();
        return;
    }
    assert(G.e[p.fi].flow>0);
    G.e[p.fi].flow--;
    int p1=u,p2=p.se;
    if(u==s)p1=0;
    p2-=p1;
    for(int j=0;j<d;j++)
        if(p2&(1<<j))ans.pb(j);
    dfs(p.se);
}

void solve()
{
    R(d,n);
    G.init();
    int all=(1<<d);
    for(int i=1;i<=n;i++)
    {
        char s[20];R(s);
        for(int j=0;j<d;j++)a[i]+=(s[j]-'0')*(1<<j);
    }
    for(int i=1;i<all;i++)
    {
        G.add_edge(i*2-1,i*2,SINF,1);
    }
    nd=(all-1)*2;
    s=++nd,t=++nd;
    G.s=++nd;G.t=++nd;
    G.n=nd;
    for(int i=1;i<=n;i++)
    {
        G.add_edge(a[i]*2,t,1,0);
        tp[G.ecnt]=1;
        g[a[i]].pb({G.ecnt,t});
        G.add_edge(G.s,a[i]*2,1,0);
        G.add_edge(a[i]*2-1,G.t,1,0);
    }
    for(int i=1;i<all;i++)if(__builtin_popcount(i)==1)
    {
        G.add_edge(s,i*2-1,SINF,0);
        g[s].pb({G.ecnt,i});
    }
    for(int i=1;i<all;i++)
        for(int j=0;j<d;j++)
        {
            if(((1<<j)&i)==0)
            {
                int p=i|(1<<j);
                G.add_edge(i*2,p*2-1,SINF,0);
                g[i].pb({G.ecnt,p});
            }
        }
    G.add_edge(t,s,SINF,1);
    auto p=G.solve();
    W(p.fi+n-1);
    while(SZ(g[s]))
    {
        dfs(s);
        while(!g[s].empty()&&!G.e[g[s].back().fi].flow)g[s].pop_back();
    }
    ans.pop_back();
    for(auto j:ans)
    {
        if(j!=-1)printf("%d ",j);
        else printf("R ");
    }
    W("");
}

int main()
{
    int T=1;
    //scanf("%d",&T);
    for(int kase=1;kase<=T;kase++)
    {
        //printf("Case #%d: ",kase);
        solve();
    }
    return 0;
}

```