Now, we can find $ A \cup B $
$ |A \cup B| = |A| + |B| - |A \cap B| $
$ |A \cup B| = \binom{40}{5} \cdot 3^{35} + \binom{40}{5} \cdot 3^{35} - \binom{40}{5} \cdot \binom{35}{5} \cdot 2^{30} $
$ |A \cup B| = 2 \cdot \binom{40}{5} \cdot 3^{35} - \binom{40}{5} \cdot \binom{35}{5} \cdot 2^{30} $