{"trustable":true,"prependHtml":"\u003cstyle type\u003d\"text/css\"\u003e\n section pre {\n display: block;\n padding: 9.5px;\n margin: 0 0 10px;\n font-size: 13px;\n line-height: 1.42857143;\n word-break: break-all;\n word-wrap: break-word;\n color: #333;\n background: rgba(255, 255, 255, 0.5);\n border: 1px solid #ccc;\n border-radius: 6px;\n }\n\u003c/style\u003e\n\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n {left: \u0027\\\\[\u0027, right: \u0027\\\\]\u0027, display: true}\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"Problem Statement","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eOn a non-empty string, a \u003cstrong\u003eleft shift\u003c/strong\u003e moves the first character to the end of the string, and a \u003cstrong\u003eright shift\u003c/strong\u003e moves the last character to the beginning of the string.\u003c/p\u003e\r\n\u003cp\u003eFor example, a left shift on \u003ccode\u003eabcde\u003c/code\u003e results in \u003ccode\u003ebcdea\u003c/code\u003e, and two right shifts on \u003ccode\u003eabcde\u003c/code\u003e result in \u003ccode\u003edeabc\u003c/code\u003e.\u003c/p\u003e\r\n\u003cp\u003eYou are given a non-empty \u003cvar\u003e\\(S\\)\u003c/var\u003e consisting of lowercase English letters. Among the strings that can be obtained by performing zero or more left shifts and zero or more right shifts on \u003cvar\u003e\\(S\\)\u003c/var\u003e, find the lexicographically smallest string and the lexicographically largest string.\u003c/p\u003e\r\n\u003cdetails\u003e\r\n\u003csummary\u003eWhat is the lexicographical order?\u003c/summary\u003e\r\n\u003cp\u003e\r\nSimply speaking, the lexicographical order is the order in which words are listed in a dictionary. As a more formal definition, here is the algorithm to determine the lexicographical order between different strings \u003cvar\u003e\\(S\\)\u003c/var\u003e and \u003cvar\u003e\\(T\\)\u003c/var\u003e.\r\n\u003c/p\u003e\r\n\r\n\u003cp\u003eBelow, let \u003cvar\u003e\\(S_i\\)\u003c/var\u003e denote the \u003cvar\u003e\\(i\\)\u003c/var\u003e-th character of \u003cvar\u003e\\(S\\)\u003c/var\u003e. Also, if \u003cvar\u003e\\(S\\)\u003c/var\u003e is lexicographically smaller than \u003cvar\u003e\\(T\\)\u003c/var\u003e, we will denote that fact as \u003cvar\u003e\\(S \\lt T\\)\u003c/var\u003e; if \u003cvar\u003e\\(S\\)\u003c/var\u003e is lexicographically larger than \u003cvar\u003e\\(T\\)\u003c/var\u003e, we will denote that fact as \u003cvar\u003e\\(S \\gt T\\)\u003c/var\u003e.\u003c/p\u003e\r\n\r\n\u003col\u003e\r\n \u003cli\u003e Let \u003cvar\u003e\\(L\\)\u003c/var\u003e be the smaller of the lengths of \u003cvar\u003e\\(S\\)\u003c/var\u003e and \u003cvar\u003e\\(T\\)\u003c/var\u003e. For each \u003cvar\u003e\\(i\u003d1,2,\\dots,L\\)\u003c/var\u003e, we check whether \u003cvar\u003e\\(S_i\\)\u003c/var\u003e and \u003cvar\u003e\\(T_i\\)\u003c/var\u003e are the same. \u003c/li\u003e\r\n \u003cli\u003e If there is an \u003cvar\u003e\\(i\\)\u003c/var\u003e such that \u003cvar\u003e\\(S_i \\neq T_i\\)\u003c/var\u003e, let \u003cvar\u003e\\(j\\)\u003c/var\u003e be the smallest such \u003cvar\u003e\\(i\\)\u003c/var\u003e. Then, we compare \u003cvar\u003e\\(S_j\\)\u003c/var\u003e and \u003cvar\u003e\\(T_j\\)\u003c/var\u003e. If \u003cvar\u003e\\(S_j\\)\u003c/var\u003e comes earlier than \u003cvar\u003e\\(T_j\\)\u003c/var\u003e in alphabetical order, we determine that \u003cvar\u003e\\(S \\lt T\\)\u003c/var\u003e and quit; if \u003cvar\u003e\\(S_j\\)\u003c/var\u003e comes later than \u003cvar\u003e\\(T_j\\)\u003c/var\u003e, we determine that \u003cvar\u003e\\(S \\gt T\\)\u003c/var\u003e and quit.\r\n \u003c/li\u003e\r\n \u003cli\u003e If there is no \u003cvar\u003e\\(i\\)\u003c/var\u003e such that \u003cvar\u003e\\(S_i \\neq T_i\\)\u003c/var\u003e, we compare the lengths of \u003cvar\u003e\\(S\\)\u003c/var\u003e and \u003cvar\u003e\\(T\\)\u003c/var\u003e. If \u003cvar\u003e\\(S\\)\u003c/var\u003e is shorter than \u003cvar\u003e\\(T\\)\u003c/var\u003e, we determine that \u003cvar\u003e\\(S \\lt T\\)\u003c/var\u003e and quit; if \u003cvar\u003e\\(S\\)\u003c/var\u003e is longer than \u003cvar\u003e\\(T\\)\u003c/var\u003e, we determine that \u003cvar\u003e\\(S \\gt T\\)\u003c/var\u003e and quit. \u003c/li\u003e\r\n\u003c/ol\u003e\r\n\r\n\u003c/details\u003e\r\n\r\n\u003c/section\u003e\r\n"}},{"title":"Constraints","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cul\u003e\r\n\u003cli\u003e\u003cvar\u003e\\(S\\)\u003c/var\u003e consists of lowercase English letters.\u003c/li\u003e\r\n\u003cli\u003eThe length of \u003cvar\u003e\\(S\\)\u003c/var\u003e is between \u003cvar\u003e\\(1\\)\u003c/var\u003e and \u003cvar\u003e\\(1000\\)\u003c/var\u003e (inclusive).\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Input","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003eInput is given from Standard Input in the following format:\u003c/p\u003e\r\n\u003cpre\u003e\u003cvar\u003e\\(S\\)\u003c/var\u003e\r\n\u003c/pre\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Output","value":{"format":"HTML","content":"\r\n\u003csection\u003e\r\n\u003cp\u003ePrint two lines. The first line should contain \u003cvar\u003e\\(S_{\\min}\\)\u003c/var\u003e, and the second line should contain \u003cvar\u003e\\(S_{\\max}\\)\u003c/var\u003e. Here, \u003cvar\u003e\\(S_{\\min}\\)\u003c/var\u003e and \u003cvar\u003e\\(S_{\\max}\\)\u003c/var\u003e are respectively the lexicographically smallest and largest strings obtained by performing zero or more left shifts and zero or more right shifts on \u003cvar\u003e\\(S\\)\u003c/var\u003e.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 1","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003eaaba\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eaaab\r\nbaaa\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\u003cp\u003eBy performing shifts, we can obtain four strings: \u003ccode\u003eaaab\u003c/code\u003e, \u003ccode\u003eaaba\u003c/code\u003e, \u003ccode\u003eabaa\u003c/code\u003e, \u003ccode\u003ebaaa\u003c/code\u003e. The lexicographically smallest and largest among them are \u003ccode\u003eaaab\u003c/code\u003e and \u003ccode\u003ebaaa\u003c/code\u003e, respectively.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 2","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003ez\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003ez\r\nz\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\r\n\u003cp\u003eAny sequence of operations results in \u003ccode\u003ez\u003c/code\u003e.\u003c/p\u003e\r\n\u003c/section\u003e\r\n"}},{"title":"Sample 3","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003eabracadabra\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eaabracadabr\r\nracadabraab\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n\u003csection\u003e\r\n\r\n\u003c/section\u003e\r\n\r\n\u003csection\u003e\r\n\u003c/section\u003e\r\n"}}]}