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

import static java.lang.Math.*;

public class MaxOrFunction implements Runnable
{
    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

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

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

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

        public String nextLine()
        {
            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);
        }
    }

	// if modulo is required set value accordingly
	public static long[][] matrixMultiply2dL(long t[][],long m[][])
	{
		long res[][]= new long[t.length][m[0].length];

		for(int i=0;i<t.length;i++)
		{
			for(int j=0;j<m[0].length;j++)
			{
				res[i][j]=0;
				for(int k=0;k<t[0].length;k++)
				{
					res[i][j]+=t[i][k]+m[k][j];
				}
			}
		}

		return res;
	}

	static long combination(long n,long r)
	{
		long ans=1;
		for(long i=0;i<r;i++)
		{
			ans=(ans*(n-i))/(i+1);
		}
		return ans;
	}

	static String toBinary(int x)
	{
		StringBuilder ans= new StringBuilder();
		for(int i=31;i>=0;--i)
		{
			int mask=1<<i;
			if((mask&x) !=0) ans.append("1");
			else ans.append("0");
		}
		return ans.toString();
	}

    public static void main(String args[]) throws Exception
    {
        new Thread(null, new MaxOrFunction(),"MaxOrFunction",1<<27).start();
    }
	// **just change the name of class from Main to reuquired**
    public void run()
    {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

		//System.out.println(toBinary(4));

		int n=sc.nextInt();
		int a[]= new int[n];
		for(int i=0;i<n;++i) a[i]=sc.nextInt();

		char ch[][]= new char[n][32];
		for(int i=0;i<n;++i)
		{
			ch[i]=toBinary(a[i]).toCharArray();
		}

		int index=-1;
		for(int i=0;i<=31;++i)
		{
			int counter=0;
			for(int j=0;j<n;++j)
			{
				if(ch[j][i]=='1' && counter==0)
				{
					index=j;
					counter++;
				}
				else if(ch[j][i]=='1' && counter!=0)
				{
					index=-1;
					counter=0;
					break;
				}
			}
			if(counter==1) break;
		}

		//for(int i=0;i<n;++i) System.out.println(a[i]+"-->"+Arrays.toString(ch[i]));
		//System.out.println("index:"+index);
		if(index!= -1) w.print(a[index]+" ");
		for(int i=0;i<n;++i)
		{
			if(i!=index) w.print(a[i]+" ");
		}

        System.out.flush();
        w.close();
    }
}


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

import static java.lang.Math.*;

public class MaxOrFunction implements Runnable
{
    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

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

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

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

        public String nextLine()
        {
            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);
        }
    }

	// if modulo is required set value accordingly
	public static long[][] matrixMultiply2dL(long t[][],long m[][])
	{
		long res[][]= new long[t.length][m[0].length];

		for(int i=0;i<t.length;i++)
		{
			for(int j=0;j<m[0].length;j++)
			{
				res[i][j]=0;
				for(int k=0;k<t[0].length;k++)
				{
					res[i][j]+=t[i][k]+m[k][j];
				}
			}
		}

		return res;
	}

	static long combination(long n,long r)
	{
		long ans=1;
		for(long i=0;i<r;i++)
		{
			ans=(ans*(n-i))/(i+1);
		}
		return ans;
	}

    public static void main(String args[]) throws Exception
    {
        new Thread(null, new MaxOrFunction(),"MaxOrFunction",1<<27).start();
    }
	// **just change the name of class from Main to reuquired**
    public void run()
    {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

		int n=sc.nextInt();
		Integer a[]= new Integer[n];
		for(int i=0;i<n;++i) a[i]=sc.nextInt();

		Arrays.sort(a);
		int i=0,j=0;
		for(i=n-1,j=n-2;i>=0;--i)
		{
			if(a[i]==-1) continue;

			while(j>=0 && a[j]==a[i]) j--;
			if(j<0) break;
			else
			{
				w.print(a[i]+" ");
				w.print(a[j]+" ");
				a[i]=-1;
				a[j]=-1;
				j--;
			}
		}

		if(i>=0)
		{
			while(i>=0)
			{
				w.println(a[i]+" ");
				i--;
			}
		}

        System.out.flush();
        w.close();
    }
}


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

import static java.lang.Math.*;

public class MaxOrFunction implements Runnable
{
    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

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

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

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

        public String nextLine()
        {
            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);
        }
    }

	// if modulo is required set value accordingly
	public static long[][] matrixMultiply2dL(long t[][],long m[][])
	{
		long res[][]= new long[t.length][m[0].length];

		for(int i=0;i<t.length;i++)
		{
			for(int j=0;j<m[0].length;j++)
			{
				res[i][j]=0;
				for(int k=0;k<t[0].length;k++)
				{
					res[i][j]+=t[i][k]+m[k][j];
				}
			}
		}

		return res;
	}

	static long combination(long n,long r)
	{
		long ans=1;
		for(long i=0;i<r;i++)
		{
			ans=(ans*(n-i))/(i+1);
		}
		return ans;
	}

    public static void main(String args[]) throws Exception
    {
        new Thread(null, new MaxOrFunction(),"MaxOrFunction",1<<27).start();
    }
	// **just change the name of class from Main to reuquired**
    public void run()
    {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

		int n=sc.nextInt();
		Integer a[]= new Integer[n];
		for(int i=0;i<n;++i) a[i]=sc.nextInt();

		Arrays.sort(a);

		if(n==1)
		{
			w.println(a[0]);
		}
		else
		{
			int index=0;
			for(index=0;index<n-1;++index)
			{
				if(a[index]!=0) break;
			}

			w.print(a[n-1]+" "+a[index]+" ");
			a[n-1]=-1;
			a[index]=-1;

			for(int i=n-1;i>=0;--i)
			{
				if(a[i]!=-1) w.print(a[i]+" ");
			}
		}

		int i=0,j=0;
		/*for(i=n-1,j=n-2;i>=0;--i)
		{
			if(a[i]==-1) continue;

			while(j>=0 && a[j]==a[i]) j--;
			if(j<0) break;
			else
			{
				w.print(a[i]+" ");
				w.print(a[j]+" ");
				a[i]=-1;
				a[j]=-1;
				j--;
			}
		}

		if(i>=0)
		{
			while(i>=0)
			{
				if(a[i]!=-1) w.print(a[i]+" ");
				i--;
			}
		}*/

        System.out.flush();
        w.close();
    }
}


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

import static java.lang.Math.*;

public class MaxOrFunction implements Runnable
{
    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

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

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

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

        public String nextLine()
        {
            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);
        }
    }

	// if modulo is required set value accordingly
	public static long[][] matrixMultiply2dL(long t[][],long m[][])
	{
		long res[][]= new long[t.length][m[0].length];

		for(int i=0;i<t.length;i++)
		{
			for(int j=0;j<m[0].length;j++)
			{
				res[i][j]=0;
				for(int k=0;k<t[0].length;k++)
				{
					res[i][j]+=t[i][k]+m[k][j];
				}
			}
		}

		return res;
	}

	static long combination(long n,long r)
	{
		long ans=1;
		for(long i=0;i<r;i++)
		{
			ans=(ans*(n-i))/(i+1);
		}
		return ans;
	}

    public static void main(String args[]) throws Exception
    {
        new Thread(null, new MaxOrFunction(),"MaxOrFunction",1<<27).start();
    }
	// **just change the name of class from Main to reuquired**
    public void run()
    {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

		int n=sc.nextInt();
		Integer a[]= new Integer[n];
		for(int i=0;i<n;++i) a[i]=sc.nextInt();

		Arrays.sort(a);
		int i=0,j=0;
		for(i=n-1,j=n-2;i>=0;--i)
		{
			if(a[i]==-1) continue;

			while(j>=0 && a[j]==a[i]) j--;
			if(j<0) break;
			else
			{
				w.print(a[i]+" ");
				w.print(a[j]+" ");
				a[i]=-1;
				a[j]=-1;
				j--;
			}
		}

		if(i>=0)
		{
			while(i>=0)
			{
				if(a[i]!=-1) w.print(a[i]+" ");
				i--;
			}
		}

        System.out.flush();
        w.close();
    }
}


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

import static java.lang.Math.*;

public class MaxOrFunction implements Runnable
{
    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream)
        {
            this.stream = stream;
        }

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

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

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

        public String nextLine()
        {
            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);
        }
    }

	// if modulo is required set value accordingly
	public static long[][] matrixMultiply2dL(long t[][],long m[][])
	{
		long res[][]= new long[t.length][m[0].length];

		for(int i=0;i<t.length;i++)
		{
			for(int j=0;j<m[0].length;j++)
			{
				res[i][j]=0;
				for(int k=0;k<t[0].length;k++)
				{
					res[i][j]+=t[i][k]+m[k][j];
				}
			}
		}

		return res;
	}

	static long combination(long n,long r)
	{
		long ans=1;
		for(long i=0;i<r;i++)
		{
			ans=(ans*(n-i))/(i+1);
		}
		return ans;
	}

	static String toBinary(int x)
	{
		StringBuilder ans= new StringBuilder();
		for(int i=31;i>=0;--i)
		{
			int mask=i<<i;
			if((mask&x) !=0) ans.append("1");
			else ans.append("0");
		}
		return ans.toString();
	}

    public static void main(String args[]) throws Exception
    {
        new Thread(null, new MaxOrFunction(),"MaxOrFunction",1<<27).start();
    }
	// **just change the name of class from Main to reuquired**
    public void run()
    {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

		int n=sc.nextInt();
		int a[]= new int[n];
		for(int i=0;i<n;++i) a[i]=sc.nextInt();

		char ch[][]= new char[n][32];
		for(int i=0;i<n;++i)
		{
			ch[i]=toBinary(a[i]).toCharArray();
		}

		int index=-1;
		for(int i=31;i>=0;--i)
		{
			int counter=0;
			for(int j=0;j<n;++j)
			{
				if(ch[j][i]=='1' && counter==0)
				{
					index=j;
					counter++;
				}
				else if(ch[j][i]=='1' && counter!=0)
				{
					index=-1;
					break;
				}
			}
			if(counter==1) break;
		}

		if(index!= -1) w.print(a[index]+" ");
		for(int i=0;i<n;++i)
		{
			if(i!=index) w.print(a[i]+" ");
		}

        System.out.flush();
        w.close();
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.*;
public class d6182
{
	public static void main (String[] args)
	 {
		Scanner sc=new Scanner(System.in);
		int t,i;
		t=1;
		double st=System.nanoTime();
		while(t>0)
		{
			t--;
			int n=sc.nextInt();
			Integer a[]=new Integer[n];
			int bc[]=new int[30];
			int j;
			for(i=0;i<n;i++)
			{
				a[i]=sc.nextInt();
				int v=a[i];
				j=0;
				while(v>0)
				{
					if(v%2!=0)
						bc[j]++;
					v/=2;
					j++;
				}
			}

			int max=0;
			for(i=0;i<n;i++)
			{
				int v=a[i];
				j=0;
				while(v>0)
				{
					if(v%2!=0)
						bc[j]--;
					v/=2;
					j++;
				}

				v=a[i];
				j=0;
				int cv=0;
				while(v>0)
				{
					if(v%2!=0)
					{
						if(bc[j]==0)
							cv+=Math.pow(2, j);
					}
					j++;
					v/=2;
				}
				v=a[i];
				j=0;
				while(v>0)
				{
					if(v%2!=0)
						bc[j]++;
					v/=2;
					j++;
				}
				if(cv>max)
				{
					int te=a[0];
					a[0]=a[i];
					a[i]=te;
					max=cv;
				}
			}
			for(i=0;i<n;i++)
				System.out.print(a[i]+" ");
			System.out.println();

		}
	}
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.*;
public class d6182
{
	public static void main (String[] args)
	 {
		Scanner sc=new Scanner(System.in);
		int t,i;
		t=1;
		double st=System.nanoTime();
		while(t>0)
		{
			t--;
			int n=sc.nextInt();
			Integer a[]=new Integer[n];
			int bc[]=new int[30];
			int j;
			for(i=0;i<n;i++)
			{
				a[i]=sc.nextInt();
				int v=a[i];
				j=0;
				while(v>0)
				{
					if(v%2!=0)
						bc[j]++;
					v/=2;
					j++;
				}
			}

			int max=0;
			for(i=0;i<n;i++)
			{
				int v=a[i];
				j=0;
				while(v>0)
				{
					if(v%2!=0)
						bc[j]--;
					v/=2;
					j++;
				}

				v=a[i];
				j=0;
				int cv=0;
				while(v>0)
				{
					if(v%2!=0)
					{
						if(bc[j]==0)
							cv+=Math.pow(2, j);
					}
					j++;
					v/=2;
				}
				v=a[i];
				j=0;
				while(v>0)
				{
					if(v%2!=0)
						bc[j]++;
					v/=2;
					j++;
				}
				if(cv>max)
				{
					int te=a[0];
					a[0]=a[i];
					a[i]=te;
				}
			}
			for(i=0;i<n;i++)
				System.out.print(a[i]+" ");
			System.out.println();

		}
	}
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.*;
public class d6182
{
	public static void main (String[] args)
	 {
		Scanner sc=new Scanner(System.in);
		int t,i;
		t=1;
		double st=System.nanoTime();
		while(t>0)
		{
			t--;
			int n=sc.nextInt();
			Integer a[]=new Integer[n];
			int bc[]=new int[30];
			int j;
			for(i=0;i<n;i++)
			{
				a[i]=sc.nextInt();
				int v=a[i];
				j=0;
				while(v>0)
				{
					if(v%2!=0)
						bc[j++]++;
					v/=2;
				}
			}

			int max=0;
			for(i=0;i<n;i++)
			{
				int v=a[i];
				j=0;
				while(v>0)
				{
					if(v%2!=0)
						bc[j++]--;
					v/=2;
				}

				v=a[i];
				j=0;
				int cv=0;
				while(v>0)
				{
					if(v%2!=0)
					{
						if(bc[j++]==0)
							cv+=Math.pow(2, j);
					}
					v/=2;
				}
				v=a[i];
				j=0;
				while(v>0)
				{
					if(v%2!=0)
						bc[j++]--;
					v/=2;
				}
				if(cv>max)
				{
					int te=a[0];
					a[0]=a[i];
					a[i]=te;
				}
			}
			for(i=0;i<n;i++)
				System.out.print(a[i]+" ");
			System.out.println();

		}
	}
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.*;
public class d6182
{
	public static void main (String[] args)
	 {
		Scanner sc=new Scanner(System.in);
		int t,i;
		t=1;
		double st=System.nanoTime();
		while(t>0)
		{
			t--;
			int n=sc.nextInt();
			Integer a[]=new Integer[n];
			for(i=0;i<n;i++)
			{
				a[i]=sc.nextInt();
			}
			Arrays.sort(a);

			for(i=n-1;i>=0;i--)
				System.out.print(a[i]+" ");
			System.out.println();

		}
	}
}


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

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

    static class CAnuHasAFunction {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = in.nextIntArray(n);
            int indi = -1;
            int c[] = new int[64];
            for (int i = 0; i < n; i++) {
                int temp = a[i];
                for (int j = 0; j < 64; j++) {
                    if (temp % 2 == 1) {
                        c[j]++;
                    }
                    temp /= 2;
                }
            }
            for (int i = 63; i >= 0; i--) {
                if (c[i] == 1) {
                    indi = i;
                    break;
                }
            }
            if (indi != -1) {
                int temp = (int) Math.pow(2, indi);
                for (int i = 0; i < n; i++) {
                    if ((a[i] & temp) > 0) {
                        indi = i;
                        break;
                    }
                }
                out.print(a[indi] + " ");
            }
            for (int i = 0; i < n; i++) if (indi != i) out.print(a[i] + " ");

        }

    }

    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[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class CAnuHasAFunction {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = in.nextIntArray(n);
            int max = -1;
            Arrays.sort(a);
            out.print(a[n - 1] + " ");
            for (int i = 0; i < n - 1; i++) out.print(a[i] + " ");

        }

    }

    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[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

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

    }
}


/*
javac c.java && java c
*/

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

public class c {
	public static void main(String[] args) { new c(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);

	int n;
	int[] a;

	c() {
		n = in.nextInt();
		a = new int[n];
		for (int i = 0; i < n; i++) a[i] = in.nextInt();
		sort(a);

		for (int i = n - 1; i >= 0; i--)
			out.print(a[i] + " ");
		out.println();
		out.close();
	}

	int abs(int x) { return x < 0 ? -x : x; }
	long abs(long x) { return x < 0 ? -x : x; }
	double abs(double x) { return x < 0 ? -x : x; }
	int min(int x, int y) { return x < y ? x : y; }
	int max(int x, int y) { return x > y ? x : y; }
	long min(long x, long y) { return x < y ? x : y; }
	long max(long x, long y) { return x > y ? x : y; }
	double min(double x, double y) { return x < y ? x : y; }
	double max(double x, double y) { return x > y ? x : y; }
	int gcd(int x, int y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long gcd(long x, long y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long lcm(int x, int y) { return ((long) x / gcd(x, y)) * y; }
	long lcm(long x, long y) { return (x / gcd(x, y)) * y; }

	void sort(int[] arr) {
		int sz = arr.length, j;
		Random r = new Random();
		for (int i = 0; i < sz; i++) {
			j = r.nextInt(i + 1);
			arr[i] = arr[j]^(arr[i]^(arr[j] = arr[i]));
		} Arrays.sort(arr);
	}

	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}


/*
javac c.java && java c
*/

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

public class c {
	public static void main(String[] args) { new c(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);

	int n;
	int[] a;

	c() {
		n = in.nextInt();
		a = new int[n];
		for (int i = 0; i < n; i++) a[i] = in.nextInt();
		sort(a);

		// mp[x] > 1 --> no bit from x is on in answer
		// only bit from st will be on
		// want leftmost bit that only occurs once

		int[] occ = new int[32];
		for (int j = 0; j < 32; j++) {
			int b = (1 << j);
			for (int i = 0; i < n; i++)
				if ((a[i] & b) == b)
					occ[j]++;
		}
		int st = -1;
		for (int i = 0; i < 32; i++)
			if (occ[i] == 1) {
				st = i;
				break;
			}
		if (st == -1) {
			for (int i : a) out.print(i + " ");
			out.println();
		}
		else {
			int put = -1, hobo = (1 << st);
			for (int i = 0; i < n; i++)
				if ((a[i] & hobo) == hobo) {
					put = i;
					break;
				}
			out.print(a[put] + " ");
			for (int i = 0; i < n; i++)
				if (i != put)
					out.print(a[i] + " ");
			out.println();
		}
		out.close();
	}

	int abs(int x) { return x < 0 ? -x : x; }
	long abs(long x) { return x < 0 ? -x : x; }
	double abs(double x) { return x < 0 ? -x : x; }
	int min(int x, int y) { return x < y ? x : y; }
	int max(int x, int y) { return x > y ? x : y; }
	long min(long x, long y) { return x < y ? x : y; }
	long max(long x, long y) { return x > y ? x : y; }
	double min(double x, double y) { return x < y ? x : y; }
	double max(double x, double y) { return x > y ? x : y; }
	int gcd(int x, int y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long gcd(long x, long y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long lcm(int x, int y) { return ((long) x / gcd(x, y)) * y; }
	long lcm(long x, long y) { return (x / gcd(x, y)) * y; }

	void sort(int[] arr) {
		int sz = arr.length, j;
		Random r = new Random();
		for (int i = 0; i < sz; i++) {
			j = r.nextInt(i + 1);
			arr[i] = arr[j]^(arr[i]^(arr[j] = arr[i]));
		} Arrays.sort(arr);
	}

	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}


/*
javac c.java && java c
*/

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

public class c {
	public static void main(String[] args) { new c(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);

	int n;
	int[] a;

	c() {
		n = in.nextInt();
		a = new int[n];
		for (int i = 0; i < n; i++) a[i] = in.nextInt();
		sort(a);

		// mp[x] > 1 --> no bit from x is on in answer
		// only bit from st will be on
		// want leftmost bit that only occurs once

		int[] occ = new int[32];
		for (int j = 0; j < 32; j++) {
			int b = (1 << j);
			for (int i = 0; i < n; i++)
				if ((a[i] & b) == b)
					occ[j]++;
		}
		int st = -1;
		for (int i = 31; i >= 0; i--)
			if (occ[i] == 1) {
				st = i;
				break;
			}
		if (st == -1) {
			for (int i : a) out.print(i + " ");
			out.println();
		}
		else {
			int put = -1, hobo = (1 << st);
			for (int i = 0; i < n; i++)
				if ((a[i] & hobo) == hobo) {
					put = i;
					break;
				}
			out.print(a[put] + " ");
			for (int i = 0; i < n; i++)
				if (i != put)
					out.print(a[i] + " ");
			out.println();
		}
		out.close();
	}

	int abs(int x) { return x < 0 ? -x : x; }
	long abs(long x) { return x < 0 ? -x : x; }
	double abs(double x) { return x < 0 ? -x : x; }
	int min(int x, int y) { return x < y ? x : y; }
	int max(int x, int y) { return x > y ? x : y; }
	long min(long x, long y) { return x < y ? x : y; }
	long max(long x, long y) { return x > y ? x : y; }
	double min(double x, double y) { return x < y ? x : y; }
	double max(double x, double y) { return x > y ? x : y; }
	int gcd(int x, int y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long gcd(long x, long y) { while (y > 0) { x = y^(x^(y = x)); y %= x; } return x; }
	long lcm(int x, int y) { return ((long) x / gcd(x, y)) * y; }
	long lcm(long x, long y) { return (x / gcd(x, y)) * y; }

	void sort(int[] arr) {
		int sz = arr.length, j;
		Random r = new Random();
		for (int i = 0; i < sz; i++) {
			j = r.nextInt(i + 1);
			arr[i] = arr[j]^(arr[i]^(arr[j] = arr[i]));
		} Arrays.sort(arr);
	}

	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}


// No sorceries shall previal. //
import java.io.*;
import java.util.*;

public class _InVoker_ {
	static long mod = 1000000007;
    public static void sort(long arr[], int start, int end) {
		if(start>=end)
			return;
		int mid=(start+end)/2;
		sort(arr,start,mid);
		sort(arr,mid+1,end);
		merge(arr,start,mid,end);
	}
	private static void merge(long arr[], int start, int mid, int end) {
		int i, j=mid+1,c=0;
		long temp[]= new long[end-start+1];
		for(i=start;i<=mid && j<=end;c++) {
			if(arr[i]<=arr[j]) {
				temp[c]=arr[i];
				i++;
			}
			else {
				temp[c]=arr[j];
				j++;
			}
		}
		while(i<=mid) {
			temp[c]=arr[i];
			i++;c++;
		}
		while(j<=end) {
			temp[c]=arr[j];
			j++;c++;
		}
		c=0;
		for(i=start;i<=end;i++,c++)
			arr[i]=temp[c];
	}
	static long gcd(long a, long b)
    {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
	static class Pair {
		int u, v;
		public Pair(int u, int v) {
			this.u = u;
			this.v = v;
		}
	}

	public static void main(String args[]) {

    	Scanner inp=new Scanner(System.in);
    	PrintWriter out= new PrintWriter(System.out);

    	int n=inp.nextInt();
		long a[]=new long[n];
		for(int i=0;i<n;i++)
			a[i]=inp.nextLong();
		sort(a,0,n-1);
		out.print(a[n-1]+" ");
		for(int i=0;i<n-1;i++) {
			out.print(a[i]+" ");
		}

    	inp.close();
    	out.close();
    }
}


// No sorceries shall previal. //
import java.io.*;
import java.util.*;

public class _InVoker_ {
	static long mod = 1000000007;
    public static void sort(long arr[], int start, int end) {
		if(start>=end)
			return;
		int mid=(start+end)/2;
		sort(arr,start,mid);
		sort(arr,mid+1,end);
		merge(arr,start,mid,end);
	}
	private static void merge(long arr[], int start, int mid, int end) {
		int i, j=mid+1,c=0;
		long temp[]= new long[end-start+1];
		for(i=start;i<=mid && j<=end;c++) {
			if(arr[i]<=arr[j]) {
				temp[c]=arr[i];
				i++;
			}
			else {
				temp[c]=arr[j];
				j++;
			}
		}
		while(i<=mid) {
			temp[c]=arr[i];
			i++;c++;
		}
		while(j<=end) {
			temp[c]=arr[j];
			j++;c++;
		}
		c=0;
		for(i=start;i<=end;i++,c++)
			arr[i]=temp[c];
	}
	static long gcd(long a, long b)
    {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
	static class Pair {
		int u, v;
		public Pair(int u, int v) {
			this.u = u;
			this.v = v;
		}
	}

	public static void main(String args[]) {

    	Scanner inp=new Scanner(System.in);
    	PrintWriter out= new PrintWriter(System.out);

    	int n=inp.nextInt();
		long a[]=new long[n];
		for(int i=0;i<n;i++)
			a[i]=inp.nextLong();
		sort(a,0,n-1);
		for(int i=0;i<n/2;i++) {
			long x=a[i];
			a[i]=a[n-i-1];
			a[n-1-i]=x;
		}
		if(n==1) {
			out.println(a[0]);
		}
		else {
			int dontPrint=-1;
			long max=0;
			for(int i=1;i<n;i++) {
				long x=(a[0]|a[i])-a[i];
				if(x>max) {
					max=x;
					dontPrint=i;
				}
			}
			out.print(a[0]+" "+a[dontPrint]+" ");
			for(int i=1;i<n;i++) {
				if(i!=dontPrint)
					out.print(a[i]+" ");
			}
			out.println();
		}

    	inp.close();
    	out.close();
    }
}


// No sorceries shall previal. //
import java.io.*;
import java.util.*;

public class _InVoker_ {
	static long mod = 1000000007;
    public static void sort(long arr[], int start, int end) {
		if(start>=end)
			return;
		int mid=(start+end)/2;
		sort(arr,start,mid);
		sort(arr,mid+1,end);
		merge(arr,start,mid,end);
	}
	private static void merge(long arr[], int start, int mid, int end) {
		int i, j=mid+1,c=0;
		long temp[]= new long[end-start+1];
		for(i=start;i<=mid && j<=end;c++) {
			if(arr[i]<=arr[j]) {
				temp[c]=arr[i];
				i++;
			}
			else {
				temp[c]=arr[j];
				j++;
			}
		}
		while(i<=mid) {
			temp[c]=arr[i];
			i++;c++;
		}
		while(j<=end) {
			temp[c]=arr[j];
			j++;c++;
		}
		c=0;
		for(i=start;i<=end;i++,c++)
			arr[i]=temp[c];
	}
	static long gcd(long a, long b)
    {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
	static class Pair {
		int u, v;
		public Pair(int u, int v) {
			this.u = u;
			this.v = v;
		}
	}

	public static void main(String args[]) {

    	Scanner inp=new Scanner(System.in);
    	PrintWriter out= new PrintWriter(System.out);

    	int n=inp.nextInt();
		long a[]=new long[n];
		for(int i=0;i<n;i++)
			a[i]=inp.nextLong();
		sort(a,0,n-1);
		for(int i=0;i<n/2;i++) {
			long x=a[i];
			a[i]=a[n-i-1];
			a[n-1-i]=x;
		}
		if(n==1) {
			out.println(a[0]);
		}
		else {
			boolean sameStart=a[0]==a[1];
			int dontPrint=-1;
			int dontPrint2=-1;
			if(sameStart) {
				for(int i=1;i<n;i++) {
					if(a[i]!=a[i-1]) {
						out.print(a[i-1]+" "+a[i]+" ");
						dontPrint=i;
						dontPrint2=i-1;
						break;
					}
				}
			}
			for(int i=0;i<n;i++) {
				if(i!=dontPrint && i!=dontPrint2)
					out.print(a[i]+" ");
			}
			out.println();
		}

    	inp.close();
    	out.close();
    }
}


// No sorceries shall previal. //
import java.io.*;
import java.util.*;

public class _InVoker_ {
	static long mod = 1000000007;
    public static void sort(long arr[], int start, int end) {
		if(start>=end)
			return;
		int mid=(start+end)/2;
		sort(arr,start,mid);
		sort(arr,mid+1,end);
		merge(arr,start,mid,end);
	}
	private static void merge(long arr[], int start, int mid, int end) {
		int i, j=mid+1,c=0;
		long temp[]= new long[end-start+1];
		for(i=start;i<=mid && j<=end;c++) {
			if(arr[i]<=arr[j]) {
				temp[c]=arr[i];
				i++;
			}
			else {
				temp[c]=arr[j];
				j++;
			}
		}
		while(i<=mid) {
			temp[c]=arr[i];
			i++;c++;
		}
		while(j<=end) {
			temp[c]=arr[j];
			j++;c++;
		}
		c=0;
		for(i=start;i<=end;i++,c++)
			arr[i]=temp[c];
	}
	static long gcd(long a, long b)
    {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
	static class Pair {
		int u, v;
		public Pair(int u, int v) {
			this.u = u;
			this.v = v;
		}
	}

	public static void main(String args[]) {

    	Scanner inp=new Scanner(System.in);
    	PrintWriter out= new PrintWriter(System.out);

    	int n=inp.nextInt();
    	int a[]=new int[n];
    	int b[][]=new int[n][32];
    	for(int i=0;i<n;i++) {
    		a[i]=inp.nextInt();
    		int x=a[i];
    		int j=31;
    		while(x>0) {
    			if(x%2==1)
    					b[i][j]=1;
    			j--;
    			x/=2;
    		}
    	}
    	int dontPrint=-1;
    	for(int j=0;j<32;j++) {
    		int c=0;
    		int index=-1;
    		for(int i=0;i<n;i++) {
    			if(b[i][j]==1) {
    				c++;
    				index=i;
    			}
    		}
    		if(c==1) {
    			out.print(a[index]+" ");
    			dontPrint=index;
    			break;
    		}
    	}
    	for(int i=0;i<n;i++) {
    		if(i!=dontPrint)
    			out.print(a[i]+" ");
    	}

    	inp.close();
    	out.close();
    }
}


// No sorceries shall previal. //
import java.io.*;
import java.util.*;

public class _InVoker_ {
	static long mod = 1000000007;
    public static void sort(long arr[], int start, int end) {
		if(start>=end)
			return;
		int mid=(start+end)/2;
		sort(arr,start,mid);
		sort(arr,mid+1,end);
		merge(arr,start,mid,end);
	}
	private static void merge(long arr[], int start, int mid, int end) {
		int i, j=mid+1,c=0;
		long temp[]= new long[end-start+1];
		for(i=start;i<=mid && j<=end;c++) {
			if(arr[i]<=arr[j]) {
				temp[c]=arr[i];
				i++;
			}
			else {
				temp[c]=arr[j];
				j++;
			}
		}
		while(i<=mid) {
			temp[c]=arr[i];
			i++;c++;
		}
		while(j<=end) {
			temp[c]=arr[j];
			j++;c++;
		}
		c=0;
		for(i=start;i<=end;i++,c++)
			arr[i]=temp[c];
	}
	static long gcd(long a, long b)
    {
      if (b == 0)
        return a;
      return gcd(b, a % b);
    }
	static class Pair {
		int u, v;
		public Pair(int u, int v) {
			this.u = u;
			this.v = v;
		}
	}

	public static void main(String args[]) {

    	Scanner inp=new Scanner(System.in);
    	PrintWriter out= new PrintWriter(System.out);

    	int n=inp.nextInt();
    	int a[]=new int[n];
    	int b[][]=new int[n][32];
    	for(int i=0;i<n;i++) {
    		a[i]=inp.nextInt();
    		int x=a[i];
    		int j=31;
    		while(x>0) {
    			if(a[i]%2==1)
    					b[i][j]=1;
    			j--;
    			x/=2;
    		}
    	}
    	int dontPrint=-1;
    	for(int j=0;j<32;j++) {
    		int c=0;
    		int index=-1;
    		for(int i=0;i<n;i++) {
    			if(b[i][j]==1) {
    				c++;
    				index=i;
    			}
    		}
    		if(c==1) {
    			out.print(a[index]+" ");
    			dontPrint=index;
    			break;
    		}
    	}
    	for(int i=0;i<n;i++) {
    		if(i!=dontPrint)
    			out.print(a[i]+" ");
    	}

    	inp.close();
    	out.close();
    }
}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main7
{
	static class Pair
	{
		int x;
		int y;
		public Pair(int x, int y)
		{
			this.x=x;
			this.y=y;
		}

   /* @Override
            public int hashCode()
            {
                final int temp = 14;
                int ans = 1;
                ans =x*31+y*13;
                return ans;
            }

            // Equal objects must produce the same
            // hash code as long as they are equal
        @Override
        public boolean equals(Object o)
        {
            if (this == o) {
                return true;
            }
            if (o == null) {
                return false;
            }
            if (this.getClass() != o.getClass()) {
                return false;
            }
            Pair other = (Pair)o;
            if (this.x != other.x || this.y!=other.y) {
                return false;
            }
            return true;
        }*/
	}
	static class Pair1
	{
		int x;
		int y;
		long z;
		Pair1(int x, int y, long z)
		{
			this.x=x;
			this.y=y;
			this.z=z;
		}
	}
    public static long pow(long a, long b)
    {
        long result=1;
        while(b>0)
        {
            if (b % 2 != 0)
            {
                result=(result*a);
                b--;
            }
            a=(a*a);
            b /= 2;
        }
        return result;
    }
    public static long fact(long num)
    {
		long value=1;
		int i=0;
		for(i=2;i<num;i++)
		{
			value=((value%mod)*i%mod)%mod;
		}
		return value;
	}
	public static long gcd(long a, long b)
	{
		if (a == 0)
			return b;
		return gcd(b%a, a);
	}
	public static long lcm(long a,long b)
	{
		return a * (b / gcd(a, b));
	}
/*   public static void dfs(int parent,boolean[] visited,int[] dp)
	{
		ArrayList<Integer> arr=new ArrayList<Integer>();
		arr=graph.get(parent);
		visited[parent]=true;
		for(int i=0;i<arr.size();i++)
		{
			int num=(int)arr.get(i);
			if(visited[num]==false)
			{
				dfs(num,visited,dp);
			}
			dp[parent]=Math.max(dp[num]+1,dp[parent]);
		}
	}
//  static int flag1=0;
	static int[] dis;*/
	static int mod=1000000007;
	static ArrayList<ArrayList<Integer>> graph;
	static ArrayList<ArrayList<Integer>> g;
/*    public static void bfs(int num,int size)
	{
		boolean[] visited=new boolean[size+1];
		Queue<Integer> q=new LinkedList<>();
		q.add(num);
		ans[num]=1;
		visited[num]=true;
		while(!q.isEmpty())
		{
			int x=q.poll();
			ArrayList<Integer> al=graph.get(x);
			for(int i=0;i<al.size();i++)
			{
				int y=al.get(i);
				if(visited[y]==false)
				{
					q.add(y);
					ans[y]=ans[x]+1;
					visited[y]=true;
				}
			}
		}
	}
	static int[] ans;*/
	public static int[] sort(int[] a)
	{
		int n=a.length;
		ArrayList<Integer> ar=new ArrayList<>();
		for(int i=0;i<a.length;i++)
		{
			ar.add(a[i]);
		}
		Collections.sort(ar);
		for(int i=0;i<n;i++)
		{
			a[i]=ar.get(i);
		}
		return a;
	}
	static int find(int num)
	{
		if(parent[num]!=num)
		{
			parent[num]=find(parent[num]);
		}
		return parent[num];
	}
	static void union(int x , int y )
	{
		int xroot = find(x);
		int yroot = find(y);

		if (rank[xroot] < rank[yroot])
		{
			parent[xroot] = yroot;
			size[yroot]+=size[xroot];
			size[xroot]=size[yroot];
		}
		else if (rank[yroot] < rank[xroot])
		{
			parent[yroot] = xroot;
			size[xroot]+=size[yroot];
			size[yroot]=size[xroot];
		}
		else
		{
			parent[xroot] = yroot;
			rank[yroot]++;
			size[yroot]+=size[xroot];
			size[xroot]=size[yroot];
		}
	}
	static int[] parent;
	static int[] rank;
	static int[] size;
	static public void main(String args[])throws IOException
	{
		int tt=1;
		while(tt-->0)
		{
			int n=i();
			int[] a=new int[n];
			int max=0;
			int index=0;
			for(int i=0;i<n;i++)
			{
				a[i]=i();
			}
			a=sort(a);
			max=a[n-1];
			ArrayList<Integer> ans=new ArrayList<>();
			int[] count=new int[n-1];
			Pair[] pair=new Pair[n-1];
			for(int i=0;i<n-1;i++)
			{
				int  tmp=a[i]&max;
				int  ct=Long.bitCount(tmp);
				count[i]=ct;
				pair[i]=new Pair(count[i],i);
			}
			Arrays.sort(pair,new Comparator<Pair>(){
				@Override
				public int compare(Pair p1, Pair p2)
				{
					if(p1.x>p2.x)
					{
						return 1;
					}
					else
						return -1;
				}
			});
			ans.add(max);
			ArrayList<Integer> ar=new ArrayList<>();
			int[] flag=new int[n-1];
			for(int i=0;i<n-1;i++)
			{
				if(pair[i].x==0)
				{
					ans.add(a[pair[i].y]);
					flag[i]=1;
				}
				else
				{
					break;
				}
			}
			for(int i=0;i<n-1;i++)
			{
				if(flag[i]==0)
					ar.add(a[pair[i].y]);
			}
			Collections.sort(ar);
			for(int i=0;i<ar.size();i++)
			{
				ans.add(ar.get(i));
			}
			for(int i=0;i<n;i++)
			{
				System.out.print(ans.get(i)+" ");
			}
			pln("");
		}
		//System.out.print(sb.toString());
	}
			/**/
	static InputReader in=new InputReader(System.in);
	static OutputWriter out=new OutputWriter(System.out);
	public static long l()
	{
		String s=in.String();
		return Long.parseLong(s);
	}
	public static void pln(String value)
	{
		System.out.println(value);
	}
	public static int i()
	{
		return in.Int();
	}
	public static String s()
	{
		return in.String();
	}
}
	class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars== -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int Int() {
			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 String String() {
			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 String();
		}

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

	class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object...objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void printLine(Object...objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}

		}

		class IOUtils {

		public static int[] readIntArray(InputReader in, int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++)
				array[i] = in.Int();
			return array;
		}

	}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main7
{
	static class Pair
	{
		int x;
		int y;
		public Pair(int x, int y)
		{
			this.x=x;
			this.y=y;
		}

   /* @Override
            public int hashCode()
            {
                final int temp = 14;
                int ans = 1;
                ans =x*31+y*13;
                return ans;
            }

            // Equal objects must produce the same
            // hash code as long as they are equal
        @Override
        public boolean equals(Object o)
        {
            if (this == o) {
                return true;
            }
            if (o == null) {
                return false;
            }
            if (this.getClass() != o.getClass()) {
                return false;
            }
            Pair other = (Pair)o;
            if (this.x != other.x || this.y!=other.y) {
                return false;
            }
            return true;
        }*/
	}
	static class Pair1
	{
		int x;
		int y;
		long z;
		Pair1(int x, int y, long z)
		{
			this.x=x;
			this.y=y;
			this.z=z;
		}
	}
    public static long pow(long a, long b)
    {
        long result=1;
        while(b>0)
        {
            if (b % 2 != 0)
            {
                result=(result*a);
                b--;
            }
            a=(a*a);
            b /= 2;
        }
        return result;
    }
    public static long fact(long num)
    {
		long value=1;
		int i=0;
		for(i=2;i<num;i++)
		{
			value=((value%mod)*i%mod)%mod;
		}
		return value;
	}
	public static long gcd(long a, long b)
	{
		if (a == 0)
			return b;
		return gcd(b%a, a);
	}
	public static long lcm(long a,long b)
	{
		return a * (b / gcd(a, b));
	}
/*   public static void dfs(int parent,boolean[] visited,int[] dp)
	{
		ArrayList<Integer> arr=new ArrayList<Integer>();
		arr=graph.get(parent);
		visited[parent]=true;
		for(int i=0;i<arr.size();i++)
		{
			int num=(int)arr.get(i);
			if(visited[num]==false)
			{
				dfs(num,visited,dp);
			}
			dp[parent]=Math.max(dp[num]+1,dp[parent]);
		}
	}
//  static int flag1=0;
	static int[] dis;*/
	static int mod=1000000007;
	static ArrayList<ArrayList<Integer>> graph;
	static ArrayList<ArrayList<Integer>> g;
/*    public static void bfs(int num,int size)
	{
		boolean[] visited=new boolean[size+1];
		Queue<Integer> q=new LinkedList<>();
		q.add(num);
		ans[num]=1;
		visited[num]=true;
		while(!q.isEmpty())
		{
			int x=q.poll();
			ArrayList<Integer> al=graph.get(x);
			for(int i=0;i<al.size();i++)
			{
				int y=al.get(i);
				if(visited[y]==false)
				{
					q.add(y);
					ans[y]=ans[x]+1;
					visited[y]=true;
				}
			}
		}
	}
	static int[] ans;*/
	public static int[] sort(int[] a)
	{
		int n=a.length;
		ArrayList<Integer> ar=new ArrayList<>();
		for(int i=0;i<a.length;i++)
		{
			ar.add(a[i]);
		}
		Collections.sort(ar);
		for(int i=0;i<n;i++)
		{
			a[i]=ar.get(i);
		}
		return a;
	}
	static int find(int num)
	{
		if(parent[num]!=num)
		{
			parent[num]=find(parent[num]);
		}
		return parent[num];
	}
	static void union(int x , int y )
	{
		int xroot = find(x);
		int yroot = find(y);

		if (rank[xroot] < rank[yroot])
		{
			parent[xroot] = yroot;
			size[yroot]+=size[xroot];
			size[xroot]=size[yroot];
		}
		else if (rank[yroot] < rank[xroot])
		{
			parent[yroot] = xroot;
			size[xroot]+=size[yroot];
			size[yroot]=size[xroot];
		}
		else
		{
			parent[xroot] = yroot;
			rank[yroot]++;
			size[yroot]+=size[xroot];
			size[xroot]=size[yroot];
		}
	}
	static int[] parent;
	static int[] rank;
	static int[] size;
	static public void main(String args[])throws IOException
	{
		int tt=1;
		while(tt-->0)
		{
			int n=i();
			int[] a=new int[n];
			int max=0;
			int index=0;
			for(int i=0;i<n;i++)
			{
				a[i]=i();
			}
			a=sort(a);
			ArrayList<Integer> ans=new ArrayList<>();
			int[] pp=new int[33];
			for(int i=0;i<n;i++)
			{
				String s=Integer.toBinaryString(a[i]);
				int o=0;
				for(int j=s.length()-1;j>=0;j--)
				{
					if(s.charAt(j)=='1')
						pp[o]++;
					o++;
				}
			}
			int mine=0;
			for(int j=0;j<33;j++)
			{
				if(pp[j]==1)
					mine=1;
			}
			if(mine==0)
			{
				for(int i=n-1;i>=0;i--)
				{
					System.out.print(a[i]+" ");
				}
				pln("");
			}
			else
			{
				for(int i=32;i>=0;i--)
				{
					if(pp[i]==1)
					{
						mine=i;
						break;
					}
				}
				int number=-1;
				int[] tp=new int[n];
				for(int j=0;j<n;j++)
				{
					String s=Integer.toBinaryString(a[j]);
					int f=0;
					for(int i=s.length()-1;i>=0;i--)
					{
						if(f==mine && s.charAt(i)=='1')
						{
							number=a[j];
							tp[j]=1;
							break;
						}
						f++;
					}
					if(number!=-1)
						break;
				}
				ans.add(number);
				for(int i=0;i<n;i++)
				{
					if(tp[i]!=1)
					{
						ans.add(a[i]);
					}
				}
				for(int i=0;i<n;i++)
				{
					System.out.print(ans.get(i)+" ");
				}
				pln("");
			}
		}
		//System.out.print(sb.toString());
	}
			/**/
	static InputReader in=new InputReader(System.in);
	static OutputWriter out=new OutputWriter(System.out);
	public static long l()
	{
		String s=in.String();
		return Long.parseLong(s);
	}
	public static void pln(String value)
	{
		System.out.println(value);
	}
	public static int i()
	{
		return in.Int();
	}
	public static String s()
	{
		return in.String();
	}
}
	class InputReader
	{
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars== -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int Int() {
			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 String String() {
			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 String();
		}

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

	class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object...objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void printLine(Object...objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}

		}

		class IOUtils {

		public static int[] readIntArray(InputReader in, int size) {
			int[] array = new int[size];
			for (int i = 0; i < size; i++)
				array[i] = in.Int();
			return array;
		}

	}


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

public class C {

    static class Pair<U extends Comparable<U>, V extends Comparable<V>>
            implements Comparable<Pair<U,V>>{

        public final U a;
        public final V b;

        private Pair(U a, V b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;

            Pair<?, ?> pair = (Pair<?, ?>) o;
            if (!a.equals(pair.a))
                return false;
            return b.equals(pair.b);
        }

        @Override
        public int hashCode() {
            return 31 * a.hashCode() + b.hashCode();
        }

        @Override
        public String toString() {
            return "(" + a + ", " + b + ")";
        }

        @Override
        public int compareTo(Pair<U, V> o) {
            if(this.a.equals(o.a)){
                return getV().compareTo(o.getV());
            }
            return getU().compareTo(o.getU());
        }
        private U getU() {
            return a;
        }
        private V getV() {
            return b;
        }
        static void print(Pair[] pairs){
            for(int i=0;i<pairs.length;i++){
                System.out.print(pairs[i]+" ");
            }
            System.out.println();
        }
        static void print(Pair[][] pairs){

            for(int i=0;i<pairs.length;i++){
                for(int j=0;j<pairs[0].length;j++) {
                    System.out.print(pairs[i] + " ");
                }
                System.out.println();
            }
        }
    }

    static BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    static long modulo = 1000000007l;
    static int max = 0;
    static int value = 0;
    static int[] count = new int[32];

    public static void main(String[] args) throws IOException {

        int size = Integer.parseInt(inp.readLine());
        int[] given = new int[size];
        String[] s1 = inp.readLine().split(" ");
        for(int i=0;i<size;i++){
            given[i] = Integer.parseInt(s1[i]);
            decToBinary(given[i]);
        }

        for(int i=0;i<size;i++){
            int a = given[i];
            sol(a);
        }

        out.write(value+" ");
        for(int i=0;i<size;i++){
            if(given[i]!=value)
            out.write(given[i]+" ");
        }

        out.flush();

    }
    public static void sol(int n)
    {
        int[] a = new int[32];
        for (int i = 31; i >= 0; i--) {
            int k = n >> i;
            if ((k & 1) > 0 && count[i]==1)
                a[i]++;
        }
        int b = 0;
        int g = 1;
        for(int i=0;i<32;i++){
            b+=g*a[i];
            g*=2;
        }
        if(max<b){
            max = b;
            value = n;
        }
    }

    public static void decToBinary(int n)
    {
        for (int i = 31; i >= 0; i--) {
            int k = n >> i;
            if ((k & 1) > 0)
                count[i]++;
        }
    }

    static void print(int[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(int[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(boolean[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(boolean[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(long[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(long[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(String[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(String[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
}


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

public class C {

    static class Pair<U extends Comparable<U>, V extends Comparable<V>>
            implements Comparable<Pair<U,V>>{

        public final U a;
        public final V b;

        private Pair(U a, V b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;

            Pair<?, ?> pair = (Pair<?, ?>) o;
            if (!a.equals(pair.a))
                return false;
            return b.equals(pair.b);
        }

        @Override
        public int hashCode() {
            return 31 * a.hashCode() + b.hashCode();
        }

        @Override
        public String toString() {
            return "(" + a + ", " + b + ")";
        }

        @Override
        public int compareTo(Pair<U, V> o) {
            if(this.a.equals(o.a)){
                return getV().compareTo(o.getV());
            }
            return getU().compareTo(o.getU());
        }
        private U getU() {
            return a;
        }
        private V getV() {
            return b;
        }
        static void print(Pair[] pairs){
            for(int i=0;i<pairs.length;i++){
                System.out.print(pairs[i]+" ");
            }
            System.out.println();
        }
        static void print(Pair[][] pairs){

            for(int i=0;i<pairs.length;i++){
                for(int j=0;j<pairs[0].length;j++) {
                    System.out.print(pairs[i] + " ");
                }
                System.out.println();
            }
        }
    }

    static BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    static long modulo = 1000000007l;
    static int max = 0;
    static int value = -1;
    static int[] count = new int[32];

    public static void main(String[] args) throws IOException {

        int size = Integer.parseInt(inp.readLine());
        int[] given = new int[size];
        String[] s1 = inp.readLine().split(" ");
        for(int i=0;i<size;i++){
            given[i] = Integer.parseInt(s1[i]);
            decToBinary(given[i]);
        }

        for(int i=0;i<size;i++){
            int a = given[i];
            sol(a);
        }

        if(value==-1){
            value = given[0];
        }
        out.write(value+" ");
        for(int i=0;i<size;i++){
            if(given[i]!=value)
            out.write(given[i]+" ");
        }

        out.flush();

    }
    public static void sol(int n)
    {
        int[] a = new int[32];
        for (int i = 31; i >= 0; i--) {
            int k = n >> i;
            if ((k & 1) > 0 && count[i]==1)
                a[i]++;
        }
        int b = 0;
        int g = 1;
        for(int i=0;i<32;i++){
            b+=g*a[i];
            g*=2;
        }
        if(max<b){
            max = b;
            value = n;
        }
    }

    public static void decToBinary(int n)
    {
        for (int i = 31; i >= 0; i--) {
            int k = n >> i;
            if ((k & 1) > 0)
                count[i]++;
        }
    }

    static void print(int[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(int[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(boolean[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(boolean[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(long[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(long[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(String[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(String[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
}


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

public class C {

    static class Pair<U extends Comparable<U>, V extends Comparable<V>>
            implements Comparable<Pair<U,V>>{

        public final U a;
        public final V b;

        private Pair(U a, V b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;

            Pair<?, ?> pair = (Pair<?, ?>) o;
            if (!a.equals(pair.a))
                return false;
            return b.equals(pair.b);
        }

        @Override
        public int hashCode() {
            return 31 * a.hashCode() + b.hashCode();
        }

        @Override
        public String toString() {
            return "(" + a + ", " + b + ")";
        }

        @Override
        public int compareTo(Pair<U, V> o) {
            if(this.a.equals(o.a)){
                return getV().compareTo(o.getV());
            }
            return getU().compareTo(o.getU());
        }
        private U getU() {
            return a;
        }
        private V getV() {
            return b;
        }
        static void print(Pair[] pairs){
            for(int i=0;i<pairs.length;i++){
                System.out.print(pairs[i]+" ");
            }
            System.out.println();
        }
        static void print(Pair[][] pairs){

            for(int i=0;i<pairs.length;i++){
                for(int j=0;j<pairs[0].length;j++) {
                    System.out.print(pairs[i] + " ");
                }
                System.out.println();
            }
        }
    }

    static BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

    static long modulo = 1000000007l;
    static int max = 0;
    static int value = -1;
    static int[] count = new int[32];

    public static void main(String[] args) throws IOException {

        int size = Integer.parseInt(inp.readLine());
        int[] given = new int[size];
        String[] s1 = inp.readLine().split(" ");
        for(int i=0;i<size;i++){
            given[i] = Integer.parseInt(s1[i]);
            decToBinary(given[i]);
        }

        for(int i=0;i<size;i++){
            int a = given[i];
            sol(a);
        }

        if(value==-1){
            for (int i = 0; i < size; i++) {
                if (given[i] != value)
                    out.write(given[i] + " ");
            }
        }
        else {
            out.write(value + " ");
            for (int i = 0; i < size; i++) {
                if (given[i] != value)
                    out.write(given[i] + " ");
            }
        }

        out.flush();

    }
    public static void sol(int n)
    {
        int[] a = new int[32];
        for (int i = 31; i >= 0; i--) {
            int k = n >> i;
            if ((k & 1) > 0 && count[i]==1)
                a[i]++;
        }
        int b = 0;
        int g = 1;
        for(int i=0;i<32;i++){
            b+=g*a[i];
            g*=2;
        }
        if(max<b){
            max = b;
            value = n;
        }
    }

    public static void decToBinary(int n)
    {
        for (int i = 31; i >= 0; i--) {
            int k = n >> i;
            if ((k & 1) > 0)
                count[i]++;
        }
    }

    static void print(int[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(int[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(boolean[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(boolean[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(long[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(long[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(String[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(String[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
}


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

public class C {

	static Scanner sc;
	static PrintWriter out;
	static int N;
	static int[]a;

	public static void main(String[]args)throws Exception{
		sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		N =sc.nextInt();
		a = new int[N];
		for(int i=0;i<N;i++)
		{
			a[i]=sc.nextInt();
		}
		if(N==1)
		{
			out.println(a[0]);
			out.flush();
			out.close();
			return;
		}
		boolean flag = false;
		int candidate = -1;
		for(int i=31;i>=0;i--)
		{
			for(int j=0;j<N;j++)
			{
				if((a[j] & (1<<i)) !=0)
				{
					if(flag)
					{
						flag = false;
						candidate = -1;
						break;
					}
					else
					{
						flag = true;
						candidate = j;
					}
				}
			}
			if(flag)
			{
				break;
			}
		}
		out.print(a[candidate]+" ");
		if(N-1!=candidate)
		{
			for(int i=0;i<N-1;i++)
			{
				if(i!=candidate)
					out.print(a[i]+" ");
			}
			out.println(a[N-1]);
		}
		else
		{
			for(int i=0;i<N-2;i++)
			{
				out.print(a[i]+" ");
			}
			out.println(a[N-2]);
		}
		out.flush();
		out.close();
	}

	static class Scanner{
		static StringTokenizer st;
		static BufferedReader br;
		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
		public Scanner(FileReader file) {
			br = new BufferedReader(file);
		}
		public static String next() throws IOException {
			while(st == null || !st.hasMoreTokens())
			{
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public int nextInt()throws IOException{
			return Integer.parseInt(next());
		}
		public double nextDouble()throws IOException{
			return Double.parseDouble(next());
		}
		public char nextChar()throws IOException{
			return next().charAt(0);
		}
		public long nextLong()throws IOException{
			return Long.parseLong(next());
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
		public void waitForInput() throws InterruptedException {
			Thread.sleep(5000);
		}
	}

}


package firstDiv2Contest;
import java.io.*;
import java.util.*;

public class C {

	static Scanner sc;
	static PrintWriter out;
	static int N;
	static int[]a;

	public static void main(String[]args)throws Exception{
		sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		N =sc.nextInt();
		a = new int[N];
		for(int i=0;i<N;i++)
		{
			a[i]=sc.nextInt();
		}
		if(N==1)
		{
			out.println(a[0]);
			out.flush();
			out.close();
			return;
		}
		boolean flag = false;
		int candidate = -1;
		for(int i=31;i>=0;i--)
		{
			for(int j=0;j<N;j++)
			{
				if((a[j] & (1<<i)) !=0)
				{
					if(flag)
					{
						flag = false;
						candidate = -1;
						break;
					}
					else
					{
						flag = true;
						candidate = j;
					}
				}
			}
			if(flag)
			{
				break;
			}
		}
		if(candidate == -1)
		{
			for(int i=0;i<N-1;i++)
			{
				out.print(a[i]+" ");
			}
			out.println(a[N-1]);
			out.flush();
			out.close();
			return;
		}
		out.print(a[candidate]+" ");
		if(N-1!=candidate)
		{
			for(int i=0;i<N-1;i++)
			{
				if(i!=candidate)
					out.print(a[i]+" ");
			}
			out.println(a[N-1]);
		}
		else
		{
			for(int i=0;i<N-2;i++)
			{
				out.print(a[i]+" ");
			}
			out.println(a[N-2]);
		}
		out.flush();
		out.close();
	}

	static class Scanner{
		static StringTokenizer st;
		static BufferedReader br;
		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
		public Scanner(FileReader file) {
			br = new BufferedReader(file);
		}
		public static String next() throws IOException {
			while(st == null || !st.hasMoreTokens())
			{
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public int nextInt()throws IOException{
			return Integer.parseInt(next());
		}
		public double nextDouble()throws IOException{
			return Double.parseDouble(next());
		}
		public char nextChar()throws IOException{
			return next().charAt(0);
		}
		public long nextLong()throws IOException{
			return Long.parseLong(next());
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
		public void waitForInput() throws InterruptedException {
			Thread.sleep(5000);
		}
	}

}


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

public class C {

	static Scanner sc;
	static PrintWriter out;
	static int N;
	static int[]a;

	public static void main(String[]args)throws Exception{
		sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		N =sc.nextInt();
		a = new int[N];
		for(int i=0;i<N;i++)
		{
			a[i]=sc.nextInt();
		}
		if(N==1)
		{
			out.println(a[0]);
			out.flush();
			out.close();
			return;
		}
		boolean flag = false;
		int candidate = -1;
		for(int i=31;i>=0;i--)
		{
			for(int j=0;j<N;j++)
			{
				if((a[j] & (1<<i)) !=0)
				{
					if(flag)
					{
						flag = false;
						candidate = -1;
						break;
					}
					else
					{
						flag = true;
						candidate = j;
					}
				}
			}
			if(flag)
			{
				break;
			}
		}
		if(candidate == -1)
		{
			for(int i=0;i<N-1;i++)
			{
				out.print(a[i]+" ");
			}
			out.println(a[N-1]);
			out.flush();
			out.close();
			return;
		}
		out.print(a[candidate]+" ");
		if(N-1!=candidate)
		{
			for(int i=0;i<N-1;i++)
			{
				if(i!=candidate)
					out.print(a[i]+" ");
			}
			out.println(a[N-1]);
		}
		else
		{
			for(int i=0;i<N-2;i++)
			{
				out.print(a[i]+" ");
			}
			out.println(a[N-2]);
		}
		out.flush();
		out.close();
	}

	static class Scanner{
		static StringTokenizer st;
		static BufferedReader br;
		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
		public Scanner(FileReader file) {
			br = new BufferedReader(file);
		}
		public static String next() throws IOException {
			while(st == null || !st.hasMoreTokens())
			{
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public int nextInt()throws IOException{
			return Integer.parseInt(next());
		}
		public double nextDouble()throws IOException{
			return Double.parseDouble(next());
		}
		public char nextChar()throws IOException{
			return next().charAt(0);
		}
		public long nextLong()throws IOException{
			return Long.parseLong(next());
		}
		public boolean ready() throws IOException {
			return br.ready();
		}
		public void waitForInput() throws InterruptedException {
			Thread.sleep(5000);
		}
	}

}


import java.io.*;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.NoSuchElementException;

public class P1300C_2 {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        final int MAX_BIT = 32;
        int n = scanner.nextInt();
        ArrayList<Integer> x = new ArrayList<>(n);
        for (int i = 0; i < n; ++i)
            x.add(scanner.nextInt());
        x.sort(Comparator.reverseOrder());
        int[] cnt = new int[MAX_BIT];
        for (int i = 0; i < n; ++i) {
            int v = x.get(i);
            for (int k = 0; k < MAX_BIT && (1 << k) <= v; ++k)
                if ((v & (1 << k)) > 0)
                    ++cnt[k];
        }
        int max = 0;
        int idx = 0;
        for (int i = 0; i < n; ++i) {
            int v = x.get(i);
            int t = 0;
            for (int k = 0; k < MAX_BIT && (1 << k) <= v; ++k) {
                if ((v & (1 << k)) > 0 && cnt[k] == 1) {
                    t |= 1 << k;
                }
            }
            if (t > max) {
                max = t;
                idx = i;
            }
        }
        writer.print(x.get(idx));
        for (int i = 0; i < n; ++i)
            if (i != idx)
                writer.print(" " + x.get(i));
        writer.println();

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        private SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }

        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

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

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

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


import java.io.*;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.NoSuchElementException;

public class P1300C {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        ArrayList<Integer> x = new ArrayList<>(n);
        for (int i = 0; i < n; ++i)
            x.add(scanner.nextInt());
        x.sort(Comparator.reverseOrder());
        for (int i = 0; i < n; ++i)
            writer.print(x.get(i) + " ");
        writer.println();

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        private SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }

        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

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

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

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


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

public class utkarsh {

    BufferedReader br;
    PrintWriter out;

    long mod = (long) (1e9 + 7), inf = (long) (3e18);

    void solve() {
        int n = ni();
        int a[] = new int[n];
        for(int i = 0; i < n; i++)  a[i] = ni();
        Arrays.sort(a);
        for(int i = n-1; i >= 0; i--)   out.print(a[i] + " ");
    }

    long mp(long b, long e) {
        long r = 1;
        while(e > 0) {
            if( (e&1) == 1 )    r = (r * b) % mod;
            b = (b * b) % mod;
            e >>= 1;
        }
        return r;
    }

    // -------- I/O Template -------------

    char nc() {
        return ns().charAt(0);
    }

    String nLine() {
        try {
            return br.readLine();
        } catch(IOException e) {
            return "-1";
        }
    }

    double nd() {
        return Double.parseDouble(ns());
    }

    long nl() {
        return Long.parseLong(ns());
    }

    int ni() {
        return Integer.parseInt(ns());
    }

    StringTokenizer ip;

    String ns() {
        if(ip == null || !ip.hasMoreTokens()) {
            try {
                ip = new StringTokenizer(br.readLine());
            } catch(IOException e) {
                throw new InputMismatchException();
            }
        }
        return ip.nextToken();
    }

    void run() {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    public static void main(String[] args) {
        new utkarsh().run();
    }
}