We consider finite sums of counting functions on the free group $F_n$ and the free monoid $M_n$ for $n geq 2$. Two such sums are considered equivalent if they differ by a bounded function. We find the complete set of linear relations between equivalence classes of sums of counting functions and apply this result to construct an explicit basis for the vector space of such equivalence classes. Moreover, we provide a graphical algorithm to determine whether two given sums of counting functions are equivalent. In particular, this yields an algorithm to decide whether two sums of Brooks quasimorphisms on $F_n$ represent the same class in bounded cohomology.