import std.cstream;void main(){foreach(char[]s;din){char[][]t;foreach(i,q;s)t~=s[i..$]~s[0..i];int j;for(t.sort;t[j]!=s;)j++;dout.writef(j," ");foreach(r;t~=" ")dout.write=r[$-1];}}
Note that non-ascii characters in the above source code will be escaped (such as \x9f).