#Lutece0147. Game
Game
Migrated from Lutece 147 Game
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
lxhgww feels quite bored these days,so he invented some weird game to kill time.
Counting is Easy
is undoubtedly the weirdest, which is played on an chess board. You are supposed to put rooks on the chess board,and there shouldn't be two of these in the same row or column. There are many different assignment,and it's clear that the exact number is .
In this game,there is a positive integer number on each cell of the board,an assignment's value is the product of all the numbers whose cells are occupied by rooks.To make the game more interesting,an assignment may be nagetive or possitive,the sign is decided by the number of Z Pairs
.If there is a pair of rooks in the assignment,and one is on the right-top direction(any angle is accepted) to another,this pair is a Z Pair
.If there are odd number of Z Pairs
,this assignment is negative,otherwise is positive.
The goal of this game is to summarize all the assignment's value,don't forget to use minus operation while the assignment is negative.
The final answer is too large to write down,so your task is just to calculate the result .
Input
There are multiple test cases in one input file.Each test case begins with two integer numbers (where ) and ().The next lines each contains integer numbers,which describes the value of each chess board cell,all the numbers are in the range of .The input is terminated by an invalid test case with , which should not be processed.
Output
For each test case,output one single line contains the answer .
Samples
2 10
4 9
2 8
0 0
4
Note
There are two assignments(# means Rook):
*#
#*
#*
*#
First assignment's value is ,and there are one Z-Pair
,so it's negative.
Second assignment's value is ,and there are no Z-pair
,so it's positive.
So the total value ,and
Resources
Sichuan State Programming Contest 2008