E. Tests Renumeration

Codeforces
IDCF858E
Time2000ms
Memory256MB
Difficulty
greedyimplementation
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. [samples]
Samples
Input #1
5
01 0
2 1
2extra 0
3 1
99 0
Output #1
4
move 3 1
move 01 5
move 2extra 4
move 99 3
Input #2
2
1 0
2 1
Output #2
3
move 1 3
move 2 1
move 3 2
Input #3
5
1 0
11 1
111 0
1111 1
11111 0
Output #3
5
move 1 5
move 11 1
move 1111 2
move 111 4
move 11111 3
API Response (JSON)
{
  "problem": {
    "name": "E. Tests Renumeration",
    "description": {
      "content": "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 O",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF858E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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.\n\nUnfortunately, the archive with O...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments