import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    while(n-->0)
    {
      int l = s.nextInt();
      int r = s.nextInt();
      int d = s.nextInt();
      if(d<l){
          System.out.println(d);
      }
      else{
          System.out.println(d*((r/d)+1));
      }
    }
  }
}


import java.util.Arrays;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;

import java.math.*;

public class Sec4 {

	public static void main(String[] args) {
		Scanner read = new Scanner (System.in);

	int m ;
	m = read.nextInt();
	int sol [];
	sol = new int[m];
	for (int i=0;i<m;i++)
	{
		int l,r,d;
		l=read.nextInt();
		r=read.nextInt();
		d=read.nextInt();
		int j = d ;
		sol[i]=0;
		while (sol[i]==0)
		{
			if (j>=l&&j<r)
			{
				j=r-(r%d)+d;
			}
			if (j%d==0&&(j<l||j>r))
			{
				sol[i]=j;
			}else
			{
				j+=d;
			}
		}
	}
	for (int i=0;i<m;i++)
	{
		System.out.println(sol[i]);
	}

}}


import java.util.Arrays;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;

import java.math.*;

public class Sec4 {

	public static void main(String[] args) {
		Scanner read = new Scanner (System.in);

	int m ;
	m = read.nextInt();
	int sol [];
	sol = new int[m];
	for (int i=0;i<m;i++)
	{
		int l,r,d;
		l=read.nextInt();
		r=read.nextInt();
		d=read.nextInt();
		int j = d ;
		sol[i]=0;
		while (sol[i]==0)
		{
			if (j%d==0&&(j<l||j>r))
			{
				sol[i]=j;
			}else
			{
				j+=d;
			}
		}
	}
	for (int i=0;i<m;i++)
	{
		System.out.println(sol[i]);
	}

}}


import java.io.*;
import java.util.*;

public class ProgEc {

	public static void main(String[] args) throws Exception {
		//FileInputStream inputStream = new FileInputStream("input.txt");
		//FileOutputStream outputStream = new FileOutputStream("output.txt");

		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;

		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);

		Solver solver = new Solver();
		solver.solve(1, in, out);

		out.close();
	}

	static class Solver {

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			for (int i = 0; i < n; i++) {
				long l = in.nextLong();
				long r = in.nextLong();
				long d = in.nextLong();

				if (d < l || d > r) { out. println(d); continue; }
				long k = r/d;
				out.println(d*(k+1));

			}
		}

	}

	static class InputReader {

		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while(tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException (e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public float nextFloat() {
			return Float.parseFloat(next());
		}
	}
}


import java.io.*;
import java.util.*;

public class ProgEc {

	public static void main(String[] args) throws Exception {
		//FileInputStream inputStream = new FileInputStream("input.txt");
		//FileOutputStream outputStream = new FileOutputStream("output.txt");

		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;

		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);

		Solver solver = new Solver();
		solver.solve(1, in, out);

		out.close();
	}

	static class Solver {

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			for (int i = 0; i < n; i++) {
				long l = in.nextLong();
				long r = in.nextLong();
				long d = in.nextLong();

				if (d < l || d > r) { out.println(d); continue; }
				for (int j = 2; j <= 10000; j++) {
					d *= j;
					if (d > r) break; else d /= j;
				}
				if (d == 1 && l == 1) out.println(r+1); else
					if (d == 1 && l != 1) out.println(1); else out.println(d);
			}
		}

	}

	static class InputReader {

		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while(tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException (e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public float nextFloat() {
			return Float.parseFloat(next());
		}
	}
}


import java.io.*;
import java.util.*;

public class ProgEc {

	public static void main(String[] args) throws Exception {
		//FileInputStream inputStream = new FileInputStream("input.txt");
		//FileOutputStream outputStream = new FileOutputStream("output.txt");

		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;

		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);

		Solver solver = new Solver();
		solver.solve(1, in, out);

		out.close();
	}

	static class Solver {

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			for (int i = 0; i < n; i++) {
				long l = in.nextLong();
				long r = in.nextLong();
				long d = in.nextLong();

				if (d < l || d > r) { out.println(d); continue; }
				for (int j = 2; j <= 100000; j++) {
					d *= j;
					if (d > r) break; else d /= j;
				}
				if (d == 1 && l == 1) out.println(r+1); else
					if (d == 1 && l != 1) out.println(1); else out.println(d);
			}
		}

	}

	static class InputReader {

		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while(tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException (e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public float nextFloat() {
			return Float.parseFloat(next());
		}
	}
}


import java.io.*;
import java.util.*;

public class ProgEc {

	public static void main(String[] args) throws Exception {
		//FileInputStream inputStream = new FileInputStream("input.txt");
		//FileOutputStream outputStream = new FileOutputStream("output.txt");

		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;

		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);

		Solver solver = new Solver();
		solver.solve(1, in, out);

		out.close();
	}

	static class Solver {

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			for (int i = 0; i < n; i++) {
				long l = in.nextLong();
				long r = in.nextLong();
				long d = in.nextLong();

				if (d < l || d > r) { out.println(d); continue; }
				for (int j = 2; j < 100000; j++) {
					d *= j;
					if (d > r) break; else d /= j;
				}
				out.println(d);
			}
		}

	}

	static class InputReader {

		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while(tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException (e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public float nextFloat() {
			return Float.parseFloat(next());
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class codeforces
{
	public static void main( String[] args ) throws IOException
	{
		Reader.init(System.in);
		int query = Reader.nextInt();
		for( int q =0 ; q < query ; q++ )
		{
			long l = Reader.nextLong();
			long r = Reader.nextLong();
			long d = Reader.nextLong();
			long res = 0;
			boolean flag = false;
			for ( int i = 1 ; i < l ; i++ )
			{
				if ( i%d ==0 )
				{
					res = i;
					flag = true;
					break;
				}
			}
			if( res == 0 )
			{
				for (long j = r+1 ; j < Integer.MAX_VALUE ; j++ )
				{
					if ( j%d == 0 )
					{
						res = j;
						break;
					}
				}
			}
			System.out.println(res);
		}
	}
}

class Reader
{
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input)
    {
        reader = new BufferedReader(new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException
    {
        while ( ! tokenizer.hasMoreTokens() )
        {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException
    {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException
    {
        return Double.parseDouble( next() );
    }

    static long nextLong() throws IOException
    {
        return Long.parseLong( next() );
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class codeforces
{
	public static void main( String[] args ) throws IOException
	{
		Reader.init(System.in);
		int query = Reader.nextInt();
		for( int q =0 ; q < query ; q++ )
		{
			long l = Reader.nextLong();
			long r = Reader.nextLong();
			long d = Reader.nextLong();
			long res = 0;
			if ( d == 1 && l != 1 )
			{
				System.out.println(1);
			}
			else if ( d < l || d > r)
			{
				System.out.println(d);
			}
			else
			{
				long r1 = ((r/d)+1)*d;
				System.out.println(r1);
			}
		}
	}
}

class Reader
{
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input)
    {
        reader = new BufferedReader(new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException
    {
        while ( ! tokenizer.hasMoreTokens() )
        {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException
    {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException
    {
        return Double.parseDouble( next() );
    }

    static long nextLong() throws IOException
    {
        return Long.parseLong( next() );
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class codeforces
{
	public static void main( String[] args ) throws IOException
	{
		Reader.init(System.in);
		int query = Reader.nextInt();
		for( int q =0 ; q < query ; q++ )
		{
			long l = Reader.nextLong();
			long r = Reader.nextLong();
			long d = Reader.nextLong();
			long res = 0;
			if ( d == 1 && l != 1 )
			{
				System.out.println(1);
			}
			else if ( d < l || d > r)
			{
				System.out.println(d);
			}
			else
			{
				//long r1 = ((r/d)+1)*d;
				long r1 = (r-(r%d))+d;
				System.out.println(r1);
			}
		}
	}
}

class Reader
{
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input)
    {
        reader = new BufferedReader(new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException
    {
        while ( ! tokenizer.hasMoreTokens() )
        {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException
    {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException
    {
        return Double.parseDouble( next() );
    }

    static long nextLong() throws IOException
    {
        return Long.parseLong( next() );
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class codeforces
{
	public static void main( String[] args ) throws IOException
	{
		Reader.init(System.in);
		int query = Reader.nextInt();
		for( int q =0 ; q < query ; q++ )
		{
			long l = Reader.nextLong();
			long r = Reader.nextLong();
			long d = Reader.nextLong();
			long res = 0;
			if ( d == 1 )
			{
				System.out.println(1);
			}
			else if ( d > r || d < l )
			{
				System.out.println(d);
			}
			else
			{
				long r1 = ((r/d)+1)*d;
				System.out.println(r1);
			}
		}
	}
}

class Reader
{
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input)
    {
        reader = new BufferedReader(new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException
    {
        while ( ! tokenizer.hasMoreTokens() )
        {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException
    {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException
    {
        return Double.parseDouble( next() );
    }

    static long nextLong() throws IOException
    {
        return Long.parseLong( next() );
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class codeforces
{
	public static void main( String[] args ) throws IOException
	{
		Reader.init(System.in);
		int query = Reader.nextInt();
		for( int q =0 ; q < query ; q++ )
		{
			long l = Reader.nextLong();
			long r = Reader.nextLong();
			long d = Reader.nextLong();
			long res = 0;
			if ( d == 1 )
			{
				System.out.println(1);
			}
			else if ( d > r || d < l )
			{
				System.out.println(d);
			}
			else
			{
				long r1 = r-(r%d)+d;
				long r2 = l-(l%d)-d;
				/*if ( r2 > 0 )
				{
					res = r2;
				}
				else
				{
					res = r1;
				}*/
				System.out.println(r1);
			}
		}
	}
}

class Reader
{
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input)
    {
        reader = new BufferedReader(new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException
    {
        while ( ! tokenizer.hasMoreTokens() )
        {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException
    {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException
    {
        return Double.parseDouble( next() );
    }

    static long nextLong() throws IOException
    {
        return Long.parseLong( next() );
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class codeforces
{
	public static void main( String[] args ) throws IOException
	{
		Reader.init(System.in);
		int query = Reader.nextInt();
		for( int q =0 ; q < query ; q++ )
		{
			long l = Reader.nextLong();
			long r = Reader.nextLong();
			long d = Reader.nextLong();
			long res = 0;
			if ( d == 1 )
			{
				System.out.println(1);
			}
			else if ( d > r || d < l )
			{
				System.out.println(d);
			}
			else
			{
				long r1 = (r-(r%d))+d;
				System.out.println(r1);
			}
		}
	}
}

class Reader
{
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input)
    {
        reader = new BufferedReader(new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException
    {
        while ( ! tokenizer.hasMoreTokens() )
        {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException
    {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException
    {
        return Double.parseDouble( next() );
    }

    static long nextLong() throws IOException
    {
        return Long.parseLong( next() );
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class codeforces
{
	public static void main( String[] args ) throws IOException
	{
		Reader.init(System.in);
		int query = Reader.nextInt();
		for( int q =0 ; q < query ; q++ )
		{
			long l = Reader.nextLong();
			long r = Reader.nextLong();
			long d = Reader.nextLong();
			long res = 0;
			if ( d == 1 )
			{
				System.out.println(1);
			}
			else if ( d > r || d < l )
			{
				System.out.println(d);
			}
			else
			{
				long r1 = r-(r%d)+d;
				long r2 = l-(l%d)-d;
				if ( r2 > 0 )
				{
					res = r2;
				}
				else
				{
					res = r1;
				}
				System.out.println(res);
			}
		}
	}
}

class Reader
{
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input)
    {
        reader = new BufferedReader(new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException
    {
        while ( ! tokenizer.hasMoreTokens() )
        {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException
    {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException
    {
        return Double.parseDouble( next() );
    }

    static long nextLong() throws IOException
    {
        return Long.parseLong( next() );
    }
}


package ECR58;

import java.util.Scanner;
import java.io.PrintWriter;

public class AMinimumInteger {
    public void solve(int testNumber, Scanner in, PrintWriter out) {
        int tc = in.nextInt();
        while(tc-- > 0) {
            int l = in.nextInt();
            int r = in.nextInt();
            int d = in.nextInt();

//            if(d < l || d > r) {
//                System.out.println(d);
//                continue;
//            }
//
//            System.out.println(d*((r%d)+1));

            if (d < l || d > r) {
                System.out.println(d);
                continue;
            }

            //System.out.println("r%d:" + r / d);

            System.out.println(d * ((r / d) + 1));
        }
    }
}


import java.util.Scanner;

public class Solution1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int l = 0,r = 0, d= 0;
        for(int i = 0; i < n; i++){
            l = in.nextInt();
            r = in.nextInt();
            d = in.nextInt();
            if(d < l || d > r){
                System.out.println(d);
                continue;
            }
            int sum = d;
            while(sum <= r){
                sum += d;
            }
            System.out.println(sum);
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vinrar
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AMinimumInteger solver = new AMinimumInteger();
        solver.solve(1, in, out);
        out.close();
    }

    static class AMinimumInteger {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int tc = in.nextInt();
            while (tc-- > 0) {
                int l = in.nextInt();
                int r = in.nextInt();
                int d = in.nextInt();

                if (d < l || d > r) {
                    System.out.println(d);
                } else {
                    System.out.println(d * ((r / d) + 1));
                }
            }
        }

    }
}


import java.util.Scanner;

public class MinimumInteger {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int wh = sc.nextInt();

        while(wh > 0) {
            int li = sc.nextInt(), ri = sc.nextInt(), div = sc.nextInt();
            if(li > div || ri < div) {
                System.out.println(div);
                wh--;
                continue;
            }

            System.out.println(div * (ri/div + 1));
            wh--;
        }
    }
}


import java.util.Scanner;

public class MinimumInteger {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int wh = sc.nextInt();

        while(wh > 0) {
            int li = sc.nextInt(), ri = sc.nextInt(), div = sc.nextInt();
            if(li > div || ri < div) {
                System.out.println(div);
                wh--;
                continue;
            }
            if(ri % div == 0) {
                System.out.println(div * (ri/div + 1));
            } else System.out.println(div * (ri % div + 1));
            wh--;
        }
    }
}


import java.util.*;
public class MI
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int q=sc.nextInt();

		while(q-->0)
		{
			int f=0;
			long r1=sc.nextLong();
			long r2=sc.nextLong();
			long n=sc.nextLong();
			if(n<r1 || r2<n)
			System.out.println(n);
			else
			{
			for(long i=1;i<r1;i++)
			{
				if(i%n==0)
				{
				    System.out.println(i);
				    f=1;
				    break;
				}
			}
			for(long i=r2+1;i<=1000000000 && f==0;i++)
			{
				if(i%n==0)
				{
				    System.out.println(i);
				    break;
				}
			}

}
		}

}
}


import java.util.*;
public class MI
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int q=sc.nextInt();

		while(q-->0)
		{
			int f=0;
			long r1=sc.nextLong();
			long r2=sc.nextLong();
			long n=sc.nextLong();
			for(long i=1;i<r1;i++)
			{
				if(i%n==0)
				{
				    System.out.println(i);
				    f=1;
				    break;
				}
			}
			for(long i=r2+1;i<1000000000 && f==0;i++)
			{
				if(i%n==0)
				{
				    System.out.println(i);
				    break;
				}
			}

		}

}
}


import java.util.*;
public class MI
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int q=sc.nextInt();

		while(q-->0)
		{
			int f=0;
			long r1=sc.nextLong();
			long r2=sc.nextLong();
			long n=sc.nextLong();
			if(n<r1 || r2<n)
			System.out.println(n);
			else
			{
			long t=r2%n;
			t=n-t;
			System.out.println(r2+t);
			}
		}

}
}


import java.util.*;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

public class Sample {
    public static void main(String[] args) throws Exception {
        FastScanner f = new FastScanner(System.in);
        int T = f.nextInt();
        while (T-- > 0) {
            // int N = f.nextInt();
            // int[] a = f.nextIntArray(N);
            int a = f.nextInt();
            int b = f.nextInt();
            int x = f.nextInt();
            System.out.println(x*min(a,b,x));

        }
    }
    static int min(int a, int b, int x)
    {
        int q = b/x;
        int r = a/x;
        if (r>1)
        {
            return 1;
        } else if (r==1)
        {
            if(a==x)
                 return q+1;
            else return 1;
        } else {
            if (q>1)
                return q+1;
            else if (q==1)
                {
                    return 2;
                }
            else return 1;
        }
    }

}
class FastScanner {
    public int BS = 1<<16;
    public char NC = (char)0;
    byte[] buf = new byte[BS];
    int bId = 0, size = 0;
    char c = NC;
    double num = 1;
    BufferedInputStream in;

    public FastScanner() {
        in = new BufferedInputStream(System.in, BS);
    }

    public FastScanner(String s) {
        try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
        }
        catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
        }
    }

    public char nextChar(){
        while(bId==size) {
            try {
                size = in.read(buf);
            }catch(Exception e) {
                return NC;
            }
            if(size==-1)return NC;
            bId=0;
        }
        return (char)buf[bId++];
    }

    public int nextInt() {
        return (int)nextLong();
    }

    public long nextLong() {
        num=1;
        boolean neg = false;
        if(c==NC)c=nextChar();
        for(;(c<'0' || c>'9'); c = nextChar()) {
            if(c=='-')neg=true;
        }
        long res = 0;
        for(; c>='0' && c <='9'; c=nextChar()) {
            res = (res<<3)+(res<<1)+c-'0';
            num*=10;
        }
        return neg?-res:res;
    }

    public double nextDouble() {
        double cur = nextLong();
        return c!='.' ? cur:cur+nextLong()/num;
    }

    public String next() {
        StringBuilder res = new StringBuilder();
        while(c<=32)c=nextChar();
        while(c>32) {
            res.append(c);
            c=nextChar();
        }
        return res.toString();
    }

    public String nextLine() {
        StringBuilder res = new StringBuilder();
        while(c<=32)c=nextChar();
        while(c!='\n') {
            res.append(c);
            c=nextChar();
        }
        return res.toString();
    }

    public boolean hasNext() {
        if(c>32)return true;
        while(true) {
            c=nextChar();
            if(c==NC)return false;
            else if(c>32)return true;
        }
    }

    public int[] nextIntArray(int n) {
        int[] res = new int[n];
        for(int i = 0; i < n; i++) res[i] = nextInt();
        return res;
    }

    public char[] nextCharArray(int n) {
        char[] res = new char[n];
        for (int i = 0; i < n; i++) {
            res[i] = nextChar();
        }
        return res;
    }

}


import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner f = new Scanner(System.in);
        int T = f.nextInt();
        while (T-- > 0) {
            // int N = f.nextInt();
            // int[] a = f.nextIntArray(N);
            int a = f.nextInt();
            int b = f.nextInt();
            int x = f.nextInt();
            System.out.println(min(a,b,x));

        }
    }
    static int min(int a, int b, int x)
    {
        // int q = b/x;
        int ans = 1;
        while (ans*x >=a && ans*x <= b)
        {
            ans++;
        }
        return ans*x;
    }

}


import java.util.*;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

public class Sample {
    public static void main(String[] args) throws Exception {
        FastScanner f = new FastScanner();
        int T = f.nextInt();
        while (T-- > 0) {
            // int N = f.nextInt();
            // int[] a = f.nextIntArray(N);
            int a = f.nextInt();
            int b = f.nextInt();
            int x = f.nextInt();
            System.out.println(x*min(a,b,x));

        }
    }
    static int min(int a, int b, int x)
    {
        int q = b/x;
        int r = a/x;
        if (r>1)
        {
            return 1;
        } else if (r==1)
        {
            if(a==x)
                 return q+1;
            else return 1;
        } else {
            if (q>1)
                return q+1;
            else if (q==1)
                {
                    return 2;
                }
            else return 1;
        }
    }

}
class FastScanner {
    public int BS = 1<<16;
    public char NC = (char)0;
    byte[] buf = new byte[BS];
    int bId = 0, size = 0;
    char c = NC;
    double num = 1;
    BufferedInputStream in;

    public FastScanner() {
        in = new BufferedInputStream(System.in, BS);
    }

    public FastScanner(String s) {
        try {
            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
        }
        catch (Exception e) {
            in = new BufferedInputStream(System.in, BS);
        }
    }

    public char nextChar(){
        while(bId==size) {
            try {
                size = in.read(buf);
            }catch(Exception e) {
                return NC;
            }
            if(size==-1)return NC;
            bId=0;
        }
        return (char)buf[bId++];
    }

    public int nextInt() {
        return (int)nextLong();
    }

    public long nextLong() {
        num=1;
        boolean neg = false;
        if(c==NC)c=nextChar();
        for(;(c<'0' || c>'9'); c = nextChar()) {
            if(c=='-')neg=true;
        }
        long res = 0;
        for(; c>='0' && c <='9'; c=nextChar()) {
            res = (res<<3)+(res<<1)+c-'0';
            num*=10;
        }
        return neg?-res:res;
    }

    public double nextDouble() {
        double cur = nextLong();
        return c!='.' ? cur:cur+nextLong()/num;
    }

    public String next() {
        StringBuilder res = new StringBuilder();
        while(c<=32)c=nextChar();
        while(c>32) {
            res.append(c);
            c=nextChar();
        }
        return res.toString();
    }

    public String nextLine() {
        StringBuilder res = new StringBuilder();
        while(c<=32)c=nextChar();
        while(c!='\n') {
            res.append(c);
            c=nextChar();
        }
        return res.toString();
    }

    public boolean hasNext() {
        if(c>32)return true;
        while(true) {
            c=nextChar();
            if(c==NC)return false;
            else if(c>32)return true;
        }
    }

    public int[] nextIntArray(int n) {
        int[] res = new int[n];
        for(int i = 0; i < n; i++) res[i] = nextInt();
        return res;
    }

    public char[] nextCharArray(int n) {
        char[] res = new char[n];
        for (int i = 0; i < n; i++) {
            res[i] = nextChar();
        }
        return res;
    }

}


import java.util.*;
public class Sample {
    public static void main(String[] args) throws Exception {
        Scanner f = new Scanner(System.in);
        int T = f.nextInt();
        while (T-- > 0) {
            // int N = f.nextInt();
            // int[] a = f.nextIntArray(N);
            int a = f.nextInt();
            int b = f.nextInt();
            int x = f.nextInt();
            System.out.println(min(a,b,x));

        }
    }
    int min(int a, int b, int x)
    {
        // int q = b/x;
        int ans = 1;
        while (ans*x >=a && ans*x <= b)
        {
            ans++;
        }
        return ans*x;
    }

}


public class Sample {
    public static void main(String[] args) throws Exception {
        Scanner f = new Scanner(System.in);
        int T = f.nextInt();
        while (T-- > 0) {
            // int N = f.nextInt();
            // int[] a = f.nextIntArray(N);
            int a = f.nextInt();
            int b = f.nextInt();
            int x = f.nextInt();
            System.out.println(min(a,b,x));

        }
    }
    int min(int a, int b, int x)
    {
        // int q = b/x;
        int ans = 1;
        while (ans*x >=a && ans*x <= b)
        {
            ans++;
        }
        return ans*x;
    }

}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numTest = sc.nextInt();
        for (int _i = 0; _i < numTest; _i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int d = sc.nextInt();
            if (l <= d && r >= d) {
                System.out.println((r/d+1)*d);
            } else {
                System.out.println(d);
            }
        }
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for (int i = 0; i < t; i++) {
            System.out.println(solve(scanner.nextInt(), scanner.nextInt(), scanner.nextInt()));
        }

    }

    private static int solve(int l, int r, int d) {
        for (int i = 1; i < Integer.MAX_VALUE; i++) {
            if (l <= d * i && d * i <= r) {
                i = r / d;
                continue;
            }
            return d * i;
        }
        return -1;
    }
}


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numTest = sc.nextInt();
        for (int _i = 0; _i < numTest; _i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();
            int d = sc.nextInt();
            if (l <= d && r >= d) {
                System.out.println((r/d+1)*d);
            } else {
                System.out.println(d);
            }
        }
    }
}


/**
 *   Author: Ridam Nagar
 *   Date: 27 February 2019
 *   Time: 01:17:36
**/
/*
package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{

    public static void main (String[] args) throws java.lang.Exception
    {
    	Scanner sc=new Scanner(System.in);
         int n=sc.nextInt();
         for(int j=0;j<n;j++){
         	int l=sc.nextInt();
         	int r=sc.nextInt();
         	int d=sc.nextInt();
            int x=0;
            int k=1;
            int f=0;
            if(d<l || d>r){
            	System.out.println(d);
            	f=1;
            }else{
            	int a=(r/d)*d +d;
            	System.out.println(a);
            }

         }

}

}


/**
 *   Author: Ridam Nagar
 *   Date: 27 February 2019
 *   Time: 01:17:36
**/
/*
package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{

    public static void main (String[] args) throws java.lang.Exception
    {
    	Scanner sc=new Scanner(System.in);
         int n=sc.nextInt();
         for(int j=0;j<n;j++){
         	int l=sc.nextInt();
         	int r=sc.nextInt();
         	int d=sc.nextInt();
            int x=0;
            int k=0;
            int f=0;
            if(d<=l){
            	System.out.println(d);
            	f=1;
            }

           if(f==0){
           	while(1==1){
           		if((r+k)%d==0){
           			System.out.println((r+k));
           			break;
           		}
           		k++;

           	}
           }

         }

}

}


/**
 *   Author: Ridam Nagar
 *   Date: 27 February 2019
 *   Time: 01:17:36
**/
/*
package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{

    public static void main (String[] args) throws java.lang.Exception
    {
    	Scanner sc=new Scanner(System.in);
         int n=sc.nextInt();
         for(int j=0;j<n;j++){
         	int l=sc.nextInt();
         	int r=sc.nextInt();
         	int d=sc.nextInt();
            int x=0;
            int k=1;
            int f=0;
            if(d<l || d>r){
            	System.out.println(d);
            	f=1;
            }else{
            	int a=0;
            	if((d+r)%d==0){
            		System.out.println(d+r);
            	}else{
            		a=d+r-(int)Math.abs(d-r);
            		System.out.println(a);
            	}
            }

         }

}

}


/**
 *   Author: Ridam Nagar
 *   Date: 27 February 2019
 *   Time: 01:17:36
**/
/*
package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{

    public static void main (String[] args) throws java.lang.Exception
    {
    	Scanner sc=new Scanner(System.in);
         int n=sc.nextInt();
         for(int j=0;j<n;j++){
         	int l=sc.nextInt();
         	int r=sc.nextInt();
         	int d=sc.nextInt();
            int f=0;
         	for(int i=1;i<l;i++){
         		if(i%d==0){
         			System.out.println(i);
         			f=1;
         			break;
         		}
         	}
         	if(f==0){
         			for(int i=r+1;i>=0;i++){
         		if(i%d==0){
         			System.out.println(i);
         			break;
         		}
         	}
         	}

         }

}

}


//https://codeforces.com/problemset/problem/1101/A
import java.util.Scanner;

public class Problem_1101_A {
    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {

        int q = scanner.nextInt();
        while (q-->0){

            int l = scanner.nextInt();
            int r = scanner.nextInt();
            int d = scanner.nextInt();

            if (l / d > 1 && d < l){
                System.out.println(d);
            }else if  (l/d > 0 && l % d != 0)
                System.out.println((l/d) * d);
            else if (l / d > 1)
                System.out.println((l/d-1) * d);
            else
                System.out.println((r/d + 1) * d);

        }

        scanner.close();
    }
}


//https://codeforces.com/problemset/problem/1101/A
import java.util.Scanner;

public class Problem_1101_A {
    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {

        int q = scanner.nextInt();
        while (q-->0){

            int l = scanner.nextInt();
            int r = scanner.nextInt();
            int d = scanner.nextInt();

            if  (l/d > 0 && l % d != 0)
                System.out.println((l/d) * d);
            else if (l / d > 1)
                System.out.println((l/d-1) * d);
            else
                System.out.println((r/d + 1) * d);

        }

        scanner.close();
    }
}


// TO LOVE IS TO KNOW WHAT'S YOUR WORTH. //
// Author :- Saurabh//
//BIT MESRA, RANCHI//
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class minimumInteger {

    static void Bolo_Jai_Mata_Di() {

        t = ni();

        tsc();      // starting time of execution

        while(t-->0){
            long l=ni(),r=ni(),x=ni();
            for(long i=x;i<120000000000l;i+=x){
                if(i>=l && i<=r)continue;
                else{
                    pl(i);break;
                }
            }
        }

        flush();
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //THE DON'T CARE ZONE BEGINS HERE...//

    static Calendar ts, te;                                                  //For time calculation
    static int mod9 = 1000000007;
    static int n, m, k, t, mod = 998244353;
    static Lelo input = new Lelo(System.in);
    static PrintWriter pw = new PrintWriter(System.out, true);

    public static void main(String[] args) {      //threading has been used to increase the stack size.

        new Thread(null, null, "BlackRise", 1 << 25)  //the last parameter is stack size desired.,
        {
            public void run() {

                try {
                    Bolo_Jai_Mata_Di();
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }

    static class Lelo {                                              //Lelo class for fast input
        private InputStream ayega;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public Lelo(InputStream ayega) {
            this.ayega = ayega;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = ayega.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public int nextInt() {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

    // functions to take input//
    static int ni() {
        return input.nextInt();
    }

    static long nl() {
        return input.nextLong();
    }

    static double nd() {
        return input.nextDouble();
    }

    static String ns() {
        return input.readString();
    }

    //functions to give output
    static void pl() {
        pw.println();
    }

    static void p(Object o) {
        pw.print(o + " ");
    }

    static void pws(Object o) {
        pw.print(o + "");
    }

    static void pl(Object o) {
        pw.println(o);
    }

    static void tsc()                                          //calculates the starting time of execution
    {
        ts = Calendar.getInstance();
        ts.setTime(new Date());
    }

    static void tec()                                          //calculates the ending time of execution
    {
        te = Calendar.getInstance();
        te.setTime(new Date());
    }

    static void pwt()                                          //prints the time taken for execution
    {
        pw.printf("\nExecution time was :- %f s\n", (te.getTimeInMillis() - ts.getTimeInMillis()) / 1000.00);
    }
    static void sort(int ar[], int n) {
        for (int i = 0; i < n; i++) {
            int ran = (int) (Math.random() * n);
            int temp = ar[i];
            ar[i] = ar[ran];
            ar[ran] = temp;
        }
        Arrays.sort(ar);
    }

    static void sort(long ar[], int n) {
        for (int i = 0; i < n; i++) {
            int ran = (int) (Math.random() * n);
            long temp = ar[i];
            ar[i] = ar[ran];
            ar[ran] = temp;
        }
        Arrays.sort(ar);
    }

    static void sort(char ar[], int n) {
        for (int i = 0; i < n; i++) {
            int ran = (int) (Math.random() * n);
            char temp = ar[i];
            ar[i] = ar[ran];
            ar[ran] = temp;
        }
        Arrays.sort(ar);
    }
    static void flush() {
        tec();                  //ending time of execution
        //pwt();                //prints the time taken to execute the program
        pw.flush();
        pw.close();
    }
}


#include <iostream>
bool judge[1000000001] = { false };
int main()
{
	int n, k, id[2 * 100000];

	int *begin = id, *end = id;
	std::cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		int temp;
		std::cin >> temp;
		if (judge[temp])
			continue;
		else
		{
			judge[temp] = true;
			if (end - begin == k)
			{
				judge[*begin] = false;
				*end++ = temp;
				begin++;

			}
			else
			{
				*end++ = temp;
			}
		}
	}
	std::cout << end - begin << std::endl;
	for (int *i = end - 1; i >= begin; i--)
	{
		std::cout << *i << " ";
	}

	return 0;
}


#include <iostream>
#include <cstdbool>
#include <cstdio>
#include <climits>
#include <algorithm>
bool judge[500000000 + 1];
int que[2 * 100000 + 1];
int main()
{
	int *que_begin = que;
	int *que_end = que;
	int n, k;
	scanf_s("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		int temp;
		scanf_s("%d", &temp);
		if (temp <= 500000000)
		{
			if (que_begin < que_end)
			{
				if (judge[temp])
					continue;
				if (que_end - que_begin < k)
				{
					*que_end++ = temp;
					judge[temp] = true;
				}
				else
				{
					*que_end++ = temp;
					judge[temp] = true;
					judge[*que_begin++] = false;
				}
			}
			else
			{
				*que_end++ = temp;
				judge[temp] = true;
			}
		}
		else
		{
			if (que_begin < que_end)
			{
				if (std::find(que_begin, que_end, temp) == que_end)
				{
					if (que_end - que_begin < k)
						*que_end++ = temp;
					else
					{
						*que_end++ = temp;
						if (*que_begin > 500000000)
							que_begin++;
						else
						{
							judge[*que_begin++] = false;
						}
					}
				}

			}
			else
			{
				*que_end++ = temp;
			}
		}
	}
	int size = que_end - que_begin;
	printf("%d\n", size);
	for(int i = size - 1; i >= 0; i--)
	{
		printf("%d ", *(que_begin + i));
	}
}


#include <iostream>
#include <cstdbool>
#include <cstdio>

bool judge[(3LL * 1000000000)];
int que[2 * 100000 + 1];
int main()
{
	int *que_begin = que;
	int *que_end = que;
	int n, k;
	scanf_s("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		int temp;
		scanf_s("%d", &temp);
		if (que_begin < que_end)
		{
			if (judge[temp])
				continue;
			if (que_end - que_begin < k)
			{
				*que_end++ = temp;
				judge[temp] = true;
			}
			else
			{
				*que_end++ = temp;
				judge[temp] = true;
				judge[*que_begin++] = false;
			}
		}
		else
		{
			*que_end++ = temp;
			judge[temp] = true;
		}
	}
	int size = que_end - que_begin;
	printf("%d\n", size);
	for(int i = size - 1; i >= 0; i--)
	{
		printf("%d ", *(que_begin + i));
	}
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <deque>
#include <algorithm>
#include <ctype.h>
#include <string>
#include <map>
#include <numeric>
#include <set>
#include <array>
#include <functional>
#include <cmath>
#include <cstring>
#include <locale>
#include <list>

using namespace std;

int main(){
    int n,k,a;
    cin>>n>>k;
    vector<int> f,q;
    map<int,int>m;
    for(int i=0; i<n; i++){
        cin>>a;
        if(m[a]==false){
            m[a]=1;
            q.push_back(a);
            f.insert(f.begin(),a);
            if(f.size()>k){
                f.pop_back();
                m.erase(q.front());
                q.erase(q.begin());
            }
        }
    }
    cout << f.size() << "\n";
    for(auto q : f)
        cout << q << " ";
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <deque>
#include <algorithm>
#include <ctype.h>
#include <string>
#include <map>
#include <numeric>
#include <set>
#include <array>
#include <functional>
#include <cmath>
#include <cstring>
#include <locale>
#include <list>
#include <queue>

using namespace std;

int main(){
    int n,k,a;
    cin>>n>>k;
    vector<int> f;
    queue <int> q;
    map<int,int>m;
    for(int i=0; i<n; i++){
        cin>>a;
        if(m[a]==false){
            m[a]=1;
            q.push(a);
            if(m.size()>k){
                m.erase(q.front());
                q.pop();
            }
        }
    }
    cout << m.size() << "\n";
    for(int i=0; i<m.size() ; i++){
        f.push_back(q.front());
        q.pop();
    }
    reverse(f.begin(),f.end());
    for(auto o:f)
        cout << o << " ";
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <deque>
#include <algorithm>
#include <ctype.h>
#include <string>
#include <map>
#include <numeric>
#include <set>
#include <array>
#include <functional>
#include <cmath>
#include <cstring>
#include <locale>
#include <list>

using namespace std;

int main(){
    int n,k,a,x;
    cin>>n>>k;
    vector<int> v,f;
    x=n;
    while(x--){
        cin>>a;
        v.push_back(a);
    }
    for(int i=0; i<n; i++){
        auto it=find(f.begin(),f.end(),v[i]);
        a=v[i];
        if(it==f.end()){
            f.insert(f.begin(),a);
            if(f.size()>k)
                f.pop_back();
        }
    }
    cout << f.size() << "\n";
    for(auto q : f)
        cout << q << " ";
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <deque>
#include <algorithm>
#include <ctype.h>
#include <string>
#include <map>
#include <numeric>
#include <set>
#include <array>
#include <functional>
#include <cmath>
#include <cstring>
#include <locale>
#include <list>

using namespace std;

int main(){
    int n,k,a,x,y=1,g=1;
    cin>>n>>k;
    vector<int> v,f;
    map<int,int>m;
    x=n;
    while(x--){
        cin>>a;
        v.push_back(a);
    }
    for(int i=0; i<n; i++){
        a=v[i];
        if(m[a]==false){
            m[a]=y++;
            f.insert(f.begin(),a);
            if(f.size()>k){
                f.pop_back();
                m.erase(g++);
            }
        }else if(f.size()>k)g++;
    }
    cout << f.size() << "\n";
    for(auto q : f)
        cout << q << " ";
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <deque>
#include <algorithm>
#include <ctype.h>
#include <string>
#include <map>
#include <numeric>
#include <set>
#include <array>
#include <functional>
#include <cmath>
#include <cstring>
#include <locale>
#include <list>

using namespace std;

int main(){
    int n,k,a,x,y=1,g=1;
    cin>>n>>k;
    vector<int> v,f,q;
    map<int,int>m;
    x=n;
    while(x--){
        cin>>a;
        v.push_back(a);
    }
    for(int i=0; i<n; i++){
        a=v[i];
        if(m[a]==false){
            m[a]=y;
            q.push_back(a);
            f.insert(f.begin(),a);
            if(f.size()>k){
                f.pop_back();
                m.erase(q.front());
                q.erase(q.begin());
            }
        }
    }
    cout << f.size() << "\n";
    for(auto q : f)
        cout << q << " ";
}


#include <iostream>
#include <set>
#include <list>

int main()
{
	int n, k, id;

	std::cin >> n >> k;

	std::set<int> onScreen;
	std::list<int> list;

	for (int i = 0; i < n; i++)
	{
		std::cin >> id;

		if (onScreen.find(id) == onScreen.end())
		{
			onScreen.insert(id);
			list.push_front(id);
			if (list.size() == k + 1)
			{
				onScreen.erase(list.back());
				list.pop_back();
			}
		}
	}

	std::cout << list.size() << std::endl;
	for (auto it = list.begin(); it != list.end(); it++)
		std::cout << *it << " ";

	return 0;
}


#include <iostream>
#include <set>
#include <list>

int main()
{
	int n, k, id;

	std::cin >> n >> k;

	std::set<int> onScreen;
	std::list<int> list;

	for (int i = 0; i < n; i++)
	{
		std::cin >> id;

		if (onScreen.find(id) == onScreen.end())
		{
			onScreen.insert(id);
			list.push_front(id);
			if (list.size() == k + 1)
			{
				onScreen.erase(list.back());
				list.pop_back();
			}
		}
	}

	std::cout << k << std::endl;
	for (auto it = list.begin(); it != list.end(); it++)
		std::cout << *it << " ";

	return 0;
}


#include<iostream>
#include<unordered_map>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
typedef long long ll;
using namespace std;
int main()
{
	unordered_map<int,int>m;
	queue<int>q;
	stack<int>s;
	int N,K,t;
	cin>>N>>K;
	while(N--)
	{
		cin>>t;
		if(!m[t])
		{
			m[t]=1;
			q.push(t);
			if(q.size()>K)
			{
				m[q.front()]=0;
				q.pop();
			}
		}
	}
	cout<<q.size()<<endl;
	while(!q.empty())
	{
		s.push(q.front());
		q.pop();
	}
	while(!s.empty())
	{
		cout<<s.top()<<" ";
		s.pop();
	}
	cout<<endl;
	return 0;
}


#include<iostream>
#include<map>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
typedef long long ll;
using namespace std;
int main()
{
	map<int,int>m;
	queue<int>q;
	stack<int>s;
	int N,K,t;
	cin>>N>>K;
	while(N--)
	{
		cin>>t;
		if(!m[t])
		{
			m[t]=1;
			q.push(t);
			if(q.size()>K)
			{
				m[q.front()]=0;
				q.pop();
			}
		}
	}
	cout<<q.size()<<endl;
	while(!q.empty())
	{
		s.push(q.front());
		q.pop();
	}
	while(!s.empty())
	{
		cout<<s.top()<<" ";
		s.pop();
	}
	cout<<endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>

using namespace std;
unsigned long long dp(unsigned long long a, unsigned long long b)
{
	unsigned long long r = 1;
	while (b > 0)
	{
		if (b & 1)
			r *= a;
		a *= a;
		b >>= 1;

	}
	return r;
}
//vector<vector<int>> mas;
//int n, cnt=0;
//vector<int> cat(n);
//vector<bool> used(n,false);
//int  m,a,b,ans=0;
//void dfs(int v,int value,int c)
//{
//	if (value > m)
//		return;
//	if (!used[v])
//	{
//		used[v] = true;
//		for (int i = 0; i < mas[v].size(); i++)
//		{
//			if (mas[v].size() == 1 && mas[v][0]==c && value + cat[v ]<=m)
//			{	ans++;
//				return;
//			}
//			if (cat[v] == 1)
//				dfs(mas[v][i], value + 1,v);
//			else
//				dfs(mas[v][i],0,v);
//		}
//	}
//	//ans++;
//	return;
//}

int main() {
#ifdef _DEBUG
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	int index = 0;
	list<int> st;
	set<int> s;
	for (int i = 0; i < n; i++)
	{
		//set<int> ::iterator it2 = s.find(v[index]);
		if (s.count(v[i]))
			continue;
		if (s.size() == k)
		{
			s.erase(st.front());
			st.pop_front();
			index++;
		}
		st.push_back(v[i]);
		s.insert(v[i]);
	}
	list<int> ::iterator it = st.end();
	it--;
	cout << st.size() << endl;
	for (; it != st.begin(); it--)
	{
		cout << *it << " ";
	}
	cout << st.front();
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>

using namespace std;
unsigned long long dp(unsigned long long a, unsigned long long b)
{
	unsigned long long r = 1;
	while (b > 0)
	{
		if (b & 1)
			r *= a;
		a *= a;
		b >>= 1;

	}
	return r;
}
vector<vector<int>> mas;
int n, cnt=0;
vector<int> cat(n);
vector<bool> used(n,false);
int  m,a,b,ans=0;
//void dfs(int v,int value,int c)
//{
//	if (value > m)
//		return;
//	if (!used[v])
//	{
//		used[v] = true;
//		for (int i = 0; i < mas[v].size(); i++)
//		{
//			if (mas[v].size() == 1 && mas[v][0]==c && value + cat[v ]<=m)
//			{	ans++;
//				return;
//			}
//			if (cat[v] == 1)
//				dfs(mas[v][i], value + 1,v);
//			else
//				dfs(mas[v][i],0,v);
//		}
//	}
//	//ans++;
//	return;
//}

int main() {
#ifdef _DEBUG
	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
#else
	//freopen("sum.in", "r", stdin);
	//freopen("sum.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	int index = 0;
	list<int> st;
	set<int> s;
	for (int i = 0; i < n; i++)
	{
		//set<int> ::iterator it2 = s.find(v[index]);
		if (s.size() == k  && s.find(v[i])==s.end())
		{
				//st.push_back(v[index]);
				st.pop_front();
				s.erase(s.find(v[index]));
				index++;
		}
		if(s.find(v[i]) == s.end() || i==0)
		st.push_back(v[i]);
		s.insert(v[i]);
	}
	list<int> ::iterator it = st.end();
	it--;
	cout << st.size() << endl;
	for (; it != st.begin(); it--)
	{
		cout << *it<< " ";
	}
	cout << st.front();
	return 0;
}


/*
URL_HERE
*/
/*

*/
#ifdef _WIN32
	#pragma warning(disable:4996)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <unordered_map>
using namespace std;
//
//unsigned long long encrypt_djb2(char* data, int n_bytes)
//{
//	unsigned long long h = 5381;
//
//	for (int i = 0; i < n_bytes; i++)
//	{
//		h = 33 * h + data[i];
//	}
//	return h;
//}
//
//struct Lut
//{
//	void** data;
//	unsigned long long* keys;
//	int size_bits;
//};
//
//void init(Lut* h, int size_bits)
//{
//	h->size_bits = size_bits;
//	int n_elements = 1 << size_bits;//same as "n_elements = 2^size_bits"
//	h->data = (void**)malloc(sizeof(void*) * n_elements);
//	h->keys = (unsigned long long*)malloc(sizeof(unsigned long long) * n_elements);
//
//	memset(h->data, 0, sizeof(void*) * n_elements);
//	memset(h->keys, 0, sizeof(unsigned long long) * n_elements);
//}
//
//int set(Lut* h, unsigned long long key, void* val)
//{
//	//knuth's golden ratio multiplicative hashing for 64-bit keys
//	int index = (key * 2654435761) >> (64 - h->size_bits);
//	int n_elements = 1 << h->size_bits;
//	for (int i = 0; i < n_elements; i++)
//	{
//		if (h->keys[index] == key) //if key exists, overwrite data
//		{
//			h->data[index] = val;
//			return index;
//		}
//
//		if (h->keys[index] == 0) //empty spot
//		{
//			h->data[index] = val;
//			h->keys[index] = key;
//			return index;
//		}
//
//		index++;
//		index &= n_elements - 1;
//	}
//
//	return -1;//return invalid index if data was not placed. this could be used as an indicator to resize.
//}
//
//void* get(Lut* h, unsigned long long key)
//{
//	int index = (key * 2654435761) >> (64 - h->size_bits);
//	int n_elements = 1 << h->size_bits;
//	for (int i = 0; i < n_elements; i++)
//	{
//		if (h->keys[index] == key)//found original key
//		{
//			return h->data[index];
//		}
//
//		if (h->keys[index] == 0) return NULL;//if you see a zero,key was never there
//
//		index++;
//		index &= n_elements - 1;
//	}
//	return NULL;
//}
//
//void resize(Lut* h)
//{
//	Lut tmp;
//	init(&tmp, h->size_bits + 1);//if previous size was 2^size_bits, now it is 2^(size_bits+1) ==> 2*2^size_bits. simply doubled the size.
//
//	int n_elements = 1 << h->size_bits;
//	for (int i = 0; i < n_elements; i++) if (h->keys[i] != 0) set(&tmp, h->keys[i], h->data[i]);
//
//	free(h->keys);
//	free(h->data);
//
//	*h = tmp;
//}

FILE* _fin = stdin;
FILE* _fout = stdout;
#define PI 3.141592653589793238462643383279502884197169399375105820974
#define ten5p1 100001
#define ten6p1 1000001
#define ten8p1 100000001
#define ten9p1 1000000001
#define ll long long
#define ull unsigned long long
#define rep(var,n) for(int var=0;var<n;++var)
#define repi(n) rep(i,n)
#define repj(n) rep(j,n)
#define repi1(n) for(int i=1;i<n;++i)
#define _min(a,b) a<b?a:b
#define _max(a,b) a>b?a:b
#define zeroi(data,n) memset(data,0,sizeof(int)*n);
#define zeroll(data,n) memset(data,0,sizeof(long long)*n);
#define one(data,n) {for(int _ONEI=0;_ONEI<n;++_ONEI) data[_ONEI]=1;}
#define readc(var) fscanf(_fin,"%c",var)
int readi() { int var; fscanf(_fin, "%d", &var); return var; }
ll readll() { ll var; fscanf(_fin, "%lld", &var); return var; }
void repreadi(int* data, int n) { repi(n) data[i] = readi(); }
void repreadll(ll* data, int n) { repi(n) data[i] = readll(); }
#define writec(var) fprintf(_fout,"%c",var)
#define writecsp(var) fprintf(_fout,"%c ",var)
#define writecln(var) fprintf(_fout,"%c\n",var)
#define writei(var) fprintf(_fout,"%d",var)
#define writeisp(var) fprintf(_fout,"%d ",var)
#define writellsp(var) fprintf(_fout,"%lld ",var)
#define writeiln(var) fprintf(_fout,"%d\n",var)
#define writellln(var) fprintf(_fout,"%lld\n",var)
#define writefln(var) fprintf(_fout,"%f\n",var)
#define writes(str) fprintf(_fout,"%s",str)
#define writesp() fprintf(_fout," ")
#define writeln() fprintf(_fout,"\n")
#define iseven(x) ((x&1)==0 ? 1:0)
#define RUN_LOCAL(testfilename) {_fin = fopen(testfilename, "r"); if(_fin==NULL) _fin=stdin;}
#define swap(type,a, b) {type t=a;a=b;b=t;}
#define swapxor(a,b) {a^=b;b^=a;a^=b;}
#define sort(data,n) std::sort(data,data+n)
#define mod(a,b) b==0 ? 0 : a==0 ? 0 :(a>0 ? a%b : b + a % b)
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }

void reversei(int* data, int n) { int k = n >> 1; repi(k) { int tmp = data[i]; data[i] = data[n - i - 1]; data[n - i - 1] = tmp; } }
int bsearch(int val, int* data, int n) { if (data[0] > val) return -1; if (data[n - 1] < val) return n; int l = 0; int r = n - 1; for (; l < r;) { int mid = (l + r + 1) >> 1; if (data[mid] <= val) l = mid; else r = mid - 1; }if (data[r] != val) ++r; return r; }
int reads(char* str, int maxsize)
{
	for (;;)
	{
		if(fgets(str, maxsize, _fin)==NULL) break;
		if (str[0] != '\n' && str[0] != '\r') break;
	}
	int slen = strlen(str);
	if (slen == 0) return 0;
	if (str[slen - 1] == '\n' || str[slen - 1] == '\r') str[--slen] = 0;
	return slen;
}

#define _Vec(type, name) \
struct name { type* data; int size; int n; };\
void init(name* t, int size) { t->data = (type*)malloc(sizeof(type) * size); t->size = size; t->n = 0; }\
void resize(name* t) { int ns = t->size * 1.2f; t->data = (type*)realloc(t->data, sizeof(type) * ns); t->size = ns; }\
void add(name* t, type val) { if (t->n >= t->size) resize(t); int k = t->n; t->data[k] = val; t->n = k + 1; }\
void free(name* t) { free(t->data);}
_Vec(int, Veci)
_Vec(long long, Vecll)
_Vec(char*, Vecs)

#define _ispal(type, name) int name(type* a, type* b, int n){repi(n){if (a[i] != b[n - i - 1]){return 0;}}return 1;}
_ispal(int, ispali)
_ispal(char, ispalc)

#define _Pair(type, name) struct name{type x, y;}; \
int cmp_##name(const void* _a, const void* _b){name* a = (name*)_a;name* b = (name*)_b;if (a->x == b->x){if (a->y < b->y) return -1;else return 1;}if (a->x < b->x) return -1;else return 1;}\
void sort_##name(name* d, int n){qsort(d, n, sizeof(name), cmp_##name);}
	_Pair(int, Pairi)

	int cmp_Str(const void* _a, const void* _b) { char* a = *((char**)_a); char* b = *((char**)_b); return strcmp(a, b); }
void sort_Str(char** str, int n) { qsort(str, n, sizeof(char*), cmp_Str); }

int main()
{
	RUN_LOCAL("data1234B1.txt");

	int n = readi();
	int k = readi();
	static int a[2 * ten5p1];
	static int s[2 * ten5p1];
	int pos = 0;
	repreadi(a, n);

	unordered_map<int, int> h;

	repi(n)
	{
		if (h[a[i]] == 0)
		{
			h[a[i]] = 1;
			s[pos++] = a[i];
			if (pos > k)
			{
				h[s[pos - k - 1]] = 0;
			}
		}
	}

	int m = _min(k, pos);
	writeiln(m);
	for (int i = 0; i < m; ++i)
	{
		writeisp(s[pos - i - 1]);
	}

	return 0;
}


// CodeforcesContest 590

#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main()
{
	ios::sync_with_stdio;
	int n, k, currentID;
	cin >> n >> k;
	set <int> screen;
	vector<int> res;
	for (n; n > 0; n--)
	{
		cin >> currentID;
		if (!screen.count(currentID))
		{
			if (screen.size() == k)
			{
				screen.erase(res.front());
				res.erase(res.begin());
			}
			screen.insert(screen.begin(), currentID);
			res.push_back(currentID);
		}
	}
	cout << screen.size() << '\n';
	for (n = 0; n < screen.size() && res.size() - 1 - n >= 0; n++)
		cout << res[res.size() - 1 - n] << ' ';
	return 0;
}


// CodeforcesContest 590

#include <iostream>
#include <vector>
#include <deque>
using namespace std;

bool isIDonScreen(int, deque <int>);

int main()
{
	ios::sync_with_stdio;
	int n, k, currentID;
	cin >> n >> k;
	deque <int> screen;
	for (n; n > 0; n--)
	{
		cin >> currentID;
		if (!isIDonScreen(currentID, screen))
		{
			//screen.insert(screen.begin(), currentID);
			screen.push_front(currentID);
			if (screen.size() > k)
				screen.pop_back();
		}
	}
	cout << screen.size() << '\n';
	for (n = 0; n < screen.size(); n++)
		cout << screen[n] << ' ';
	return 0;
}

bool isIDonScreen(int ID, deque <int> IDonScreen)
{
	int i;
	for (i = 0; i < IDonScreen.size(); i++)
		if (IDonScreen[i] == ID)
			return true;
	return false;
}


// CodeforcesContest 590

#include <iostream>
#include <vector>
using namespace std;

bool isIDonScreen(int, vector <int>);

int main()
{
	int n, k, currentID;
	cin >> n >> k;
	vector <int> screen;
	for (n; n > 0; n--)
	{
		cin >> currentID;
		if (!isIDonScreen(currentID, screen))
		{
			screen.insert(screen.begin(), currentID);
			if (screen.size() > k)
				screen.pop_back();
		}
	}
	cout << screen.size() << endl;
	for (n = 0; n < screen.size(); n++)
		cout << screen[n] << ' ';
	return 0;
}

bool isIDonScreen(int ID, vector <int> IDonScreen)
{
	int i;
	for (i = 0; i < IDonScreen.size(); i++)
		if (IDonScreen[i] == ID)
			return true;
	return false;
}


// CodeforcesContest 590

#include <iostream>
#include <vector>
#include <set>
using namespace std;

//bool isIDonScreen(int, deque <int>);

int main()
{
	ios::sync_with_stdio;
	int n, k, currentID;
	cin >> n >> k;
	set <int> screen;
	vector<int> res;
	for (n; n > 0; n--)
	{
		cin >> currentID;
		//if (!isIDonScreen(currentID, screen))
		//{
		//	//screen.insert(screen.begin(), currentID);
		//	screen.push_front(currentID);
		//	//if (screen.size() > k)
		//	//	screen.pop_back();
		//}
		if (screen.find(currentID) == screen.end())
		{
			if (screen.size() >= k)
				screen.erase(screen.end());
			screen.insert(screen.begin(), currentID);
			res.push_back(currentID);
		}
	}
	cout << screen.size() << '\n';
	for (n = 0; n < screen.size(); n++)
		cout << res[res.size() - 1 - n] << ' ';
	return 0;
}

//bool isIDonScreen(int ID, deque <int> IDonScreen)
//{
//	int i;
//	for (i = 0; i < min(IDonScreen.size(), k); i++)
//		if (IDonScreen[i] == ID)
//			return true;
//	return false;
//}


// CodeforcesContest 590

#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main()
{
	ios::sync_with_stdio;
	int n, k, currentID;
	cin >> n >> k;
	set <int> screen;
	vector<int> res;
	for (n; n > 0; n--)
	{
		cin >> currentID;
		if (!screen.count(currentID))
		{
			if (screen.size() == k)
			{
				screen.erase(res.front());
				res.erase(res.begin());
			}
			screen.insert(screen.begin(), currentID);
			res.push_back(currentID);
		}
	}
	cout << screen.size() << '\n';
	for (n = 0; n < res.size(); n++)
		cout << res[res.size() - 1 - n] << ' ';
	return 0;
}


// CodeforcesContest 590

#include <iostream>
#include <vector>
#include <set>
using namespace std;

//bool isIDonScreen(int, deque <int>);

int main()
{
	ios::sync_with_stdio;
	int n, k, currentID;
	cin >> n >> k;
	set <int> screen;
	vector<int> res;
	for (n; n > 0; n--)
	{
		cin >> currentID;
		//if (!isIDonScreen(currentID, screen))
		//{
		//	//screen.insert(screen.begin(), currentID);
		//	screen.push_front(currentID);
		//	//if (screen.size() > k)
		//	//	screen.pop_back();
		//}
		if (screen.find(currentID) == screen.end())
		{
			if (screen.size() >= k)
				screen.erase(screen.end());
			screen.insert(screen.begin(), currentID);
			res.push_back(currentID);
		}
	}
	cout << screen.size() << '\n';
	for (n = 0; n < screen.size() && res.size() - 1 - n >= 0; n++)
		cout << res[res.size() - 1 - n] << ' ';
	return 0;
}

//bool isIDonScreen(int ID, deque <int> IDonScreen)
//{
//	int i;
//	for (i = 0; i < min(IDonScreen.size(), k); i++)
//		if (IDonScreen[i] == ID)
//			return true;
//	return false;
//}


#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <list>
using namespace std;

#define ll long long

int main(){

	ll n, k;
	cin >> n >> k;
	map <ll, bool> id;
	list <ll> v;
	ll inp;

	for (ll i = 0; i < n; i++){

		cin >> inp;

		if (id[inp] == true)
			continue;

		ll len = v.size();

		if (len < k){
			v.push_front(inp);
			id[inp] = true;
		}

		else{
			v.push_front(inp);
			id[inp] = true;

			id[ v.back() ] = false;
			v.pop_back();
		}

	}

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

	for (auto i : v)
		cout << i << " ";

}


#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <list>
using namespace std;

#define ll long long

int main(){

	ll n, k;
	cin >> n >> k;
	map <ll, bool> id;
	vector <ll> v;
	ll inp;

	for (ll i = 0; i < n; i++){

		cin >> inp;

		if (id[inp] == true)
			continue;

		ll len = v.size();

		if (len < k){
			v.insert(v.begin(), inp);
			id[inp] = true;
		}

		else{
			v.insert(v.begin(), inp);
			id[inp] = true;
			id[v[k]] = false;
			v.pop_back();
		}

	}

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

	for (auto i : v)
		cout << i << " ";

}


#include<iostream>
#include<queue>
#include<set>

using namespace std;

set<int> s;
set<int> :: iterator it;
queue<int> q;

int ans[20005];

int main(){
	int i, j, m, n;
	int a;
	scanf("%d%d", &n, &m);
	for(i = 0;i < n;i++){
		scanf("%d", &a);
		if(!s.count(a)){
			s.insert(a);
			q.push(a);
			if(q.size() > m){
				it = s.find(q.front());
				s.erase(it);
				q.pop();
			}
		}
	}
	cout << q.size() << endl;
	j = q.size();
	for(i = 0;i < j;i++){
		ans[i] = q.front();
		q.pop();
	}
	for(i = j - 1;i >= 0;i--){
		printf("%d ", ans[i]);
	}
	return 0;
}


#include<iostream>
#include<queue>
#include<set>

using namespace std;

set<int> s;
set<int> :: iterator it;
queue<int> q;

int ans[200005];

int main(){
	int i, j, m, n;
	int a;
	scanf("%d%d", &n, &m);
	for(i = 0;i < n;i++){
		scanf("%d", &a);
		if(!s.count(a)){
			s.insert(a);
			q.push(a);
			if(q.size() > m){
				it = s.find(q.front());
				s.erase(it);
				q.pop();
			}
		}
	}
	cout << q.size() << endl;
	j = q.size();
	for(i = 0;i < j;i++){
		ans[i] = q.front();
		q.pop();
	}
	for(i = j - 1;i >= 0;i--){
		cout << ans[i] << " ";
	}
	return 0;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<intrin.h>
#include<bitset>
#include<nmmintrin.h>
#include<map>
#include<unordered_set>
#include<deque>
#define pb push_back
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define vc vector<int>
#define inf 0x3f3f3f3f
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define t_case ll tt; cin>>tt; while (tt--)
#define int long long
#define For(i,j,k) for (int i=(int)(j);i<(int)(k);i++)
#define ins insert
#define in(x); { for (auto &i : x) cin >> i; }
#define out(x); { for (auto i : x) cout<< i<< " "; }
using namespace std;
int n, k;
deque<int> ans;
void main() {
	fastio
		cin >> n >> k;
		For(i, 1, n + 1) {
		int a; cin >> a;
		if (ans.size() == k && find(ans.begin(), ans.end(), a) == ans.end()) { ans.pop_back();ans.push_front(a); }
		else if (find(ans.begin(), ans.end(), a) == ans.end()) ans.push_front(a);
	}
		cout << ans.size() << "\n";
		out(ans) cout << "\n";

}


#include <iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<intrin.h>
#include<bitset>
#include<nmmintrin.h>
#include<map>
#include<unordered_set>
#include<deque>
#define pb push_back
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define vc vector<int>
#define inf 0x3f3f3f3f
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define t_case ll tt; cin>>tt; while (tt--)
#define int long long
#define For(i,j,k) for (int i=(int)(j);i<(int)(k);i++)
#define ins insert
#define in(x); { for (auto &i : x) cin >> i; }
#define out(x); { for (auto i : x) cout<< i<< " "; }
using namespace std;
int n, k;
deque<int> ans;
set<int> s;
void main() {
	fastio
		cin >> n >> k;
		For(i, 1, n + 1) {
		int a; cin >> a;
		if (!s.count(a)) {
			if (ans.size() == k) {
				s.erase(ans.back());
				ans.pop_back();
			}
	       ans.push_front(a); s.insert(a);
		}
	}
		cout << ans.size() << "\n";
		out(ans) cout << "\n";

}


#include <iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<intrin.h>
#include<bitset>
#include<nmmintrin.h>
#include<map>
#include<unordered_set>
#define pb push_back
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define vc vector<int>
#define inf 0x3f3f3f3f
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define t_case ll tt; cin>>tt; while (tt--)
#define int long long
#define For(i,j,k) for (int i=(int)(j);i<(int)(k);i++)
#define ins insert
#define in(x); { for (auto &i : x) cin >> i; }
#define out(x); { for (auto i : x) cout<< i<< " "; }
using namespace std;
unordered_set<int> s;
int n, k;
vector<int> ans;
void main() {
	fastio
		cin >> n >> k;
		For(i, 1, n + 1) {
		int a; cin >> a;
		if (s.size() == k && !s.count(a)) { s.insert(a);s.erase(next(s.begin(),k)); }
		else s.insert(a);
	}
		for (auto i : s)ans.push_back(i);
		reverse(ans.begin(), ans.end());
		cout << ans.size() << "\n";
		out(ans) cout << "\n";
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<intrin.h>
#include<bitset>
#include<nmmintrin.h>
#include<map>
#include<unordered_set>
#include<deque>
#define pb push_back
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define vc vector<int>
#define inf 0x3f3f3f3f
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define t_case ll tt; cin>>tt; while (tt--)
#define int long long
#define For(i,j,k) for (int i=(int)(j);i<(int)(k);i++)
#define ins insert
#define in(x); { for (auto &i : x) cin >> i; }
#define out(x); { for (auto i : x) cout<< i<< " "; }
using namespace std;
int n, k;
vector<int> ans;
set<int> s;
void main() {
	fastio
		cin >> n >> k;
		For(i, 1, n + 1) {
		int a; cin >> a;
		if (ans.size() == k && !s.count(a)) {
			ans.push_back(a);ans.erase(ans.begin()); s.clear();
			for (auto i : ans)s.insert(i);
		}
		else if (!s.count(a)) {
			ans.push_back(a), s.insert(a);
		}
	}
		reverse(ans.begin(), ans.end());
		cout << ans.size() << "\n";
		out(ans) cout << "\n";
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include <time.h>
#include<string>
#include<stack>
#include<vector>
#include<map>
#include<deque>
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, unsigned int> iu;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define EXT(st_) cout<<"\n>>>Exicution Time: "<<(double)(clock()-st_)/CLOCKS_PER_SEC<<endl;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, x;
	deque<unsigned long long> v;
	map<unsigned long long, unsigned long long> m;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
			if (m.find(x) == m.end() && v.size() >= k)
			{
				m.erase(v.back());
				v.pop_back();
			}
			if (m.find(x) == m.end()) {
				m[x] = x;
				v.push_front(x);
			}

	}
	printf("%llu\n", v.size());
	for (int i = 0; i < v.size() - 1; i++)
		printf("%llu ", v[i]);
	printf("%llu", v[v.size() - 1]);
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include <time.h>
#include<string>
#include<stack>
#include<vector>
#include<map>
#include<deque>
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, unsigned int> iu;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define EXT(st_) cout<<"\n>>>Exicution Time: "<<(double)(clock()-st_)/CLOCKS_PER_SEC<<endl;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, x;
	deque<unsigned long long> v;
	map<unsigned long long, unsigned long long> m;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
			if (m.find(x) == m.end() && v.size() >= k)
			{
				m.erase(v.back());
				v.pop_back();
			}
			if (m.find(x) == m.end()) {
				m[x] = x;
				v.push_front(x);
			}

	}
	printf("%d\n", v.size());
	for (int i = 0; i < v.size() - 1; i++)
		printf("%llu ", v[i]);
	printf("%llu", v[v.size() - 1]);
	return 0;
}


#include <iostream>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <map>
#define sf scanf
#define pf printf
using namespace std;

 int main(){

 int n,k,val,i,x,p,len;

    while (sf ("%d %d",&n,&k) != EOF)
    {
        map<int,int> mp;
        stack <int> st;

        for (i=1; i<=n; i++)
        {
            sf ("%d",&val);

            if (st.empty())
            {
                mp[val] = 1;
                st.push(val);
            }
            else
            {
                p = st.size()-mp[val]+1;

                if (mp[val] == 0 || (p > 0 && p > k))
                {
                    x = st.top();
                    mp[val] = mp[x]+1;
                    st.push(val);
                }
            }
        }

        if (st.size() > k)
            len = k;
        else
            len = st.size();

        pf ("%d\n%d",len,st.top());
        st.pop();
        --len;

        while (!st.empty())
        {
            if (!len)
                break;

            pf (" %d",st.top());
            --len;
            st.pop();
        }

        pf ("\n");
    }
 }


#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long int
using namespace std;
int main()
{
    vector<ll> s;
    vector<ll> :: iterator it;
    ll q,n;

    cin >> q >> n;

    for(ll i = 0;i < q;i++)
        {
            ll val;
            cin >> val;
            if(find(s.begin(),s.end(),val)==s.end())
            {
                if(s.size() == n)
                {

                    s.erase(s.begin());
                    s.push_back(val);
                }
                else
                {
                    s.push_back(val);
                }

            }
        }
        reverse(s.begin(),s.end());

        cout << s.size() << endl;

    for(it = s.begin();it != s.end();it++)
    {
        cout << *it << " ";
    }

}


#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long int
using namespace std;
int main()
{
    vector<int> s;
    vector<int> :: iterator it;
    ll q,n;

    cin >> q >> n;

    for(int i = 0;i < q;i++)
        {
            int val;
            cin >> val;
            if(find(s.begin(),s.end(),val)==s.end())
            {
                if(s.size() == n)
                {

                    s.erase(s.begin());
                    s.push_back(val);
                }
                else
                {
                    s.push_back(val);
                }

            }
        }
        reverse(s.begin(),s.end());

        cout << s.size() << endl;

    for(it = s.begin();it != s.end();it++)
    {
        cout << *it << " ";
    }

}


#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long int

using namespace std;
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    vector<ll> s;
    vector<ll> :: iterator it;
    ll q,n;

    cin >> q >> n;

    for(ll i = 0;i < q;i++)
        {
            ll val;
            cin >> val;
            if(find(s.begin(),s.end(),val)==s.end())
            {
                if(s.size() == n)
                {

                    s.erase(s.begin());
                    s.push_back(val);
                }
                else
                {
                    s.push_back(val);
                }

            }
        }
        reverse(s.begin(),s.end());

        cout << s.size() << endl;

    for(it = s.begin();it != s.end();it++)
    {
        cout << *it << " ";
    }

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int a[200001];
vector<long long> vec;
set<long long> myset;
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		bool found = false;
		int k = min(m, int(vec.size()));
		int q = myset.size();
		myset.insert(a[i]);
		if (q == myset.size()) found = true;

		if (!found) {
			if (vec.size() == m) {
				myset.erase(vec[0]);
				vec.erase(vec.begin());
			}
			vec.push_back(a[i]);
		}
	}
	m = min(m, int(vec.size()));
	cout << m << endl;
	for (int i = m-1; i >= 0; i--) {
		cout << vec[i] << " ";
	}
	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int a[200001];
vector<long long> vec;
set<long long> myset;
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		bool found = false;
		int q = myset.size();
		myset.insert(a[i]);
		if (q == myset.size()) found = true;

		if (!found) {
			if (vec.size() >= m) {
				myset.erase(vec[vec.size()-m]);
			}
			vec.push_back(a[i]);
		}
	}
	m = min(m, int(vec.size()));
	cout << m << endl;
	for (int i = m-1; i >= 0; i--) {
		cout << vec[i] << " ";
	}
	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int a[200001];
vector<long long> vec;
set<long long> myset;
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		bool found = false;
		int q = myset.size();
		myset.insert(a[i]);
		if (q == myset.size()) found = true;

		if (!found) {
			if (myset.size() > m) {
				myset.erase(vec[vec.size()-m]);
			}
			vec.push_back(a[i]);
		}
	}
	m = min(m, int(vec.size()));
	cout << m << endl;
	for (int i = m-1; i >= 0; i--) {
		cout << vec[i] << " ";
	}
	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int a[200001];
vector<long long> vec;
set<long long> myset;
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		bool found = false;
		int q = myset.size();
		myset.insert(a[i]);
		if (q == myset.size()) found = true;

		if (!found) {
			if (myset.size() >= m) {
				myset.erase(vec[vec.size()-m]);
			}
			vec.push_back(a[i]);
		}
	}
	m = min(m, int(vec.size()));
	cout << m << endl;
	for (int i = m-1; i >= 0; i--) {
		cout << vec[i] << " ";
	}
	cout << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int a[200001];
vector<long long> vec;
set<long long> myset;
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		bool found = false;
		int q = myset.size();
		myset.insert(a[i]);
		if (q == myset.size()) found = true;

		if (!found) {
			if (myset.size() > m) {
				myset.erase(vec[vec.size()-m]);
			}
			vec.push_back(a[i]);
		}
	}
	m = min(m, int(vec.size()));
	cout << m << endl;
	for (int i = 0; i < m; i++) {
		cout << vec[vec.size()-1-i] << " ";
	}
	cout << endl;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
const int maxn = 2e5 + 26;
deque<int> q;
map<int,bool> m;
int main()
{
    int n,k;
    while(scanf("%d%d",&n,&k))
    {
        m.clear();
        while(!q.empty())
            q.pop_front();
        int tmp;
        for(int i=0;i!=n;++i)
        {
            scanf("%d",&tmp);
            bool flag = m[tmp];
            if(!flag)
            {
                q.push_front(tmp);
                if(q.size() > k)
                {
                    int value = q.back();
                    q.pop_back();
                    m[value] = false;
                }
                m[tmp] = true;
            }
        }
        if(q.size())
            cout<<q[0];
        for(int i=1;i!=q.size();++i)
            cout<<" "<<q[i];
        cout<<endl;
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
const int maxn = 2e5 + 26;
deque<int> q;
map<int,bool> m;
int main()
{
    int n,k;
    while(scanf("%d%d",&n,&k)==2)
    {
        m.clear();
        q.clear();
        int tmp;
        for(int i=0;i!=n;++i)
        {
            scanf("%d",&tmp);
            if(!m[tmp])
            {
                q.push_front(tmp);
                if(q.size() > k)
                {
                    int value = q.back();
                    q.pop_back();
                    m[value] = false;
                }
                m[tmp] = true;
            }
        }
        cout<<q.size()<<endl;
        if(q.size())
            cout<<q[0];
        for(int i=1;i!=q.size();++i)
            cout<<" "<<q[i];
        cout<<endl;
    }
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<memory.h>
#include<queue>
#include<map>
using namespace std;

map<int,bool> m;
queue<int> q;
queue<int> b;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		q.push(a);
	}

	int cnt = 0;
	while (!q.empty()) {
		if (m[q.front()] == false)
		{
			if (cnt == k)
			{
				b.push(q.front());
				m[q.front()] = true;
				m[b.front()] = false;
				b.pop();

			}
			else
			{
				b.push(q.front());
				cnt++;
				m[q.front()] = true;

			}

		}
		q.pop();

	}

	int size = b.size();
	cout << size<<'\n';
	vector<int> aa;
	while (!b.empty()) {
		aa.push_back(b.front()); b.pop();
	}
	for (int i = size - 1; i>= 0; i--)
		cout << aa[i] << " ";

}


#include<iostream>
#include<algorithm>
#include<vector>
#include<memory.h>
#include<queue>
#include<map>
using namespace std;

map<int,bool> m;
queue<int> q;
vector<int> b;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		q.push(a);
	}
	int cnt = 0;
	while (!q.empty()) {
		if (m[q.front()] == false)
		{
			if (cnt == k)
			{
				b.insert(b.begin(), q.front());
				m[q.front()] = true;
				m[b.back()] = false;
				b.pop_back();

			}
			else
			{
				b.insert(b.begin(), q.front());
				cnt++;
				m[q.front()] = true;

			}

		}
		q.pop();

	}
	int size = b.size();
	cout << size<<'\n';
	for (int i = 0; i < size; i++)
		cout << b[i] << " ";

}


#include<iostream>
#include<algorithm>
#include<vector>
#include<memory.h>
#include<queue>
#include<map>
using namespace std;

map<int,bool> m;
queue<int> q;
vector<int> b;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		q.push(a);
	}
	int cnt = 0;
	while (!q.empty()) {
		if (m[q.front()] == false)
		{
			if (cnt == k)
			{
				b.insert(b.begin(), q.front());
				m[q.front()] = true;
				m[b.back()] = false;
				b.pop_back();

			}
			else
			{
				b.insert(b.begin(), q.front());

				cnt++;
				m[q.front()] = true;

			}

		}
		q.pop();

	}
	cout << b.size()<<'\n';
	for (int i = 0; i < b.size(); i++)
		cout << b[i] << " ";

}


#include<iostream>
#include<set>
#include<queue>
using namespace std;
queue<int> scr;
set<int> scrid;
int n, k;
const int maxn = 2e5 + 10;
int a[maxn], b[maxn], lisan[maxn];
int tree[4*maxn];
void add(int k, int x, int l, int r, int num) {
	if (l == r) {
		tree[k] += num;
		return;
	}
	int mid = (l + r) / 2;
	if (x <= mid) add(k * 2, x, l, mid, num);
	else add(k * 2 + 1, x, mid + 1, r, num);
	tree[k] += num;
}
int qq(int k, int x, int l, int r) {
	if (l == r)return tree[k];
	int mid = (l + r) / 2;
	if (x <= mid) return qq(k * 2, x, l, mid);
	else return qq(k * 2 + 1, x, mid + 1, r);
}
//inline int lowbit(int x) {
//	return x & (-x);
//}
//void modify(int x, int num) {
//	for (;x <= n; x += lowbit(x))
//		tree[x]+=num;
//}
//int query(int x) {
//	int sum = 0;
//	for (; x >= 1; x -= lowbit(x))
//		sum += tree[x];
//	return sum;
//}
int main() {
	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	int size = unique(b, b + n)-b;
	for (int i = 0; i < n; i++) {
		lisan[i] = lower_bound(b, b + size, a[i]) - b + 1;
	}

	int current = 0, pos = 0;
	while (current < k && pos < n) {
		if (qq(1, lisan[pos], 1, size)) {
			pos++;
			continue;
		}
		else {
			scr.push(lisan[pos]);
			add(1, lisan[pos], 1, size, 1);
			current++;
			pos++;
		}
	}
	while (pos < n) {
		if (qq(1, lisan[pos], 1, size)) {
			pos++;
			continue;
		}
		else {
			scr.push(lisan[pos]);
			add(1, lisan[pos], 1, size, 1);
			pos++;
			add(1, scr.front(), 1, size, -1);
			scr.pop();
		}
	}
	cout << current << endl;
	int ans[maxn];
	int ii = 0;
	while (!scr.empty()) {
		ans[ii++] = b[scr.front() - 1];
		scr.pop();
	}
	for (int i = ii - 1; i >= 0; i--)cout << ans[i] << ' ';
	return 0;
}


#include<iostream>
#include<set>
#include<queue>
using namespace std;
queue<int> scr;
set<int> scrid;
int n, k;
const int maxn = 2e5 + 10;
int a[maxn], b[maxn], lisan[maxn];
int tree[maxn];
void add(int k, int x, int l, int r, int num) {
	if (l == r) {
		tree[k] += num;
		return;
	}
	int mid = (l + r) / 2;
	if (x <= mid) add(k * 2, x, l, mid, num);
	else add(k * 2 + 1, x, mid + 1, r, num);
	tree[k] += num;
}
int qq(int k, int x, int l, int r) {
	if (l == r)return tree[k];
	int mid = (l + r) / 2;
	if (x <= mid) return qq(k * 2, x, l, mid);
	else return qq(k * 2 + 1, x, mid + 1, r);
}
//inline int lowbit(int x) {
//	return x & (-x);
//}
//void modify(int x, int num) {
//	for (;x <= n; x += lowbit(x))
//		tree[x]+=num;
//}
//int query(int x) {
//	int sum = 0;
//	for (; x >= 1; x -= lowbit(x))
//		sum += tree[x];
//	return sum;
//}
int main() {
	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	int size = unique(b, b + n)-b;
	for (int i = 0; i < n; i++) {
		lisan[i] = lower_bound(b, b + size, a[i]) - b + 1;
	}

	int current = 0, pos = 0;
	while (current < k && pos < n) {
		if (qq(1, lisan[pos], 1, size)) {
			pos++;
			continue;
		}
		else {
			scr.push(lisan[pos]);
			add(1, lisan[pos], 1, size, 1);
			current++;
			pos++;
		}
	}
	while (pos < n) {
		if (qq(1, lisan[pos], 1, size)) {
			pos++;
			continue;
		}
		else {
			scr.push(lisan[pos]);
			add(1, lisan[pos], 1, size, 1);
			pos++;
			add(1, scr.front(), 1, size, -1);
			scr.pop();
		}
	}
	cout << current << endl;
	int ans[maxn];
	int ii = 0;
	while (!scr.empty()) {
		ans[ii++] = b[scr.front() - 1];
		scr.pop();
	}
	for (int i = ii - 1; i >= 0; i--)cout << ans[i] << ' ';
	return 0;
}


#include <iostream>
#include <set>
#include <map>

using namespace std;

int main()
{

    int n, k;
    cin >> n >> k;
    map <int, int> map;
    set <pair <int, int>> s;
    int id;
    int time = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> id;
        if (map.count(id) == 0 || map[id] == -1)
        {
            if (s.size() == k)
            {
                map[s.begin()->second] = -1;
                s.erase(s.begin());
                time++;
                map[id] = time;
                s.insert({ time, id });

            }
            else
            {
                time++;
                map[id] = time;
                s.insert({ time,id });
            }
        }
    }
    cout << s.size()<<endl;
    for (auto elem=s.rbegin(); elem!=s.rend();elem++)
    {
        pair <int,int> tmp = *elem;
        cout << tmp.second << ' ';
    }
}


#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
map <long,long>mp;
int a[200005];
int main()
{
    long n,k,i,j=0,b;
    cin >>n;cin <<k;
    for(i=1;i<=n;i++)
    {
        cin >>b;
        if(mp[b])
        continue;
        mp[b]=1;
        a[++j]=b;
        if(j>k)
        mp(a[j-k])=0;
    }
    cout <<min(j,k)<<endl;
    for(i=j;i>=max(j-k+1,1);i--)
    cout <<a[i]<<" ";
}


#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
map <long,long>mp;
int a[200005];
int main()
{
    long n,k,i,j=0,b;
    cin >>n;cin >>k;
    for(i=1;i<=n;i++)
    {
        cin >>b;
        if(mp[b])
        continue;
        mp[b]=1;
        a[++j]=b;
        if(j>k)
        mp[a[j-k]]=0;
    }
    cout <<min(j,k)<<endl;
    if((j-k+1)<1){
    for(i=j;i>=1;--i)
    cout <<a[i]<<" ";}
    else{
     for(i=j;i>=j-k+1;--i)
    cout <<a[i]<<" ";
     }
}


#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
map <long,long>mp;
int a[200005];
int main()
{
    long n,k,i,j=0,b;
    cin >>n;cin >>k;
    for(i=1;i<=n;i++)
    {
        cin >>b;
        if(mp[b])
        continue;
        mp[b]=1;
        a[++j]=b;
        if(j>k)
        mp(a[j-k])=0;
    }
    cout <<min(j,k)<<endl;
    for(i=j;i>=max(j-k+1,1);i--)
    cout <<a[i]<<" ";
}


#include <iostream>
#include <cstdio>
//stl
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <bitset>

#define ll long long
#define ioio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const ll mod = 1000000007;
const double eps = 1e-9;
const double pi = acos(-1.0);
using namespace std;

ll binpow(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b == 1)
		return a;
	if (b % 2 == 0)
	{
		ll call = binpow(a, b / 2) % mod;
		return ((call % mod) * call) % mod;
	}
	if (b % 2 == 1)
	{
		return (binpow(a, b - 1) % mod) * a % mod;
	}
}

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<int>v(n);
	for (auto& i : v)
		cin >> i;
	set<int>s;
	stack<int>st;
	for (int i = 0; i < n; ++i)
	{
		if (s.count(v[i]) == 0)
		{
			if (st.size() == k)
			{
				s.erase(s.find(st.top()));
				st.pop();
				st.push(v[i]);
				s.insert(v[i]);
			}
			else
			{
				st.push(v[i]);
				s.insert(v[i]);
			}
		}
	}
	vector<int>ans;
	while (!st.empty())
	{
		ans.push_back(st.top());
		st.pop();
	}
	int x = ans.size();
	cout << x << endl;
	for (int i = 0; i < x; ++i)
		cout << ans[i] << ' ';
}

int main()
{
	ioio;
	/*int n;
	cin >> n;
	for (int i = 0; i < n; ++i)*/
	solve();
}


#include <iostream>
#include <cstdio>
//stl
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <bitset>

#define ll long long
#define ioio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const ll mod = 1000000007;
const double eps = 1e-9;
const double pi = acos(-1.0);
using namespace std;

ll binpow(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b == 1)
		return a;
	if (b % 2 == 0)
	{
		ll call = binpow(a, b / 2) % mod;
		return ((call % mod) * call) % mod;
	}
	if (b % 2 == 1)
	{
		return (binpow(a, b - 1) % mod) * a % mod;
	}
}

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<int>v(n);
	for (auto& i : v)
		cin >> i;
	set<int>s;
	deque<int>st;
	for (int i = 0; i < n; ++i)
	{
		if (s.count(v[i]) == 0)
		{
			if (st.size() == k)
			{
				s.erase(s.find(st.back()));
				st.pop_back();
				st.push_front(v[i]);
				s.insert(v[i]);
			}
			else
			{
				st.push_front(v[i]);
				s.insert(v[i]);
			}
		}
	}
	vector<int>ans;
	while (!st.empty())
	{
		ans.push_back(st.front());
		st.pop_front();
	}
	int x = ans.size();
	cout << x << endl;
	for (int i = 0; i < x; ++i)
		cout << ans[i] << ' ';
}

int main()
{
	ioio;
	/*int n;
	cin >> n;
	for (int i = 0; i < n; ++i)*/
	solve();
}