#include <bits/stdc++.h>
using std::max;
using std::min;
const int maxn = 9010;
const int maxm = 200010;
int n, k, p[1 << 20], a[1 << 20], id[1 << 20], cnt = 0;
int head[maxn], to[maxm << 1], next[maxm << 1], tot = -1;
int val[maxm << 1], cost[maxm << 1], dis[maxn], maxflow = 0, maxcost = 0;
bool vis[maxn], key[1 << 20];
inline int popcount(int x) {
  int res = 0;
  while (x) {
    x &= x - 1;
    ++res;
  }
  return res;
}
inline void add_edge(int u, int v, int w, int c) {
  to[++tot] = v;
  val[tot] = w, cost[tot] = c;
  next[tot] = head[u];
  head[u] = tot;
}
inline bool spfa(const int &S, const int &T) {
  std::queue<int> q;
  memset(dis, ~0x3f, sizeof(dis));
  q.push(S), dis[S] = 0;
  int u;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    vis[u] = false;
    for (int c = head[u], v; ~c; c = next[c]) {
      v = to[c];
      if (val[c] && dis[v] < dis[u] + cost[c]) {
        dis[v] = dis[u] + cost[c];
        if (!vis[v]) {
          vis[v] = true;
          q.push(v);
        }
      }
    }
  }
  return dis[T] > -0x3f3f3f3f;
}
int dfs(int u, int flow, const int &T) {
  if (u == T) return flow;
  vis[u] = true;
  int used = 0, cur;
  for (int c = head[u], v; ~c; c = next[c]) {
    v = to[c];
    if (val[c] && dis[v] == dis[u] + cost[c] && !vis[v]) {
      cur = dfs(v, min(flow - used, val[c]), T);
      maxcost += cur * cost[c];
      val[c] -= cur;
      val[c ^ 1] += cur;
      used += cur;
      if (used == flow) break;
    }
  }
  vis[u] = false;
  if (!used) dis[u] = 0x3f3f3f3f;
  return used;
}
inline void Dinic(int S, int T) {
  maxflow = 0, maxcost = 0;
  while (spfa(S, T)) maxflow += dfs(S, 0x3f3f3f3f, T);
}
int main() {
  scanf("%d%d", &n, &k);
  k = min(k, 1 << (n - 1));
  for (int i = 0; i < (1 << n); ++i) scanf("%d", a + i);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < (1 << n); ++j) p[j] = j;
    std::nth_element(p, p + 2 * k, p + (1 << n), [&](int x, int y) {
      return a[x] + a[x ^ (1 << i)] > a[y] + a[y ^ (1 << i)];
    });
    for (int j = 0; j < 2 * k; ++j) key[p[j]] = true;
  }
  for (int i = 0; i < (1 << n); ++i) {
    if (key[i]) id[i] = ++cnt;
  }
  int S = cnt + 2, T = cnt + 3;
  memset(head, -1, sizeof(head));
  add_edge(S, cnt + 1, k, 0), add_edge(cnt + 1, S, 0, 0);
  for (int i = 0; i < (1 << n); ++i) {
    if (!key[i]) continue;
    if (popcount(i) & 1) {
      add_edge(id[i], T, 1, a[i]);
      add_edge(T, id[i], 0, -a[i]);
    } else {
      add_edge(cnt + 1, id[i], 1, a[i]);
      add_edge(id[i], cnt + 1, 0, -a[i]);
    }
  }
  for (int i = 0; i < (1 << n); ++i) {
    if (!(key[i]) || (popcount(i) & 1)) continue;
    for (int j = 0; j < n; ++j) {
      if (!key[i ^ (1 << j)]) continue;
      add_edge(id[i], id[i ^ (1 << j)], 1, 0);
      add_edge(id[i ^ (1 << j)], id[i], 0, 0);
    }
  }
  Dinic(S, T);
  printf("%d\n", maxcost);
  return 0;
}

### Prompt

In cpp, your task is to solve the following problem:

There are currently n hot topics numbered from 0 to n-1 at your local bridge club and 2^n players numbered from 0 to 2^n-1. Each player holds a different set of views on those n topics, more specifically, the i-th player holds a positive view on the j-th topic if i\ \&\ 2^j > 0, and a negative view otherwise. Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND).

You are going to organize a bridge tournament capable of accommodating at most k pairs of players (bridge is played in teams of two people). You can select teams arbitrarily while each player is in at most one team, but there is one catch: two players cannot be in the same pair if they disagree on 2 or more of those n topics, as they would argue too much during the play.

You know that the i-th player will pay you a_i dollars if they play in this tournament. Compute the maximum amount of money that you can earn if you pair the players in your club optimally.

Input

The first line contains two integers n, k (1 ≤ n ≤ 20, 1 ≤ k ≤ 200) — the number of hot topics and the number of pairs of players that your tournament can accommodate.

The second line contains 2^n integers a_0, a_1, ..., a_{2^n-1} (0 ≤ a_i ≤ 10^6) — the amounts of money that the players will pay to play in the tournament.

Output

Print one integer: the maximum amount of money that you can earn if you pair the players in your club optimally under the above conditions.

Examples

Input


3 1
8 3 5 7 1 10 3 2


Output


13


Input


2 3
7 4 5 7


Output


23


Input


3 2
1 9 1 5 7 8 1 1


Output


29

Note

In the first example, the best we can do is to pair together the 0-th player and the 2-nd player resulting in earnings of 8 + 5 = 13 dollars. Although pairing the 0-th player with the 5-th player would give us 8 + 10 = 18 dollars, we cannot do this because those two players disagree on 2 of the 3 hot topics.

In the second example, we can pair the 0-th player with the 1-st player and pair the 2-nd player with the 3-rd player resulting in earnings of 7 + 4 + 5 + 7 = 23 dollars.

### Response

```cpp
#include <bits/stdc++.h>
using std::max;
using std::min;
const int maxn = 9010;
const int maxm = 200010;
int n, k, p[1 << 20], a[1 << 20], id[1 << 20], cnt = 0;
int head[maxn], to[maxm << 1], next[maxm << 1], tot = -1;
int val[maxm << 1], cost[maxm << 1], dis[maxn], maxflow = 0, maxcost = 0;
bool vis[maxn], key[1 << 20];
inline int popcount(int x) {
  int res = 0;
  while (x) {
    x &= x - 1;
    ++res;
  }
  return res;
}
inline void add_edge(int u, int v, int w, int c) {
  to[++tot] = v;
  val[tot] = w, cost[tot] = c;
  next[tot] = head[u];
  head[u] = tot;
}
inline bool spfa(const int &S, const int &T) {
  std::queue<int> q;
  memset(dis, ~0x3f, sizeof(dis));
  q.push(S), dis[S] = 0;
  int u;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    vis[u] = false;
    for (int c = head[u], v; ~c; c = next[c]) {
      v = to[c];
      if (val[c] && dis[v] < dis[u] + cost[c]) {
        dis[v] = dis[u] + cost[c];
        if (!vis[v]) {
          vis[v] = true;
          q.push(v);
        }
      }
    }
  }
  return dis[T] > -0x3f3f3f3f;
}
int dfs(int u, int flow, const int &T) {
  if (u == T) return flow;
  vis[u] = true;
  int used = 0, cur;
  for (int c = head[u], v; ~c; c = next[c]) {
    v = to[c];
    if (val[c] && dis[v] == dis[u] + cost[c] && !vis[v]) {
      cur = dfs(v, min(flow - used, val[c]), T);
      maxcost += cur * cost[c];
      val[c] -= cur;
      val[c ^ 1] += cur;
      used += cur;
      if (used == flow) break;
    }
  }
  vis[u] = false;
  if (!used) dis[u] = 0x3f3f3f3f;
  return used;
}
inline void Dinic(int S, int T) {
  maxflow = 0, maxcost = 0;
  while (spfa(S, T)) maxflow += dfs(S, 0x3f3f3f3f, T);
}
int main() {
  scanf("%d%d", &n, &k);
  k = min(k, 1 << (n - 1));
  for (int i = 0; i < (1 << n); ++i) scanf("%d", a + i);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < (1 << n); ++j) p[j] = j;
    std::nth_element(p, p + 2 * k, p + (1 << n), [&](int x, int y) {
      return a[x] + a[x ^ (1 << i)] > a[y] + a[y ^ (1 << i)];
    });
    for (int j = 0; j < 2 * k; ++j) key[p[j]] = true;
  }
  for (int i = 0; i < (1 << n); ++i) {
    if (key[i]) id[i] = ++cnt;
  }
  int S = cnt + 2, T = cnt + 3;
  memset(head, -1, sizeof(head));
  add_edge(S, cnt + 1, k, 0), add_edge(cnt + 1, S, 0, 0);
  for (int i = 0; i < (1 << n); ++i) {
    if (!key[i]) continue;
    if (popcount(i) & 1) {
      add_edge(id[i], T, 1, a[i]);
      add_edge(T, id[i], 0, -a[i]);
    } else {
      add_edge(cnt + 1, id[i], 1, a[i]);
      add_edge(id[i], cnt + 1, 0, -a[i]);
    }
  }
  for (int i = 0; i < (1 << n); ++i) {
    if (!(key[i]) || (popcount(i) & 1)) continue;
    for (int j = 0; j < n; ++j) {
      if (!key[i ^ (1 << j)]) continue;
      add_edge(id[i], id[i ^ (1 << j)], 1, 0);
      add_edge(id[i ^ (1 << j)], id[i], 0, 0);
    }
  }
  Dinic(S, T);
  printf("%d\n", maxcost);
  return 0;
}

```