Covering Sets

Let's consider a set S of N different elements numbered from 0 to N - 1. It's a well-known fact that there are exactly 2N subsets of S (including the empty subset). Each subset S' of S can be encoded as a bitmask B(S') containing N bits, where the i'th bit of B(S') is equal to 1 if the i'th element of S belongs to S', and 0 otherwise. Each bitmask can also be considered as a non-negative integer represented in binary.


	For example, suppose N is equal to 5. Then S = {0, 1, 2, 3, 4}. Let's assume S' = {0, 3, 4}. Then B(S') = 1 × 20 + 0 × 21 + 0 × 22 + 1 × 23 + 1 × 24 = 110012 = 2510.


	Let's say that a triple (A, B, C) of subsets of S covers a subset D of S, if D is a subset of the union of subsets A, B and C. In other words, every element of D is an element of at least one of A, B, or C.


	Let's consider four functions F, G, H and R. Each takes a subset of S as the only parameter and returns a non-negative integer. You are given the values of F(i), G(i), and H(i) for each 0 ≤ i < 2N.


	The value of the function R of a subset X of S is equal to the sum of F(A) × G(B) × H(C) for all triples (A, B, C) of subsets of S that cover X.


	Your task is to calculate R(0) + R(1) + ... + R(2N - 1) modulo 1000000007(109 + 7).

Input

	The first line of the input contains one integer N.


	The second line of the input contains 2N integers, denoting the values of F(0), F(1), ..., F(2N - 1). The third and the fourth lines of the input contains the values of G and H in the same format.

Output

	The output should contain one integer: R(0) + R(1) + ... + R(2N - 1) modulo 1000000007(109 + 7).

Constraints
1 ≤ N ≤ 20;
0 ≤ Fi, Gi, Hi < 1,000,000,007(109 + 7).
Example
Input:
2
1 3 9 12
0 5 1 2
2 3 4 1

Output:
7680

Explanations

Here's the table of what sets are covered by all the possible triples for N = 1:


A
B
C
D


0
0
0
{0}


0
0
1
{0, 1}


0
1
0
{0, 1}


0
1
1
{0, 1}


1
0
0
{0, 1}


1
0
1
{0, 1}


1
1
0
{0, 1}


1
1
1
{0, 1}

Example input:

Example output:


Solution:

    #include <bits/stdc++.h>
    using namespace std;
    
    #define MOD 1000000007
    
    long long int f[1<<20];
    long long int g[1<<20];
    long long int h[1<<20];
    long long int ans[1<<20];
    
    void transform(int a,int b)
    {
    	if(a+1==b)return;
    
    	int mid = (a+b)/2;
    	transform(a,mid);
    	transform(mid,b);
    
    	for(int i=0;i<mid-a;i++)
    	{
    		f[mid+i] += f[a+i];
    		if(f[mid+i]>=MOD)f[mid+i]-=MOD;
    		g[mid+i] += g[a+i];
    		if(g[mid+i]>=MOD)g[mid+i]-=MOD;
    		h[mid+i] += h[a+i];
    		if(h[mid+i]>=MOD)h[mid+i]-=MOD;
    	}
    
    	return;
    }
    
    void revtransform(int l,int h)
    {
    	if(l+1==h)return;
    
    	int mid = (l+h)/2;
    	
    	for(int i=0;i<mid-l;i++)
    	{
    		ans[mid+i] -= ans[l+i];
    		if(ans[mid+i]<0)ans[mid+i]+=MOD;
    	}
    
    	revtransform(l,mid);
    	revtransform(mid,h);
    	return;
    }
    
    int main()
    {
    	int N;
    	long long int k = 0;
    
    	scanf("%d",&N);
    
    	for(int i=0;i<(1<<N);i++)scanf("%lld",&f[i]);
    	for(int i=0;i<(1<<N);i++)scanf("%lld",&g[i]);
    	for(int i=0;i<(1<<N);i++)scanf("%lld",&h[i]);
    
    	transform(0,(1<<N));
    
    	for(int i=0;i < (1<<N); i++)ans[i] = ( ( ( f[i] * g[i] ) %MOD ) * h[i]) %MOD;
    
    	revtransform(0,(1<<N));
    
    	for(int i=0;i<(1<<N);i++) k = (k + (ans[i]*(1<<__builtin_popcount(i))%MOD)%MOD)%MOD;
    
    	printf("%lld\n",k);
    	
    	return 0;
     }