496B.md (1445B)
1 Source: https://codeforces.com/problemset/problem/496/B 2 3 B. Secret Combination 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068. 22 23 You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number. 24 25 Input 26 27 The first line contains a single integer *n* (1 ≤ *n* ≤ 1000) — the number of digits on the display. 28 29 The second line contains *n* digits — the initial state of the display. 30 31 Output 32 33 Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. 34 35 Examples 36 37 Input 38 39 ``` 40 3 41 579 42 ``` 43 44 Output 45 46 ``` 47 024 48 ``` 49 50 Input 51 52 ``` 53 4 54 2014 55 ``` 56 57 Output 58 59 ``` 60 0142 61 ```