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

public class C implements Runnable
{
    @Override
    public void run() {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        int q = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
        int[] arr = new int[q];
        for (int i = 0; i < q; i++) {
            arr[i] = in.nextInt();
        }

        w.println(print(arr));

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

    private static String print(int[] a) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : a) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        int first = -1;
        int l = 0;
        int[] count = new int[32];
        for (int num : a) {
            if (map.get(num) > 1) {
                continue;
            }
            int d = 0;
            int temp = num;
            while (temp > 0) {
                count[d++] += (temp & 1);
                temp = (temp >> 1);
            }
            if (d > l) {
                l = d;
                first = num;
            }
        }

        long max = 0;

        for (int num : a) {
            if (map.get(num) > 1) {
                continue;
            }
            int[] c = new int[32];
            int temp = num;
            int d = 0;
            while (temp > 0) {
                c[d++] += (temp & 1);
                temp = (temp >> 1);
            }
            if (d < l) {
                continue;
            }
            long val = 0;
            for (int i = 0; i < d; i++) {
                val = val * 2;
                if (count[i] == 1 && c[i] == 1) {
                    val += 1;
                }
            }
            //System.out.println(num + " " + val);
            if (val > max) {
                max = val;
                first = num;
            }
        }

        boolean add = false;
        StringBuilder sb = new StringBuilder();
//        if (first == -1) {
//            add = true;
//        }
//        else {
            sb.append(first);
//        }
//
        for (int i = a.length - 1; i >= 0; i--) {
            if (a[i] == first && !add) {
                add = true;
                continue;
            }
            sb.append(" " + a[i]);
        }

        return sb.toString().trim();
    }

    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);
        }
    }

    public static void main(String args[]) throws Exception
    {
        new Thread(null, new C(),"Main",1<<27).start();
    }

}


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

public class C implements Runnable
{
    @Override
    public void run() {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        int q = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
        int[] arr = new int[q];
        for (int i = 0; i < q; i++) {
            arr[i] = in.nextInt();
        }

        w.println(print(arr));

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

    private static String print(int[] a) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : a) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }

        int[] count = new int[32];
        for (int num : a) {
            if (map.get(num) > 1) {
                continue;
            }
            int d = 0;
            int temp = num;
            while (temp > 0) {
                count[d++] += (temp & 1);
                temp = (temp >> 1);
            }
        }

//        for (int c : count) {
//            System.out.print(c + " ");
//        }
//        System.out.println();

        long max = 0;
        int first = -1;
        for (int num : a) {
            if (map.get(num) > 1) {
                continue;
            }
            int[] c = new int[32];
            int temp = num;
            int d = 0;
            while (temp > 0) {
                c[d++] += (temp & 1);
                temp = (temp >> 1);
            }

            long val = 0;
            for (int i = d - 1; i >= 0; i--) {
                val = val * 2;
                if (count[i] == 1 && c[i] == 1) {
                    val += 1;
                }
            }
            //System.out.println(num + " " + val);
            if (val > max) {
                max = val;
                first = num;
            }

        }

        boolean add = false;
        StringBuilder sb = new StringBuilder();
//        if (first == -1) {
//            add = true;
//        }
//        else {
            sb.append(first);
//        }
//
        for (int i = a.length - 1; i >= 0; i--) {
            if (a[i] == first && !add) {
                add = true;
                continue;
            }
            sb.append(" " + a[i]);
        }

        return sb.toString().trim();
    }

    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);
        }
    }

    public static void main(String args[]) throws Exception
    {
        new Thread(null, new C(),"Main",1<<27).start();
    }

}


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

public class C implements Runnable
{
    @Override
    public void run() {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        int q = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
        int[] arr = new int[q];
        for (int i = 0; i < q; i++) {
            arr[i] = in.nextInt();
        }

        w.println(print(arr));

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

    private static String print(int[] a) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : a) {
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        int[] count = new int[32];
        for (int num : a) {
            if (map.get(num) > 1) {
                continue;
            }
            int d = 0;
            int temp = num;
            while (temp > 0) {
                count[d++] += (temp & 1);
                temp = (temp >> 1);
            }
        }

        long max = 0;
        int first = -1;
        for (int num : a) {
            if (map.get(num) > 1) {
                continue;
            }
            int[] c = new int[32];
            int temp = num;
            int d = 0;
            while (temp > 0) {
                c[d++] += (temp & 1);
                temp = (temp >> 1);
            }

            long val = 0;
            for (int i = 0; i < d; i++) {
                val = val * 2;
                if (count[i] == 1 && c[i] == 1) {
                    val += 1;
                }
            }

            if (val > max) {
                max = val;
                first = num;
            }
        }

        boolean add = false;
        StringBuilder sb = new StringBuilder();
        if (first == -1) {
            add = true;
        }
        else {
            sb.append(first);
        }

        for (int i = a.length - 1; i >= 0; i--) {
            if (a[i] == first && !add) {
                add = true;
                continue;
            }
            sb.append(" " + a[i]);
        }

        return sb.toString().trim();
    }

    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);
        }
    }

    public static void main(String args[]) throws Exception
    {
        new Thread(null, new C(),"Main",1<<27).start();
    }

}


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

public class C implements Runnable
{
    @Override
    public void run() {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        int q = in.nextInt(); // Scanner has functions to read ints, longs, strings, chars, etc.
        int[] arr = new int[q];
        for (int i = 0; i < q; i++) {
            arr[i] = in.nextInt();
        }

        w.println(print(arr));

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

    private static String print(int[] a) {
        int[] count = new int[32];
        for (int num : a) {
            int d = 0;
            int temp = num;
            while (temp > 0) {
                count[d++] += (temp & 1);
                temp = (temp >> 1);
            }
        }

        long max = 0;
        int first = 0;
        for (int num : a) {
            int[] c = new int[32];
            int temp = num;
            int d = 0;
            while (temp > 0) {
                c[d++] += (temp & 1);
                temp = (temp >> 1);
            }

            long val = 0;
            for (int i = 0; i < d; i++) {
                val = val * 2;
                if (count[i] == 1 && c[i] == 1) {
                    val += 1;
                }
            }

            if (val > max) {
                max = val;
                first = num;
            }
        }

        boolean add = false;
        StringBuilder sb = new StringBuilder();
        sb.append(first);
        for (int i = a.length - 1; i >= 0; i--) {
            if (a[i] == first && !add) {
                add = true;
                continue;
            }
            sb.append(" " + a[i]);
        }
        return sb.toString();
    }

    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);
        }
    }

    public static void main(String args[]) throws Exception
    {
        new Thread(null, new C(),"Main",1<<27).start();
    }

}


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

import static java.lang.Math.min;

/**
 * Created by Katushka on 08.02.2020.
 */
public class AnuHasAFunction {

    public static void main(String[] args) throws FileNotFoundException {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = in.nextInt();
        int[] a = new int[n];
        int[][] binary = new int[n][32];
        int maxBit = -1;

        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            int t = a[i];
            int j = 0;
            while (t > 0) {
                binary[i][j] = t % 2;
                t /= 2;
                j++;
            }
            if (maxBit < j) {
                maxBit = j;
            }
        }
        for (int i = 0; i < min(maxBit + 1, 32); i++) {
            int ones = 0;
            for (int j = 0; j < n; j++) {
                if (binary[j][i] == 1) {
                    ones++;
                }
                if (ones > 1) {
                    break;
                }
            }
            if (ones > 1) {
                for (int j = 0; j < n; j++) {
                    binary[j][i] = 0;
                }
            }
        }

        int max = 0;
        int maxIndex = 0;

        for (int i = 0; i < n; i++) {
            int t = 0;
            int d = 1;
            for (int j = 0; j < min(maxBit + 1, 32); j++) {
                t += binary[i][j] * d;
                d *= 2;
            }
            if (t > max) {
                max = t;
                maxIndex = i;
            }
        }

        int t = a[maxIndex];
        a[maxIndex] = a[0];
        a[0] = t;

        StringBuilder ans = new StringBuilder();
        for (int elem : a) {
            ans.append(elem).append(' ');
        }
        out.println(ans);

        out.close();
    }

    private 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 String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

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

        public char nextChar() {
            return next().charAt(0);
        }
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;

import static jdk.nashorn.internal.objects.NativeMath.min;

/**
 * Created by Katushka on 08.02.2020.
 */
public class AnuHasAFunction {

    public static void main(String[] args) throws FileNotFoundException {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = in.nextInt();
        int[] a = new int[n];
        int[][] binary = new int[n][32];
        int maxBit = -1;

        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            int t = a[i];
            int j = 0;
            while (t > 0) {
                binary[i][j] = t % 2;
                t /= 2;
                j++;
            }
            if (maxBit < j) {
                maxBit = j;
            }
        }
        for (int i = 0; i < min(maxBit + 1, 32); i++) {
            int ones = 0;
            for (int j = 0; j < n; j++) {
                if (binary[j][i] == 1) {
                    ones++;
                }
                if (ones > 1) {
                    break;
                }
            }
            if (ones > 1) {
                for (int j = 0; j < n; j++) {
                    binary[j][i] = 0;
                }
            }
        }

        int max = 0;
        int maxIndex = 0;

        for (int i = 0; i < n; i++) {
            int t = 0;
            int d = 1;
            for (int j = 0; j < min(maxBit + 1, 32); j++) {
                t += binary[i][j] * d;
                d *= 2;
            }
            if (t > max) {
                max = t;
                maxIndex = i;
            }
        }

        int t = a[maxIndex];
        a[maxIndex] = a[0];
        a[0] = t;

        StringBuilder ans = new StringBuilder();
        for (int elem : a) {
            ans.append(elem).append(' ');
        }
        out.println(ans);

        out.close();
    }

    private 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 String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

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

        public char nextChar() {
            return next().charAt(0);
        }
    }
}


import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class j {

    public static void main(String[] args) {
        FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        Task solver = new Task();
        int t = 1;
        for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
        out.close();
    }

    static class Task {

        public void solve(int testNumber, FastReader scan, PrintWriter out) {
            int n = scan.nextInt(), maxLog = 31;
            int[] a = new int[n], bitFreq = new int[maxLog];
            int maxVal = -1;
            for(int i = 0; i < n; i++) {
                a[i] = scan.nextInt();
                for(int j = 0; j < maxLog; j++) {
                    if((a[i] & (1 << j)) > 0) bitFreq[j]++;
                }
            }
            for(int i = 0; i < n; i++) {
                int curr = 0;
                for(int j = 0; j < maxLog; j++) {
                    if(bitFreq[j] == 1 && (a[i] & (1 << j)) > 0) curr += 1 << j;
                }
                maxVal = Math.max(maxVal, curr);
            }
            if(maxVal != -1) out.printf("%d ", maxVal);
            for(int i = 0; i < n; i++) {
                if(a[i] != maxVal) out.printf("%d ", a[i]);
            }
        }
    }

    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class j {

    public static void main(String[] args) {
        FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        Task solver = new Task();
        int t = 1;
        for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
        out.close();
    }

    static class Task {

        public void solve(int testNumber, FastReader scan, PrintWriter out) {
            int n = scan.nextInt(), maxLog = 31;
            int[] a = new int[n], bitFreq = new int[maxLog];
            int maxVal = -1, actual = -1;
            boolean used = false;
            for(int i = 0; i < n; i++) {
                a[i] = scan.nextInt();
                for(int j = 0; j < maxLog; j++) {
                    if((a[i] & (1 << j)) > 0) bitFreq[j]++;
                }
            }
            for(int i = 0; i < n; i++) {
                int curr = 0;
                for(int j = 0; j < maxLog; j++) {
                    if(bitFreq[j] == 1 && (a[i] & (1 << j)) > 0) curr += 1 << j;
                }
                if(curr > maxVal) {
                    maxVal = curr;
                    actual = a[i];
                }
            }
            if(actual != -1) out.printf("%d ", actual);
            for(int i = 0; i < n; i++) {
                if(a[i] == actual && !used) {
                    used = true;
                    continue;
                }
                out.printf("%d ", a[i]);
            }
        }
    }

    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class j {

    public static void main(String[] args) {
        FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        Task solver = new Task();
        int t = 1;
        for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
        out.close();
    }

    static class Task {

        public void solve(int testNumber, FastReader scan, PrintWriter out) {
            int n = scan.nextInt(), maxLog = 31;
            int[] a = new int[n], bitFreq = new int[maxLog];
            int maxVal = -1, actual = -1;
            for(int i = 0; i < n; i++) {
                a[i] = scan.nextInt();
                for(int j = 0; j < maxLog; j++) {
                    if((a[i] & (1 << j)) > 0) bitFreq[j]++;
                }
            }
            for(int i = 0; i < n; i++) {
                int curr = 0;
                for(int j = 0; j < maxLog; j++) {
                    if(bitFreq[j] == 1 && (a[i] & (1 << j)) > 0) curr += 1 << j;
                }
                if(curr > maxVal) {
                    maxVal = curr;
                    actual = a[i];
                }
            }
            if(actual != -1) out.printf("%d ", actual);
            for(int i = 0; i < n; i++) {
                if(a[i] != actual) out.printf("%d ", a[i]);
            }
        }
    }

    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}


import java.awt.*;
import java.io.*;
import java.nio.channels.InterruptedByTimeoutException;
import java.util.*;
import java.util.List;

public class C {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }

    static int gcd(int a,int b)
    {
        if(b==0)
        {
            return a;
        }
        return gcd(b,a%b);
    }

    static boolean isPrime(int n) {
        //check if n is a multiple of 2
        if (n % 2 == 0) return false;
        //if not, then just check the odds
        for (int i = 3; i <= Math.sqrt(n); i += 2) {
            if (n % i == 0)
                return false;
        }
        return true;
    }

    static int onesComp(int val)
    {
        String str=Integer.toBinaryString(val);
        int newval=0;
        int pow=0;
        for(int i=str.length()-1;i>=0;i--)
        {
            if(str.charAt(i)=='0')
            {
                newval+=Math.pow(2,pow);
            }
            pow++;
        }
        return newval;
    }

    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
//        int t = ri();
        int t = 1;
        while (t-- > 0)
        {
            int n=ri();
            int[] arr=rai(n);
            int[] count=new int[31];

            for(int i=0;i<31;i++)
            {
                for(int j:arr)
                {
                    if((j&(1<<i))==(1<<i))
                    {
                        count[i]++;
                    }
                }
            }

            int pow=-1;
            for(int i=30;i>=0;i--)
            {
                if(count[i]==1)
                {
                    pow=i;
                    break;
                }
            }
            if(pow==-1)
            {
                ans.append("0\n");
            }
            else {

                int ind=-1;
                for(int i=0;i<n;i++)
                {
                    if((arr[i]&(1<<pow))==(1<<pow))
                    {
                        ind=i;
                    }
                }
                int res=arr[ind];
                ans.append(arr[ind]).append(" ");
                for(int i=0;i<n;i++)
                {
                    if(i!=ind)
                    {
                        ans.append(arr[i]).append(" ");
                        res&=onesComp(arr[i]);
                    }
                }
//                System.out.println(res);
                ans.append("\n");
            }

        }

        out.print(ans.toString());
        out.flush();

    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;

public class Codeforces2 {

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

        Scanner s = new Scanner(System.in);
//
        int n=s.nextInt();
        int[] arr=new int[n];
        int val=0;
        HashMap<Integer,Integer> map=new HashMap<>();
        for(int i=0;i<n;i++)
        {
            arr[i]=s.nextInt();
            if(arr[i]>val)
            {
                val=arr[i];
            }
            map.put(arr[i],map.getOrDefault(arr[i],0)+1);
        }

        map.put(val,map.get(val)-1);
        if(map.get(val)==0)
        {
            map.remove(val);
        }
        List<Integer> list=new ArrayList<>();
        list.add(val);
        while(map.size()!=0)
        {
            int max=Integer.MIN_VALUE;
            int value=-1;
            for(int i:map.keySet())
            {
                int v=(val|i)-i;
                if(v>max)
                {
                    max=v;
                    value=i;
                }
            }
            map.put(value,map.get(value)-1);
            if(map.get(value)==0)
            {
                map.remove(value);
            }
            list.add(value);
            val=max;
        }
//        int[] ans=new int[n];
        for(int i=0;i<list.size();i++)
        {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();

    }
}


import java.awt.*;
import java.io.*;
import java.nio.channels.InterruptedByTimeoutException;
import java.util.*;
import java.util.List;

public class C {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }

    static int gcd(int a,int b)
    {
        if(b==0)
        {
            return a;
        }
        return gcd(b,a%b);
    }

    static boolean isPrime(int n) {
        //check if n is a multiple of 2
        if (n % 2 == 0) return false;
        //if not, then just check the odds
        for (int i = 3; i <= Math.sqrt(n); i += 2) {
            if (n % i == 0)
                return false;
        }
        return true;
    }

    static int onesComp(int val)
    {
        String str=Integer.toBinaryString(val);
        int newval=0;
        int pow=0;
        for(int i=str.length()-1;i>=0;i--)
        {
            if(str.charAt(i)=='0')
            {
                newval+=Math.pow(2,pow);
            }
            pow++;
        }
        return newval;
    }

    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
//        int t = ri();
        int t = 1;
        while (t-- > 0)
        {
            int n=ri();
            int[] arr=rai(n);
            int[] count=new int[31];

            for(int i=0;i<31;i++)
            {
                for(int j:arr)
                {
                    if((j&(1<<i))==(1<<i))
                    {
                        count[i]++;
                    }
                }
            }

            int pow=-1;
            for(int i=30;i>=0;i--)
            {
                if(count[i]==1)
                {
                    pow=i;
                    break;
                }
            }
            if(pow==-1)
            {
                for(int i:arr)
                {
                    ans.append(i).append(" ");
                }
                ans.append("\n");
            }
            else {

                int ind=-1;
                for(int i=0;i<n;i++)
                {
                    if((arr[i]&(1<<pow))==(1<<pow))
                    {
                        ind=i;
                    }
                }
                int res=arr[ind];
                ans.append(arr[ind]).append(" ");
                for(int i=0;i<n;i++)
                {
                    if(i!=ind)
                    {
                        ans.append(arr[i]).append(" ");
                        res&=onesComp(arr[i]);
                    }
                }
//                System.out.println(res);
                ans.append("\n");
            }

        }

        out.print(ans.toString());
        out.flush();

    }

}


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

import static java.util.Comparator.*;

public class Codeforces {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
//        int t=s.nextInt();
//        for(int i=0;i<t;i++)
//        {
            int n=s.nextInt();
            int[] arr=new int[n];

            for(int j=0;j<n;j++)
            {
                arr[j]=s.nextInt();

            }
            Arrays.sort(arr);
            for(int j=arr.length-1;j>=0;j--)
            {
                System.out.print(arr[j]+" ");
            }
            System.out.println();

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class OffBit {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] arr = new long[N];
        for(int i = 0; i < N; i++) {
            arr[i] = scanner.nextLong();
        }
        Arrays.sort(arr);
        for(int i = arr.length - 1; i >= 0; i--) {
            System.out.print(arr[i] + ((i != 0) ? " ": ""));
        }
        /*for(int i = 0; i < arr.length - 1; i++) {
            System.out.println(arr[i] + "^" + arr[arr.length - 1] + " = " + (arr[i] ^ arr[arr.length - 1]));
        }
        System.out.println();
        for(int i = 0; i < 4; i++) {
            for(int k = 0; k < 4; k++) {
                if(i == k) continue;
                for(int j = 0; j < 4; j++) {
                    if(j == i || j == k) continue;
                    for(int m = 0; m < 4; m++) {
                        if(m == j || m == i || m == k) continue;
                        long[] temp = new long[]{arr[i], arr[k], arr[j], arr[m]};
                        long answer = temp[0];
                        for(int n = 1; n < temp.length; n++) {
                            answer = (answer | temp[n]) - temp[n];
                        }
                        System.out.println(Arrays.toString(temp) + " " + answer);
                    }
                }
            }
        }*/
    }
}


import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class OffBit {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] arr = new long[N];
        for(int i = 0; i < N; i++) {
            arr[i] = scanner.nextLong();
        }
        Arrays.sort(arr);
        int minFirst = -1;
        long maxAnswer = 0;
        /*for(int i = 0; i < arr.length; i++) {
            long answer = arr[i];
            for(int k = 0; k < arr.length; k++) {
                if(k == i) continue;
                answer = (answer | arr[k]) - arr[k];
            }
            if(answer > maxAnswer) {
                maxAnswer = answer;
                minFirst = i;
            }
        }*/
        long[] noDuplicates = new long[arr.length];
        int k = 0;
        for(int i = 0; i < arr.length; i++) {
            if(i == 0) {
                if(arr[0] != arr[i + 1]) {
                    noDuplicates[k++] = arr[i];
                }
            } else if(i == arr.length - 1) {
                if(arr[i] != arr[i - 1]) {
                    noDuplicates[k++] = arr[i];
                }
            } else {
                if(arr[i] != arr[i - 1] && arr[i] != arr[i + 1]) {
                    noDuplicates[k++] = arr[i];
                }
            }
        }
        Arrays.sort(noDuplicates);
        long maxVal = noDuplicates[noDuplicates.length - 1];
        //Max value without duplicates
        for(int i = arr.length - 1; i >= 1; i--) {
            if(arr[i] == maxVal) {
                minFirst = i;
            }
        }
        if(minFirst != -1)
            System.out.print(arr[minFirst]);
        else {
            minFirst = 0;
            System.out.print(arr[minFirst]);
        }
        for(int i = 0; i < arr.length; i++) {
            if (i == minFirst) continue;
            System.out.print(" " + arr[i]);
        }
    }
}


import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class OffBit {

    private long maxAnswer;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] arr = new int[N];
        int[] bits = new int[32];
        for (int i = 0; i < N; i++) {
            arr[i] = scanner.nextInt();
            for(int b = 0; b < bits.length; b++) {
                if((arr[i] & (1 << b)) > 0) {
                    bits[b]++;
                }
            }
        }
        int minFirst = 0;
        long maxAnswer = 0;
        for(int i = 0; i < arr.length; i++) {
            int answer = 0;
            for(int b = 0; b < bits.length; b++) {
                if(bits[b] == 1 && (arr[i] & (1 << b)) > 0) {
                    answer += (1 << b);
                }
            }
            if(answer > maxAnswer) {
                maxAnswer = answer;
                minFirst = i;
            }
        }
        System.out.print(arr[minFirst]);
        for (int i = 0; i < arr.length; i++) {
            if (i == minFirst) continue;
            System.out.print(" " + arr[i]);
        }
    }
}


import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class OffBit {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] arr = new long[N];
        for(int i = 0; i < N; i++) {
            arr[i] = scanner.nextLong();
        }
        Arrays.sort(arr);
        int minFirst = -1;
        long maxAnswer = 0;
        /*for(int i = 0; i < arr.length; i++) {
            long answer = arr[i];
            for(int k = 0; k < arr.length; k++) {
                if(k == i) continue;
                answer = (answer | arr[k]) - arr[k];
            }
            if(answer > maxAnswer) {
                maxAnswer = answer;
                minFirst = i;
            }
        }*/
        long[] noDuplicates = new long[arr.length];
        int k = 0;
        if(arr.length == 1) {
            System.out.println(arr[0]);
        } else {
            for (int i = 0; i < arr.length; i++) {
                if (i == 0) {
                    if (arr[i] != arr[i + 1]) {
                        noDuplicates[k++] = arr[i];
                    }
                } else if (i == arr.length - 1) {
                    if (arr[i] != arr[i - 1]) {
                        noDuplicates[k++] = arr[i];
                    }
                } else {
                    if (arr[i] != arr[i - 1] && arr[i] != arr[i + 1]) {
                        noDuplicates[k++] = arr[i];
                    }
                }
            }
            Arrays.sort(noDuplicates);
            long maxVal = noDuplicates[noDuplicates.length - 1];
            //Max value without duplicates
            for (int i = arr.length - 1; i >= 1; i--) {
                if (arr[i] == maxVal) {
                    minFirst = i;
                }
            }
            if (minFirst != -1)
                System.out.print(arr[minFirst]);
            else {
                minFirst = 0;
                System.out.print(arr[minFirst]);
            }
            for (int i = 0; i < arr.length; i++) {
                if (i == minFirst) continue;
                System.out.print(" " + arr[i]);
            }
        }
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class OffBit {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] arr = new long[N];
        for(int i = 0; i < N; i++) {
            arr[i] = scanner.nextLong();
        }
        Arrays.sort(arr);
        int minFirst = 0;
        long maxAnswer = 0;
        for(int i = 0; i < arr.length; i++) {
            long answer = arr[i];
            for(int k = 0; k < arr.length; k++) {
                if(k == i) continue;
                answer = (answer | arr[k]) - arr[k];
            }
            if(answer > maxAnswer) {
                maxAnswer = answer;
                minFirst = i;
            }
        }
        System.out.print(arr[minFirst]);
        for(int i = 0; i < arr.length; i++) {
            if(i == minFirst) continue;
            System.out.print(" " + arr[i]);
        }
        /*for(int i = 0; i < arr.length - 1; i++) {
            System.out.println(arr[i] + "^" + arr[arr.length - 1] + " = " + (arr[i] ^ arr[arr.length - 1]));
        }
        System.out.println();*/
        /*for(int i = 0; i < 4; i++) {
            for(int k = 0; k < 4; k++) {
                if(i == k) continue;
                for(int j = 0; j < 4; j++) {
                    if(j == i || j == k) continue;
                    for(int m = 0; m < 4; m++) {
                        if(m == j || m == i || m == k) continue;
                        long[] temp = new long[]{arr[i], arr[k], arr[j], arr[m]};
                        long answer = temp[0];
                        for(int n = 1; n < temp.length; n++) {
                            answer = (answer | temp[n]) - temp[n];
                        }
                        System.out.println(Arrays.toString(temp) + " " + answer);
                    }
                }
            }
        }*/
    }
}


import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class OffBit {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] arr = new long[N];
        for(int i = 0; i < N; i++) {
            arr[i] = scanner.nextLong();
        }
        Arrays.sort(arr);
        int minFirst = -1;
        long maxAnswer = 0;
        /*for(int i = 0; i < arr.length; i++) {
            long answer = arr[i];
            for(int k = 0; k < arr.length; k++) {
                if(k == i) continue;
                answer = (answer | arr[k]) - arr[k];
            }
            if(answer > maxAnswer) {
                maxAnswer = answer;
                minFirst = i;
            }
        }*/
        HashSet<Long> set = new HashSet<>();
        for(int i = 0; i < arr.length; i++) {
            set.add(arr[i]);
        }
        long[] noDuplicates = removeDuplicateElements(arr, arr.length);
        Arrays.sort(noDuplicates);
        long maxVal = noDuplicates[noDuplicates.length - 1];
        //Max value without duplicates
        for(int i = arr.length - 1; i >= 1; i--) {
            if(arr[i] == maxVal) {
                minFirst = i;
            }
        }
        if(minFirst != -1)
            System.out.print(arr[minFirst]);
        else {
            minFirst = 0;
            System.out.print(arr[minFirst]);
        }
        for(int i = 0; i < arr.length; i++) {
            if (i == minFirst) continue;
            System.out.print(" " + arr[i]);
        }
    }

    public static long[] removeDuplicateElements(long arr[], int n) {
        long[] temp = new long[n];
        int j = 0;
        for (int i=0; i<n-1; i++){
            if (arr[i] != arr[i+1]){
                temp[j++] = arr[i];
            }
        }
        temp[j++] = arr[n-1];
        return temp;
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class OffBit {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = scanner.nextInt();
        }
        Arrays.sort(arr);
        for(int i = arr.length - 1; i >= 0; i--) {
            System.out.print(arr[i] + ((i != 0) ? " ": ""));
        }
        /*for(int i = 0; i < arr.length - 1; i++) {
            System.out.println(arr[i] + "^" + arr[arr.length - 1] + " = " + (arr[i] ^ arr[arr.length - 1]));
        }*/
        /*System.out.println();
        for(int i = 0; i < 4; i++) {
            for(int k = 0; k < 4; k++) {
                if(i == k) continue;
                for(int j = 0; j < 4; j++) {
                    if(j == i || j == k) continue;
                    for(int m = 0; m < 4; m++) {
                        if(m == j || m == i || m == k) continue;
                        int[] temp = new int[]{arr[i], arr[k], arr[j], arr[m]};
                        int answer = temp[0];
                        for(int n = 1; n < temp.length; n++) {
                            answer = (answer | temp[n]) - temp[n];
                        }
                        System.out.println(Arrays.toString(temp) + " " + answer);
                    }
                }
            }
        }*/
    }
}


/* @nikhil_supertramp */

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

public class AnuHasAFunction
{
    public static void main(String[] args)throws Exception
    {
        new Solver().solve();
    }
}
//  cd competetive-programming/src/Codeforces
//  javac -d ../../classes AnuHasAFunction.java
//  java AnuHasAFunction
//  problem link : https://codeforces.com/contest/1300/problem/C

class Solver {
    final Helper hp;
    final int MAXN = 1000_006;
    final long MOD = (long) 1e9 + 7;
    void solve() throws Exception
    {
        //for(int tc = hp.nextInt(); tc > 0; tc--)
        {
            int n = hp.nextInt();
            int  arr[] = hp.getIntArray(n);
            for(int b = 30; b >= 0; b--)
            {
                ArrayList<Integer> li = new ArrayList<>();
                for(int i = 0; i < n; i++)
                {
                    if(arr[i] & (1 << b) > 0)
                        li.add(i);
                }

                if(li.size() == 1)
                {
                    hp.print(arr[li.get(0)] + " ");
                    for(int i = 0; i < n; i++)
                    {
                        if(i != li.get(0))
                            hp.println(arr[i] + " ");
                    }
                    hp.println();
                    hp.flush();
                    return;
                }
            }
            for(int i : arr)hp.print(arr[i] + " ");
        }

        hp.flush();
    }

    Solver() {
        hp = new Helper(MOD, MAXN);
        hp.initIO(System.in, System.out);
    }
}

class Pair implements Comparable<Pair>{
    int x;
    int y;//long z;

    public Pair(int x, int y)
    {
        this.x = x;
        this.y = y;
        //this.z = z;
    }
    @Override
    public int compareTo(Pair p)
    {
        if(p.y == y)
        return x - p.x;
        return p.y - y;
    }
}

class Helper {
    final long MOD;
    final int MAXN;
    final Random rnd;

    public Helper(long mod, int maxn) {
        MOD = mod;
        MAXN = maxn;
        rnd = new Random();
    }

    public static int[] sieve;
    public static ArrayList<Integer> primes;

    public void setSieve() {
        primes = new ArrayList<>();
        sieve = new int[MAXN];
        int i, j;
        for (i = 2; i < MAXN; ++i)
            if (sieve[i] == 0) {
                primes.add(i);
                for (j = i; j < MAXN; j += i) {
                    sieve[j] = i;
                }
            }
    }

    public static long[] factorial;

    public void setFactorial() {
        factorial = new long[MAXN];
        factorial[0] = 1;
        for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
    }

    public long getFactorial(int n) {
        if (factorial == null) setFactorial();
        return factorial[n];
    }

    public long ncr(int n, int r) {
        if (r > n) return 0;
        if (factorial == null) setFactorial();
        long numerator = factorial[n];
        long denominator = factorial[r] * factorial[n - r] % MOD;
        return numerator * pow(denominator, MOD - 2, MOD) % MOD;
    }

    public long[] getLongArray(int size) throws Exception {
        long[] ar = new long[size];
        for (int i = 0; i < size; ++i) ar[i] = nextLong();
        return ar;
    }

    public int[] getIntArray(int size) throws Exception {
        int[] ar = new int[size];
        for (int i = 0; i < size; ++i) ar[i] = nextInt();
        return ar;
	}

    public int[] getIntArray(String s)throws Exception
    {
        s = s.trim().replaceAll("\\s+", " ");
        String[] strs = s.split(" ");
        int[] arr = new int[strs.length];
        for(int i = 0; i < strs.length; i++)
        {
            arr[i] =  Integer.parseInt(strs[i]);
        }
        return arr;
    }

	public long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public long max(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public int max(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public long min(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public int min(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public long sum(long[] ar) {
        long sum = 0;
        for (long itr : ar) sum += itr;
        return sum;
    }

    public long sum(int[] ar) {
        long sum = 0;
        for (int itr : ar) sum += itr;
        return sum;
    }

    public void shuffle(int[] ar) {
        int r;
        for (int i = 0; i < ar.length; ++i) {
            r = rnd.nextInt(ar.length);
            if (r != i) {
                ar[i] ^= ar[r];
                ar[r] ^= ar[i];
                ar[i] ^= ar[r];
            }
        }
    }

    public void shuffle(long[] ar) {
        int r;
        for (int i = 0; i < ar.length; ++i) {
            r = rnd.nextInt(ar.length);
            if (r != i) {
                ar[i] ^= ar[r];
                ar[r] ^= ar[i];
                ar[i] ^= ar[r];
            }
        }
    }

    public long pow(long base, long exp, long MOD) {
        base %= MOD;
        long ret = 1;
        while (exp > 0) {
            if ((exp & 1) == 1) ret = ret * base % MOD;
            base = base * base % MOD;
            exp >>= 1;
        }
        return ret;
    }

    static byte[] buf = new byte[1000_006];
    static int index, total;
    static InputStream in;
    static BufferedWriter bw;

    public void initIO(InputStream is, OutputStream os) {
        try {
            in = is;
            bw = new BufferedWriter(new OutputStreamWriter(os));
        } catch (Exception e) {
        }
    }

    public void initIO(String inputFile, String outputFile) {
        try {
            in = new FileInputStream(inputFile);
            bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(outputFile)));
        } catch (Exception e) {
        }
    }

    private int scan() throws Exception {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0)
                return -1;
        }
        return buf[index++];
    }

    public String nextLine() throws Exception {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c >= 32; c = scan())
            sb.append((char) c);
        return sb.toString();
    }

    public String next() throws Exception {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan())
            sb.append((char) c);
        return sb.toString();
    }

    public int nextInt() throws Exception {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public long nextLong() throws Exception {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public void print(Object a) throws Exception {
        bw.write(a.toString());
    }

    public void printsp(Object a) throws Exception {
        print(a);
        print(" ");
    }

    public void println() throws Exception {
        bw.write("\n");
    }

    public void println(Object a) throws Exception {
        print(a);
        println();
    }

    public void flush() throws Exception {
        bw.flush();
    }
}


/* @nikhil_supertramp */

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

public class AnuHasAFunction
{
    public static void main(String[] args)throws Exception
    {
        new Solver().solve();
    }
}
//  cd competetive-programming/src/Codeforces
//  javac -d ../../classes AnuHasAFunction.java
//  java AnuHasAFunction
//  problem link : https://codeforces.com/contest/1300/problem/C

class Solver {
    final Helper hp;
    final int MAXN = 1000_006;
    final long MOD = (long) 1e9 + 7;
    void solve() throws Exception
    {
        //for(int tc = hp.nextInt(); tc > 0; tc--)
        {
            int n = hp.nextInt();
            int  arr[] = hp.getIntArray(n);
            for(int b = 30; b >= 0; b--)
            {
                ArrayList<Integer> li = new ArrayList<>();
                for(int i = 0; i < n; i++)
                {
                    if(((arr[i]) & (1 << b)) > 0)
                        li.add(i);
                }

                if(li.size() == 1)
                {
                    hp.print(arr[li.get(0)] + " ");
                    for(int i = 0; i < n; i++)
                    {
                        if(i != li.get(0))
                            hp.print(arr[i] + " ");
                    }
                    hp.println();
                    hp.flush();
                    return;
                }
            }
            for(int i : arr)hp.print(i + " ");
        }

        hp.flush();
    }

    Solver() {
        hp = new Helper(MOD, MAXN);
        hp.initIO(System.in, System.out);
    }
}

class Pair implements Comparable<Pair>{
    int x;
    int y;//long z;

    public Pair(int x, int y)
    {
        this.x = x;
        this.y = y;
        //this.z = z;
    }
    @Override
    public int compareTo(Pair p)
    {
        if(p.y == y)
        return x - p.x;
        return p.y - y;
    }
}

class Helper {
    final long MOD;
    final int MAXN;
    final Random rnd;

    public Helper(long mod, int maxn) {
        MOD = mod;
        MAXN = maxn;
        rnd = new Random();
    }

    public static int[] sieve;
    public static ArrayList<Integer> primes;

    public void setSieve() {
        primes = new ArrayList<>();
        sieve = new int[MAXN];
        int i, j;
        for (i = 2; i < MAXN; ++i)
            if (sieve[i] == 0) {
                primes.add(i);
                for (j = i; j < MAXN; j += i) {
                    sieve[j] = i;
                }
            }
    }

    public static long[] factorial;

    public void setFactorial() {
        factorial = new long[MAXN];
        factorial[0] = 1;
        for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
    }

    public long getFactorial(int n) {
        if (factorial == null) setFactorial();
        return factorial[n];
    }

    public long ncr(int n, int r) {
        if (r > n) return 0;
        if (factorial == null) setFactorial();
        long numerator = factorial[n];
        long denominator = factorial[r] * factorial[n - r] % MOD;
        return numerator * pow(denominator, MOD - 2, MOD) % MOD;
    }

    public long[] getLongArray(int size) throws Exception {
        long[] ar = new long[size];
        for (int i = 0; i < size; ++i) ar[i] = nextLong();
        return ar;
    }

    public int[] getIntArray(int size) throws Exception {
        int[] ar = new int[size];
        for (int i = 0; i < size; ++i) ar[i] = nextInt();
        return ar;
	}

    public int[] getIntArray(String s)throws Exception
    {
        s = s.trim().replaceAll("\\s+", " ");
        String[] strs = s.split(" ");
        int[] arr = new int[strs.length];
        for(int i = 0; i < strs.length; i++)
        {
            arr[i] =  Integer.parseInt(strs[i]);
        }
        return arr;
    }

	public long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public long max(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public int max(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public long min(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public int min(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public long sum(long[] ar) {
        long sum = 0;
        for (long itr : ar) sum += itr;
        return sum;
    }

    public long sum(int[] ar) {
        long sum = 0;
        for (int itr : ar) sum += itr;
        return sum;
    }

    public void shuffle(int[] ar) {
        int r;
        for (int i = 0; i < ar.length; ++i) {
            r = rnd.nextInt(ar.length);
            if (r != i) {
                ar[i] ^= ar[r];
                ar[r] ^= ar[i];
                ar[i] ^= ar[r];
            }
        }
    }

    public void shuffle(long[] ar) {
        int r;
        for (int i = 0; i < ar.length; ++i) {
            r = rnd.nextInt(ar.length);
            if (r != i) {
                ar[i] ^= ar[r];
                ar[r] ^= ar[i];
                ar[i] ^= ar[r];
            }
        }
    }

    public long pow(long base, long exp, long MOD) {
        base %= MOD;
        long ret = 1;
        while (exp > 0) {
            if ((exp & 1) == 1) ret = ret * base % MOD;
            base = base * base % MOD;
            exp >>= 1;
        }
        return ret;
    }

    static byte[] buf = new byte[1000_006];
    static int index, total;
    static InputStream in;
    static BufferedWriter bw;

    public void initIO(InputStream is, OutputStream os) {
        try {
            in = is;
            bw = new BufferedWriter(new OutputStreamWriter(os));
        } catch (Exception e) {
        }
    }

    public void initIO(String inputFile, String outputFile) {
        try {
            in = new FileInputStream(inputFile);
            bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(outputFile)));
        } catch (Exception e) {
        }
    }

    private int scan() throws Exception {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0)
                return -1;
        }
        return buf[index++];
    }

    public String nextLine() throws Exception {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c >= 32; c = scan())
            sb.append((char) c);
        return sb.toString();
    }

    public String next() throws Exception {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan())
            sb.append((char) c);
        return sb.toString();
    }

    public int nextInt() throws Exception {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public long nextLong() throws Exception {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public void print(Object a) throws Exception {
        bw.write(a.toString());
    }

    public void printsp(Object a) throws Exception {
        print(a);
        print(" ");
    }

    public void println() throws Exception {
        bw.write("\n");
    }

    public void println(Object a) throws Exception {
        print(a);
        println();
    }

    public void flush() throws Exception {
        bw.flush();
    }
}


/* @nikhil_supertramp */

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

public class AnuHasAFunction
{
    public static void main(String[] args)throws Exception
    {
        new Solver().solve();
    }
}
//  cd competetive-programming/src/Codeforces
//  javac -d ../../classes AnuHasAFunction.java
//  java AnuHasAFunction
//  problem link : https://codeforces.com/contest/1300/problem/C

class Solver {
    final Helper hp;
    final int MAXN = 1000_006;
    final long MOD = (long) 1e9 + 7;
    void solve() throws Exception
    {
        //for(int tc = hp.nextInt(); tc > 0; tc--)
        {
            int n = hp.nextInt();
            int  arr[] = hp.getIntArray(n);
            for(int b = 30; b >= 0; b--)
            {
                ArrayList<Integer> li = new ArrayList<>();
                for(int i = 0; i < n; i++)
                {
                    if(((arr[i]) & (1 << b)) > 0)
                        li.add(i);
                }

                if(li.size() == 1)
                {
                    hp.print(arr[li.get(0)] + " ");
                    for(int i = 0; i < n; i++)
                    {
                        if(i != li.get(0))
                            hp.print(arr[i] + " ");
                    }
                    hp.println();
                    hp.flush();
                    return;
                }
            }
            for(int i : arr)hp.print(arr[i] + " ");
        }

        hp.flush();
    }

    Solver() {
        hp = new Helper(MOD, MAXN);
        hp.initIO(System.in, System.out);
    }
}

class Pair implements Comparable<Pair>{
    int x;
    int y;//long z;

    public Pair(int x, int y)
    {
        this.x = x;
        this.y = y;
        //this.z = z;
    }
    @Override
    public int compareTo(Pair p)
    {
        if(p.y == y)
        return x - p.x;
        return p.y - y;
    }
}

class Helper {
    final long MOD;
    final int MAXN;
    final Random rnd;

    public Helper(long mod, int maxn) {
        MOD = mod;
        MAXN = maxn;
        rnd = new Random();
    }

    public static int[] sieve;
    public static ArrayList<Integer> primes;

    public void setSieve() {
        primes = new ArrayList<>();
        sieve = new int[MAXN];
        int i, j;
        for (i = 2; i < MAXN; ++i)
            if (sieve[i] == 0) {
                primes.add(i);
                for (j = i; j < MAXN; j += i) {
                    sieve[j] = i;
                }
            }
    }

    public static long[] factorial;

    public void setFactorial() {
        factorial = new long[MAXN];
        factorial[0] = 1;
        for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
    }

    public long getFactorial(int n) {
        if (factorial == null) setFactorial();
        return factorial[n];
    }

    public long ncr(int n, int r) {
        if (r > n) return 0;
        if (factorial == null) setFactorial();
        long numerator = factorial[n];
        long denominator = factorial[r] * factorial[n - r] % MOD;
        return numerator * pow(denominator, MOD - 2, MOD) % MOD;
    }

    public long[] getLongArray(int size) throws Exception {
        long[] ar = new long[size];
        for (int i = 0; i < size; ++i) ar[i] = nextLong();
        return ar;
    }

    public int[] getIntArray(int size) throws Exception {
        int[] ar = new int[size];
        for (int i = 0; i < size; ++i) ar[i] = nextInt();
        return ar;
	}

    public int[] getIntArray(String s)throws Exception
    {
        s = s.trim().replaceAll("\\s+", " ");
        String[] strs = s.split(" ");
        int[] arr = new int[strs.length];
        for(int i = 0; i < strs.length; i++)
        {
            arr[i] =  Integer.parseInt(strs[i]);
        }
        return arr;
    }

	public long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public long max(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public int max(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public long min(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public int min(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public long sum(long[] ar) {
        long sum = 0;
        for (long itr : ar) sum += itr;
        return sum;
    }

    public long sum(int[] ar) {
        long sum = 0;
        for (int itr : ar) sum += itr;
        return sum;
    }

    public void shuffle(int[] ar) {
        int r;
        for (int i = 0; i < ar.length; ++i) {
            r = rnd.nextInt(ar.length);
            if (r != i) {
                ar[i] ^= ar[r];
                ar[r] ^= ar[i];
                ar[i] ^= ar[r];
            }
        }
    }

    public void shuffle(long[] ar) {
        int r;
        for (int i = 0; i < ar.length; ++i) {
            r = rnd.nextInt(ar.length);
            if (r != i) {
                ar[i] ^= ar[r];
                ar[r] ^= ar[i];
                ar[i] ^= ar[r];
            }
        }
    }

    public long pow(long base, long exp, long MOD) {
        base %= MOD;
        long ret = 1;
        while (exp > 0) {
            if ((exp & 1) == 1) ret = ret * base % MOD;
            base = base * base % MOD;
            exp >>= 1;
        }
        return ret;
    }

    static byte[] buf = new byte[1000_006];
    static int index, total;
    static InputStream in;
    static BufferedWriter bw;

    public void initIO(InputStream is, OutputStream os) {
        try {
            in = is;
            bw = new BufferedWriter(new OutputStreamWriter(os));
        } catch (Exception e) {
        }
    }

    public void initIO(String inputFile, String outputFile) {
        try {
            in = new FileInputStream(inputFile);
            bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(outputFile)));
        } catch (Exception e) {
        }
    }

    private int scan() throws Exception {
        if (index >= total) {
            index = 0;
            total = in.read(buf);
            if (total <= 0)
                return -1;
        }
        return buf[index++];
    }

    public String nextLine() throws Exception {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c >= 32; c = scan())
            sb.append((char) c);
        return sb.toString();
    }

    public String next() throws Exception {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan())
            sb.append((char) c);
        return sb.toString();
    }

    public int nextInt() throws Exception {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public long nextLong() throws Exception {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public void print(Object a) throws Exception {
        bw.write(a.toString());
    }

    public void printsp(Object a) throws Exception {
        print(a);
        print(" ");
    }

    public void println() throws Exception {
        bw.write("\n");
    }

    public void println(Object a) throws Exception {
        print(a);
        println();
    }

    public void flush() throws Exception {
        bw.flush();
    }
}


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.print(a[i]+" ");
				i--;
			}
		}

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