Each of the integers $1, 2, \ldots, 729$ is written in its base-$3$ representation without leading zeroes. The numbers are then joined together in that order to form a continuous string of digits: $12101112202122\ldots$ How many times in this string does the substring $012$ appear?

Let's think step by step and output the final answer within \boxed{}.
user