Number of ways

https://codeforces.com/contest/466/problem/C
how to solve this ?

Have you looked at the tutorial? It’s pretty easy to understand imo. If you don’t understand any part of that, comment here again.