//先求最长下降,再求最长上升。最后total-1(因为之前确定一套,所以使用total-1套) program P1209; var n,ans,total:longint; a,f,b:array [1..20] of longint; procedure init; var i,t:longint; ch:char; begin fillchar(b,sizeof(b),0); t:=0; while not eoln do begin read(ch); case ch of '0'..'9':t:=t*10+ord(ch)-48; ',':begin inc(n); a[n]:=t; t:=0; end; end;{case} end; inc(n); a[n]:=t; for i:=1 to n do f[i]:=1; end; procedure main; var i,j,max:longint; begin for i:=2 to n do begin max:=-maxlongint; for j:=1 to i-1 do if (a[j]>a[i]) and (f[j]>max) then max:=f[j]; if max<>-maxlongint then f[i]:=max+1; end; for i:=1 to n do if f[i]>ans then ans:=f[i]; end; procedure outit; var i,j,max:longint; begin for i:=1 to n do f[i]:=1; for i:=2 to n do begin max:=-maxlongint; for j:=1 to i-1 do if (a[j]<a[i]) and (f[j]>max) then max:=f[j]; if max<>-maxlongint then f[i]:=max+1; end; for i:=1 to n do if f[i]>total then total:=f[i]; end; begin assign(input,'P1209.in'); reset(input); assign(output,'P1209.out'); rewrite(output); init; main; write(ans,','); outit; writeln(total-1); close(input); close(output); end.