#include <stdio.h> #include <string.h> #define MAX 0x7fffffff #define M 300002 char id[M]; void run() { } int getmin(char * pat,int len) { int i=0,j=1,k=0; while(i<len && j<len && k<len) { int t = pat[(i+k)%len] - pat[(j+k)%len]; if(t == 0) { k++; } else { if(t > 0) i += k+1; else j += k+1; if(i == j) j++; k = 0 ; } } return i<j ? i : j; } int main(int argc, char *argv[]) { #ifdef __LOCAL freopen("in.txt","r",stdin); #endif while(scanf("%s",id) != EOF) { int len = strlen(id); char id0 = id[0]; for(int i=0;i<len-1;i++) { id[i] = id[i+1]>=id[i] ? id[i+1]-id[i]+'0' : 8-(id[i]-id[i+1])+'0'; } id[i] = id0>=id[i] ? id0-id[i]+'0' : 8-(id[i]-id0)+'0'; int minstart = getmin(id,len); printf("%s",id+minstart); id[minstart] = '\0'; printf("%s\n",id); } return 0; }