Hello Codeforces!

I have a programming problem form Iranian Olympiad in Informatics in type of Project Euler problems and I want you to help me for solving this problem:

Suppose that we have a $$$m \times n$$$ table that every cell of this table has filled with an integer, so that the sum of the numbers in $$$i$$$'th row of the table is $$$a_i$$$ and the sum of numbers in $$$i$$$'th column of the table is $$$b_i$$$. We say the sequence below **key sequence**:

$$$[a_1,a_2,\ldots,a_m,b_1,b_2,\ldots,b_n]$$$

Suppose again we write down all of the ways of filling a $$$5 \times 5$$$ table with numbers 0,1,2 so that at least one number 2 exists in the table, and calcute their key sequences. If the number of distinic sequences is $$$M_3$$$, What is the $$$M_3 mod \Delta$$$?($$$\Delta=10039$$$)

If you have a sulotion that solves this problem in less than 15 minutes, your sulotion is useful!

And like my other blog entry, sorry for my bad English!