{$APPTYPE CONSOLE}
type Tstr=array [1..10000] of char;
var ms,s:Tstr;
    p,l,ls,i:longint;
    ch:char;

function max(x,y:longint):longint;
begin
    if x>y then max:=x else max:=y;
end;

function br(n:longint; var s:Tstr; var ls:longint):longint;
var d,lssub:array[0..10] of longint;
    ssub:array[0..10] of Tstr;
    i,mind,b,bb,depth,j,j1:longint;

begin
    dec(p);
    i:=0;
    while i<=n-1 do begin
        if ms[p]='a' then begin
            d[i]:=1;
            ssub[i,1]:='a';
            lssub[i]:=1;
            dec(p);
        end
        else begin d[i]:=br(ord(ms[p])-ord('0'),ssub[i],lssub[i]); end;
        inc(i);
    end;
    mind:=100000;
    for b:=0 to n-1 do begin
        depth:=0;
        for i:=0 to n-1 do begin
            for j:=0 to n-1 do begin
                if depth<lssub[(b+i) mod n]+ j];
        end;
        if depth<mind then begin
            mind:=depth; bb:=b;
        end;
    end;
    j:=1;
    for i:=0 to n-1 do begin
        j1:=1;
        while j1<=lssub[(bb+i)mod n] do begin
            s[j]:=ssub[(bb+i)mod n,j1];
            inc(j); inc(j1);
        end;
    end;
    s[j]:=chr(n+ord('0'));
    ls:=j;
    br:=mind;
end;


begin
    assign(input,'chandelier.in');reset(input);
    assign(output,'chandelier.out');rewrite(output);

    read(ch); p:=0;
    while ch in ['1'..'9','a'] do begin
        inc(p);
        ms[p]:=ch;
        read(ch);
    end;
    writeln( br(ord(ms[p])-ord('0'),s,ls) );
    for i:=1 to ls do write(s[i]);
end.
