• + 0 comments

    There are 2^(2^n) subsets of S, and a moment's thought will convince you that the xor values are uniformly distributed across the 2^n possible values. So the answer we're looking for is 2^((2^n)-n)%M. Calculating that naively (even with pow) will get you a TLE because the exponent gets excessive for large n. But, since M is prime, we can use Fermat's Little Theorem to reduce the modulus of the exponent mod M-1and wind up with values that pow can deal with in the time limit.

    M = 10**9+7
    def solve(n):
        exp = pow(2,n,M-1)
        return pow(2,exp-n,M)