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;
const int MOD = 1000000007;
void yes() {
  cout << "Yes"
       << "\n";
}
void no() {
  cout << "No"
       << "\n";
}
struct Sync_stdio {
  Sync_stdio() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
  }
} _sync_stdio;
struct FAIL {
  FAIL() {
    cout << "CHANGE!!!"
         << "\n";
  }
};
struct Z {
  int number;
  string data;
  int is_sample;
  int operator==(const Z &other) const {
    return make_tuple(number, data, is_sample) ==
           make_tuple(other.number, other.data, other.is_sample);
  }
};
int get(const string &x, int n) {
  if (x[0] == '0' && x.size() > 1) {
    return -1;
  }
  int res = 0;
  for (int i = (0); i < (x.size()); ++i) {
    res *= 10;
    if (!('0' <= x[i] && x[i] <= '9')) {
      return -1;
    }
    res += x[i] - '0';
  }
  if (!(1 <= res && res <= n)) {
    return -1;
  }
  return res;
}
Z BAD = {-2, "", -2};
int main() {
  srand(12);
  int n;
  cin >> n;
  vector<Z> v(n);
  int samples = 0;
  for (int i = (0); i < (n); ++i) {
    cin >> v[i].data >> v[i].is_sample;
    v[i].number = get(v[i].data, n);
    samples += v[i].is_sample;
  }
  vector<Z> used(n + 1, BAD);
  vector<Z> other;
  int flag = 0;
  for (int i = (0); i < (n); ++i) {
    if (v[i].number != -1) {
      used[v[i].number] = v[i];
    } else {
      other.push_back(v[i]);
      flag = 1;
    }
  }
  vector<pair<string, string>> res;
  int j = 1;
  int k = samples + 1;
  while (j <= samples) {
    while (j <= samples && !(used[j] == BAD)) {
      ++j;
    }
    while (k <= n && used[k].is_sample != 1) {
      ++k;
    }
    if (j <= samples && k <= n) {
      res.push_back({to_string(k), to_string(j)});
      swap(used[j], used[k]);
    }
    ++j;
    ++k;
  }
  j = 1;
  k = samples + 1;
  while (j <= samples) {
    while (j <= samples && used[j].is_sample != 0) {
      ++j;
    }
    while (k <= n && !(used[k] == BAD)) {
      ++k;
    }
    if (j <= samples && k <= n) {
      res.push_back({to_string(j), to_string(k)});
      swap(used[j], used[k]);
    }
    ++j;
    ++k;
  }
  j = 1;
  k = samples + 1;
  while (other.size() > 1) {
    if (other.back().is_sample == 1) {
      while (j <= samples && !(used[j] == BAD)) {
        ++j;
      }
      assert(j != samples + 1);
      res.push_back({other.back().data, to_string(j)});
      used[j] = other.back();
      other.pop_back();
    } else {
      while (k <= n && !(used[k] == BAD)) {
        ++k;
      }
      assert(k != n + 1);
      res.push_back({other.back().data, to_string(k)});
      used[k] = other.back();
      other.pop_back();
    }
  }
  int f = 0;
  int free_mem = -1;
  if (!flag) {
    for (int i = (1); i < (n + 1); ++i) {
      if (((i <= samples) ^ used[i].is_sample)) {
        v[i].number = -1;
        v[i].data = "a";
        other.push_back(v[i]);
        used[i] = BAD;
        res.push_back({to_string(i), "a"});
        f = 1;
        free_mem = i;
        break;
      }
    }
    if (!f) {
      cout << 0;
      return 0;
    }
  } else {
    for (int i = (1); i < (n + 1); ++i) {
      if (used[i] == BAD) {
        free_mem = i;
        break;
      }
    }
  }
  j = 1;
  k = samples + 1;
  while (1) {
    if (free_mem <= samples) {
      while (k <= n && used[k].is_sample != 1) {
        ++k;
      }
      if (k == n + 1) {
        res.push_back({other.back().data, to_string(free_mem)});
        used[free_mem] = other.back();
        other.pop_back();
        break;
      } else {
        res.push_back({to_string(k), to_string(free_mem)});
        swap(used[k], used[free_mem]);
        free_mem = k;
      }
    } else {
      while (j <= samples && used[j].is_sample != 0) {
        ++j;
      }
      if (j == samples + 1) {
        res.push_back({other.back().data, to_string(free_mem)});
        used[free_mem] = other.back();
        other.pop_back();
        break;
      } else {
        res.push_back({to_string(j), to_string(free_mem)});
        swap(used[j], used[free_mem]);
        free_mem = j;
      }
    }
  }
  cout << res.size() << "\n";
  for (int i = (0); i < (res.size()); ++i) {
    cout << "move " << res[i].first << " " << res[i].second << "\n";
  }
  return 0;
}