Hello you will see the problem is that given for example a list [1,9,3,5,2,6,4,7,8] this takes each value from the list and says if when this number appears N has some value lower than it and will tell them where at the end everything will be added

there are no smaller numbers after = 0

9 (Empty)  has at 3,5,2,6,4,7,8 afterwards = 7

3  has 2 later = 1

5  has the 2.4 subsequently = 2

2  does not have minor numbers that happen it = 0

6  has 4 later = 1

4  does not have minor numbers after = 0

7  does not have minor numbers after = 0

8  does not have minor numbers after = 0
at the end adding all that would give 11
This is the function you create
menores(X,[],Aux): Aux is 0+0.
menores(X,[HT],Cuenta): X>H> Aux is 1+0; Aux is 0+0, menores(X,T,Aux), Cuenta is Aux.
but these have been the results
?
 menores(1,[9,3,5,2,6,4,7,8],POP).
POP = 0 .
? menores(3,[5,2,6,4,7,8],POP).
POP = 0.
should give the second a 1 since this function is the first part that compares each value if it is smaller and how many and will return it to a function that will accumulate and will be responsible for getting the head and calling this function .