fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).expect("INPUT::read line failed");
    let amount = input.trim().parse::<i32>().expect("AMOUNT::parse to i32 failed");

    let mut rows = String::new();
    std::io::stdin().read_line(&mut rows).expect("ROWS::read line failed");

    let (mut anton_win, mut danik_win) = (i32::default(), i32::default());

    for _i in 0..rows.len() {
        match rows.pop().unwrap() {
            'A' => anton_win += 1,
            'D' => danik_win += 1,
            _ => (),
        }
    }
    //println!("anton_win = {}\r\ndanik_win = {}\r\n", anton_win, danik_win);
    if anton_win > danik_win {
        println!("Anton");
    }else if anton_win == danik_win {
        println!("FriendShip");
    }else {
        println!("Danik");
    }

}


//! http://codeforces.com/contest/734/problem/A

fn main() {
  use std::io;
  use std::cmp::Ordering;
  let mut buf = String::new();
  io::stdin().read_line(&mut buf).unwrap();
  buf.clear();
  io::stdin().read_line(&mut buf).unwrap();
  let games = buf.trim().as_bytes();
  let mut anton = 0;
  let mut danik = 0;
  for &b in games {
    if b == b'A' { anton += 1; }
    if b == b'D' { danik += 1; }
  }
  println!("{}",
    match anton.cmp(&danik) {
      Ordering::Less => "Danik",
      Ordering::Greater => "Anton",
      Ordering::Equal => "Friendship"
    }
  );
}


#[allow(unused)] use std::io::*;
#[allow(unused)] use std::collections::*;
#[allow(unused)] use std::mem::*;
#[allow(unused)] use std::num::*;
#[allow(unused)] use std::cmp::*;
#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{
    let mut inp = String::new(); stdin().read_line(&mut inp).ok();
    let s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).collect();
    let mut cnt : usize = 0;
    fn next<T>(cnt: &mut usize, p: &Vec<&str>) -> T where T:std::str::FromStr
    { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }
    ($(next::<$x>(&mut cnt, &s)), +)
    }}; }
#[allow(unused)] macro_rules! arr { ($($n:expr, $T:ty), +) => {{
    let mut inp = String::new(); stdin().read_line(&mut inp).ok();
    let mut s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0);
    ($({let mut v = Vec::new(); v.reserve(($n) as usize);
        for _ in 0..$n { let t = s.next(); if t == None { break; }
        v.push(t.unwrap().parse::<$T>().unwrap()); } v }),+)
    }}; }

///////////////////////////////////////////////////////////////////////////////
fn main()
{
    scan!(usize);
    let s = scan!(String);
    let a = s.chars().filter(|x| *x == 'A').count();
    let b = s.chars().filter(|x| *x == 'D').count();
    println!("{}", if a == b { "Friendship" } else { if a > b { "Anton" } else { "Danik" } } );
}


//Anton likes to play chess, and so does his friend Danik.
//
//Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
//
//Now Anton wonders, who won more games, he or Danik? Help him determine this.
//Input
//
//The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of games played.
//
//The second line contains a string s, consisting of n uppercase English letters 'A' and 'D' — the outcome of each of the games. The i-th character of the string is equal to 'A' if the Anton won the i-th game and 'D' if Danik won the i-th game.
//Output
//
//If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
//
//If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
//
//If Anton and Danik won the same number of games, print "Friendship" (without quotes).
//
use std::io::stdin;

fn main() {
    let mut buffer = String::new();
    stdin().read_line(&mut buffer).expect("error reading line");
    stdin().read_line(&mut buffer).expect("error reading line");
    let mut anton = 0;
    let mut danik = 0;
    for c in buffer.chars() {
        match c {
            'A' => anton += 1,
            'D' => danik += 1,
            _ => (),
        };
    }
    if anton == danik {
        println!("Friendship");
    } else if anton > danik {
        println!("Anton")
    } else if danik > anton {
        println!("Danik");
    }
}


use std::io::{self, BufRead};

fn getdata() -> String {
    let mut buf = String::new();
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        buf = line.unwrap();
    }
    buf
}

fn count_occurences<F>(string: &String, is_occurence: F) -> u32
                        where F: Fn(char) -> bool {
    let mut count = 0;
    for c in string.chars() {
        if is_occurence(c) {
            count += 1;
        }
    }
    count
}

fn winner(matches: String) -> &'static str {
    let anton_wins_count = count_occurences(&matches, |c: char| c == 'A') as i32;
    let danik_wins_count = count_occurences(&matches, |c: char| c == 'D') as i32;
    match anton_wins_count - danik_wins_count {
        diff if diff > 0 => "Anton",
        diff if diff < 0 => "Danik",
        _ => "Friendship",
    }
}

fn main() {
    println!("{}", winner(getdata()));
}


use std::io::{self, BufRead};
use std::cmp::Ordering;

fn getdata() -> String {
    let mut buf = String::new();
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        buf = line.unwrap();
    }
    buf
}

fn count_occurences<F>(string: &String, is_occurence: F) -> u32
                        where F: Fn(char) -> bool {
    let mut count = 0;
    for c in string.chars() {
        if is_occurence(c) {
            count += 1;
        }
    }
    count
}

fn winner(matches: String) -> &'static str {
    let anton_wins_count = count_occurences(&matches, |c: char| c == 'A');
    let danik_wins_count = count_occurences(&matches, |c: char| c == 'D');
    match anton_wins_count.cmp(&danik_wins_count) {
        Ordering::Greater => "Anton",
        Ordering::Less => "Danik",
        Ordering::Equal => "Friendship",
    }
}

fn main() {
    println!("{}", winner(getdata()));
}


use std::cmp::Ordering;

fn main() {
    {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
    }

    let scores = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    };

    let d_count = scores.chars().filter(|&s| s == 'A').count();
    let a_count = scores.len() - d_count;
    match a_count.cmp(&d_count) {
        Ordering::Less => println!("Anton"),
        Ordering::Greater => println!("Danik"),
        Ordering::Equal => println!("Friendship"),
    }
}


use std::io;

fn main() {
    let mut round = String::new();
    let mut winners = String::new();

    let _ = io::stdin().read_line(&mut round);
    let _ = io::stdin().read_line(&mut winners);

    let mut anton = 0;
    let mut danik = 0;
    for winner in winners.trim().chars() {
        println!("{}", winner);
        if winner == 'A' {
            anton += 1;
        } else {
            danik += 1;
        }
    }

    if anton > danik {
        println!("Anton");
    } else if anton < danik {
        println!("{} Danik {} Anton", danik, anton);
    } else {
        println!("Friendship");
    }
}


use std::io;

fn main() {
    let mut round = String::new();
    let mut winners = String::new();

    let _ = io::stdin().read_line(&mut round);
    let _ = io::stdin().read_line(&mut winners);

    let mut anton = 0;
    let mut danik = 0;
    for winner in winners.trim().chars() {
        if winner == 'A' {
            anton += 1;
        } else {
            danik += 1;
        }
    }

    if anton > danik {
        println!("Anton");
    } else if anton < danik {
        println!("Danik");
    } else {
        println!("Friendship");
    }
}


use std::io;

fn main() {
    let mut round = String::new();
    let mut winners = String::new();

    let _ = io::stdin().read_line(&mut round);
    let _ = io::stdin().read_line(&mut winners);

    let mut anton = 0;
    let mut danik = 0;
    for winner in winners.trim().chars() {
        println!("{}", winner);
        if winner == 'A' {
            anton += 1;
        } else {
            danik += 1;
        }
    }

    if anton > danik {
        println!("Anton");
    } else if anton < danik {
        println!("Danik");
    } else {
        println!("Friendship");
    }
}


//spnauti-rust
struct WordReader {
    it : std::vec::IntoIter<String>,
}
#[allow(dead_code)]
impl WordReader {
    fn new<T : std::io::Read>(mut reader : T) -> WordReader {
        let mut s = String::new();
        reader.read_to_string(&mut s).unwrap();
        WordReader { it : s
            .split_ascii_whitespace()
            .map(String::from).collect::<Vec<_>>()
            .into_iter()
        }
    }
    fn from_stdin() -> WordReader {
        WordReader::new(std::io::stdin())
    }
    fn s(&mut self) -> String {
        self.it.next().unwrap()
    }
    fn ab(&mut self) -> Vec<u8> {
        self.it.next().unwrap().into_bytes()
    }
    fn i(&mut self) -> i32 {
        self.it.next().unwrap().parse().unwrap()
    }
}

fn main() {
    let mut input = WordReader::from_stdin();
    let n = input.i();
    let d = (input.ab().into_iter().filter(|&a| a == b'D').count() * 2) as i32;
    use std::cmp::Ordering::*;
    let sol = match n.cmp(&d) {
        | Less => "Danik",
        | Equal => "Friendship",
        | Greater => "Anton",
    };
    println!("{}", sol);
}


use std::collections::HashMap;
fn main() {
    let line = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    };
    let mut counter = HashMap::new();
    line.chars().for_each(|c| *counter.entry(c).or_insert(0) += 1);
    let d = *counter.entry('D').or_default();
    let a = *counter.entry('A').or_default();
    println!("{}",
             if a == d {
                 "Friendship"
             } else if a > d {
                 "Anton"
             } else {
                 "Danik"
             });
}


use std::collections::HashMap;
fn main() {
    let line = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    };
    let mut counter = HashMap::new();
    line.chars().for_each(|c| *counter.entry(c).or_insert(0) += 1);
    let d = *counter.entry('D').or_insert(0);
    let a = *counter.entry('A').or_insert(0);
    println!("{}",
             if a == d {
                 "Friendship"
             } else if a > d {
                 "Anton"
             } else {
                 "Danik"
             });
}


use std::collections::HashMap;
fn main() {
    let _ = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    };

    let line = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    };
    let mut counter = HashMap::new();
    line.chars().for_each(|c| *counter.entry(c).or_insert(0) += 1);
    let d = *counter.entry('D').or_insert(0);
    let a = *counter.entry('A').or_insert(0);
    println!("{}",
             if a == d {
                 "Friendship"
             } else if a > d {
                 "Anton"
             } else {
                 "Danik"
             });
}


/*
    Implementation, strings - https://codeforces.com/problemset/problem/281/A
    Completed: 4/7/20 3:43
*/

use std::io;

fn main() {
    let mut first_input = String::new();
    io::stdin().read_line(&mut first_input).unwrap();

    let mut last_input = String::new();
    io::stdin().read_line(&mut last_input).unwrap();

    let mut anton = 0;
    let mut danik = 0;

    for char in last_input.trim().chars() {
        if char.eq(&'D') {
            danik += 1;
        } else {
            anton += 1;
        }
    }

    if anton == danik {
        println!("Friendship");
    } else if anton > danik {
        println!("Anton");
    } else {
        println!("Danik");
    }

}


use std::io::*;

fn main() {
    let mut line = String::new();
    stdin().read_line(&mut line).ok().expect("read error");
    line = line.trim().to_string();

    let mut word = String::new();
    stdin().read_line(&mut word).ok().expect("read error");
    word = word.trim().to_string();

    let mut count_anton = 0;
    let mut count_danik = 0;

    for char in word.chars() {
        if char == 'A' {
            count_anton += 1;
        } else {
            count_danik += 1;
        }
    }

    if count_anton > count_danik {
        println!("Anton");
    } else if count_danik > count_anton {
        println!("Danik");
    } else {
        println!("Friendship");
    }
}


use std::io::{BufReader, BufRead};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut balance = 0;
    let games = BufReader::new(std::io::stdin())
        .lines()
        .map(Result::unwrap)
        .skip(1)
        .next()
        .unwrap();

    for game in games.chars() {
        match game {
        | 'A' => balance += 1,
        | 'D' => balance -= 1,
        | _ => (),
        }
    }

    match balance {
    | n if n < 0 => println!("Danik"),
    | 0 => println!("Friendship"),
    | _ => println!("Anton"),
    }

    Ok(())
}


use std::cmp::Ordering;

macro_rules! read_line {
    ($v:ident) => {
        let mut temp = String::new();
        std::io::stdin().read_line(&mut temp).unwrap();
        let $v = temp;
    };
    (var, $t:ty, $($v:ident), *) => {
        read_line!(input_line);
        let mut iter = parse_token!($t, input_line);
        $(
            let $v = iter.next().unwrap();
        )*
    };
    (vec, $t:ty, $v:ident) => {
        read_line!(input_line);
        let iter = parse_token!($t, input_line);
        let $v: Vec<$t> = iter.collect();
    };
    ($($v:ident; $t:ty), *) => {
        read_line!(input_line);
        let mut iter = input_line.split_whitespace();
        $(
            let $v: $t = iter.next().unwrap().parse().unwrap();
        )*
    };
}

macro_rules! parse_token {
    ($t:ty, $e:expr) => {
        $e.split_whitespace().map(|x| x.parse::<$t>().unwrap());
    };
}

fn main() {
    read_line!(input_line);
    read_line!(input_line);
    let sum = input_line.trim().chars().fold((0, 0), |acc, x| {
        match x {
            'A' => (acc.0 + 1, acc.1),
            'D' => (acc.0, acc.1 + 1),
            _ => unreachable!()
        }
    });
    match sum.0.cmp(&sum.1) {
        Ordering::Greater => println!("Anton"),
        Ordering::Equal => println!("Friendship"),
        Ordering::Less => println!("Danik")
    }
}


#include<bits/stdc++.h>
using namespace std;
#define print printf("==================\n");
typedef    long long ll;
typedef   unsigned long long ull;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define readf                freopen("in.txt", "r", stdin);
#define writef               freopen("out.txt", "w", stdout);
typedef pair<ll,  ll   > payar;
priority_queue<int, vector<int>,  greater<int> > pq1,pq2; ///accending
vector< pair<ll,payar  > > vpp;
vector < payar >  vp;
#define pi acos(-1.0)
const ll INF = 10e12;
#define EPS 1e-9
#define  mod   1000000007
#define  mod2   100000000
#define all(x) x.begin(),x.end()
#define endl "\n"
const int N=3e5+5;

deque<int>v;
deque<int>::iterator it;
map<int,bool>mp;
int main()
{
    IOS;

    int  n,k;
    cin>>n>>k;
    ll ara[n];

    for(int i = 0 ; i<n ; i++)
    {
        cin>>ara[i];

    }

    int sz=0;
    for(int i = 0 ; i<n ; i++)
    {
        if( mp[ara[i]])
        {
            continue;
        }
        else
        {
            if(k>sz)
            {
                v.push_front(ara[i]);
                sz++;
                mp[ara[i]]=true;
            }
            else
            {
                it = v.begin();
                //
                int top= v.at(v.size()-1);
                mp[top]=0;
                v.pop_back();
                v.push_front(ara[i]);
                mp[ara[i]]=1;
                sz++;
            }
        }

    }
    cout<<v.size()<<endl;

    for(auto it:v)
    {
        cout<<it<<" ";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long inf=0x7fffffff;
#define MAX 500005
#define ll long long
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define repp(i,s,e) for(int i=s;i<e;i++)
#define dep(i,e,s) for(int i=e;i>=s;i--)
#define pf printf
#define sf scanf
#define mst(a,x) memset(a,x,sizeof(a))
struct node{
    int n,w;
};
bool cmp(node a,node b){
    return a.n<b.n;
}
ll n,m,t,a[200001],f,k,bot=1;
inline int read(){
     int X=0,w=0; char ch=0;
     while(!isdigit(ch)) {
          w|=ch=='-';
          ch=getchar();
     }
     while(isdigit(ch))
          X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
     return w?-X:X;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>k;
    m=0;
    rep(i,1,n){
    	t=read();
    	f=0;
    	rep(j,bot,bot+m-1){
    		if (a[j]==t){
    			f=1;
    			break;
			}
		}
		if (f==0){
			if (m<k){
				m++;
				a[m]=t;
			}
			else{
				bot++;
				m++;
				a[m]=t;
			}
		}
	}
	if (m>k)
	    cout<<k<<endl;
	else
	    cout<<m<<endl;
	dep(i,bot+m-1,bot+1){
		cout<<a[i]<<" ";
	}
	cout<<a[bot]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long inf=0x7fffffff;
#define MAX 500005
#define ll long long
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define repp(i,s,e) for(int i=s;i<e;i++)
#define dep(i,e,s) for(int i=e;i>=s;i--)
#define pf printf
#define sf scanf
#define mst(a,x) memset(a,x,sizeof(a))
ll n,m,t,a[200001],f,k,r,bot;
inline int read(){
     int X=0,w=0; char ch=0;
     while(!isdigit(ch)) {
          w|=ch=='-';
          ch=getchar();
     }
     while(isdigit(ch))
          X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
     return w?-X:X;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    n=read();k=read();
    m=0;bot=1;r=0;
    rep(i,1,n){
    	t=read();
    	f=0;
    	rep(j,bot,bot+r-1){
    		if (a[j]==t){
    			f=1;
    			break;
			}
		}
		if (f==0){
			if (m<k){
				m++;
				r=m;
				a[m]=t;
			}
			else{
				bot++;
				m++;
				a[m]=t;
			}
		}
	}
	cout<<r<<endl;
	dep(i,bot+r-1,bot+1){
		cout<<a[i]<<" ";
	}
	cout<<a[bot]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long inf=0x7fffffff;
#define MAX 500005
#define ll long long
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define repp(i,s,e) for(int i=s;i<e;i++)
#define dep(i,e,s) for(int i=e;i>=s;i--)
#define pf printf
#define sf scanf
#define mst(a,x) memset(a,x,sizeof(a))
ll n,m,t,a[200001],f,k,r,bot;
inline int read(){
     int X=0,w=0; char ch=0;
     while(!isdigit(ch)) {
          w|=ch=='-';
          ch=getchar();
     }
     while(isdigit(ch))
          X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
     return w?-X:X;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    n=read();k=read();
    m=0;bot=1;r=0;
    rep(i,1,n){
    	t=read();
    	f=0;
    	if (r>=1){
    		if (binary_search(a+bot,a+bot+r-1,t)==1||a[m]==t){
    	     	f=1;
		    }
		}
		if (f==0){
			if (m<k){
				m++;
				r=m;
				a[m]=t;
			}
			else{
				bot++;
				m++;
				a[m]=t;
			}
		}
	}
	cout<<r<<endl;
	dep(i,bot+r-1,bot+1){
		cout<<a[i]<<" ";
	}
	cout<<a[bot]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long inf=0x7fffffff;
#define MAX 500005
#define ll long long
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define repp(i,s,e) for(int i=s;i<e;i++)
#define dep(i,e,s) for(int i=e;i>=s;i--)
#define pf printf
#define sf scanf
#define mst(a,x) memset(a,x,sizeof(a))
ll n,m,t,a[200001],f,k,r,bot;
inline int read(){
     int X=0,w=0; char ch=0;
     while(!isdigit(ch)) {
          w|=ch=='-';
          ch=getchar();
     }
     while(isdigit(ch))
          X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
     return w?-X:X;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    n=read();k=read();
    m=0;bot=1;
    rep(i,1,n){
    	t=read();
    	f=0;
    	rep(j,bot,bot+r-1){
    		if (a[j]==t){
    			f=1;
    			break;
			}
		}
		if (f==0){
			if (m<k){
				m++;
				r=m;
				a[m]=t;
			}
			else{
				bot++;
				m++;
				a[m]=t;
			}
		}
	}
	if (m>k)m=k;
	cout<<m<<endl;
	dep(i,bot+m-1,bot+1){
		cout<<a[i]<<" ";
	}
	cout<<a[bot]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long inf=0x7fffffff;
#define MAX 500005
#define ll long long
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define repp(i,s,e) for(int i=s;i<e;i++)
#define dep(i,e,s) for(int i=e;i>=s;i--)
#define pf printf
#define sf scanf
#define mst(a,x) memset(a,x,sizeof(a))
ll n,k,t;
map<ll,bool> check;
deque<ll> v;
inline int read(){
     int X=0,w=0; char ch=0;
     while(!isdigit(ch)) {
          w|=ch=='-';
          ch=getchar();
     }
     while(isdigit(ch))
          X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
     return w?-X:X;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    n=read();k=read();
    t=read();
    check[t]=1;
    v.push_back(t);
    rep(i,2,n){
    	t=read();
    	if (!check[t]){
		    v.push_back(t);
		    check[t]=1;
    		if (v.size()>k){
    			check[v[0]]=0;
    		    v.pop_front();
			}
		}
	}
	cout<<v.size()<<endl;
	dep(i,v.size()-1,1){
		cout<<v[i]<<" ";
	}
	cout<<v[0]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long inf=0x7fffffff;
#define MAX 500005
#define ll long long
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define repp(i,s,e) for(int i=s;i<e;i++)
#define dep(i,e,s) for(int i=e;i>=s;i--)
#define pf printf
#define sf scanf
#define mst(a,x) memset(a,x,sizeof(a))
ll n,m,t,a[200001],f,k,r,bot;
inline int read(){
     int X=0,w=0; char ch=0;
     while(!isdigit(ch)) {
          w|=ch=='-';
          ch=getchar();
     }
     while(isdigit(ch))
          X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
     return w?-X:X;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    n=read();k=read();
    m=0;bot=1;r=0;
    rep(i,1,n){
    	t=read();
    	f=0;
    	if (1<=r){
    		if (binary_search(a+bot,a+bot+r-1,t)){
		    	f=1;
		    }
		}
		if (a[bot+r-1]==t)f=1;
		if (a[bot]==t)f=1;
		if (f==0){
			if (m<k){
				m++;
				r=m;
				a[m]=t;
			}
			else{
				bot++;
				m++;
				a[m]=t;
			}
		}
	}
	if (m>k)m=k;
	cout<<m<<endl;
	dep(i,bot+m-1,bot+1){
		cout<<a[i]<<" ";
	}
	cout<<a[bot]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long inf=0x7fffffff;
#define MAX 500005
#define ll long long
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define repp(i,s,e) for(int i=s;i<e;i++)
#define dep(i,e,s) for(int i=e;i>=s;i--)
#define pf printf
#define sf scanf
#define mst(a,x) memset(a,x,sizeof(a))
ll n,m,t,a[200001],f,k,bot;
inline int read(){
     int X=0,w=0; char ch=0;
     while(!isdigit(ch)) {
          w|=ch=='-';
          ch=getchar();
     }
     while(isdigit(ch))
          X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
     return w?-X:X;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>k;
    m=0;bot=1;
    rep(i,1,n){
    	t=read();
    	f=0;
    	rep(j,bot,bot+m-1){
    		if (a[j]==t){
    			f=1;
    			break;
			}
		}
		if (f==0){
			if (m<k){
				m++;
				a[m]=t;
			}
			else{
				bot++;
				m++;
				a[m]=t;
			}
		}
	}
	if (m>k)
	    cout<<k<<endl;
	else
	    cout<<m<<endl;
	if (m>k)m=k;
	dep(i,bot+m-1,bot+1){
		cout<<a[i]<<" ";
	}
	cout<<a[bot]<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define si signed
#define sc(x) scanf("%I64d",&x);
#define read(A) for(int i=0;i<n;i++) scanf("%I64d",&A[i]);
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define P pair<int,int>
#define maxn 200000+50
bool vis[maxn];
list<int> a;
int n,k,s;
int x;
si main()
{
    s=0;
    sc(n);
    sc(k);
    for(int i=0; i<n; i++)
    {
        sc(x);
        if(!vis[x])
        {
            if(s==k)
            {
              vis[a.back()]=0;
              a.pop_back();
              a.push_front(x);
              vis[x]=1;
            }
            else
            {
                a.push_front(x);
                vis[x]=1;
                s++;
            }
        }
    }
    auto it=a.begin();
    cout<<a.size()<<'\n';
    while(it!=a.end()){
        cout<<*it<<' ';
        it++;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define si signed
#define sc(x) scanf("%I64d",&x);
#define read(A) for(int i=0;i<n;i++) scanf("%I64d",&A[i]);
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define P pair<int,int>
#define maxn 200000+50
map<si,si> vis;
int A[2*maxn+1000];
int n,k,s;
si x;
si main()
{
    s=0;
    sc(n);
    sc(k);
    int l,r;
    l=r=maxn+100;

    for(int i=0; i<n; i++)
    {
        scanf("%d",&x);
        if(!vis[x])
        {
            if(s==k)
            {
                vis[A[r]]=0;
                r--;
                A[l]=x;
                l--;
                vis[x]=1;
            }
            else
            {
                A[l]=x;
                l--;
                vis[x]=1;
                s++;
            }
        }
    }
    cout<<r-l<<'\n';
    for(int i=l+1; i<=r; i++)
    {
        cout<<A[i]<<' ';
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define si signed
#define sc(x) scanf("%I64d",&x);
#define read(A) for(int i=0;i<n;i++) scanf("%I64d",&A[i]);
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define P pair<int,int>
#define maxn 200000+50
unordered_map<int,si> vis;
int A[2*maxn+1000];
int n,k,s;
int x;
si main()
{
    s=0;
    sc(n);
    sc(k);
    int l,r;
    l=r=maxn+100;

    for(int i=0; i<n; i++)
    {
        sc(x);
        if(!vis[x])
        {
            if(s==k)
            {
                vis[A[r]]=0;
                r--;
                A[l]=x;
                l--;
                vis[x]=1;
            }
            else
            {
                A[l]=x;
                l--;
                vis[x]=1;
                s++;
            }
        }
    }
    cout<<r-l<<'\n';
    for(int i=l+1; i<=r; i++)
    {
        cout<<A[i]<<' ';
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define si signed
#define sc(x) scanf("%I64d",&x);
#define read(A) for(int i=0;i<n;i++) scanf("%I64d",&A[i]);
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define P pair<int,int>
#define maxn 200000+50
unordered_map<int,si> vis;
list<int> a;
int n,k,s;
int x;
si main()
{
    s=0;
    sc(n);
    sc(k);
    for(int i=0; i<n; i++)
    {
        sc(x);
        if(!vis[x])
        {
            if(s==k)
            {
              vis[a.back()]=0;
              a.pop_back();
              a.push_front(x);
              vis[x]=1;
            }
            else
            {
                a.push_front(x);
                vis[x]=1;
                s++;
            }
        }
    }
    auto it=a.begin();
    cout<<a.size()<<'\n';
    while(it!=a.end()){
        cout<<*it<<' ';
        it++;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define si signed
#define sc(x) scanf("%I64d",&x);
#define read(A) for(int i=0;i<n;i++) scanf("%I64d",&A[i]);
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define P pair<int,int>
#define maxn 200000+50
unordered_map<si,si> vis;
int A[2*maxn+1000];
int n,k,s;
si x;
si main()
{
    s=0;
    sc(n);
    sc(k);
    int l,r;
    l=r=maxn+100;

    for(int i=0; i<n; i++)
    {
        scanf("%d",&x);
        if(!vis[x])
        {
            if(s==k)
            {
                vis[A[r]]=0;
                r--;
                A[l]=x;
                l--;
                vis[x]=1;
            }
            else
            {
                A[l]=x;
                l--;
                vis[x]=1;
                s++;
            }
        }
    }
    cout<<r-l<<'\n';
    for(int i=l+1; i<=r; i++)
    {
        cout<<A[i]<<' ';
    }
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
    long long int n,k;
    cin>>n>>k;
    vector<long long int>v;
     map<long long int,long long int>mp;
    while(n--)
    {
        long long int i;
        cin>>i;
        vector<long long int>:: iterator it;
        //cout<<mp[i]<<endl;
        if(mp[i]==0)
        {
            if(v.size()>=k)
                {
                    mp[v[0]]=0;
                    //cout<<mp[v[0]]<<endl;
                    it=v.begin();
                    v.erase(it);
                }
            v.push_back(i);
            mp[i]=1;
        }

    }
    cout<<v.size()<<endl;
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
    long long int m,n;
    cin>>n>>m;
    map<long long int,long long int>mp;
    vector<long long int>v;
    for(int i=0;i<n;i++)
    {
        long long int a;
        cin>>a;
        if(mp[a]==0)
        {
            if(v.size()<m)
            {
                v.push_back(a);

            }
            else
            {
                mp[v[0]]=0;
                v.erase(v.begin());
                v.push_back(a);
            }
            mp[a]=1;
        }
    }
    cout<<v.size()<<endl;
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
    long long int m,n;
    cin>>n>>m;
    map<long long int,int>mp;
    vector<long long int>v;
    for(int i=0;i<n;i++)
    {
        long long int a;
        cin>>a;
        if(mp[a]==0)
        {
            if(v.size()<m)
            {
                v.push_back(a);

            }
            else
            {
                mp[v[0]]=0;
                v.erase(v.begin());
                v.push_back(a);
            }
            mp[a]=1;
        }
    }
    cout<<v.size()<<endl;
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
    long long int n,k;
    cin>>n>>k;
    vector<long long int>v;
    while(n--)
    {
        long long int i;
        cin>>i;
        vector<long long int>:: iterator it;
        it=find(v.begin(),v.end(),i);
        if(it==v.end())
        {
            if(v.size()>=k)
                {
                    it=v.begin();
                    v.erase(it);
                }
            v.push_back(i);
        }

    }
    cout<<v.size()<<endl;
    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i]<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
    long long int m,n;
    cin>>n>>m;
    map<long long int,int>mp;
    deque<long long int>q;
    for(int i=0;i<n;i++)
    {
        long long int a;
        cin>>a;
        if(mp[a]==0)
        {
            if(q.size()<m)
            {
                q.push_front(a);

            }
            else
            {
                mp[q.back()]=0;
                q.pop_back();
               q.push_front(a);
            }
            mp[a]=1;
        }
    }
    cout<<q.size()<<endl;

    for(auto i=q.begin();i!=q.end();i++)
    {
        cout<<*i<<" ";

    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<map>

using namespace std;

typedef long long ll;

map<ll, int>mp;
ll ans[205];

int main()
{
	int n, k, cnt = 0, cnt1 = 0, cnt2 = 0;
	ll t;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &t);
		if (mp.count(t) > 0)
		{
			continue;
		}
		else
		{
			if (cnt == k)
			{
				for (map<ll, int>::iterator it = mp.begin(); it != mp.end(); it++)
				{
					if (it->first == ans[cnt1])
					{
						mp.erase(it);
					}
				}
				++cnt1;
			}
			else
			{
				++cnt;
			}
			mp[t] = 1;
			ans[cnt2++] = t;
		}
	}
	printf("%d\n", cnt);
	for (int i = cnt2 - 1; i >= cnt1; i--)
	{
		printf("%lld ", ans[i]);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<bitset>

using namespace std;

typedef long long ll;

bitset<1000000005> vis;
ll ans[200005];

int main()
{
	int n, k, cnt = 0, cnt1 = 0, cnt2 = 0;
	ll t;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%I64d", &t);
		if (!vis[t])
		{
			if (cnt == k)
			{
				vis[ans[cnt1]] = 0;
				++cnt1;
			}
			else
			{
				++cnt;
			}
			vis[t] = 1;
			ans[cnt2++] = t;
		}
		else
		{
			continue;
		}
	}
	printf("%d\n", cnt);
	for (int i = cnt2 - 1; i >= cnt1; i--)
	{
		printf("%I64d ", ans[i]);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<map>

using namespace std;

typedef long long ll;

map<ll, int>mp;
ll ans[205];

int main()
{
	int n, k, cnt = 0, cnt1 = 0, cnt2 = 0;
	ll t;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &t);
		if (mp.count(t) > 0)
		{
			continue;
		}
		else
		{
			if (cnt == k)
			{
				map<ll, int>::iterator keys = mp.begin();
				printf("delete %lld\n", keys->first);
				mp.erase(keys);
				++cnt1;
			}
			else
			{
				++cnt;
			}
			mp[t] = 1;
			ans[cnt2++] = t;
		}
	}
	printf("%d\n", cnt);
	for (int i = cnt2 - 1; i >= cnt1; i--)
	{
		printf("%lld ", ans[i]);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<map>

using namespace std;

typedef long long ll;

map<ll, int>mp;
ll ans[205];

int main()
{
	int n, k, cnt = 0, cnt1 = 0, cnt2 = 0;
	ll t;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &t);
		if (mp.count(t) > 0)
		{
			continue;
		}
		else
		{
			if (cnt == k)
			{
				map<ll, int>::iterator keys = mp.begin();
				mp.erase(keys);
				++cnt1;
			}
			else
			{
				++cnt;
			}
			mp[t] = 1;
			ans[cnt2++] = t;
		}
	}
	printf("%d\n", cnt);
	for (int i = cnt2 - 1; i >= cnt1; i--)
	{
		printf("%lld ", ans[i]);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<map>

using namespace std;

typedef long long ll;

map<ll, int>mp;
bool vis[1000000005];
ll ans[200005];

int main()
{
	int n, k, cnt = 0, cnt1 = 0, cnt2 = 0;
	ll t;
	scanf("%d %d", &n, &k);
	memset(vis, true, sizeof(vis));
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &t);
		if (vis[t])
		{
			if (cnt == k)
			{
				vis[ans[cnt1]] = true;
				++cnt1;
			}
			else
			{
				++cnt;
			}
			vis[t] = false;
			ans[cnt2++] = t;
		}
		else
		{
			continue;
		}
	}
	printf("%d\n", cnt);
	for (int i = cnt2 - 1; i >= cnt1; i--)
	{
		printf("%lld ", ans[i]);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<string.h>

using namespace std;

typedef long long ll;

bool vis[1000000005];
ll ans[200005];

int main()
{
	int n, k, cnt = 0, cnt1 = 0, cnt2 = 0;
	ll t;
	scanf("%d %d", &n, &k);
	memset(vis, true, sizeof(vis));
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &t);
		if (vis[t])
		{
			if (cnt == k)
			{
				vis[ans[cnt1]] = true;
				++cnt1;
			}
			else
			{
				++cnt;
			}
			vis[t] = false;
			ans[cnt2++] = t;
		}
		else
		{
			continue;
		}
	}
	printf("%d\n", cnt);
	for (int i = cnt2 - 1; i >= cnt1; i--)
	{
		printf("%lld ", ans[i]);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<map>

using namespace std;

typedef long long ll;

map<ll, int>mp;
ll ans[205];

int main()
{
	int n, k, cnt = 0, cnt1 = 0, cnt2 = 0;
	ll t;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &t);
		if (mp.count(t) > 0)
		{
			continue;
		}
		else
		{
			if (cnt == k)
			{
				for (map<ll, int>::iterator it = mp.begin(); it != mp.end(); it++)
				{
					if (it->first == ans[cnt1])
					{
						mp.erase(it);
						break;
					}
				}
				++cnt1;
			}
			else
			{
				++cnt;
			}
			mp[t] = 1;
			ans[cnt2++] = t;
		}
	}
	printf("%d\n", cnt);
	for (int i = cnt2 - 1; i >= cnt1; i--)
	{
		printf("%lld ", ans[i]);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<string.h>

using namespace std;

typedef long long ll;

map<ll, int>mp;
bool vis[1000000005];
ll ans[200005];

int main()
{
	int n, k, cnt = 0, cnt1 = 0, cnt2 = 0;
	ll t;
	scanf("%d %d", &n, &k);
	memset(vis, true, sizeof(vis));
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &t);
		if (vis[t])
		{
			if (cnt == k)
			{
				vis[ans[cnt1]] = true;
				++cnt1;
			}
			else
			{
				++cnt;
			}
			vis[t] = false;
			ans[cnt2++] = t;
		}
		else
		{
			continue;
		}
	}
	printf("%d\n", cnt);
	for (int i = cnt2 - 1; i >= cnt1; i--)
	{
		printf("%lld ", ans[i]);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<map>

using namespace std;

typedef long long ll;

map<ll, int>mp;
ll ans[200005];

int main()
{
	int n, k, cnt = 0, cnt1 = 0, cnt2 = 0;
	ll t;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &t);
		if (mp.count(t) > 0)
		{
			continue;
		}
		else
		{
			if (cnt == k)
			{
				for (map<ll, int>::iterator it = mp.begin(); it != mp.end(); it++)
				{
					if (it->first == ans[cnt1])
					{
						mp.erase(it);
						break;
					}
				}
				++cnt1;
			}
			else
			{
				++cnt;
			}
			mp[t] = 1;
			ans[cnt2++] = t;
		}
	}
	printf("%d\n", cnt);
	for (int i = cnt2 - 1; i >= cnt1; i--)
	{
		printf("%lld ", ans[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

struct BIT
{
	vll v;
	BIT(ll n)
	{
		v.resize(n+1,0);
	}
	void update_BIT(ll index,ll n)
	{
		index++;
		while(index<v.size())
		{
			v[index]+=n;
			index+=index&(-index);
		}
	}
	ll get_sum(ll index)
	{
		ll sum=0;
		index++;
		while(index>0)
		{
		sum+=v[index];
		index-=index&(-index);
		}
		return sum;
	}
};

struct SegmentTree
{
	ll n;
	vll v;
	SegmentTree(ll size)
	{
		n=4*size+1;
		v.resize(n,0);
	}

	void build(ll ar[],ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]=ar[ipos];
		else
		{
		ll mid=(ipos+fpos)/2;
		build(ar,ipos,mid,pos*2);
		build(ar,mid+1,fpos,pos*2+1);
		v[pos]=v[pos*2]+v[pos*2+1];
		}
	}

	void update(ll index,ll val,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]+=val;
		else
		{
			v[pos]+=val;
			ll mid=(ipos+fpos)/2;
			if(mid>=index)
			update(index,val,ipos,mid,pos*2);
			else
			update(index,val,mid+1,fpos,pos*2+1);
		}

	}

	ll get_sum(ll l,ll r,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return 0;
		if(l>r)
		return 0;
		ll mid=(ipos+fpos)/2;
		if((l==ipos)&&(r==fpos))
		return v[pos];
		else return get_sum(l,min(mid,r),ipos,mid,pos*2)+get_sum(max(mid+1,l),r,mid+1,fpos,pos*2+1);

	}
};

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll b[n];
	input(b,n);
	vll a;
	a.pb(b[0]);
	rep(i,1,n-1,1)
	if(b[i]!=b[i-1])
	a.pb(b[i]);
	n=a.size();
	vll v;
	umll m;
	ll idx=0;
	rep(i,0,n-1,1)
	{
//		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(v.size()>=(k+idx))
		{
		m[v[idx]]=0;
		idx++;
		}
		v.pb(a[i]);
		m[a[i]]=1;
		}
	}
	cout<<(ll)v.size()-idx<<"\n";
	repb(i,(ll)v.size()-1,idx,1)
	cout<<v[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define vll                     vector<ll>
#define um                      unordered_map
#define umll                    um<ll,ll>

using namespace std;
int main()
{
	//fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	vll v;
	umll m;
	ll idx=0;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(v.size()>=(k+idx))
		{
		m[v[idx]]=0;
		idx++;
		}
		v.pb(a[i]);
		m[a[i]]=1;
		}
	}
	cout<<(ll)v.size()-idx<<"\n";
	repb(i,(ll)v.size()-1,idx,1)
	cout<<v[i]<<" ";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

void showq(queue <int> gq)
{
	stack<int> disp;
    queue <int> g = gq;
    while (!g.empty())
    {
    	disp.push(g.front());
        //cout<< g.front()<<" ";
        g.pop();
    }
    while(!disp.empty())
    {
    	cout<<disp.top()<<" ";
    	disp.pop();
	}
    cout << '\n';
}

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	queue<int> q;
	map<int,int> freq;
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
		if(freq[a[i]]==0) q.push(a[i]);
		freq[a[i]]++;
		if(q.size()>k)
		{
			freq[q.front()]=0;
			q.pop();
		}
	}
	cout<<q.size()<<endl;
	showq(q);
/*	int disp[q.size()+1];
	for(int i=0; i<q.size(); i++)
	{
		disp[i]=q.front();
		q.pop();
	}
	for(int i=q.size(); i>=0; i--)
	{
		cout<<disp[i]<<" ";
	}*/
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

struct BIT
{
	vll v;
	BIT(ll n)
	{
		v.resize(n+1,0);
	}
	void update_BIT(ll index,ll n)
	{
		index++;
		while(index<v.size())
		{
			v[index]+=n;
			index+=index&(-index);
		}
	}
	ll get_sum(ll index)
	{
		ll sum=0;
		index++;
		while(index>0)
		{
		sum+=v[index];
		index-=index&(-index);
		}
		return sum;
	}
};

struct SegmentTree
{
	ll n;
	vll v;
	SegmentTree(ll size)
	{
		n=4*size+1;
		v.resize(n,0);
	}

	void build(ll ar[],ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]=ar[ipos];
		else
		{
		ll mid=(ipos+fpos)/2;
		build(ar,ipos,mid,pos*2);
		build(ar,mid+1,fpos,pos*2+1);
		v[pos]=v[pos*2]+v[pos*2+1];
		}
	}

	void update(ll index,ll val,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]+=val;
		else
		{
			v[pos]+=val;
			ll mid=(ipos+fpos)/2;
			if(mid>=index)
			update(index,val,ipos,mid,pos*2);
			else
			update(index,val,mid+1,fpos,pos*2+1);
		}

	}

	ll get_sum(ll l,ll r,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return 0;
		if(l>r)
		return 0;
		ll mid=(ipos+fpos)/2;
		if((l==ipos)&&(r==fpos))
		return v[pos];
		else return get_sum(l,min(mid,r),ipos,mid,pos*2)+get_sum(max(mid+1,l),r,mid+1,fpos,pos*2+1);

	}
};

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	vll v;
	umll m;
	ll idx=0;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(v.size()>=k)
		{
		m[v[0]]=0;
	//	v.erase(v.begin()+0);
		idx++;
		}
		v.pb(a[i]);
		m[a[i]]=1;
		}
	}
	cout<<(ll)v.size()-idx<<"\n";
	repb(i,(ll)v.size()-1,idx,1)
	cout<<v[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	vll v;
	set<ll> s;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(s.find(a[i])==s.end())
		{
		if(v.size()>=k)
		{
		s.erase(v[0]);
		v.erase(v.begin()+0);
		}
		v.pb(a[i]);
		s.insert(a[i]);
		}
	}
	print(v.size());
	repb(i,(ll)v.size()-1,0,1)
	cout<<v[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

struct BIT
{
	vll v;
	BIT(ll n)
	{
		v.resize(n+1,0);
	}
	void update_BIT(ll index,ll n)
	{
		index++;
		while(index<v.size())
		{
			v[index]+=n;
			index+=index&(-index);
		}
	}
	ll get_sum(ll index)
	{
		ll sum=0;
		index++;
		while(index>0)
		{
		sum+=v[index];
		index-=index&(-index);
		}
		return sum;
	}
};

struct SegmentTree
{
	ll n;
	vll v;
	SegmentTree(ll size)
	{
		n=4*size+1;
		v.resize(n,0);
	}

	void build(ll ar[],ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]=ar[ipos];
		else
		{
		ll mid=(ipos+fpos)/2;
		build(ar,ipos,mid,pos*2);
		build(ar,mid+1,fpos,pos*2+1);
		v[pos]=v[pos*2]+v[pos*2+1];
		}
	}

	void update(ll index,ll val,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]+=val;
		else
		{
			v[pos]+=val;
			ll mid=(ipos+fpos)/2;
			if(mid>=index)
			update(index,val,ipos,mid,pos*2);
			else
			update(index,val,mid+1,fpos,pos*2+1);
		}

	}

	ll get_sum(ll l,ll r,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return 0;
		if(l>r)
		return 0;
		ll mid=(ipos+fpos)/2;
		if((l==ipos)&&(r==fpos))
		return v[pos];
		else return get_sum(l,min(mid,r),ipos,mid,pos*2)+get_sum(max(mid+1,l),r,mid+1,fpos,pos*2+1);

	}
};

vll v(200005);
using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	umll m;
	ll idx=0;
	ll t=-1;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(t>=(k+idx))
		{
		m[v[idx]]=0;
		idx++;
		}
		v[++t]=a[i];
	//	cout<<t<<" ";
		m[a[i]]=1;
		}
	}
//	db(t,idx);
	cout<<t+1-idx<<"\n";
	repb(i,t,idx,1)
	cout<<v[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vvll                    vector<vector<ll>>
#define pll                     pair<ll,ll>
#define all(x)                  x.begin(),x.end()
#define inf                     1e18
#define vvpll                   vector<vector<pair<ll,ll>>>
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define pqll                    priority_queue<ll>
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define umll                    unordered_map<ll,ll>
#define mll                     map<ll,ll>
#define input(a,n)              ll I;rep(I,0,n-1,1) cin>>a[I];
#define countbit                __builtin_popcount // Number of set bits .
#define fbo(k)                  find_by_order // K-th element in a set (counting from zero) .
#define ook(k)                  order_of_key //  Number of items strictly smaller than k .
#define lb                      lower_bound
#define up                      upper_bound
#define in                      insert
const long double pi=acos(-1);
ll pows(ll b,ll e){if(e==0)return 1;else if(e%2==0){ll a=pow(b,e/2);return a*a;}else {ll a=pow(b,e/2);return b*a*a;}}
ll gcd(ll a,ll b){if(a<b)return gcd(b,a);else if(b==0)return a;else return gcd(b,a%b);}
ll isPrime(ll n){ll p=(ll)sqrt(n);rep(i,2,p,1) if(n%i==0) return 0;return 1;}// reuturn 1 if prime
unsigned ll powm(ll x,unsigned ll y,ll m=MOD){x=x%m;unsigned ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll lcm(ll a,ll b){ return (a*b)/gcd(a,b);}
ll modInverse(ll a, ll m) { return powm(a, m-2, m);}
bool issq(ll n){ ll p=sqrt(n);return p*p==n;}
//#define db(x) cout <<#x<<": "<<x<<'\n';
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
vll prime;// if i==prime[i] then prime otherwise smallest prime factor of that number
void seive(ll n)
{
    prime.resize(n+1,1);
    prime[0] = 0, prime[1] = 0;
    for (ll i = 2; i*i <= n; i++)
        if (prime[i])
            for (ll j = i * i; j <= n; j += i)
                prime[j] = 0;
}
ll extended_GCD(ll a ,ll b ,ll &x ,ll &y){
    if(a == 0){
        x = 0;
        y = 1;
        return b;
    }
    ll x1 , y1;
    ll gcd = extended_GCD(b%a , a , x1 , y1);
    x = y1 - (b/a)*x1;
    y = x1;
    return gcd;
}
    ll mulInv(ll a , ll mod=26){
    ll x , y;
    extended_GCD(a , mod , x , y);
    if(x < 0) x += mod;
    return x;
}
ll find(ll num[], ll rem[], ll k,ll prod)
{
    // Compute product of all numbers
    ll result = 0;
    // Apply above formula
    for (ll i = 0; i < k; i++)
    {
        ll pp = prod / num[i];
        result += rem[i] * mulInv(pp, num[i]) * pp;
    }
    return result % prod;
}
ll nCr(ll n,ll k)
{
  ll res = 1;

      // Since C(n, k) = C(n, n-k)
      if ( k > n - k )
          k = n - k;

      // Calculate value of
      // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
      for (ll i = 0; i < k; ++i)
      {
          res *= (n - i);
          res /= (i + 1);
      }

      return res;
}
class DSU
{
 public:vll parent,size;
public: DSU(ll n)
{

        parent.resize(n+1);size.resize(n+1);
        for(ll i=1;i<=n;i++)
            {
              parent[i]=i;
              size[i]=1;
            }
    }
public:ll find_set(ll x)
    {
      if(parent[x]==x)
      {
        return x;
      }
      return parent[x]=find_set(parent[x]);
    }
public:void union_set(ll x,ll y)
    {
        x=find_set(x);y=find_set(y);
        if(x!=y)
        {
          if(size[x]<size[y])
          {
            swap(x,y);
          }
          parent[y]=x;
          size[x]+=size[y];
        }
}
};
bool cmp(pair<ll,ll>&p1,pair<ll,ll>&p2)
{
  if(p1.fi-p1.se>0&&p2.fi-p2.se>0)
  {
    return p1.fi-p1.se>p2.fi-p2.se;
  }
  return abs(p1.fi-p1.se)<abs(p2.fi-p2.se);
}
bool isPalindrome(string s)
{
  ll i,j;
  for(i=0,j=s.length()-1;i<=j;i++,j--)
  {
    if(s[i]!=s[j])
    {
      return 0;
    }
  }
return 1;
}
ll ToInt(char ch)
{
  return ch-'0';
}
char ToChar(ll a)
{
  return a+'0';
}
bool isSubSeq(string str1, string str2, ll m, ll n)
{
    // Base Cases
    if (m == 0) return true;
    if (n == 0) return false;
    // If last characters of two strings are matching
    if (str1[m-1] == str2[n-1])
        return isSubSeq(str1, str2, m-1, n-1);
    // If last characters are not matching
    return isSubSeq(str1, str2, m, n-1);
}
void printVectorPair(vpll v)
{
  for(ll i=0;i<v.size();i++)
  {
    cout<<v[i].fi<<" "<<v[i].se<<"\n";
  }
}
void modBigNumber(string num, ll m)
{
    // Store the modulus of big number
    vector<int> vec;
    ll mod = 0;
    // Do step by step division
    for (int i = 0; i < num.size(); i++) {
        int digit = num[i] - '0';
        mod = mod * 10 + digit;
        int quo = mod / m;
        if((vec.size()!=0)||(quo!=0))        //to remove initiale zeros
        vec.push_back(quo);
        mod = mod % m;
    }
   // cout << "\nRemainder : " << mod << "\n";
   // cout << "Quotient : ";rep(i,0,vec.size()-1,1)cout<<vec[i];cout<<"\n";
    return;
}
struct BIT
{
vector<ll>bitree;ll n;
BIT(ll n)
{
this->n=n;
bitree.resize(n+1,0);
}
void update(ll idx,ll val)
{
  idx++;
  while(idx<=n)
  {
    bitree[idx]+=val;
    idx+=idx&(-idx);
  }
}
ll Sum(ll idx)
{
  ll sum=0;
  idx++;
  while(idx>0)
  {
    sum+=bitree[idx];
    idx-=idx&(-idx);
  }
  return sum;
}
};
struct SegmentTree
{
	ll n;
	vll v;
	SegmentTree(ll size)
	{
		n=4*size+1;
		v.resize(n,0);
	}

	void build(ll ar[],ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]=ar[ipos];
		else
		{
		ll mid=(ipos+fpos)/2;
		build(ar,ipos,mid,pos*2);
		build(ar,mid+1,fpos,pos*2+1);
		v[pos]=v[pos*2]+v[pos*2+1];
		}
	}
	void update(ll index,ll val,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]+=val;
		else
		{
			v[pos]+=val;
			ll mid=(ipos+fpos)/2;
			if(mid>=index)
			update(index,val,ipos,mid,pos*2);
			else
			update(index,val,mid+1,fpos,pos*2+1);
		}
	}
	ll get_sum(ll l,ll r,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return 0;
		if(l>r)
		return 0;
		ll mid=(ipos+fpos)/2;
		if((l==ipos)&&(r==fpos))
		return v[pos];
		else return get_sum(l,min(mid,r),ipos,mid,pos*2)+get_sum(max(mid+1,l),r,mid+1,fpos,pos*2+1);
	}
};
struct Dijkstra
{
vll p,dis;
ll n;
vll check;
Dijkstra(vvpll adj,ll size)
{
	n=size;
	p.resize(n+1,-1);
	dis.resize(n+1,inf);
	check.resize(n+1,0);
}
void build(ll s,vvpll adj)
{
	dis[s]=0;
//	db(n);
    set<pair<ll,ll>> q;
    q.insert({0,s});
	while(!q.empty())
	{
		ll v=q.begin()->se;
		q.erase(q.begin());
		for(auto i:adj[v])
		{
			if(dis[i.fi]>dis[v]+i.se)
			{
			q.erase({dis[i.fi],i.fi});
			dis[i.fi]=dis[v]+i.se;
			p[i.fi]=v;
			q.insert({dis[v]+i.se,i.fi});
			}
		}
	}
}
vll get_path(ll s,ll v)
{
	vll path;
	ll i;
	for(i=v;p[i]!=-1;i=p[i])
	path.pb(i);
	path.pb(i);
	reverse(path.begin(),path.end());
	return path;
}
};
ll sumofdigits(ll a)
{
	ll val=0;
	while(a>0)
	{
		val+=a%10;
		a/=10;
	}
	return val;
}
int main()
{
fastIO
  ll n,m,i,j,k,x,y,z,f,p,q,g,l,r,w,h,sum=0,sum1=0,sum2=0,prod=1,a,b,c,d,index,x1,x2,ans=0,count=0,count1=0,flag=0,flag1=0,flag2=0;string s,s1,s3;
cin>>n>>k;
ll ar[n];
umll m1;
for(i=0;i<n;i++)
{
  cin>>ar[i];
}
vll v;
umll m2;
ll curr=0;
for(i=0;i<n;i++)
{
  if(m1[ar[i]]>=1)
  {
    continue;
  }
  else
  {
    if(i>=k)
    {
    m2[curr]=1;
    m1[v[curr]]=0;
    if(m1[v[curr]]==0)
    {
      m1.erase(v[curr]);
    }
    curr++;
    v.pb(ar[i]);
    m1[ar[i]]++;
    }
    else
    {
      v.pb(ar[i]);
      m1[ar[i]]++;
    }
  }
}
vll v2;
for(i=0;i<v.size();i++)
{
  if(m2[i]!=1)
  {
    v2.pb(v[i]);
  }
}
cout<<v2.size()<<"\n";
for(i=v2.size()-1;i>=0;i--)
{
cout<<v2[i]<<" ";
}
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

struct BIT
{
	vll v;
	BIT(ll n)
	{
		v.resize(n+1,0);
	}
	void update_BIT(ll index,ll n)
	{
		index++;
		while(index<v.size())
		{
			v[index]+=n;
			index+=index&(-index);
		}
	}
	ll get_sum(ll index)
	{
		ll sum=0;
		index++;
		while(index>0)
		{
		sum+=v[index];
		index-=index&(-index);
		}
		return sum;
	}
};

struct SegmentTree
{
	ll n;
	vll v;
	SegmentTree(ll size)
	{
		n=4*size+1;
		v.resize(n,0);
	}

	void build(ll ar[],ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]=ar[ipos];
		else
		{
		ll mid=(ipos+fpos)/2;
		build(ar,ipos,mid,pos*2);
		build(ar,mid+1,fpos,pos*2+1);
		v[pos]=v[pos*2]+v[pos*2+1];
		}
	}

	void update(ll index,ll val,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]+=val;
		else
		{
			v[pos]+=val;
			ll mid=(ipos+fpos)/2;
			if(mid>=index)
			update(index,val,ipos,mid,pos*2);
			else
			update(index,val,mid+1,fpos,pos*2+1);
		}

	}

	ll get_sum(ll l,ll r,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return 0;
		if(l>r)
		return 0;
		ll mid=(ipos+fpos)/2;
		if((l==ipos)&&(r==fpos))
		return v[pos];
		else return get_sum(l,min(mid,r),ipos,mid,pos*2)+get_sum(max(mid+1,l),r,mid+1,fpos,pos*2+1);

	}
};

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	queue<ll> v;
	umll m;
	ll idx=0;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(v.size()>=k)
		{
		m[v.front()]=0;
		v.pop();
		idx++;
		}
		v.push(a[i]);
		m[a[i]]=1;
		}
	}
	ll size=v.size();
	vll vv;
	cout<<(ll)v.size()<<"\n";
	repb(i,size-1,0,1)
	{
	ll val=v.front();
	vv.pb(val);
	v.pop();
	}
	repb(i,(ll)vv.size()-1,0,1)
	cout<<vv[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	vll v;
	umll m;
	ll idx=0,size=0;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(size>=(k+idx))
		{
		m[v[idx]]=0;
		idx++;
		}
		v.pb(a[i]);
		size++;
		m[a[i]]=1;
		}
	}
	cout<<size-idx<<"\n";
	repb(i,size-1,idx,1)
	cout<<v[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	vll v;
	umll m;
	ll idx=0,size=0;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(size>=(k+idx))
		{
		m[v[idx]]=0;
		idx++;
		}
		v.pb(a[i]);
		size++;
		m[a[i]]++;
		}
	}
	cout<<size-idx<<"\n";
	repb(i,size-1,idx,1)
	cout<<v[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

struct BIT
{
	vll v;
	BIT(ll n)
	{
		v.resize(n+1,0);
	}
	void update_BIT(ll index,ll n)
	{
		index++;
		while(index<v.size())
		{
			v[index]+=n;
			index+=index&(-index);
		}
	}
	ll get_sum(ll index)
	{
		ll sum=0;
		index++;
		while(index>0)
		{
		sum+=v[index];
		index-=index&(-index);
		}
		return sum;
	}
};

struct SegmentTree
{
	ll n;
	vll v;
	SegmentTree(ll size)
	{
		n=4*size+1;
		v.resize(n,0);
	}

	void build(ll ar[],ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]=ar[ipos];
		else
		{
		ll mid=(ipos+fpos)/2;
		build(ar,ipos,mid,pos*2);
		build(ar,mid+1,fpos,pos*2+1);
		v[pos]=v[pos*2]+v[pos*2+1];
		}
	}

	void update(ll index,ll val,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]+=val;
		else
		{
			v[pos]+=val;
			ll mid=(ipos+fpos)/2;
			if(mid>=index)
			update(index,val,ipos,mid,pos*2);
			else
			update(index,val,mid+1,fpos,pos*2+1);
		}

	}

	ll get_sum(ll l,ll r,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return 0;
		if(l>r)
		return 0;
		ll mid=(ipos+fpos)/2;
		if((l==ipos)&&(r==fpos))
		return v[pos];
		else return get_sum(l,min(mid,r),ipos,mid,pos*2)+get_sum(max(mid+1,l),r,mid+1,fpos,pos*2+1);

	}
};

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	vll v;
	umll m;
	ll idx=0;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(v.size()>=(k+idx))
		{
		m[v[idx]]=0;
		idx++;
		}
		v.pb(a[i]);
		m[a[i]]=1;
		}
	}
	cout<<(ll)v.size()-idx<<"\n";
	repb(i,(ll)v.size()-1,idx,1)
	cout<<v[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

struct BIT
{
	vll v;
	BIT(ll n)
	{
		v.resize(n+1,0);
	}
	void update_BIT(ll index,ll n)
	{
		index++;
		while(index<v.size())
		{
			v[index]+=n;
			index+=index&(-index);
		}
	}
	ll get_sum(ll index)
	{
		ll sum=0;
		index++;
		while(index>0)
		{
		sum+=v[index];
		index-=index&(-index);
		}
		return sum;
	}
};

struct SegmentTree
{
	ll n;
	vll v;
	SegmentTree(ll size)
	{
		n=4*size+1;
		v.resize(n,0);
	}

	void build(ll ar[],ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]=ar[ipos];
		else
		{
		ll mid=(ipos+fpos)/2;
		build(ar,ipos,mid,pos*2);
		build(ar,mid+1,fpos,pos*2+1);
		v[pos]=v[pos*2]+v[pos*2+1];
		}
	}

	void update(ll index,ll val,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]+=val;
		else
		{
			v[pos]+=val;
			ll mid=(ipos+fpos)/2;
			if(mid>=index)
			update(index,val,ipos,mid,pos*2);
			else
			update(index,val,mid+1,fpos,pos*2+1);
		}

	}

	ll get_sum(ll l,ll r,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return 0;
		if(l>r)
		return 0;
		ll mid=(ipos+fpos)/2;
		if((l==ipos)&&(r==fpos))
		return v[pos];
		else return get_sum(l,min(mid,r),ipos,mid,pos*2)+get_sum(max(mid+1,l),r,mid+1,fpos,pos*2+1);

	}
};

vll v(200005);
using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	umll m;
	ll idx=0;
	ll t=-1;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(t+1>=(k+idx))
		{
		m[v[idx]]=0;
		idx++;
		}
		v[++t]=a[i];
	//	cout<<t<<" ";
		m[a[i]]=1;
		}
	}
//	db(t,idx);
	cout<<t+1-idx<<"\n";
	repb(i,t,idx,1)
	cout<<v[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

struct BIT
{
	vll v;
	BIT(ll n)
	{
		v.resize(n+1,0);
	}
	void update_BIT(ll index,ll n)
	{
		index++;
		while(index<v.size())
		{
			v[index]+=n;
			index+=index&(-index);
		}
	}
	ll get_sum(ll index)
	{
		ll sum=0;
		index++;
		while(index>0)
		{
		sum+=v[index];
		index-=index&(-index);
		}
		return sum;
	}
};

struct SegmentTree
{
	ll n;
	vll v;
	SegmentTree(ll size)
	{
		n=4*size+1;
		v.resize(n,0);
	}

	void build(ll ar[],ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]=ar[ipos];
		else
		{
		ll mid=(ipos+fpos)/2;
		build(ar,ipos,mid,pos*2);
		build(ar,mid+1,fpos,pos*2+1);
		v[pos]=v[pos*2]+v[pos*2+1];
		}
	}

	void update(ll index,ll val,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]+=val;
		else
		{
			v[pos]+=val;
			ll mid=(ipos+fpos)/2;
			if(mid>=index)
			update(index,val,ipos,mid,pos*2);
			else
			update(index,val,mid+1,fpos,pos*2+1);
		}

	}

	ll get_sum(ll l,ll r,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return 0;
		if(l>r)
		return 0;
		ll mid=(ipos+fpos)/2;
		if((l==ipos)&&(r==fpos))
		return v[pos];
		else return get_sum(l,min(mid,r),ipos,mid,pos*2)+get_sum(max(mid+1,l),r,mid+1,fpos,pos*2+1);

	}
};

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	vll v;
	umll m;
	ll idx=0,size=0;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(size>=(k+idx))
		{
		m[v[idx]]=0;
		idx++;
		}
		v.pb(a[i]);
		size++;
		m[a[i]]=1;
		}
	}
	cout<<size-idx<<"\n";
	repb(i,size-1,idx,1)
	cout<<v[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	vll v;
	umll m;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(v.size()>=k)
		{
		m[v[0]]=0;
		v.erase(v.begin()+0);
		}
		v.pb(a[i]);
		m[a[i]]=1;
		}
	}
	print(v.size());
	repb(i,(ll)v.size()-1,0,1)
	cout<<v[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	queue<ll> v;
	umll m;
	ll size=0;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(size>=k)
		{
		m[v.front()]=0;
		v.pop();
		size--;
		}
		v.push(a[i]);
		size++;
		m[a[i]]=1;
		}
	}
	cout<<size<<"\n";
	vll ans;
	while(!v.empty())
	{
		ans.pb(v.front());
		v.pop();
	}
	repb(i,size-1,0,1)
	cout<<ans[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	queue<ll> v;
	set<ll> m;
	ll size=0;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m.find(a[i])==m.end())
		{
		if(size>=k)
		{
		m.erase(v.front());
		v.pop();
		size--;
		}
		v.push(a[i]);
		size++;
		m.insert(a[i]);
		}
	}
	cout<<size<<"\n";
	vll ans;
	while(!v.empty())
	{
		ans.pb(v.front());
		v.pop();
	}
	repb(i,size-1,0,1)
	cout<<ans[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

struct BIT
{
	vll v;
	BIT(ll n)
	{
		v.resize(n+1,0);
	}
	void update_BIT(ll index,ll n)
	{
		index++;
		while(index<v.size())
		{
			v[index]+=n;
			index+=index&(-index);
		}
	}
	ll get_sum(ll index)
	{
		ll sum=0;
		index++;
		while(index>0)
		{
		sum+=v[index];
		index-=index&(-index);
		}
		return sum;
	}
};

struct SegmentTree
{
	ll n;
	vll v;
	SegmentTree(ll size)
	{
		n=4*size+1;
		v.resize(n,0);
	}

	void build(ll ar[],ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]=ar[ipos];
		else
		{
		ll mid=(ipos+fpos)/2;
		build(ar,ipos,mid,pos*2);
		build(ar,mid+1,fpos,pos*2+1);
		v[pos]=v[pos*2]+v[pos*2+1];
		}
	}

	void update(ll index,ll val,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return ;
		if(ipos==fpos)
		v[pos]+=val;
		else
		{
			v[pos]+=val;
			ll mid=(ipos+fpos)/2;
			if(mid>=index)
			update(index,val,ipos,mid,pos*2);
			else
			update(index,val,mid+1,fpos,pos*2+1);
		}

	}

	ll get_sum(ll l,ll r,ll ipos,ll fpos,ll pos=1)
	{
		if(ipos>fpos)
		return 0;
		if(l>r)
		return 0;
		ll mid=(ipos+fpos)/2;
		if((l==ipos)&&(r==fpos))
		return v[pos];
		else return get_sum(l,min(mid,r),ipos,mid,pos*2)+get_sum(max(mid+1,l),r,mid+1,fpos,pos*2+1);

	}
};

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	vll v;
	umll m;
	ll idx=0,size=0;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(size>=(k+idx))
		{
		m[v[idx]]=0;
		idx++;
		}
		v.pb(a[i]);
		size++;
		m[a[i]]=1;
		}
	}
	cout<<size-idx<<"\n";
	repb(i,size-1,idx,1)
	cout<<v[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     1e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define print(a)                cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,val)               lower_bound(all(v),val)-v.begin()
#define ub(v,val)               upper_bound(all(v),val)-v.begin()
#define SS                      stringstream
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

using namespace std;
int main()
{
	fastIO
	ll n,k;
	cin>>n>>k;
	ll a[n];
	vll v;
	umll m;
	ll idx=0;
	rep(i,0,n-1,1)
	{
		cin>>a[i];
		if(m[a[i]]==0)
		{
		if(v.size()>=k)
		{
		m[v[0]]=0;
	//	v.erase(v.begin()+0);
		idx++;
		}
		v.pb(a[i]);
		m[a[i]]=1;
		}
	}
	print(v.size());
	repb(i,(ll)v.size()-1,idx,1)
	cout<<v[i]<<" ";
	return 0;
}