Codeforces 496B Secret Combination

Source: Internet
Author: User

Secret CombinationTime limit:2000MS Memory Limit:262144KB 64bit IO Format:%i64d &%i6 4u SubmitStatusPracticecodeforces 496B

Description

You got a box with a combination lock. The lock has a display showing  n  digits. There is and buttons on the box with each button changes digits on the display. You are 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 was currently showing Number 579, then if we push the Firs T button, the display would show 680, and if after that we push the second button, the Display would show 068.

Know that the lock would open if the display is showing the smallest possible number so can be obtained by pushing th e buttons in some order. The leading zeros is ignored while comparing numbers. Now your task was to find the desired number.

Input

The first line contains a single integer n (1≤ n ≤1000)-the number of digits on the display.

The second line contains n digits-the Initial state of the display.

Output

Print a single line containing n digits-the desired state of the display containing the smallest possible n Umber.

Sample Input

Input
3
579
Output
024
Input
4
2014
Output
0142
1#include <stdio.h>2#include <string.h>3 intMain ()4 {5     intN;6     inti,j,k;7     Chara[1005];8     intb[1005];9      while(SCANF ("%d", &n)! =EOF)Ten     { Oneb[0]=0; A          for(i=1;i< +; i++) -b[i]=9; -scanf"%s", a); the          for(i=0; i<n;i++) -         { -             intx='9'-a[i]+1; -              for(j=1; j<n;j++) +             { -                 intY= (a[(i+j)%n]-'0'+X)%Ten; +                 if(y<B[j]) A                 { at                      for(k=1; k<n;k++) -                     { -B[k]= (a[(i+k)%n]-'0'+X)%Ten; -                     } -                      Break; -                 } in                 Else if(y>B[j]) -                 { to                      Break; +                 } -             } the         } *          for(i=0; i<n;i++) $printf"%d", B[i]);Panax Notoginsengprintf"\ n"); -     } the     return 0; +}
View Code

Codeforces 496B Secret Combination

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.