import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf3 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static void solve()throws IOException {
        int n = f.ni(); int arr[] = inpint(n); int ans[] = new int[n];
        int c[] = new int[25];
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < 25; ++j) {
                if(arr[i] & (1 << j) != 0) ++c[j];
            }
        }
        for(int e = 0; e < 25; ++e) {
            for(int i = 0; i < n; ++i) {
                if(c[e] > i) ans[i] += 1 << e;
            }
        }
        long res = 0;
        for(int i = 0; i < n; ++i) {
            res += (long)ans[i] * (long)anss[i];
        }
        pn(res);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nd(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long lcm(long a,long b){return (a*b/gcd(a,b));}
    static long gcd(long a,long b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf3 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static void solve()throws IOException {
        int n = f.ni(); int arr[] = inpint(n); int ans[] = new int[n];
        int c[] = new int[25];
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < 25; ++j) {
                if((arr[i] & (1 << j)) != 0) ++c[j];
            }
        }
        for(int e = 0; e < 25; ++e) {
            for(int i = 0; i < n; ++i) {
                if(c[e] > i) ans[i] += 1 << e;
            }
        }
        long res = 0;
        for(int i = 0; i < n; ++i) {
            res += (long)ans[i] * (long)anss[i];
        }
        pn(res);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nd(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long lcm(long a,long b){return (a*b/gcd(a,b));}
    static long gcd(long a,long b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf3 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static void solve()throws IOException {
        int n = f.ni(); int arr[] = inpint(n); int ans[] = new int[n];
        int c[] = new int[25];
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < 25; ++j) {
                if(arr[i] & (1 << j) != 0) ++c[j];
            }
        }
        for(int e = 0; e < 25; ++e) {
            for(int i = 0; i < n; ++i) {
                if(c[e] > i) ans[i] += 1 << e;
            }
        }
        long res = 0;
        for(int i = 0; i < n; ++i) {
            res += (long)ans[i] * (long)ans[i];
        }
        pn(res);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nd(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long lcm(long a,long b){return (a*b/gcd(a,b));}
    static long gcd(long a,long b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
import java.text.*;
public class cf3 {
    static long mod = (long)1e9 + 7;
    static long mod1 = 998244353;
    static FastScanner f;
    static PrintWriter pw = new PrintWriter(System.out);
    static Scanner S = new Scanner(System.in);
    static long x0; static long y0;
    static void solve()throws IOException {
        int n = f.ni(); int arr[] = inpint(n); int ans[] = new int[n];
        int c[] = new int[25];
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < 25; ++j) {
                if((arr[i] & (1 << j)) != 0) ++c[j];
            }
        }
        for(int e = 0; e < 25; ++e) {
            for(int i = 0; i < n; ++i) {
                if(c[e] > i) ans[i] += 1 << e;
            }
        }
        long res = 0;
        for(int i = 0; i < n; ++i) {
            res += (long)ans[i] * (long)ans[i];
        }
        pn(res);
    }
    public static void main(String[] args)throws IOException {
        init();
        int t = 1;
        while(t --> 0) {solve();}
        pw.flush();
        pw.close();
    }

/******************************END OF MAIN PROGRAM*******************************************/
    public static void init()throws IOException{if(System.getProperty("ONLINE_JUDGE")==null){f=new FastScanner("");}else{f=new FastScanner(System.in);}}
    public static class FastScanner {
        BufferedReader br;StringTokenizer st;
        FastScanner(InputStream stream){try{br=new BufferedReader(new InputStreamReader(stream));}catch(Exception e){e.printStackTrace();}}
        FastScanner(String str){try{br=new BufferedReader(new FileReader("!a.txt"));}catch(Exception e){e.printStackTrace();}}
        String next(){while(st==null||!st.hasMoreTokens()){try{st=new StringTokenizer(br.readLine());}catch(IOException e){e.printStackTrace();}}return st.nextToken();}
        String nextLine()throws IOException{return br.readLine();}int ni(){return Integer.parseInt(next());}long nl(){return Long.parseLong(next());}double nd(){return Double.parseDouble(next());}
    }
    public static void pn(Object o){pw.println(o);}
    public static void p(Object o){pw.print(o);}
    public static void pni(Object o){pw.println(o);pw.flush();}
    static int gcd(int a,int b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long lcm(long a,long b){return (a*b/gcd(a,b));}
    static long gcd(long a,long b){if(b==0)return a;else{return gcd(b,a%b);}}
    static long exgcd(long a,long b){if(b==0){x0=1;y0=0;return a;}long temp=exgcd(b,a%b);long t=x0;x0=y0;y0=t-a/b*y0;return temp;}
    static long pow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=res*a;b>>=1;a=a*a;}return res;}
    static long mpow(long a,long b){long res=1;while(b>0){if((b&1)==1)res=((res%mod)*(a%mod))%mod;b>>=1;a=((a%mod)*(a%mod))%mod;}return res;}
    static long mul(long a , long b){return ((a%mod)*(b%mod)%mod);}
    static long adp(long a , long b){return ((a%mod)+(b%mod)%mod);}
    static boolean isPrime(long n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(long i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static boolean isPrime(int n){if(n<=1)return false;if(n<=3)return true;if(n%2==0||n%3==0)return false;for(int i=5;i*i<=n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;}
    static HashSet<Long> factors(long n){HashSet<Long> hs=new HashSet<Long>();for(long i=1;i<=(long)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Integer> factors(int n){HashSet<Integer> hs=new HashSet<Integer>();for(int i=1;i<=(int)Math.sqrt(n);i++){if(n%i==0){hs.add(i);hs.add(n/i);}}return hs;}
    static HashSet<Long> pf(long n){HashSet<Long> ff=factors(n);HashSet<Long> ans=new HashSet<Long>();for(Long i:ff)if(isPrime(i))ans.add(i);return ans;}
    static HashSet<Integer> pf(int n){HashSet<Integer> ff=factors(n);HashSet<Integer> ans=new HashSet<Integer>();for(Integer i:ff)if(isPrime(i))ans.add(i);return ans;}
    static int[] inpint(int n){int arr[]=new int[n];for(int i=0;i<n;i++){arr[i]=f.ni();}return arr;}
    static long[] inplong(int n){long arr[] = new long[n];for(int i=0;i<n;i++){arr[i]=f.nl();}return arr;}
    static boolean ise(int x){return ((x&1)==0);}static boolean ise(long x){return ((x&1)==0);}
    static int gnv(char c){return Character.getNumericValue(c);}
    static int log(long x){return x==1?0:(1+log(x/2));} static int log(int x){return x==1?0:(1+log(x/2));}
    static void sort(int[] a){ArrayList<Integer> l=new ArrayList<>();for(int i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(long[] a){ArrayList<Long> l=new ArrayList<>();for(long i:a)l.add(i);Collections.sort(l);for(int i=0;i<a.length;++i)a[i]=l.get(i);}
    static void sort(ArrayList<Integer> a){Collections.sort(a);}
}


// package june2020;

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

public class cf_subs {
	static FastReader scn = new FastReader();
	static OutputStream out = new BufferedOutputStream(System.out);
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		int t = 1;
		while(t-->0) {
			int n = scn.nextInt();
			int[] bits = new int[21];
			int[] a = new int[n];

			for(int i=0;i<n;i++) {
				a[i] = scn.nextInt();
				for(int j=20;j>=0;j--) {
					if((a[i]&1<<j)>0) {
						bits[j]++;
					}
				}
			}
			long ans=0;
			while(sum(bits)>0) {
				long k=0;
				for(int i=20;i>=0;i--) {
					if(bits[i]>0) {
						bits[i]--;
						k+=(1<<i);
					}
				}
				ans+=k*k;
			}
			out.write((ans+"\n").getBytes());
		}
		out.close();
	}
	static int sum(int[] bits) {
		int ans=0;
		for(int i=0;i<=20;i++) {
			ans+=bits[i];
		}

		return ans;
	}
	public static int[] merge(int[] one,int[] two){
		int[] res = new int[one.length+two.length];
		int i = 0;
		int j = 0;
		int k = 0;

		while(i<one.length&&j<two.length){
			if(one[i]<two[j]){
				res[k] = one[i];
				i++;
				k++;
			}
			else{
				res[k] = two[j];
				j++;
				k++;
			}
		}

		if(i==one.length){
			while(j<two.length){
				res[k] = two[j];
				j++;
				k++;
			}
		}
		else{
			while(i<one.length){
				res[k] = one[i];
				k++;
				i++;
			}
		}
		return res;
	}
	public static int[] mergesort(int[] arr, int l, int r){
		if(l==r){
			int[] br = new int[1];
			br[0] = arr[l];
			return br;
		}
		int mid = (l+r)/2;
		int[] fh = mergesort(arr,l,mid);
		int[] sh = mergesort(arr,mid+1,r);

		return merge(fh,sh);
	}
//	static int dfs(int idx) {
//
//	}
	static <T> int upperBound(List<T> ls, T x) throws RuntimeException {
		if (ls.size() == 0)
			return -1;
		if (ls.get(0) instanceof Integer) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Integer) t1).compareTo((Integer) t2) > 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Long) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Long) t1).compareTo((Long) t2) > 0 ? 1 : -1);
		} else if (ls.get(0) instanceof Double) {
			return ~Collections.binarySearch(ls, x, (t1, t2) -> ((Double) t1).compareTo((Double) t2) > 0 ? 1 : -1);
		} else {
			System.err.println(
					String.format("%s:Arey Maa chudi padi hai", Thread.currentThread().getStackTrace()[1].getMethodName()));
			throw new RuntimeException();
		}
	}
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

}
//


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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
       int n = in.nextInt();
       int[] a = new int[n];
       for (int i = 0; i < n; i++) {
           a[i] = in.nextInt();
       }
       int[] cnt = new int[21];
       for (int i = 0; i < n; i++) {
           for (int j = 0; j < 20; j++) {
               if (((1 << j) & a[i]) != 0) {
                   cnt[j]++;
               }
           }
       }
       long answer = 0;
       while (true) {
           int ch = 0;
           int mn = Integer.MAX_VALUE;
           for (int j = 0; j < 20; j++) {
               if (cnt[j] != 0) {
                   ch |= (1 << j);
                   mn = Math.min(mn, cnt[j]);
               }
           }
           if (ch == 0) {
               break;
           }
           answer += (ch * 1l * ch) * mn;
           for (int j = 0; j < 20; j++) {
               if (cnt[j] != 0) {
                   cnt[j] -= mn;
               }
           }
       }
       out.println(answer);
       out.close();
    }
}


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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
       int n = in.nextInt();
       int[] a = new int[n];
       for (int i = 0; i < n; i++) {
           a[i] = in.nextInt();
       }
       for (int i = 1; i < n; i++) {
           int a0 = a[0];
           a[0] |= a[i];
           a[i] &= a0;
       }
       long answer = 0;
       for (int i = 0; i < n; i++) {
           answer += a[i] * 1l * a[i];
       }
       out.println(answer);
        out.close();
    }
}


import java.io.*;
import java.util.*;
public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static int ceildiv(int x, int y){
        return x%y==0? x/y: x/y+1;
    }
    static void count(HashMap<Integer, Integer> map, int x){
        for(int i=0; x>0; x>>=1, i++){
            if((x&1)==1){
                if(map.containsKey(i))
                    map.replace(i, map.get(i)+1);
                else
                    map.put(i, 1);
            }
        }
    }
    static void print(boolean b){ pw.println(b?"YES":"NO");}
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int n=sc.nextInt();
        int[] arr=sc.nextArr(n);
        HashMap<Integer, Integer> map= new HashMap<Integer, Integer>();
        for(int i=0; i<n; i++)
            count(map, arr[i]);
        long ans=0l;
        while(!map.isEmpty()){
            int x=0;
            for(int y: map.keySet())
                x+=1<<y;
            int temp=x;
            for(int i=0; x>0; x>>=1, i++){
                if((x&1)==1){
                    if(map.get(i)==1)
                        map.remove(i);
                    else
                        map.replace(i, map.get(i)-1);
                }
            }
            ans+=temp*1l*temp;
        }
        pw.println(ans);
        pw.close();
    }
    static void printArr(int[] arr){
        for(int i=0; i<arr.length-1; i++)
            pw.print(arr[i]+" ");
        pw.println(arr[arr.length-1]);
    }
    static void printArr(long[] arr){
        for(int i=0; i<arr.length-1; i++)
            pw.print(arr[i]+" ");
        pw.println(arr[arr.length-1]);
    }
    static void printArr(Integer[] arr){
        for(int i=0; i<arr.length-1; i++)
            pw.print(arr[i]+" ");
        pw.println(arr[arr.length-1]);
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n, int l) throws IOException{
            Pair[] arr=new Pair[n];
            if(l==2){
                int[] a=nextArr(n), b=nextArr(n);
                for(int i=0; i<n; i++)
                    arr[i]=new Pair(a[i], b[i]);
                return arr;
            }
            for(int i=0; i<n; i++)
                arr[i]=new Pair(nextInt(), nextInt());
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Kad{
        long sum;
        int max;
        public Kad(long x, int y) {
            this.sum=x;
            this.max=y;
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return this.x*1000+this.y;
        }
        public int compareTo(Pair other) {
            if(this.x!=other.x)
                return this.x-other.x;
            return this.y-other.y;
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
        public boolean equal(Pair p){
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
    }
}


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

import javax.swing.text.html.MinimalHTMLWriter;

public class tr1 {
	static PrintWriter out;
	static StringBuilder sb;
	static int n, m, k, x, y;
	static long mod = 998244353;
	static Boolean[][] memo;
	static String s;
	static HashSet<Integer>[] ad;
	static long inf = Long.MAX_VALUE;
	static int[] color;
	static ArrayList<Integer> o, z;
	static char[][] g;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();
		Arrays.sort(a);
		TreeSet<Integer>[] ts = new TreeSet[20];
		for (int i = 0; i < 20; i++)
			ts[i] = new TreeSet<>();
		int[] ar = new int[n];
		for (int i = 0; i < n; i++)
			ar[i] = a[i];
		for (int i = 0; i < n; i++) {
			for (int bit = 0; bit < 20; bit++) {
				if ((ar[i] & (1 << bit)) != 0) {
					ts[bit].add(i);
				}
			}
		}
		for (int i = n - 1; i >= 0; i--) {
			int[] remove = new int[20];
			Arrays.fill(remove, -1);
			for (int bit = 19; bit >= 0; bit--) {
				if ((ar[i] & (1 << bit)) == 0) {
					if (ts[bit].isEmpty())
						continue;
					int x = ar[i];
					int y = ar[ts[bit].first()];
					int id = ts[bit].first();
					ar[i] = x | y;
					ar[id] = x & y;
					int num = ar[id] ^ y;
					while (num > 0) {
						int p=(int)((Math.log10(num & -num)) / Math.log10(2)) ;
						remove[p] = id;
						num -= 1<<p;
					}
				}
			}
			for (int bit = 0; bit < 20; bit++) {
				if (remove[bit] != -1)
					ts[bit].remove(remove[bit]);
			}
			for (int bit = 0; bit < 20; bit++) {
				if (ts[bit].contains(i))
					ts[bit].remove(i);
			}
		}
		long ans = 0;
		for (int i = 0; i < n; i++)
			ans = ans + ar[i] * 1l * ar[i];
		out.println(ans);
		out.flush();
	}

	static int gcd(int a, int b) {

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

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

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

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

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}


import java.io.*;
import java.util.*;
public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static int ceildiv(int x, int y){
        return x%y==0? x/y: x/y+1;
    }
    static void count(TreeMap<Integer, Integer> map, int x){
        for(int i=0; x>0; x>>=1, i++){
            if((x&1)==1){
                if(map.containsKey(i))
                    map.replace(i, map.get(i)+1);
                else
                    map.put(i, 1);
            }
        }
    }
    static void print(boolean b){ pw.println(b?"YES":"NO");}
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int n=sc.nextInt();
        int[] arr=sc.nextArr(n);
        TreeMap<Integer, Integer> map= new TreeMap<Integer, Integer>();
        for(int i=0; i<n; i++)
            count(map, arr[i]);
        long ans=0l;
        while(!map.isEmpty()){
            int x=0;
            for(int y: map.keySet())
                x+=1<<y;
            int temp=x;
            for(int i=0; x>0; x>>=1, i++){
                if((x&1)==1){
                    if(map.get(i)==1)
                        map.remove(i);
                    else
                        map.replace(i, map.get(i)-1);
                }
            }
            ans+=temp*1l*temp;
        }
        pw.println(ans);
        pw.close();
    }
    static void printArr(int[] arr){
        for(int i=0; i<arr.length-1; i++)
            pw.print(arr[i]+" ");
        pw.println(arr[arr.length-1]);
    }
    static void printArr(long[] arr){
        for(int i=0; i<arr.length-1; i++)
            pw.print(arr[i]+" ");
        pw.println(arr[arr.length-1]);
    }
    static void printArr(Integer[] arr){
        for(int i=0; i<arr.length-1; i++)
            pw.print(arr[i]+" ");
        pw.println(arr[arr.length-1]);
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n, int l) throws IOException{
            Pair[] arr=new Pair[n];
            if(l==2){
                int[] a=nextArr(n), b=nextArr(n);
                for(int i=0; i<n; i++)
                    arr[i]=new Pair(a[i], b[i]);
                return arr;
            }
            for(int i=0; i<n; i++)
                arr[i]=new Pair(nextInt(), nextInt());
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Kad{
        long sum;
        int max;
        public Kad(long x, int y) {
            this.sum=x;
            this.max=y;
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return this.x*1000+this.y;
        }
        public int compareTo(Pair other) {
            if(this.x!=other.x)
                return this.x-other.x;
            return this.y-other.y;
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
        public boolean equal(Pair p){
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
    }
}


import java.io.*;
import java.util.*;
public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static int ceildiv(int x, int y){
        return x%y==0? x/y: x/y+1;
    }
    static void count(int[] freq, int x){
        for(int i=0; x>0; x>>=1, i++){
            if((x&1)==1)
                freq[i]++;
        }
    }
    static void print(boolean b){ pw.println(b?"YES":"NO");}
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int n=sc.nextInt();
        int[] arr=sc.nextArr(n);
        int[] freq=new int[20];
        for(int i=0; i<n; i++)
            count(freq, arr[i]);
        long ans=0l;
        while(true){
            int x=0;
            for(int i=0; i<20; i++){
                if(freq[i]>0){
                    x+=1<<i;
                    freq[i]--;
                }
            }
            if(x==0)
                break;
            ans+=x*1l*x;
        }
        pw.println(ans);
        pw.close();
    }
    static void printArr(int[] arr){
        for(int i=0; i<arr.length-1; i++)
            pw.print(arr[i]+" ");
        pw.println(arr[arr.length-1]);
    }
    static void printArr(long[] arr){
        for(int i=0; i<arr.length-1; i++)
            pw.print(arr[i]+" ");
        pw.println(arr[arr.length-1]);
    }
    static void printArr(Integer[] arr){
        for(int i=0; i<arr.length-1; i++)
            pw.print(arr[i]+" ");
        pw.println(arr[arr.length-1]);
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public Pair nextPair() throws IOException{
            return new Pair(nextInt(), nextInt());
        }
        public Pair[] nextPairArr(int n, int l) throws IOException{
            Pair[] arr=new Pair[n];
            if(l==2){
                int[] a=nextArr(n), b=nextArr(n);
                for(int i=0; i<n; i++)
                    arr[i]=new Pair(a[i], b[i]);
                return arr;
            }
            for(int i=0; i<n; i++)
                arr[i]=new Pair(nextInt(), nextInt());
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Kad{
        long sum;
        int max;
        public Kad(long x, int y) {
            this.sum=x;
            this.max=y;
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return this.x*1000+this.y;
        }
        public int compareTo(Pair other) {
            if(this.x!=other.x)
                return this.x-other.x;
            return this.y-other.y;
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
        public boolean equal(Pair p){
            if(this.x==p.x)
                return this.y==p.y;
            if(this.x==p.y)
                return this.y==p.x;
            else
                return false;
        }
    }
}


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

import static java.lang.Math.*;

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

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

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

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

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

		public String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
		public int nextInt()
		{
			int c = read();

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

			int sgn = 1;

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

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

			return res * sgn;
		}

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

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

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

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

			return res.toString();
		}

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

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

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}
	public static void main(String args[]) throws Exception
	{
		new Thread(null, new Solution(),"Main",1<<27).start();
	}

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

	public static long findGCD(long arr[], int n)
	{
		long result = arr[0];
		for (int i = 1; i < n; i++)
			result = gcd(arr[i], result);
		return result;
	}

	static void sortbycolomn(long arr[][], int col)
    {

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

          @Override

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

            if (entry1[col] > entry2[col])
                return 1;
            else
                return -1;
          }
        });
    }

	static class Box implements Comparable<Box>{
	    int h=0,w=0,d=0,area;
	    Box(int h,int w,int d){
	        this.h = h;
	        this.w = w;
	        this.d = d;
	    }

	    public int compareTo(Box o){
	        return o.area-this.area;
	    }
	}

	public void run()
	{
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

        int n=in.nextInt();
        int[] bit = new int[22];
        int x=0;
        for(int i=0;i<n;i++){
            x = in.nextInt();
            int j=0;
            while(x!=0 && x!=1){
                if(x%2==1) bit[j]++;
                x=x/2;
                j++;
            }
            bit[j]+=x;
        }
        long[] ans=new long[n];
        for(int i=0;i<n;i++){
            for(int j=0;j<22;j++){
                if(bit[j]!=0){
                    bit[j]--;
                    ans[i] = (long)(ans[i] + (long)Math.pow(2,j));
                }
            }
        }
        long fans=0;
        for(int i=0;i<n;i++) fans = (long)(fans + (long)Math.pow(ans[i],2));
        w.println(fans);

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


import java.util.*;
import java.io.*;
import java.io.BufferedReader;
import java.awt.Point;

public class Z_D{
	public static final long mod= 1000000007;
	public static Debug db;

	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Autocompletion solver = new Autocompletion();
		db=new Debug(System.getSecurityManager()==null);
		solver.solve(1, in, out);
		out.close();
	}
	static class Autocompletion {

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n=in.nextInt();
			long arr[]=new long[n];
			int count[]=new int[22];
			for(int i=0;i<n;i++) {
				arr[i]=in.nextLong();
			}
			for(int i=0;i<n;i++) {
				for(int j=0;j<count.length;j++) {
					if((arr[i] & (1<<j))!=0) {
						count[j]++;
					}
				}

			}
			long sum=0;
			for(int i=0;i<n;i++) {
				long mx=0;
				for(int j=0;j<count.length;j++) {
					if(count[j]>=1) {
						mx+=1<<j;
						count[j]--;
					}
				}
				sum+=mx*mx;
			}
			out.println(sum);
		}
	}

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

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public int[] nextIntArr(int n) {
        	int arr[]=new int[n];
        	for(int i=0;i<n;i++) {
        		arr[i]=this.nextInt();
        	}
        	return arr;
        }
    }
	public static class Debug {
        private boolean allowDebug;

        public Debug(boolean allowDebug) {
            this.allowDebug = allowDebug;
        }

        private void outputName(String name) {
            System.out.print(name + " = ");
        }

        public void debug(String name, int x) {
            if (!allowDebug) {
                return;
            }

            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, long x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, double x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, int[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, long[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, double[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, Object x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, Object... x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.deepToString(x));
        }
    }
}


import java.util.*;
import java.io.*;
import java.io.BufferedReader;
import java.awt.Point;

public class Z_D{
	public static final long mod= 1000000007;
	public static Debug db;

	public static void main(String[] args) throws IOException {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Autocompletion solver = new Autocompletion();
		db=new Debug(System.getSecurityManager()==null);
		solver.solve(1, in, out);
		out.close();
	}
	static class Autocompletion {

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n=in.nextInt();
			long arr[]=new long[n];
			for(int i=0;i<n;i++) {
				arr[i]=in.nextLong();
			}
			Arrays.sort(arr);
			for(int i=0;i<n-1;i++) {
				long a=arr[i]|arr[i+1];
				long b=arr[i]&arr[i+1];
					arr[i]=b;
					arr[i+1]=a;

			}
			long sum=0;
			for(int i=0;i<n;i++) {
				sum+=arr[i]*arr[i];
			}
			out.println(sum);
		}
	}

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

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public int[] nextIntArr(int n) {
        	int arr[]=new int[n];
        	for(int i=0;i<n;i++) {
        		arr[i]=this.nextInt();
        	}
        	return arr;
        }
    }
	public static class Debug {
        private boolean allowDebug;

        public Debug(boolean allowDebug) {
            this.allowDebug = allowDebug;
        }

        private void outputName(String name) {
            System.out.print(name + " = ");
        }

        public void debug(String name, int x) {
            if (!allowDebug) {
                return;
            }

            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, long x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, double x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, int[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, long[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, double[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, Object x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, Object... x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.deepToString(x));
        }
    }
}


import java.util.*;
import java.io.*;
public class Main3
{
	public static void main(String[] args) throws IOException
	{
		int n,k;
		long ans=0;//long as are finding max possible sum of squares
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		n=Integer.parseInt(br.readLine().trim());
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
		String s[]=br.readLine().trim().split("\\s+");
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=Integer.parseInt(s[i]);
		int bitarr[]=new int[26];//to store res of & and |

		for(int i=0;i<n;i++){
            int z=arr[i];
            for(int j=0;j<25;j++){
                if((z&(1<<j))!=0)
                	bitarr[j]++;
            }
        }
        for(int i=0;i<n;i++){
            long c=0;
            for(int j=0;j<25;j++){
                if(bitarr[j]>0){
                    c|=(1<<j);
                    bitarr[j]--;
                }
            }
            ans+=c*c;
        }
		out.print(ans);
		out.flush();
		out.close();
	}
}


import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
       static class FastReader{
               BufferedReader br;
               StringTokenizer st;
               public FastReader()throws IOException{
                 br=new BufferedReader(new InputStreamReader(System.in));
               }
               public FastReader(String s)throws IOException{
                 br=new BufferedReader(new FileReader(new File(s)));
               }
               String next(){
                 while(st==null || !st.hasMoreElements()){
                   try{
                      st=new StringTokenizer(br.readLine());
                   }
                   catch(Exception e){
                     e.printStackTrace();
                   }

                 }
                 return st.nextToken();
               }
               String nextLine(){
               String str="";
                 try{
                   str=br.readLine();
                 }
                catch(Exception e){
                  e.printStackTrace();
                }
               return str;
               }
              int nextInt(){
                return Integer.parseInt(next());
              }
            long nextLong(){
              return Long.parseLong(next());
            }
            double nextDouble(){
              return Double.parseDouble(next());
            }

       }

        public static void main(String args[]) throws IOException {
            FastReader in = new FastReader();
           PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out));
           int n=in.nextInt();
           int a[]=new int[20];
            for(int i=0;i<n;i++){
                     int x=in.nextInt();
                     for(int j=0;j<20;j++){
                              if(x%2==1){
                              a[j]++;
                              }
                        x=(x-x%2)/2;
                     }
            }
            long print=0;
            for(int i=0;i<n;i++){
                    long x=0;
                     for(int j=0;j<20;j++){
                                if(a[j]>0){
                                x=x+(int)Math.pow(2,j);
                                a[j]--;

                                }

                     }
                     print+=(x*x);

            }
            out.println(print);
            out.close();
        }

}


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

public class Main {

	public static void main(String[] args) throws IOException,InterruptedException{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long[] arr=new long[n];
		long max=0;
		int c=0;
		for (int i = 0; i < n; i++) {
			arr[i]=sc.nextLong();
			if (arr[i]>max) {
				max=arr[i];
				c=i;
			}
		}
		for (int i = 0; i < n; i++) {
			if (i!=c) {
				long tmp=arr[c];
				arr[c]|=arr[i];
				arr[i]&=tmp;
			}
		}
		long res=0;
		for (int i = 0; i < n; i++) {
			res+=(arr[i]*arr[i]);
		}
//		pw.println(Arrays.toString(arr));
		pw.println(res);
		pw.close();
    }

	static PrintWriter pw=new PrintWriter(System.out);
	static long pow(int a,int b) {
		long r=1l;
		for (int i = 0; i < b; i++) {
			r*=a;
		}
		return r;
	}
	static int[]lp;
	static void sieveLinear(int N){
		ArrayList<Integer> primes = new ArrayList<Integer>();
		lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i){
			if(lp[i] == 0){
				primes.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primes)//all primes smaller than or equal my lowest prime divisor
				if(p > curLP || p * 1l * i > N)
					break;
				else
					lp[p * i] = p;
		}
	}
	static long gcd(int x,int y) {
		while (x!=y) {
			if(Math.max(x,y)/Math.min(x,y)==(double)(Math.max(x,y))/Math.min(x,y)) return Math.min(x,y);
			if(lp.length!=0) {
				if(lp[x]==x) {
					if(y/x==y/(double)x) return x;
					else return 1;
				}else if (lp[y]==y) {
					if(x/y==x/(double)y) return y;
					else return 1;
				}
			}
			if(x>y) x-=y;
			else y-=x;
		}
		return x;
	}
	static class pair implements Comparable<pair> {
		int x;
		int y;

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

		public String toString() {
			return x + " " + y;
		}
		public boolean equals(Object o) {
            if (o instanceof pair) {
                pair p = (pair)o;
                return p.x == x && p.y == y;
            }
            return false;
        }
        public int hashCode() {
            return new Double(x).hashCode() * 31 + new Double(y).hashCode();
        }
        public int compareTo(pair other) {
        	if(this.x==other.x) {
        		return Long.compare(this.y, other.y);
        	}
			return Long.compare(this.x, other.x);
		}
	}
	static class tuble implements Comparable<tuble> {
		int x;
		int y;
		int z;

		public tuble(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public String toString() {
			return x + " " + y + " " + z;
		}

		public int compareTo(tuble other) {
			if (this.x == other.x) {
				if(this.y==other.y) return this.z - other.z;
				else return this.y - other.y;
			} else {
				return this.x - other.x;
			}
		}
	}
 	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}


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

public class Momo {

	public static void main(String[] args) throws IOException,InterruptedException{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] arr=new int[n];
		int[] bits=new int[20];
		int[][] res=new int[n][20];
		for (int i = 0; i < arr.length; i++) {
			arr[i]=sc.nextInt();
			int tmp=arr[i];
			int p=0;
			while(tmp>0) {
				if(tmp%2==1) bits[p]++;
				tmp/=2;
				p++;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 20; j++) {
				if(bits[j]>=1) {
					res[i][j]=1;
					bits[j]--;
				}
			}
		}
//		pw.println(Arrays.deepToString(res));
		long sum=0;
		for (int i = 0; i < n; i++) {
			long k=0;
			for (int j = 0; j < 20; j++) {
				k+=pow(2,j)*res[i][j];
			}
			sum+=k*k;
		}
		pw.println(sum);
		pw.close();
    }

	static PrintWriter pw=new PrintWriter(System.out);
	static long pow(int a,int b) {
		long r=1l;
		for (int i = 0; i < b; i++) {
			r*=a;
		}
		return r;
	}
	static int[]lp;
	static void sieveLinear(int N){
		ArrayList<Integer> primes = new ArrayList<Integer>();
		lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i){
			if(lp[i] == 0){
				primes.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primes)//all primes smaller than or equal my lowest prime divisor
				if(p > curLP || p * 1l * i > N)
					break;
				else
					lp[p * i] = p;
		}
	}
	static long gcd(int x,int y) {
		while (x!=y) {
			if(Math.max(x,y)/Math.min(x,y)==(double)(Math.max(x,y))/Math.min(x,y)) return Math.min(x,y);
			if(lp.length!=0) {
				if(lp[x]==x) {
					if(y/x==y/(double)x) return x;
					else return 1;
				}else if (lp[y]==y) {
					if(x/y==x/(double)y) return y;
					else return 1;
				}
			}
			if(x>y) x-=y;
			else y-=x;
		}
		return x;
	}
	static class pair implements Comparable<pair> {
		int x;
		int y;

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

		public String toString() {
			return x + " " + y;
		}
		public boolean equals(Object o) {
            if (o instanceof pair) {
                pair p = (pair)o;
                return p.x == x && p.y == y;
            }
            return false;
        }
        public int hashCode() {
            return new Double(x).hashCode() * 31 + new Double(y).hashCode();
        }
        public int compareTo(pair other) {
        	if(this.x==other.x) {
        		return Long.compare(this.y, other.y);
        	}
			return Long.compare(this.x, other.x);
		}
	}
	static class tuble implements Comparable<tuble> {
		int x;
		int y;
		int z;

		public tuble(int x, int y, int z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

		public String toString() {
			return x + " " + y + " " + z;
		}

		public int compareTo(tuble other) {
			if (this.x == other.x) {
				if(this.y==other.y) return this.z - other.z;
				else return this.y - other.y;
			} else {
				return this.x - other.x;
			}
		}
	}
 	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public boolean hasNext() {
			// TODO Auto-generated method stub
			return false;
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}

}


import java.util.*;
import java.io.*;
public class AndOrAndSquareSums {
    public static void main(String agrs[]) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] arr = new int[20];
        for(int k = 0; k < n; k++)
        {
            long a = in.nextLong();
            for(int b = 0; b < 20; b++)
            {
                if((a & (1L << b)) > 0)
                {
                    arr[b]++;
                }
            }
        }
        long ans = 0;
        long max = 1L << 19;
        for(int k = 0; k < n; k++)
        {
            long temp = 0;
            long at = max;
            for(int b = 19; b >= 0; b--)
            {
                if(arr[b] > 0)
                {
                    arr[b]--;
                    temp += at;
                }
                at >>= 1;
            }
            ans += temp * temp;
        }
        out.println(ans);
        out.close();
    }
}


import java.util.*;
public class j3 {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int x=n;
        int arr[]=new int[20];

        while(x-->0){
            int p=sc.nextInt();
            for(int i=0;i<20;i++){
                arr[i]+=(p>>i&1);
            }
           // System.out.println(Arrays.toString(arr));

        }

        long ans=0;
        while(n-->0) {
            long tmp=0;
            for (int i = 0; i < 20; i++) {
                if(arr[i]>0) {
                    tmp += (1 << i);
                    arr[i]--;
                }
            }
           // System.out.println(tmp);
            ans+=(tmp*tmp);
        }
        System.out.println(ans);

    }
}


// Don't place your source in a package
import java.util.*;
import java.lang.*;
import java.io.*;

// Please name your class Main
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
	    Scanner in = new Scanner(System.in);
		int N =in.nextInt();
		int A[]=new int[N];
		for(int i=0;i<N;i++)A[i]=in.nextInt();
		Solution s=new Solution();
		s.solution(A);
	}

}

class Solution{
	public void solution(int A[]){
		long res=0;
		int bits[]=new int[22];
		for(int i=0;i<A.length;i++){
			int n=A[i];
			for(int j=0;j<bits.length;j++){
				int b=n&1;n>>=1;
				bits[j]+=b;
			}
		}
		while(sum(bits)!=0){
			long n=0;
			//System.out.println(sum(bits));
			for(int i=0;i<bits.length;i++){
				if(bits[i]!=0){
					bits[i]--;
					n^=(1<<i);
				}
			}
			res+=(n*n);
		}
		System.out.println(res);

	}

	public int sum(int A[]){
		int res=0;for(int i:A)res+=i;return res;
	}
}


import java.io.*;
import java.math.*;
import java.util.*;
public class ANDORandSquareSum {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		long[] bits = new long[21];
		long ans = 0;
 		for (int i = 1; i <= N; i++) {
			int x = input.nextInt();
			for (int mask = 0; (1<<mask) <= x; mask++) {
				int cur = x>>mask;
				if (cur%2==1) bits[mask]++;
			}
		}
 		while (true) {
 			long curans = 0;
 			boolean added = false;
 			for (int i = 0; i < 20; i++) {
 				if (bits[i]>0) {
 					curans+=(1<<i);
 					bits[i]--;
 					added=true;
 				}
 			}
 			ans+=curans*curans;
 			if (!added) break;
 		}
 		System.out.println(ans);
	}
}


import java.io.*;
import java.math.*;
import java.util.*;
public class ANDORandSquareSum {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		long[] bits = new long[21];
		long ans = 0;
 		for (int i = 1; i <= N; i++) { //Basically converting numbers to binary and
 			//storing occurrences per binary slot using an array to mimic
			int x = input.nextInt();
			for (int mask = 0; (1<<mask) <= x; mask++) {
				int cur = x>>mask;
				if (cur%2==1) bits[mask]++;
			}
		}
 		while (true) {
 			long curans = 0;
 			boolean added = false;
 			for (int i = 0; i < 20; i++) {
 				if (bits[i]>0) {
 					curans+=(1<<i);
 					bits[i]--;
 					added=true;
 				}
 			}
 			ans+=curans*curans;
 			if (!added) break;
 		}
 		System.out.println(ans);
	}
}


import java.io.*;
import java.util.*;
public class Main{
	static void main() throws Exception{
		int n=sc.nextInt();
		int[]in=sc.intArr(n);
		int[]bits=new int[20];
		for(int i=0;i<n;i++) {
			for(int j=0;j<20;j++) {
				bits[j]+=((in[i]>>j)&1);
			}
		}
		long ans=0;
		for(int i=0;i<n;i++) {
			long cur=0;
			for(int j=0;j<20;j++) {
				int can=Math.min(1, bits[j]);
				bits[j]-=can;

				cur|=(can<<j);
			}
			ans+=(cur*cur);
		}
		pw.println(ans);
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
		int tc=1;
//		tc=sc.nextInt();
		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

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

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}


import java.util.*;

import static java.lang.Long.parseLong;

public class D {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String [] a = new String [n];
        int maxlen = 0;
        for (int i = 0; i < n; i++) {
            a[i] = Long.toBinaryString(in.nextLong());
            if (a[i].length() > maxlen) {
                maxlen = a[i].length();
        }
        }

        for (int i = 0; i < n; i++) {
            int temp = maxlen - a[i].length();
            for (int j = 0; j < temp; j++) {
                a[i] = '0' + a[i];
            }
        }

        int [] count = new int [maxlen];
        for (int i = 0; i < maxlen; i++) {
            for (int j = 0; j < n; j++) {
                if (a[j].charAt(i) == '1') {
                    count[i]++;
                }
            }
        }

        for (int i = n - 1; i >= 0; i--) {
            a[i] = "";
            for (int j = 0; j < maxlen; j++) {
                if (count[j] > 0) {
                    a[i] = a[i] + '1';
                    count[j]--;
                } else {
                    a[i] = a[i] + '0';
                }
            }
        }

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


import java.util.*;
public class D {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long [] a = new long [n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
        }
        long ans = 0;

        for (int i = 1; i < n; i++) {
            long temp = a[i - 1];
            a[i - 1] = temp & a[i];
            a[i] = temp | a[i];
        }

        for (int i = 0; i < n; i++) {
            long temp = a[i];
            a[i] = temp & a[n];
            a[n] = temp | a[n];
        }

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


import java.util.*;
public class D {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long [] a = new long [n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
        }
        long ans = 0;

        for (int i = 1; i < n; i++) {
            long temp = a[i - 1];
            a[i - 1] = temp & a[i];
            a[i] = temp | a[i];
        }

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


import java.util.*;
public class D {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long [] a = new long [n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
        }
        long ans = 0;

        for (int i = 1; i < n; i++) {
            long temp = a[i - 1];
            a[i - 1] = temp & a[i];
            a[i] = temp | a[i];
        }

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


import java.util.*;
public class D {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long [] a = new long [n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
        }
        long ans = 0;

        for (int i = 1; i < n; i++) {
            long temp = a[i - 1];
            if ((temp & a[i]) != 0) {
                a[i - 1] = temp & a[i];
                a[i] = temp | a[i];
            } else {
                a[i] = temp;
                a[i - 1] = a[i];
            }
        }

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


import java.util.*;
public class D {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long [] a = new long [n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
        }
        long ans = 0;

        for (int i = 1; i < n; i++) {
            long temp = a[i - 1];
            a[i - 1] = temp & a[i];
            a[i] = temp | a[i];
        }

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


import java.util.*;
public class D {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        long [] a = new long [n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
        }
        long ans = 0;

        for (int i = 1; i < n; i++) {
            long temp = a[i - 1];
            if ((temp & a[i]) != 0) {
                a[i - 1] = temp & a[i];
                a[i] = temp | a[i];
            }
        }

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


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

public class Square_Sum {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long arr[] = new long[n];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = sc.nextLong();
		}
		 System.out.println(SquareSum(arr));

	}

	public static long SquareSum(long arr[]) {
		long ans=0;
		int cn[] = new int [20];
		for (int i = 0; i < arr.length; i++) {
			for(int j=0; j<20; j++) {
				if(((1<<j)&arr[i])!=0) {
					cn[j]++;
				}
			}

		}
		while(true) {
			int mask=0;
			int min_ones=Integer.MAX_VALUE;
			for(int i=0; i<20; i++) {
				if(cn[i]!=0) {
					mask|=(1<<i);
					min_ones=Math.min(min_ones, cn[i]);
				}
			}
			if(mask==0) {
				break;
			}
			ans+=(mask*1l*mask)*min_ones;
			for (int j = 0; j < cn.length; j++) {
				if(cn[j]>0) {
					cn[j]-=min_ones;
				}
			}

		}
		return ans;

		}
	}


public class Main {
    public static void main(String args[]) {
        System.out.println("Hello World!");
    }
}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Main{
	static BufferedReader br;
	static int in() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
    public static void main(String[] args) throws Exception {
        br = new BufferedReader(new InputStreamReader(System.in));
        int n=in();
        int[] arr=split();
        long ans=0;
        int[] bits=new int[20];
        for(int i=0;i<n;i++)
        {
        	for(int j=0;j<20;j++)
        	{
        		if((arr[i]&(1<<j))!=0)
        			bits[j]++;
        	}
        }
        while(true)
        {
        	int cnt=0;
        	for(int i=0;i<20;i++)
        	{
        		if(bits[i]!=0)
        		{
        			cnt++;
        			break;
        		}
        	}
        	if(cnt==0)
        		break;
        	long a=0;
        	for(int i=0;i<20;i++)
        	{
        		if(bits[i]!=0)
        		{
        			a=a+(1<<i);
        			bits[i]--;
        		}
        	}
        	ans=ans+a*a;
        }
        System.out.println(ans);
    }
}


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

/**
 * @author nidhigoel
 */
public class ANDORAndSquareSum {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "nidhigoel", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
	        OutputStream outputStream = System.out;
	        InputReader in = new InputReader(inputStream);
	        PrintWriter out = new PrintWriter(outputStream);
	        TaskA solver = new TaskA();
	        int testNumber = 1;
	        // int testNumber = in.nextInt();
	        for(int i=1;i<=testNumber;i++)
		        solver.solve(i, in, out);
	        out.close();
        }
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = new int[n];
            for(int i=0;i<n;i++)
            	a[i] = in.nextInt();
            int count[] = new int[22];
            for(int i=0;i<n;i++){
            	int x = a[i];
            	for(int j=0;j<22;j++)
            		if(((a[i]>>j)&1) == 1)
            			count[j]++;
            }
            long sum = 0;
            while(true){
            	boolean found = false;
            	long num = 0;
            	for(int i=0;i<22;i++){
            		if(count[i]>0){
            			num += 1<<i;
            			count[i]--;
            			found = true;
            		}
            	}
            	sum += pow(num , 2);
            	if(!found)
            		break;
            }
            out.println(sum);
        }

        public int nCr(int n, int r){
            int x=n-r,y=0,z=1;
            while(y<r){
                z=(z*(x+1))/(y+1);
                x++;y++;
            }
            return z;
        }
        public void permutations(ArrayList<Integer> ans,  int a[] , int visited[] , int count,  int number){
            if(count == a.length){
                ans.add(number);
                return;
            }
            for(int i=0;i<a.length;i++){
                if(visited[a[i]]!=0)
                    continue;
                count++;
                number *= 10;
                number += a[i];
                visited[a[i]] = 1;
                permutations(ans , a , visited , count , number);

                count--;
                number /= 10;
                visited[a[i]] = 0;

            }
        }
        public void nextGreater(int a[] , int []ng , int n){
            Stack<Combine> s = new Stack<>();
            for(int i=0;i<2*n;i++){
                int k = i%n;
                Combine c = new Combine(a[k] , k);
                while(s.size()>0 && s.peek().value <= c.value){
                    Combine d = s.pop();
                    if(ng[d.delete]==0)
                        ng[d.delete] = c.delete;

                }
                s.push(c);
            }
        }
        public void sieve(int a[]){
            a[0] = a[1] = 1;
            int i;
            for(i=2;i*i<=a.length;i++){
                if(a[i] != 0)
                    continue;
                a[i] = i;
                for(int k = (i)*(i);k<a.length;k+=i){
                    if(a[k] != 0)
                        continue;
                    a[k] = i;
                }
            }
        }
        public long nCrPFermet(int n , int r , long p){
            if(r==0)
                return 1l;
            long fact[] = new long[n+1];
            fact[0] = 1;
            for(int i=1;i<=n;i++)
                fact[i] = (i*fact[i-1])%p;
            long modInverseR = pow(fact[r] , p-2 , p);
            long modInverseNR = pow(fact[n-r] , p-2 , p);
            long w = (((fact[n]*modInverseR)%p)*modInverseNR)%p;
            return w;
        }
        public long pow(long a, long b, long m) {
            a %= m;
            long res = 1;
            while (b > 0) {
                long x = b&1;
                if (x == 1)
                    res = res * a % m;
                a = a * a % m;
                b >>= 1;
            }
            return res;
        }
        public long pow(long a, long b) {
            long res = 1;
            while (b > 0) {
                long x = b&1;
                if (x == 1)
                    res = res * a;
                a = a * a;
                b >>= 1;
            }
            return res;
        }
        public void swap(int a[] , int p1 , int p2){
            int x = a[p1];
            a[p1] = a[p2];
            a[p2] = x;
        }
        public void sortedArrayToBST(TreeSet<Integer> a , int start, int end) {
            if (start > end) {
                return;
            }
            int mid = (start + end) / 2;
            a.add(mid);
            sortedArrayToBST(a, start, mid - 1);
            sortedArrayToBST(a, mid + 1, end);
        }
        class Combine{
            int value;
            int delete;
            Combine(int val , int delete){
                this.value = val;
                this.delete = delete;
            }
        }
        class Sort2 implements Comparator<Combine>{
            public int compare(Combine a , Combine b){
                if(a.value > b.value)
                    return 1;
                else if(a.value == b.value && a.delete>b.delete)
                    return 1;
                else if(a.value == b.value && a.delete == b.delete)
                    return 0;
                return -1;
            }
        }
        public int lowerLastBound(ArrayList<Integer> a , int x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>=x)
                return -1;
            if(a.get(r)<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid-1)<x)
                    return mid-1;
                else if(a.get(mid)>=x)
                    r = mid-1;
                else if(a.get(mid)<x && a.get(mid+1)>=x)
                    return mid;
                else if(a.get(mid)<x && a.get(mid+1)<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(ArrayList<Integer> a , Integer x){
            int l = 0;
            int r = a.size()-1;
            if(a.get(l)>x)
                return l;
            if(a.get(r)<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a.get(mid) == x && a.get(mid+1)>x)
                    return mid+1;
                else if(a.get(mid)<=x)
                    l = mid+1;
                else if(a.get(mid)>x && a.get(mid-1)<=x)
                    return mid;
                else if(a.get(mid)>x && a.get(mid-1)>x)
                    r = mid-1;
            }
            return mid;
        }
        public int lowerLastBound(int a[] , int x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>=x)
                return -1;
            if(a[r]<x)
                return r;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid-1]<x)
                    return mid-1;
                else if(a[mid]>=x)
                    r = mid-1;
                else if(a[mid]<x && a[mid+1]>=x)
                    return mid;
                else if(a[mid]<x && a[mid+1]<x)
                    l = mid+1;
            }
            return mid;
        }
        public int upperFirstBound(long a[] , long x){
            int l = 0;
            int r = a.length-1;
            if(a[l]>x)
                return l;
            if(a[r]<=x)
                return r+1;
            int mid = -1;
            while(l<=r){
                mid = (l+r)/2;
                if(a[mid] == x && a[mid+1]>x)
                    return mid+1;
                else if(a[mid]<=x)
                    l = mid+1;
                else if(a[mid]>x && a[mid-1]<=x)
                    return mid;
                else if(a[mid]>x && a[mid-1]>x)
                    r = mid-1;
            }
            return mid;
        }
        public long log(float number , int base){
            return (long) Math.floor((Math.log(number) / Math.log(base)));
        }
        public long gcd(long a , long b){
            if(a<b){
                long c = b;
                b = a;
                a = c;
            }
            if(b == 0)
                return a;
            return gcd(b , a%b);
        }
        public long[] gcdEx(long p, long q) {
            if (q == 0)
                return new long[] { p, 1, 0 };
            long[] vals = gcdEx(q, p % q);
            long d = vals[0];
            long a = vals[2];
            long b = vals[1] - (p / q) * vals[2];
            // 0->gcd 1->xValue 2->yValue
            return new long[] { d, a, b };
        }
        public void print2d(long a[][] , PrintWriter out){
            for(int i=0;i<a.length;i++){
                for(int j=0;j<a[i].length;j++)
                    out.print(a[i][j] + " ");
                out.println();
            }
            out.println();
        }
        public void print1d(int a[] , PrintWriter out){
            for(int i=0;i<a.length;i++)
                out.print(a[i] + " ");
            out.println();
            out.println();
        }

    }

    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.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

public class TestClass {
    public static void main(String args[] ) throws Exception {
        /* Sample code to perform I/O:
         * Use either of these methods for input

        //BufferedReader
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String name = br.readLine();                // Reading input from STDIN
        System.out.println("Hi, " + name + ".");    // Writing output to STDOUT

        //Scanner
        Scanner s = new Scanner(System.in);
        String name = s.nextLine();                 // Reading input from STDIN
        System.out.println("Hi, " + name + ".");    // Writing output to STDOUT

        */

        // Write your code here
        PrintWriter pw=new PrintWriter(System.out);
        Scanner scn=new Scanner(System.in);
        int n = scn.nextInt();
        long[] d = new long[20];
        long mx=-1;
        while(n-->0){
            long a = scn.nextLong();
            int i=0;
            while(a>0){
                if((a&1)==1)
                    d[i]++;
                if(mx<d[i])
                    mx=d[i];
                a=a/2;
                i++;
            }
        }
        //  for(int j=0;j<20;j++){
        //         pw.print(d[j]+" ");
        // }
        long res=0;
        for(int i=0;i<mx;i++){
            long num=0;
            for(int j=0;j<20;j++){
                if(d[j]>0){
                    num=num+(1L<<j);
                    d[j]--;
                }
            }
            //pw.print(num+" "+mx);
            res=res+num*num;
        }
        pw.println(res);

        pw.close();
    }

}


// package GlobalRound8;

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

public class ProblemD {
    public static void main(String[] args)throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        StringBuilder print=new StringBuilder();
        int n=Integer.parseInt(br.readLine());
        int a[]=new int[n+1];
        st=new StringTokenizer(br.readLine());
        int count[]=new int[20];
        for(int i=1;i<=n;i++){
            a[i]=Integer.parseInt(st.nextToken());
            update(a[i],count);
        }
        long sum=0;
        for(int i=0;i<n;i++){
            int temp=0;
            for(int j=0;j<20;j++){
                if(count[j]!=0){
                    count[j]-=1;
                    temp|=(1<<j);
                }
            }
            sum+=1l*temp*temp;
        }
        System.out.println(sum);
    }
    public static void update(int num,int count[]){
        for(int i=0;i<20;i++){
            int t=1<<i;
            if((t&num)!=0){
                count[i]++;
            }
        }
    }
}


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 = (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;
	   }
	}
}