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

public class D_AND_OR_Square_Sum {

	static String pad = "000000000000000000000000000000000000";

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
	    PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

	    int n = sc.nextInt();
	    int[] a = new int[n];

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

	    Arrays.sort(a);

	    int max_bits = Math.max(1, (int) Math.ceil((Math.log(a[a.length - 1])/Math.log(2))));

	    int[][] a_binary = new int[n][max_bits];
	    for(int i = 0; i < n; i++) {
	    	String s = new StringBuilder(Integer.toBinaryString(a[i])).reverse().toString() + pad;
	    	for(int j = 0; j < max_bits; j++) {
	    		a_binary[i][j] = Character.getNumericValue(s.charAt(j));
	    	}
	    }

	    // compute number of 1s at each bit across all n values
	    int[] bit_count = new int[max_bits];
	    for(int bit = 0; bit < max_bits; bit++) {
	    	for(int i = 0; i < a_binary.length; i++) {
	    		if(a_binary[i][bit] == 1) {
	    			bit_count[bit]++;
	    		}
	    	}
	    }

	    // update numbers by shifting our 1s as far right as possible
	    // update each row of bits
	    for(int bit = 0; bit < max_bits; bit++) {
	    	// go from right to left
	    	int v;
	    	for(v = n - 1; bit_count[bit] > 0 && v >= 0; v--) {
	    		if(a_binary[v][bit] == 0) {
	    			a_binary[v][bit] = 1;
	    		}

	    		// decrement if we see a 0 or 1 b/c we're using up 1s regardless
	    		bit_count[bit]--;
	    	}

	    	// make remaining bits 0
	    	for(; v >= 0; v--) {
	    		a_binary[v][bit] = 0;
	    	}
	    }

	    // calculate sum
	    long ans = 0;
	    for(int i = 0; i < a_binary.length; i++) {
	    	long curr_value = 0;
	    	for(int j = 0; j < a_binary[i].length; j++) {
	    		// sum using binary digits
	    		curr_value += Math.pow(2, j)*a_binary[i][j];
	    	}

	    	ans += curr_value*curr_value;
	    }

	    // print answer
	    out.println(ans);

	    out.close();
	}

	private static class MyScanner {
		BufferedReader br;
	    StringTokenizer st;

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


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

public class d extends PrintWriter{
    static BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
    // static Scanner s=new Scanner(System.in);
    d() { super(System.out); }
    public static void main(String[] args) throws IOException{
        d d1=new d();d1.main();d1.flush();
    }void main() throws IOException {
        //        StringBuilder sb = new StringBuilder();
        PrintWriter out = new PrintWriter(System.out);
      //  System.out.println('B'+4);
       // String[] s1=s();
       int t=1;
       while(t-->00){
        String[] s2=s();
        int n=i(s2[0]);
        long[] a=new long[n];
        String[] s3=s();for(int i=0;i<n;i++) a[i]=l(s3[i]);
        Arrays.sort(a);
        for(int bitno=0;bitno<21;bitno++){
            int i=0;int j=n-1;
            while(true)
            {
            while(j>=0&&(a[j]&(1<<bitno))!=0) j--;
            while(i<n&&(a[i]&(1<<bitno))==0) i++;
            if(i>=j) break;
            a[j]^=(1<<bitno);
            a[i]^=(1<<bitno);
            }
        }
        long ans=0;
        for(int i=0;i<n;i++){
            ans+=(a[i]*a[i]);
        }
           System.out.println(ans);
       }
    }
    static int MAXN;
    static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    static String[] s() throws IOException {

        return s.readLine().trim().split("\\s+");
    }

    static int i(String ss) {
        return Integer.parseInt(ss);
    }
    static long l(String ss) {
        return Long.parseLong(ss);
    }
}
class node implements Comparator<node>{
    int ver,val;
    public node(){}
    public node(int ver,int val) {
        this.ver=ver;this.val=val;
    }public int compare(node n1,node n2){
        return n1.val-n2.val;
    }
}

class Student12 {
    int  l;int r;
    public Student12(int l, int r) {
        this.l = l;
        this.r = r;
    }

    public String toString()
    {
        return this.l+" ";
    }
}
class Sortbyroll12 implements Comparator<Student12> {

    public int compare(Student12 a, Student12 b){
        return a.l-b.l;
        //        if(a.r<b.r) return 1;else if(a.r==b.r) return 0;else return -1;// a.r-b.r;
          /*  if(b.r<a.r) return -1;
            else if(b.r==a.r) return 0;
            return 1;*/

        //   return b.r-a.r;
           /*
           if(b.l<a.l) return -1;
           else if(b.l==a.l) {
               return b.r-a.r;
           }
           return 1;*/
        //        return b.r- a.r;
        //        return (int) a.l-(int) b.l;
             /*   if(a.r<b.r) return -1;
                else if(a.r==b.r){
                    if(a.r==b.r){
                        return 0;
                    }
                    if(a.r<b.r) return -1;
                    return 1;}
                return 1;  */}
}
class Node1 implements Comparator<Node1>{
    int node;long val;
    public  Node1(){}
    public  Node1(int node,long val){
        this.node=node;this.val=val;
    }
    @Override
    public int compare(Node1 a,Node1 b){
        if(a.val<b.val) return -1;
        if(a.val==b.val) return 0;
        {
            return 1;
        }
    }
}


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

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

    static class DANDORAndSquareSum {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int cnt[] = new int[20];
            long a[] = new long[200200];
            for (int i = 0; i < n; i++) {
                long x = in.nextLong();
                for (int j = 0; j < 20; j++) {
                    cnt[j] += (x >> j) & 1;
                }
            }
            for (int i = 0; i < 20; i++) {
                for (int j = 0; j < cnt[i]; j++) {
                    a[j] |= 1 << i;
                }
            }
            long ans = 0;
            for (int i = 0; i < n; i++) {
                ans += a[i] * a[i];
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

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

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
    public static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.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);
        }
    }

    static long gcd(long a, long b){
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    static long lcm(long a, long b)  {
        return (a*b)/gcd(a, b);
    }
    public static void sortbyColumn(int arr[][], int col)
    {

        Arrays.sort(arr, new Comparator<int[]>() {

          @Override

          public int compare(final int[] entry1,
                             final int[] entry2) {

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }
    static long func(long a[],long size,int s){
        long max1=a[s];
        long maxc=a[s];
        for(int i=s+1;i<size;i++){
            maxc=Math.max(a[i],maxc+a[i]);
            max1=Math.max(maxc,max1);
        }
        return max1;
    }
    public static class Pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<Pair<U, V>> {
        public U x;
        public V y;

        public Pair(U x, V y) {
            this.x = x;
            this.y = y;
        }

        public int hashCode() {
            return (x == null ? 0 : x.hashCode() * 31) + (y == null ? 0 : y.hashCode());
        }

        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Pair<U, V> p = (Pair<U, V>) o;
            return (x == null ? p.x == null : x.equals(p.x)) && (y == null ? p.y == null : y.equals(p.y));
        }

        public int compareTo(Pair<U, V> b) {
            int cmpU = x.compareTo(b.x);
            return cmpU != 0 ? cmpU : y.compareTo(b.y);
        }

        public String toString() {
            return String.format("(%s, %s)", x.toString(), y.toString());
        }

    }
    // static LinkedList<Integer> li;
    // static LinkedList<Integer> ans;
    static int ans1=0,ans2=0,k;
    static long dist[];
    static int visited[];
    //static int arr[];
    static ArrayList<Integer> adj[];

    public static void main(String args[]){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter w = new PrintWriter(outputStream);
        int t,i,j,flag=0;
        int n=in.nextInt();
        int count[]=new int[20];
        for(i=0;i<n;i++){
            long a=in.nextLong();
            for(j=0;j<20;j++){
                if((a&(1L<<j))>0){
                    count[j]++;
                }
            }
        }
        long max=1L<<19;
        long ans=0;
        for(i=0;i<n;i++){
            long at=max;
            long c=0;
            for(j=19;j>=0;j--){
                if(count[j]>0){
                    c+=at;
                    count[j]--;
                }
                at>>=1;
            }
            ans+=c*c;
        }
        w.println(ans);

        w.close();
    }
}


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

public class D implements Runnable {
	FastReader sc;
	PrintWriter out;
	long mod = (long)1e9 + 7;

	void solve()
	{

		int tc = 1;
		outer: while(tc-- > 0)
		{
			int n = sc.ni();
			long a[] = sc.nla(n);

			int cnt = 50;

			while(cnt-- > 0)
			{
				for(int i = n-2; i >= 0; i--)
				{
					long x = a[i]|a[i+1];
					long y = a[i]&a[i+1];

					a[i] = x;
					a[i+1] = y;
				}

				for(int i = 0; i < n-1; i++)
				{
					long x = a[i]|a[i+1];
					long y = a[i]&a[i+1];

					a[i] = x;
					a[i+1] = y;
				}
			}

			long ans = 0L;

			for(int i = 0; i < n; i++)
			{
				ans += a[i]*a[i];
			}
			out.println(ans);
		}
	}

	class Pair implements Comparable<Pair>
	{

		int x;
		int y;

		Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		}

		public int compareTo(Pair o)
		{

			if(x != o.x)
			{
				if(x > o.x) return 1;  //increasing order
				else return -1;
			}
			else
			{
				if(y > o.y) return 1;  //increasing order
				else return -1;
			}
		}
	}

	public void run()
	{
		out = new PrintWriter(System.out);
		sc = new FastReader();
		solve();
		out.flush();
	}

	public static void main(String[] args)
	{
		new Thread(null, new D(), "Main", 1 << 28).start();
	}

	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 ni()
        {
            return Integer.parseInt(next());
        }

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

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

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

		int[] nia(int n) {
			int[] ar = new int[n];
			for (int i = 0; i < n; i++)
				ar[i] = ni();
			return ar;
		}

		long[] nla(int n) {
			long[] ar = new long[n];
			for (int i = 0; i < n; i++)
				ar[i] = nl();
			return ar;
		}

		int[][] nim(int n, int m) {
			int[][] ar = new int[n][];
			for (int i = 0; i < n; i++) {
				ar[i] = nia(m);
			}
			return ar;
		}

		long[][] nlm(int n, int m) {
			long[][] ar = new long[n][];
			for (int i = 0; i < n; i++) {
				ar[i] = nla(m);
			}
			return ar;
		}

		String reverse(String s)
		{
			StringBuilder r = new StringBuilder(s);
			return r.reverse().toString();
		}

		void merge1(int arr[], int l, int m, int r)
	    {
	        int n1 = m - l + 1;
	        int n2 = r - m;
	        int L[] = new int [n1];
	        int R[] = new int [n2];
	        for (int i=0; i<n1; ++i)
	            L[i] = arr[l + i];
	        for (int j=0; j<n2; ++j)
	            R[j] = arr[m + 1+ j];
	        int i = 0, j = 0;
	        int k = l;
	        while (i < n1 && j < n2)
	        {
	            if (L[i]<=R[j])
	            {
	                arr[k] = L[i];
	                i++;
	            }
	            else
	            {
	                arr[k] = R[j];
	                j++;
	            }
	            k++;
	        }
	        while (i < n1)
	        {
	            arr[k] = L[i];
	            i++;
	            k++;
	        }
	        while (j < n2)
	        {
	            arr[k] = R[j];
	            j++;
	            k++;
	        }
	    }
	    void sort1(int arr[], int l, int r)
	    {
	        if (l < r)
	        {
	            int m = (l+r)/2;
	            sort1(arr, l, m);
	            sort1(arr , m+1, r);
	            merge1(arr, l, m, r);
	        }
	    }
    }
}


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

public class D implements Runnable {
	FastReader sc;
	PrintWriter out;
	long mod = (long)1e9 + 7;

	void solve()
	{

		int tc = 1;
		outer: while(tc-- > 0)
		{
			int n = sc.ni();
			long a[] = sc.nla(n);

			int cnt = 500;

			while(cnt-- > 0)
			{
				for(int i = n-2; i >= 0; i--)
				{
					long x = a[i]|a[i+1];
					long y = a[i]&a[i+1];

					a[i] = x;
					a[i+1] = y;
				}

				for(int i = 0; i < n-1; i++)
				{
					long x = a[i]|a[i+1];
					long y = a[i]&a[i+1];

					a[i] = x;
					a[i+1] = y;
				}
			}

			long ans = 0L;

			for(int i = 0; i < n; i++)
			{
				ans += a[i]*a[i];
			}
			out.println(ans);
		}
	}

	class Pair implements Comparable<Pair>
	{

		int x;
		int y;

		Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		}

		public int compareTo(Pair o)
		{

			if(x != o.x)
			{
				if(x > o.x) return 1;  //increasing order
				else return -1;
			}
			else
			{
				if(y > o.y) return 1;  //increasing order
				else return -1;
			}
		}
	}

	public void run()
	{
		out = new PrintWriter(System.out);
		sc = new FastReader();
		solve();
		out.flush();
	}

	public static void main(String[] args)
	{
		new Thread(null, new D(), "Main", 1 << 28).start();
	}

	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 ni()
        {
            return Integer.parseInt(next());
        }

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

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

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

		int[] nia(int n) {
			int[] ar = new int[n];
			for (int i = 0; i < n; i++)
				ar[i] = ni();
			return ar;
		}

		long[] nla(int n) {
			long[] ar = new long[n];
			for (int i = 0; i < n; i++)
				ar[i] = nl();
			return ar;
		}

		int[][] nim(int n, int m) {
			int[][] ar = new int[n][];
			for (int i = 0; i < n; i++) {
				ar[i] = nia(m);
			}
			return ar;
		}

		long[][] nlm(int n, int m) {
			long[][] ar = new long[n][];
			for (int i = 0; i < n; i++) {
				ar[i] = nla(m);
			}
			return ar;
		}

		String reverse(String s)
		{
			StringBuilder r = new StringBuilder(s);
			return r.reverse().toString();
		}

		void merge1(int arr[], int l, int m, int r)
	    {
	        int n1 = m - l + 1;
	        int n2 = r - m;
	        int L[] = new int [n1];
	        int R[] = new int [n2];
	        for (int i=0; i<n1; ++i)
	            L[i] = arr[l + i];
	        for (int j=0; j<n2; ++j)
	            R[j] = arr[m + 1+ j];
	        int i = 0, j = 0;
	        int k = l;
	        while (i < n1 && j < n2)
	        {
	            if (L[i]<=R[j])
	            {
	                arr[k] = L[i];
	                i++;
	            }
	            else
	            {
	                arr[k] = R[j];
	                j++;
	            }
	            k++;
	        }
	        while (i < n1)
	        {
	            arr[k] = L[i];
	            i++;
	            k++;
	        }
	        while (j < n2)
	        {
	            arr[k] = R[j];
	            j++;
	            k++;
	        }
	    }
	    void sort1(int arr[], int l, int r)
	    {
	        if (l < r)
	        {
	            int m = (l+r)/2;
	            sort1(arr, l, m);
	            sort1(arr , m+1, r);
	            merge1(arr, l, m, r);
	        }
	    }
    }
}


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

public class D implements Runnable {
	FastReader sc;
	PrintWriter out;
	long mod = (long)1e9 + 7;

	void solve()
	{

		int tc = 1;
		outer: while(tc-- > 0)
		{
			int n = sc.ni();
			long a[] = sc.nla(n);

			for(int i = n-2; i >= 0; i--)
			{
				long x = a[i]|a[i+1];
				long y = a[i]&a[i+1];

				a[i] = x;
				a[i+1] = y;
			}

			for(int i = 0; i < n-1; i++)
			{
				long x = a[i]|a[i+1];
				long y = a[i]&a[i+1];

				a[i] = x;
				a[i+1] = y;
			}

			long ans = 0L;

			for(int i = 0; i < n; i++)
			{
				ans += a[i]*a[i];
			}
			out.println(ans);
		}
	}

	class Pair implements Comparable<Pair>
	{

		int x;
		int y;

		Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		}

		public int compareTo(Pair o)
		{

			if(x != o.x)
			{
				if(x > o.x) return 1;  //increasing order
				else return -1;
			}
			else
			{
				if(y > o.y) return 1;  //increasing order
				else return -1;
			}
		}
	}

	public void run()
	{
		out = new PrintWriter(System.out);
		sc = new FastReader();
		solve();
		out.flush();
	}

	public static void main(String[] args)
	{
		new Thread(null, new D(), "Main", 1 << 28).start();
	}

	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 ni()
        {
            return Integer.parseInt(next());
        }

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

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

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

		int[] nia(int n) {
			int[] ar = new int[n];
			for (int i = 0; i < n; i++)
				ar[i] = ni();
			return ar;
		}

		long[] nla(int n) {
			long[] ar = new long[n];
			for (int i = 0; i < n; i++)
				ar[i] = nl();
			return ar;
		}

		int[][] nim(int n, int m) {
			int[][] ar = new int[n][];
			for (int i = 0; i < n; i++) {
				ar[i] = nia(m);
			}
			return ar;
		}

		long[][] nlm(int n, int m) {
			long[][] ar = new long[n][];
			for (int i = 0; i < n; i++) {
				ar[i] = nla(m);
			}
			return ar;
		}

		String reverse(String s)
		{
			StringBuilder r = new StringBuilder(s);
			return r.reverse().toString();
		}

		void merge1(int arr[], int l, int m, int r)
	    {
	        int n1 = m - l + 1;
	        int n2 = r - m;
	        int L[] = new int [n1];
	        int R[] = new int [n2];
	        for (int i=0; i<n1; ++i)
	            L[i] = arr[l + i];
	        for (int j=0; j<n2; ++j)
	            R[j] = arr[m + 1+ j];
	        int i = 0, j = 0;
	        int k = l;
	        while (i < n1 && j < n2)
	        {
	            if (L[i]<=R[j])
	            {
	                arr[k] = L[i];
	                i++;
	            }
	            else
	            {
	                arr[k] = R[j];
	                j++;
	            }
	            k++;
	        }
	        while (i < n1)
	        {
	            arr[k] = L[i];
	            i++;
	            k++;
	        }
	        while (j < n2)
	        {
	            arr[k] = R[j];
	            j++;
	            k++;
	        }
	    }
	    void sort1(int arr[], int l, int r)
	    {
	        if (l < r)
	        {
	            int m = (l+r)/2;
	            sort1(arr, l, m);
	            sort1(arr , m+1, r);
	            merge1(arr, l, m, r);
	        }
	    }
    }
}


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

public class D implements Runnable {
	FastReader sc;
	PrintWriter out;
	long mod = (long)1e9 + 7;

	void solve()
	{

		int tc = 1;
		outer: while(tc-- > 0)
		{
			int n = sc.ni();
			long a[] = sc.nla(n);

			int cnt = 10000;

			while(cnt-- > 0)
			{
				for(int i = n-2; i >= 0; i--)
				{
					long x = a[i]|a[i+1];
					long y = a[i]&a[i+1];

					a[i] = x;
					a[i+1] = y;
				}

				for(int i = 0; i < n-1; i++)
				{
					long x = a[i]|a[i+1];
					long y = a[i]&a[i+1];

					a[i] = x;
					a[i+1] = y;
				}
			}

			long ans = 0L;

			for(int i = 0; i < n; i++)
			{
				ans += a[i]*a[i];
			}
			out.println(ans);
		}
	}

	class Pair implements Comparable<Pair>
	{

		int x;
		int y;

		Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		}

		public int compareTo(Pair o)
		{

			if(x != o.x)
			{
				if(x > o.x) return 1;  //increasing order
				else return -1;
			}
			else
			{
				if(y > o.y) return 1;  //increasing order
				else return -1;
			}
		}
	}

	public void run()
	{
		out = new PrintWriter(System.out);
		sc = new FastReader();
		solve();
		out.flush();
	}

	public static void main(String[] args)
	{
		new Thread(null, new D(), "Main", 1 << 28).start();
	}

	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 ni()
        {
            return Integer.parseInt(next());
        }

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

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

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

		int[] nia(int n) {
			int[] ar = new int[n];
			for (int i = 0; i < n; i++)
				ar[i] = ni();
			return ar;
		}

		long[] nla(int n) {
			long[] ar = new long[n];
			for (int i = 0; i < n; i++)
				ar[i] = nl();
			return ar;
		}

		int[][] nim(int n, int m) {
			int[][] ar = new int[n][];
			for (int i = 0; i < n; i++) {
				ar[i] = nia(m);
			}
			return ar;
		}

		long[][] nlm(int n, int m) {
			long[][] ar = new long[n][];
			for (int i = 0; i < n; i++) {
				ar[i] = nla(m);
			}
			return ar;
		}

		String reverse(String s)
		{
			StringBuilder r = new StringBuilder(s);
			return r.reverse().toString();
		}

		void merge1(int arr[], int l, int m, int r)
	    {
	        int n1 = m - l + 1;
	        int n2 = r - m;
	        int L[] = new int [n1];
	        int R[] = new int [n2];
	        for (int i=0; i<n1; ++i)
	            L[i] = arr[l + i];
	        for (int j=0; j<n2; ++j)
	            R[j] = arr[m + 1+ j];
	        int i = 0, j = 0;
	        int k = l;
	        while (i < n1 && j < n2)
	        {
	            if (L[i]<=R[j])
	            {
	                arr[k] = L[i];
	                i++;
	            }
	            else
	            {
	                arr[k] = R[j];
	                j++;
	            }
	            k++;
	        }
	        while (i < n1)
	        {
	            arr[k] = L[i];
	            i++;
	            k++;
	        }
	        while (j < n2)
	        {
	            arr[k] = R[j];
	            j++;
	            k++;
	        }
	    }
	    void sort1(int arr[], int l, int r)
	    {
	        if (l < r)
	        {
	            int m = (l+r)/2;
	            sort1(arr, l, m);
	            sort1(arr , m+1, r);
	            merge1(arr, l, m, r);
	        }
	    }
    }
}


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

public class D implements Runnable {
	FastReader sc;
	PrintWriter out;
	long mod = (long)1e9 + 7;

	void solve()
	{

		int tc = 1;
		outer: while(tc-- > 0)
		{
			int n = sc.ni();
			long a[] = sc.nla(n);

			int cnt[] = new int[21];

			for(int i = 0; i < n; i++)
			{
				long x = a[i];

				int bit = 0;
				while(x > 0)
				{
					if(x%2 != 0)
					{
						cnt[bit]++;
					}

					x = x/2;
					bit++;
				}
			}

			int steps = 0;
			for(int i = 0; i <= 20; i++)
			{
				steps = Math.max(steps,cnt[i]);
			}

			long ans = 0L;
			for(int i = 0; i < steps; i++)
			{
				long x = 0L;
				for(int j = 0; j <= 20; j++)
				{
					if(cnt[j] > 0)
					{
						x += (long)Math.pow(2,j);
						cnt[j]--;
					}
				}

				ans += x*x;
			}

			out.println(ans);
		}
	}

	class Pair implements Comparable<Pair>
	{

		int x;
		int y;

		Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		}

		public int compareTo(Pair o)
		{

			if(x != o.x)
			{
				if(x > o.x) return 1;  //increasing order
				else return -1;
			}
			else
			{
				if(y > o.y) return 1;  //increasing order
				else return -1;
			}
		}
	}

	public void run()
	{
		out = new PrintWriter(System.out);
		sc = new FastReader();
		solve();
		out.flush();
	}

	public static void main(String[] args)
	{
		new Thread(null, new D(), "Main", 1 << 28).start();
	}

	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 ni()
        {
            return Integer.parseInt(next());
        }

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

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

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

		int[] nia(int n) {
			int[] ar = new int[n];
			for (int i = 0; i < n; i++)
				ar[i] = ni();
			return ar;
		}

		long[] nla(int n) {
			long[] ar = new long[n];
			for (int i = 0; i < n; i++)
				ar[i] = nl();
			return ar;
		}

		int[][] nim(int n, int m) {
			int[][] ar = new int[n][];
			for (int i = 0; i < n; i++) {
				ar[i] = nia(m);
			}
			return ar;
		}

		long[][] nlm(int n, int m) {
			long[][] ar = new long[n][];
			for (int i = 0; i < n; i++) {
				ar[i] = nla(m);
			}
			return ar;
		}

		String reverse(String s)
		{
			StringBuilder r = new StringBuilder(s);
			return r.reverse().toString();
		}

		void merge1(int arr[], int l, int m, int r)
	    {
	        int n1 = m - l + 1;
	        int n2 = r - m;
	        int L[] = new int [n1];
	        int R[] = new int [n2];
	        for (int i=0; i<n1; ++i)
	            L[i] = arr[l + i];
	        for (int j=0; j<n2; ++j)
	            R[j] = arr[m + 1+ j];
	        int i = 0, j = 0;
	        int k = l;
	        while (i < n1 && j < n2)
	        {
	            if (L[i]<=R[j])
	            {
	                arr[k] = L[i];
	                i++;
	            }
	            else
	            {
	                arr[k] = R[j];
	                j++;
	            }
	            k++;
	        }
	        while (i < n1)
	        {
	            arr[k] = L[i];
	            i++;
	            k++;
	        }
	        while (j < n2)
	        {
	            arr[k] = R[j];
	            j++;
	            k++;
	        }
	    }
	    void sort1(int arr[], int l, int r)
	    {
	        if (l < r)
	        {
	            int m = (l+r)/2;
	            sort1(arr, l, m);
	            sort1(arr , m+1, r);
	            merge1(arr, l, m, r);
	        }
	    }
    }
}


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

public class D implements Runnable {
	FastReader sc;
	PrintWriter out;
	long mod = (long)1e9 + 7;

	void solve()
	{

		int tc = 1;
		outer: while(tc-- > 0)
		{
			int n = sc.ni();
			long a[] = sc.nla(n);

			int cnt = 100;

			while(cnt-- > 0)
			{
				for(int i = n-2; i >= 0; i--)
				{
					long x = a[i]|a[i+1];
					long y = a[i]&a[i+1];

					a[i] = x;
					a[i+1] = y;
				}

				for(int i = 0; i < n-1; i++)
				{
					long x = a[i]|a[i+1];
					long y = a[i]&a[i+1];

					a[i] = x;
					a[i+1] = y;
				}
			}

			long ans = 0L;

			for(int i = 0; i < n; i++)
			{
				ans += a[i]*a[i];
			}
			out.println(ans);
		}
	}

	class Pair implements Comparable<Pair>
	{

		int x;
		int y;

		Pair(int x,int y)
		{
			this.x = x;
			this.y = y;
		}

		public int compareTo(Pair o)
		{

			if(x != o.x)
			{
				if(x > o.x) return 1;  //increasing order
				else return -1;
			}
			else
			{
				if(y > o.y) return 1;  //increasing order
				else return -1;
			}
		}
	}

	public void run()
	{
		out = new PrintWriter(System.out);
		sc = new FastReader();
		solve();
		out.flush();
	}

	public static void main(String[] args)
	{
		new Thread(null, new D(), "Main", 1 << 28).start();
	}

	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 ni()
        {
            return Integer.parseInt(next());
        }

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

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

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

		int[] nia(int n) {
			int[] ar = new int[n];
			for (int i = 0; i < n; i++)
				ar[i] = ni();
			return ar;
		}

		long[] nla(int n) {
			long[] ar = new long[n];
			for (int i = 0; i < n; i++)
				ar[i] = nl();
			return ar;
		}

		int[][] nim(int n, int m) {
			int[][] ar = new int[n][];
			for (int i = 0; i < n; i++) {
				ar[i] = nia(m);
			}
			return ar;
		}

		long[][] nlm(int n, int m) {
			long[][] ar = new long[n][];
			for (int i = 0; i < n; i++) {
				ar[i] = nla(m);
			}
			return ar;
		}

		String reverse(String s)
		{
			StringBuilder r = new StringBuilder(s);
			return r.reverse().toString();
		}

		void merge1(int arr[], int l, int m, int r)
	    {
	        int n1 = m - l + 1;
	        int n2 = r - m;
	        int L[] = new int [n1];
	        int R[] = new int [n2];
	        for (int i=0; i<n1; ++i)
	            L[i] = arr[l + i];
	        for (int j=0; j<n2; ++j)
	            R[j] = arr[m + 1+ j];
	        int i = 0, j = 0;
	        int k = l;
	        while (i < n1 && j < n2)
	        {
	            if (L[i]<=R[j])
	            {
	                arr[k] = L[i];
	                i++;
	            }
	            else
	            {
	                arr[k] = R[j];
	                j++;
	            }
	            k++;
	        }
	        while (i < n1)
	        {
	            arr[k] = L[i];
	            i++;
	            k++;
	        }
	        while (j < n2)
	        {
	            arr[k] = R[j];
	            j++;
	            k++;
	        }
	    }
	    void sort1(int arr[], int l, int r)
	    {
	        if (l < r)
	        {
	            int m = (l+r)/2;
	            sort1(arr, l, m);
	            sort1(arr , m+1, r);
	            merge1(arr, l, m, r);
	        }
	    }
    }
}


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

public class HelloWorld{

     public static void main(String []args) throws IOException{
        Reader sc=new Reader();
        long ans=0;
        int n=sc.nextInt();
        long a[]=new long[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        long na[]=new long[n];
        for(int i=30;i>=0;i--){
            int count=0;
            for(int j=0;j<n;j++){
                if( (a[j]&(1<<i)) !=0 )count++;
            }
            //System.out.println(count);
            for(int j=0;j<count;j++){
                na[j]|=(1<<i);
            }
        }
        for(int i=0;i<n;i++){
            //System.out.print(na[i]+" ");
            ans+=(na[i]*na[i]);
        }
        //System.out.println();
        System.out.print(ans);
     }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}


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

public class HelloWorld{

     public static void main(String []args) throws IOException{
        Reader sc=new Reader();
        long ans=0;
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        int na[]=new int[n];
        for(int i=30;i>=0;i--){
            int count=0;
            for(int j=0;j<n;j++){
                if( (a[j]&(1<<i)) !=0 )count++;
            }
            //System.out.println(count);
            for(int j=0;j<count;j++){
                na[j]|=(1<<i);
            }
        }
        for(int i=0;i<n;i++){
            //System.out.print(na[i]+" ");
            ans+=(na[i]*na[i]);
        }
        System.out.println();
        System.out.print(ans);
     }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}


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

public class Codeforces_1368_D {
	static FastReader sc;
	static PrintWriter pw;

	public static void main(String[] args) throws FileNotFoundException {
		boolean submit = true;
		sc = new FastReader(submit);
		pw=new PrintWriter(System.out);

		int T = 1; //sc.nextInt();
		for (int t = 0; t < T; t++) {

			solve();
			pw.flush();
		}

		pw.close();

	}

	static void solve() {
		// Solution
		int n=_int();
		long[] Arr=new long[n];
		for(int i=0;i<n;i++) {
			Arr[i]=_long();
		}

		for(int i=0;i<n;i++) {
			for(int j=i+1;j<n ;j++) {
				long I=Arr[i];
				long J=Arr[j];
				//if((I&J)>0) {
				Arr[i]=I&J;
				Arr[j]=I|J;
				//}
			}
		}

		long sum=0;
		for(long x:Arr) {
			sum+=x*x;
		}
		Println(sum);
	}

	/*
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 */

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader(boolean b) throws FileNotFoundException {
			if (b) {
				br = new BufferedReader(new InputStreamReader(System.in));
			} else {
				br = new BufferedReader(new FileReader("src/input.txt"));
			}

		}

		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 int _int() {
		return sc.nextInt();
	}

	static int[] _int(int n) {
		int[] Arr = new int[n];
		for (int i = 0; i < n; i++) {
			Arr[i] = sc.nextInt();
		}
		return Arr;
	}

	static int[][] _int(int m, int n) {
		int[][] Arr = new int[m][n];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				Arr[i][j] = sc.nextInt();
			}
		}
		return Arr;
	}

	static long _long() {
		return sc.nextLong();
	}

	static long[] _long(int n) {
		long[] Arr = new long[n];
		for (int i = 0; i < n; i++) {
			Arr[i] = sc.nextLong();
		}
		return Arr;
	}

	static long[][] _long(int m, int n) {
		long[][] Arr = new long[m][n];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				Arr[i][j] = sc.nextLong();
			}
		}
		return Arr;
	}

	static String _string() {
		return sc.next();
	}

	static String[] _string(int n) {
		String[] s = new String[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.next();
		}
		return s;
	}

	static char _char() {
		return sc.next().charAt(0);
	}

	static char[] _chars() {
		return sc.next().toCharArray();
	}

	static char[] _char(int n) {
		char[] c = new char[n];
		for (int i = 0; i < n; i++) {
			c[i] = sc.next().charAt(0);
		}
		return c;
	}

	static char[][] _chars(int n) {
		char[][] C = new char[n][];
		for (int i = 0; i < n; i++) {
			C[i] = _chars();
		}
		return C;
	}

	static char[][] _char(int m, int n) {
		char[][] C = new char[m][n];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				C[m][n] = sc.next().charAt(0);
			}
		}
		return C;
	}

	static int max(int m, int n) {
		return m > n ? m : n;
	}

	static int min(int m, int n) {
		return m < n ? m : n;
	}

	static long max(long m, long n) {
		return m > n ? m : n;
	}

	static long min(long m, long n) {
		return m < n ? m : n;
	}

	static int max(Iterable<Integer> A) {
		int ans = Integer.MIN_VALUE;
		for (int i : A) {
			if (i > ans) {
				ans = i;
			}
		}
		return ans;
	}

	static int min(Iterable<Integer> A) {
		int ans = Integer.MAX_VALUE;
		for (int i : A) {
			if (i < ans) {
				ans = i;
			}
		}
		return ans;
	}

	static int max(int[] A) {
		int ans = Integer.MIN_VALUE;
		for (int i : A) {
			if (i > ans) {
				ans = i;
			}
		}
		return ans;
	}

	static int min(int[] A) {
		int ans = Integer.MAX_VALUE;
		for (int i : A) {
			if (i < ans) {
				ans = i;
			}
		}
		return ans;
	}

	static void Println() {
		pw.println();
	}

	static void Print(long x) {
		pw.print(x);
	}

	static void Println(long x) {
		pw.println(x);
	}

	static void Print(String s) {
		pw.print(s);
	}

	static void Println(String s) {
		pw.println(s);
	}

	static void Println(String[] A) {
		for (String s : A) {
			pw.println(s);
		}
	}

	static void Print(String[] A) {
		for (String s : A) {
			pw.print(s + " ");
		}
		pw.println();
	}

	static void Print(int[] A) {
		for (int i : A) {
			pw.print(i + " ");
		}
		pw.println();
	}

	static void Println(int[] A) {
		for (int i : A) {
			pw.println(i);
		}
	}

	static void Println(int[][] A) {
		for (int[] a : A) {
			for (int i : a) {
				pw.print(i + " ");
			}
			pw.println();
		}
	}

	static void Sort(int[] A) {
		Arrays.sort(A);
	}

	static void Sort(List<Integer> A) {
		Collections.sort(A);
	}

	static void Sortr(int[] A) {
		Arrays.sort(A);
		reverse(A);
	}

	static void reverse(int[] A) {
		int n = A.length;
		if (n < 2)
			return;
		int temp;
		for (int i = 0; i < n / 2; i++) {
			temp = A[i];
			A[i] = A[n - i - 1];
			A[n - i - 1] = temp;
		}
	}

	static void Sortr(List<Integer> A) {
		Collections.sort(A, Collections.reverseOrder());
	}

}


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

public class Codeforces_1368_D {
	static FastReader sc;
	static PrintWriter pw;

	public static void main(String[] args) throws FileNotFoundException {
		boolean submit = true;
		sc = new FastReader(submit);
		pw=new PrintWriter(System.out);

		int T = 1; //sc.nextInt();
		for (int t = 0; t < T; t++) {

			solve();
			pw.flush();
		}

		pw.close();

	}

	static void solve() {
		// Solution
		int n=_int();
		long[] Arr=new long[n];
		for(int i=0;i<n;i++) {
			Arr[i]=_long();
		}

		int[] bits=new int[22];
		for(long x:Arr) {
			for(int i=0;i<22;i++) {
				bits[i] +=  (x&(1<<i))>>i;
			}
		}

		//Print(bits);

		long sum=0;

		while(true) {
			long cur=0;
			for(int i=0;i<22;i++) {
				if(bits[i]>0) {
					cur+=1<<i;
					bits[i]--;
				}
			}
			if(cur==0) break;
			sum+=cur*cur;
		}
		Println(sum);
	}

	/*
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 *
	 */

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader(boolean b) throws FileNotFoundException {
			if (b) {
				br = new BufferedReader(new InputStreamReader(System.in));
			} else {
				br = new BufferedReader(new FileReader("src/input.txt"));
			}

		}

		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 int _int() {
		return sc.nextInt();
	}

	static int[] _int(int n) {
		int[] Arr = new int[n];
		for (int i = 0; i < n; i++) {
			Arr[i] = sc.nextInt();
		}
		return Arr;
	}

	static int[][] _int(int m, int n) {
		int[][] Arr = new int[m][n];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				Arr[i][j] = sc.nextInt();
			}
		}
		return Arr;
	}

	static long _long() {
		return sc.nextLong();
	}

	static long[] _long(int n) {
		long[] Arr = new long[n];
		for (int i = 0; i < n; i++) {
			Arr[i] = sc.nextLong();
		}
		return Arr;
	}

	static long[][] _long(int m, int n) {
		long[][] Arr = new long[m][n];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				Arr[i][j] = sc.nextLong();
			}
		}
		return Arr;
	}

	static String _string() {
		return sc.next();
	}

	static String[] _string(int n) {
		String[] s = new String[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.next();
		}
		return s;
	}

	static char _char() {
		return sc.next().charAt(0);
	}

	static char[] _chars() {
		return sc.next().toCharArray();
	}

	static char[] _char(int n) {
		char[] c = new char[n];
		for (int i = 0; i < n; i++) {
			c[i] = sc.next().charAt(0);
		}
		return c;
	}

	static char[][] _chars(int n) {
		char[][] C = new char[n][];
		for (int i = 0; i < n; i++) {
			C[i] = _chars();
		}
		return C;
	}

	static char[][] _char(int m, int n) {
		char[][] C = new char[m][n];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				C[m][n] = sc.next().charAt(0);
			}
		}
		return C;
	}

	static int max(int m, int n) {
		return m > n ? m : n;
	}

	static int min(int m, int n) {
		return m < n ? m : n;
	}

	static long max(long m, long n) {
		return m > n ? m : n;
	}

	static long min(long m, long n) {
		return m < n ? m : n;
	}

	static int max(Iterable<Integer> A) {
		int ans = Integer.MIN_VALUE;
		for (int i : A) {
			if (i > ans) {
				ans = i;
			}
		}
		return ans;
	}

	static int min(Iterable<Integer> A) {
		int ans = Integer.MAX_VALUE;
		for (int i : A) {
			if (i < ans) {
				ans = i;
			}
		}
		return ans;
	}

	static int max(int[] A) {
		int ans = Integer.MIN_VALUE;
		for (int i : A) {
			if (i > ans) {
				ans = i;
			}
		}
		return ans;
	}

	static int min(int[] A) {
		int ans = Integer.MAX_VALUE;
		for (int i : A) {
			if (i < ans) {
				ans = i;
			}
		}
		return ans;
	}

	static void Println() {
		pw.println();
	}

	static void Print(long x) {
		pw.print(x);
	}

	static void Println(long x) {
		pw.println(x);
	}

	static void Print(String s) {
		pw.print(s);
	}

	static void Println(String s) {
		pw.println(s);
	}

	static void Println(String[] A) {
		for (String s : A) {
			pw.println(s);
		}
	}

	static void Print(String[] A) {
		for (String s : A) {
			pw.print(s + " ");
		}
		pw.println();
	}

	static void Print(int[] A) {
		for (int i : A) {
			pw.print(i + " ");
		}
		pw.println();
	}

	static void Println(int[] A) {
		for (int i : A) {
			pw.println(i);
		}
	}

	static void Println(int[][] A) {
		for (int[] a : A) {
			for (int i : a) {
				pw.print(i + " ");
			}
			pw.println();
		}
	}

	static void Sort(int[] A) {
		Arrays.sort(A);
	}

	static void Sort(List<Integer> A) {
		Collections.sort(A);
	}

	static void Sortr(int[] A) {
		Arrays.sort(A);
		reverse(A);
	}

	static void reverse(int[] A) {
		int n = A.length;
		if (n < 2)
			return;
		int temp;
		for (int i = 0; i < n / 2; i++) {
			temp = A[i];
			A[i] = A[n - i - 1];
			A[n - i - 1] = temp;
		}
	}

	static void Sortr(List<Integer> A) {
		Collections.sort(A, Collections.reverseOrder());
	}

}


import java.util.*;

//import javax.lang.model.util.ElementScanner6;

import java.lang.*;
import java.util.Scanner;

//import jdk.internal.org.jline.utils.InputStreamReader;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class q3
{
	public static void main (String[] args) throws java.lang.Exception
	{
        // your code goes here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out= new PrintWriter(System.out);
        long n= Long.parseLong(br.readLine());
        long[] arr = new long[(int)n];
        String[] ab= br.readLine().split(" ");
        long[] count=new long[20];
        for(int i=0;i<n;i++)
        {
            arr[i]=Long.parseLong(ab[i]);
            for(int it=0;it<20;it++)
            {
                if((arr[i] & (1<<it))>=1)
                {
                    count[it]++;
                }
            }
        }
        // for(int i=0;i<20;i++)
        // {
        //     System.out.print(count[i]+" ");
        // }
        long ans=0;
        for(int i=0;i<n;i++)
        {
            long prod=0;
            for(int j=0;j<20;j++)
            {
                if(count[j]>=1)
                {
                    prod+=Math.pow(2,j);
                }
                count[j]--;
            }
            ans+=(prod*prod);
        }
        out.print(ans);
        out.flush();

    }
}


import java.util.*;

//import javax.lang.model.util.ElementScanner6;

import java.lang.*;
import java.util.Scanner;

//import jdk.internal.org.jline.utils.InputStreamReader;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class q3
{
	public static void main (String[] args) throws java.lang.Exception
	{
        // your code goes here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out= new PrintWriter(System.out);
        long n= Long.parseLong(br.readLine());
        long[] arr = new long[(int)n];
        String[] ab= br.readLine().split(" ");
        for(int i=0;i<n;i++)
        {
            arr[i]=Long.parseLong(ab[i]);
        }
        Arrays.sort(arr);
        for(long i=n-2;i>=0;i--)
        {
            long a=arr[(int)n-1]|arr[(int)i];
            long b =arr[(int)i]&arr[(int)n-1];
            arr[(int)n-1]=a;
            arr[(int)i]=b;

        }
        long ans= 0;
        for(int i=0;i<n;i++)
        {
            //System.out.print(arr[i]+" ");
            ans+=(arr[i]*arr[i]);
        }
        System.out.println(ans);

    }
}


import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.text.DecimalFormat;
import java.lang.Math;
import java.util.Iterator;
import java.util.TreeSet;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.*;

public class A1360{
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static long mod = (long)(1e9+7);
	static FastReader sc = new FastReader();
	//static boolean[] sieve = new boolean[10000001];
	public static void main(String[] args) {
		int t = 1;
		//Arrays.fill(sieve, true);
        //soe();
		while(t-->0){
		    int n = sc.nextInt();
		    int[] a = new int[21];
		    int[] b = new int[n];
		    for(int i = 0; i < n; i++){
		        b[i] = sc.nextInt();
		    }
		    for(int i = 0; i < n; i++){
		        int mask = b[i];
		        for(int j = 0; j < 21; j++){
		            int lastBit = (mask & 1);
		            if(lastBit==1){
		                a[j]++;
		            }
		            mask >>= 1;
		        }
		    }
		    long ans = 0;
		    while(true){
		        long temp = 0;
		        for(int i = 0; i < 21; i++){
		            if(a[i]>0){
		                temp += (int)Math.pow(2,i);
		                a[i]--;
		            }
		        }
		        if(temp==0){
		            break;
		        }
		        else{
		            ans += temp*temp;
		        }
		    }
		    out.println(ans);
		}
		out.close();
	}
	/*public static void soe() {
		sieve[0]=sieve[1]=false;
		for(int i=2;i<=10000000;i++) {
			if(sieve[i]) {
				if(i*1l*i<=10000000) {
					for(int j = i*i;j<=10000000;j+=i) {
						sieve[j] = false;
					}
				}
			}
		}
	}*/
	public static int ffloor(int[] b, long ele){
	    int s = 0;
	    int e = b.length-1;
	    while(s<=e){
	        int m = s+(e-s)/2;
	        if(b[m] == ele){
	            return b[m];
	        }
	        else if(b[m]>ele){
	            e = m-1;
	        }
	        else{
	            s = m+1;
	        }
	    }
	    return b[e];
	}
	public static int cceil(int[] a, long ele){
	    int s = 0;
	    int e = a.length-1;
	    while(s<=e){
	        int m = s+(e-s)/2;
	        if(a[m] == ele){
	            return a[m];
	        }
	        else if(a[m]>ele){
	            e = m-1;
	        }
	        else{
	            s = m+1;
	        }
	    }
	    return a[s];
	}
	public static int floor(ArrayList<Pair> A , long ele){
	    int s = 0;
	    int e = A.size()-1;
	    while(s<=e){
	        int m = s+(e-s)/2;
	        if(A.get(m).x == ele){
	            return A.get(m).x;
	        }
	        else if(A.get(m).x>ele){
	            e = m-1;
	        }
	        else{
	            s = m+1;
	        }
	    }
	    return A.get(e).x;
	}
	public static int ceil(Pair[] a, long ele){
	    int s = 0;
	    int e = a.length-1;
	    while(s<=e){
	        int m = s+(e-s)/2;
	        if(a[m].x == ele){
	            a[m].y = 1;
	            return a[m].x;
	        }
	        else if(a[m].x>ele){
	            e = m-1;
	        }
	        else{
	            s = m+1;
	        }
	    }
	    a[s].y = 1;
	    return a[s].x;
	}
	////////////////////////////////////////////////////////////////////////////////
	static class Pair implements Comparable<Pair>{
		int x;
		int y;
		public Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}
		@Override
		public int compareTo(Pair o) {
			// TODO Auto-generated method stub
			if(this.x==o.x){
			    return (this.y-o.y);
			}
			return (this.x-o.x);
		}
	}
	public static int countSetBits(int n){
	    int count = 0;
	    while(n>0){
	        count += n&1;
	        n >>= 1;
	    }
	    return count;
	}
	public static boolean isPrime(int n){
	    if(n < 2){
	        return false;
	    }
	    if(n%2==0){
	        return n==2;
	    }
	    if(n%3==0){
	        return n==3;
	    }
	    int i = 5;
	    int h = (int)Math.floor(Math.sqrt(n)+1);
	    while(i <= h){
	        if(n%i==0){
	            return false;
	        }
	        if(n%(i+2)==0){
	            return false;
	        }
	        i += 6;
	    }
	    return true;
	}
	public static long gcd(long a, long b){
	    return b==0? a:gcd(b, a%b);
	}
	public static long bSearch(int n,ArrayList<Long> A){
	    int s = 0;
	    int e = A.size()-1;
	    while(s<=e){
	        int m = s+(e-s)/2;
	        if(A.get(m)==(long)n){
	            return A.get(m);
	        }
	        else if(A.get(m)>(long)n){
	            e = m-1;
	        }
	        else{
	            s = m+1;
	        }
	    }
	    return A.get(s);
	}
	static long modulo = (long)1e9+7;
	public static long modinv(long x){
	    return modpow(x, modulo-2);
	}
	public static long modpow(long a, long b){
	    if(b==0){
	        return 1;
	    }
	    long x = modpow(a, b/2);
	    x = (x*x)%modulo;
	    if(b%2==1){
	        return (x*a)%modulo;
	    }
	    return x;
	}
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct

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

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

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


import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    // Start writing your solution here. -------------------------------------

    int n = sc.nextInt();
    Long[] a = new Long[n];

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }

    Arrays.sort(a);
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        long x = a[i];
        long y = a[j];
        a[i] = x & y;
        a[j] = x | y;
      }
    }

    long sum = 0;
    for (int i = 0; i < n; i++) {
      sum += Math.pow(a[i], 2);
    }

    out.println(sum);

    // Stop writing your solution here. -------------------------------------
    out.close();
  }

  //-----------PrintWriter for faster output---------------------------------
  public static PrintWriter out;

  //-----------MyScanner class for faster input----------
  public static class MyScanner {

    BufferedReader br;
    StringTokenizer st;

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

  }
  //--------------------------------------------------------
}


import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    // Start writing your solution here. -------------------------------------

    int n = sc.nextInt();
    int[] b = new int[20];

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      for (int j = 0; a > 0; j++) {
        b[j] += a % 2;
        a /= 2;
      }
    }

    long sum = 0;
    for (int i = 19; i >= 0; i--) {
      while (b[i] > 0) {
        long a = 0;
        for (int j = i; j >= 0; j--) {
          if (b[j] > 0) {
            a += Math.pow(2, j);
            b[j]--;
          }
        }
        sum += Math.pow(a, 2);
      }
    }

    out.println(sum);

    // Stop writing your solution here. -------------------------------------
    out.close();
  }

  //-----------PrintWriter for faster output---------------------------------
  public static PrintWriter out;

  //-----------MyScanner class for faster input----------
  public static class MyScanner {

    BufferedReader br;
    StringTokenizer st;

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

  }
  //--------------------------------------------------------
}


import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    // Start writing your solution here. -------------------------------------

    int n = sc.nextInt();
    int[] b = new int[20];

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      for (int j = 0; a > 0; j++) {
        b[j] += a % 2;
        a /= 2;
      }
    }

    long sum = 0;
    for (int i = 19; i >= 0; i--) {
      while (b[i] > 0) {
        long a = 0;
        for (int j = i; j >= 0; j--) {
          if (b[j] > 0) {
            a += Math.pow(2, j);
            b[j]--;
          }
        }
        sum += a * a;
      }
    }

    out.println(sum);

    // Stop writing your solution here. -------------------------------------
    out.close();
  }

  //-----------PrintWriter for faster output---------------------------------
  public static PrintWriter out;

  //-----------MyScanner class for faster input----------
  public static class MyScanner {

    BufferedReader br;
    StringTokenizer st;

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

  }
  //--------------------------------------------------------
}


import java.util.*;

/*
*
* */
public class TaskD {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int bit = 0; bit < 20; bit++) {
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                cnt += (a[i] >> bit & 1);
            }
            for (int i = 0; i < cnt; i++) {
                b[n - 1 - i] |= (1 << bit);
            }
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += b[i] * b[i];
        }
        System.out.println(ans);
    }
}


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

int main()
{
    int n;
    cin >> n;
    set<int>s;
    int A[n];
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        s.insert(a);
        A[i] = a;
    }
    if (s.find(1) != s.end()) {
        cout << 2*n << endl;
        for (int i = 0; i < n; i++) {
            cout << A[i] << " " << 1 << " ";
        }
        cout << endl;
        return 0;
    }
    for (int i = 0; i < n; i++) {
        int g = A[i];
        for (int j = i + 1; j < n; j++) {
            g = __gcd(g, A[j]);
        }
        if (s.find(g) == s.end()) {
            cout << -1;
            return 0;
        }
    }
    cout << 2*n << endl;
    for (int i = 0; i < n; i++) {
        cout << A[i] << " " << A[0] << " ";
    }
}


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

int main()
{
    int n;
    cin >> n;
    set<int>s;
    int A[n];
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        s.insert(a);
        A[i] = a;
    }
    if (s.find(1) != s.end()) {
        cout << 2*n << endl;
        for (int i = 0; i < n; i++) {
            cout << A[i] << " " << 1 << " ";
        }
        cout << endl;
    }
    for (int i = 0; i < n; i++) {
        int g = A[i];
        for (int j = i + 1; j < n; j++) {
            g = __gcd(g, A[j]);
        }
        if (s.find(g) == s.end()) {
            cout << -1;
            return 0;
        }
    }
    cout << 2*n << endl;
    for (int i = 0; i < n; i++) {
        cout << A[i] << " " << A[i] << " ";
    }
}


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

int main()
{
    int n;
    cin >> n;
    set<int>s;
    int A[n];
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        s.insert(a);
        A[i] = a;
    }
    if (s.find(1) != s.end()) {
        cout << 2*n << endl;
        for (int i = 0; i < n; i++) {
            cout << A[i] << " " << 1 << " ";
        }
        cout << endl;
        return 0;
    }
    for (int i = 0; i < n; i++) {
        int g = A[i];
        for (int j = i + 1; j < n; j++) {
            g = __gcd(g, A[j]);
        }
        if (s.find(g) == s.end()) {
            cout << -1;
            return 0;
        }
    }
    cout << 2*n << endl;
    for (int i = 0; i < n; i++) {
        cout << A[i] << " " << A[i] << " ";
    }
}


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

int main()
{
    int n;
    cin >> n;
    set<int>s;
    int A[n];
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        s.insert(a);
        A[i] = a;
    }
    if (s.find(1) != s.end()) {
        cout << 2*n << endl;
        for (int i = 0; i < n; i++) {
            cout << A[i] << " " << 1 << " ";
        }
        cout << endl;
        return 0;
    }
    vector<int>ans;
    for (int i = 0; i < n; i++) {
        ans.push_back(A[i]);
        bool f = false;
        if (i == n - 1) break;
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            if (s.find(__gcd(A[i], A[j])) != s.end() ) {
                ans.push_back(A[j]);
                f = true;
                break;
            }
        }
        if (!f) {
            cout << -1;
            return 0;
        }
    }
    cout << ans.size() << endl;
    for (int i : ans) {
        cout << i << " ";
    }
}


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

int main()
{
    int n;
    cin >> n;
    set<int>s;
    int A[n];
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        s.insert(a);
        A[i] = a;
    }
    if (s.find(1) != s.end()) {
        cout << 2*n << endl;
        for (int i = 0; i < n; i++) {
            cout << A[i] << " " << 1 << " ";
        }
        cout << endl;
    }
    for (int i = 0; i < n; i++) {
        int g = A[i];
        for (int j = i + 1; j < n; j++) {
            g = __gcd(g, A[j]);
        }
        if (s.find(g) == s.end()) {
            cout << -1;
            return 0;
        }
    }
    cout << 2*n << endl;
    for (int i = 0; i < n; i++) {
        cout << A[i] << " " << A[0] << " ";
    }
}


#include<bits\stdc++.h>
#define int long long
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define infi INT_MAX
#define rinfi INT_MIN
#define inf LLONG_MAX
#define rinf LLONG_MIN
#define ff first
#define ss second
using namespace std;
const int mx=2000000;
vector<int>g[mx];
map<int,int>vp;
int a,ok=0;
vector<int>ans;
void dfs(int p)
{
    vp[p]=1;
    ans.push_back(p);
    if(ans.size()==a)
    {
        ok=1;
        return;
    }
   // cout<<p<<" "<<ok<<endl;
    for(auto x: g[p])
    {
        if(vp[x]==0 && !ok){
            dfs(x);
            if(!ok)
                ans.pop_back();
        }
    }
}
main()
{
    //fast
    int tc=1,i,j,k;
    //cin>>tc;
    while(tc--)
    {
        cin>>a;
        int aa[a];
        map<int,int>mp;
        int gg;
        for(i=0;i<a;i++)
        {
            cin>>aa[i];
            gg=aa[i];
            mp[aa[i]]=1;
        }
        for(i=0;i<a;i++)
        {
            gg=__gcd(gg,aa[i]);
            for(j=0;j<a;j++)
            {
                if(i==j)
                    continue;
                else
                {
                    k=__gcd(aa[i],aa[j]);
                    if(mp[k]==1)
                    {
                       g[aa[i]].push_back(aa[j]);
                        g[aa[j]].push_back(aa[i]);
                    }
                }
            }
        }
        if(mp[gg]!=1){
        for(i=0;i<a;i++)
        {
            vp.clear();
            ans.clear();
            dfs(aa[i]);
            if(ok)
                break;
        }
        }
        else
        {
            ok=1;
            for(i=0;i<a;i++)
            {
                ans.push_back(gg);
                ans.push_back(aa[i]);
            }
        }
        if(!ok)
            cout<<-1<<endl;
        else
        {
            cout<<ans.size()<<endl;
            for(auto x : ans)
                cout<<x<<" ";
            cout<<endl;
        }
    }
}


#include<bits\stdc++.h>
#define int long long
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define infi INT_MAX
#define rinfi INT_MIN
#define inf LLONG_MAX
#define rinf LLONG_MIN
#define ff first
#define ss second
using namespace std;
vector<int>g[2000000];
map<int,int>vp;
int a,ok=0;
vector<int>ans;
void dfs(int p)
{
    vp[p]=1;
    ans.push_back(p);
    if(ans.size()==a)
    {
        ok=1;
        return;
    }
   // cout<<p<<" "<<ok<<endl;
    for(auto x: g[p])
    {
        if(vp[x]==0 && !ok){
            dfs(x);
            if(!ok)
                ans.pop_back();
        }
    }
}
main()
{
    //fast
    int tc=1,i,j,k;
    //cin>>tc;
    while(tc--)
    {
        cin>>a;
        int aa[a];
        map<int,int>mp;
        for(i=0;i<a;i++)
        {
            cin>>aa[i];
            mp[aa[i]]=1;
        }
        for(i=0;i<a;i++)
        {
            for(j=0;j<a;j++)
            {
                if(i==j)
                    continue;
                else
                {
                    k=__gcd(aa[i],aa[j]);
                    if(mp[k])
                    {
                        g[aa[i]].push_back(aa[j]);
                        g[aa[j]].push_back(aa[i]);
                    }
                }
            }
        }
        for(i=0;i<a;i++)
        {
            vp.clear();
            ans.clear();
            dfs(aa[i]);
            if(ok)
                break;
        }
        if(!ok)
            cout<<-1<<endl;
        else
        {
            cout<<ans.size()<<endl;
            for(auto x : ans)
                cout<<x<<" ";
            cout<<endl;
        }
    }
}


#include<bits\stdc++.h>
#define int long long
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#ifndef ONLINE_JUDGE
#define line cout<<"here - "<<__LINE__<<"\n";
#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
#else
#define line
#define dbg(a)
#endif
using namespace std;
int lcm(int a,int b)
{
    int an=__gcd(a,b);
    a/=an;
    return a*b;
}
main()
{
//    fast
    int tc=1,i,j;
//    cin>>tc;
    while(tc--)
    {
      int a;
      cin>>a;
      int aa[a];
      map<int,int>mp;
      for(i=0;i<a;i++)
        cin>>aa[i],mp[aa[i]]=1;
        for(i=0;i<a;i++)
        {
            if(aa[i]%aa[0])
            {
                cout<<-1<<endl;
                return 0;
            }
        }
       cout<<2*a<<endl;
       for(i=0;i<a;i++)
        cout<<aa[i]<<" "<<aa[0]<<" ";
       cout<<endl;

    }
}


#include<bits\stdc++.h>
#define int long long
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#ifndef ONLINE_JUDGE
#define line cout<<"here - "<<__LINE__<<"\n";
#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
#else
#define line
#define dbg(a)
#endif
using namespace std;
main()
{
//    fast
    int tc=1,i,j;
//    cin>>tc;
    while(tc--)
    {
      int a;
      cin>>a;
      int aa[a];
      map<int,int>mp;
      for(i=0;i<a;i++)
        cin>>aa[i],mp[aa[i]]=1;
        int ok=1;
        for(i=0;i<a;i++)
        {
            for(j=0;j<a;j++)
            {
                int p=__gcd(aa[i],aa[j]);
                if(mp[p]==0)
                  {
                      cout<<-1<<endl;
                      return 0;
                  }
            }
        }
      cout<<a<<endl;
       for(i=0;i<a;i++)
        cout<<aa[i]<<" ";

    }
}


#include<bits\stdc++.h>
#define int long long
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define infi INT_MAX
#define rinfi INT_MIN
#define inf LLONG_MAX
#define rinf LLONG_MIN
#define ff first
#define ss second
using namespace std;
vector<int>g[2000000];
map<int,int>vp;
int a,ok=0;
vector<int>ans;
void dfs(int p)
{
    vp[p]=1;
    ans.push_back(p);
    if(ans.size()==a)
    {
        ok=1;
        return;
    }
   // cout<<p<<" "<<ok<<endl;
    for(auto x: g[p])
    {
        if(vp[x]==0 && !ok){
            dfs(x);
            if(!ok)
                ans.pop_back();
        }
    }
}
main()
{
    //fast
    int tc=1,i,j,k;
    //cin>>tc;
    while(tc--)
    {
        cin>>a;
        int aa[a];
        map<int,int>mp;
        int g;
        for(i=0;i<a;i++)
        {
            cin>>aa[i];
            g=aa[i];
            mp[aa[i]]=1;
        }
        for(i=0;i<a;i++)
        {
            g=__gcd(g,aa[i]);
            for(j=0;j<a;j++)
            {
                if(i==j)
                    continue;
                else
                {
                    k=__gcd(aa[i],aa[j]);
                    if(mp[k])
                    {
                        g[aa[i]].push_back(aa[j]);
                        g[aa[j]].push_back(aa[i]);
                    }
                }
            }
        }
        if(mp[g]!=1){
        for(i=0;i<a;i++)
        {
            vp.clear();
            ans.clear();
            dfs(aa[i]);
            if(ok)
                break;
        }
        }
        else
        {
            ok=1
            for(i=0;i<a;i++)
            {
                ans.push_back(g);
                ans.push_back(aa[i]);
            }
        }
        if(!ok)
            cout<<-1<<endl;
        else
        {
            cout<<ans.size()<<endl;
            for(auto x : ans)
                cout<<x<<" ";
            cout<<endl;
        }
    }
}


#include<bits\stdc++.h>
#define int long long
#define endl '\n'
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#ifndef ONLINE_JUDGE
#define line cout<<"here - "<<__LINE__<<"\n";
#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
#else
#define line
#define dbg(a)
#endif
using namespace std;
main()
{
//    fast
    int tc=1,i,j;
//    cin>>tc;
    while(tc--)
    {
      int a;
      cin>>a;
      int aa[a];
      map<int,int>mp;
      for(i=0;i<a;i++)
        cin>>aa[i],mp[aa[i]]=1;
        int ok=1;
        for(i=0;i<a;i++)
        {
            int p=aa[i];
            for(j=0;j<a;j++)
            {
                p=__gcd(p,aa[j]);
                if(mp[p]==0)
                  {
                      cout<<-1<<endl;
                      return 0;
                  }
            }
        }
      cout<<a<<endl;
       for(i=0;i<a;i++)
        cout<<aa[i]<<" ";

    }
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define ld long double
#define pb push_back
#define mp3 make_pair
#define rep1(i,a,b) for(ll i=a;i<=b;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
const ll  mod=1e9+7;
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
const ll  N=100000+5;
int main(){
  IOS;
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
  cin>>a[i];
  ll p=a[0];
  for(ll i=1;i<n;i++){
     if(a[i]%p!=0){
       cout<<-1;
       return 0;
     }
  }
  cout<<n<<endl;
    for(ll i=0;i<n;i++){
      cout<<a[i]<<' ';
    }
  }


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define ld long double
#define pb push_back
#define mp3 make_pair
#define rep1(i,a,b) for(ll i=a;i<=b;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
const ll  mod=1e9+7;
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
const ll  N=100000+5;
int main(){
  IOS;
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
  cin>>a[i];
  ll p=a[0];
  for(ll i=1;i<n;i++){
     if(a[i]%p!=0){
       cout<<-1;
       return 0;
     }
  }
  cout<<2*(n-1)<<endl;
    for(ll i=1;i<n;i++){
      cout<<a[0]<<' '<<a[1]<<' ';
    }
  }


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define ld long double
#define pb push_back
#define mp3 make_pair
#define rep1(i,a,b) for(ll i=a;i<=b;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
const ll  mod=1e9+7;
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
const ll  N=100000+5;
int main(){
  IOS;
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
  cin>>a[i];
  ll p=a[0];
  for(ll i=1;i<n;i++){
     if(a[i]%p!=0){
       cout<<-1;
       return 0;
     }
  }
  cout<<2*(n)<<endl;
    for(ll i=0;i<n;i++){
      cout<<a[0]<<' '<<a[i]<<' ';
    }
  }


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define ld long double
#define pb push_back
#define mp3 make_pair
#define rep1(i,a,b) for(ll i=a;i<=b;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
const ll  mod=1e9+7;
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
const ll  N=100000+5;
int main(){
  IOS;
  ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
  cin>>a[i];
  ll p=a[0];
  for(ll i=1;i<n;i++){
     if(a[i]%p!=0){
       cout<<-1;
       return 0;
     }
  }
  cout<<2*(n-1)<<endl;
    for(ll i=1;i<n;i++){
      cout<<a[0]<<' '<<a[i]<<' ';
    }
  }


#include<bits/stdc++.h>

using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;

const int N = 1000 + 5 , M = 1e6 + 6;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);

int n , m;

int st[N << 2];
bool exist[N];

void update(int p , int l , int r , int dx , int x){
    if(l == r){
            st[p] = x;
            return;
    }

    int mid = (l + r) >> 1;
    if(dx <= mid) update(p << 1 , l , mid , dx , x);
    else update(p << 1 | 1 , mid + 1 , r , dx , x);

    st[p] = __gcd(st[p << 1] , st[p << 1 | 1]);
}

int query(int p , int l , int r , int S , int E){
    if(l >= S && r <= E) return st[p];
    if(l > E || r < S) return 0;

    int mid = (l + r) >> 1;
    return __gcd( query(p << 1 , l , mid , S , E) , query(p << 1 | 1 , mid + 1 , r , S , E) );
}

void solve(int testCase){

    scanf("%d" , &n);

    for(int i = 1 ; i <= n ; i ++){
            int x; scanf("%d" , &x);
            update(1 , 1 , n , i , x);
            exist[x] = 1;
    }

    for(int i = 1 ; i <= n ; i ++){
            for(int j = i+1 ; j <= n ; j ++){
                    if(!exist[ query(1 , 1 , n , i , j) ]){
                            printf("-1\n");
                            return;
                    }
            }
    }

    printf("%d\n" , n);
    for(int i = 1 ; i <= n ; i ++) printf("%d%c" , query(1 , 1 , n , i , i) , i == n ? '\n' : ' ');
}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;

const int N = 1000 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);

int n , m;
int a[N];

void solve(int testCase){

    scanf("%d" , &n);

    int mn = 2e6 , g = 0;
    for(int i = 0 ; i < n ; i ++){
            scanf("%d" , &a[i]);
            mn = min(mn , a[i]);
            g = __gcd(g , a[i]);
    }

    if(g != mn){
            printf("-1\n");
            return;
    }

    printf("%d\n" , 2*n);
    for(int i = 0 ; i < n ; i ++){
            printf("%d %d " , a[i] , mn);
    }
}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;

const int N = 1000 + 5 , M = 1e6 + 6;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);

int n , m;

int st[N << 2];
bool exist[M];

void update(int p , int l , int r , int dx , int x){
    if(l == r){
            st[p] = x;
            return;
    }

    int mid = (l + r) >> 1;
    if(dx <= mid) update(p << 1 , l , mid , dx , x);
    else update(p << 1 | 1 , mid + 1 , r , dx , x);

    st[p] = __gcd(st[p << 1] , st[p << 1 | 1]);
}

int query(int p , int l , int r , int S , int E){
    if(l >= S && r <= E) return st[p];
    if(l > E || r < S) return 0;

    int mid = (l + r) >> 1;
    return __gcd( query(p << 1 , l , mid , S , E) , query(p << 1 | 1 , mid + 1 , r , S , E) );
}

void solve(int testCase){

    scanf("%d" , &n);

    for(int i = 1 ; i <= n ; i ++){
            int x; scanf("%d" , &x);
            update(1 , 1 , n , i , x);
            exist[x] = 1;
    }

    for(int i = 1 ; i <= n ; i ++){
            for(int j = i+1 ; j <= n ; j ++){
                    if(!exist[ query(1 , 1 , n , i , j) ]){
                            printf("-1\n");
                            return;
                    }
            }
    }

    printf("%d\n" , n);
    for(int i = 1 ; i <= n ; i ++) printf("%d%c" , query(1 , 1 , n , i , i) , i == n ? '\n' : ' ');
}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<n;i++)
        if(a[i]%a[0])
        {
            cout<<-1<<endl;
            return;
        }
    cout<<2*n<<endl;
    for(int i=0;i<n;i++)
        cout<<a[i]<<" "<<a[0]<<" ";
    cout<<endl;

}

int32_t main()
{

    IOS;

    int t;
    t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<n;i++)
        if(a[i]%a[0])
        {
            cout<<-1<<endl;
            return;
        }
    cout<<2*n<<endl;
    for(int i=0;i<n;i++)
        cout<<a[i]<<" "<<a[0];
    cout<<endl;

}

int32_t main()
{

    IOS;

    int t;
    t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}