parse(S, Count) :- atom_chars(S,Chars), string(Count,Chars, []).

string(N) --> as(N).

as(N) --> [a], as(M), {N is M + 1}.
as(0) --> [].
