Use inclusion-exclusion for 408 (runs in 12s).
DP based solution for 406 (runs in 1 min).