An $8 \times 8 \times 8$ cube is painted red on 3 faces and blue on 3 faces such that no corner is surrounded by three faces of the same color. The cube is then cut into 512 unit cubes. How many of these cubes contain both red and blue paint on at least one of their faces?

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