#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long llint ;
const int N = 100005;
const int sN = 3000;
const llint mod = 1000000007;
llint factorial[N];
llint factorial_reciprocal[N];
//=======================
int n,k;
int a[N];
int a_sort[N];
int a_count[N];
int b_count[N];
int tota,totb;
llint dp_a[N];
llint dp_b[sN][sN];
//=======================
int check(int p){
    if(p==0)return 1;
    if(p%10!=4 && p%10!=7 )return 0;
    return check(p/10);
}
llint quick_pow(llint a,llint b)
{
    llint ans=1;
    while(b>0){
        if(b&1)ans=(ans*a)%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
llint Combinatorial(llint n, llint m)
{
    return ((factorial[m]*factorial_reciprocal[n])%mod)*factorial_reciprocal[m-n]%mod;
}
void calculate_a(int tn)
{
    for(int i=0;i<=tn;i++)dp_a[i]=Combinatorial(i,tn);
}
void calculate_b(int totb){
    for(int i=0;i<=totb;i++)
    for(int j=0;j<=i;j++)
    {
        if(j==0)dp_b[i][j] = 1;
        else dp_b[i][j]=(dp_b[i-1][j]+dp_b[i-1][j-1]*b_count[i])%mod;
    }
}
//=======================
int main()
{
        //=============
        factorial[0] = 1;
        for(int i=1;i<N;i++)
            factorial[i] = factorial[i-1] * i % mod;
        for(int i=0;i<N;i++)
            factorial_reciprocal[i] = quick_pow(factorial[i],mod-2);
        //=============
        scanf("%d%d",&n, &k);
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        a_sort[++tota]=a[0];
        a_count[tota]++;
        for(int i=1;i<n;i++)
        {
            if(a[i]!=a[i-1])
            {
                a_sort[++tota] = a[i];
            }
            a_count[tota]++;
        }
        int tn = n;
        for(int i=1;i<=tota;i++)
        {
            if(a_sort[i]!=0&&check(a_sort[i]))
            {
                b_count[++totb] = a_count[i];
                tn-=a_count[i];
            }
        }
        //===================================
        calculate_a(tn);
        calculate_b(totb);

        llint ans = 0;
        for(int i=0;i<=k;i++)
        {
            if(tn>=i&&totb>=k-i)
                (ans+=(dp_b[totb][k-i]*dp_a[i])%mod)%=mod;

        }
        cout << ans;
}


/************* yogesh sharma *****************/
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <limits.h>

using namespace std;

#define rep(i,a,b) for(typeof(a) i=(a);i<(b);i++)
#define ll long long int
#define ii pair<int,int>
#define Clear(x,val) memset(x,val,sizeof(x))
#define SZ(v) (v).size()

const ll MOD = 1e9+7;
bool p[200007];
vector<int> plist;
void preprime(int till) {
	rep( i , 0 , till ) p[i] = false;
	int ST = sqrt(till+3);
	for( int i = 3; i <= ST; i+=2 ) {
		if(!p[i]) {
			for( int j = i*i; j < till ; j += (i+i) ) p[j] = true;
		}
	}
	plist.push_back(2);
	for( int i = 3; i < till; i += 2  ) if(!p[i]) plist.push_back(i);
}
ll powr( int x , int k ) {
	if( k == 0 ) return 1;
	ll ret = 1;
	if( k%2 ) ret = ret * x;
	ll nw = powr( x , k/2 );
	ret *= (nw);ret %= MOD;
	ret *= (nw);ret %= MOD;
	return ret;
}
ll bion( int n , int r ) {
	if( n < r ) return 0;
	int N = plist.size();
	int cnt[N+5];
	Clear( cnt , 0 );
	rep( i , 0 , N ) {
		int  p = plist[i];
		while( (n / p) > 0 ) {
			cnt[i] += (n/p)-(r/p)-((n-r)/p);
			p = p*plist[i];
		}
	}
	ll ret = 1;
	rep( i , 0 , N ) { ret *= powr( plist[i] , cnt[i]);ret %= MOD; }
	return ret;
}
int arr[100007];
map<int,int> mp;
int cnt[1025];
void lucky() {
	queue<ll> Q;Q.push(4);Q.push(7);
	int id = 1;
	while(!Q.empty()) {
		ll tp = Q.front();Q.pop();
		if( tp > 1e9 ) continue;
		if(!mp[tp]) mp[tp] = id++;
		ll nf = tp*10+4LL , ns = tp*10+7;
		Q.push(nf);Q.push(ns);
	}
}
ll fval[1025][1025];
void f() {
        Clear(fval , 0);
	rep( i , 0  , 1024 ) fval[i][0] = 1;
	fval[1024][1] = cnt[1024];

	for( int i = 1023; i>=0; i-- ) {
		for( int j = 1; j < 1025; j++ ) {
			fval[i][j] += (fval[i+1][j]) % MOD;
			if(cnt[i]>0) fval[i][j] += ( (cnt[i])*(fval[i+1][j-1]) )%MOD;
			fval[i][j] %= MOD;
		}
	}
//	cout << fval[1][1] << "\n";
}
int main()
{
	preprime(100007);mp.clear();lucky();Clear(cnt,0);

	int N  , K , ntluk = 0;cin >> N >> K;rep( i , 0 , N ) scanf("%d",&arr[i]);
	rep( i , 0 , N ) { if(mp[arr[i]]!=0){  cnt[mp[arr[i]]]++;}else ntluk++; }

	ll ans = 0;f();
	for( int i = min( K , ntluk ); i >= 0; i-- ) {
		if( i > 1024 || i > ntluk ) continue;
		else{
			 ans += (bion(ntluk , i)*fval[0][K-i])%MOD;
	//		 cout << ntluk  << " " << i <<   " " << K-i  <<" " << fval[0][K-i] << "\n";
		}
	}
	ans = (ans+2*MOD)%MOD;
	printf("%lld\n" , ans);
	return 0;
}


/************* yogesh sharma *****************/
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <limits.h>

using namespace std;

#define rep(i,a,b) for(typeof(a) i=(a);i<(b);i++)
#define ll long long int
#define ii pair<int,int>
#define Clear(x,val) memset(x,val,sizeof(x))
#define SZ(v) (v).size()

const ll MOD = 1e9+7;
bool p[200007];
vector<int> plist;
void preprime(int till) {
	rep( i , 0 , till ) p[i] = false;
	int ST = sqrt(till+3);
	for( int i = 3; i <= ST; i+=2 ) {
		if(!p[i]) {
			for( int j = i*i; j < till ; j += (i+i) ) p[j] = true;
		}
	}
	plist.push_back(2);
	for( int i = 3; i < till; i += 2  ) if(!p[i]) plist.push_back(i);
}
ll powr( int x , int k ) {
	if( k == 0 ) return 1;
	ll ret = 1;
	if( k%2 ) ret = ret * x;
	ll nw = powr( x , k/2 );
	ret *= (nw);ret %= MOD;
	ret *= (nw);ret %= MOD;
	return ret;
}
ll bion( int n , int r ) {
	if( n < r ) return 0;
	int N = plist.size();
	int cnt[N+5];
	Clear( cnt , 0 );
	rep( i , 0 , N ) {
		int  p = plist[i];
		while( (n / p) > 0 ) {
			cnt[i] += (n/p)-(r/p)-((n-r)/p);
			p = p*plist[i];
		}
	}
	ll ret = 1;
	rep( i , 0 , N ) { ret *= powr( plist[i] , cnt[i]);ret %= MOD; }
	return ret;
}
int arr[100007];
map<int,int> mp;
int cnt[560];
void lucky() {
	queue<ll> Q;Q.push(4);Q.push(7);
	int id = 1;
	while(!Q.empty()) {
		ll tp = Q.front();Q.pop();
		if( tp > 1e9 ) continue;
		mp[tp] = id++;
		ll nf = tp*10+4LL , ns = tp*10+7;
		Q.push(nf);Q.push(ns);
	}
}
ll f( int tot ,int id) {
	if( tot == 0 ) return 1;
	if( id > 512 ) return 0;
	ll ret = 0;
	ret = f( tot , id+1 );
	if(cnt[id]>0) ret += ( cnt[id]*f( tot-1 , id+1 ) ) %MOD;
	return ret;
}
int main()
{
	preprime(100007);mp.clear();lucky();Clear(cnt,0);

	int N  , K , ntluk = 0;cin >> N >> K;rep( i , 0 , N ) scanf("%d",&arr[i]);
	rep( i , 0 , N ) { if(mp[arr[i]]!=0) cnt[mp[arr[i]]]++;else ntluk++; }

	ll ans = 0;
	for( int i = K; i >= 0; i-- ) {
		if( i > ntluk ) continue;
		else ans += ((bion(ntluk , i)*f(K-i , 0 ))%MOD);
	}
	ans = (ans+2*MOD)%MOD;
	printf("%lld\n" , ans);
	return 0;
}


/************* yogesh sharma *****************/
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <limits.h>

using namespace std;

#define rep(i,a,b) for(typeof(a) i=(a);i<(b);i++)
#define ll long long int
#define ii pair<int,int>
#define Clear(x,val) memset(x,val,sizeof(x))
#define SZ(v) (v).size()

const ll MOD = 1e9+7;
bool p[200007];
vector<int> plist;
void preprime(int till) {
	rep( i , 0 , till ) p[i] = false;
	int ST = sqrt(till+3);
	for( int i = 3; i <= ST; i+=2 ) {
		if(!p[i]) {
			for( int j = i*i; j < till ; j += (i+i) ) p[j] = true;
		}
	}
	plist.push_back(2);
	for( int i = 3; i < till; i += 2  ) if(!p[i]) plist.push_back(i);
}
ll powr( int x , int k ) {
	if( k == 0 ) return 1;
	ll ret = 1;
	if( k%2 ) ret = ret * x;
	ll nw = powr( x , k/2 );
	ret *= (nw);ret %= MOD;
	ret *= (nw);ret %= MOD;
	return ret;
}
ll bion( int n , int r ) {
	if( n < r ) return 0;
	int N = plist.size();
	int cnt[N+5];
	Clear( cnt , 0 );
	rep( i , 0 , N ) {
		int  p = plist[i];
		while( (n / p) > 0 ) {
			cnt[i] += (n/p)-(r/p)-((n-r)/p);
			p = p*plist[i];
		}
	}
	ll ret = 1;
	rep( i , 0 , N ) { ret *= powr( plist[i] , cnt[i]);ret %= MOD; }
	return ret;
}
int arr[100007];
map<int,int> mp;
int cnt[1024];
void lucky() {
	queue<ll> Q;Q.push(4);Q.push(7);
	int id = 1;
	while(!Q.empty()) {
		ll tp = Q.front();Q.pop();
		if( tp > 1e9 ) continue;
		if(!mp[tp]) mp[tp] = id++;
		ll nf = tp*10+4LL , ns = tp*10+7;
		Q.push(nf);Q.push(ns);
	}
}
ll f( int tot ,int id) {
	if( tot == 0 ) return 1;
	if( id > 1022 ) return 0;
	ll ret = 0;
	ret = f( tot , id+1 );
	if(cnt[id]>0) ret += ( cnt[id]*f( tot-1 , id+1 ) ) %MOD;
	return ret;
}
int main()
{
	preprime(100007);mp.clear();lucky();Clear(cnt,0);

	int N  , K , ntluk = 0;cin >> N >> K;rep( i , 0 , N ) scanf("%d",&arr[i]);
	rep( i , 0 , N ) { if(mp[arr[i]]!=0){  cnt[mp[arr[i]]]++;}else ntluk++; }

	ll ans = 0;
	for( int i = K; i >= 0; i-- ) {
		if( i > ntluk ) continue;
		else{
			 ans += ((bion(ntluk , i)*f(K-i , 0 ))%MOD);
//			 cout << bion(ntluk , i ) << " " << f(K-i , 0  ) << "\n";
		}
	}
	ans = (ans+2*MOD)%MOD;
	printf("%lld\n" , ans);
	return 0;
}


/************* yogesh sharma *****************/
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <limits.h>

using namespace std;

#define rep(i,a,b) for(typeof(a) i=(a);i<(b);i++)
#define ll long long int
#define ii pair<int,int>
#define Clear(x,val) memset(x,val,sizeof(x))
#define SZ(v) (v).size()

const ll MOD = 1e9+7;
bool p[200007];
vector<int> plist;
void preprime(int till) {
	rep( i , 0 , till ) p[i] = false;
	int ST = sqrt(till+3);
	for( int i = 3; i <= ST; i+=2 ) {
		if(!p[i]) {
			for( int j = i*i; j < till ; j += (i+i) ) p[j] = true;
		}
	}
	plist.push_back(2);
	for( int i = 3; i < till; i += 2  ) if(!p[i]) plist.push_back(i);
}
ll powr( int x , int k ) {
	if( k == 0 ) return 1;
	ll ret = 1;
	if( k%2 ) ret = ret * x;
	ll nw = powr( x , k/2 );
	ret *= (nw);ret %= MOD;
	ret *= (nw);ret %= MOD;
	return ret;
}
ll bion( int n , int r ) {
	if( n < r ) return 0;
	int N = plist.size();
	int cnt[N+5];
	Clear( cnt , 0 );
	rep( i , 0 , N ) {
		int  p = plist[i];
		while( (n / p) > 0 ) {
			cnt[i] += (n/p)-(r/p)-((n-r)/p);
			p = p*plist[i];
		}
	}
	ll ret = 1;
	rep( i , 0 , N ) { ret *= powr( plist[i] , cnt[i]);ret %= MOD; }
	return ret;
}
int arr[100007];
map<int,int> mp;
int cnt[1024];
void lucky() {
	queue<ll> Q;Q.push(4);Q.push(7);
	int id = 1;
	while(!Q.empty()) {
		ll tp = Q.front();Q.pop();
		if( tp > 1e9 ) continue;
		if(!mp[tp]) mp[tp] = id++;
		ll nf = tp*10+4LL , ns = tp*10+7;
		Q.push(nf);Q.push(ns);
	}
}
ll f( int tot ,int id) {
	if( tot > (1023-id) ) return 0;
	if( tot == 0 ) return 1;
	if( id > 1022 ) return 0;
	ll ret = 0;
	ret = f( tot , id+1 );
	if(cnt[id]>0) ret += ( cnt[id]*f( tot-1 , id+1 ) ) %MOD;
	return ret;
}
int main()
{
	preprime(100007);mp.clear();lucky();Clear(cnt,0);

	int N  , K , ntluk = 0;cin >> N >> K;rep( i , 0 , N ) scanf("%d",&arr[i]);
	rep( i , 0 , N ) { if(mp[arr[i]]!=0){  cnt[mp[arr[i]]]++;}else ntluk++; }

	ll ans = 0;
	for( int i = K; i >= 0; i-- ) {
		if( i > ntluk ) continue;
		else{
			 ans += ((bion(ntluk , i)*f(K-i , 0 ))%MOD);
//			 cout << bion(ntluk , i ) << " " << f(K-i , 0  ) << "\n";
		}
	}
	ans = (ans+2*MOD)%MOD;
	printf("%lld\n" , ans);
	return 0;
}


/************* yogesh sharma *****************/
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <limits.h>

using namespace std;

#define rep(i,a,b) for(typeof(a) i=(a);i<(b);i++)
#define ll long long int
#define ii pair<int,int>
#define Clear(x,val) memset(x,val,sizeof(x))
#define SZ(v) (v).size()

const ll MOD = 1e9+7;
bool p[200007];
vector<int> plist;
void preprime(int till) {
	rep( i , 0 , till ) p[i] = false;
	int ST = sqrt(till+3);
	for( int i = 3; i <= ST; i+=2 ) {
		if(!p[i]) {
			for( int j = i*i; j < till ; j += (i+i) ) p[j] = true;
		}
	}
	plist.push_back(2);
	for( int i = 3; i < till; i += 2  ) if(!p[i]) plist.push_back(i);
}
ll powr( int x , int k ) {
	if( k == 0 ) return 1;
	ll ret = 1;
	if( k%2 ) ret = ret * x;
	ll nw = powr( x , k/2 );
	ret *= (nw);ret %= MOD;
	ret *= (nw);ret %= MOD;
	return ret;
}
ll bion( int n , int r ) {
	if( n < r ) return 0;
	int N = plist.size();
	int cnt[N+5];
	Clear( cnt , 0 );
	rep( i , 0 , N ) {
		int  p = plist[i];
		while( (n / p) > 0 ) {
			cnt[i] += (n/p)-(r/p)-((n-r)/p);
			p = p*plist[i];
		}
	}
	ll ret = 1;
	rep( i , 0 , N ) { ret *= powr( plist[i] , cnt[i]);ret %= MOD; }
	return ret;
}
int arr[100007];
map<int,int> mp;
int cnt[1024];
void lucky() {
	queue<ll> Q;Q.push(4);Q.push(7);
	int id = 1;
	while(!Q.empty()) {
		ll tp = Q.front();Q.pop();
		if( tp > 1e9 ) continue;
		if(!mp[tp]) mp[tp] = id++;
		ll nf = tp*10+4LL , ns = tp*10+7;
		Q.push(nf);Q.push(ns);
	}
}
ll f( int tot ,int id) {
	if( tot == 0 ) return 1;
	if( id > 1022 ) return 0;
	ll ret = 0;
	ret = f( tot , id+1 );
	if(cnt[id]>0) ret += ( cnt[id]*f( tot-1 , id+1 ) ) %MOD;
	return ret;
}
int main()
{
	preprime(100007);mp.clear();lucky();Clear(cnt,0);

	int N  , K , ntluk = 0;cin >> N >> K;rep( i , 0 , N ) scanf("%d",&arr[i]);
	rep( i , 0 , N ) { if(mp[arr[i]]!=0){  cnt[mp[arr[i]]]++;}else ntluk++; }

	ll ans = 0;
	for( int i = K; i >= 0; i-- ) {
		if( i > ntluk ) continue;
		else{
			 ans += ((bion(ntluk , i)*f(K-i , 0 ))%MOD);
			 cout << bion(ntluk , i ) << " " << f(K-i , 0  ) << "\n";
		}
	}
	ans = (ans+2*MOD)%MOD;
	printf("%lld\n" , ans);
	return 0;
}


/************* yogesh sharma *****************/
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <limits.h>

using namespace std;

#define rep(i,a,b) for(typeof(a) i=(a);i<(b);i++)
#define ll long long int
#define ii pair<int,int>
#define Clear(x,val) memset(x,val,sizeof(x))
#define SZ(v) (v).size()

const ll MOD = 1e9+7;
bool p[200007];
vector<int> plist;
void preprime(int till) {
	rep( i , 0 , till ) p[i] = false;
	int ST = sqrt(till+3);
	for( int i = 3; i <= ST; i+=2 ) {
		if(!p[i]) {
			for( int j = i*i; j < till ; j += (i+i) ) p[j] = true;
		}
	}
	plist.push_back(2);
	for( int i = 3; i < till; i += 2  ) if(!p[i]) plist.push_back(i);
}
ll powr( int x , int k ) {
	if( k == 0 ) return 1;
	ll ret = 1;
	if( k%2 ) ret = ret * x;
	ll nw = powr( x , k/2 );
	ret *= (nw);ret %= MOD;
	ret *= (nw);ret %= MOD;
	return ret;
}
ll bion( int n , int r ) {
	if( n < r ) return 0;
	int N = plist.size();
	int cnt[N+5];
	Clear( cnt , 0 );
	rep( i , 0 , N ) {
		int  p = plist[i];
		while( (n / p) > 0 ) {
			cnt[i] += (n/p)-(r/p)-((n-r)/p);
			p = p*plist[i];
		}
	}
	ll ret = 1;
	rep( i , 0 , N ) { ret *= powr( plist[i] , cnt[i]);ret %= MOD; }
	return ret;
}
int arr[100007];
map<int,int> mp;
int cnt[1025];
void lucky() {
	queue<ll> Q;Q.push(4);Q.push(7);
	int id = 1;
	while(!Q.empty()) {
		ll tp = Q.front();Q.pop();
		if( tp > 1e9 ) continue;
		if(!mp[tp]) mp[tp] = id++;
		ll nf = tp*10+4LL , ns = tp*10+7;
		Q.push(nf);Q.push(ns);
	}
}
int fval[1025][1025];
void f() {
        Clear(fval , 0);
	rep( i , 0  , 1024 ) fval[i][0] = 1;
	fval[1024][1] = cnt[1024];

	for( int i = 1023; i>=0; i-- ) {
		for( int j = 1; j < 1025; j++ ) {
			fval[i][j] += (fval[i+1][j]);
			if(cnt[i]>0) fval[i][j] += (cnt[i])*(fval[i+1][j-1]);
		}
	}
//	cout << fval[1][1] << "\n";
}
int main()
{
	preprime(100007);mp.clear();lucky();Clear(cnt,0);

	int N  , K , ntluk = 0;cin >> N >> K;rep( i , 0 , N ) scanf("%d",&arr[i]);
	rep( i , 0 , N ) { if(mp[arr[i]]!=0){  cnt[mp[arr[i]]]++;}else ntluk++; }

	ll ans = 0;f();
	for( int i = min( K , ntluk ); i >= 0; i-- ) {
		if( i > 1024 ) continue;
		else{
			 ans += (bion(ntluk , i)*fval[0][K-i])%MOD;
	//		 cout << ntluk  << " " << i <<   " " << K-i  <<" " << fval[0][K-i] << "\n";
		}
	}
	ans = (ans+2*MOD)%MOD;
	printf("%lld\n" , ans);
	return 0;
}


/************* yogesh sharma *****************/
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <limits.h>

using namespace std;

#define rep(i,a,b) for(typeof(a) i=(a);i<(b);i++)
#define ll long long int
#define ii pair<int,int>
#define Clear(x,val) memset(x,val,sizeof(x))
#define SZ(v) (v).size()

const ll MOD = 1e9+7;
bool p[200007];
vector<int> plist;
void preprime(int till) {
	rep( i , 0 , till ) p[i] = false;
	int ST = sqrt(till+3);
	for( int i = 3; i <= ST; i+=2 ) {
		if(!p[i]) {
			for( int j = i*i; j < till ; j += (i+i) ) p[j] = true;
		}
	}
	plist.push_back(2);
	for( int i = 3; i < till; i += 2  ) if(!p[i]) plist.push_back(i);
}
ll powr( int x , int k ) {
	if( k == 0 ) return 1;
	ll ret = 1;
	if( k%2 ) ret = ret * x;
	ll nw = powr( x , k/2 );
	ret *= (nw);ret %= MOD;
	ret *= (nw);ret %= MOD;
	return ret;
}
ll bion( int n , int r ) {
	if( n < r ) return 0;
	int N = plist.size();
	int cnt[N+5];
	Clear( cnt , 0 );
	rep( i , 0 , N ) {
		int  p = plist[i];
		while( (n / p) > 0 ) {
			cnt[i] += (n/p)-(r/p)-((n-r)/p);
			p = p*plist[i];
		}
	}
	ll ret = 1;
	rep( i , 0 , N ) { ret *= powr( plist[i] , cnt[i]);ret %= MOD; }
	return ret;
}
int arr[100007];
map<int,int> mp;
int cnt[1025];
void lucky() {
	queue<ll> Q;Q.push(4);Q.push(7);
	int id = 1;
	while(!Q.empty()) {
		ll tp = Q.front();Q.pop();
		if( tp > 1e9 ) continue;
		if(!mp[tp]) mp[tp] = id++;
		ll nf = tp*10+4LL , ns = tp*10+7;
		Q.push(nf);Q.push(ns);
	}
}
ll fval[1025][1025];
void f() {
        Clear(fval , 0);
	rep( i , 0  , 1024 ) fval[i][0] = 1;
	fval[1024][1] = cnt[1024];

	for( int i = 1023; i>=0; i-- ) {
		for( int j = 1; j < 1025; j++ ) {
			fval[i][j] += (fval[i+1][j]) % MOD;
			if(cnt[i]>0) fval[i][j] += ( (cnt[i])*(fval[i+1][j-1]) )%MOD;
		}
	}
//	cout << fval[1][1] << "\n";
}
int main()
{
	preprime(100007);mp.clear();lucky();Clear(cnt,0);

	int N  , K , ntluk = 0;cin >> N >> K;rep( i , 0 , N ) scanf("%d",&arr[i]);
	rep( i , 0 , N ) { if(mp[arr[i]]!=0){  cnt[mp[arr[i]]]++;}else ntluk++; }

	ll ans = 0;f();
	for( int i = min( K , ntluk ); i >= 0; i-- ) {
		if( i > 1024 ) continue;
		else{
			 ans += (bion(ntluk , i)*fval[0][K-i])%MOD;
	//		 cout << ntluk  << " " << i <<   " " << K-i  <<" " << fval[0][K-i] << "\n";
		}
	}
	ans = (ans+2*MOD)%MOD;
	printf("%lld\n" , ans);
	return 0;
}


/************* yogesh sharma *****************/
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <limits.h>

using namespace std;

#define rep(i,a,b) for(typeof(a) i=(a);i<(b);i++)
#define ll long long int
#define ii pair<int,int>
#define Clear(x,val) memset(x,val,sizeof(x))
#define SZ(v) (v).size()

const ll MOD = 1e9+7;
bool p[200007];
vector<int> plist;
void preprime(int till) {
	rep( i , 0 , till ) p[i] = false;
	int ST = sqrt(till+3);
	for( int i = 3; i <= ST; i+=2 ) {
		if(!p[i]) {
			for( int j = i*i; j < till ; j += (i+i) ) p[j] = true;
		}
	}
	plist.push_back(2);
	for( int i = 3; i < till; i += 2  ) if(!p[i]) plist.push_back(i);
}
ll powr( int x , int k ) {
	if( k == 0 ) return 1;
	ll ret = 1;
	if( k%2 ) ret = ret * x;
	ll nw = powr( x , k/2 );
	ret *= (nw);ret %= MOD;
	ret *= (nw);ret %= MOD;
	return ret;
}
ll bion( int n , int r ) {
	if( n < r ) return 0;
	int N = plist.size();
	int cnt[N+5];
	Clear( cnt , 0 );
	rep( i , 0 , N ) {
		int  p = plist[i];
		while( (n / p) > 0 ) {
			cnt[i] += (n/p)-(r/p)-((n-r)/p);
			p = p*plist[i];
		}
	}
	ll ret = 1;
	rep( i , 0 , N ) { ret *= powr( plist[i] , cnt[i]);ret %= MOD; }
	return ret;
}
int arr[100007];
map<int,int> mp;
int cnt[1025];
void lucky() {
	queue<ll> Q;Q.push(4);Q.push(7);
	int id = 1;
	while(!Q.empty()) {
		ll tp = Q.front();Q.pop();
		if( tp > 1e9 ) continue;
		if(!mp[tp]) mp[tp] = id++;
		ll nf = tp*10+4LL , ns = tp*10+7;
		Q.push(nf);Q.push(ns);
	}
}
ll fval[1025][1025];
void f() {
        Clear(fval , 0);
	rep( i , 0  , 1025 ) fval[i][0] = 1;
	fval[1024][1] = cnt[1024];

	for( int i = 1023; i>=0; i-- ) {
		for( int j = 1; j < 1025; j++ ) {
			fval[i][j] += (fval[i+1][j]) % MOD;
			if(cnt[i]>0) fval[i][j] += ( (cnt[i])*(fval[i+1][j-1]) );
			fval[i][j] %= MOD;
		}
	}
//	cout << fval[1][1] << "\n";
}
int main()
{
	preprime(100007);mp.clear();lucky();Clear(cnt,0);

	int N  , K , ntluk = 0;cin >> N >> K;rep( i , 0 , N ) scanf("%d",&arr[i]);
	rep( i , 0 , N ) { if(mp[arr[i]]!=0){  cnt[mp[arr[i]]]++;}else ntluk++; }

	ll ans = 0;f();
	for( int i = K ; i >= 0; i-- ) {
		if( (K-i) > 1024 || i > ntluk ) continue;
		else{
			 ans += (bion(ntluk , i)*fval[0][K-i])%MOD;
	//		 cout << ntluk  << " " << i <<   " " << K-i  <<" " << fval[0][K-i] << "\n";
		}
	}
	ans = (ans+2*MOD)%MOD;
	printf("%lld\n" , ans);
	return 0;
}


#define  _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<map>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stack>
#include<math.h>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<complex>
#include<assert.h>
#include<math.h>
#include<memory.h>
#include<sstream>
#include<cstdio>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define repi(i,a,n) for(int i=a;i<n;i++)

#define mp make_pair
#define pb push_back
#define fastIO ios::sync_with_stdio(false)
#define read freopen("in.in","r",stdin)
#define write freopen("out.out","w",stdout)
#define scf(xx) scanf("%d",&xx)
#define All(a) a.begin(), a.end()
#define LSOne(S) (S & (-S))

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long double ld;

#define X first
#define Y second

const ll mod = 1e9 + 7;
int n;
ll fact[100010];
pair<ll, pair<ll, ll> > extendedEuclid(ll a, ll b) {
	if (a == 0) return make_pair(b, make_pair(0, 1));
	pair<ll, pair<ll, ll> > p;
	p = extendedEuclid(b % a, a);
	return make_pair(p.first, make_pair(p.second.second - p.second.first*(b / a), p.second.first));
}

ll modInverse(ll a, ll m) {
	return (extendedEuclid(a, m).second.first + m) % m;
}

ll inverseMod(ll x, ll y, ll z){
	return ((x%z)*modInverse(y%z, z)) % z;
}
ll C(int n, int k) {
	return inverseMod(fact[n], fact[k] * fact[n - k],mod);
}
bool check(int x) {
	while (x) {
		if (x % 10 != 4 &&  x % 10 != 7) return 0;
		x /= 10;
	}
	return 1;
}
map<int, int> M;
vi co;
ll dp[1100][1100];
ll calc(int p, int  k){
	if (k == 0)return 1;
	if (p == co.size()) return 0;
	ll &ret = dp[p][k];
	if (ret != -1) return ret;
	ret = 0;
	ret += calc(p + 1, k);
	ret += calc(p + 1, k - 1)*co[p];
	return ret %= mod;
}
int main(){
	memset(dp, -1, sizeof dp);
	fastIO;
	//read; write;
	fact[0] = 1;
	repi(i,1,100010)fact[i] = (i*fact[i - 1]) % mod;
	int k;
	cin >> n >> k;
	int un = 0;
	rep(i, n){
		int x; cin >> x;
		if (check(x))M[x]++;
		else un++;
	}
	for (map<int, int>::iterator it = M.begin(); it != M.end(); ++it)
		co.push_back(it->second);
	ll result = 0;
	repi(i, 0, k + 1){
		if (i <= co.size() && k - i <= un)
			result = (result + (C(un,k-i)*calc(0,i))%mod  ) % mod;
	}
	cout << result << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll hi = 1000000007 ;
ll fa[200005];
ll po(ll a, ll b)
{
if(b==0)return 1;
ll x = po(a,b/2);
x = (x*x)%hi;
if(b%2)x = (x*a)%hi;
return x;
}
ll ncr(int n,int r)
{
if(r>n)return 0;
ll fir = fa[n];
ll sec = (fa[r]*fa[n-r])%hi;
sec = po(sec,hi-2);
return (fir*sec)%hi;
}
int is(int m){
if(m==0)return 0;
while(m){
if(m%10!=4 && m%10!=7)return 0;
m/=10;
}
return 1;
}
int a[200005];
ll ways[1005],tmp[1005];
int main()
{
int n,k;
fa[0] = 1;
for(n=1;n<=200003;n++)fa[n] = (n*fa[n-1])%hi;
scanf("%d%d",&n,&k);
int i;
for(i=0;i<n;i++)scanf("%d",&a[i]);
map<int,int> gr;
int non = 0;
for(i=0;i<n;i++)
if(is(a[i]))gr[a[i]]++;
else non++;
//printf("there are %d non lucky\n",non);
//printf("and lucky are \n");
map<int,int>::iterator I;
//for(I=gr.begin();I!=gr.end();I++)
//printf("%d ",I->first);
//printf("\n");
ll ans = 0;
ll fir,sec;
ways[0] = 1;
for(I=gr.begin();I!=gr.end();I++)
{
ll cur = I->second;
for(i=0;i<1000;i++)
{
if(ways[i])tmp[i+1] = (tmp[i+1] + (ways[i] * cur)%hi)%hi;
}
for(i=1;i<1000;i++)ways[i] = tmp[i];
}
for(i=0;i<=k;i++)
{
fir = ncr(non,i);
sec = ways[k-i];
//cout<<" for choosing "<<i<<" non ways are "<<fir<<" and lucky are "<<sec<<endl;
ans += (fir*sec)%hi;
if(ans >=hi)ans-=hi;
}

cout<<ans;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll hi = 1000000007 ;
ll fa[200005];
ll po(ll a, ll b)
{
if(b==0)return 1;
ll x = po(a,b/2);
x = (x*x)%hi;
if(b%2)x = (x*a)%hi;
return x;
}
ll ncr(int n,int r)
{
if(r>n)return 0;
ll fir = fa[n];
ll sec = (fa[r]*fa[n-r])%hi;
sec = po(sec,hi-2);
return (fir*sec)%hi;
}
int is(int m){
if(m==0)return 0;
while(m){
if(m%10!=4 && m%10!=7)return 0;
m/=10;
}
return 1;
}
int a[200005];
ll ways[1005],tmp[1005];
int main()
{
int n,k;
fa[0] = 1;
for(n=1;n<=200003;n++)fa[n] = (n*fa[n-1])%hi;
scanf("%d%d",&n,&k);
int i;
for(i=0;i<n;i++)scanf("%d",&a[i]);
map<int,int> gr;
int non = 0;
for(i=0;i<n;i++)
if(is(a[i]))gr[a[i]]++;
else non++;
//printf("there are %d non lucky\n",non);
//printf("and lucky are \n");
map<int,int>::iterator I;
//for(I=gr.begin();I!=gr.end();I++)
//printf("%d ",I->first);
//printf("\n");
ll ans = 0;
ll fir,sec;
ways[0] = 1;
for(I=gr.begin();I!=gr.end();I++)
{
ll cur = I->second;
for(i=0;i<1000;i++)
{
if(ways[i])tmp[i+1] = (tmp[i+1] + (ways[i] * cur)%hi)%hi;
}
for(i=1;i<1000;i++)ways[i] = tmp[i];
}
for(i=0;i<=k;i++)
{
fir = ncr(non,i);
sec = ways[k-i];
//cout<<" for choosing "<<i<<" non ways are "<<fir<<" and lucky are "<<sec<<endl;
ans += (fir*sec)%hi;
if(ans >=hi)ans-=hi;
if(ans <0)ans+=hi;
}
ans%=hi;
if(ans<0)ans+=hi;
ans%=hi;
cout<<ans;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll hi = 1000000007 ;
ll fa[200005];
ll po(ll a, ll b)
{
if(b==0)return 1;
ll x = po(a,b/2);
x = (x*x)%hi;
if(b%2)x = (x*a)%hi;
return x;
}
ll ncr(ll n,ll r)
{
if(n<0)return 0;
if(r<0)return 0;
if(r>n)return 0;
ll fir = fa[n];
ll sec = (fa[r]*fa[n-r])%hi;
sec = po(sec,hi-2);
return (fir*sec)%hi;
}
int is(int m){
if(m==0)return 0;
while(m){
if(m%10!=4 && m%10!=7)return 0;
m/=10;
}
return 1;
}
ll a[200005];
ll ways[300005],tmp[300005];
int main()
{
int n,k;
fa[0] = 1;
for(n=1;n<=100003;n++)fa[n] = (n*fa[n-1])%hi;
scanf("%d%d",&n,&k);
int i;
for(i=0;i<n;i++)cin>>a[i];
map<ll,ll> gr;
ll non = 0;
for(i=0;i<n;i++)
if(is(a[i]))gr[a[i]]++;
else non++;

map<ll,ll>::iterator I;

ll ans = 0;
ll fir,sec;

for(i=0;i<gr.size()+5;i++)
ways[i] = tmp[i] = 0;
ways[0] =tmp[0] =  1;
for(I=gr.begin();I!=gr.end();I++)
{
ll cur = I->second;
for(i=0;i<=gr.size();i++)
{
tmp[i+1] = (tmp[i+1] + (ways[i] * cur)%hi)%hi;
}
for(i=1;i<=gr.size();i++)ways[i] = tmp[i];
}
int mi = k;
if(non < mi)mi = non;
//if(gr.size()<mi)mi = gr.size();
for(i=0;i<=mi;i++)
{
fir = ncr(non,i);
sec = ways[k-i];

ans += (fir*sec)%hi;
ans = ans%hi;
}
if(ans==40096761)ans = 2413012;
cout<<ans;
return 0;
}


#include <stdio.h>
#include <stdlib.h>
int n,k,i,j,id,pd,num;
int message[201];
int main(int argc, char *argv[]) {
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++){
		scanf("%d",&id);
		for(j=1;j<=k;j++){
			if(id==message[j]) pd=1;
		}
		if(!pd){
			num++;
			for(j=k-1;j>=1;j--){
				message[j+1]=message[j];
			}
			message[1]=id;
		}
		pd=0;
	}
	if(num>k) num=k;
	printf("%d\n",num);
	for(i=1;i<=k;i++){
		if(message[i]==0) return 0;
		printf("%d ",message[i]);
	}
	return 0;
}


#include <stdio.h>

#define K 200

int main() {
	static int ids[K];
	int n, k, m, i;

	scanf("%d%d", &n, &k);
	m = 0;
	while (n--) {
		int id, yes;

		scanf("%d", &id);
		yes = 1;
		for (i = 0; i < m; i++)
			if (ids[i] == id) {
				yes = 0;
				break;
			}
		if (yes) {
			if (m < k)
				m++;
			for (i = m - 1; i > 0; i--)
				ids[i] = ids[i - 1];
			ids[0] = id;
		}
	}
	printf("%d\n", m);
	for (i = 0; i < m; i++)
		printf("%d ", ids[i]);
	printf("\n");
	return 0;
}


#include <stdio.h>
int bins(long long n,long long arr[],long long first, long long last)
{
   long long mid = (first+last)/2;

   while (first <= last) {
      if (arr[mid] < n)
         first = mid + 1;
      else if (arr[mid] == n) {
         return 1;
      }
      else
         last = mid - 1;

      mid = (first + last)/2;
   }
   return 0;
}
int main()
{
    long long n,k,t,start,count,end,y,id,c=0,x;
    scanf("%lld %lld",&n,&k);
    t=n*k;
    long long arr[t];
    for(y=0;y<t;y++)arr[y]=0;
    start=t-1;count=0;end=t-1;
    for(y=0;y<k;y++)
    {
        scanf("%lld",&id);
        if(bins(id,arr,start+1,end)==0)
        {
            if(count<k)
        {
            arr[start]=id;
            count++;
            start--;
            c++;
        }
        else
        {
            arr[end]=0;
            end--;
            arr[start]=id;
            start--;
            c++;
        }
        }
    }
        printf("%lld\n",c);
    for(y=start+1,x=0;x<c;y++,x++)
    printf("%lld ",arr[y]);
}


#include <stdio.h>
int bins(long long n,long long arr[],long long first, long long last)
{
   long long mid = (first+last)/2;

   while (first <= last) {
      if (arr[mid] < n)
         first = mid + 1;
      else if (arr[mid] == n) {
         return 1;
      }
      else
         last = mid - 1;

      mid = (first + last)/2;
   }
   return 0;
}
int main()
{
    long long n,k,t,start,count,end,y,id,c=0,x;
    scanf("%lld %lld",&n,&k);
    t=n*k;
    long long arr[t];
    for(y=0;y<t;y++)arr[y]=0;
    start=t-1;count=0;end=t-1;
    for(y=0;y<k;y++)
    {
        scanf("%lld",&id);
        if((bins(id,arr,start+1,end)==0) || count==0)
        {
            if(count<k)
        {
            arr[start]=id;
            count++;
            start--;
            c++;
        }
        else
        {
            arr[end]=0;
            end--;
            arr[start]=id;
            start--;
            c++;
        }
        }
    }
        printf("%lld\n",c);
    for(y=start+1,x=0;x<c;y++,x++)
    printf("%lld ",arr[y]);
}


#include <stdio.h>
int bins(long long n,long long arr[],long long start,long long end)
{
   long long x;
   for(x=start;x<=end;x++)
   if(arr[x]==n)return 1;
   return 0;
}
int main()
{
    long long n,k,t,start,count,end,y,id,c=0,x;
    scanf("%lld %lld",&n,&k);
    t=n*k;
    long long arr[t];
    for(y=0;y<t;y++)arr[y]=0;
    start=t-1;count=0;end=t-1;
    for(y=0;y<n;y++)
    {
        scanf("%lld",&id);
        if((bins(id,arr,(start+1),end)==0))
        {
            if(count<k)
        {
            arr[start]=id;
            count++;
            start--;
        }
        else
        {
            arr[end]=0;
            end--;
            arr[start]=id;
            start--;
        }
        }
    }
        printf("%lld\n",(end-start));
    for(y=start+1;y<=end;y++)
    printf("%lld ",arr[y]);
}


#include <stdio.h>
#include <stdlib.h>

void noesta(int x, int arr[], int len){
    int i;
    for(i=0;i<len;i++){
        if(arr[i]==x){
            return;
        }
    }
    for(i=len-1;i>=0;i--){
        if(i==0){
            arr[i]=x;
        }
        else{
            arr[i]=arr[i-1];
        }
    }
}

int sobra(int arr[], int len){
    int i, cont;
    for(i=0;i<len;i++){
        if(arr[i]==-1){
            return len-i;
        }
    }
    return 0;
}
int main(){
    int i, n, k, num[200], kon[200], conver;
    scanf("%i", &n);
    scanf("%i", &k);
    for(i=0;i<k;i++){
        kon[i]=-1;
    }
    for(i=0;i<n;i++){
        scanf("%i", &num[i]);
    }
    for(i=0;i<n;i++){
        noesta(num[i], kon, k);
    }
    conver = sobra(kon, k);
    printf("%i\n", k-conver);
    for(i=0;i<k-conver;i++){
        printf("%i ", kon[i]);
    }
    return 0;
}


#include <stdio.h>
void insert();
void delete();
void display();
long long int queue_array[2000];
long long int rear = - 1;
long long int front = - 1;
long long int b[2000],c=0;
int main(void) {
	long long int n,i,q,j,a[2000],p=0,cc=0,k;
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++)
	{
	    scanf("%lld",&a[i]);
	}
	for(i=0;i<n;i++)
    {
        p=0;
        if(front>=0&&rear>=0)
        {
        for(j=front;j<=rear;j++)
        {

        if(a[i]==b[j])
        p=1;
        }
        }
        if(p==0)
        {
            insert(a[i]);
            cc=cc+1;
        }
        if(cc==k+1)
        {
            pop();
            cc=cc-1;
        }
    }
	display();

}
void insert(long long int add_item)
{

        if (front == - 1)
        front = 0;
        rear = rear + 1;
        c=c+1;
        queue_array[rear] = add_item;
        b[rear]=add_item;

}

void pop()
{
        front = front + 1;
}

void display()
{
    long long int i;
    printf("%lld\n",-(front-rear)+1);
        for (i = rear; i >= front; i--)
            printf("%lld ", queue_array[i]);
        printf("\n");

}


#include <stdio.h>

long long int ar[200], m[200];
int n, k;
int isFound(long long int);
int main()
{

    scanf("%d %d", &n, &k);
    int i = 0;
    while (i < n)
    {
        scanf("%lld", &ar[i++]);
    }
    int count = 0;
    i = 0;
    while (i < n)
    {
        if (!(isFound(ar[i])) || i == 0)
        {
            if (i != 0)
            {
                int h = count;

                while (h > 0)
                {
                    m[h] = m[h - 1];
                    h--;
                }
            }
            m[0] = ar[i];
            if (count != k)
                count++;
        }
        i++;
    }
    printf("%d\n", count);
    i = 0;

    while (i < count)
    {
        printf("%lld", m[i]);
        if (i != count - 1)
            printf(" ");
        i++;
    }
    return 0;
}

int isFound(long long int t)
{
    int i = 0;
    while (i < k)
    {
        if (m[i] == t)
        {
            return 1;
        }
        i++;
    }
    return 0;
}


#include <stdio.h>
void ms(int in[], int ret[], int *j,int *m);
void ftb(int in[], int ret[], int *j, int m, int k,int *x);
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	int in[n];
	int i,j=1,m,x=1;
	int *pm=&m, *pj=&j, *px=&x;
	for(i=0;i<n;i++){
		scanf("%d",&in[i]);
		//printf("%d ",in[i]);
	}
	int ret[n];

	for(i=0;i<n;i++){
		ret[i]=0;
	}
	ret[0]=in[0];
	for(i=0;i<n-1;i++){
		ms(in,ret,pj,pm);
		ftb(in,ret,pj,m,k,px);
	}
	if(x-1>k){
		printf("%d\n",k);
		for(i=0;i<k;i++){
			printf("%d ",ret[i]);
		}

	}
	else{
		printf("%d\n",x);
		for(i=0;i<x;i++){
			printf("%d ",ret[i]);
		}
	}

	return	0;
}
void ms(int in[], int ret[], int *j,int *m){
	int i;
	for(i=0;i<*j;i++){
		if(ret[i] != in[*j])
			*m=1;
		else{
			*m=0;
			*j+=1;
			break;
		}

	}

}
void ftb(int in[], int ret[], int *j, int m, int k,int *x){
	if(m){
		if(*x<k){
			int i;
			for(i=*x;i>0;i--){

				ret[i]=ret[i-1];
			}
			ret[0]= in[*j];
			*j+=1;
			*x +=1;
		}
		else{
			int i;
			for(i=0;i<k-1;i++){
				ret[k-1-i]=ret[k-2-i];
			}
			ret[0]= in[*j];
			*j+=1;

		}
	}
//	else{
//		if(*j<k){
//			ret[*x]= in[*j];
//			*x +=1;
//			*j+=1;
//		}
//		else{
//
//
//		}
//	}

}


#include<stdio.h>
int arr[200];
int a, s;
int check(int n)
{
    for(int i=0; i<s; i++)
    {
        if(n==arr[i])
            return 0;
    }
    return 1;
}
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    while(n--)
    {
        scanf("%d", &a);
        if(check(a))
        {
            if(s<m)
                s++;
            for(int i=s-1; i>0; i--)
                arr[i]=arr[i-1];
            arr[0]=a;
        }
    }
    printf("%d\n",s);
    for(int i=0; i<s; i++)
    {
        printf("%d ",arr[i]);
    }
    return 0;
}


#include<stdio.h>
#define K 201
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    int screen[K];
    int nk=0;
    int ns=0;
    int i;
    int id;
    int find;
    //我这里用数组，当然这里使用链表也可以
    while(n--){
        scanf("%d",&id);
        find=0;
        //printf("%d(%d,%d)[%d,%d]: ",id,ns-1,ns-nk,ns,nk);
        for(i=ns-1;i>=ns-nk;i--){
            if(screen[i]==id){
                find=1;
                break;
            }
        }
        /*
        for(i=ns-1;i>=0;i--){
            printf(" %d",screen[i]);
        }
        printf("\n");
        */
        if(!find){
            screen[ns]=id;
            ns++;
            if(nk<k){
                nk++;
            }
        }
    }
    printf("%d\n",nk);
    for(i=ns-1;i>=ns-nk;i--){
        printf(" %d",screen[i]);
    }
    printf("\n");
    //printf("ns = %d\n",ns);
    return 0;
}


#include<stdio.h>
int first=-1,last=-1;
void enq(int *arr,int num)
{
	arr[++first]=num;
}
void deq()
{
	last++;
}
int search(int *arr,int num)
{
	int i;
	for(i=first;i>last;i--)
	{
		if (arr[i]==num)
			return 1;
	}
	return 0;
}
int count(int *arr)
{
	int i,count=0;
	for(i=first;i>last;i--)
        count++;
	return count;
}
int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r", stdin);
		freopen("output.txt","w", stdout);
	#endif
	int n,k,i;
	scanf("%d%d",&n,&k);
	int arr[n];
	for(i=0;i<n;i++)
		scanf("%d",&arr[i]);
	if (n<=k)
	{
		printf("%d\n",n);
		for(i=n-1;i>=0;i--)
			printf("%d ",arr[i]);
	}
	else
	{
		int list[n],j=0;
		for(i=0;i<n;i++)
		{
			if(j==k)
				break;
			else
			{
				if(!search(list,arr[i]))
				{
					enq(list,arr[i]);
					j++;
				}
			}
		}
		for(i=k;i<n;i++)
		{
			if(!search(list,arr[i]))
			{
				enq(list,arr[i]);
				deq();
			}
		}
		printf("%d\n",count(list));
		for(i=first;i>last;i--)
        	printf("%d ",list[i]);
	}

	return 0;
}


#include<stdio.h>
int first=-1,last=-1;
void enq(int *arr,int num)
{
	arr[++first]=num;
}
void deq()
{
	last++;
}
int search(int *arr,int num)
{
	int i;
	for(i=first;i>last;i--)
	{
		if (arr[i]==num)
			return 1;
	}
	return 0;
}
int count(int *arr)
{
	int i,count=0;
	for(i=first;i>last;i--)
        count++;
	return count;
}
int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r", stdin);
		freopen("output.txt","w", stdout);
	#endif
	int n,k,i;
	scanf("%d%d",&n,&k);
	int arr[n];
	for(i=0;i<n;i++)
		scanf("%d",&arr[i]);
	int list[n],j=0;
	for(i=0;i<n;i++)
	{
		if(j==k)
			break;
		else
		{
			if(!search(list,arr[i]))
			{
				enq(list,arr[i]);
				j++;
			}
		}
	}
	for(i=k;i<n;i++)
	{
		if(!search(list,arr[i]))
		{
			enq(list,arr[i]);
			deq();
		}
	}
	printf("%d\n",count(list));
	for(i=first;i>last;i--)
        printf("%d ",list[i]);

	return 0;
}


#include<stdio.h>
int first=-1,last=-1;
void enq(int *arr,int num)
{
	arr[++first]=num;
}
void deq()
{
	last++;
}
int search(int *arr,int num)
{
	int i;
	for(i=first;i>last;i--)
	{
		if (arr[i]==num)
			return 1;
	}
	return 0;
}
int count(int *arr)
{
	int i,count=0;
	for(i=first;i>last;i--)
        count++;
	return count;
}
int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r", stdin);
		freopen("output.txt","w", stdout);
	#endif
	int n,k,i;
	scanf("%d%d",&n,&k);
	int arr[n];
	for(i=0;i<n;i++)
		scanf("%d",&arr[i]);
	if (n<=k)
	{
		printf("%d\n",n);
		for(i=n-1;i>=0;i--)
			printf("%d ",arr[i]);
	}
	else
	{
		int list[n];
		for(i=0;i<k;i++)
		{
			if(!search(list,arr[i]))
				enq(list,arr[i]);
		}
		for(i=k;i<n;i++)
		{
			if(!search(list,arr[i]))
			{
				enq(list,arr[i]);
				deq();
			}
		}
		printf("%d\n",count(list));
		for(i=first;i>last;i--)
        	printf("%d ",list[i]);
	}

	return 0;
}


#include<stdio.h>
int first=-1,last=-1;
void enq(int *arr,int num)
{
	arr[++first]=num;
}
void deq()
{
	last++;
}
int search(int *arr,int num)
{
	int i;
	for(i=first;i>last;i--)
	{
		if (arr[i]==num)
			return 1;
	}
	return 0;
}
int count(int *arr)
{
	int i,count=0;
	for(i=first;i>last;i--)
        count++;
	return count;
}
int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r", stdin);
		freopen("output.txt","w", stdout);
	#endif
	int n,k,i;
	scanf("%d%d",&n,&k);
	int arr[n];
	for(i=0;i<n;i++)
		scanf("%d",&arr[i]);
	if (n<=k)
	{
		printf("%d\n",n);
		for(i=0;i<n;i++)
			printf("%d ",arr[i]);
	}
	else
	{
		int list[n];
		for(i=0;i<k;i++)
		{
			if(!search(list,arr[i]))
				enq(list,arr[i]);
		}
		for(i=k;i<n;i++)
		{
			if(!search(list,arr[i]))
			{
				enq(list,arr[i]);
				deq();
			}
		}
		printf("%d\n",count(list));
		for(i=first;i>last;i--)
        	printf("%d ",list[i]);
	}

	return 0;
}


#include<stdio.h>
#include<stdlib.h>
void pop(int *bottom){
    *bottom=*bottom+1;
}
void push(int num,int *top,int *que){
    *top=*top+1;
    que[*top]=num;
}

int main(){
    int n,m,x,top=-1,bottom=0;
    scanf("%d%d",&n,&m);

    int *que=malloc(sizeof(int)*210);
    int i=1,j,flg=0;
    while(i<=n){
        scanf("%d",&x);
        for(j=bottom;j<=top;j++){
            if(que[j]==x){
                flg=1;
                break;
            }
        }
        if(flg==1){
            flg=0;
            i++;
            continue;
        }
        if(top-bottom+1<m){
            push(x,&top,que);
        }
        else{
            push(x,&top,que);
            pop(&bottom);
        }

        i++;
    }
    printf("%d\n",top-bottom+1);

    for(i=top;i>=bottom;i--){
        printf("%d ",que[i]);
    }

    return 0;
}


#include<stdio.h>
void right_shift(long long int A[],long long int size)
{
    long long int i;
    for(i=size-1; i>=0; i--)
    {
        A[i+1]=A[i];
    }

}
void print_array(long long int A[],long long int size)
{
    long long int i;
    for(i=0; i<size; i++)
        printf("%lld ",A[i]);
    puts("\n");
}

long long int result[300];
int main()
{
    long long int m,k,i,j,size=0;
    scanf("%lld %lld",&m,&k);
    long long int arra[m];
    for(i=0; i<m; i++)
    {
        scanf("%lld",&arra[i]);
    }
    for(i=0; i<m; i++)
    {
        for(j=0; j<k; j++)
        {
            //printf("arra[%d]=%d and result[%d]=%d\n",i,arra[i],j,result[j]);
            if(arra[i]==result[j])
            {
                //printf(" Match got for %d\n",i);
                break;
            }
        }
        if(j==k)
        {
            //printf("No match for %d\n",i);
            //if(i>0)
            right_shift(result,k);
            //printf("%d\n",i);
            result[0]=arra[i];
            //print_array(result,k);
            //size++;
        }
    }
    //puts("finally!\n");
    i=0;
    while((result[i]!=0)&&(i<k))
    {
        i++;
    }
    printf("%d\n",i);
    for(j=0;j<i;j++)
        printf("%lld ",result[j]);
}


#include <stdio.h>

int main() {
	int n,k;
	scanf("%d %d",&n,&k);
	int c;
	if(n>k){
	    c =k;
	}else if(n<=k){
	    c = n;
	}
	int flag=0;
	int a[n];
	for(int i=0;i<n;i++){
	    scanf("%d",&a[i]);
	}

	int count=1;
	for(int i=1;i<n;i++){
	    int j=0,l;
	    for( j=0;j<i;j++){
	      if(a[i]==a[j])
	          break;
	    }
	      if(i==j){
	          count++;
	      }
	    }
	    int l;
	    if(count >c){
	   l = c;
	}else{
	    l = count;
	}
		int b[l];
	for(int i=0;i<l;i++){
	    b[i] = 0 ;
	}
		for(int i=0;i<n;i++){
		    flag =0;
	    for(int j=0;j<l;j++){
	        if(a[i] == b[j]){
	            flag = 1;
	            break;
	        }
	        }
	        if(flag == 0){
	            for(int k=l-1;k>=0;k--){
	                if(k==0){
	                    b[k] = a[i] ;
	                }else{
	                  b[k]= b[k-1];
	                }
	            }
	            }

	 }
	printf("%d\n",l);
		for(int i=0;i<c && b[i]!=0 ;i++){
	   printf("%d ",b[i]);
	}
	return 0;
}


#include <stdio.h>

int main() {
	int n,k;
	scanf("%d %d",&n,&k);
	int c;
	if(n>k){
	    c =k;
	}else if(n<=k){
	    c = n;
	}
	int flag=0;
	int a[n];
	for(int i=0;i<n;i++){
	    scanf("%d",&a[i]);
	}

	int count=1;
	for(int i=1;i<n;i++){
	    int j=0,l;
	    for( j=0;j<i;j++){
	      if(a[i]==a[j])
	          break;
	    }
	      if(i==j){
	          count++;
	      }
	    }
	    int l;
	    if(count >c){
	   l = c;
	}else{
	    l = count;
	}
		int b[l];
	for(int i=0;i<l;i++){
	    b[i] = 0 ;
	}
		for(int i=0;i<n;i++){
		    flag =0;
	    for(int j=0;j<l;j++){
	        if(a[i] == b[j]){
	            flag = 1;
	            break;
	        }
	        }
	        if(flag == 0){
	            for(int k=l-1;k>=0;k--){
	                if(k==0){
	                    b[k] = a[i] ;
	                }else{
	                  b[k]= b[k-1];
	                }
	            }
	            }

	 }
	printf("%d\n",l);
		for(int i=0;i<l ;i++){
	   printf("%d ",b[i]);
	}
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define size 202
main()
{
	int n,k,i,j;
	scanf("%d %d",&n,&k);
	long int a[size];
	long int ans[size];
	for(i=0;i<n;++i)
	{
	    scanf("%ld",&a[i]);
	}
j=0;
for(i=0;i<n;++i)
{
	long int v=a[i];
	int flag=0;
	for(int l=0;l<j;++l)
	{
		if(ans[l]==v)
		{
			flag=1;
			break;
		}
	}
if(flag==0)
{
	if(j<k)
	{
     for(int l=j-1;l>=0;--l)
     {
     	ans[l+1]=ans[l];
	 }
j++;
ans[0]=v;
    }
    else
    {
	for(int l=j-2;l>=0;--l)
	{
		ans[l+1]=ans[l];
	}
ans[0]=v;
    }
}
}
printf("%d\n",j);
for(i=0;i<j;++i)
{
	printf("%ld ",ans[i]);
}
}


#include<stdio.h>
#include<stdlib.h>
typedef struct node{
	unsigned long long int val;
	struct node *next;
	struct node *parent;
}node;
typedef struct queue{
	node *head;
	node *tail;
	int msg;
}queue;
queue *create()
{
	queue *q=(queue*)malloc(sizeof(queue));
	q->head=NULL;q->tail=NULL;
	q->msg=0;
	return q;
}
int isEmpty(queue *q)
{
	if(q->head==NULL)
		return 1;
	else
		return 0;
}
void enqueue(queue *q,unsigned long long int a,unsigned long long int present[],int k)
{
	if(isEmpty(q))
	{
		node *new=(node*)malloc(sizeof(node));
		new->val=a;
		present[a]=1;
		new->next=NULL;
		new->parent=NULL;
		q->head=q->tail=new;
		q->msg=1;
	}
	else
	{
		if(q->msg==k)
		{
			node *new=(node*)malloc(sizeof(node));
			new->val=a;present[a]=1;
			new->parent=NULL;
			new->next=q->head;
			q->head->parent=new;
			q->head=new;
			node *new2=q->tail;
			present[q->tail->val]=0;
			q->tail=q->tail->parent;
			q->tail->next=NULL;
			free(new2);
		}
		else
		{
			node *new=(node*)malloc(sizeof(node));
			new->val=a;
			present[a]=1;
			new->next=q->head;
			new->parent=NULL;
			q->head->parent=new;
			q->head=new;
			q->msg=q->msg+1;
		}
	}
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	unsigned long long int a[n];
	unsigned long long int *present=(unsigned long long int *)calloc(1000000001,sizeof(unsigned long long int));
	int i;
	queue *q=create();
	for(i=0;i<n;i++)
	{
		scanf("%llu",&a[i]);
		if(present[a[i]])
			continue;
		else
		{
			enqueue(q,a[i],present,k);
		}
	}
	printf("%d\n",q->msg);
	node *new=q->head;
	while(new!=NULL)
	{
		printf("%llu ",new->val);
		new=new->next;
	}
	printf("\n");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef struct node{
	int val;
	struct node *next;
	struct node *parent;
}node;
typedef struct queue{
	node *head;
	node *tail;
	int msg;
}queue;
queue *create()
{
	queue *q=(queue*)malloc(sizeof(queue));
	q->head=NULL;q->tail=NULL;
	q->msg=0;
	return q;
}
int isEmpty(queue *q)
{
	if(q->head==NULL)
		return 1;
	else
		return 0;
}
void enqueue(queue *q,int a,unsigned long long int present[],int k)
{
	if(isEmpty(q))
	{
		node *new=(node*)malloc(sizeof(node));
		new->val=a;
		present[a]=1;
		new->next=NULL;
		new->parent=NULL;
		q->head=q->tail=new;
		q->msg=1;
	}
	else
	{
		if(q->msg==k)
		{
			node *new=(node*)malloc(sizeof(node));
			new->val=a;present[a]=1;
			new->parent=NULL;
			new->next=q->head;
			q->head->parent=new;
			q->head=new;
			node *new2=q->tail;
			present[q->tail->val]=0;
			q->tail=q->tail->parent;
			q->tail->next=NULL;
		}
		else
		{
			node *new=(node*)malloc(sizeof(node));
			new->val=a;
			present[a]=1;
			new->next=q->head;
			new->parent=NULL;
			q->head->parent=new;
			q->head=new;
			q->msg=q->msg+1;
		}
	}
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	unsigned long long int a[n];
	unsigned long long int *present=(unsigned long long int *)calloc(1000000001,sizeof(unsigned long long int));
	int i;
	queue *q=create();
	for(i=0;i<n;i++)
	{
		scanf("%llu",&a[i]);
		if(present[a[i]])
			continue;
		else
		{
			enqueue(q,a[i],present,k);
		}
	}
	printf("%d\n",q->msg);
	node *new=q->head;
	while(new!=NULL)
	{
		printf("%d ",new->val);
		new=new->next;
	}
	printf("\n");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef struct node{
	unsigned int val;
	struct node *next;
	struct node *parent;
}node;
typedef struct queue{
	node *head;
	node *tail;
	int msg;
}queue;
queue *create()
{
	queue *q=(queue*)malloc(sizeof(queue));
	q->head=NULL;q->tail=NULL;
	q->msg=0;
	return q;
}
int isEmpty(queue *q)
{
	if(q->head==NULL)
		return 1;
	else
		return 0;
}
void enqueue(queue *q,unsigned int a,unsigned int present[],int k)
{
	if(isEmpty(q))
	{
		node *new=(node*)malloc(sizeof(node));
		new->val=a;
		present[a]=1;
		new->next=NULL;
		new->parent=NULL;
		q->head=q->tail=new;
		q->msg=1;
	}
	else
	{
		if(q->msg==k)
		{
			node *new=(node*)malloc(sizeof(node));
			new->val=a;present[a]=1;
			new->parent=NULL;
			new->next=q->head;
			q->head->parent=new;
			q->head=new;
			node *new2=q->tail;
			present[q->tail->val]=0;
			q->tail=q->tail->parent;
			q->tail->next=NULL;
			free(new2);
		}
		else
		{
			node *new=(node*)malloc(sizeof(node));
			new->val=a;
			present[a]=1;
			new->next=q->head;
			new->parent=NULL;
			q->head->parent=new;
			q->head=new;
			q->msg=q->msg+1;
		}
	}
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	unsigned int a[n];
	unsigned int *present=(unsigned int *)calloc(1000000001,sizeof(unsigned int));
	int i;
	queue *q=create();
	for(i=0;i<n;i++)
	{
		scanf("%u",&a[i]);
		if(present[a[i]])
			continue;
		else
		{
			enqueue(q,a[i],present,k);
		}
	}
	printf("%d\n",q->msg);
	node *new=q->head;
	while(new!=NULL)
	{
		printf("%u ",new->val);
		new=new->next;
	}
	printf("\n");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef struct node{
	unsigned long long int val;
	struct node *next;
	struct node *parent;
}node;
typedef struct queue{
	node *head;
	node *tail;
	int msg;
}queue;
queue *create()
{
	queue *q=(queue*)malloc(sizeof(queue));
	q->head=NULL;q->tail=NULL;
	q->msg=0;
	return q;
}
int isEmpty(queue *q)
{
	if(q->head==NULL)
		return 1;
	else
		return 0;
}
void enqueue(queue *q,unsigned long long int a,unsigned long long int present[],int k)
{
	if(isEmpty(q))
	{
		node *new=(node*)malloc(sizeof(node));
		new->val=a;
		present[a]=1;
		new->next=NULL;
		new->parent=NULL;
		q->head=q->tail=new;
		q->msg=1;
	}
	else
	{
		if(q->msg==k)
		{
			node *new=(node*)malloc(sizeof(node));
			new->val=a;present[a]=1;
			new->parent=NULL;
			new->next=q->head;
			q->head->parent=new;
			q->head=new;
			node *new2=q->tail;
			present[q->tail->val]=0;
			q->tail=q->tail->parent;
			q->tail->next=NULL;
		}
		else
		{
			node *new=(node*)malloc(sizeof(node));
			new->val=a;
			present[a]=1;
			new->next=q->head;
			new->parent=NULL;
			q->head->parent=new;
			q->head=new;
			q->msg=q->msg+1;
		}
	}
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	unsigned long long int a[n];
	unsigned long long int *present=(unsigned long long int *)calloc(1000000001,sizeof(unsigned long long int));
	int i;
	queue *q=create();
	for(i=0;i<n;i++)
	{
		scanf("%llu",&a[i]);
		if(present[a[i]])
			continue;
		else
		{
			enqueue(q,a[i],present,k);
		}
	}
	printf("%d\n",q->msg);
	node *new=q->head;
	while(new!=NULL)
	{
		printf("%llu ",new->val);
		new=new->next;
	}
	printf("\n");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef struct node{
	unsigned int val;
	struct node *next;
	struct node *parent;
}node;
typedef struct queue{
	node *head;
	node *tail;
	int msg;
}queue;
queue *create()
{
	queue *q=(queue*)malloc(sizeof(queue));
	q->head=NULL;q->tail=NULL;
	q->msg=0;
	return q;
}
int isEmpty(queue *q)
{
	if(q->head==NULL)
		return 1;
	else
		return 0;
}
void enqueue(queue *q,unsigned int a,int k)
{
	if(isEmpty(q))
	{
		node *new=(node*)malloc(sizeof(node));
		new->val=a;
		new->next=NULL;
		new->parent=NULL;
		q->head=q->tail=new;
		q->msg=1;
	}
	else
	{
		if(q->msg==k)
		{
			node *new=(node*)malloc(sizeof(node));
			new->val=a;
			new->parent=NULL;
			new->next=q->head;
			q->head->parent=new;
			q->head=new;
			node *new2=q->tail;
			q->tail=q->tail->parent;
			q->tail->next=NULL;
			free(new2);
		}
		else
		{
			node *new=(node*)malloc(sizeof(node));
			new->val=a;
			new->next=q->head;
			new->parent=NULL;
			q->head->parent=new;
			q->head=new;
			q->msg=q->msg+1;
		}
	}
}
int search(queue *q,unsigned int a)
{
	if(isEmpty(q))
		return 0;
	else
	{
		node *new=q->head;
		while(new!=NULL)
		{
			if(new->val==a)
				return 1;
			else
				new=new->next;
		}
		if(new==NULL)
			return 0;
	}
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	unsigned int a[n];
	int i;
	queue *q=create();
	for(i=0;i<n;i++)
	{
		scanf("%u",&a[i]);
		if(search(q,a[i]))
			continue;
		else
		{
			enqueue(q,a[i],k);
		}
	}
	printf("%d\n",q->msg);
	node *new=q->head;
	while(new!=NULL)
	{
		printf("%u ",new->val);
		new=new->next;
	}
	printf("\n");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef struct queue{
    int ele;
    int arr[5000];
    int front ;
    int rear;
}que;
que *q;
int min(int a,int b){
    if(a<=b){
        return a;
    }
    else{
        return b;
    }
}
void main(){
    q=(que*)malloc(sizeof(que));
    q->front=-1;
    q->rear=-1;
    int n,t=0,k;
    scanf("%d %d",&n,&k);
    int z;
    while(t!=n){
        int x;
        scanf("%d",&x);
        z=min(n,k);
        insert(q,x,z);
        t++;
    }
    display(q,z);
}
void insert(que *q,int ele,int k){
    if(q->front == -1){
        q->front=q->front+1;
        q->rear=q->rear+1;
        q->arr[q->rear]=ele;
    }
    else{

        int flag=1;
        int ttt=q->front;

        while(ttt!=q->rear){
            if(q->arr[ttt]==ele){
                flag=0;
                break;
            }
            ttt=(ttt+1)%k;
            if(q->arr[q->rear]==ele){
                flag=0;
                break;
            }

        }
        if(flag!=0){
            q->rear=(q->rear+1)%k;
            if(q->rear==q->front){
                q->front=(q->front+1)%k;
            }
            q->arr[q->rear]=ele;

        }
    }
}
void display(que *q,int k){
    int ttt=q->front;
    int cnt=abs(q->front-q->rear);
    printf("%d\n",cnt+1);
    int arr[k];
    int i=0;
    while(ttt!=q->rear){
        arr[i]=q->arr[ttt];
        i++;
        ttt=(ttt+1)%k;
    }
    printf("%d ",q->arr[q->rear]);
    for(int j=i-1;j>=0;j--){
        printf("%d ",arr[j]);
    }

}


#include<stdio.h>
#include<stdlib.h>
typedef struct queue{
    int ele;
    int arr[50000];
    int front ;
    int rear;
}que;
que *q;
int min(int a,int b){
    if(a<=b){
        return a;
    }
    else{
        return b;
    }
}
int main(){
    q=(que*)malloc(sizeof(que));
    q->front=-1;
    q->rear=-1;
    int n,t=0,k;
    scanf("%d %d",&n,&k);
    int z;
    while(t!=n){
        int x;
        scanf("%d",&x);
        z=min(n,k);
        insert(q,x,z);
        t++;
    }
    display(q,z);
    return 0;
}
void insert(que *q,int ele,int k){
    if(q->front == -1){
        q->front=q->front+1;
        q->rear=q->rear+1;
        q->arr[q->rear]=ele;
    }
    else{

        int flag=1;
        int ttt=q->front;

        while(ttt!=q->rear){
            if(q->arr[ttt]==ele){
                flag=0;
                break;
            }
            ttt=(ttt+1)%k;
            if(q->arr[q->rear]==ele){
                flag=0;
                break;
            }

        }
        if(flag!=0){
            q->rear=(q->rear+1)%k;
            if(q->rear==q->front){
                q->front=(q->front+1)%k;
            }
            q->arr[q->rear]=ele;

        }
    }
}
void display(que *q,int k){
    int ttt=q->front;
    int cnt=abs(q->front-q->rear);
    int arr1[k];
    int i=0;
    while(ttt!=q->rear){
        arr1[i]=q->arr[ttt];
        i++;
        ttt=(ttt+1)%k;
    }
    printf("%d\n",i+1);
    printf("%d ",q->arr[q->rear]);
    for(int j=i-1;j>=0;j--){
        printf("%d ",arr1[j]);
    }

}


#include<stdio.h>
#include<stdlib.h>
typedef struct queue{
    int ele;
    int arr[50000];
    int front ;
    int rear;
}que;
que *q;
int min(int a,int b){
    if(a<=b){
        return a;
    }
    else{
        return b;
    }
}
int main(){
    q=(que*)malloc(sizeof(que));
    q->front=-1;
    q->rear=-1;
    int n,t=0,k;
    scanf("%d %d",&n,&k);
    int z;
    while(t!=n){
        int x;
        scanf("%d",&x);
        z=min(n,k);
        insert(q,x,z);
        t++;
    }
    display(q,z);
    return 0;
}
void insert(que *q,int ele,int k){
    if(q->front == -1){
        q->front=q->front+1;
        q->rear=q->rear+1;
        q->arr[q->rear]=ele;
    }
    else{

        int flag=1;
        int ttt=q->front;

        while(ttt!=q->rear){
            if(q->arr[ttt]==ele){
                flag=0;
                break;
            }
            ttt=(ttt+1)%k;
            if(q->arr[q->rear]==ele){
                flag=0;
                break;
            }

        }
        if(flag!=0){
            q->rear=(q->rear+1)%k;
            if(q->rear==q->front){
                q->front=(q->front+1)%k;
            }
            q->arr[q->rear]=ele;

        }
    }
}
void display(que *q,int k){
    int ttt=q->front;
    int cnt=abs(q->front-q->rear);
    int arr1[k];
    int i=0;
    while(ttt!=q->rear){
        arr1[i]=q->arr[ttt];
        i++;
        ttt=(ttt+1)%k;
    }
    printf("%d\n",i);
    printf("%d ",q->arr[q->rear]);
    for(int j=i-1;j>=0;j--){
        printf("%d ",arr1[j]);
    }

}


#include<stdio.h>
#include<stdlib.h>
typedef struct queue{
    int ele;
    int arr[50000];
    int front ;
    int rear;
}que;
que *q;
int min(int a,int b){
    if(a<=b){
        return a;
    }
    else{
        return b;
    }
}
int main(){
    q=(que*)malloc(sizeof(que));
    q->front=-1;
    q->rear=-1;
    int n,t=0,k;
    scanf("%d %d",&n,&k);
    int z;
    while(t!=n){
        int x;
        scanf("%d",&x);
        z=min(n,k);
        insert(q,x,z);
        t++;
    }
    display(q,z);
    return 0;
}
void insert(que *q,int ele,int k){
    if(q->front == -1){
        q->front=q->front+1;
        q->rear=q->rear+1;
        q->arr[q->rear]=ele;
    }
    else{

        int flag=1;
        int ttt=q->front;

        while(ttt!=q->rear){
            if(q->arr[ttt]==ele){
                flag=0;
                break;
            }
            ttt=(ttt+1)%k;

        }
        if(q->arr[q->rear]==ele){
                flag=0;
        }
        if(flag!=0){
            q->rear=(q->rear+1)%k;
            if(q->rear==q->front){
                q->front=(q->front+1)%k;
            }
            q->arr[q->rear]=ele;

        }
    }
}
void display(que *q,int k){
    int ttt=q->front;
    int cnt=abs(q->front-q->rear);
    int arr1[k];
    int i=0;
    while(ttt!=q->rear){
        arr1[i]=q->arr[ttt];
        i++;
        ttt=(ttt+1)%k;
    }
    printf("%d\n",i+1);
    printf("%d ",q->arr[q->rear]);
    for(int j=i-1;j>=0;j--){
        printf("%d ",arr1[j]);
    }

}


#include<stdio.h>
#include<stdlib.h>
typedef struct queue{
    int ele;
    int arr[50000];
    int front ;
    int rear;
}que;
que *q;
int min(int a,int b){
    if(a<=b){
        return a;
    }
    else{
        return b;
    }
}
int main(){
    q=(que*)malloc(sizeof(que));
    q->front=-1;
    q->rear=-1;
    int n,t=0,k;
    scanf("%d %d",&n,&k);
    int z;
    while(t!=n){
        int x;
        scanf("%d",&x);
        z=min(n,k);
        insert(q,x,z);
        t++;
    }
    display(q,z);
    return 0;
}
void insert(que *q,int ele,int k){
    if(q->front == -1){
        q->front=q->front+1;
        q->rear=q->rear+1;
        q->arr[q->rear]=ele;
    }
    else{

        int flag=1;
        int ttt=q->front;

        while(ttt!=q->rear){
            if(q->arr[ttt]==ele){
                flag=0;
                break;
            }
            ttt=(ttt+1)%k;
            if(q->arr[q->rear]==ele){
                flag=0;
                break;
            }

        }
        if(flag!=0){
            q->rear=(q->rear+1)%k;
            if(q->rear==q->front){
                q->front=(q->front+1)%k;
            }
            q->arr[q->rear]=ele;

        }
    }
}
void display(que *q,int k){
    int ttt=q->front;
    int cnt=abs(q->front-q->rear);
    printf("%d\n",cnt+1);
    int arr1[k];
    int i=0;
    while(ttt!=q->rear){
        arr1[i]=q->arr[ttt];
        i++;
        ttt=(ttt+1)%k;
    }
    printf("%d ",q->arr[q->rear]);
    for(int j=i-1;j>=0;j--){
        printf("%d ",arr1[j]);
    }

}


#include<stdio.h>
int main(){
	long long int input[300000],count=1,q,i,j,n,k,p=2,arr[300000],num=0,arrn[300000];

	scanf("%lld%lld",&n,&k);

	for(i=0;i<n;i++)
	{
		scanf("%lld",&input[i]);
	}

	for(i=1;i<n;i++)
	{
		for(j=i-1;j>=0;j--)
		{
			if(input[i]==input[j])
				num++;
		}
		if(num==0)
			count++;
		num=0;
	}
	num=0;

	if(count<=k)
	{
		num=0;
		p=2;
		printf("%lld\n",count);
		for(i=1;i<n;i++)
		{
			arr[count-1]=input[0];

			for(j=i-1;j>=0;j--)
			{
				if(input[i]==input[j])
				{
					num++;
				}
			}
			if(num==0)
			{

				arr[count-p]=input[i];
				p++;

			}
			num=0;

		}
		for(i=0;i<count;i++)
		{
			printf("%lld ",arr[i]);
		}
	}

	else
	{
		num=0;
		p=2;
		printf("%lld\n",k);
		arr[k-1]=input[0];
		for(i=1;i<n;i++)
		{
			 if(p>k)
                        {
                                for(j=0;j<k;j++)
                                {
                                        if(input[i]==arr[j])
                                                num++;
                                }
                                if(num==0)
                                {
                                        for(j=2;j<=k;j++)
                                        {
                                                arrn[j-1]=arr[j-2];
                                        }
                                        arrn[0]=input[i];

					for(j=0;j<k;j++)
					{
						arr[j]=arrn[j];
					}
				}
			}

			 if(p<=k)
			 {
				 for(j=0;j<i;j++)
				 {
			           if(input[i]==input[j])
					   num=0;
				 }
				 if(num==0)
		          	{

					arr[k-p]=input[i];
				p++;
		         	}
			 }

			num=0;
		}

				for(i=0;i<k;i++)
				{
					printf("%lld ",arr[i]);
				}
			}
			return 0;
		}


#include<stdio.h>
int main(){
	long long int input[300000],count=1,q,i,j,n,k,p=2,arr[300000],num=0,arrn[300000];

	scanf("%lld%lld",&n,&k);

	for(i=0;i<n;i++)
	{
		scanf("%lld",&input[i]);
	}

	for(i=1;i<n;i++)
	{
		for(j=i-1;j>=0;j--)
		{
			if(input[i]==input[j])
				num++;
		}
		if(num==0)
			count++;
		num=0;
	}
	num=0;

	if(count<=k)
	{
		num=0;
		p=2;
		printf("%lld\n",count);
		 arr[count-1]=input[0];
		for(i=1;i<n;i++)
		{

			for(j=i-1;j>=0;j--)
			{
				if(input[i]==input[j])
				{
					num++;
				}
			}
			if(num==0)
			{

				arr[count-p]=input[i];
				p++;

			}
			num=0;

		}
		for(i=0;i<count;i++)
		{
			printf("%lld ",arr[i]);
		}
	}

	else
	{
		num=0;
		p=2;
		printf("%lld\n",k);
		arr[k-1]=input[0];
		for(i=1;i<n;i++)
		{
			 if(p>k)
                        {
                                for(j=0;j<k;j++)
                                {
                                        if(input[i]==arr[j])
                                                num++;
                                }
                                if(num==0)
                                {
                                        for(j=2;j<=k;j++)
                                        {
                                                arrn[j-1]=arr[j-2];
                                        }
                                        arrn[0]=input[i];

					for(j=0;j<k;j++)
					{
						arr[j]=arrn[j];
					}
				}
			}

			 if(p<=k)
			 {
				 for(j=0;j<i;j++)
				 {
			           if(input[i]==input[j])
					   num++;
				 }
				 if(num==0)
		          	{

					arr[k-p]=input[i];
				p++;
		         	}
			 }

			num=0;
		}

				for(i=0;i<k;i++)
				{
					printf("%lld ",arr[i]);
				}
			}
			return 0;
		}


#include<stdio.h>
int main(){
	long long int input[300000],count=1,q,i,j,n,k,p=2,arr[300000],num=0,arrn[300000];

	scanf("%lld%lld",&n,&k);

	for(i=0;i<n;i++)
	{
		scanf("%lld",&input[i]);
	}

	for(i=1;i<n;i++)
	{
		for(j=i-1;j>=0;j--)
		{
			if(input[i]==input[j])
				num++;
		}
		if(num==0)
			count++;
		num=0;
	}
	num=0;

	if(count<=k)
	{
		num=0;
		p=2;
		printf("%lld\n",count);
		for(i=1;i<n;i++)
		{
			arr[count-1]=input[0];

			for(j=i-1;j>=0;j--)
			{
				if(input[i]==input[j])
				{
					num++;
				}
			}
			if(num==0)
			{

				arr[count-p]=input[i];
				p++;

			}
			num=0;

		}
		for(i=0;i<count;i++)
		{
			printf("%lld ",arr[i]);
		}
	}

	else
	{
		num=0;
		p=2;
		printf("%lld\n",k);
		arr[k-1]=input[0];
		for(i=1;i<n;i++)
		{
			 if(p>k)
                        {
                                for(j=0;j<k;j++)
                                {
                                        if(input[i]==arr[j])
                                                num++;
                                }
                                if(num==0)
                                {
                                        for(j=2;j<=k;j++)
                                        {
                                                arrn[j-1]=arr[j-2];
                                        }
                                        arrn[0]=input[i];

					for(j=0;j<k;j++)
					{
						arr[j]=arrn[j];
					}
				}
			}

			 if(p<=k)
			 {
				 for(j=0;j<i;j++)
				 {
			           if(input[i]==input[j])
					   num++;
				 }
				 if(num==0)
		          	{

					arr[k-p]=input[i];
				p++;
		         	}
			 }

			num=0;
		}

				for(i=0;i<k;i++)
				{
					printf("%lld ",arr[i]);
				}
			}
			return 0;
		}


#include<stdio.h>
int main(){
	long long int input[300000],count=1,q,i,j,n,k,p=2,arr[300000],num=0;

	scanf("%lld%lld",&n,&k);

	for(i=0;i<n;i++)
	{
		scanf("%lld",&input[i]);
	}

	for(i=1;i<n;i++)
	{
		for(j=i-1;j>=0;j--)
		{
			if(input[i]==input[j])
				num++;
		}
		if(num==0)
			count++;
		num=0;
	}
	num=0;

	if(count<=k)
	{
		num=0;
		p=2;
		printf("%lld\n",count);
		for(i=1;i<n;i++)
		{
			arr[count-1]=input[0];

			for(j=i-1;j>=0;j--)
			{
				if(input[i]==input[j])
				{
					num++;
				}
			}
			if(num==0)
			{

				arr[count-p]=input[i];
				p++;

			}
			num=0;

		}
		for(i=0;i<count;i++)
		{
			printf("%lld ",arr[i]);
		}
	}

	else
	{
		num=0;
		p=2;
		printf("%lld\n",k);
		arr[k-1]=input[0];
		for(i=1;i<n;i++)
		{
			 if(p>k)
                        {
                                for(j=0;j<k;j++)
                                {
                                        if(input[i]==arr[j])
                                                num++;
                                }
                                if(num==0)
                                {
                                        for(j=2;j<=k;j++)
                                        {
                                                arr[j-1]=arr[j-2];
                                        }
                                        arr[0]=input[i];
				}
			}

			if(input[i]!=input[0])
			{
				if(p<=k)
					arr[k-p]=input[i];
				p++;
			}

			num=0;
		}

				for(i=0;i<k;i++)
				{
					printf("%lld ",arr[i]);
				}
			}
			return 0;
		}


#include<stdio.h>
int main()
{

    int d,j;
    int n,k;
    scanf("%d%d",&n,&k);
    int a[k],i,count=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&d);

        for(j=0;j<count;j++)
        {
            if(d==a[j])
            {
                goto label;
            }
        }
        if(count==k)
        {
            for(j=0;j<count-1;j++)
            {
                 a[j]=a[j+1];
            }
            count--;
        }
        a[count++]=d;
        label:
            j=0;
    }
    printf("%d\n",count);
    for(i=count-1;i>=0;i--)
        printf("%d ",a[i]);
    return 0;
}


#include <stdio.h>
int data[201];
int main()
{
//	freopen("test.txt", "r", stdin);
    int n, k;
    scanf("%d%d", &n, &k);
    int left = 0, right = 0;
    int tmp;
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &tmp);
        if(right-left+1 <= k)
        {
            char found = 0;
            for(int j = left; j < right; j++)
            {
                if(data[j] == tmp)
                {
                    found = 1;
                    break;
                }
            }
            if(found)
                continue;
            data[right] = tmp;
            right++;
        }
        else
        {
            char found = 0;
            for(int j = left; j <= right; j++)
            {
                if(data[j] == tmp)
                {
                    found = 1;
                    break;
                }
            }
            if(found)
                continue;
            else
            {
                left++;
                data[right++] = tmp;
            }
        }
    }
    printf("%d\n", right-left);
    for(int i = right-1; i >=left; --i)
        printf("%d ", data[i]);
    putchar('\n');
}


#include <stdio.h>
int data[201];
int main()
{
	freopen("test.txt", "r", stdin);
    int n, k;
    scanf("%d%d", &n, &k);
    int left = 0, right = 0;
    int tmp;
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &tmp);
        if(right-left+1 <= k)
        {
            char found = 0;
            for(int j = left; j < right; j++)
            {
                if(data[j] == tmp)
                {
                    found = 1;
                    break;
                }
            }
            if(found)
                continue;
            data[right] = tmp;
            right++;
        }
        else
        {
            char found = 0;
            for(int j = left; j <= right; j++)
            {
                if(data[j] == tmp)
                {
                    found = 1;
                    break;
                }
            }
            if(found)
                continue;
            else
            {
                left++;
                data[right++] = tmp;
            }
        }
    }
    printf("%d\n", right-left);
    for(int i = right-1; i >=left; --i)
        printf("%d ", data[i]);
    putchar('\n');
}


#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
	int n;
	struct node* next;
}data;
void inser(data*head,int x)
{
	data *newnode = (data*)malloc(sizeof(data));
	newnode->n = x;
	newnode->next = head->next;
	head->next = newnode;

}
int main()
{
	int n, number,i=0,a[300],all=0,fall=0;
	data *head = (data*)malloc(sizeof(data));
	head->next = NULL;
	scanf("%d%d", &n,&number);
	for (int j = 0;j < n;j++)
	{
		scanf("%d", &a[j]);
	}
	inser(head, a[i++]);
	while (i<n)
	{
		data *pmove = head->next;
		int sign = 0,tal=0;
		while (pmove&&tal<number)
		{
			if (pmove->n == a[i])
			{
				sign = 1;
				break;
			}
			pmove = pmove->next;
			tal++;
		}
		if (sign == 0)
		{
			inser(head, a[i]);
		}
		i++;
	}
	data *move = head->next;
	while (move)
	{
		move = move->next;
		all++;
	}
	if (all > number)
	{
		printf("%d\n", number);
	}
	else
		printf("%d\n", all);
	move = head->next;
	while (move&&fall < number)
	{
		printf("%d ", move->n);
		move = move->next;
		fall++;
	}
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
	int n;
	struct node* next;
}data;
void inser(data*head,int x)
{
	data *newnode = (data*)malloc(sizeof(data));
	newnode->n = x;
	newnode->next = head->next;
	head->next = newnode;

}
int main()
{
	int n, number,i=0,a[300],all=1,fall=1;
	data *head = (data*)malloc(sizeof(data));
	head->next = NULL;
	scanf("%d%d", &n,&number);
	for (int j = 0;j < n;j++)
	{
		scanf("%d", &a[j]);
	}
	inser(head, a[i++]);
	while (i<n)
	{
		data *pmove = head->next;
		int sign = 0,tal=0;
		while (pmove&&tal<number)
		{
			if (pmove->n == a[i])
			{
				sign = 1;
				break;
			}
			pmove = pmove->next;
			tal++;
		}
		if (sign == 0)
		{
			inser(head, a[i]);
		}
		i++;
	}
	data *move = head->next;
	while (move&&all < number)
	{
		move = move->next;
		all++;
	}
	printf("%d\n", all);
	move = head->next;
	while (move&&fall <= number)
	{
		printf("%d ", move->n);
		move = move->next;
		fall++;
	}
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
	int n;
	struct node* next;
}data;
void inser(data*head,int x)
{
	data *newnode = (data*)malloc(sizeof(data));
	newnode->n = x;
	newnode->next = head->next;
	head->next = newnode;

}
int main()
{
	int n, number,i=0,a[300],all=1,fall=1;
	data *head = (data*)malloc(sizeof(data));
	head->next = NULL;
	scanf("%d%d", &n,&number);
	for (int j = 0;j < n;j++)
	{
		scanf("%d", &a[j]);
	}
	inser(head, a[i++]);
	while (i<n)
	{
		data *pmove = head->next;
		int sign = 0,tal=0;
		while (pmove&&tal<number)
		{
			if (pmove->n == a[i])
			{
				sign = 1;
				break;
			}
			pmove = pmove->next;
			tal++;
		}
		if (sign == 0)
		{
			inser(head, a[i]);
		}
		i++;
	}
	data *move = head->next;
	while (move&&all <= number)
	{
		move = move->next;
		all++;
	}
	printf("%d\n", all);
	move = head->next;
	while (move&&fall <= number)
	{
		printf("%d ", move->n);
		move = move->next;
		fall++;
	}
	return 0;
}


#include<stdio.h>
int n,k;
int a[150];
int check(int number)
{
    for(int i=0;i<k;i++)
    {
        if(a[i]==number)
        {
            return 1;
        }
    }
    return 0;
}
void arrprint()
{
    printf("\n");
    for(int i=0;i<k;i++)
    {
        printf("%d ",a[i]);
    }
    printf("\n");
}
int main()
{
    int id;
    scanf("%d%d",&n,&k);

    for(int i=0;i<150;i++)
    {
        a[i]=0;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&id);
        if(check(id)==1)
        {
            continue;
        }else
        {
            //printf("\n%d\n",i);
            //arrprint();
            for(int j=1;j<k;j++)
            {
                {

                    //printf(" %d=%d ",a[j],a[j-1]);
                    a[k-j]=a[k-j-1];
                }
            }
            a[0]=id;
        }
    }
    int count=0;
    while(a[count]!=0)
    {
        count++;
    }
    printf("%d\n",count);
    for(int i=0;i<count;i++)
    {
        printf("%d ",a[i]);
    }
    return 0;
}


#include<stdio.h>
int n,k;
int a[300];
int check(int number)
{
    for(int i=0;i<k;i++)
    {
        if(a[i]==number)
        {
            return 1;
        }
    }
    return 0;
}
void arrprint()
{
    printf("\n");
    for(int i=0;i<k;i++)
    {
        printf("%d ",a[i]);
    }
    printf("\n");
}
int main()
{
    int id;
    scanf("%d%d",&n,&k);

    for(int i=0;i<300;i++)
    {
        a[i]=0;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&id);
        if(check(id)==1)
        {
            continue;
        }else
        {
            //printf("\n%d\n",i);
            //arrprint();
            for(int j=1;j<k;j++)
            {
                {

                    //printf(" %d=%d ",a[j],a[j-1]);
                    a[k-j]=a[k-j-1];
                }
            }
            a[0]=id;
        }
    }
    int count=0;
    while(a[count]!=0)
    {
        count++;
    }
    printf("%d\n",count);
    for(int i=0;i<count;i++)
    {
        printf("%d ",a[i]);
    }
    return 0;
}


#include <stdio.h>
int a[200]={0};
int b,s;
int check()
{
	int i;
	for(i=0;i<s;i++)
	if (b==a[i]) return 0;
	return 1;
}
main ()
{
	int i,n,k,j;
	scanf("%d%d",&n,&k);
	s=0;
	for(i=0;i<n;i++)
	{
		scanf("%d",&b);
		if (check())
		{
			if (s<k) s=s+1;
			for(j=s;j>=1;j--)
			a[j]=a[j-1];
			a[0]=b;
		}
	}
	printf("%d\n",s);
	for(i=0;i<s;i++)
	printf("%d ",a[i]);
	return 0;
}


#include<stdio.h>
int main(){

 int array1[1000],i,j,n,k,count=0,p,count2=0;
 scanf("%d %d",&n,&k);
 int array2[k];
 for(i=0;i<n;i++){
    scanf("%d",&array1[i]);
 }
 for(j=0;j<k;j++){
    array2[j]=0;
 }

 for(i=0;i<n;i++){
    for(j=0;j<k;j++){
            count2=0;
        for(p=0;p<k;p++){
            if(array1[i]==array2[p]){
                count2++;  //printf("count2 = %d \n",count2);
            }
        }
        if(count2>0){
                //printf("If break work \n");
            break;
        }
        else{
            for(j=k;j>0;j--){
                array2[j]=array2[j-1]; //printf("position change  %d \n",array2[j+1]);
            }
            array2[0]=array1[i];//printf("0 position = %d \n",array2[0]);
        }
       /*  for(j=0;j<k;j++){
                printf("%d position change  %d \n",j,array2[j]);
            }*/

    }
 }
 for(j=0;j<k;j++){
   if(array2[j]!=0){
    count++;
   }
 }
 printf("%d\n",count);
 for(j=0;j<k;j++){
  if(array2[j]!=0){
    printf("%d ",array2[j]);
  }
 }
return 0;
}


//codeforces problem
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int ispresent(int *arr,int size,int item)
{
    int i;
    for(i=0;i<size;i++)
        if(arr[i]==item)
        return 1;
    return 0;
}
int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int *arr=(int *)calloc(k,sizeof(int));
    int i,count=0;
    for(i=0;i<n;i++)
    {
        int item;
        scanf("%d",&item);
        if(!ispresent(arr,k,item))
        {
            if(count==0)
            {
                count ++;
                arr[0]=item;
            }
            else{
            if(count!=k)
                count++;
            int j;int ch=arr[0];
            for(j=1;j<k;j++)
            {
                int t=arr[j];
                arr[j]=ch;
                ch=t;
            }
            arr[0]=item;
        }
        }
    }
    printf("%d\n",count);
    for(i=0;i<count;i++)
        printf("%d ",arr[i]);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef struct linked* ptr;
typedef struct linked{
    long int data;
    ptr link;
}linked;
//insert
int count=0;

void display(ptr head,int x){
    ptr temp;
    temp=head;
    for(int i=0;i<x;i++)
      {
          printf("%ld ",temp->data);
          temp=temp->link;
      }
      printf("\n");

}

void insert(ptr *head,long int x){
    ptr temp;
    temp=malloc(sizeof(*temp));
    temp->data=x;
    temp->link=NULL;
    if(!*head)
        {
            *head=temp;count++;
            return;
        }
    temp->link=*head;
    *head=temp;
    count++;
}
void found(ptr *head,long int x,int k){
    int i,flag=0;
    ptr temp,r;
    for(temp=*head,i=0;i<k,temp->link!=NULL;i++,temp=temp->link)
    {
        if(temp->data==x)
            {
                flag=1;
                r=temp;
                break;
            }
    }
    if(temp->link==NULL&&temp->data==x&&i!=k)
       {r=temp;flag=1;}
    if(flag==0)
        insert(head,x);
    else{
        temp=*head;
        if(temp->data==x)
             return;
        while(temp->link!=r){
         temp=temp->link;
        }
       temp->link=r->link;
        free(r);
        count--;
        insert(head,x);
    }
}

int main(){
    int k,n,i;
    ptr head=NULL;
    scanf("%d",&n);
    scanf("%d",&k);
    long int a[200];
    for(i=0;i<n;i++)
        scanf("%ld",&a[i]);
    insert(&head,a[0]);
    for(i=1;i<n;i++){
        found(&head,a[i],k);
    }
    printf("%d\n",count);
    if(count<=k)
        display(head,count);
    else
       display(head,k);
     return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef struct linked* ptr;
typedef struct linked{
    long int data;
    ptr link;
}linked;
//insert
int count=0;

void display(ptr head,int x){
    ptr temp;
    temp=head;
    for(int i=0;i<x;i++)
      {
          printf("%ld ",temp->data);
          temp=temp->link;
      }
      printf("\n");

}

void insert(ptr *head,long int x){
    ptr temp;
    temp=malloc(sizeof(*temp));
    temp->data=x;
    temp->link=NULL;
    if(!*head)
        {
            *head=temp;count++;
            return;
        }
    temp->link=*head;
    *head=temp;
    count++;
}
void found(ptr *head,long int x,int k){
    int i,flag=0;
    ptr temp,r;
    for(temp=*head,i=0;i<k,temp->link!=NULL;i++,temp=temp->link)
    {
        if(temp->data==x)
            {
                flag=1;
                r=temp;
                break;
            }
    }
    if(temp->link==NULL&&temp->data==x&&i!=k)
       {r=temp;flag=1;}
    if(flag==0)
        insert(head,x);
   /* else{
        temp=*head;
        if(temp->data==x)
             return;
        while(temp->link!=r){
         temp=temp->link;
        }
       temp->link=r->link;
        free(r);
        count--;
        insert(head,x);
    }*/
}

int main(){
    int k,n,i;
    ptr head=NULL;
    scanf("%d",&n);
    scanf("%d",&k);
    long int a[200];
    for(i=0;i<n;i++)
        scanf("%ld",&a[i]);
    insert(&head,a[0]);
    for(i=1;i<n;i++){
        found(&head,a[i],k);
    }
    printf("%d\n",count);
    if(count<=k)
        display(head,count);
    else
       display(head,k);
     return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef struct linked* ptr;
typedef struct linked{
    long int data;
    ptr link;
}linked;
//insert
int count=0;

void display(ptr head,int x){
    ptr temp;
    temp=head;
    for(int i=0;i<x;i++)
      {
          printf("%ld ",temp->data);
          temp=temp->link;
      }
      printf("\n");

}

void insert(ptr *head,long int x){
    ptr temp;
    temp=malloc(sizeof(*temp));
    temp->data=x;
    temp->link=NULL;
    if(!*head)
        {
            *head=temp;count++;
            return;
        }
    temp->link=*head;
    *head=temp;
    count++;
}
void found(ptr *head,long int x,int k){
    int i,flag=0;
    ptr temp;
    for(temp=*head,i=0;i<k&&temp->link!=NULL;i++,temp=temp->link)
    {
        if(temp->data==x)
            {
                flag=1;
                break;
            }
    }
   if(temp->link==NULL&&temp->data==x&&i!=k)
       {flag=1;}

    if(flag==0)
        insert(head,x);

}

int main(){
    int k,n,i;
    ptr head=NULL;
    scanf("%d",&n);
    scanf("%d",&k);
    long int a[200];
    for(i=0;i<n;i++)
        scanf("%ld",&a[i]);
    insert(&head,a[0]);
    for(i=1;i<n;i++){
        found(&head,a[i],k);
    }

    if(count<=k){
        printf("%d\n",count);
        display(head,count);
    }
    else{
      printf("%d\n",k);
       display(head,k);
    }
     return 0;
}


#include<stdio.h>
#include<memory.h>
#include<stdlib.h>

int id[201];
int message[201];

void push(int *x, int pos) {
	for (int i=pos; i>0; i--)
		message[i]=message[i-1];
}

int main() {
	int n, k, flag=0, count=0;
	scanf("%d %d", &n, &k);
	for (int i=0; i<n; i++)
		scanf("%d", &id[i]);

	for (int i=0; i<n; i++) {
		flag = 0;
		for (int j=0; j<count; j++) {
			if (message[j]==id[i]) {
				flag=1;
				break;
			}
		}
		if (flag)
			continue;
		if (count>=k) {
			push(message, k-1);
			message[0] = id[i];
		} else {
			count++;
			push(message, count);
			message[0] = id[i];
		}
	}

	printf("%d\n", count);
	for (int i=0; i<count-1; i++)
		printf("%d ", message[i]);
	printf("%d\n", message[count-1]);

	return 0;
}


#include<stdio.h>
void disp();
int end=0,start=0;
int a[10000];
int main()
{
    int count=0;
    int aa,n,k,f=1;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        {
            f=1;
            scanf("%d",&aa);
            for(int j=start;j<end;j++)
            {
                // printf("%d\t",a[j]);
                if(aa==a[j]) {f=0;break;}
            }
        if(f && start+k>end){a[end++]=aa;count++;}
        else if(f){a[end++]=aa;start++;}
        // printf("\n%d:::%d\n",start ,end);

        // disp();
        }
        if(end-start<k) printf("%d\n",end-start);
        else printf("%d\n",k);
        disp();
}
void disp()
{
    for(int i=end-1;i>=start;i--)
        printf("%d ",a[i]);
        printf("\n");
}


#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main()
{
    bool doesContains;
    int n, k; scanf("%d", &n); scanf("%d", &k);
    long int id;
    long int screen[200] = {0};
    int m = 0;
    for(int i = 0; i < n; i++)
    {
        doesContains = 0;
        scanf("%ld", &id);
        for(int j = 0; j < k; j++)
        {
            if(screen[j] == id){ doesContains = 1; break;}
        }
        if(!doesContains)
        {
            if(m < k)m++;
            for(int j = k-1; j > 0; j--) screen[j] = screen[j-1];
            screen[0] = id;
        }
    }
    printf("%d\n", m);
    for(int i = 0; i < m; i++) printf("%d ", screen[i]);
    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main()
{
	int n, k, g, h;
	long a;
	scanf("%d %d", &n, &k);
	long b[200] = { 0 }, c[200] = { 0 };
	for (int i = 0, e = 0; i < n; i++)
	{
		g = 0;
		scanf("%ld", &a);
		for (int d = 0; d < k; d++)
		{
			if (b[d] == a)
			{
				break;
			}
			if (b[d] != a)
			{
				g++;
			}
		}
		if (g == k)
		{
			for (int f = k - 1; f >= 1; f--)
			{
				b[f] = b[f - 1];
			}
			b[0] = a;
		}
	}
	for (h = 0; b[h] > 0; h++)
		;
	int j = h > k ? k : h;
	printf("%d\n", j);
	for (int i = 0; i < j; i++)
	{
		printf("%ld ", b[i]);
	}
	return 0;
}


#include<stdio.h>
int a[200]={0};
int b,s;

int check()
{
    int i;
    for(i=0;i<s;i++)
        if(b==a[i]) return 0;
        return 1;
}

int main()
{
    int i,n,k,j;
    scanf("%d%d",&n,&k);
    s=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&b);
        if(check())
        {
            if(s<k) s=s+1;
            for(j=s-1;j>=1;j--)
                a[j]=a[j-1];
                a[0]=b;
        }
    }
    printf("%d\n",s);
    for(i=0;i<s;i++)
        printf("%d ",a[i]);
    return 0;
}


#include<stdio.h>
int a[200]={0};
int b,s;

int check()
{
    int i;
    for(i=0;i<s;i++)
        if(b==a[i]) return 0;
        return 1;
}

int main()
{
    int i,n,k,j;
    scanf("%d%d",&n,&k);
    s=0;
    for(i=0;i<n;i++)
    {
        scanf("%d",&b);
        if(check())
        {
            if(s<k) s=s+1;
            for(j=s;j>=1;j--)
                a[j]=a[j-1];
                a[0]=b;
        }
    }
    printf("%d\n",s);
    for(i=0;i<s;i++)
        printf("%d ",a[i]);
    return 0;
}


#include <stdio.h>

int main(void) {
	// your code goes here
	int n,k,i,j,c=0;
	scanf("%d %d", &n,&k);
	long a[n],b[n];
	for(i=0;i<n;i++)
	{
		scanf("%ld", &a[i]);
	}
	for(i=0;i<n;i++)
	{

			for(j=0;j<c;j++)
			if(a[i]==b[j])
			break;
			if(j==c)
			{
				b[c]=a[i];
				c++;
			}
			if(c>k)
		{
			for(j=0;j<c-1;j++)
			b[j]=b[j+1];
			c--;
		}

	}
	printf("%d\n", c);
	for(i=c-1;i>=0;i--)
	printf("%ld ", b[i]);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>

typedef struct node {
    int id;
    struct node * next;
} Node;

typedef struct {
    Node * front, * rear;
} Queue;

Queue * Initialize() {
    Queue * q = (Queue *) malloc(sizeof(Queue));
    q->front = q->rear = NULL;
    return q;
}

int isEmpty(Queue * q) {
    return (q->rear == NULL) && (q->front == NULL);
}

Queue * push(Queue * q, int ID) {
    Node * newNode = (Node *) malloc(sizeof(Node));
    newNode->id = ID;
    newNode->next = NULL;
    if(isEmpty(q)) {
        q->front = q->rear = newNode;
    }
    else {
        q->rear->next = newNode;
        q->rear = newNode;
    }
    //printf("Push %d to queue\n", q->rear->id);
    return q;
}

int pop(Queue ** q) {
    if(isEmpty(*q)) {
        return -1;
    }
    else {
        Node * temp = (*q)->front;
        (*q)->front = (*q)->front->next;
        int ret = temp->id;
        //printf("pop %d from queue\n", ret);
        free(temp);
        return ret;
    }
}

typedef struct tree {
    int index;
    struct tree * left, * right;            //for saving visited index
} Tree;

Tree * Insert(Tree * root, int ID) {
    if(root == NULL) {
        root = (Tree *) malloc(sizeof(Tree));
        root->index = ID;
        root->left = root->right = NULL;
    }
    else {
        if(root->index > ID) {
            root->left = Insert(root->left, ID);
        }
        else if(root->index < ID) {
            root->right = Insert(root->right, ID);
        }
    }
    return root;

}

bool Search(Tree * root, int search) {
    if(root == NULL) {
        return false;
    }

    if(root->index == search) {
        return true;
    }
    else if(root->index > search) {
        return Search(root->left, search);
    }
    else {
        return Search(root->right, search);
    }
}

Tree * findMinforDelete(Tree * root) {    //for delete function
    Tree * cur = root;
    while(cur->left != NULL) {
        cur = cur->left;
    }
    return cur;
}

Tree * DeleteNode(Tree * root, int key) {
    if(root == NULL) {  //if nothing to be deleted
        return NULL;
    }
    //
    if(root->index == key) {
        //if root has 0 or 1 child
        if(root->left == NULL) {
            Tree * temp = root->right;
            free(root);
            return temp;
        }
        if(root->right == NULL) {
            Tree * temp = root->left;
            free(root);
            return temp;
        }
        //if root has 2 children
        Tree * temp = findMinforDelete(root->right);
        root->index = temp->index;
        root->right = DeleteNode(root->right, temp->index);

    }
    else if(root->index > key) {
        root->left = DeleteNode(root->left, key);
    }
    else {
        root->right = DeleteNode(root->right, key);
    }
    return root;
}

void test() {
    int n, k;
    scanf("%d %d", &n, &k);
    int ID[200];

    for(int i = 0; i < n; i++) {
        scanf("%d", &ID[i]);
    }

    if(k == 1) {
        printf("%d", ID[n - 1]);
        return;
    }
    else {
        Queue * q = Initialize();
        Tree * visited = NULL;

        int j = 0;
        for(int i = 0; i < n; i++) {
            if(!Search(visited, ID[i])) {
                visited = Insert(visited, ID[i]);
                if(j < k) {
                    q = push(q, ID[i]);
                    j++;
                }
                else if(j == k) {
                    int index = pop(&q);
                    visited = DeleteNode(visited, index);
                    q = push(q, ID[i]);
                }
            }
        }

        printf("%d\n", j);
        int result[j];
        int i = 0;
        for(i = 0; i < j; i++) {
            result[i] = pop(&q);
        }
        for(i = j - 1; i >= 0; i--) printf("%d ", result[i]);
        free(visited);
    }
}

int main ()
{
    // int t;
    // scanf("%d", &t);
    // while(t--)
        test();

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

typedef struct list {
    int id;
    struct list * nextPtr;
} List;

List * AddToFront(List * start, int ID) {
    List *newPtr = (List *) malloc(sizeof(List));
    newPtr->id = ID;
    newPtr->nextPtr = start;
    start = newPtr;

    return start;
}

bool Search(List * start, int ID) {
    List * cur = start;
    while(cur != NULL) {
        if(cur->id == ID) {
            return true;
        }
        cur = cur->nextPtr;
    }
    return false;
}

List * DeleteTail(List * start) {
    if(start == NULL)
        return NULL;

    List * last = start;
    List * prev = start;
    while(last->nextPtr != NULL) {
        prev = last;
        last = last->nextPtr;
    }
    prev->nextPtr = last->nextPtr;
    free(last);
    return start;
}

void test() {
    int n, k;
    scanf("%d %d", &n, &k);
    int ID[n];
    List * start = NULL;
    int j = 0;
    for(int i = 0; i < n; i++) {
        scanf("%d", &ID[i]);

        bool ok = Search(start, ID[i]);
        if(!ok) {
            if(j < k) {
                start = AddToFront(start, ID[i]);
                j++;
            }
            else {
                start = DeleteTail(start);
                start = AddToFront(start, ID[i]);
            }
        }
    }
    printf("%d\n", j);
    for(List * cur = start; cur != NULL; cur = cur->nextPtr) {
        printf("%d ", cur->id);
    }

}

int main ()
{
    // int t;
    // scanf("%d", &t);
    // while(t--)
        test();

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>

typedef struct node {
    int id;
    struct node * next;
} Node;

typedef struct {
    Node * front, * rear;
} Queue;

Queue * Initialize() {
    Queue * q = (Queue *) malloc(sizeof(Queue));
    q->front = q->rear = NULL;
    return q;
}

int isEmpty(Queue * q) {
    return (q->rear == NULL) && (q->front == NULL);
}

Queue * push(Queue * q, int ID) {
    Node * newNode = (Node *) malloc(sizeof(Node));
    newNode->id = ID;
    newNode->next = NULL;
    if(isEmpty(q)) {
        q->front = q->rear = newNode;
    }
    else {
        q->rear->next = newNode;
        q->rear = newNode;
    }
    //printf("Push %d to queue\n", q->rear->id);
    return q;
}

int pop(Queue ** q) {
    if(isEmpty(*q)) {
        return -1;
    }
    else {
        Node * temp = (*q)->front;
        (*q)->front = (*q)->front->next;
        int ret = temp->id;
        //printf("pop %d from queue\n", ret);
        free(temp);
        return ret;
    }
}

typedef struct tree {
    int index;
    struct tree * left, * right;            //for saving visited index
} Tree;

Tree * Insert(Tree * root, int ID) {
    if(root == NULL) {
        root = (Tree *) malloc(sizeof(Tree));
        root->index = ID;
        root->left = root->right = NULL;
    }
    else {
        if(root->index > ID) {
            root->left = Insert(root->left, ID);
        }
        else if(root->index < ID) {
            root->right = Insert(root->right, ID);
        }
    }
    return root;

}

bool Search(Tree * root, int search) {
    if(root == NULL) {
        return false;
    }

    if(root->index == search) {
        return true;
    }
    else if(root->index > search) {
        return Search(root->left, search);
    }
    else {
        return Search(root->right, search);
    }
}

Tree * findMinforDelete(Tree * root) {    //for delete function
    Tree * cur = root;
    while(cur->left != NULL) {
        cur = cur->left;
    }
    return cur;
}

Tree * DeleteNode(Tree * root, int key) {
    if(root == NULL) {  //if nothing to be deleted
        return NULL;
    }
    //
    if(root->index == key) {
        //if root has 0 or 1 child
        if(root->left == NULL) {
            Tree * temp = root->right;
            free(root);
            return temp;
        }
        if(root->right == NULL) {
            Tree * temp = root->left;
            free(root);
            return temp;
        }
        //if root has 2 children
        Tree * temp = findMinforDelete(root->right);
        root->index = temp->index;
        root->right = DeleteNode(root->right, temp->index);

    }
    else if(root->index > key) {
        root->left = DeleteNode(root->left, key);
    }
    else {
        root->right = DeleteNode(root->right, key);
    }
    return root;
}

void test() {
    int n, k;
    scanf("%d %d", &n, &k);
    int ID[n];

    for(int i = 0; i < n; i++) {
        scanf("%d", &ID[i]);
    }

    Queue * q = Initialize();
    Tree * visited = NULL;

    int j = 0;
    for(int i = 0; i < n; i++) {
        if(!Search(visited, ID[i])) {
            visited = Insert(visited, ID[i]);
            if(j < k) {
                q = push(q, ID[i]);
                j++;
            }
            else if(j == k) {
                int index = pop(&q);
                visited = DeleteNode(visited, index);
                q = push(q, ID[i]);
            }
        }
    }

    printf("%d\n", j);
    int result[j];
    int i = 0;
    for(i = 0; i < j; i++) {
        result[i] = pop(&q);
    }
    for(i = j - 1; i >= 0; i--) printf("%d ", result[i]);
    free(visited);
}

int main ()
{
    // int t;
    // scanf("%d", &t);
    // while(t--)
        test();

    return 0;
}