You can combine the techniques of inclusion-exclusion principle and "stars and bars" to obtain a formula (which is very long, because the formula has 5 big terms due to inclusion-exclusion principle.).
I don't have the time to find out the exact formula though. -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To post to this group, send email to google-code@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/d7b889b2-2fd9-453e-9a51-e0b93c3f1177%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.