malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool ch[30];   int whenlast[30];   char g[1000005];   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       scanf(  %c , &g[i]);       whenlast[g[i] -  A ] = i;     }     int rlt = 0, ans = 0;     for (int i = 0; i < n; i++) {       ch[g[i] -  A ] = true;       rlt = 0;       for (int p = 0; p < 30; p++)         if (ch[p]) rlt++;       ans = max(ans, rlt);       for (int x = 0; x < 30; x++)         if (whenlast[x] == i) ch[x] = false;     }     if (ans <= k)       puts( NO );     else       puts( YES );     return 0;   }
#include <bits/stdc++.h>   long long R = 7 + 1e9, NUMTESTCASE;   const int NN = 10 + 2e6;   const double pi = acos(-1.0);   int di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1},       DI[8] = {1, 1, 0, -1, -1, -1, 0, 1}, DJ[8] = {0, 1, 1, 1, 0, -1, -1, -1};   using namespace std;   int n, ti = 1, timein[NN], timeout[NN], lev[NN], parn[NN], Hash[NN], m,          segtree[NN];   vector<int> G[NN];   void DFS(int ver, int par, int cnt) {     int in = ti++;     for (int u : G[ver])       if (u != par) DFS(u, ver, cnt + 1);     Hash[ver] = ++m;     lev[Hash[ver]] = cnt;     parn[Hash[ver]] = par;     timein[Hash[ver]] = in;     timeout[Hash[ver]] = ti++;   }   bool isgra(int ver, int par) {     return (timein[par] <= timein[ver] && timeout[par] >= timeout[ver]);   }   unordered_map<int, unordered_map<int, int> > memo;   int com_par(int u, int v) {     if (isgra(v, u)) return u;     if (isgra(u, v)) return v;     auto it1 = memo.find(u);     if (it1 != memo.end()) {       auto it2 = it1->second.find(v);       if (it2 != it1->second.end()) return it2->second;     }     return memo[u][v] = memo[v][u] = com_par(u, parn[v]);   }   void build(int pos, int st, int en) {     if (st == en) {       segtree[pos] = st;       return;     }     build(2 * pos, st, (st + en) / 2);     build(2 * pos + 1, (st + en) / 2 + 1, en);     segtree[pos] = com_par(segtree[2 * pos], segtree[2 * pos + 1]);   }   int seg_com_par(int pos, int st, int en, int u, int v) {     if (en < u || st > v) return -1;     if (st >= u && en <= v) return segtree[pos];     int flag1 = seg_com_par(2 * pos, st, (st + en) / 2, u, v);     int flag2 = seg_com_par(2 * pos + 1, (st + en) / 2 + 1, en, u, v);     int res;     if (flag1 != -1 && flag2 != -1)       res = com_par(flag1, flag2);     else if (flag1 != -1)       res = flag1;     else       res = flag2;     return res;   }   int dis(int v, int u) {     if (u > v) swap(u, v);     return lev[v] + lev[u] - 2 * lev[seg_com_par(1, 1, m, u, v)];   }   int main() {     cin >> n;     int u, v;     for (int i = (1); i <= (n - 1); ++i) {       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     DFS(1, -1, 0);     parn[Hash[1]] = 1;     for (int i = (1); i <= (n); ++i) parn[i] = Hash[parn[i]];     build(1, 1, m);     int x, y, a, b, k, q;     cin >> q;     while (q--) {       scanf( %d%d%d%d%d , &x, &y, &a, &b, &k);       x = Hash[x];       y = Hash[y];       a = Hash[a];       b = Hash[b];       int flag = 0, ab = dis(a, b), axyb = 1 + dis(a, x) + dis(y, b),           ayxb = 1 + dis(a, y) + dis(x, b);       if (ab % 2 == k % 2 && ab <= k) flag = 1;       if (axyb % 2 == k % 2 && axyb <= k) flag = 1;       if (ayxb % 2 == k % 2 && ayxb <= k) flag = 1;       printf(flag ?  YES n  :  NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[501];   long long b[501];   long long dp[2][501][501];   int main() {     int n, k, m = 1000000007, i, j, l;     long long ans = 0;     scanf( %d %d , &n, &k);     a[0] = 1;     for (i = 1; i <= 500; i++) a[i] = a[i - 1] * 2 % m;     for (i = 1; i <= 500; i++) {       b[i] = a[i] - 1;       if (b[i] < 0) b[i] += m;     }     dp[1][0][0] = 1;     for (i = 1; i <= n; i++) {       for (j = 0; j <= k; j++) {         for (l = 0; l < i; l++) {           if (dp[i & 1][j][l] == 0) continue;           dp[(i + 1) & 1][j][l] =               (dp[(i + 1) & 1][j][l] + dp[i & 1][j][l] * a[l] % m) % m;           dp[(i + 1) & 1][j + 1][i] =               (dp[(i + 1) & 1][j + 1][i] +                dp[i & 1][j][l] * a[l] % m * b[i - l] % m) %               m;           dp[i & 1][j][l] = 0;         }       }     }     for (i = 0; i <= n; i++) ans += dp[(n + 1) & 1][k][i];     ans %= m;     printf( %I64d n , ans);     return 0;   }
#include <cmath>      #include <algorithm>   #include <iostream>   #include <string>   #include <vector>      using namespace std;      typedef long double ld;   typedef vector<int> vi;   typedef long long ll;      constexpr ld EPS = numeric_limits<ld>::epsilon();   constexpr int INF = numeric_limits<int>::max() - 10;   constexpr ll LINF = numeric_limits<ll>::max() - 10;      int w;   int h;   int n;      void input() {     cin >> w >> h >> n;   }      void solve() {     int alpha = (w & -w);     int beta = (h & -h);        string ans =  NO ;     if (alpha * beta >= n)       ans =  YES ;        cout << ans <<   n ;   }      int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);        cout.precision(16);     cout << fixed;        int _times = 1;      #ifdef _DEBUG     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   #endif        cin >> _times;        while (_times--) {       input();       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[n], b[m];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     int c[n];     for (int i = 0; i < n; i++) {       int check = a[i];       int j = 0;       for (; j < m; j++)         if (b[j] == check) {           c[i] = 1;           break;         }       if (j == m) c[i] = 0;     }     for (int i = 0; i < n; i++)       if (c[i] == 1) cout << a[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};   int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};   long long POW(long long x, long long y) {     long long ans = 1;     long long base = x;     while (y) {       if (y & 1) {         ans *= base;       }       base = base * base;       y = y >> 1;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, i, j, k, t, temp, tc;     cin >> tc;     while (tc--) {       cin >> n;       string a, b;       vector<long long> ans;       cin >> a >> b;       for (i = n - 1; i >= 0; i--) {         if (a[i] != b[i]) {           if (a[0] != b[i]) {             ans.push_back(i);           } else {             ans.push_back(0);             if (b[i] ==  1 ) {               a[0] =  0 ;             } else {               a[0] =  1 ;             }             ans.push_back(i);           }           for (j = 0; j <= i; j++) {             if (a[j] ==  1 ) {               a[j] =  0 ;             } else {               a[j] =  1 ;             }           }           long long lb = 0, ub = i;           while (lb < ub) {             auto ch = a[lb];             a[lb] = a[ub];             a[ub] = ch;             lb++;             ub--;           }         }       }       cout << ans.size() <<    ;       for (auto x : ans) {         cout << x + 1 <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inft = 1000000009;   const int MAXN = 400005, MAXM = MAXN;   int n;   vector<int> adj[MAXN];   int edgx[MAXM];   int cc;   int cycle[MAXM];   char used[MAXM];   int ep, sp, cur[MAXN], stackedge[MAXM];   void search(int v) {     sp = 0;     while (1) {       while (cur[v] != adj[v].size()) {         int e = adj[v][cur[v]++];         if (used[e]) continue;         used[e] = 1;         stackedge[sp++] = e;         v ^= edgx[e];       }       sp--;       if (sp < 0) break;       cycle[cc++] = stackedge[sp];       v ^= edgx[stackedge[sp]];     }   }   void search_all() {     for (int v = 0; v < (n); ++v) search(v);   }   void addedge(int a, int b) {     edgx[ep] = a ^ b;     adj[a].push_back(ep);     adj[b].push_back(ep);     ep++;   }   void clear() {     for (int i = 0; i < (n); ++i) adj[i].clear();     cc = 0;     ep = 0;     sp = 0;     for (int i = 0; i < (n); ++i) cur[i] = 0;   }   int X[MAXN], Y[MAXN];   char ANS[MAXN];   int main() {     int nn;     scanf( %d , &nn);     n = MAXN;     for (int i = 0; i < (nn); ++i) {       int a, b;       scanf( %d%d , &a, &b);       ++X[a];       ++Y[b];       addedge(a, b + MAXN / 2);     }     for (int i = 0; i < (MAXN / 2); ++i)       if (X[i] % 2) addedge(0, i);     for (int i = 0; i < (MAXN / 2); ++i)       if (Y[i] % 2) addedge(0, MAXN / 2 + i);     search_all();     for (int i = 0; i < (ep); ++i)       if (cycle[i] < nn) ANS[cycle[i]] = i % 2 ?  r  :  b ;     printf( %s n , ANS);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int b, w;     cin >> w >> b;     if (w == 0)       cout <<  0.000000000  << endl;     else if (b == 0)       cout <<  1.000000000  << endl;     else if (b == 1)       printf( %.9f n , double(w) / (w + 1));     else if (b == 2)       printf( %.9f n , double(w * (w + 1) + 2) / ((w + 1) * (w + 2)));     else {       double p[w + 1][b + 1];       if (b >= 2 * w) {         for (int col = b - 2 * w; col >= 0; col -= 3) p[0][col] = 0.0;         int startcol, endcol;         for (int row = 1; row <= w; row++) {           startcol = (b + w - row) % 3;           endcol = b - 2 * (w - row);           if (startcol == 0)             p[row][startcol] = 1.0;           else if (startcol == 1)             p[row][startcol] = double(row) / (row + 1);           else             p[row][startcol] =                 double(row * (row + 1) + 2) / ((row + 1) * (row + 2));           for (int col = startcol + 3; col <= endcol; col += 3) {             p[row][col] =                 double(row) / (row + col) +                 (p[row][col - 3] * (col - 2) + p[row - 1][col - 2] * row) * col *                     (col - 1) / (row + col) / (row + col - 1) / (row + col - 2);           }         }       } else {         int startcol, endcol;         int firstrow = w - b / 2;         for (int row = firstrow; row <= w; row++) {           startcol = (b + w - row) % 3;           endcol = b - 2 * (w - row);           if (startcol == 0)             p[row][startcol] = 1.0;           else if (startcol == 1)             p[row][startcol] = double(row) / (row + 1);           else             p[row][startcol] =                 double(row * (row + 1) + 2) / ((row + 1) * (row + 2));           for (int col = startcol + 3; col <= endcol; col += 3) {             p[row][col] =                 double(row) / (row + col) +                 (p[row][col - 3] * (col - 2) + p[row - 1][col - 2] * row) * col *                     (col - 1) / (row + col) / (row + col - 1) / (row + col - 2);           }         }       }       printf( %.9f n , p[w][b]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> s[100010];   bool flag[100010];   long double ans;   void dfs(int now, int deep) {     ans += 1.0 / (deep * 1.0);     flag[now] = false;     for (int i = 0; i < s[now].size(); i++) {       int next = s[now][i];       if (flag[next]) dfs(next, deep + 1);     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       s[x].push_back(y);       s[y].push_back(x);     }     memset(flag, true, sizeof(flag));     ans = 0;     dfs(1, 1);     cout << fixed << setprecision(6) << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, t, m;   int vi[200010];   vector<int> v[200010];   map<int, int> mp;   int main() {     long long int a, b, c, r, l = 0, tt;     cin >> r >> a >> b >> c;     if ((b - c) <= a) {       if (r >= b) {         tt = (long long int)((double)(r - b) / (double)(b - c));         t = tt++;         if (t == tt) {           t++;         }         r = r - t * (b - c);         l = l + t;         while (r >= b) {           r = r - (b - c);           l++;         }       }       if (r >= a) {         t = r / a;         r = r - t * a;         l = l + t;       }     } else {       if (r >= a) {         t = r / a;         r = r - t * a;         l = l + t;       }       if (r >= b) {         tt = (long long int)((double)(r - b) / (double)(b - c));         t = tt++;         if (t == tt) {           t++;         }         r = r - t * (b - c);         l = l + t;         while (r >= b) {           r = r - (b - c);           l++;         }       }     }     cout << l << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class UnionFind {    private:    public:     vector<int> p, rank, setSize, minn;     int numSets;     UnionFind(int N) {       setSize.assign(N, 1);       numSets = N;       rank.assign(N, 0);       p.assign(N, 0);       minn.resize(N);       for (int i = 0; i < N; i++) {         p[i] = i;         minn[i] = i;       }     }     int findSet(int i) {       if (p[i] == i)         return i;       else {         p[i] = findSet(p[i]);         minn[p[i]] = min(minn[p[i]], i);         return p[i];       }     }     bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }     void unionSet(int i, int j) {       if (!isSameSet(i, j)) {         numSets--;         int x = findSet(i), y = findSet(j);         if (rank[x] > rank[y]) {           p[y] = x;           setSize[x] += setSize[y];           minn[x] = min(minn[x], minn[y]);         } else {           p[x] = y;           setSize[y] += setSize[x];           minn[y] = min(minn[x], minn[y]);           if (rank[x] == rank[y]) rank[y]++;         }       }     }     int numDisjointSets() { return numSets; }     int sizeOfSet(int i) { return setSize[findSet(i)]; }   };   class fenwick_tree {     vector<long> t;     long size;       public:     fenwick_tree(long n) {       t.assign(n + 1, 0);       size = n + 1;     }     long LSOne(long k) { return k & (-k); }     void update(long index, long val) {       for (; index < size; index += LSOne(index)) t[index] += val;     }     long query_full(long a, long b) {       return query(b) - ((a <= 1) ? 0 : query(a - 1));     }     long query(long b) {       if (b < 1) return 0;       long sum = 0;       for (; b; b -= LSOne(b)) sum += t[b];       return sum;     }   };   long long gcd(long long a, long long b) {     while (b != 0) {       long long t = b;       b = a % b;       a = t;     }     return a;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long w, h, i, j, k, ans, c, s;     cin >> w >> h;     ans = 0;     for (i = 1; i < w; i++) {       c = min(i, w - i);       s = 0;       for (j = 0; j < h; j++) s += (h - j) / 2;       ans += c * s;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   const double EPS = 1e-10;   const double PI = 3.1415926535897932384626433832795;   const int CLK = CLOCKS_PER_SEC;   int calc(int s, int f, int t, int m) {     if (s == f) return 0;     s--;     f--;     t %= (2 * (m - 1));     int tos;     int stof;     bool up = (t < m - 1);     int pos = (t < m - 1) ? t : (2 * m - 2) - t;     if (up) {       if (s >= pos) {         tos = s - pos;       } else {         tos = (2 * m - 2) - pos - s;         up = false;       }     } else {       if (s <= pos) {         tos = pos - s;       } else {         tos = pos + s;         up = true;       }     }     pos = s;     if (up) {       if (f >= pos) {         stof = f - pos;       } else {         stof = (2 * m - 2) - pos - f;       }     } else {       if (f <= pos) {         stof = pos - f;       } else {         stof = pos + f;       }     }     return tos + stof;   }   int main() {     int n, m;     int s, f, t;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> s >> f >> t;       cout << calc(s, f, t, m) + t << endl;     }     return 0;   }
#include <bits/stdc++.h>   const double pi = acos(-1.0);   const int INF = 0x3f3f3f3f;   const double eps = 1e-8;   const int MAXN = 1e3 + 10;   const int mod = 1e9 + 7;   const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};   const int seed = 131;   int cases = 0;   char str[MAXN];   int mp[MAXN], col[MAXN], cnt[30], vis[MAXN], need[MAXN], ans[MAXN];   std::vector<int> primes, fac[MAXN], f[MAXN];   std::priority_queue<std::pair<int, int> > num;   std::vector<std::pair<int, int> > number_of_need;   void init() {     for (int i = 2; i < MAXN; i++)       if (!vis[i])         for (int j = i; j < MAXN; j += i) {           fac[j].push_back(i);           if (j != i) vis[j] = 1;         }     for (int i = 2; i < MAXN; i++)       if (!vis[i]) primes.push_back(i);   }   int find(int n) { return col[n] = n == col[n] ? n : find(col[n]); }   int main() {     init();     scanf( %s , str);     int len = strlen(str);     for (int i = 0; i < len; i++) cnt[str[i] -  a ]++;     for (int i = 0; i < 26; i++)       if (cnt[i]) num.push({cnt[i], i});     for (int i = 2; i <= len; i++) {       if ((int)fac[i].size() == 1)         col[i] = i;       else {         int v = find(fac[i][0]);         for (int j = 1; j < (int)fac[i].size(); j++) col[fac[i][j]] = v;       }     }     for (int pri : primes) {       if (pri > len) break;       find(pri);     }     for (int i = 2; i <= len; i++) f[col[fac[i][0]]].push_back(i);     for (int i = 2; i <= len; i++)       if (!f[i].empty()) {         if (num.empty() || num.top().first < (int)f[i].size()) {           puts( NO );           return 0;         }         std::pair<int, int> u = num.top();         num.pop();         for (int j : f[i]) str[j] = char(u.second +  a );         if (u.first - (int)f[i].size() > 0)           num.push({u.first - (int)f[i].size(), u.second});       }     if (num.empty()) {       puts( NO );       return 0;     }     str[1] = char(num.top().second +  a );     puts( YES );     printf( %s n , str + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   long long mod = 1000000007;   const int MX = 0x3f3f3f3f;   bool G[8][8];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     if (n <= 6) {       cout << m << endl;       return 0;     }     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       G[u][v] = G[v][u] = true;     }     int mini = INT_MAX;     for (int i = 1; i <= 7; i++) {       for (int j = 1; j <= 7; j++) {         if (j == i) continue;         int cur = 0;         for (int k = 1; k <= 7; k++) cur += G[i][k] & G[j][k];         mini = min(mini, cur);       }     }     cout << m - mini <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   int mod = 1e9 + 7;   int a, b, c, d, n, m, x, y, z;   vector<int> v;   int arr[3];   int main() {     cin >> a >> b >> c;     for (int i = 0; i <= a; i++) {       x = c - i;       y = b - (a - i);       if (x >= 0 && y >= 0 && x == y) {         cout << a - i <<     << x <<     << i << endl;         return 0;       }     }     cout <<  Impossible  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100001];   int main() {     int n, mini, temp;     cin >> n;     cin >> mini;     int minindex = 0, maxindex = 0, flag = 1;     for (int i = 1; i < n; i++) {       cin >> temp;       if (mini == temp) {         maxindex = i;         a[flag] = i;         flag++;       }       if (temp < mini) {         mini = temp;         minindex = i;         maxindex = i;         flag = 0;         a[flag] = i;         flag++;       }     }     sort(a, a + flag);     for (int i = 0; i < flag - 1; i++) a[i] = a[i + 1] - a[i];     temp = a[0];     for (int i = 1; i < flag - 1; i++) {       if (temp > a[i]) temp = a[i];     }     cout << temp;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int mod = 1e9 + 7;   const char nl =   n ;   const int N = int(2e5) + 99;   const int INF = int(1e9) + 99;   long long add(long long x, long long y) {     x += y;     if (x >= mod) return x - mod;     return x;   }   long long sub(long long x, long long y) {     x -= y;     if (x < 0) return x + mod;     return x;   }   long long mult(long long x, long long y) { return (x * y) % mod; }   long long bin_pow(long long x, long long p) {     if (p == 0) return 1;     if (p & 1) return mult(x, bin_pow(x, p - 1));     return bin_pow(mult(x, x), p / 2);   }   long long rev(long long x) { return bin_pow(x, mod - 2); }   long long gcd(long long x, long long y) { return (y == 0 ? x : gcd(y, x % y)); }   long long lcm(long long x, long long y) { return (x / gcd(x, y)) * y; }   string s, t;   int nxt[N][26];   void solve() {     int tc;     cin >> tc;     while (tc--) {       cin >> s >> t;       for (int i = 0; i < ((int)(s).size() + 5); i++) {         for (int j = 0; j < (26); j++) {           nxt[i][j] = INF;         }       }       for (int i = (int)(s).size() - 1; i >= 0; --i) {         for (int j = 0; j < (26); j++) {           nxt[i][j] = nxt[i + 1][j];         }         nxt[i][s[i] -  a ] = i;       }       int res = 1, pos = 0;       for (int i = 0; i < ((int)(t).size()); i++) {         if (pos == (int)(s).size()) {           pos = 0;           res++;         }         if (nxt[pos][t[i] -  a ] == INF) {           pos = 0;           ++res;         }         if (nxt[pos][t[i] -  a ] == INF && pos == 0) {           res = INF;           break;         }         pos = nxt[pos][t[i] -  a ] + 1;       }       if (res >= INF) {         cout << -1 << nl;       } else {         cout << res << nl;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline int read() {     int x = 0;     char ch = getchar();     bool positive = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) positive = 0;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     return positive ? x : -x;   }   inline void write(int a) {     if (a >= 10) write(a / 10);     putchar( 0  + a % 10);   }   inline void writeln(int a) {     if (a < 0) {       a = -a;       putchar( - );     }     write(a);     puts(  );   }   const int mod = 1000000007, rev = (mod + 1) / 2, N = 20;   int ans, n, bit[1 << N];   long long a[1 << N], ycl[21];   char ch[(1 << N) + 5];   void FWT(long long *a, int n) {     for (int k = 1; k < n; k <<= 1) {       for (int i = 0; i < n; i += k << 1) {         for (register int j = 0; j < k; j++) {           long long x = a[i + j];           a[i + j] = a[i + j] + a[i + j + k];           a[i + j + k] = x - a[i + j + k];         }       }     }   }   int main() {     n = read();     scanf( %s , ch);     for (int i = 0; i < (1 << n); i++) a[i] = ch[i] -  0 ;     FWT(a, 1 << n);     for (int i = 0; i < (1 << n); i++) a[i] = a[i] * a[i] % mod;     FWT(a, 1 << n);     ycl[0] = 1;     for (int i = 1; i <= n; i++) ycl[i] = ycl[i - 1] * rev % mod;     for (int i = 0; i < (1 << n); i++) {       bit[i] = bit[i >> 1] + (i & 1);       ans = (ans + a[i] % mod * ycl[bit[i]]) % mod;     }     cout << (long long)(ans + mod) % mod * 3 % mod << endl;   }