Problem: A Christmas party in city S. had n children. All children came in mittens. The mittens can be of different colors, but each child had the left and the right mitten of the same color. Let's say that the colors of the mittens are numbered with integers from 1 to m, and the children are numbered from 1 to n. Then the i-th child has both mittens of color ci.

The Party had Santa Claus ('Father Frost' in Russian), his granddaughter Snow Girl, the children danced around the richly decorated Christmas tree. In fact, everything was so bright and diverse that the children wanted to wear mittens of distinct colors. The children decided to swap the mittens so that each of them got one left and one right mitten in the end, and these two mittens were of distinct colors. All mittens are of the same size and fit all the children.

The children started exchanging the mittens haphazardly, but they couldn't reach the situation when each child has a pair of mittens of distinct colors. Vasily Petrov, the dad of one of the children, noted that in the general case the children's idea may turn out impossible. Besides, he is a mathematician and he came up with such scheme of distributing mittens that the number of children that have distinct-colored mittens was maximum. You task is to repeat his discovery. Note that the left and right mittens are different: each child must end up with one left and one right mitten.

Input

The first line contains two integers n and m — the number of the children and the number of possible mitten colors (1 ≤ n ≤ 5000, 1 ≤ m ≤ 100). The second line contains n integers c1, c2, ... cn, where ci is the color of the mittens of the i-th child (1 ≤ ci ≤ m).

Output

In the first line, print the maximum number of children who can end up with a distinct-colored pair of mittens. In the next n lines print the way the mittens can be distributed in this case. On the i-th of these lines print two space-separated integers: the color of the left and the color of the right mitten the i-th child will get. If there are multiple solutions, you can print any of them.

Examples

Input

6 3
1 3 2 2 1 1


Output

6
2 1
1 2
2 1
1 3
1 2
3 1


Input

4 2
1 2 1 1


Output

2
1 2
1 1
2 1
1 1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int v, u, c, f, r;
  Edge(){};
  Edge(int v, int u, int c, int f, int r) : v(v), u(u), c(c), f(f), r(r){};
};
const int N = 5020, inf = 1000000000;
Edge g[301][301];
int n, m, sz[N], s, t, c[N], p[301][5001], kol1[5001], kol2[5001], kol[5001];
void add_edge(int a, int b, int u, int c) {
  Edge e1(b, u, c, 0, sz[b]), e2(a, 0, -c, 0, sz[a]);
  g[a][sz[a]++] = e1;
  g[b][sz[b]++] = e2;
}
int MinCostFlow() {
  int dist[N], p[N], pr[N], pl[N], flow = 0, cost = 0, nv = t;
  bool used[N];
  memset(pl, 0, sizeof(pl));
  while (true) {
    memset(used, false, sizeof(used));
    for (int i = 1; i <= nv; i++) dist[i] = inf;
    dist[s] = 0;
    while (true) {
      int v, d = inf;
      for (int i = 1; i <= nv; i++)
        if (!used[i] && dist[i] < d) {
          v = i;
          d = dist[i];
        }
      if (d == inf) break;
      used[v] = true;
      for (int i = 0; i <= sz[v] - 1; i++)
        if (g[v][i].f < g[v][i].u &&
            dist[g[v][i].v] > d + pl[v] - pl[g[v][i].v] + g[v][i].c) {
          dist[g[v][i].v] = d + pl[v] - pl[g[v][i].v] + g[v][i].c;
          p[g[v][i].v] = v;
          pr[g[v][i].v] = i;
        }
    }
    if (dist[t] == inf) break;
    int v = t, addflow = inf;
    while (v != s) {
      int u = p[v], j = pr[v];
      addflow = min(addflow, g[u][j].u - g[u][j].f);
      v = u;
    }
    v = t;
    while (v != s) {
      int u = p[v], j = pr[v];
      g[u][j].f += addflow;
      g[v][g[u][j].r].f -= addflow;
      v = u;
    }
    for (int i = 1; i <= nv; i++) pl[i] += dist[i];
    for (int i = 1; i <= nv; i++) pl[i] = max(pl[i], -inf);
    for (int i = 1; i <= nv; i++) pl[i] = min(pl[i], inf);
    flow += addflow;
  }
  return flow;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> c[i];
  memset(kol, 0, sizeof(kol));
  memset(sz, 0, sizeof(sz));
  for (int i = 1; i <= n; i++) kol[c[i]]++;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= m; j++)
      if (i != j) {
        add_edge(i, j + m, inf, 1);
      }
  s = 2 * m + 1;
  t = 2 * m + 2;
  for (int i = 1; i <= m; i++) add_edge(s, i, kol[i], 1);
  for (int i = 1; i <= m; i++) add_edge(i + m, t, kol[i], 1);
  int ans = MinCostFlow();
  cout << ans << endl;
  memset(kol1, 0, sizeof(kol1));
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j <= sz[i] - 1; j++) {
      if (g[i][j].f > 0 && g[i][j].v <= 2 * m) {
        for (int r = 1; r <= g[i][j].f; r++) {
          kol1[i]++;
          p[i][kol1[i]] = g[i][j].v - m;
        }
      }
    }
  }
  memset(kol2, 0, sizeof(kol2));
  for (int i = 1; i <= n; i++) {
    kol2[c[i]]++;
    if (kol2[c[i]] > kol1[c[i]]) {
      cout << c[i] << " " << c[i] << endl;
      continue;
    }
    cout << c[i] << " " << p[c[i]][kol2[c[i]]] << endl;
  }
  return 0;
}