Problem: The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.

Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.

Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests.

Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only.

The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command.

Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run:

  * all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; 
  * all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests. 

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of files with tests.

n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct.

Output

In the first line print the minimum number of lines in Vladimir's script file.

After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6.

Examples

Input

5
01 0
2 1
2extra 0
3 1
99 0


Output

4
move 3 1
move 01 5
move 2extra 4
move 99 3


Input

2
1 0
2 1


Output

3
move 1 3
move 2 1
move 3 2

Input

5
1 0
11 1
111 0
1111 1
11111 0


Output

5
move 1 5
move 11 1
move 1111 2
move 111 4
move 11111 3

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using vi = vector<lli>;
using vvi = vector<vi>;
using pii = tuple<lli, lli>;
using vii = vector<pii>;
using vvii = vector<vii>;
string TYPE(const int*) { return "%d"; }
string TYPE(const lli*) { return "%lld"; }
string TYPE(const char*) { return "%c"; }
string TYPE(const char**) { return "%s"; }
string TYPE(const unsigned int*) { return "%u"; }
const int MAX_BUF = 100 * 1000 + 42;
char buf[MAX_BUF];
void RD() {}
template <typename T, typename... Args>
void RD(T* v, Args... args) {
  scanf((" " + TYPE(v)).c_str(), v);
  RD(args...);
}
template <typename... Args>
void RD(string* v, Args... args) {
  scanf(" %s", buf);
  (*v) = buf;
  RD(args...);
}
void PR(bool nl = true) {
  if (nl) printf("\n");
}
template <typename T, typename... Args>
void PR(bool nl, T v, Args... args) {
  printf((TYPE(&v) + " ").c_str(), v);
  PR(nl, args...);
}
template <typename... Args>
void PR(bool nl, string& v, Args... args) {
  printf("%s", v.c_str());
  PR(nl, args...);
}
template <typename... Args>
void PR(Args... args) {
  PR(true, args...);
}
const long long int oo = 1000 * 1000 * 1000;
struct Coord {
  int x, y;
  Coord(int x = 0, int y = 0) : x(x), y(y) {}
  Coord operator+(const Coord& droite) const {
    return Coord(x + droite.x, y + droite.y);
  }
};
struct AB {
  int k;
  vector<lli> arbre;
  AB(int _k = 20, lli def = 0) {
    k = _k;
    for (lli i = 0; i < (lli)(1 << k); ++i)
      arbre.push_back(i < (1 << (k - 1)) ? 0LL : def);
    for (lli i = (((1 << (k - 1)) - 1)); i >= (lli)(1); --i)
      arbre[i] = arbre[i << 1] + arbre[(i << 1) ^ 1];
  }
  void set(int i, lli x) {
    int feuille = i + (1 << (k - 1));
    arbre[feuille] = x;
    iset(feuille >> 1);
  }
  void iset(int noeud) {
    if (noeud) {
      arbre[noeud] = arbre[noeud << 1] + arbre[(noeud << 1) ^ 1];
      iset(noeud >> 1);
    }
  }
  lli sum(int deb, int fin, int noeud = 1, int p = 0, int q = -1) {
    if (q < p) q = 1 << (k - 1);
    if (deb <= p && q <= fin) return arbre[noeud];
    if (deb >= q || fin <= p) return 0LL;
    int mil = (p + q) / 2;
    return sum(deb, fin, noeud << 1, p, mil) +
           sum(deb, fin, (noeud << 1) ^ 1, mil, q);
  }
};
char buff[42];
set<int> fin[2];
string tmp[2][100 * 1000 + 42];
set<int> swp[2];
set<string> wait[2];
int nb[2];
set<int> dispo;
bool isInt(string s) {
  if (s == "0") return true;
  if (s[0] < '1' || s[0] > '9') return false;
  for (lli i = (1); i <= (lli)(s.length() - 1); ++i)
    if (s[i] < '0' || s[i] > '9') return false;
  return true;
}
vector<string> op;
int main() {
  int n, e = 0;
  RD(&n);
  for (lli i = 0; i < (lli)(n); ++i) {
    int ty;
    scanf(" %s%d", buff, &ty);
    e += ty;
    tmp[ty][nb[ty]++] = buff;
  }
  for (lli i = (1); i <= (lli)(n); ++i) fin[i <= e].insert(i);
  dispo.insert(0);
  for (lli i = (n + 1); i <= (lli)(1E6 - 1); ++i) dispo.insert(i);
  for (lli i = 0; i < (lli)(2); ++i)
    for (lli j = 0; j < (lli)(nb[i]); ++j)
      if (isInt(tmp[i][j])) {
        int x = stoi(tmp[i][j]);
        if (0 < x && x <= e) {
          fin[1].erase(x);
          if (!i) swp[0].insert(x);
        } else if (x <= n) {
          fin[0].erase(x);
          if (i) swp[1].insert(x);
        } else {
          dispo.erase(x);
          wait[i].insert(tmp[i][j]);
        }
      } else
        wait[i].insert(tmp[i][j]);
  for (lli i = 0; i < (lli)(n); ++i)
    for (lli j = 0; j < (lli)(2); ++j) {
      if (fin[j].size() && swp[j].size()) {
        int x = *fin[j].begin();
        int y = *swp[j].begin();
        op.push_back(to_string(y) + " " + to_string(x));
        fin[j].erase(x);
        swp[j].erase(y);
        fin[!j].insert(y);
      }
    }
  if (swp[0].size()) {
    assert(swp[0].size() > 0);
    assert(swp[1].size() > 0);
    int x = *dispo.begin();
    int y = *swp[0].begin();
    op.push_back(to_string(y) + " " + to_string(x));
    dispo.erase(x);
    swp[0].erase(y);
    wait[0].insert(to_string(x));
    fin[1].insert(y);
    for (lli i = 0; i < (lli)(n); ++i)
      for (lli j = 0; j < (lli)(2); ++j) {
        if (fin[j].size() && swp[j].size()) {
          int x = *fin[j].begin();
          int y = *swp[j].begin();
          op.push_back(to_string(y) + " " + to_string(x));
          fin[j].erase(x);
          swp[j].erase(y);
          fin[!j].insert(y);
        }
      }
  }
  for (lli i = 0; i < (lli)(2); ++i) {
    int m = wait[i].size();
    for (lli j = 0; j < (lli)(m); ++j) {
      int x = *fin[i].begin();
      string y = *wait[i].begin();
      op.push_back(y + " " + to_string(x));
      fin[i].erase(x);
      wait[i].erase(y);
    }
  }
  PR((int)op.size());
  for (auto o : op) printf("move %s\n", o.c_str());
  return 0;
}