main :-
	read_num(N),
	read_n_num_list(N, L),
        findall(_, make_triangle(N, L, _, _, _), Triangles),
        length(Triangles, Ans),
	write(Ans),
	nl,
	halt.


% A, B, Cの三辺を持つ三角形ができるか？
triangle(A, B, C) :-
	max_list([A, B, C], Max),
	select(Max, [A, B, C], Rest),
	sumlist(Rest, Sum),
	Max < Sum,
        !.

make_triangle(N, List, A, B, C) :-
        numlist(1, N, IndexList),
	member(I, IndexList),
        IPlusOne is I + 1,
        numlist(IPlusOne, N, IndexListForJ),
        member(J, IndexListForJ),
        JPlusOne is J + 1,
        numlist(JPlusOne, N, IndexListForK),
        member(K, IndexListForK),
        
        nth1(I, List, A),
        nth1(J, List, B),
        nth1(K, List, C),
        is_set([A, B, C]),
        triangle(A, B, C).

read_n_num_list(Num, List) :-
	read_n_num_list_aux(Num, [], List),
	!.
read_n_num_list_aux(0, List, List).
read_n_num_list_aux(Num, Old, Accum) :-
	read_num(NewItem),
	NewNum is Num - 1,
	append(Old, [NewItem], NewList),
	read_n_num_list_aux(NewNum, NewList, Accum).
	

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

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

