codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

569B.md (2092B)


      1 Source: https://codeforces.com/problemset/problem/569/B
      2 
      3 B. Inventory
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.
     22 
     23 During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering.
     24 
     25 You have been given information on current inventory numbers for *n* items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to *n* by changing the number of as few items as possible. Let us remind you that a set of *n* numbers forms a permutation if all the numbers are in the range from 1 to *n*, and no two numbers are equal.
     26 
     27 Input
     28 
     29 The first line contains a single integer *n* — the number of items (1 ≤ *n* ≤ 105).
     30 
     31 The second line contains *n* numbers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 105) — the initial inventory numbers of the items.
     32 
     33 Output
     34 
     35 Print *n* numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 3  
     43 1 3 2
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 1 3 2
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 4  
     56 2 2 3 3
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 2 1 3 4
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 1  
     69 2
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 1
     76 ```
     77 
     78 Note
     79 
     80 In the first test the numeration is already a permutation, so there is no need to change anything.
     81 
     82 In the second test there are two pairs of equal numbers, in each pair you need to replace one number.
     83 
     84 In the third test you need to replace 2 by 1, as the numbering should start from one.