#include <bits/stdc++.h>
using namespace std;
         
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define eb emplace_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size() 
#define ara cout<<"ara-ara\n"; 

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 <<"\n";
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif


// naive Bipartite matcher 
// runs in O(E*V)
// no augmenting path  <==>  max matching 
struct BipartiteMatcher
{
    ll n1,n2;
    vector<ll>match;
    vector<vector<ll>>adj;
    vector<bool>visited;

    BipartiteMatcher(ll l,ll r)
    {
        n1=l;
        n2=r;
        match.resize(n2+1,-1);
        adj.resize(n1+1);
        visited.resize(n1+1);
    }    

    void addEdge(ll u,ll v)
    {
        adj[u].push_back(v);
    }

    bool dfs(ll u)
    {   
        if(visited[u])  return 0;
        visited[u]=1;
        for(auto j : adj[u])
        {
            if(match[j]==-1 || dfs(match[j]))
            {
                match[j]=u;
                return 1;
            }
        }
        return 0;
    }

    void findMatching()
    {
        for(ll i=1;i<=n1;i++)
        {
            for(ll j=1;j<=n1;j++) visited[j]=0;
            dfs(i);    
        }
    }

    void print()
    {
        f(i,1,n2+1)
        {
            if(match[i]!=-1)
            {
                cout<<match[i]<<" "<<i<<"\n";
            }
        }
    }
};


const ll N=(1<<10)+5;
ll d,n,a[N],pos[N];

ll conv(string s)
{
  ll res=0;
  f(i,0,d)
  {
    ll pval=d-1-i;
    if(s[i]=='1') res^=(1<<pval);
  }
  return res;
}


void func()
{
  cin>>d>>n;
  vector<pll>vec;
  vec.eb(infl,infl);
  f(i,1,n+1)
  {
    string s;
    cin>>s;
    a[i]=conv(s);
    vec.eb(__builtin_popcountll(a[i]),i);
  }
  sort(ALL(vec));
  reverse(ALL(vec));
  f(i,1,n+1) pos[vec[i].S]=i;
  
  BipartiteMatcher M(n,n);
  f(i,1,n+1)
  {
    f(j,1,n+1)
    {
        if(i!=j && (a[i]&a[j]) == a[i] )  M.addEdge(pos[i],pos[j]); 
    }
  }

  M.findMatching();

  vector< vll >chains;
  vll R(n+1,-1);
  vector<bool> head(n+1,0);
  f(i,1,n+1) 
  {
    if(M.match[i]!=-1) R[M.match[i]]=i;
    else head[i]=1;
  }

  f(i,1,n+1)
  {
    if(head[i])
    {
       ll u=i;
       vll curr;
       while(u!=-1)
       {
            curr.pb(u);
            u=R[u]; 
       }
       chains.pb(curr);
    }
  }
  
  vll ans;
  f(i,0,sz(chains))
  {
    vll &v=chains[i];
    ll curr=0;
    for(auto j : v)
    { 
       ll value=a[vec[j].S],want=(value^curr);
       f(bit,0,d) if( want&(1LL<<bit) ) ans.pb(bit);
       curr=value;
    }
    if(i!=sz(chains)-1) ans.pb(-1);
  }

  cout<<sz(ans)<<"\n";
  for(auto i : ans)
  {
    if(i==-1) cout<<"R ";
    else cout<<d-1-i<<" ";
  }
  cout<<"\n";

}
     
int main() 
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE

    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
       //cout<<"Case #"<<i<<": ";
       //cout<<"\n";
       func();
       //clr();
    }
     
    return 0;
}

### Prompt

Generate 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 fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define eb emplace_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size() 
#define ara cout<<"ara-ara\n"; 

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 <<"\n";
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif


// naive Bipartite matcher 
// runs in O(E*V)
// no augmenting path  <==>  max matching 
struct BipartiteMatcher
{
    ll n1,n2;
    vector<ll>match;
    vector<vector<ll>>adj;
    vector<bool>visited;

    BipartiteMatcher(ll l,ll r)
    {
        n1=l;
        n2=r;
        match.resize(n2+1,-1);
        adj.resize(n1+1);
        visited.resize(n1+1);
    }    

    void addEdge(ll u,ll v)
    {
        adj[u].push_back(v);
    }

    bool dfs(ll u)
    {   
        if(visited[u])  return 0;
        visited[u]=1;
        for(auto j : adj[u])
        {
            if(match[j]==-1 || dfs(match[j]))
            {
                match[j]=u;
                return 1;
            }
        }
        return 0;
    }

    void findMatching()
    {
        for(ll i=1;i<=n1;i++)
        {
            for(ll j=1;j<=n1;j++) visited[j]=0;
            dfs(i);    
        }
    }

    void print()
    {
        f(i,1,n2+1)
        {
            if(match[i]!=-1)
            {
                cout<<match[i]<<" "<<i<<"\n";
            }
        }
    }
};


const ll N=(1<<10)+5;
ll d,n,a[N],pos[N];

ll conv(string s)
{
  ll res=0;
  f(i,0,d)
  {
    ll pval=d-1-i;
    if(s[i]=='1') res^=(1<<pval);
  }
  return res;
}


void func()
{
  cin>>d>>n;
  vector<pll>vec;
  vec.eb(infl,infl);
  f(i,1,n+1)
  {
    string s;
    cin>>s;
    a[i]=conv(s);
    vec.eb(__builtin_popcountll(a[i]),i);
  }
  sort(ALL(vec));
  reverse(ALL(vec));
  f(i,1,n+1) pos[vec[i].S]=i;
  
  BipartiteMatcher M(n,n);
  f(i,1,n+1)
  {
    f(j,1,n+1)
    {
        if(i!=j && (a[i]&a[j]) == a[i] )  M.addEdge(pos[i],pos[j]); 
    }
  }

  M.findMatching();

  vector< vll >chains;
  vll R(n+1,-1);
  vector<bool> head(n+1,0);
  f(i,1,n+1) 
  {
    if(M.match[i]!=-1) R[M.match[i]]=i;
    else head[i]=1;
  }

  f(i,1,n+1)
  {
    if(head[i])
    {
       ll u=i;
       vll curr;
       while(u!=-1)
       {
            curr.pb(u);
            u=R[u]; 
       }
       chains.pb(curr);
    }
  }
  
  vll ans;
  f(i,0,sz(chains))
  {
    vll &v=chains[i];
    ll curr=0;
    for(auto j : v)
    { 
       ll value=a[vec[j].S],want=(value^curr);
       f(bit,0,d) if( want&(1LL<<bit) ) ans.pb(bit);
       curr=value;
    }
    if(i!=sz(chains)-1) ans.pb(-1);
  }

  cout<<sz(ans)<<"\n";
  for(auto i : ans)
  {
    if(i==-1) cout<<"R ";
    else cout<<d-1-i<<" ";
  }
  cout<<"\n";

}
     
int main() 
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE

    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
       //cout<<"Case #"<<i<<": ";
       //cout<<"\n";
       func();
       //clr();
    }
     
    return 0;
}

```