Hard Function

0

0 votes
Very-Easy, Simple-math
Problem

Rohan is solving a very easy problem but it seems very hard to him. Actually he got a list of n numbers and he has to perform a function on those numbers which is defined as -

f(a1,a2,a3......an)=ni=1ain1i<jng(ai,aj)+n1i<j<kng(ai,aj,ak)...+(1)n1g(a1,a2,..,an)

Rohan searches the whole internet and finds that the code to the function g(x,y) is available. Also he finds out that for more than two numbers g can be calculated as g(a,b,c)=g(g(a,b),g(b,c)) and this technique can be used to calculate g for even a list of numbers. So given a list of the numbers can you calculate the function f for Rohan . Algorithm for function g(x,y) is given below -

function g(x,y) {
    if(x-y>0)
        x = x^y^y; // ^ is the xor operator here
    else
        x = x^y^x;// ^ is the xor operator here
    return x;
}
Input
First line contains n as input. Next line contains n space separated integers.
Output
In output give the output of function f for the given list of numbers
Constraints
1A[i]1018
2n105

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

F(1,1) = 2 - 1 = 1

Editor Image

?