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>
#pragma GCC optimize("O3")
const double PI = acos(-1);
using namespace std;
const int MAX = 100 * 1000 + 10;
char buffer[10];
string name[MAX];
int type[MAX], n, e;
vector<pair<string, string> > ans;
bool read_num(const string& s, int& x) {
  x = 0;
  for (char c : s) {
    if ('0' <= c && c <= '9')
      x = x * 10 + c - '0';
    else
      return 0;
  }
  if (x == 0 && ((int)s.size()) != 1) return 0;
  if (s[0] == '0') return 0;
  return 1;
}
int get_num(const string& s) {
  int x;
  assert(read_num(s, x));
  return x;
}
void do_count(int target, int s, int e, vector<int>& inRange,
              vector<int>& inOtherRange, vector<int>& other) {
  for (int i = 0; i < (n); i++) {
    if (type[i] == target) {
      int x;
      if (read_num(name[i], x)) {
        if (s <= x && x <= e)
          inRange.push_back(i);
        else if (x > n)
          other.push_back(i);
        else
          inOtherRange.push_back(i);
      } else
        other.push_back(i);
    }
  }
  sort(inRange.begin(), inRange.end(), [](const int& a, const int& b) {
    return get_num(name[a]) < get_num(name[b]);
  });
  sort(inOtherRange.begin(), inOtherRange.end(),
       [](const int& a, const int& b) {
         return get_num(name[a]) < get_num(name[b]);
       });
}
void get_free(set<int>& S, int s, int e, vector<int>& A, vector<int>& B) {
  for (int i = (s); i <= (e); i++) S.insert(i);
  for (int x : A) {
    auto p = S.find(get_num(name[x]));
    assert(p != S.end());
    S.erase(p);
  }
  for (int x : B) {
    auto p = S.find(get_num(name[x]));
    assert(p != S.end());
    S.erase(p);
  }
}
bool work(set<int>& S, vector<int>& A, vector<int>& B, set<int>& O,
          bool yes = 0) {
  bool ret = 0;
  while (!A.empty() && !S.empty()) {
    int x = A.back();
    A.pop_back();
    ans.push_back(make_pair(name[x], to_string(*S.begin())));
    O.insert(get_num(name[x]));
    S.erase(S.begin());
    ret = 1;
  }
  if (yes) {
    while (!B.empty() && !S.empty()) {
      int x = B.back();
      B.pop_back();
      ans.push_back(make_pair(name[x], to_string(*S.begin())));
      S.erase(S.begin());
      ret = 1;
    }
  }
  return ret;
}
string get_aux() {
  set<int> S;
  for (int i = 0; i < (n); i++) {
    int x;
    if (read_num(name[i], x)) {
      S.insert(x);
    }
  }
  int i;
  for (i = n + 1;; i++)
    if (S.find(i) == S.end()) break;
  return to_string(i);
}
void work2(vector<int>& A, vector<int>& B) {
  assert(((int)A.size()) == ((int)B.size()));
  if (A.empty()) return;
  string aux = get_aux();
  int x = A.back(), y, pos = 0;
  A.pop_back();
  ans.push_back(make_pair(name[x], aux));
  while (!A.empty() || !B.empty()) {
    if (pos == 0) {
      y = B.back();
      B.pop_back();
    } else {
      y = A.back();
      A.pop_back();
    }
    ans.push_back(make_pair(name[y], name[x]));
    x = y;
    pos ^= 1;
  }
  ans.push_back(make_pair(aux, name[x]));
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) {
    scanf("%s %d", buffer, type + i);
    e += type[i];
    name[i] = string(buffer);
  }
  vector<int> AinRange, AinOtherRange, Aother;
  vector<int> BinRange, BinOtherRange, Bother;
  do_count(1, 1, e, AinRange, AinOtherRange, Aother);
  do_count(0, e + 1, n, BinRange, BinOtherRange, Bother);
  set<int> up, down;
  get_free(up, 1, e, AinRange, BinOtherRange);
  get_free(down, e + 1, n, BinRange, AinOtherRange);
  while (work(up, AinOtherRange, Aother, down) ||
         work(down, BinOtherRange, Bother, up))
    ;
  work(up, AinOtherRange, Aother, down, 1);
  work(down, BinOtherRange, Bother, up, 1);
  work2(AinOtherRange, BinOtherRange);
  assert(AinOtherRange.empty());
  assert(Aother.empty());
  assert(BinOtherRange.empty());
  assert(Bother.empty());
  printf("%d\n", ((int)ans.size()));
  for (auto p : ans) printf("move %s %s\n", p.first.c_str(), p.second.c_str());
  return 0;
}