Ninjas and Monkeys and Bears, Oh My! This challenge is NinjaBearMonkey's prize for winning my Block Building Bot Flocks! challenge with the Black Knight submission. Congratulations NinjaBearMonkey!
The challenge here is fairly simple, but has a variety of possible approaches. The story goes that in the world of Isometric Illusions, there are 6 different types of creatures:

Ninjas, abbreviated N
Bears, abbreviated B
Monkeys, abbreviated M
NinjaBears, abbreviated NB
BearMonkeys, abbreviated BM
NinjaBearMonkeys, abbreviated NBM

(NinjaBearMonkey is, of course, the last, most powerful type.)
Your task is to take a census of these creatures when they are lined up side-by-side, i.e. when their abbreviation strings are concatenated. The caveat is that you need to make sure not to over-count the parts of some creatures as separate creatures that happen to look similar. The creatures will line up such that:

Any instance of NBM is 1 NinjaBearMonkey and 0 other creatures.
Any instance of NB not followed by M is 1 NinjaBear and 0 other creatures.
Any instance of BM not preceded by N is 1 BearMonkey and 0 other creatures.
Otherwise, instances of N, B, and M are single Ninjas, Bears, and Monkeys respectively.

The line is read from left to right.
So, for example, in the line of creatures NBMMBNBNBM, there are 0 Ninjas, 1 Bear, 1 Monkey, 1 NinjaBear, 0 BearMonkeys, and 2 NinjaBearMonkeys.
Challenge
Write a program or function that takes in a string of the characters N, B, and M, and prints or returns how many of each of the 6 types of creatures are present in it.
The output should have the form
#N #B #M #NB #BM #NBM

with the respective creature count replacing each # sign. All 6 counts must be shown, separated by spaces, even when they are 0. However, they may be in any order (e.g. #NBM could come first).
Also:

The input string will only contain the characters N, B, and M.
If the empty string is input, then all the counts are 0.
The output may optionally contain a single leading and/or trailing space, and/or a single trailing newline.

The shortest submission in bytes wins.
Examples
Input: NB
Output: 0N 0B 0M 1NB 0BM 0NBM
Input: NBM
Output: 0N 0B 0M 0NB 0BM 1NBM
Input: NBMMBNBNBM (example from above)
Output: 0N 1B 1M 1NB 0BM 2NBM
Input: MBNNBBMNBM
Output: 1N 1B 1M 1NB 1BM 1NBM
Input: NNNMNBMMBMMBMMMNBMNNMNNNBNNNBNBBNBNMMNBBNBMMBBMBMBBBNNMBMBMMNNNNNMMBMMBM
Output: 17N 6B 14M 5NB 8BM 3NBM
JavaScript ES6, 86 bytes

f=s=&gt;'NBM BM NB M B N'.replace(/\S+/g,e=&gt;(i=0,s=s.replace(RegExp(e,'g'),_=&gt;++i))&amp;&amp;i+e)


(I just had to answer this.) It goes through each substring of NBM, starting with the longer ones, which take higher priority. It searches for each occurrence of that particular string and removes it (in this case replacing it with the current count so it won't be matched again). It finally replaces each substring with the count + the string.

This Stack Snippet is written in the ES5 equivalent of the above code to make it easier to test from any browser. It is also slightly ungolfed code. The UI updates with every keystroke.



f=function(s){
  return'NBM BM NB M B N'.replace(/\S+/g,function(e){
    i=0
    s=s.replace(RegExp(e,'g'),function(){
      return++i
    })
    return i+e
  })
}

run=function(){document.getElementById('output').innerHTML=f(document.getElementById('input').value)};document.getElementById('input').onkeyup=run;run()
&lt;input type="text" id="input" value="NBMMBNBNBM" /&gt;&lt;br /&gt;&lt;samp id="output"&gt;&lt;/samp&gt;