fun main(args: Array<String>) {
val num=readLine()!!.toInt()
val listFish = List(num) {
val map=readLine()!!.split(" ").map(String::toInt)
map[0]*map[1]
}

val MINUS=kaijo(num-2)
var minusNum=0
for(i in 0..listFish.size-1){
    for(j in i+1..listFish.size-1){
        if(listFish[i]+listFish[j]==0){
            minusNum+=MINUS
        }
    }
}

val ans=kaijo(num)-minusNum
println(ans%1000000007)
}

fun kaijo(num:Int):Int{
    var ans=1;
    for(i in 1..num){
        ans=ans*i
    }
    return ans
}