Rosetta Problems

How many ways?

https://onlinejudge.u-aizu.ac.jp/problems/ITP1_7_B