/*
ID: daeseok1
LANG: JAVA
TASK: wormhole
*/

import java.util.Scanner;
import java.util.Formatter;
import java.io.File;
import java.io.IOException;

public class wormhole {

  public static final int MAX_N = 12;

  public static int [] next = new int [MAX_N];
  public static int [] pairs = new int [MAX_N];

  public static boolean is_cycle(int n) {
    for (int s = 0; s < n; s++) {
      int pos = s;

      for (int c = 0; c < n; c++) {
        pos = next[pairs[pos]];
      }

      if (pos != 0)
        return true;
    }
    return false;
  }

  public static int makePairs(int n) {
    int i, total = 0;

    for (i = 0; i < n; i++)
      if (pairs[i] == 0) break;

    if (i >= n - 1) {
      if (is_cycle(n)) return 1;

      return 0;
    }

    for (int j = i + 1; j < n; j++) {
      if (pairs[j] == 0) {
        pairs[i] = j;
        pairs[j] = i;
        total += makePairs(n);
        pairs[i] = pairs[j] = 0;
      }
    }

    return total;
  }

  public static void main (String [] args) throws IOException {
    Scanner in = new Scanner(new File("wormhole.in"));        // file input
    Formatter out = new Formatter(new File("wormhole.out"));  // file output

    int n = Integer.parseInt(in.nextLine());
    int [] x = new int [n];
    int [] y = new int [n];

    int inCnt = 0;
    while (inCnt < n) {
      x[inCnt] = Integer.parseInt(in.next());
      y[inCnt] = Integer.parseInt(in.next());

      inCnt++;
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (x[j] > x[i] && y[i] == y[j]) {
          if (next[i] == 0 ||
              x[j] - x[i] < x[next[i]] - x[i]) {
            System.out.println("next[" + i + "] : " + j);
            next[i] = j;
          }
        }
      }
    }

    out.format("%d\n", makePairs(n));  // format() has the same syntax as printf()

    out.close();    // flush the output and close the output file
    System.exit(0); // likely needed in USACO
  }
}

@@ -251,16 +251,20 @@
 t %5BMAX_N
+ + 1
 %5D;%0A  pub
@@ -303,16 +303,20 @@
 t %5BMAX_N
+ + 1
 %5D;%0A%0A  pu
@@ -374,14 +374,15 @@
 s = 
-0
+1
 ; s %3C
+=
  n; 
@@ -504,16 +504,18 @@
 os != 0)
+ %7B
 %0A       
@@ -528,16 +528,24 @@
 n true;%0A
+      %7D%0A
     %7D%0A  
@@ -636,30 +636,31 @@
    for (i = 
-0
+1
 ; i %3C
+=
  n; i++)%0A   
@@ -704,15 +704,10 @@
 (i %3E
-=
  n
- - 1
 ) %7B%0A
@@ -786,24 +786,25 @@
 = i + 1; j %3C
+=
  n; j++) %7B%0A 
@@ -1263,16 +1263,20 @@
 w int %5Bn
+ + 1
 %5D;%0A    i
@@ -1295,16 +1295,20 @@
 w int %5Bn
+ + 1
 %5D;%0A%0A    
@@ -1319,17 +1319,17 @@
 inCnt = 
-0
+1
 ;%0A    wh
@@ -1340,16 +1340,17 @@
 (inCnt %3C
+=
  n) %7B%0A  
@@ -1483,14 +1483,15 @@
 i = 
-0
+1
 ; i %3C
+=
  n; 
@@ -1520,14 +1520,15 @@
 j = 
-0
+1
 ; j %3C
+=
  n; 
@@ -1652,24 +1652,26 @@
 %5D - x%5Bi%5D) %7B%0A
+//
             

update wormhole