program c;

{$APPTYPE CONSOLE}
{$R-,Q-,S-,H+}
{$MINSTACKSIZE 4000000}

uses
  Math,
  SysUtils;

Type
  Integer=LongInt;
  Real=Extended;

Const
  TaskID='chandelier';
  InFile=TaskID+'.in';
  OutFile=TaskID+'.out';
  MaxP=10002;

Var
  NP:Integer;
  P:Array[1..MaxP]Of Char;
  Opt:Array[0..1,1..MaxP]Of Char;
  NextSib,PrevSib,Rq:Array[0..MaxP]Of Integer;
  Res:Integer;

Procedure Load;
Var
  Ch:Char;
Begin
  ReSet(Input,InFile);
  NP:=0;
  While Not EOF Do Begin
    Read(Ch);
    If Ch>' ' Then Begin
      Inc(NP);
      P[NP]:=Ch;
    End;
  End;
  Close(Input);
End;

Function Optimize(Fin,Step:Integer; Out Req:Integer):Integer;
Var
  J,K,Cur,PI,I,TNum,Num,LastI,RAt:Integer;
Begin
  If P[Fin]>'9' Then Begin
    Opt[Step,Fin]:=P[Fin];
    Req:=1;
    Optimize:=Fin-1;
    Exit;
  End;
  Num:=Ord(P[Fin])-Ord('0');
  I:=Fin-1;
  While Num>0 Do Begin
    PI:=I;
    I:=Optimize(I,1-Step,Rq[I]);
    NextSib[PI]:=I;
    Dec(Num);
  End;
  Optimize:=I;
  Req:=0;
  Num:=Ord(P[Fin])-Ord('0');
  I:=Fin-1;
  PI:=0;
  While Num>0 Do Begin
    If Rq[I]+Num-1>Req Then Begin
      Req:=Rq[I]+Num-1;
    End;
    PrevSib[I]:=PI;
    PI:=I;
    I:=NextSib[I];
    Dec(Num);
  End;
  Cur:=Req;
  Num:=Ord(P[Fin])-Ord('0');
  TNum:=Num;
  I:=PI;
  LastI:=PI;
  RAt:=PI;
  While I>0 Do Begin
    If Cur=Rq[I] Then
      Break;
    Dec(Cur);
    If Rq[I]+TNum-1>Cur Then
      Cur:=Rq[I]+TNum-1;
    I:=PrevSib[I];
    If Cur<Req Then BEgin
      Req:=Cur;
      RAt:=I;
    End;
  End;
  I:=RAt;
  J:=NextSib[LastI];
  Num:=TNum;
  While Num>0 Do Begin
    For K:=NextSib[I]+1 To I Do Begin
      Inc(J);
      Opt[Step,J]:=Opt[1-Step,K];
    End;
    I:=PrevSib[I];
    If I=0 Then I:=LastI;
    Dec(Num);
  End;
  Opt[Step,Fin]:=P[Fin];
End;

Procedure Solve;
Begin
  Optimize(NP,0,Res);
End;

Procedure Save;
Var
  I:Integer;
Begin
  ReWrite(Output,OutFile);
  WriteLn(Res);
  For I:=1 To NP Do Write(Opt[0,I]);
  Close(Output);
End;

begin
  Load;
  Solve;
  Save;
end.
