Consider the paths of length $16$ that follow the lines from the lower left corner to the upper right corner on an $8\times 8$ grid. Find the number of such paths that change direction exactly four times, as in the examples shown below.
Four direction changes mean five straight segments, alternating directions. If the path starts to the right, it has three right segments and two up segments.
The $8$ right steps split into $3$ positive parts in $\binom72=21$ ways and the $8$ up steps into $2$ parts in $\binom71=7$ ways.
With $2$ starting directions: $2\cdot21\cdot7=294$. The answer is $\boxed{294}$.
Consider the paths of length $14$ that follow the lines from the lower left corner to the upper right corner on a $7\times 7$ grid. Find the number of such paths that change direction exactly five times, as in the examples shown below.