:- use_module(library(apply)).
:- use_module(library(yall)).

main :-
	read_num(N),
        read_n_string_list(N, L),
        include([X]>>(X == "AC"),
                L,
                AC),
        include([X]>>(X == "WA"),
                L,
                WA),
        include([X]>>(X == "TLE"),
                L,
                TLE),
        include([X]>>(X == "RE"),
                L,
                RE),
        length(AC, NumAC),
        length(WA, NumWA),
        length(TLE, NumTLE),
        length(RE, NumRE),
	write('AC x '), write(NumAC), nl,
        write('WA x '), write(NumWA), nl,
        write('TLE x '), write(NumTLE), nl,
        write('RE x '), write(NumRE), nl,
	nl,
	halt.


read_n_string_list(N, L) :-
	read_n_string_list_aux(N, [], L),
	!.
read_n_string_list_aux(0, L, L).
read_n_string_list_aux(N, Acc, L) :-
	read_str(NewS),
	NewN is N - 1,
	read_n_string_list_aux(NewN, [NewS|Acc], L).
	

read_str(S) :-
        read_string(current_input, ' \n', '', _, S).

read_num(N) :-
	read_str(S),
	number_string(N, S).

