import java.io.BufferedReader

fun main() {
    val br = System.`in`.bufferedReader()
    val n = br.readInt()
    val counts = IntArray(20)
    repeat(n) {
        val num = br.readInt()
        for (x in 0 until 20) {
            if (1 shl x and num != 0) {
                counts[x]++
            }
        }
    }
    var sum = 0L
    repeat(n) {
        var num = 0L
        for (x in 0 until 20) {
            if (counts[x] != 0) {
                counts[x]--
                num = num or (1L shl x)
            }
        }
        sum += num * num
    }
    print(sum)
}

private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val NL_INT = '\n'.toInt()

@Suppress("DuplicatedCode")
private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }

    while (read <= SPACE_INT && read != -1 && read != NL_INT) {
        mark(1)
        read = read()
    }
    if (read > SPACE_INT) {
        reset()
    }
    return if (neg) -ret else ret
}


import java.lang.Long.highestOneBit

fun readInt() = readLine()!!.toInt()
fun readLongs() = readLine()!!.split(' ').map { it.toLong() }.toTypedArray()

fun main() {
    readInt()
    val vs = readLongs()
    val fs = vs.map { 0L }.toTypedArray()

    var b = highestOneBit(vs.max()!!)
    while (b > 0) {
        val count = vs.count { it and b != 0L }
        for (i in 0 until count) fs[i] = fs[i] or b
        b = b ushr 1
    }

    val res = fs.map { it*it }.sum()
    println(res)
}


import java.lang.Long.highestOneBit
import java.util.*

fun readInt() = readLine()!!.toInt()
fun readLongs() = readLine()!!.split(' ').map { it.toLong() }

fun pq() = PriorityQueue<Long>()

fun main() {
    readInt()
    val ms = sortedMapOf<Long, Int>()
    val bs = (0..20).map { (1L shl it) to pq() }.toMap().toMutableMap()

    fun add(v: Long) {
        ms[v] = ms.getOrDefault(v, 0) + 1
        var n = 1L
        while (n <= v) {
            if (v and n != 0L) bs[n]!!.add(v)
            n *= 2
        }
    }
    fun remove(v: Long) {
        ms[v] = ms[v]!! - 1
        if (ms[v] == 0) ms.remove(v)
        var n = 1L
        while (n <= v) {
            if (v and n != 0L) bs[n]!!.remove(v)
            n *= 2
        }
    }

    for (v in readLongs().filter { it != 0L }) add(v)

    var res = 0L
    while (ms.isNotEmpty()) {
        val i = ms.lastKey()
        remove(i)

        var modified = false
        var b = highestOneBit(i)
        while (b > 0) {
            if (i and b == 0L && bs.getOrDefault(b, pq()).isNotEmpty()) {
                val j = bs[b]!!.first()
                remove(j)
                add(i and j)
                add(i or j)
                modified = true
                break
            }
            b = b ushr 1
        }

        if (!modified) {
            res += i * i
        }
    }

    println(res)
}


import Mod.mdiv
import Mod.mmod
import Mod.mmult
import Mod.mplus
import Mod.mpow
import Mod.setMod
import NumTh.inverse
import kotlin.collections.*
import kotlin.math.*
import java.util.Queue
import java.util.LinkedList
import java.util.PriorityQueue
import NumTh.gcd
import java.util.Stack

fun readLn() = readLine()!!.trim() // string line
fun readInt() = readLn().trim().toInt() // single int
fun readStrings() = readLn().trim().split(" ") // list of strings
fun readInts() = readStrings().map { it.trim().toInt() } // list of ints
fun readLongs() = readStrings().map { it.trim().toLong() } // list of ints
fun readLong() = readLn().trim().toLong() // list of strings
fun writeGoogleAnswer(case: Int, str: String) = println("Case #$case: $str")

object NumTh {
    fun euclideanExt(la: Long, lb: Long): Triple<Long, Long, Long> {
        val signa = sign(la.toDouble()).toLong()
        val signb = sign(lb.toDouble()).toLong()

        var a = abs(la)
        var b = abs(lb)
        val reverse = a > b
        if (reverse) {
            a = b.also { b = a }
        }

        var m11 = 1L
        var m12 = 0L
        var m21 = 0L
        var m22 = 1L

        while (a > 0) {
            val tmp = b / a
            a = (b % a).also { b = a }
            m11 = (m12 - m11 * tmp).also { m12 = m11.also { m21 = (m22 - m21 * tmp).also { m22 = m21 } } }
        }
        var x = m12
        var y = m22
        var d = b
        if (reverse) {
            x = x.also { y = x }
        }
        return Triple(signa * x, signb * y, d)
    }

    fun euclideanExt(la: Int, lb: Int): Triple<Int, Int, Int> {
        val res = euclideanExt(la.toLong(), lb.toLong())
        return Triple(res.first.toInt(), res.second.toInt(), res.third.toInt())
    }

    public fun inverse(la: Long, mod: Long): Long {
        val res = euclideanExt(la mmod mod, mod).first
        return if (res < 0) res + mod else res
    }

    public fun inverse(la: Int, mod: Int): Int {
        val res = euclideanExt(la mmod mod, mod).first
        return if (res < 0) res + mod else res
    }

    infix fun Long.gcd(lb: Long) = euclideanExt(this, lb).third

    infix fun Int.gcd(lb: Int) = euclideanExt(this, lb).third

    fun chinese(qs: List<Int>, ans: List<Int>): Pair<Int, Int> {

        if (qs.count() == 1) {
            return Pair(qs[0], ans[0] % qs[0])
        }
        val rng1 = 0 until qs.count() / 2
        val res1 = chinese(qs.slice(rng1), ans.slice(rng1))
        val rng2 = qs.count() / 2 until qs.count()
        val res2 = chinese(qs.slice(rng2), ans.slice(rng2))
        // println(res1)
        // println( res2 )
        // println( inverse(res2.first, res1.first) )
        // println( inverse(res1.first, res2.first) )
        val mod = res1.first * res2.first
        val res = (res1.second * res2.first * inverse(res2.first, res1.first) + res2.second * res1.first * inverse(res1.first, res2.first)) % mod
        return Pair(mod, res)
    }

    public fun Long.getPDivisors(): MutableList<Long> {
        if (this == 0L) {
            throw Exception()
        }
        var n = abs(this)
        val res = mutableListOf<Long>()
        while (n % 2L == 0L) {
            res.add(2L)
            n /= 2L
        }

        var cur = 3L
        while (n > 1) {
            if (n % cur != 0L) {
                cur += 2
                continue
            }
            while (n % cur == 0L) {
                res.add(cur)
                n /= cur
            }
            cur += 2
        }
        return res
    }

    public fun Long.getAllDivisors(): MutableList<Long> {
        if (this == 0L) {
            throw Exception()
        }
        val n = abs(this)
        val res = mutableListOf<Long>()
        var v = 2L
        while (v * v < n) {
            if (n % v == 0L) {
                res.add(v)
            }
            v++
        }
        if (v * v == n) {
            res.add(v)
        }
        return res
    }

    public fun Int.getAllDivisors(): MutableList<Int> {
        if (this == 0) {
            throw Exception()
        }
        val n = abs(this)
        val res = mutableListOf<Int>()
        var v = 2
        while (v * v < n) {
            if (n % v == 0) {
                res.add(v)
            }
            v++
        }
        if (v * v == n) {
            res.add(v)
        }
        return res
    }

    public fun Int.getPDivisors(): MutableList<Int> {
        if (this == 0) {
            throw Exception()
        }
        var n = abs(this)
        val res = mutableListOf<Int>()
        while (n % 2 == 0) {
            res.add(2)
            n /= 2
        }

        var cur = 3
        while (n > 1) {
            if (n % cur != 0) {
                cur += 2
                continue
            }
            while (n % cur == 0) {
                res.add(cur)
                n /= cur
            }
            cur += 2
        }
        return res
    }
}

object Mod {
    private var _div = 2L

    public val div: Long
        get() = _div

    public fun setMod(div: Long) {
        if (div <= 0) {
            throw Exception()
        }
        _div = div
    }

    public fun setMod(div: Int) {
        if (div <= 0) {
            throw Exception()
        }
        _div = div.toLong()
    }

    public fun Long.mmod(): Long {
        return if (this < 0) _div + (this % _div) else this % _div
    }

    public fun Int.mmod(): Int {
        return (if (this < 0) _div + (this % _div) else this % _div).toInt()
    }

    public infix fun Long.mrem(v: Long): Long {
        if (v == 0L) {
            throw Exception()
        }
        return abs(this) % v
    }

    public fun Long.mpow(exp: Long, divisor: Long): Long {
        if (this == 0L && exp <= 0) {
            throw Exception()
        }

        if (exp == 0L) {
            return 1L
        }
        if (exp == 1L) {
            return this
        }
        var lv = this
        var lexp = exp

        var res = 1L
        while (lexp > 0) {
            res = (res * if (lexp % 2 == 1L) lv else 1L) % divisor
            lv = (lv * lv) % divisor
            lexp /= 2L
        }
        return res
    }

    public fun Int.mpow(exp: Int, divisor: Long): Int {

        return (this.toLong()).mpow(exp.toLong(), divisor.toLong()).toInt()
    }

    public fun Long.mmult(v: Long, mod: Long): Long {
        if (mod <= 0) {
            throw Exception()
        }
        return (this * v) mmod mod
    }

    public fun Int.mmult(v: Int, mod: Int): Int {
        return this.toLong().mmult(v.toLong(), mod.toLong()).toInt()
    }

    public infix fun Long.mmult(v: Long): Long {
        return this.mmult(v, _div)
    }

    public infix fun Int.mmult(v: Int): Int {
        return this.toLong().mmult(v.toLong(), _div).toInt()
    }

    public fun Long.mdiv(v: Long, mod: Long): Long {
        if (mod <= 0) {
            throw Exception()
        }
        return this.mmult(inverse(v, mod), mod)
    }

    public fun Int.mdiv(v: Int, mod: Int): Int {
        if (mod <= 0) {
            throw Exception()
        }
        return this.toLong().mdiv(v.toLong(), mod.toLong()).toInt()
    }

    public infix fun Long.mdiv(v: Long): Long {
        return this.mdiv(v, _div)
    }

    public infix fun Int.mdiv(v: Int): Int {
        return this.toLong().mdiv(v.toLong(), _div).toInt()
    }

    public fun Long.mminus(v: Long, mod: Long): Long {
        return this.mplus(-1L*v, mod)
    }

    public fun Int.mminus(v: Int, mod: Int): Int {
        return this.mplus(-1*v, mod)
    }

    public fun Long.mplus(v: Long, mod: Long): Long {
        if (mod <= 0) {
            throw Exception()
        }
        return (this + v) mmod mod
    }

    public fun Int.mplus(v: Int, mod: Int): Int {
        return this.toLong().mplus(v.toLong(), mod.toLong()).toInt()
    }

    public infix fun Long.mminus(v: Long): Long {
        return this.mplus(-1L*v, _div)
    }

    public infix fun Int.mminus(v: Int): Int {
        return this.mplus(-1*v, _div.toInt()).toInt()
    }

    public infix fun Long.mplus(v: Long): Long {
        return this.mplus(v, _div)
    }

    public infix fun Int.mplus(v: Int): Int {
        return this.mplus(v, _div.toInt())
    }

    public infix fun Long.mmod(mod: Long): Long {
        if (mod <= 0L) {
            throw Exception()
        }
        return if (this < 0) mod + (this % mod) else this % mod
    }

    public infix fun Int.mmod(mod: Int): Int {
        if (mod <= 0) {
            throw Exception()
        }
        return (if (this < 0) mod + (this % mod) else this % mod).toInt()
    }

    public infix fun Long.mpow(exp: Long): Long {
        return this.mpow(exp, _div)
    }

    public infix fun Int.mpow(exp: Int): Int {
        return this.mpow(exp, _div)
    }
}

object Comb {

    var facts: LongArray = LongArray(0)
        private set

    public fun Int.mprecompute() {
        if (this < 0) {
            throw Exception()
        }
        facts = LongArray(this + 1)
        facts[0] = 1L
        for (i in 1..this) {
            facts[i] = facts[i - 1] mmult i.toLong()
        }
    }

    public fun Long.mfact(mod: Long): Long {
        if (this == 1L || this == 0L) {
            return 1L
        }

        var res = 1L
        for (i in 2L..this) {
            res = (res * i) mmod mod
        }
        return res
    }

    public fun Long.mfact(): Long {
        return this.mfact(Mod.div)
    }

    public fun Int.mfact(mod: Int): Int {
        return this.toLong().mfact(mod.toLong()).toInt()
    }

    public fun Int.fact(): Int {
        return this.mfact(Mod.div.toInt())
    }
}

fun getMaxBit(v: Long): Int {
    var res = 0
    var cur = v
    while (cur > 0) {
        res++
        cur = cur shr 1
    }
    return res
}

fun isPrime(vl: Long): Boolean {

    var test = 2L
    while (test * test <= vl && (vl % test != 0L)) {
        test++
    }
    return (vl == 2L) || (vl % test) != 0L
}

fun getBit(v: Long, s: Int): Long {
    return (v shr s) and 1
}

fun getNext1(v1: Long, s: Int): Int {
    var cur = s
    while (getBit(v1, cur) == 0L && cur < 64) {
        cur++
    }
    return cur
}

fun replace10(v1: Long, v2: Long, st: Int, reverse: Boolean, res: MutableList<String>): Int {
    var onep1 = getNext1(v1, st + 1)
    var onep2 = getNext1(v2, st + 1)
    var last = min(onep1, onep2)
    if (last == 64) {
        last = st + 2
    }
    last -= 1
    for (i in st..last - 1) {
        res.add(if (reverse) "S" else "W")
    }
    res.add(if (reverse) "N" else "E")
    return last + 1
}

fun replace11(v1: Long, v2: Long, st: Int, reverse: Boolean, res: MutableList<String>): Int? {
    var onep1 = getNext0(v1, st + 1)
    var onep2 = getNext0(v2, st + 1)
    if (onep1 != onep2) {
        return null
    }
    res.add(if (reverse) "S" else "W")

    var last = onep1
    for (i in (st + 1)..(last - 1)) {
        res.add(if (reverse) "E" else "N")
    }
    res.add(if (reverse) "N" else "E")
    return last + 1
}

fun getNext0(v1: Long, s: Int): Int {
    var cur = s
    while (getBit(v1, cur) == 1L && cur < 64) {
        cur++
    }
    return cur
}

fun ppow(v: Long, pow: Long, mod: Long): Long {

    if (pow == 0L) {
        return 1L
    }
    if (pow == 1L) {
        return v
    }
    var res = if (pow % 2L == 1L) v else 1L
    val tmp = ppow((v*v) % mod, pow / 2, mod)
    res *= (tmp * tmp) % mod
    res = res % mod
    return res
}

class UF {
    val rank = HashMap<Int, Int>()
    val parent = HashMap<Int, Int>()
    val counts = HashMap<Int, Int>()
    var groupCnt = 0

    fun add(v: Int) {
        if (!rank.containsKey(v)) {
            groupCnt ++
            // println("$v: $groupCnt")
            rank[v] = 1
            parent[v] = v
            counts[v] = 1
        }
    }

    fun getParent(v: Int): Int {

        add(v)
        var p1 = v

        while (parent[p1] != p1) {

            val tmp = p1
            p1 = parent[p1]!!
            parent[tmp] = parent[p1]!!
        }
        return p1
    }

    fun union(v1: Int, v2: Int) {

        // println("union: $v1, $v2")
        var p1 = getParent(v1)
        var p2 = getParent(v2)
        if (p1 == p2) {
            return
        }

        groupCnt --
        // println(groupCnt)
        if (rank[p2]!! > rank[p1]!!) {
            parent[p1] = p2
            counts[p2] = counts[p2]!! + counts[p1]!!
        } else if (rank[p2]!! < rank[p1]!!) {
            parent[p2] = p1
            counts[p1] = counts[p1]!! + counts[p2]!!
        } else {
            parent[p1] = p2
            counts[p2] = counts[p2]!! + counts[p1]!!
        }
    }

    fun connected(v1: Int, v2: Int): Boolean {
        return getParent(v1) == getParent(v2)
    }
}

fun main(args: Array<String>) {

    val n = readInt()

    var arr = readLongs()

    val cnt = MutableList(20) { 0L }
    for (i in 0..arr.lastIndex) {
        var el = arr[i]
        var j = 0
        while(el > 0){
            cnt[j]+=(el%2L)
            el = el / 2
            j++
        }

    }
    var res = 0L
    var mx = cnt.max()!!
    for (i in 1L..mx) {
        var tmp = 0L
        var pw = 1L
        for (j in 0..19) {
            if(cnt[j] > 0){
                cnt[j]--
                tmp+=pw
            }
            pw*=2L
        }
        res += tmp*tmp
    }
    println(res)

}


import kotlin.math.max
import kotlin.math.min

fun main(args : Array<String>) {
//    val input = Scanner(System.`in`)
//    var t = readLine()!!.toInt()

//    for(i in 0..256) {
//        for (j in 0..256) {
//            for (k in 0..256) {
//                var x0 = i and j
//                var y0 = i or j
//                var z0 = k
//                var val00 = x0*x0+y0*y0+z0*z0
//                var val01 = (x0 and z0)*(x0 and z0)+y0*y0+(x0 or z0)*(x0 or z0)
//                var val02 = (y0 and z0)*(y0 and z0)+x0*x0+(y0 or z0)*(y0 or z0)
//
//                println("$val00 $val01 $val02")
//
////                var x1 = i and k
////                var y1 = j
////                var z1 = i or k
////                var val1 = x1*x1+y1*y1+z1*z1
//            }
//            if(i*i+j*j> (i and j) * (i and j) + (i or j) * (i or j) ) {
//                println("$i $j")
//            }
//        }
//    }

    val t = 1
    repeat(t) {
        val n = readLine()!!.toLong()
        val a = readLine()!!.split(" ").map{ it.toLong() }.toMutableList()
//        val n = 200000
//        val a = Array(n){1024*1024-1}.toMutableList()

//        a.sortDescending()
//
//        var loops = 0
//
//        for( l in 0 until n-1) {
//
//            for (i in l until n-1) {
//                var didChange = false
//                for (j in i+1 until n) {
//                    if(a[i]*a[i] + a[j]*a[j] < (a[i] and a[j])*(a[i] and a[j]) + (a[i] or a[j]) * (a[i] or a[j])) {
//                        val t1 = (a[i] and a[j])
//                        val t2 = (a[i] or a[j])
//                        a[i] = t2
//                        a[j] = t1
//                        didChange = true
//                    }
//                }
//                if (didChange) {
//                    ++loops
//                }
//            }
//
//        }
//
//        println(loops)

        val counts = Array(20){0}

        var msk = 1L
        var power = 0

        while(msk < 1024*1024) {
            for ( x in a) {
                if(x and msk != 0L) {
                    counts[power]++
                }
            }
            msk *= 2
            power++
        }

        var ans = 0L

        for(i in 0 until n) {
            var number = 0L
            var mult = 1024*512
            for (j in 19 downTo 0) {
                if(counts[j] > 0) {
                    number += mult
                    counts[j]--
                }
                mult /= 2
            }
            ans += number * number
        }

        println(ans)

//        println(ans.joinToString(separator = " ") { (it + 1).toString()})
    }

}


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

public class D {

	public static void main(String[] args) throws IOException
	{
		BufferedReader ob = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb = new StringBuffer();

		int n=Integer.parseInt(ob.readLine());
		String s[]=ob.readLine().split(" ");
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=Integer.parseInt(s[i]);

		int arr[]=new int[21];

		for(int i=0;i<n;i++)
		{
			int x=a[i];
			int v=20;
			while(x>0)
			{
				if((x&1)==1)
					arr[v]++;
				v--;
				x=x>>1;
			}
		}
		long ans=0;
		for(int i=0;i<n;i++)
		{
			long val=0;
			for(int j=20;j>=0;j--)
			{
				if(arr[j]>0)
				{
					arr[j]--;
					val=val+(long)Math.pow(2, 20-j);
				}
			}
			ans+=val;
		}
		System.out.println(ans);

	}
}


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

public class D {

	public static void main(String[] args) throws IOException
	{
		BufferedReader ob = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb = new StringBuffer();

		int n=Integer.parseInt(ob.readLine());
		String s[]=ob.readLine().split(" ");
		int a[]=new int[n];
		for(int i=0;i<n;i++)
			a[i]=Integer.parseInt(s[i]);

		int arr[]=new int[20];

		for(int i=0;i<n;i++)
		{
			int x=a[i];
			int v=19;
			while(x>0)
			{
				if((x&1)==1)
					arr[v]++;
				v--;
				x=x>>1;
			}
		}
		long ans=0;
		for(int i=0;i<n;i++)
		{
			long val=0;
			for(int j=19;j>=0;j--)
			{
				if(arr[j]>0)
				{
					arr[j]--;
					val=val+(long)Math.pow(2, 19-j);
				}
			}
			ans+=val*val;
		}
		System.out.println(ans);

	}
}


//package code;
import java.io.*;
import java.util.*;
import java.math.*;

public class c
{
    public static int t,Dx ,Dy ,J,n,len=1000005,answer,k,x,q,r,s,m,phi[],Bit[] ,a[],tin[],tout[],discover[],time=0, b[],count,degree[],parent[][] , size[] ,mat[][] , depth[],pre[],blockSize;
    static long  mod=(long)(1e9) + 7 ,sum ,mod1=(long)(998244353),bit[],ans , dp[];
    static int[] dx={-1, 1,0,0} , dy={0 ,0 , -1 ,1};
    static boolean visited[],isPandatic[] ;
    public static TreeSet<Integer> ts[];
    public static ArrayList<Integer> list ,adj[] ,divisor[];
    public static PrintWriter pw;
    public static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    public static int max1=2000005;
    public static void main(String[] args){
        new Thread(null,null,"Prabhat Kumar Prajapati",1<<28)
        {
           public void run()
           {
               try
               {
                   solve();
               }
               catch(Exception e)
               {
                   e.printStackTrace();
                   System.exit(1);
               }
           }
        }.start();
    }
// public static class Pair{
//         int ver;
//         long cost;
//         Pair(int ver , long cost){
//             this.ver=ver;
//             this.cost=cost;
//         }
//     }
public static class Point{
  int x,y;
  Point(int x ,int y){
    this.x=x;
    this.y=y;
  }
}
public static void solve()throws IOException
{
    pw = new PrintWriter(System.out);
    Scanner sc=new Scanner(System.in);
    n=sc.nextInt();
    a=new int[n];
    for(int i=0;i<n;i++)a[i]=sc.nextInt();
    int[] bitCount=new int[21];
    for(int i=0;i<n;i++){
      for(int j=0;j<21;j++){
        if((a[i]&(1<<j)) !=0)bitCount[j]++;
      }
    }

    long ans=0;
    for(int i=0;i<n;i++){
      long num=0;
      for(int j=0;j<21;j++){
        if(bitCount[j]>0){
          num|=(1<<j);
          bitCount[j]--;
        }
      }
      ans+=num*num;
    }
    pw.println(ans);
    pw.close();
}

static void update(int index , int val){
  while(index<len){
    Bit[index]=Math.max(Bit[index] ,val);
    index+=(index&(-index));
  }
}
static int query(int index){
  int max=0;
  while(index>0){
    max=Math.max(max  , Bit[index]);
    index-=(index&(-index));
  }
  return max;
}
// public static void dfs1(int cur , int par){
//   tin[cur]=time++;
//   parent[cur][0]=par==-1?0:par;
//   for(int i=1;i<28;i++)parent[cur][i]=parent[parent[cur][i-1]][i-1];

//   for(Pair p:adj[cur]){
//     int ver=p.ver;
//     if(ver==par)continue;
//     dfs1(ver,cur);
//   }
//   tout[cur]=time-1;
// }
public  static boolean isParent(int u ,int v){
  return tin[u]<=tin[v]&&tout[u]>=tout[v];
}
public  static int lca(int u , int v){
  if(isParent(u,v))return u;
  if(isParent(v,u))return v;

  for(int i=27;i>=0;i--){
    if(!isParent(parent[u][i],v)){
      u=parent[u][i];
    }
  }
  return parent[u][0];
}

static void phi(){
  phi=new int[len];
  boolean[] isPrime=new boolean[len];
  Arrays.fill(isPrime , true);
  for(int i=2;i<len;i++)phi[i]=i;

  for(int i=2;i<len;i++){
      if(phi[i] == i){
      phi[i] = i-1;
      for(int j = 2*i;j<len;j+=i)
        phi[j] = (phi[j]/i)*(i-1);
    }
  }
}
public static long[] seive(){
  // divisor = prime divisor
  //divisor=new LinkedList[len];
  long[] prefixSum=new long[len+1];
  //for(int i=0;i<len;i++)divisor[i]=new LinkedList<>();
    boolean[] isPrime=new boolean[len];
    Arrays.fill(isPrime , true);
    isPrime[0]=isPrime[1]=false;
    for(int i=2;i<len;i++){
      if(!isPrime[i]){
       prefixSum[i]=prefixSum[i-1];
       continue;
      }
      else prefixSum[i]=prefixSum[i-1]+i;

      for(int j=2*i;j<len;j+=i){
       // divisor[j].add(i);
        isPrime[j]=false;
      }
    }
    return prefixSum;
}

// here ans will store number of nodes on longest path
// static int dfs(int cur){
//     int d1=0;
//     int d2=0;
//     visited[cur]=true;
//     for(int ver:adj[cur]){
//         if(visited[ver])continue;
//         int x=dfs(ver);
//         if(x>d1){
//             d2=d1;
//             d1=x;
//         }
//         else if(x>d2){
//             d2=x;
//         }
//         ans=Math.max(ans , d1+d2+1);
//     }
//     //pw.println((cur+1)  +" "+d1+" "+d2);
//     return d1+1;
// }
public static long pow(long n,long p,long m)
{
    long  result = 1;
      if(p==0)
        return 1;

    while(p!=0)
    {
        if(p%2==1)
            result *= n;
        if(result>=m)
        result%=m;
        p >>=1;
        n*=n;
        if(n>=m)
        n%=m;
    }
    return result;
}

}


//package com.company;

import java.util.Scanner;

public class CF_1368_D {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;++i) {
            a[i]=sc.nextInt();
        }
        int c[]=new int[32];
        for(int i=0;i<n;++i) {
            for(int j=0;j<31;++j) {
                if((a[i]&(1<<j))>0)
                    c[j]++;
            }
        }
        int tc=0;
        for(int i=0;i<31;++i) {
            if(c[i]>0)
                tc++;
        }
        int p=tc;
        long ans=0;
        while(p>0) {
            int mask=0;
            for(int i=30;i>=0;--i) {
                if(c[i]>0) {
                    mask|=1<<i;
                    c[i]--;
                    if(c[i]==0)
                        p--;
                }
            }
            ans+=mask*1l*mask;
        }
        System.out.println(ans);
    }
}


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

public class n1{
	static PrintWriter out=new PrintWriter(System.out);
	public static void main(String[] args) throws Exception{
		int n=I.readInt();
		long[]q=new long[n];
		for(int i=0;i<n;i++) {
			q[i]=I.readInt();
		}
		Arrays.sort(q);
		for(int i=q.length-2;i>=0;i--) {
			long r=q[q.length-1]|q[i];
			long l=q[q.length-1]&q[i];
			q[q.length-1]=r;
			q[i]=l;
		}
		long sum=0;
		for(long l:q) {
			sum+=l*l;
		}
		System.out.println(sum);
	}

}

class I{
	static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
	public static String nextToken() throws Exception{
		while(st==null||!st.hasMoreTokens()){
			st=new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}
	public static int readInt() throws Exception{
		return Integer.parseInt(nextToken());
	}
	public static long readLong() throws Exception{
		return Long.parseLong(nextToken());
	}
	public static double readDouble() throws Exception{
		return Double.parseDouble(nextToken());
	}
	public static String readString() throws Exception{
		return nextToken();
	}
	public static String readLine() throws Exception{
		return in.readLine();
	}
}
class tocka implements Comparable<tocka>{
	int x,y;
	tocka(int a,int b){
		x=a;
		y=b;
	}
	@Override public int hashCode(){
		final int prime=31;
		int result=1;
		result=prime*result+x;
		result=prime*result+y;
		return result;
	}
	@Override public boolean equals(Object obj){
		if(this==obj)
			return true;
		if(obj==null)
			return false;
		if(getClass()!=obj.getClass())
			return false;
		tocka other=(tocka)obj;
		if(x!=other.x)
			return false;
		if(y!=other.y)
			return false;
		return true;
	}
	@Override public int compareTo(tocka o){
		return y-o.y;
	}
	@Override public String toString(){
		return "tocka [p="+x+", q="+y+"]";
	}

}


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

public class n1{
	static PrintWriter out=new PrintWriter(System.out);
	public static void main(String[] args) throws Exception{
		int n=I.readInt();
		long[]q=new long[n];
		for(int i=0;i<n;i++) {
			q[i]=I.readInt();
		}
		Arrays.sort(q);
		int[]count=new int[20];
		for(long i:q) {
			int p=19;
			long j=i;
			while(j>0) {
				count[p--]+=j%2;
				j/=2;
			}
		}
//		System.out.println(Arrays.toString(count));
		long sum=0;
		while(true) {
			long l=0;
			long pow=1;
			for(int p=19;p>=0;p--) {
				if(count[p]>0) {
					l+=pow;
					count[p]--;
				}
				pow*=2;
			}
			sum+=l*l;
			if(l==0) {
				break;
			}
		}
		System.out.println(sum);
	}

}

class I{
	static BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
	public static String nextToken() throws Exception{
		while(st==null||!st.hasMoreTokens()){
			st=new StringTokenizer(in.readLine());
		}
		return st.nextToken();
	}
	public static int readInt() throws Exception{
		return Integer.parseInt(nextToken());
	}
	public static long readLong() throws Exception{
		return Long.parseLong(nextToken());
	}
	public static double readDouble() throws Exception{
		return Double.parseDouble(nextToken());
	}
	public static String readString() throws Exception{
		return nextToken();
	}
	public static String readLine() throws Exception{
		return in.readLine();
	}
}
class tocka implements Comparable<tocka>{
	int x,y;
	tocka(int a,int b){
		x=a;
		y=b;
	}
	@Override public int hashCode(){
		final int prime=31;
		int result=1;
		result=prime*result+x;
		result=prime*result+y;
		return result;
	}
	@Override public boolean equals(Object obj){
		if(this==obj)
			return true;
		if(obj==null)
			return false;
		if(getClass()!=obj.getClass())
			return false;
		tocka other=(tocka)obj;
		if(x!=other.x)
			return false;
		if(y!=other.y)
			return false;
		return true;
	}
	@Override public int compareTo(tocka o){
		return y-o.y;
	}
	@Override public String toString(){
		return "tocka [p="+x+", q="+y+"]";
	}

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	public static Scanner sc = new Scanner(System.in);
	public static StringTokenizer st;

	public static int[] bitCount = new int[30];

	public static void main(String[] args) throws NumberFormatException, IOException {
		int N = Integer.parseInt(br.readLine());

		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < N; i++) {
			int num = Integer.parseInt(st.nextToken());

			int pos = 0;
			while (num > 0) {
				if (num % 2 == 1) {
					bitCount[pos]++;
				}
				pos++;
				num = num >>> 1;
			}
		}

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

		long ans = 0;

		while (true) {
			boolean fin = true;
			long cur = 0;
			for (int i = bitCount.length - 1; i >= 0; i--) {
				cur *= 2;
				if (bitCount[i] > 0) {
					fin = false;
					cur++;
					bitCount[i]--;
				}
			}
			if (fin) {
				break;
			}
			ans += Math.pow(cur, 2);
		}
		System.out.println(ans);

	}

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	public static Scanner sc = new Scanner(System.in);
	public static StringTokenizer st;

	public static long[] bitCount = new long[30];

	public static void main(String[] args) throws NumberFormatException, IOException {
		int N = Integer.parseInt(br.readLine());

		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < N; i++) {
			int num = Integer.parseInt(st.nextToken());

			int pos = 0;
			while (num > 0) {
				if (num % 2 == 1) {
					bitCount[pos]++;
				}
				pos++;
				num = num >>> 1;
			}
		}

		long ans = 0;

		while (true) {
			boolean fin = true;
			long cur = 0;
			for (int i = bitCount.length - 1; i >= 0; i--) {
				cur *= 2;
				if (bitCount[i] > 0) {
					fin = false;
					cur++;
					bitCount[i]--;
				}
			}
			if (fin) {
				break;
			}
			ans += Math.pow(cur, 2);
		}
		System.out.println(ans);

	}

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	public static Scanner sc = new Scanner(System.in);
	public static StringTokenizer st;

	public static int[] bitCount = new int[21];

	public static void main(String[] args) throws NumberFormatException, IOException {
		int N = Integer.parseInt(br.readLine());

		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < N; i++) {
			int num = Integer.parseInt(st.nextToken());

			int pos = 0;
			while (num > 0) {
				if (num % 2 == 1) {
					bitCount[pos]++;
				}
				pos++;
				num = num >>> 1;
			}
		}

		long ans = 0;

		while (true) {
			boolean fin = true;
			long cur = 0;
			for (int i = bitCount.length - 1; i >= 0; i--) {
				cur *= 2;
				if (bitCount[i] > 0) {
					fin = false;
					cur++;
					bitCount[i]--;
				}
			}
			if (fin) {
				break;
			}
			ans += Math.pow(cur, 2);
		}
		System.out.println(ans);

	}

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	public static Scanner sc = new Scanner(System.in);
	public static StringTokenizer st;

	public static long[] bitCount = new long[30];

	public static void main(String[] args) throws NumberFormatException, IOException {
		int N = Integer.parseInt(br.readLine());

		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < N; i++) {
			int num = Integer.parseInt(st.nextToken());

			for (int j = 0; j < bitCount.length; j++) {
				if ((num & (1 << j)) > 0) {
					bitCount[j]++;
				}
			}
		}

		long ans = 0;

		while (true) {
			boolean fin = true;
			long cur = 0;
			for (int i = bitCount.length - 1; i >= 0; i--) {
				cur *= 2;
				if (bitCount[i] > 0) {
					fin = false;
					cur++;
					bitCount[i]--;
				}
			}
			if (fin) {
				break;
			}
			ans += Math.pow(cur, 2);
		}
		System.out.println(ans);

	}

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	public static Scanner sc = new Scanner(System.in);
	public static StringTokenizer st;

	public static long[] bitCount = new long[30];

	public static void main(String[] args) throws NumberFormatException, IOException {
		int N = Integer.parseInt(br.readLine());

		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < N; i++) {
			int num = Integer.parseInt(st.nextToken());

			for (int j = 0; j < bitCount.length; j++) {
				if ((num & (1 << j)) > 0) {
					bitCount[j]++;
				}
			}
		}

		long ans = 0;

		for(int it = 0 ; it < N ; it++) {
			long cur = 0;
			for (int i = 0; i < bitCount.length; i++) {
				if (bitCount[i] > 0) {
					cur += (1 << (long)i);
					bitCount[i]--;
				}
			}
			ans += Math.pow(cur, 2);
		}
		System.out.println(ans);

	}

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	public static Scanner sc = new Scanner(System.in);
	public static StringTokenizer st;

	public static long[] bitCount = new long[30];

	public static void main(String[] args) throws NumberFormatException, IOException {
		int N = Integer.parseInt(br.readLine());

		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < N; i++) {
			int num = Integer.parseInt(st.nextToken());

			for (int j = 0; j < bitCount.length; j++) {
				if ((num & (1 << j)) > 0) {
					bitCount[j]++;
				}
			}
		}

		long ans = 0;

		for(int it = 0 ; it < N ; it++) {
			long cur = 0;
			for (int i = 0; i < bitCount.length; i++) {
				if (bitCount[i] > 0) {
					cur += (1 << (long)i);
					bitCount[i]--;
				}
			}
			ans += (cur * cur);
		}
		System.out.println(ans);

	}

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	public static Scanner sc = new Scanner(System.in);
	public static StringTokenizer st;

	public static long[] bitCount = new long[30];

	public static void main(String[] args) throws NumberFormatException, IOException {
		int N = Integer.parseInt(br.readLine());

		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < N; i++) {
			int num = Integer.parseInt(st.nextToken());

			for (int j = 0; j < bitCount.length; j++) {
				if ((num & (1 << j)) > 0) {
					bitCount[j]++;
				}
			}
		}

		long ans = 0;

		for(int it = 0 ; it < N ; it++) {
			long cur = 0;
			for (int i = 0; i < bitCount.length; i++) {
				if (bitCount[i] > 0) {
					cur += (1 << i);
					bitCount[i]--;
				}
			}
			ans += (cur * cur);
		}
		System.out.println(ans);

	}

}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	public static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	public static Scanner sc = new Scanner(System.in);
	public static StringTokenizer st;

	public static long[] bitCount = new long[30];

	public static void main(String[] args) throws NumberFormatException, IOException {
		int N = Integer.parseInt(br.readLine());

		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < N; i++) {
			int num = Integer.parseInt(st.nextToken());

			for (int j = 0; j < bitCount.length; j++) {
				if ((num & (1 << j)) > 0) {
					bitCount[j]++;
				}
			}
		}

		long ans = 0;

		while (true) {
			boolean fin = true;
			long cur = 0;
			for (int i = bitCount.length - 1; i >= 0; i--) {
				cur *= 2;
				if (bitCount[i] > 0) {
					fin = false;
					cur++;
					bitCount[i]--;
				}
			}
			if (fin) {
				break;
			}
			ans += cur * cur;
		}
		System.out.println(ans);

	}

}


import java.io.*;
import java.util.*;
public class Main {
	static BufferedReader br;
	static PrintWriter pr;
	static int cin() 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;
	}
	static long[] splitL() throws IOException
	{
		String[] cmd=br.readLine().split(" ");
		long[] ans=new long[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Long.valueOf(cmd[i]);
		}
		return ans;
	}
	static int sum(long n)
	{
		int ans=0;
		while(n!=0)
		{
			ans=ans+(int)(n%10);
			n=n/10;
		}
		return ans;
	}
	static int gcd(int x,int y)
	{
		if(x==0)
			return y;
		if(y==0)
			return x;
		if(x>y)
			return gcd(x%y,y);
		else
			return gcd(x,y%x);
	}
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		br=new BufferedReader(new InputStreamReader(System.in));
		pr=new PrintWriter(new OutputStreamWriter(System.out));
		int cases=1;
		while(cases!=0)
		{
			cases--;
			int n=cin();
			int[]arr=split();
			int[]set=new int[21];
			for(int i=20;i>=0;i--)
			{
				int cnt=0;
				for(int j=0;j<n;j++)
				{
					if((arr[j]&(1<<i))!=0)
						cnt++;
				}
				set[i]=cnt;
			}
			long ans=0;
			while(true)
			{
				int c=0;
				for(int i=0;i<=20;i++)
				{
					if(set[i]==0)
						c++;
				}
				if(c==21)
					break;
				long h=0;
				for(int i=0;i<=20;i++)
				{
					if(set[i]==0)
						continue;
					h+=(1<<i);
					set[i]--;
				}
				ans+=h*h;
			}
			System.out.println(ans);
		}
	}
}


// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class DL4 {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            Long[] arr=new Long[n];
            ArrayList<Integer>[] pq=new ArrayList[20];
            for(int i=0;i<20;i++){
                pq[i]=new ArrayList<>();
            }
            for(int i=0;i<n;i++){
                arr[i]=scan.nextLong();
            }
            Arrays.sort(arr);
            for(int i=0;i<n;i++){
                long temp=arr[i];
                int j=0;
                while(temp>0&&j<20){
                    if((temp&1)!=1){
                        pq[j].add(i);
                    }
                    temp>>=1;
                    j++;
                }
            }
            for(int i=0;i<n;i++){
                long temp=arr[i];
                int j=0;
                long v=1;
                while(temp>0){
                    if((temp&1)==1){
                        if(pq[j].size()>0){
                            Integer in=pq[j].get(pq[j].size()-1);
                            pq[j].remove(pq[j].size()-1);
                            if(in>i) {
                                arr[in] += v;
                                arr[i] -= v;
                            }
                        }
                    }
                    temp>>=1;
                    v*=2;
                    j++;
                }
            }
            long ans=0;
            for(int i=0;i<n;i++){
                ans+=arr[i]*arr[i];
            }
            out.println(ans);
        }
        out.flush();
        out.close();
    }
    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;
        }
    }

}


// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class DL4 {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            Long[] arr=new Long[n];
            ArrayList<Integer>[] pq=new ArrayList[20];
            for(int i=0;i<20;i++){
                pq[i]=new ArrayList<>();
            }
            for(int i=0;i<n;i++){
                arr[i]=scan.nextLong();
            }
            Arrays.sort(arr);
            for(int i=0;i<n;i++){
                long temp=arr[i];
                int j=0;
                while(temp>0&&j<20){
                    if((temp&1)!=1){
                        pq[j].add(i);
                    }
                    temp>>=1;
                    j++;
                }
            }
            for(int i=0;i<n;i++){
                long temp=arr[i];
                int j=0;
                long v=1;
                while(temp>0){
                    if((temp&1)==1){
                        if(pq[j].size()>0){
                            Integer in=pq[j].get(pq[j].size()-1);
                            pq[j].remove(pq[j].size()-1);
                            if(in>i) {
                                arr[in] += v;
                                arr[i] -= v;
                            }
                        }
                    }
                    temp>>=1;
                    v*=2;
                    j++;
                }
            }
            long ans=0;
            for(int i=0;i<n;i++){
                ans+=arr[i]*arr[i];
            }
            out.println(ans);
        }
        out.flush();
        out.close();
    }
    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;
        }
    }

}


// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class DL4 {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        int t=1;
//        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            Long[] arr=new Long[n];
            for(int i=0;i<n;i++){
                arr[i]=scan.nextLong();
            }
            Arrays.sort(arr);
            for(int i=1;i<n;i++){
                long temp=arr[i];
                arr[i]=(arr[i]|arr[i-1]);
                arr[i-1]=(temp&arr[i-1]);
            }
            long ans=0;
            for(int i=0;i<n;i++){
                ans+=arr[i]*arr[i];
            }
            out.println(ans);
        }
        out.flush();
        out.close();
    }
    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;
        }
    }

}


    // package com.company;
    import java.util.*;
    import java.lang.*;
    import java.io.*;
    //****Use Integer Wrapper Class for Arrays.sort()****
    public class DL4 {
        static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
        public static void main(String[] Args){
            FastReader scan=new FastReader();
            int t=1;
    //        t=scan.nextInt();
            while(t-->0){
                int n=scan.nextInt();
                Long[] arr=new Long[n];
                PriorityQueue<Integer>[] pq=new PriorityQueue[20];
                for(int i=0;i<20;i++){
                    pq[i]=new PriorityQueue<>(n,Collections.reverseOrder());
                }
                for(int i=0;i<n;i++){
                    arr[i]=scan.nextLong();
                }
                Arrays.sort(arr);
                for(int i=0;i<n;i++){
                    long temp=arr[i];
                    int j=0;
                    while(temp>0&&j<20){
                        if((temp&1)!=1){
                            pq[j].add(i);
                        }
                        temp>>=1;
                        j++;
                    }
                }
                for(int i=0;i<n;i++){
                    long temp=arr[i];
                    int j=0;
                    long v=1;
                    while(temp>0){
                        if((temp&1)==1){
                            if(pq[j].size()>0){
                                Integer in=pq[j].remove();
                                if(in>i) {
                                    arr[in] += v;
                                    arr[i] -= v;
                                }
                            }
                        }
                        temp>>=1;
                        v*=2;
                        j++;
                    }
                }
                long ans=0;
                for(int i=0;i<n;i++){
                    ans+=arr[i]*arr[i];
                }
                out.println(ans);
            }
            out.flush();
            out.close();
        }
        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.*;
import java.io.IOException;

import java.util.*;
//import javafx.util.Pair;
//import java.util.concurrent.LinkedBlockingDeque;

//import sun.net.www.content.audio.wav;

   public  class Codeforces {

        public static long mod = (long)Math.pow(10, 9)+7 ;
        public static double epsilon=0.00000000008854;//value of epsilon
        public static InputReader sc = new InputReader(System.in);
        public static PrintWriter pw = new PrintWriter(System.out);

        public static long gcd(long a,long b){
            while(b>0){
                long t=b;
                b=a%b;
                a=t;
            }
            return a;
        }
        public static long fun(int a1[],TreeSet<Integer> tr2,TreeSet<Integer> tr3){
            int n1=a1.length;
            long max=Long.MAX_VALUE;
                for(int i=0;i<n1;i++){
                    Integer mi2=tr2.floor(a1[i]);
                    Integer ma2=tr2.ceiling(a1[i]);
                    long b2;
                    if(mi2==null)
                    b2=ma2;
                    else if(ma2==null){
                        b2=mi2;
                    }
                    else {
                        if(ma2-a1[i]>a1[i]-mi2){
                            b2=mi2;
                        }
                        else b2=ma2;
                    }
                    Integer mi3=tr3.floor(a1[i]);
                    Integer ma3=tr3.ceiling(a1[i]);
                    long b3;
                    if(mi3==null)
                    b3=ma3;
                    else if(ma3==null){
                        b3=mi3;
                    }
                    else {
                        if(ma3-a1[i]>a1[i]-mi3){
                            b3=mi3;
                        }
                        else b3=ma3;
                    }
                    max=Math.min((a1[i]-b2)*(a1[i]-b2)+(a1[i]-b3)*(a1[i]-b3)+(b2-b3)*(b2-b3),max);

                }

            return max;
        }

        public static void main(String[] args) {
            // code starts..
            int n=sc.nextInt();
            int a[]=scanArray(n);
            for(int i=1;i<n;i++){
                int t=a[i];
                a[i]=a[i]|a[i-1];
                a[i-1]=t&a[i-1];
            }
            long c=0;
            for(int i=0;i<n;i++){
                c+=(long)a[i]*(long)a[i];
            }
            pw.println(c);
            // Code ends...
            pw.flush();
            pw.close();
        }

        public static Comparator<Integer[]> column(int i){
            return
            new Comparator<Integer[]>() {
                @Override
                public int compare(Integer[] o1, Integer[] o2) {
                    return o1[i].compareTo(o2[i]);//for ascending
                    //return o2[i].compareTo(o1[i]);//for descending
                }
            };
        }
        public static String reverseString(String s){
            StringBuilder input1 = new StringBuilder();
            input1.append(s);
            input1 = input1.reverse();
            return input1.toString();
        }
        public static int[] scanArray(int n){
            int a[]=new int [n];
            for(int i=0;i<n;i++)
            a[i]=sc.nextInt();

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

            return a;
        }
        public static String [] scanStrings(int n){
            String a[]=new String [n];
            for(int i=0;i<n;i++)
            a[i]=sc.nextLine();

            return a;
        }

    }

    class InputReader {

            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int curChar, snumChars;
            private SpaceCharFilter filter;

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

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

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

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

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

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

            public String nextLine() {
                int c = snext();
                while (isSpaceChar(c))
                    c = snext();
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = snext();
                } while (!isEndOfLine(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;
            }

            private boolean isEndOfLine(int c) {
                return c == '\n' || c == '\r' || c == -1;
            }

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


import java.io.*;
import java.io.IOException;

import java.util.*;
//import javafx.util.Pair;
//import java.util.concurrent.LinkedBlockingDeque;

//import sun.net.www.content.audio.wav;

   public  class Codeforces {

        public static long mod = (long)Math.pow(10, 9)+7 ;
        public static double epsilon=0.00000000008854;//value of epsilon
        public static InputReader sc = new InputReader(System.in);
        public static PrintWriter pw = new PrintWriter(System.out);

        public static long gcd(long a,long b){
            while(b>0){
                long t=b;
                b=a%b;
                a=t;
            }
            return a;
        }
        public static long fun(int a1[],TreeSet<Integer> tr2,TreeSet<Integer> tr3){
            int n1=a1.length;
            long max=Long.MAX_VALUE;
                for(int i=0;i<n1;i++){
                    Integer mi2=tr2.floor(a1[i]);
                    Integer ma2=tr2.ceiling(a1[i]);
                    long b2;
                    if(mi2==null)
                    b2=ma2;
                    else if(ma2==null){
                        b2=mi2;
                    }
                    else {
                        if(ma2-a1[i]>a1[i]-mi2){
                            b2=mi2;
                        }
                        else b2=ma2;
                    }
                    Integer mi3=tr3.floor(a1[i]);
                    Integer ma3=tr3.ceiling(a1[i]);
                    long b3;
                    if(mi3==null)
                    b3=ma3;
                    else if(ma3==null){
                        b3=mi3;
                    }
                    else {
                        if(ma3-a1[i]>a1[i]-mi3){
                            b3=mi3;
                        }
                        else b3=ma3;
                    }
                    max=Math.min((a1[i]-b2)*(a1[i]-b2)+(a1[i]-b3)*(a1[i]-b3)+(b2-b3)*(b2-b3),max);

                }

            return max;
        }

        public static void main(String[] args) {
            // code starts..
            int n=sc.nextInt();
            long a[]=scanLongArray(n);
            int bit[]=new int[20];
            for(int i=0;i<n;i++){
                long t=a[i];
                int k=0;
                while(t>0){
                    bit[k++]+=t&1;
                    t/=2;
                }
            }
            int f=0;long c=0;
            while(f==0){
                long p=0;
                for(int i=0;i<20;i++){
                    if(bit[i]>0){
                        bit[i]--;
                        p+=1<<i;
                    }
                }
                c+=p*p;
                if(p==0)
                f=1;
            }
            pw.println(c);
            // Code ends...
            pw.flush();
            pw.close();
        }

        public static Comparator<Integer[]> column(int i){
            return
            new Comparator<Integer[]>() {
                @Override
                public int compare(Integer[] o1, Integer[] o2) {
                    return o1[i].compareTo(o2[i]);//for ascending
                    //return o2[i].compareTo(o1[i]);//for descending
                }
            };
        }
        public static String reverseString(String s){
            StringBuilder input1 = new StringBuilder();
            input1.append(s);
            input1 = input1.reverse();
            return input1.toString();
        }
        public static int[] scanArray(int n){
            int a[]=new int [n];
            for(int i=0;i<n;i++)
            a[i]=sc.nextInt();

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

            return a;
        }
        public static String [] scanStrings(int n){
            String a[]=new String [n];
            for(int i=0;i<n;i++)
            a[i]=sc.nextLine();

            return a;
        }

    }

    class InputReader {

            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int curChar, snumChars;
            private SpaceCharFilter filter;

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

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

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

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

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

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

            public String nextLine() {
                int c = snext();
                while (isSpaceChar(c))
                    c = snext();
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = snext();
                } while (!isEndOfLine(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;
            }

            private boolean isEndOfLine(int c) {
                return c == '\n' || c == '\r' || c == -1;
            }

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


import java.io.*;
import java.io.IOException;

import java.util.*;
//import javafx.util.Pair;
//import java.util.concurrent.LinkedBlockingDeque;

//import sun.net.www.content.audio.wav;

   public  class Codeforces {

        public static long mod = (long)Math.pow(10, 9)+7 ;
        public static double epsilon=0.00000000008854;//value of epsilon
        public static InputReader sc = new InputReader(System.in);
        public static PrintWriter pw = new PrintWriter(System.out);

        public static long gcd(long a,long b){
            while(b>0){
                long t=b;
                b=a%b;
                a=t;
            }
            return a;
        }
        public static long fun(int a1[],TreeSet<Integer> tr2,TreeSet<Integer> tr3){
            int n1=a1.length;
            long max=Long.MAX_VALUE;
                for(int i=0;i<n1;i++){
                    Integer mi2=tr2.floor(a1[i]);
                    Integer ma2=tr2.ceiling(a1[i]);
                    long b2;
                    if(mi2==null)
                    b2=ma2;
                    else if(ma2==null){
                        b2=mi2;
                    }
                    else {
                        if(ma2-a1[i]>a1[i]-mi2){
                            b2=mi2;
                        }
                        else b2=ma2;
                    }
                    Integer mi3=tr3.floor(a1[i]);
                    Integer ma3=tr3.ceiling(a1[i]);
                    long b3;
                    if(mi3==null)
                    b3=ma3;
                    else if(ma3==null){
                        b3=mi3;
                    }
                    else {
                        if(ma3-a1[i]>a1[i]-mi3){
                            b3=mi3;
                        }
                        else b3=ma3;
                    }
                    max=Math.min((a1[i]-b2)*(a1[i]-b2)+(a1[i]-b3)*(a1[i]-b3)+(b2-b3)*(b2-b3),max);

                }

            return max;
        }

        public static void main(String[] args) {
            // code starts..
            int n=sc.nextInt();
            int a[]=scanArray(n);
            Arrays.sort(a);
            for(int i=1;i<n;i++){
                int t=a[i];
                a[i]=a[i]|a[i-1];
                a[i-1]=t&a[i-1];
            }
            long c=0;
            for(int i=0;i<n;i++){
                c+=(long)a[i]*(long)a[i];
            }
            pw.println(c);
            // Code ends...
            pw.flush();
            pw.close();
        }

        public static Comparator<Integer[]> column(int i){
            return
            new Comparator<Integer[]>() {
                @Override
                public int compare(Integer[] o1, Integer[] o2) {
                    return o1[i].compareTo(o2[i]);//for ascending
                    //return o2[i].compareTo(o1[i]);//for descending
                }
            };
        }
        public static String reverseString(String s){
            StringBuilder input1 = new StringBuilder();
            input1.append(s);
            input1 = input1.reverse();
            return input1.toString();
        }
        public static int[] scanArray(int n){
            int a[]=new int [n];
            for(int i=0;i<n;i++)
            a[i]=sc.nextInt();

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

            return a;
        }
        public static String [] scanStrings(int n){
            String a[]=new String [n];
            for(int i=0;i<n;i++)
            a[i]=sc.nextLine();

            return a;
        }

    }

    class InputReader {

            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int curChar, snumChars;
            private SpaceCharFilter filter;

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

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

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

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

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

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

            public String nextLine() {
                int c = snext();
                while (isSpaceChar(c))
                    c = snext();
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = snext();
                } while (!isEndOfLine(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;
            }

            private boolean isEndOfLine(int c) {
                return c == '\n' || c == '\r' || c == -1;
            }

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


import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.LongAdder;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] bit = new int[20];
        for (int i=0;i<n;i++){
            int x = input.nextInt();
            for (int j=0;j<20;j++){
                if ((x & (1<<j)) > 0) bit[j]++;
            }
        }
        long sum = 0;
        for (int i=0;i<n;i++){
            long ans = 0;
            for (int j=0;j<20;j++){
                if (bit[j]>0){
                    ans += (1<<j);
                    bit[j]--;
                }
            }
            sum += ans*ans;
        }
        System.out.println(sum);
    }
}


import java.util.*;
import java.io.*;
public class A
{
      public static void main(String ar[]) throws Exception
      {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int n=Integer.parseInt(br.readLine());
            String s1[]=br.readLine().split(" ");
            int a[]=new int[n];
            int b[]=new int[20];
            for(int i=0;i<n;i++)
            {
                  a[i]=Integer.parseInt(s1[i]);
                  for(int j=0;j<20;j++)
                   if((a[i]>>j)%2==1)
                    b[j]++;
            }

            //System.out.println(Arrays.toString(b));

            Arrays.fill(a,0);
            long S=0;
            for(int i=n-1;i>=0;i--)
            {
                  for(int j=0;j<20;j++)
                   if(b[j]>0)
                   { a[i]+=(int)Math.pow(2,j); b[j]--; }
                  S+=(long)a[i]*a[i];
            }

            //System.out.println(Arrays.toString(a));
            System.out.println(S);
      }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;

public class ANDORSquareSum { // Template for CF
    public static class ListComparator implements Comparator<List<Integer>> {

        @Override
        public int compare(List<Integer> l1, List<Integer> l2) {
            for (int i = 0; i < l1.size(); ++i) {
                if (l1.get(i).compareTo(l2.get(i)) != 0) {
                    return l1.get(i).compareTo(l2.get(i));
                }
            }
            return 0;
        }
    }

    public static void main(String[] args) throws IOException {
        // Check for int overflow!!!!
        // Should you use a long to store the sum or smthn?
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int N = Integer.parseInt(f.readLine());
        int[] bits = new int[21];
        StringTokenizer st = new StringTokenizer(f.readLine());
        for (int i = 0; i < N; i++) {
            int a = Integer.parseInt(st.nextToken());
            for (int j = 1; j <= 20; j++) {
                if ((a & 1) == 1) {
                    bits[j]++;
                }
                a = a >> 1;
            }
        }
        long sum = 0;
        while (true) {
            boolean check = false;
            long curr = 0;
            for (int i = 1; i <= 20; i++) {
                if (bits[i] > 0) {
                    bits[i]--;
                    check = true;
                    curr += (int) Math.pow(2, i - 1);
                }
            }
            sum += (curr * curr);
            if (!check) {
                break;
            }
        }
        out.println(sum);
        out.close();
    }

}


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

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

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

  }

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

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

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

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

  }
}


import java.io.*;import java.util.*;import java.math.*;
public class Main
{
	static long mod=1000000007l;
    static int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;
    static long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE;
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;

    static public void main(String[] args)throws Exception
    {
    	st=new StringTokenizer(br.readLine());
    	int n=i();
    	int ar[]=ari(n);
    	long c=0l;
    	for(int x=1;x<n;x++)
    	{
    		int v1=ar[x-1]&ar[x];
    		int v2=ar[x-1]|ar[x];
    		c+=1l*v1*v1;
    		ar[x]=v2;
    	}
    	c+=1l*ar[n-1]*ar[n-1];
    	pl(c);
    }

    static int max(int a,int b){return a>b?a:b;}
    static int min(int a,int b){return a<b?a:b;}
    static int abs(int a){return Math.abs(a);}
    static long max(long a,long b){return a>b?a:b;}
    static long min(long a,long b){return a<b?a:b;}
    static long abs(long a){return Math.abs(a);}
    static int sq(int a){return (int)Math.sqrt(a);}
    static long sq(long a){return (long)Math.sqrt(a);}
    static int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
//    static void g(int i)
//    {
//    	for(int e:ar[i])
//    	{
//    		if(e==i)continue;
//    		al[i].add(e);
//    		g(e);
//    	}
//    }
    static int ncr(int n,int c,long m)
    {
        long a=1l;
        for(int x=n-c+1;x<=n;x++)a=((a*x)%m);
        long b=1l;
        for(int x=2;x<=c;x++)b=((b*x)%m);
        return (int)((a*(div((int)b,m-2,m)%m))%m);
    }
    static int fib(int n){return (int)Math.round(Math.pow((1+sq(5))/2,n)/sq(5));}
    static boolean[] sieve(int n)
    {
        boolean bo[]=new boolean[n+1];
        bo[0]=true;bo[1]=true;
        for(int x=4;x<=n;x+=2)bo[x]=true;
        for(int x=3;x*x<=n;x+=2)if(!bo[x])for(int y=x*x;y<=n;y+=x)bo[y]=true;
        return bo;
    }
    static int[] fac(int n)
    {
        int bo[]=new int[n+1];
        for(int x=1;x<=n;x++)for(int y=x;y<=n;y+=x)bo[y]++;
        return bo;
    }
    static long div(long a,long b,long m)
    {
        long r=1l;
        a%=m;
        while(b>0)
        {
            if((b&1)==1)r=(r*a)%m;
            b>>=1;
            a=(a*a)%m;
        }
        return r;
    }
    static int i()throws IOException
    {
        if(!st.hasMoreTokens()) st=new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }
    static long l()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Long.parseLong(st.nextToken());
    }
    static String s()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return st.nextToken();
    }
    static double d()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Double.parseDouble(st.nextToken());
    }
    static void p(Object p){System.out.print(p);}
    static void p(String p){System.out.print(p);}
    static void p(int p){System.out.print(p);}
    static void p(double p){System.out.print(p);}
    static void p(long p){System.out.print(p);}
    static void p(char p){System.out.print(p);}
    static void p(boolean p){System.out.print(p);}
    static void pl(Object p){System.out.println(p);}
    static void pl(String p){System.out.println(p);}
    static void pl(int p){System.out.println(p);}
    static void pl(char p){System.out.println(p);}
    static void pl(double p){System.out.println(p);}
    static void pl(long p){System.out.println(p);}
    static void pl(boolean p){System.out.println(p);}
    static void pl(){System.out.println();}
    static int[] ari(int n)throws IOException
    {
        int ar[]=new int[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=Integer.parseInt(st.nextToken());
        return ar;
    }
    static int[][] ari(int n,int m)throws IOException
    {
        int ar[][]=new int[n][m];
        for(int x=0;x<n;x++)
        {
        	if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());
        }
        return ar;
    }
    static long[] arl(int n)throws IOException
    {
        long ar[]=new long[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++) ar[x]=Long.parseLong(st.nextToken());
        return ar;
    }
    static long[][] arl(int n,int m)throws IOException
    {
        long ar[][]=new long[n][m];
        for(int x=0;x<n;x++)
        {
        	if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());
        }
        return ar;
    }
    static String[] ars(int n)throws IOException
    {
        String ar[]=new String[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++) ar[x]=st.nextToken();
        return ar;
    }
    static double[] ard(int n)throws IOException
    {
        double ar[]=new double[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());
        return ar;
    }
    static double[][] ard(int n,int m)throws IOException
    {
        double ar[][]=new double[n][m];
        for(int x=0;x<n;x++)
        {
        	if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Double.parseDouble(st.nextToken());
        }
        return ar;
    }
    static char[] arc(int n)throws IOException
    {
        char ar[]=new char[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);
        return ar;
    }
    static char[][] arc(int n,int m)throws IOException
    {
        char ar[][]=new char[n][m];
        for(int x=0;x<n;x++)
        {
            String s=br.readLine();
            for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);
        }
        return ar;
    }
    static void p(int ar[])
    {
        StringBuilder sb=new StringBuilder(11*ar.length);
        for(int a:ar)
        {
        	sb.append(a);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(int ar[][])
    {
        StringBuilder sb;
        for(int a[]:ar)
        {
            sb=new StringBuilder(2*a.length);
            for(int aa:a)
            {
            	sb.append(aa);
            	sb.append(' ');
            }
            System.out.println(sb);
        }
    }
    static void p(long ar[])
    {
        StringBuilder sb=new StringBuilder(20*ar.length);
        for(long a:ar)
        {
        	sb.append(a);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(long ar[][])
    {
        StringBuilder sb;
        for(long a[]:ar)
        {
            sb=new StringBuilder(2*a.length);
            for(long aa:a)
            {
            	sb.append(aa);
            	sb.append(' ');
            }
            System.out.println(sb);
        }
    }
    static void p(String ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(String a:ar)
        {
        	sb.append(a);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(double ar[])
    {
        StringBuilder sb=new StringBuilder(20*ar.length);
        for(double a:ar)
        {
        	sb.append(a);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(double ar[][])
    {
        StringBuilder sb;
        for(double a[]:ar)
        {
            sb=new StringBuilder(4*a.length);
            for(double aa:a)
            {
            	sb.append(aa);
            	sb.append(' ');
            }
            System.out.println(sb);
        }
    }
    static void p(char ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(char aa:ar)
        {
        	sb.append(aa);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(char ar[][])
    {
        StringBuilder sb;
        for(char a[]:ar)
        {
            sb=new StringBuilder(2*a.length);
            for(char aa:a)
            {
            	sb.append(aa);
            	sb.append(' ');
            }
            System.out.println(sb);
        }
    }
}


import java.io.*;import java.util.*;import java.math.*;
public class Main
{
	static long mod=1000000007l;
    static int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;
    static long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE;
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;

    static public void main(String[] args)throws Exception
    {
    	st=new StringTokenizer(br.readLine());
    	int n=i();
    	int ar[]=ari(n);
    	int b[]=new int[21];
    	for(int x:ar)
    	{
    		for(int y=0;y<21;y++)
    		{
    			if((x&(1<<y))!=0)b[y]++;
    		}
    		//p(b);
    	}
    	//p(b);
    	long c=0l;
    	for(int x=0;x<n;x++)
    	{
    		int v=0;
    		for(int y=20;y>=0;y--)
    		{
    			v*=2;
    			if(b[y]>0)
    			{
    				v++;
    				b[y]--;
    			}
    		}
    		c+=1l*v*v;
    	}
    	pl(c);
    }

    static int max(int a,int b){return a>b?a:b;}
    static int min(int a,int b){return a<b?a:b;}
    static int abs(int a){return Math.abs(a);}
    static long max(long a,long b){return a>b?a:b;}
    static long min(long a,long b){return a<b?a:b;}
    static long abs(long a){return Math.abs(a);}
    static int sq(int a){return (int)Math.sqrt(a);}
    static long sq(long a){return (long)Math.sqrt(a);}
    static int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
//    static void g(int i)
//    {
//    	for(int e:ar[i])
//    	{
//    		if(e==i)continue;
//    		al[i].add(e);
//    		g(e);
//    	}
//    }
    static int ncr(int n,int c,long m)
    {
        long a=1l;
        for(int x=n-c+1;x<=n;x++)a=((a*x)%m);
        long b=1l;
        for(int x=2;x<=c;x++)b=((b*x)%m);
        return (int)((a*(div((int)b,m-2,m)%m))%m);
    }
    static int fib(int n){return (int)Math.round(Math.pow((1+sq(5))/2,n)/sq(5));}
    static boolean[] sieve(int n)
    {
        boolean bo[]=new boolean[n+1];
        bo[0]=true;bo[1]=true;
        for(int x=4;x<=n;x+=2)bo[x]=true;
        for(int x=3;x*x<=n;x+=2)if(!bo[x])for(int y=x*x;y<=n;y+=x)bo[y]=true;
        return bo;
    }
    static int[] fac(int n)
    {
        int bo[]=new int[n+1];
        for(int x=1;x<=n;x++)for(int y=x;y<=n;y+=x)bo[y]++;
        return bo;
    }
    static long div(long a,long b,long m)
    {
        long r=1l;
        a%=m;
        while(b>0)
        {
            if((b&1)==1)r=(r*a)%m;
            b>>=1;
            a=(a*a)%m;
        }
        return r;
    }
    static int i()throws IOException
    {
        if(!st.hasMoreTokens()) st=new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }
    static long l()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Long.parseLong(st.nextToken());
    }
    static String s()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return st.nextToken();
    }
    static double d()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Double.parseDouble(st.nextToken());
    }
    static void p(Object p){System.out.print(p);}
    static void p(String p){System.out.print(p);}
    static void p(int p){System.out.print(p);}
    static void p(double p){System.out.print(p);}
    static void p(long p){System.out.print(p);}
    static void p(char p){System.out.print(p);}
    static void p(boolean p){System.out.print(p);}
    static void pl(Object p){System.out.println(p);}
    static void pl(String p){System.out.println(p);}
    static void pl(int p){System.out.println(p);}
    static void pl(char p){System.out.println(p);}
    static void pl(double p){System.out.println(p);}
    static void pl(long p){System.out.println(p);}
    static void pl(boolean p){System.out.println(p);}
    static void pl(){System.out.println();}
    static int[] ari(int n)throws IOException
    {
        int ar[]=new int[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=Integer.parseInt(st.nextToken());
        return ar;
    }
    static int[][] ari(int n,int m)throws IOException
    {
        int ar[][]=new int[n][m];
        for(int x=0;x<n;x++)
        {
        	if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());
        }
        return ar;
    }
    static long[] arl(int n)throws IOException
    {
        long ar[]=new long[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++) ar[x]=Long.parseLong(st.nextToken());
        return ar;
    }
    static long[][] arl(int n,int m)throws IOException
    {
        long ar[][]=new long[n][m];
        for(int x=0;x<n;x++)
        {
        	if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());
        }
        return ar;
    }
    static String[] ars(int n)throws IOException
    {
        String ar[]=new String[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++) ar[x]=st.nextToken();
        return ar;
    }
    static double[] ard(int n)throws IOException
    {
        double ar[]=new double[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());
        return ar;
    }
    static double[][] ard(int n,int m)throws IOException
    {
        double ar[][]=new double[n][m];
        for(int x=0;x<n;x++)
        {
        	if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Double.parseDouble(st.nextToken());
        }
        return ar;
    }
    static char[] arc(int n)throws IOException
    {
        char ar[]=new char[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);
        return ar;
    }
    static char[][] arc(int n,int m)throws IOException
    {
        char ar[][]=new char[n][m];
        for(int x=0;x<n;x++)
        {
            String s=br.readLine();
            for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);
        }
        return ar;
    }
    static void p(int ar[])
    {
        StringBuilder sb=new StringBuilder(11*ar.length);
        for(int a:ar)
        {
        	sb.append(a);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(int ar[][])
    {
        StringBuilder sb;
        for(int a[]:ar)
        {
            sb=new StringBuilder(2*a.length);
            for(int aa:a)
            {
            	sb.append(aa);
            	sb.append(' ');
            }
            System.out.println(sb);
        }
    }
    static void p(long ar[])
    {
        StringBuilder sb=new StringBuilder(20*ar.length);
        for(long a:ar)
        {
        	sb.append(a);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(long ar[][])
    {
        StringBuilder sb;
        for(long a[]:ar)
        {
            sb=new StringBuilder(2*a.length);
            for(long aa:a)
            {
            	sb.append(aa);
            	sb.append(' ');
            }
            System.out.println(sb);
        }
    }
    static void p(String ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(String a:ar)
        {
        	sb.append(a);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(double ar[])
    {
        StringBuilder sb=new StringBuilder(20*ar.length);
        for(double a:ar)
        {
        	sb.append(a);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(double ar[][])
    {
        StringBuilder sb;
        for(double a[]:ar)
        {
            sb=new StringBuilder(4*a.length);
            for(double aa:a)
            {
            	sb.append(aa);
            	sb.append(' ');
            }
            System.out.println(sb);
        }
    }
    static void p(char ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(char aa:ar)
        {
        	sb.append(aa);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(char ar[][])
    {
        StringBuilder sb;
        for(char a[]:ar)
        {
            sb=new StringBuilder(2*a.length);
            for(char aa:a)
            {
            	sb.append(aa);
            	sb.append(' ');
            }
            System.out.println(sb);
        }
    }
}