I think I am not generating the right maps.
For the forst test, w=3 and h=2, I get this:
For cell 0,2 (top right) I think I should apply x+y×W+1 = 2+0*3+1 = 3;
and then R^(2^3 mod lcm(1722,1578)) mod 1579*1723 is 100000^8 mod 2720617 = 2588150,
which is even, so the wall should be built to the south.
But the error indicates the test solution has the wall on the east.
I have tried several variations in the exponent formula, and I can manage
so get thiws map right (it has only two walls), but I haven't been able to do a large map right.