#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<vector> usingnamespace std; #define MAXN ( 1 << 20 ) + 12 #define P 998244353 //#define int long long typedeflonglong ll; int n , inv2; int A[MAXN] , B[MAXN] , I[MAXN]; intPow( int a , int x ){ int res = a , ans = 1; while( x ) { if( x & 1 ) ans = 1ll * ans * res % P; res = 1ll * res * res % P , x >>= 1; } return ans; } namespace fwt { inlinevoidFWT1(int a[], int len){ for (int mid = 2; mid <= len; mid <<= 1) for (int i = 0; i < len; i += mid) for (int j = i; j < i + (mid >> 1); j++) a[j + (mid >> 1)] += a[j] , a[j + (mid >> 1)] %= P; } inlinevoidIFWT1(int a[], int len){ for (int mid = 2; mid <= len; mid <<= 1) for (int i = 0; i < len; i += mid) for (int j = i; j < i + (mid >> 1); j++) a[j + (mid >> 1)] -= a[j] , a[j + (mid >> 1)] += P , a[j + (mid >> 1)] %= P; } inlinevoidFWT2(int a[], int len){ for (int mid = 2; mid <= len; mid <<= 1) for (int i = 0; i < len; i += mid) for (int j = i; j < i + (mid >> 1); j++) a[j] += a[j + (mid >> 1)]; } inlinevoidIFWT2(int a[], int len){ for (int mid = 2; mid <= len; mid <<= 1) for (int i = 0; i < len; i += mid) for (int j = i; j < i + (mid >> 1); j++) a[j] -= a[j + (mid >> 1)]; } inlinevoidFWT3(int a[], int len){ for (int mid = 2; mid <= len; mid <<= 1) for (int i = 0; i < len; i += mid) for (int j = i; j < i + (mid >> 1); j++) { ll x = a[j], y = a[j + (mid >> 1)]; a[j] = ( x + y ) % P, a[j + (mid >> 1)] = ( x - y + P ) % P ; } } inlinevoidIFWT3(int a[], int len){ for (int mid = 2; mid <= len; mid <<= 1) for (int i = 0; i < len; i += mid) for (int j = i; j < i + (mid >> 1); j++) { ll x = a[j], y = a[j + (mid >> 1)]; a[j] = ( 1ll * (x + y) % P * inv2 ) % P, a[j + (mid >> 1)] = ( 1ll * (x - y + P) % P * inv2 ) % P; } } }
int a[20][MAXN] , b[20][MAXN] , ans[20][MAXN] , res[MAXN]; signedmain(){ cin >> n; inv2 = Pow( 2 , P - 2 ); int len = ( 1 << n ); for( int i = 0 ; i < len ; ++ i ) scanf("%d",&A[i]) , a[__builtin_popcount( i )][i] = 1ll * A[i] * ( 1 << ( __builtin_popcount( i ) ) ) % P; for( int i = 0 ; i < len ; ++ i ) scanf("%d",&B[i]) , b[__builtin_popcount( i )][i] = B[i]; for( int i = 0 ; i <= n ; ++ i ) fwt::FWT3( a[i] , len ) , fwt::FWT3( b[i] , len ); for( int i = 0 ; i <= n ; ++ i ) { for( int j = 0 ; j <= i ; ++ j ) { for( int k = 0 ; k < len ; ++ k ) ( ans[j][k] += 1ll * a[i - j][k] * b[i][k] % P ) %= P; // , cout << i - j << ' ' << k << ':' << a[i - j][k] << endl;; } } for( int i = 0 ; i <= n ; ++ i ) fwt::IFWT3( ans[i] , len ); for( int i = 0 ; i < len ; ++ i ) res[i] = ans[__builtin_popcount( i )][i]; int c = 1 , ret = 0; for( int i = 0 ; i < len ; ++ i ) ret = ( ret + 1ll * res[i] * c % P ) % P , c = 1ll * c * 1526 % P; // , cout << res[i] << endl; cout << ret << endl; }