import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.List;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Egor Kulikov (egor@egork.net)
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int count = in.readInt();
        int[] row = new int[count - 1];
        int[] column = new int[count - 1];
        IOUtils.readIntArrays(in, row, column);
        MiscUtils.decreaseByOne(row, column);
        int[] queue = new int[count - 1];
        int size = 0;
        int nextRow = count - 1;
        int nextColumn = 0;
        List<Swap> answer = new ArrayList<Swap>();
        boolean[] added = new boolean[count - 1];
        for (int i = 0; i < count - 1; i++) {
            if (size == i) {
                for (int j = 0; j < count - 1; j++) {
                    if (!added[j]) {
                        added[j] = true;
                        queue[size++] = j;
                        break;
                    }
                }
            }
            int currentRow = row[queue[i]];
            int currentColumn = column[queue[i]];
            if (currentRow <= nextRow) {
                if (currentRow != nextRow)
                    answer.add(new Swap(1, currentRow + 1, nextRow + 1));
                for (int j = 0; j < count - 1; j++) {
                    if (currentRow == row[j]) {
                        row[j] = nextRow;
                        if (!added[j]) {
                            queue[size++] = j;
                            added[j] = true;
                        }
                    } else if (nextRow == row[j])
                        row[j] = currentRow;
                }
                nextRow--;
            }
            if (currentColumn >= nextColumn) {
                if (currentColumn != nextColumn)
                    answer.add(new Swap(2, currentColumn + 1, nextColumn + 1));
                for (int j = 0; j < count - 1; j++) {
                    if (currentColumn == column[j]) {
                        column[j] = nextColumn;
                        if (!added[j]) {
                            queue[size++] = j;
                            added[j] = true;
                        }
                    } else if (nextColumn == column[j])
                        column[j] = currentColumn;
                }
                nextColumn++;
            }
        }
        out.printLine(answer.size());
        for (Swap swap : answer)
            out.printLine(swap.type, swap.from, swap.to);
    }

    static class Swap {
        final int type, from, to;

        Swap(int type, int from, int to) {
            this.type = type;
            this.from = from;
            this.to = to;
        }
    }
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	public static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

    public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	}

class IOUtils {

	public static void readIntArrays(InputReader in, int[]... arrays) {
		for (int i = 0; i < arrays[0].length; i++) {
			for (int j = 0; j < arrays.length; j++)
				arrays[j][i] = in.readInt();
		}
	}

	}

class MiscUtils {

    public static void decreaseByOne(int[]...arrays) {
		for (int[] array : arrays) {
			for (int i = 0; i < array.length; i++)
				array[i]--;
		}
	}

	}


/*
PROG: cc
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class cc {
   int[] x, y;
   int n, m, r;
   String s = "";

   void swap(int c, int i, int j) {
      ++r;
      s += String.format("%d %d %d\n", c, i + 1, j + 1);
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      boolean[] rf = new boolean[n];
      x = new int[m];
      y = new int[m];

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]) - 1;
         y[i] = Integer.parseInt(pa[1]) - 1;
         rf[x[i]] = true;
      }

      for(int i = 0; i < n; ++i) if(rf[i])
         for(int j = i + 1; j < n; ++j) if(!rf[j]) {
            swap(1, i, j);
            rf[i] = false;
            rf[j] = true;
            break;
         }

      int c = 0;
      for(int i = 0; i < n; ++i) {
         if(rf[i]) {
            for(int j = 0; j < m; ++j) {
               if(x[j] == i) {
                  if(y[j] > c)
                     swap(2, y[j], c++);
                  if(y[j] == c)
                     ++c;
               }
            }
         }
      }

      System.out.println(r);
      System.out.println(s);
   }

   public static void main(String[] args) throws Exception {
      new cc().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class c {
   int n, m;
   int[] x, y, z;
   List<String> li = new ArrayList<String>();

   void swap(int c, int i, int j) {
      li.add(String.format("%d %d %d", c, i, j));
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      x = new int[m];
      y = new int[m];
      z = new int[m];

      for(int i = 0; i < m; ++i) z[i] = i;

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]);
         y[i] = Integer.parseInt(pa[1]);
      }

      boolean ca = true;
      int a = 1, b = n;
      while(ca) {
         ca = false;
         int f = -1, t = -1;
         boolean[] v = new boolean[n];
         for(int i = 0; i < m; ++i) {
            if(x[i] == a)
               f = x[i];
            v[x[i] - 1] = true;
         }
         for(int i = 0; i < n; ++i)
            if(!v[i]) t = i + 1;
         if(f != -1 && t != -1) {
            swap(1, f, t);
            ca = true;
         }

         f = -1; t = -1;
         v = new boolean[n];
         for(int i = 0; i < m; ++i) {
            if(y[i] == b)
               f = y[i];
            v[y[i] - 1] = true;
         }
         for(int i = 0; i < n; ++i)
            if(!v[i]) t = i + 1;
         if(f != -1 && t != -1) {
            swap(2, f, t);
            ca = true;
         }
      }

      System.out.println(li.size());
      for(String s : li)
         System.out.println(s);
      //print();
   }

   void print() {
      for(int i = 0; i < m; ++i)
         debug(x[i], y[i]);
      System.out.println();
   }
   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class c {
   int n, m;
   int[] x, y, z;
   List<String> li = new ArrayList<String>();

   void swap(int c, int i, int j) {
      li.add(String.format("%d %d %d", c, i, j));
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      x = new int[m];
      y = new int[m];
      z = new int[m];

      for(int i = 0; i < m; ++i) z[i] = i;

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]);
         y[i] = Integer.parseInt(pa[1]);
      }

      for(int i = 1; i < n; ++i) {
         boolean by = false, bx = false;
         for(int j = 0; j < m; ++j) {
            if(i == y[j]) by = true;
            if(n - i + 1 == x[j]) bx = true;
         }
         if(!by)
            swap(2, i, i + 1);
         if(!bx)
            swap(1, n - i + 1, n - i);
      }

      for(int i = 0; i < m; ++i)
         if(x[i] == y[i])
            swap(2, y[i], y[i] - 1);

      System.out.println(li.size());
      for(String s : li)
         System.out.println(s);

   }

   void print() {
      for(int i = 0; i < m; ++i)
         debug(x[i], y[i]);
      System.out.println();
   }
   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.io.*;
import java.awt.*;
public class c {
   int n, m;
   ArrayList<String> li = new ArrayList<String>();
   ArrayList<Point> pi = new ArrayList<Point>();

   void swap(int c, int i, int j) {
      li.add(String.format("%d %d %d", c, i, j));
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(pi.get(d).x == i) pi.get(d).x = j;
            else if(pi.get(d).x == j) pi.get(d).x = i;
         } else {
            if(pi.get(d).y == i) pi.get(d).y = j;
            else if(pi.get(d).y == j) pi.get(d).y = i;
         }
      }
   }

   void sort() {
      Collections.sort(pi, new Comparator<Point>() {
         public int compare(Point a, Point b) {
            return b.x - a.x;
         }
      });
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         pi.add(new Point(Integer.parseInt(pa[0]), Integer.parseInt(pa[1])));
      }
      int a = n, b = 1;
      for(Point p : pi) {
         if(p.x < a) swap(1, p.x, a);
         if(p.y > b) swap(2, p.y, b);
         b = b + 1;
         a = a - 1;
      }

      sort();
      for(Point p : pi) {
         if(p.x <= p.y) {
            for(int j = 0; j < m; ++j) {
               boolean ca = true;
               for(int k = j; k < m; ++k) {
                  if(pi.get(j).x != pi.get(k).x) {
                     j = k - 1;
                     break;
                  }
                  if(p.x <= pi.get(k).y)
                     ca = false;
               }
               if(ca) {
                  swap(1, p.x, pi.get(j).x);
                  sort();
                  break;
               }
            }
         }
      }
      System.out.println(li.size());
      for(String s : li)
         System.out.println(s);
      print();
   }

   void print() {
      for(Point p : pi)
         if(p.x <= p.y)
            debug(p.x, p.y);
      System.out.println();
   }
   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.io.*;
import java.awt.*;
public class c {
   int n, m;
   ArrayList<String> li = new ArrayList<String>();
   ArrayList<Point> pi = new ArrayList<Point>();

   void swap(int c, int i, int j) {
      li.add(String.format("%d %d %d", c, i, j));
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(pi.get(d).x == i) pi.get(d).x = j;
            else if(pi.get(d).x == j) pi.get(d).x = i;
         } else {
            if(pi.get(d).y == i) pi.get(d).y = j;
            else if(pi.get(d).y == j) pi.get(d).y = i;
         }
      }
   }

   void sort() {
      Collections.sort(pi, new Comparator<Point>() {
         public int compare(Point a, Point b) {
            return b.x - a.x;
         }
      });
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         pi.add(new Point(Integer.parseInt(pa[0]), Integer.parseInt(pa[1])));
      }
      int a = n, b = 1;
      for(Point p : pi) {
         if(p.x < a) swap(1, p.x, a);
         if(p.y > b) swap(2, p.y, b);
         b = b + 1;
         a = a - 1;
      }

      sort();
      for(int i = 0; i < m; ++i) {
         Point p = pi.get(i);
         if(p.x <= p.y) {
            for(int j = 0; j < m; ++j) {
               boolean ca = true;
               for(int k = j; k < m; ++k) {
                  if(pi.get(j).x != pi.get(k).x) {
                     j = k - 1;
                     break;
                  }
                  if(p.x <= pi.get(k).y)
                     ca = false;
               }
               if(ca) {
                  swap(1, p.x, pi.get(j).x);
                  sort();
                  i = -1;
                  break;
               }
            }
         }
      }
      System.out.println(li.size());
      for(String s : li)
         System.out.println(s);
      print();
   }

   void print() {
      for(Point p : pi)
         if(p.x <= p.y)
            debug(p.x, p.y);
      System.out.println();
   }
   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class c {
   int n, m;
   int[] x, y, z;
   List<String> li = new ArrayList<String>();

   void swap(int c, int i, int j) {
      li.add(String.format("%d %d %d", c, i, j));
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      x = new int[m];
      y = new int[m];
      z = new int[m];

      for(int i = 0; i < m; ++i) z[i] = i;

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]);
         y[i] = Integer.parseInt(pa[1]);
      }

      boolean ca = true;
      int a = n, b = 1;
      for(int i = 0; i < m; ++i) {
         if(x[i] < a) swap(1, x[i], a);
         if(y[i] > b) swap(2, y[i], b);
         b = b + 1;
         a = a - 1;
      }
      for(int i = 0; i < m; ++i)
         if(x[i] == y[i])
            swap(1, x[i], x[i] + 1);
      for(int i = 0; i < m; ++i)
         if(x[i] < y[i])
            swap(1, x[i], n);
      System.out.println(li.size());
      for(String s : li)
         System.out.println(s);
      //print();
   }

   void print() {
      for(int i = 0; i < m; ++i)
         debug(x[i], y[i]);
      System.out.println();
   }
   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.awt.*;
import java.io.*;

public class c {
   class co {
      int c, i, j;
      co(int c, int i, int j) {
         this.c = c;
         this.i = i;
         this.j = j;
      }
   }
   ArrayList<Point> li = new ArrayList<Point>();
   ArrayList<co> r = new ArrayList<co>();

   void swap(int c, int i, int j) {
      for(int d = 0; d < li.size(); ++d) {
         if(c == 2) {
            if(li.get(d).y == i)
               li.get(d).y = j;
            else if(li.get(d).y == j)
               li.get(d).y = i;
         } else {
            if(li.get(d).x == i)
               li.get(d).x = j;
            else if(li.get(d).x == j)
               li.get(d).x = i;
         }
      }
   }
   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(br.readLine());

      for(int i = 0; i < n - 1; ++i) {
         String[] pa = br.readLine().split(" ");
         li.add(new Point(Integer.parseInt(pa[0]), Integer.parseInt(pa[1])));
      }

      boolean bx = false, by = false;
      for(Point p : li) {
         if(p.x == n)
            bx = true;
         if(p.y == 1)
            by = true;
      }
      if(!bx) {
         r.add(new co(1, n, n - 1));
         swap(1, n, n - 1);
      }
      if(!by) {
         r.add(new co(2, 1, 2));
         swap(2, 1, 2);
      }
      for(int i = 2; i < n; ++i) {
         bx = false;
         by = false;
         for(Point p : li) {
            if(p.x == i)
               bx = true;
            if(p.y == i)
               by = true;
         }
         if(!bx) {
            r.add(new co(1, i, i - 1));
            swap(1, i, i - 1);
         }
         if(!by) {
            r.add(new co(2, i, i + 1));
            swap(2, i, i + 1);
         }
      }
      for(Point p : li)
         if(p.x == p.y) {
            r.add(new co(2, p.y, p.y - 1));
            swap(2, p.y, p.y - 1);
         }

      for(Point p : li)
         if(p.x == p.y) {
            r.add(new co(1, p.x, p.x + 1));
            swap(1, p.x, p.x + 1);
         }

      System.out.println(r.size());
      for(co b : r) {
         System.out.println(String.format("%d %d %d", b.c, b.i, b.j));
      }
   }

   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class c {
   int n, m;
   int[] x, y, z;
   List<String> li = new ArrayList<String>();

   void swap(int c, int i, int j) {
      li.add(String.format("%d %d %d", c, i, j));
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      x = new int[m];
      y = new int[m];
      z = new int[m];

      for(int i = 0; i < m; ++i) z[i] = i;

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]);
         y[i] = Integer.parseInt(pa[1]);
      }

      boolean ca = true;
      int a = n, b = 1;
      for(int i = 0; i < m; ++i) {
         if(x[i] != a) swap(1, x[i], a);
         if(y[i] > b) swap(2, y[i], b);
         b = b + 1;
      }
      for(int i = 0; i < m; ++i)
         if(x[i] == y[i])
            swap(1, x[i], x[i] + 1);
      System.out.println(li.size());
      for(String s : li)
         System.out.println(s);
      //print();
   }

   void print() {
      for(int i = 0; i < m; ++i)
         debug(x[i], y[i]);
      System.out.println();
   }
   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: cc
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class cc {
   int[] x, y;
   int n, m, r;
   String s = "";

   void swap(int c, int i, int j) {
      ++r;
      s += String.format("%d %d %d\n", c, i + 1, j + 1);
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      boolean[] rf = new boolean[n];
      x = new int[m];
      y = new int[m];

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]) - 1;
         y[i] = Integer.parseInt(pa[1]) - 1;
         rf[x[i]] = true;
      }

      for(int i = 0; i < n; ++i) if(rf[i])
         for(int j = 0; j < n; ++j) if(!rf[j]) {
            swap(1, i, j);
            rf[i] = false;
            rf[j] = true;
         }

      int c = 0;
      for(int i = 0; i < n; ++i) {
         if(rf[i]) {
            for(int j = 0; j < m; ++j) {
               if(x[j] == i) {
                  if(y[j] > c)
                     swap(2, y[j], c++);
                  if(y[j] == c)
                     ++c;
               }
            }
         }
      }

      System.out.println(r);
      System.out.println(s);
   }

   public static void main(String[] args) throws Exception {
      new cc().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class c {
   int n, m;
   int[] x, y, z;
   List<String> li = new ArrayList<String>();

   void swap(int c, int i, int j) {
      li.add(String.format("%d %d %d", c, i, j));
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      x = new int[m];
      y = new int[m];
      z = new int[m];

      for(int i = 0; i < m; ++i) z[i] = i;

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]);
         y[i] = Integer.parseInt(pa[1]);
      }

      for(int i = 1; i < n; ++i) {
         boolean by = false, bx = false;
         for(int j = 0; j < m; ++j) {
            if(i == y[j]) by = true;
            if(n - i + 1 == x[j]) bx = true;
         }
         if(!by)
            swap(2, i, i + 1);
         if(!bx)
            swap(1, n - i + 1, n - i);
      }

      for(int i = 0; i < m; ++i)
         if(x[i] == y[i]) {
            swap(2, y[i], y[i] - 1);
            i = -1;
         }

      System.out.println(li.size());
      for(String s : li)
         System.out.println(s);

   }

   void print() {
      for(int i = 0; i < m; ++i)
         debug(x[i], y[i]);
      System.out.println();
   }
   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: cc
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class cc {
   int[] x, y;
   int n, m, r;
   String s = "";

   void swap(int c, int i, int j) {
      ++r;
      s += String.format("%d %d %d\n", c, i + 1, j + 1);
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      boolean[] rf = new boolean[n];
      x = new int[m];
      y = new int[m];

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]) - 1;
         y[i] = Integer.parseInt(pa[1]) - 1;
         rf[x[i]] = true;
      }

      for(int i = 0; i < n; ++i) if(rf[i])
         for(int j = i + 1; j < n; ++j) if(!rf[j]) {
            swap(1, i, j);
            rf[i] = false;
            rf[j] = true;
            break;
         }

      int c = 0;
      for(int i = 0; i < n; ++i) {
         if(rf[i]) {
            for(int j = 0; j < m; ++j) {
               if(x[j] == i) {
                  if(y[j] > c)
                     swap(2, y[j], c++);
                  //if(y[j] == c)
                  //   ++c;
               }
            }
         }
      }

      System.out.println(r);
      System.out.println(s);
   }

   public static void main(String[] args) throws Exception {
      new cc().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class c {
   int n, m;
   int[] x, y, z;
   List<String> li = new ArrayList<String>();

   void swap(int c, int i, int j) {
      li.add(String.format("%d %d %d", c, i, j));
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      x = new int[m];
      y = new int[m];
      z = new int[m];

      for(int i = 0; i < m; ++i) z[i] = i;

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]);
         y[i] = Integer.parseInt(pa[1]);
      }
      int a = n, b = 1;
      for(int i = 0; i < m; ++i) {
         if(x[i] < a) swap(1, x[i], a);
         if(y[i] > b) swap(2, y[i], b);
         b = b + 1;
         a = a - 1;
      }
      for(int k = 0; k < 3; ++k)
         for(int i = 0; i < m; ++i)
            if(x[i] <= y[i])
               swap(1, x[i], y[i] + 1);
      System.out.println(li.size());
      for(String s : li)
         System.out.println(s);
      print();
   }

   void print() {
      for(int i = 0; i < m; ++i)
         if(x[i] <= y[i])
            debug(x[i], y[i]);
      System.out.println();
   }
   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class c {
   int n, m;
   int[] x, y, z;
   List<String> li = new ArrayList<String>();

   void swap(int c, int i, int j) {
      li.add(String.format("%d %d %d", c, i, j));
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      x = new int[m];
      y = new int[m];
      z = new int[m];

      for(int i = 0; i < m; ++i) z[i] = i;

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]);
         y[i] = Integer.parseInt(pa[1]);
      }
      int a = n, b = 1;
      for(int i = 0; i < m; ++i) {
         if(x[i] < a) swap(1, x[i], a);
         if(y[i] > b) swap(2, y[i], b);
         b = b + 1;
         a = a - 1;
      }
      for(int k = 0; k < 10; ++k)
         for(int i = 0; i < m; ++i)
            if(x[i] <= y[i])
               swap(1, x[i], y[i] + 1);
      System.out.println(li.size());
      for(String s : li)
         System.out.println(s);
      print();
   }

   void print() {
      for(int i = 0; i < m; ++i)
         if(x[i] <= y[i])
            debug(x[i], y[i]);
      System.out.println();
   }
   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class c {
   int n, m;
   int[] x, y, z;
   List<String> li = new ArrayList<String>();

   void swap(int c, int i, int j) {
      li.add(String.format("%d %d %d", c, i, j));
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      x = new int[m];
      y = new int[m];
      z = new int[m];

      for(int i = 0; i < m; ++i) z[i] = i;

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]);
         y[i] = Integer.parseInt(pa[1]);
      }

      boolean ca = true;
      int a = n, b = 1;
      for(int i = 0; i < m; ++i) {
         if(x[i] < a) swap(1, x[i], a);
         if(y[i] > b) swap(2, y[i], b);
         b = b + 1;
         a = a - 1;
      }
      for(int i = 0; i < m; ++i)
         if(x[i] <= y[i]) {
            swap(1, x[i], y[i] + 1);
            i = -1;
         }
      System.out.println(li.size());
      for(String s : li)
         System.out.println(s);
      //print();
   }

   void print() {
      for(int i = 0; i < m; ++i)
         debug(x[i], y[i]);
      System.out.println();
   }
   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class c {
   int n, m;
   int[] x, y, z;
   List<String> li = new ArrayList<String>();

   void swap(int c, int i, int j) {
      li.add(String.format("%d %d %d", c, i, j));
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      x = new int[m];
      y = new int[m];
      z = new int[m];

      for(int i = 0; i < m; ++i) z[i] = i;

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]);
         y[i] = Integer.parseInt(pa[1]);
      }

      boolean ca = true;
      int a = n, b = 1;
      for(int i = 0; i < m; ++i) {
         if(x[i] < a) swap(1, x[i], a);
         if(y[i] > b) swap(2, y[i], b);
         b = b + 1;
         a = a - 1;
      }
      for(int i = 0; i < m; ++i)
         if(x[i] <= y[i])
            swap(1, x[i], y[i] + 1);
      System.out.println(li.size());
      for(String s : li)
         System.out.println(s);
      //print();
   }

   void print() {
      for(int i = 0; i < m; ++i)
         debug(x[i], y[i]);
      System.out.println();
   }
   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: c
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class c {
   int n, m;
   int[] x, y, z;
   List<String> li = new ArrayList<String>();

   void swap(int c, int i, int j) {
      li.add(String.format("%d %d %d", c, i, j));
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      x = new int[m];
      y = new int[m];
      z = new int[m];

      for(int i = 0; i < m; ++i) z[i] = i;

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]);
         y[i] = Integer.parseInt(pa[1]);
      }

      boolean ca = true;
      int a = n, b = 1;
      for(int i = 0; i < m; ++i) {
         if(x[i] < a) swap(1, x[i], a);
         if(y[i] > b) swap(2, y[i], b);
         b = b + 1;
         a = a - 1;
      }
      for(int i = 0; i < m; ++i)
         if(x[i] == y[i])
            swap(1, x[i], x[i] + 1);
      System.out.println(li.size());
      for(String s : li)
         System.out.println(s);
      //print();
   }

   void print() {
      for(int i = 0; i < m; ++i)
         debug(x[i], y[i]);
      System.out.println();
   }
   public static void main(String[] args) throws Exception {
      new c().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


/*
PROG: cc
LANG: JAVA
*/
import java.util.*;
import java.io.*;

public class cc {
   int[] x, y;
   int n, m, r;
   String s = "";

   void swap(int c, int i, int j) {
      ++r;
      s += String.format("%d %d %d\n", c, i + 1, j + 1);
      for(int d = 0; d < m; ++d) {
         if(c == 1) {
            if(x[d] == i) x[d] = j;
            else if(x[d] == j) x[d] = i;
         } else {
            if(y[d] == i) y[d] = j;
            else if(y[d] == j) y[d] = i;
         }
      }
   }

   private void solve() throws Exception {
      //BufferedReader br = new BufferedReader(new FileReader("c.in"));
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      n = Integer.parseInt(br.readLine());
      m = n - 1;
      boolean[] rf = new boolean[n];
      x = new int[m];
      y = new int[m];

      for(int i = 0; i < m; ++i) {
         String[] pa = br.readLine().split(" ");
         x[i] = Integer.parseInt(pa[0]) - 1;
         y[i] = Integer.parseInt(pa[1]) - 1;
         rf[x[i]] = true;
      }

      for(int i = 0; i < n; ++i) if(rf[i])
         for(int j = 0; j < n; ++j) if(!rf[j]) {
            swap(1, i, j);
            rf[i] = false;
            rf[j] = true;
            break;
         }

      int c = 0;
      for(int i = 0; i < n; ++i) {
         if(rf[i]) {
            for(int j = 0; j < m; ++j) {
               if(x[j] == i) {
                  if(y[j] > c)
                     swap(2, y[j], c++);
                  if(y[j] == c)
                     ++c;
               }
            }
         }
      }

      System.out.println(r);
      System.out.println(s);
   }

   public static void main(String[] args) throws Exception {
      new cc().solve();
   }

   static void debug(Object...o) {
      System.err.println(Arrays.deepToString(o));
   }

}


import java.util.*;
import java.io.*;

public class C266
{
    static void check(int[] x, int[] y)
    {
        for(int i=0;i<x.length;i++)
            System.out.println((x[i]+1)+" > "+(y[i]+1));
    }

    static void swap(int a, int b, int[] x, int[] y)
    {
        for(int i=0;i<x.length;i++)
            if(x[i]==a)
                x[i]=b;
            else if(x[i]==b)
                x[i]=a;
    }

    public static void main(String[] args) throws IOException
    {
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext())
        {
            int n=sc.nextInt();
            int[] x=new int[n-1];
            int[] y=new int[n-1];
            for(int i=0;i<n-1;i++)
            {
                x[i]=sc.nextInt()-1;
                y[i]=sc.nextInt()-1;
            }

            int numops=0;
            StringBuffer sb=new StringBuffer();
            boolean[] filledRow=new boolean[n];

            for(int i=0;i<n-1;i++)
                filledRow[x[i]]=true;
            for(int i=0;i<n;i++) if(filledRow[i])
                for(int j=i+1;j<n;j++) if(!filledRow[j])
                {
                    swap(i,j,x,y);
                    filledRow[i]=false;
                    filledRow[j]=true;
                    numops++;
                    sb.append("1 "+(i+1)+" "+(j+1)+"\n");
                    break;
                }

            int colnum=0;
            for(int i=0;i<n;i++) if(filledRow[i])
            {
                for(int j=0;j<n-1;j++)
                    if(x[j]==i&&y[j]>colnum)
                    {
                        //System.out.println(i+" "+j+" "+x[j]+" "+y[j]+" colnum: "+colnum);
                        int other=y[j];
                        swap(colnum,other,y,x);
                        numops++;
                        sb.append("2 "+(colnum+1)+" "+(other+1)+"\n");
                        colnum++;
                    }
                    else if(x[j]==i&&y[j]==colnum)
                        colnum++;
            }
            System.out.println(numops);
            System.out.print(sb);
            //check(x,y);
        }
    }
}

class MyArray
{
    static void sort(int[] q)
    {
        sort(q,0,q.length);
    }

    static void sort(int[] q, int a, int b)
    {
        Random rng=new Random(System.currentTimeMillis());
        for(int i=a;i<b;i++)
        {
            int ind=i+rng.nextInt(b-i);
            int h=q[i];
            q[i]=q[ind];
            q[ind]=h;
        }
        Arrays.sort(q,a,b);
    }
}


import java.util.*;
import java.io.*;

public class C266
{
    static void check(int[] x, int[] y)
    {
        for(int i=0;i<x.length;i++)
            System.out.println((x[i]+1)+" > "+(y[i]+1));
    }

    static void swap(int a, int b, int[] x, int[] y)
    {
        for(int i=0;i<x.length;i++)
            if(x[i]==a)
                x[i]=b;
            else if(x[i]==b)
                x[i]=a;
    }

    public static void main(String[] args) throws IOException
    {
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext())
        {
            int n=sc.nextInt();
            int[] x=new int[n-1];
            int[] y=new int[n-1];
            for(int i=0;i<n-1;i++)
            {
                x[i]=sc.nextInt()-1;
                y[i]=sc.nextInt()-1;
            }

            int numops=0;
            StringBuffer sb=new StringBuffer();
            boolean[] filledRow=new boolean[n];

            for(int i=0;i<n-1;i++)
                filledRow[x[i]]=true;
            for(int i=0;i<n;i++) if(filledRow[i])
                for(int j=i+1;j<n;j++) if(!filledRow[j])
                {
                    swap(i,j,x,y);
                    filledRow[i]=false;
                    filledRow[j]=true;
                    numops++;
                    sb.append("1 "+(i+1)+" "+(j+1)+"\n");
                    break;
                }

            int colnum=0;
            for(int i=0;i<n;i++) if(filledRow[i])
            {
                for(int j=0;j<n-1;j++)
                    if(x[j]==i&&y[j]>colnum)
                    {
                        //System.out.println(i+" "+j+" "+x[j]+" "+y[j]+" colnum: "+colnum);
                        int other=y[j];
                        swap(colnum,other,y,x);
                        numops++;
                        sb.append("2 "+(colnum+1)+" "+(other+1)+"\n");
                        colnum++;
                    }
                    else if(x[j]==i&&y[j]>colnum)
                        colnum++;
            }
            System.out.println(numops);
            System.out.print(sb);
            //check(x,y);
        }
    }
}

class MyArray
{
    static void sort(int[] q)
    {
        sort(q,0,q.length);
    }

    static void sort(int[] q, int a, int b)
    {
        Random rng=new Random(System.currentTimeMillis());
        for(int i=a;i<b;i++)
        {
            int ind=i+rng.nextInt(b-i);
            int h=q[i];
            q[i]=q[ind];
            q[ind]=h;
        }
        Arrays.sort(q,a,b);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class C {

	static class Scanner{
		BufferedReader br=null;
		StringTokenizer tk=null;
		public Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() throws IOException{
			while(tk==null || !tk.hasMoreTokens())
				tk=new StringTokenizer(br.readLine());
			return tk.nextToken();
		}
		public int nextInt() throws NumberFormatException, IOException{
			return Integer.valueOf(next());
		}
		public double nextDouble() throws NumberFormatException, IOException{
			return Double.valueOf(next());
		}
	}

	static class pair{
		int x,y;
		public pair(int xx,int yy){
			x=xx;
			y=yy;
		}
	}

	static void swap(int i,int j,int[] array){
		int tmp=array[i];
		array[i]=array[j];
		array[j]=tmp;
	}

	static void swapC(int a,int b,pair[] v){
		for(int i=0;i<N - 1;i++){
			if (v[i].y==a)
				v[i].y=b;
			else if(v[i].y==b)
				v[i].y=a;
		}
	}

	static void swapR(int a,int b,pair[] v){
		for(int i=0;i<N - 1;i++){
			if (v[i].x==a)
				v[i].x=b;
			else if(v[i].x==b)
				v[i].x=a;
		}
	}

	static void dbg(pair[] v ){
		int N=v.length + 1;
		int[][] a=new int[N][N];
		for(int i=0;i<N;i++)
			for(int j=0;j<N;j++)
				a[i][j]=0;
		for(int i=0;i<N - 1;i++)
			a[v[i].x][v[i].y]++;
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++)
				System.out.print(a[i][j]+" ");
			System.out.println();
		}
	}

	static int N;

	public static void main(String args[]) throws NumberFormatException, IOException{
		Scanner sc=new Scanner();
		N=sc.nextInt();
		pair[] v=new pair[N-1];
		for(int i=0;i<N - 1;i++)
			v[i]=new pair(sc.nextInt() - 1,sc.nextInt() - 1);
		int[] countC=new int[N];
		for(int i=0;i<N;i++) countC[i]=0;
		for(int i=0;i<N - 1;i++)
			countC[v[i].y]++;
		int total=0;
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<N;i++){
			int best=countC[i];
			int index=i;
			for(int c=i+1;c<N;c++){
				if (countC[c]>best){
					best=countC[c];
					index=c;
				}
			}
			if (index!=i){
				swapC(i , index, v);
				swap(i, index, countC);
				sb.append("2 "+(i+1)+" "+(index+1)+"\n");
				total++;
			}
		}
		int[] rightmost=new int[N];
		for(int i=0;i<N;i++) rightmost[i]=-1;
		for(int i=0;i<N - 1;i++)
			rightmost[v[i].x] = Math.max(rightmost[v[i].x], v[i].y);
		for(int i=N-1;i>=0;i--){
			int best=rightmost[i];
			int index=i;
			for(int r=i-1;r>=0;r--){
				if (rightmost[r]>best){
					best=rightmost[r];
					index=r;
				}
			}
			if (index!=i){
				swapR(i , index, v);
				swap(i, index, rightmost);
				sb.append("1 "+(i+1)+" "+(index+1)+"\n");
				total++;
			}
		}
		System.out.println(total);
		System.out.print(sb.toString());
	}

}


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    private void doSwap(int table[][],int f,int l,int t,int n) {
        if(f==l)
            return;
        int []buf=new int[n];
        if(t==1) {     //swap rows
          for(int i=0;i<n;i++) {
              buf[i]=table[l][i];
          }
          for(int i=0;i<n;i++) {
              table[l][i]=table[f][i];
           }
           for(int i=0;i<n;i++) {
               table[f][i]=buf[i];
           }
        }
        else { //swap columns
            for(int i=0;i<n;i++) {
                buf[i]=table[i][l];
            }
            for(int i=0;i<n;i++) {
                table[i][l]=table[i][f];
            }
            for(int i=0;i<n;i++) {
                table[i][f]=buf[i];
            }
        }

    }
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n=in.nextInt();
        int x[]=new int[n-1];
        int y[]=new int[n-1];
        int sumr[]=new int[n];
        int sumc[]=new int[n];
        int table[][]=new int[n][n];
        for(int i=0;i<n-1;i++) {
           x[i]=in.nextInt()-1;
           sumr[x[i]]++;
           y[i]=in.nextInt()-1;
           sumc[y[i]]++;
           table[x[i]][y[i]]=1;
        }
        ArrayList<SwapData> arlist=new ArrayList<SwapData>(2*n);
        for(int i=0;i<n;i++) {
            //find empty row
            int emptryRowId=-1;
            for(int j=i;j<n;j++) {
                if(sumr[j]==0)
                    emptryRowId=j;
            }
           // System.out.println("A"+emptryRowId);
            // swap top row with empty:
            if(emptryRowId!=i && emptryRowId!=-1) {
                int s=sumr[emptryRowId];
                sumr[emptryRowId]=sumr[i];
                sumr[i]=s;
                doSwap(table,emptryRowId,i,1,n);
                arlist.add(new SwapData(i,emptryRowId,1))    ;
            }

            // find column with greatest number of ones
            int curMax=-1;
            int curColumn=-1;
            for(int j=i;j<n;j++) {
               if(sumc[j]>curMax) {
                   curMax=sumc[j];
                   curColumn=j ;
               }
            }
            // swap found row with left:
            if(curColumn!=i) {
                int s=sumc[curColumn];
                sumc[curColumn]=sumc[i];
                sumc[i]=s;
                doSwap(table,curColumn,i,2,n);
                arlist.add(new SwapData(i,curColumn,2))    ;
            }
            // removed used 1 from sumr:
            for(int j=0;j<n;j++) {
                if(table[j][i]==1)
                    sumr[j]--;
            }
        }
        out.println(arlist.size());
        for(int i=0;i<arlist.size();i++) {
            out.println(arlist.get(i).t+" "+(arlist.get(i).x+1)+" "+(arlist.get(i).y+1));
        }

    }
}

class SwapData {
    int x,y,t;

    SwapData(int x, int y, int t)
    {
        this.x = x;
        this.y = y;
        this.t = t;
    }
}

class InputReader {
    StringTokenizer st;
    BufferedReader in;
    public InputReader(InputStream ins)
    {
        in = new BufferedReader(new InputStreamReader(ins));
    }

    public String nextToken()
    {
        while(st==null || !st.hasMoreTokens())
        {
            try {
                st=new StringTokenizer(in.readLine());
            } catch (IOException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
        return st.nextToken();
    }
    public int nextInt()
    {

        return Integer.parseInt(nextToken());
    }

    }


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n=in.nextInt();
        int x[]=new int[n-1];
        int y[]=new int[n-1];
        int sumr[]=new int[n];
        int sumc[]=new int[n];
        for(int i=0;i<n-1;i++) {
           x[i]=in.nextInt()-1;
           sumr[x[i]]++;
           y[i]=in.nextInt()-1;
           sumc[y[i]]++;
        }
        ArrayList<SwapData> arlist=new ArrayList<SwapData>(2*n);
        for(int i=0;i<n;i++) {
            //find empty row
            int emptryRowId=-1;
            for(int j=i;j<n;j++) {
                if(sumr[j]==0)
                    emptryRowId=j;
            }
            //System.out.println("A"+emptryRowId);
            // swap top row with empty:
            if(emptryRowId!=i && emptryRowId!=-1) {
                int s=sumr[emptryRowId];
                sumr[emptryRowId]=sumr[i];
                sumr[i]=s;
                arlist.add(new SwapData(i,emptryRowId,1))    ;
            }
            // find column with greatest number of ones
            int curMax=-1;
            int curColumn=-1;
            for(int j=i;j<n;j++) {
               if(sumc[j]>curMax) {
                   curMax=sumc[j];
                   curColumn=j ;
               }
            }
            // swap found row with left:
            if(curColumn!=i) {
                int s=sumc[curColumn];
                sumc[curColumn]=sumc[i];
                sumc[i]=s;
                arlist.add(new SwapData(i,curColumn,2))    ;
            }
        }
        out.println(arlist.size());
        for(int i=0;i<arlist.size();i++) {
            out.println(arlist.get(i).t+" "+(arlist.get(i).x+1)+" "+(arlist.get(i).y+1));
        }

    }
}

class SwapData {
    int x,y,t;

    SwapData(int x, int y, int t)
    {
        this.x = x;
        this.y = y;
        this.t = t;
    }
}

class InputReader {
    StringTokenizer st;
    BufferedReader in;
    public InputReader(InputStream ins)
    {
        in = new BufferedReader(new InputStreamReader(ins));
    }

    public String nextToken()
    {
        while(st==null || !st.hasMoreTokens())
        {
            try {
                st=new StringTokenizer(in.readLine());
            } catch (IOException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }
        return st.nextToken();
    }
    public int nextInt()
    {

        return Integer.parseInt(nextToken());
    }

    }


import java.util.*;
import java.io.*;

public class Round162Div2 {
	public static void main(String[] args) throws IOException {
		rd = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(System.out);
		N = Integer.parseInt(rd.readLine());
		A = new int[N][N];
		int[][] R = new int[N][N];
		int[][] C = new int[N][N];
		for(int i=0; i<N-1; i++){
			st = new StringTokenizer(rd.readLine());
			int x = -1+Integer.parseInt(st.nextToken()), y = -1+Integer.parseInt(st.nextToken());
			A[x][y] = 1;
		}
		for(int i=0; i<N; i++){
			R[i][N-1] = (A[i][N-1]==1? 1: 0);
			for(int a=N-2; a>=0; a--) R[i][a] = R[i][a+1] + (A[i][a]==1? 1: 0);
			C[i][N-1] = (A[N-1][i]==1? 1: 0);
			for(int j=N-2; j>=0; j--) C[i][j] = C[i][j+1] + (A[j][i]==1? 1: 0);
		}
		ArrayList<String> l = new ArrayList<String>();
		X = new int[N];
		Y = new int[N];
		int[] Z = new int[N];
		int k = 0;
		int[] r = new int[N];
		int[] c = new int[N];
		for(int i=0; i<N; i++){
			r[i] = R[i][0];
			c[i] = C[i][0];
		}
		for(int i=0; i<N-1; i++){
			for(int j=i; j<N; j++){
				if(r[j]==0){
					if(j==i){
						for(int d=i; d<N; d++){
							if(c[d]!=0){
								if(d==i) break;
								// swap columns (i, d).
								l.add(2+" "+(i+1)+" "+(d+1));
								X[k] = i;
								Y[k] = d;
								Z[k] = 2;

								for(int s=i; s<N; s++){
									if(A[s][d]==1) r[s]--;
								}

								int[] temp = new int[N];
								for(int s=0; s<N; s++) temp[s] = A[s][i];
								for(int s=0; s<N; s++) A[s][i] = A[s][d];
								for(int s=0; s<N; s++) A[s][d] = temp[s];

								int tc = c[i]; c[i] = c[d]; c[d] = tc;

								for(int s=i; s<N; s++) if(A[i][s]==1) c[s]--;

								break;
							}
						}
						break;
					}
					// swap rows (i, j).
					l.add(1+" "+(i+1)+" "+(j+1));
					X[k] = i;
					Y[k] = j;
					Z[k] = 1;

					for(int s=i; s<N; s++){
						if(A[j][s]==1) c[s]--;
					}

					int[] temp = new int[N];
					for(int s=0; s<N; s++) temp[s] = A[i][s];
					for(int s=0; s<N; s++) A[i][s] = A[j][s];
					for(int s=0; s<N; s++) A[j][s] = temp[s];

					int tr = r[i]; r[i] = r[j]; r[j] = tr;

					for(int s=i; s<N; s++) if(A[s][i]==1) r[i]--;

					break;
				}
			}
		}
		if(2>1){
			pw.println(l.size());
			for(int i=0; i<l.size(); i++) pw.println(l.get(i));
			pw.flush();
			return;
		}

		for(int i=0; i<N-1; i++){
			System.out.println("i: "+i);
			for(int j=i; j<N; j++){
				if(R[j][i]==0){
					if(j==i){
						System.out.println("here");
						// swap any column
						for(int d=i; d<N; d++){
							if(C[d][i]!=0){
								if(d==i) break;
								// swap d, i columns
								l.add(2+" "+(d+1)+" "+(i+1));
								System.out.println("add "+l.get(l.size()-1));
								X[k] = d;
								Y[k] = i;
								Z[k] = 2;
								int[] temp = new int[N];
								for(int z=0; z<N; z++){
									temp[z] = C[i][z];
								}
								for(int z=0; z<N; z++) C[i][z] = C[j][z];
								for(int z=0; z<N; z++) C[j][z] = temp[z];

								break;
							}
						}
						break;
					}
					int g = i+1, h = j+1;
					l.add(1+" "+g+" "+h);
					X[k] = i;
					Y[k] = j;
					Z[k] = 1;
					k++;
					System.out.println("add "+l.get(l.size()-1));
					int[] temp = new int[N];
					for(int x=0; x<N; x++) temp[x] = R[i][x];
					for(int x=0; x<N; x++) R[i][x] = R[j][x];
					for(int x=0; x<N; x++) R[j][x] = temp[x];
					break;
				}
			}
		}
		if(R[N-1][N-1]==1){
			for(int i=0; i<l.size(); i++){
				int a = X[i], b = Y[i];
				if(Z[i]==2){
				for(int d=0; d<N; d++){
					int temp = A[a][d];
					A[a][d] = A[b][d];
					A[b][d] = temp;
				}
				}
				else{
					for(int d=0; d<N; d++){
						int temp = A[d][a];
						A[d][a] = A[d][b];
						A[d][b] = temp;
					}
				}
			}
			for(int i=0; i<N; i++){
				int c1 = 0;
				for(int j=0; j<N; j++){
					if(A[j][i]!=0) c1++;
				}
				if(c1==0){
					l.add(2+" "+(i+1)+" "+N);
					pw.println(l.size());
					for(int x=0; x<l.size(); x++) pw.println(l.get(x));
					pw.flush();
					return;
				}
			}
		}
		pw.println(l.size());
		for(int i=0; i<l.size(); i++) pw.println(l.get(i));
		pw.flush();
	}

	static int N;
	static int[][] A;
	static int[] X, Y;

	static BufferedReader rd;
	static PrintWriter pw;
	static StringTokenizer st;
}


import java.util.*;
import java.io.*;

public class Round162Div2 {
	public static void main(String[] args) throws IOException {
		rd = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(System.out);
		N = Integer.parseInt(rd.readLine());
		A = new int[N][N];
		int[][] R = new int[N][N];
		int[][] C = new int[N][N];
		for(int i=0; i<N-1; i++){
			st = new StringTokenizer(rd.readLine());
			int x = -1+Integer.parseInt(st.nextToken()), y = -1+Integer.parseInt(st.nextToken());
			A[x][y] = 1;
		}
		for(int i=0; i<N; i++){
			R[i][N-1] = (A[i][N-1]==1? 1: 0);
			for(int a=N-2; a>=0; a--) R[i][a] = R[i][a+1] + (A[i][a]==1? 1: 0);
			C[i][N-1] = (A[N-1][i]==1? 1: 0);
			for(int j=N-2; j>=0; j--) C[i][j] = C[i][j+1] + (A[j][i]==1? 1: 0);
		}
		ArrayList<String> l = new ArrayList<String>();
		X = new int[N];
		Y = new int[N];
		int[] Z = new int[N];
		int k = 0;
		int[] r = new int[N];
		int[] c = new int[N];
		for(int i=0; i<N; i++){
			r[i] = R[i][0];
			c[i] = C[i][0];
		}
		for(int i=0; i<N-1; i++){
			for(int j=i; j<N; j++){
				if(r[j]==0){
					if(j==i){
						for(int d=i; d<N; d++){
							if(c[d]!=0){
								if(d==i){
									for(int s=0; s<N; s++){
										if(A[i][s]==1) c[s]--;
										if(A[s][i]==1) r[s]--;
									}
									break;
								}
								// swap columns (i, d).
								l.add(2+" "+(i+1)+" "+(d+1));
								X[k] = i;
								Y[k] = d;
								Z[k] = 2;

								for(int s=i; s<N; s++){
									if(A[s][d]==1) r[s]--;
								}

								int[] temp = new int[N];
								for(int s=0; s<N; s++) temp[s] = A[s][i];
								for(int s=0; s<N; s++) A[s][i] = A[s][d];
								for(int s=0; s<N; s++) A[s][d] = temp[s];

								int tc = c[i]; c[i] = c[d]; c[d] = tc;

								for(int s=i; s<N; s++) if(A[i][s]==1) c[s]--;
								if(r[i]==0){

								}

								break;
							}
						}
						break;
					}
					// swap rows (i, j).
					l.add(1+" "+(i+1)+" "+(j+1));
					X[k] = i;
					Y[k] = j;
					Z[k] = 1;

					for(int s=i; s<N; s++){
						if(A[j][s]==1) c[s]--;
					}

					int[] temp = new int[N];
					for(int s=0; s<N; s++) temp[s] = A[i][s];
					for(int s=0; s<N; s++) A[i][s] = A[j][s];
					for(int s=0; s<N; s++) A[j][s] = temp[s];

					int tr = r[i]; r[i] = r[j]; r[j] = tr;

					for(int s=i; s<N; s++) if(A[s][i]==1) r[s]--;
					if(c[i]==0){
						// need to swap i with some column
						for(int d=i+1; d<N; d++){
							if(c[d]!=0){
								// swap cols i, d
								l.add(2+" "+(i+1)+" "+(d+1));
								X[k] = i;
								Y[k] = d;
								Z[k] = 2;

								for(int s=i; s<N; s++){
									if(A[s][d]==1) r[s]--;
								}

								temp = new int[N];
								for(int s=0; s<N; s++) temp[s] = A[s][i];
								for(int s=0; s<N; s++) A[s][i] = A[s][d];
								for(int s=0; s<N; s++) A[s][d] = temp[s];

								int tc = c[i]; c[i] = c[d]; c[d] = tc;

			//					for(int s=i; s<N; s++) if(A[i][s]==1) c[s]--;
							}
						}

					}

					break;
				}
			}
		}
		if(2>1){
			if(A[N-1][N-1]==1){
				for(int i=0; i<N; i++){
					int c1 = 0;
					for(int j=0; j<N; j++){
						if(A[j][i]!=0) c1++;
					}
					if(c1==0){
						l.add(2+" "+(i+1)+" "+N);
						pw.println(l.size());
						for(int x=0; x<l.size(); x++) pw.println(l.get(x));
						pw.flush();
						return;
					}
				}
			}
			pw.println(l.size());
			for(int i=0; i<l.size(); i++) pw.println(l.get(i));
			pw.flush();
			return;
		}

		for(int i=0; i<N-1; i++){
			System.out.println("i: "+i);
			for(int j=i; j<N; j++){
				if(R[j][i]==0){
					if(j==i){
						System.out.println("here");
						// swap any column
						for(int d=i; d<N; d++){
							if(C[d][i]!=0){
								if(d==i) break;
								// swap d, i columns
								l.add(2+" "+(d+1)+" "+(i+1));
								System.out.println("add "+l.get(l.size()-1));
								X[k] = d;
								Y[k] = i;
								Z[k] = 2;
								int[] temp = new int[N];
								for(int z=0; z<N; z++){
									temp[z] = C[i][z];
								}
								for(int z=0; z<N; z++) C[i][z] = C[j][z];
								for(int z=0; z<N; z++) C[j][z] = temp[z];

								break;
							}
						}
						break;
					}
					int g = i+1, h = j+1;
					l.add(1+" "+g+" "+h);
					X[k] = i;
					Y[k] = j;
					Z[k] = 1;
					k++;
					System.out.println("add "+l.get(l.size()-1));
					int[] temp = new int[N];
					for(int x=0; x<N; x++) temp[x] = R[i][x];
					for(int x=0; x<N; x++) R[i][x] = R[j][x];
					for(int x=0; x<N; x++) R[j][x] = temp[x];
					break;
				}
			}
		}
		if(R[N-1][N-1]==1){
			for(int i=0; i<l.size(); i++){
				int a = X[i], b = Y[i];
				if(Z[i]==2){
				for(int d=0; d<N; d++){
					int temp = A[a][d];
					A[a][d] = A[b][d];
					A[b][d] = temp;
				}
				}
				else{
					for(int d=0; d<N; d++){
						int temp = A[d][a];
						A[d][a] = A[d][b];
						A[d][b] = temp;
					}
				}
			}
			for(int i=0; i<N; i++){
				int c1 = 0;
				for(int j=0; j<N; j++){
					if(A[j][i]!=0) c1++;
				}
				if(c1==0){
					l.add(2+" "+(i+1)+" "+N);
					pw.println(l.size());
					for(int x=0; x<l.size(); x++) pw.println(l.get(x));
					pw.flush();
					return;
				}
			}
		}
		pw.println(l.size());
		for(int i=0; i<l.size(); i++) pw.println(l.get(i));
		pw.flush();
	}

	static int N;
	static int[][] A;
	static int[] X, Y;

	static BufferedReader rd;
	static PrintWriter pw;
	static StringTokenizer st;
}


<?php
$brothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/$bagcount); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo "\n";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo PHP_EOL;
				}

	}

}else{
	echo" Your input is not even";
	}

?>


<?php
	// $input = "2";

    $input = trim(file_get_contents("php://stdin"));
    $input = $input- '0';
    $total_candy=0;
	$bag = pow($input, 2);
	for($i=1; $i<=$bag; $i++)
		$total_candy = $i+$total_candy;
	$fair_distribute = $total_candy/$input;

	for($j=1; $j<$input; $j++){
		echo $j.' '.($fair_distribute-$j).PHP_EOL;
	}
	echo ($j).' '.($fair_distribute-$j);


<?php
    // $input = "2";

    $input = trim(file_get_contents("php://stdin"));
    $input = $input- '0';
    $total_candy=0;
    $bag = pow($input, 2);
    for($i=1; $i<=$bag; $i++)
        $total_candy = $i+$total_candy;
    $fair_distribute = $total_candy/$input;

    $round=0;
    for($j=1; $j<=$bag/2;){
        $round=$input/2;
        while($round!=0){
            echo $j.' '.($bag-$j+1).' ';
            $round--;
            $j++;
        }
        echo PHP_EOL;
    }


<?php
    // $input = "2";

    $input = trim(file_get_contents("php://stdin"));
    $input = $input- '0';
    $total_candy=0;
    $bag = pow($input, 2);
    for($i=1; $i<=$bag; $i++)
        $total_candy = $i+$total_candy;
    $fair_distribute = $total_candy/$input;

    $round=0;
    for($j=1; $j<=$input*2;){
        $round=$input/2;
        while($round!=0){
            echo $j.' '.($bag-$j+1).' ';
            $round--;
            $j++;
        }
        echo PHP_EOL;
    }


<?php
    // $input = "2";

    $input = trim(file_get_contents("php://stdin"));
    $input = $input- '0';
    $total_candy=0;
    $bag = pow($input, 2);
    for($i=1; $i<=$bag; $i++)
        $total_candy = $i+$total_candy;
    $fair_distribute = $total_candy/$input;

    $round=0;
    for($j=1; $j<=$input*2; $j++){
        $round=$input/2;
        while($round!=0){
            echo $j.' '.($bag-$j+1).' ';
            $round--;
            $j++;
        }
        echo PHP_EOL;
    }


<?php
error_reporting("off");
//334A: Candy Bags
$n = trim(fgets(STDIN)); //$n = 6;
$candyboxes = pow($n, 2);
$halfway = $candyboxes / 2;
$sections = $halfway / $n;
$curindex = 1;
$brothers = array(); //multidimen
$answer = "";

//assign sections from the first half
for ($i = 1; $i <= $n; $i++) {
    $endofsection = (int)$curindex + (int)$sections - 1;
    $brothers[$i] = range($curindex, $endofsection);
    $curindex += $sections;
}

//now add their other halfs from the top half
$onehundredplusone = $candyboxes + 1;
foreach ($brothers as $key => $valuearray) {
    foreach ($valuearray as $value) {
        $brothers[$key][] = $onehundredplusone - $value;
    }
    $answer .= implode(" ", $brothers[$key])."\n";
}

echo $answer;
?>


<?php
error_reporting("off");
//334A: Candy Bags
$n = trim(fgets(STDIN)); $n = 6;
$candyboxes = pow($n, 2);
$halfway = $candyboxes / 2;
$sections = $halfway / $n;
$curindex = 1;
$brothers = array(); //multidimen
$answer = "";

//assign sections from the first half
for ($i = 1; $i <= $n; $i++) {
    $endofsection = (int)$curindex + (int)$sections - 1;
    $brothers[$i] = range($curindex, $endofsection);
    $curindex += $sections;
}

//now add their other halfs from the top half
$onehundredplusone = $candyboxes + 1;
foreach ($brothers as $key => $valuearray) {
    foreach ($valuearray as $value) {
        $brothers[$key][] = $onehundredplusone - $value;
    }
    $answer .= implode(" ", $brothers[$key])."\n";
}

echo $answer;
?>


import bisect
from collections import defaultdict
from collections import deque
import math
import re
import sys
import itertools

def ni():
    return int(raw_input())

def nis():
    return map(int, raw_input().split())

def si():
    return raw_input()

def sis():
    return raw_input().split()

def spaced(a):
    return ' '.join(map(str, a))

n = ni()

i = 1
j = n ** 2

for _ in range(n):
    bag = []
    for _ in range(n / 2):
        bag.append(i)
        bag.append(j)
        i += 1
        j -= 1
    print spaced(bag)


from itertools import *

n = int(raw_input())
m = [range((k-1)*n+1,k*n+1) for k in xrange(1,n+1)]
for j in xrange(n):
  e = [m[i][(i+j)%n] for i in xrange(n)]
  print ' '.join(imap(str, e))


if __name__ == '__main__':
    n = int(raw_input())

    bags = [str(i) for i in range(1, n**2+1)]

    for i in range(n):
        left, right = i*(n/2), (i+1)*(n/2)

        if i == 0:
            print ' '.join(bags[left:right]) + ' ' + ' '.join(bags[-right:])
        else:
            print ' '.join(bags[left:right]) + ' ' + ' '.join(bags[-right:-left])


import sys
if sys.subversion[0] == "PyPy":
    import io, atexit
    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()

RS = raw_input
RI = lambda x=int: map(x,RS().split())
RN = lambda x=int: x(RS())
''' ...................................................................... '''

n = RN()
arr = [[] for i in xrange(n)]

s=1
e=n*n

while s<e:
    for i in xrange(n):
        arr[i].extend([s,e])
        s+=1
        e-=1

for i in arr:
    print ' '.join(map(str,i))


from __future__ import division, print_function

DEBUG = 0

import os, sys
from atexit import register
from io import BytesIO
import itertools

if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

if DEBUG:
    debug_print = print
else:
    sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
    sys.stdout = BytesIO()
    register(lambda: os.write(1, sys.stdout.getvalue()))

    input = lambda: sys.stdin.readline().rstrip('\r\n')
    debug_print = lambda *x, **y: None

def input_as_list():
    return list(map(int, input().split()))

def array_of(f, *dim):
    return [array_of(f, *dim[1:]) for _ in range(dim[0])] if dim else f()

def main():
    n = int(input())
    idxs = list(range(1, n+1)) * 2

    for i in range(n):
        for j in range(n):
            print(n*j + idxs[i+j], end= ' ')
        print()

main()


'''input
4
'''

from collections import defaultdict as df
from bisect import bisect_left as bl
from itertools import combinations as c
import sys
from math import *
from random import randint as R
import heapq as hp
#import time

n=input()
for i in range(n):
	s=0
	for j in range(n/2):
		print i*n+1+j,n*n-i*n-j,
		#s+=i*n+1+j+n*n-i*n-j
	#print s
	print


n=input()
a,b=1,n**2
while a<b:
    print a,b
    a+=1
    b-=1


n = int(raw_input())
A = [i for i in xrange(1,n*n + 1)]
s = sum(A)/n;
for i in xrange(n):
	B = [];
	c = 1;
	t = 0;
	while t < s:
		if c : B.append(A.pop());
		else : B.append(A.pop(0));
		t += B[-1];
		c ^= 1;
	print " ".join([str(b) for b in B])


n = input()
for i in range(n):
    for j in range(n):
        print 1 + j*n + (i+j)%n,
print "\n"


n = input()
for i in range(n):
    for j in range(n):
        print 1 + j*n + (i+j)%n,
    print "\n"


n=int(input())
a=[]
for i in range(1,n**2+1) :
	a.append(i)
ans=[]
for i in range(0,n) :
	x,y=a[i],a[len(a)-1-i]
	ans.append(list([x,y]))
for i in range(len(ans)) :
	print(ans[i][0],ans[i][1],end='\n')


n=int(input())
a=[]
for i in range(1,n**2+1) :
	a.append(i)
ans=[]
print(len(a))
for i in range(0,n) :
	x,y=a[i],a[len(a)-1-i]
	ans.append(list([x,y]))
for i in range(len(ans)) :
	print(ans[i][0],ans[i][1],end='\n')


n=int(input())
a=[]
for i in range(1,n**2+1) :
	a.append(i)
ans=[]
for i in range(0,(n**2)//2,n//2) :
	put=[]
	for j in range(i,i+n//2) :
		put.append(a[j])
		put.append(a[len(a)-1-j])
	ans.append(put)
for i in range(len(ans)) :
	for j in range(0,n) :
		print(ans[i][j],end=" ")
	print()


n = int(input())
ans = [x for x in range(1,n*n+1)]
for i in range((n*n)//2):
	print(ans[i], ans[n*n-i-1])


n=(int)(input())
for i in range(n):
	print(i+1,n*n-i, sep=" ")


n = int(input())
for i in range(n*n//2):
    print(i+1, n*n-i)


#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
   ll a,b;
   cin>>a>>b;ll count=0,m=max(a,b),n=min(a,b);
   while(m&&n)
   {  if(m==n)break;
   count+=m/n;
     m=m%n;
     m=m+n;n=m-n;m=m-n;
   }cout<<count;
}


n=int(input())
ans=[[0]*(n) for i in range(n)]
cnt=1
for j in range(n):
    if j%2==0:
        for i in range(n):
            ans[i][j]=cnt
            cnt+=1
    else:
        for i in range(n-1,-1,-1):
            ans[i][j]=cnt
            cnt+=1
for i in ans:
    print(*i)


n = int(input())

total = n**2+1
cursor = 1

for i in range(n):
    for j in range(n//2):
        print('{} {}'.format(cursor, total-cursor), end=' ')
        cursor += 1
    print()


n = int(input().strip())
i = 1
j = n**2
while i < j:
	arr = [i, j]
	for x in range(n//2-1):
		i += 1
		j -= 1
		arr.append(i)
		arr.append(j)
	i += 1
	j -= 1
	print(*arr)


n=int(input())
ans=0
res=pow(n,2)//2
i=1
j=n**2
while i<=res and j>=res :
    print(i,j)
    i+=1
    j-=1


n = int(input())
start = 1
end = n*n
for i in range(1, n+1):
    bro = []
    for j in range(n//2):
        bro.append(start)
        start += 1
    for j in range(n//2):
        bro.append(end)
        end -= 1

    print(' '.join(map(str, bro)))


n=int(input())**2
k=0
for i in range(n//2):
    print(i+1,n-i,end=' ')
    k+=1
    if k%2==0:
        print()


n=int(input())
ar=[i for i in range(1,n**2+1)]
k=0
for i in range(n):
    k=i
    for j in range(n//2):
        print(k+1,n*n-k,end=' ')
        k+=1
    print()


n=int(input())
ar=[i for i in range(1,2*n+1)]
for i in range(n):
    print(ar[i],ar[2*n-1-i])


import math
from decimal import *
getcontext().prec = 30
n=int(input())
curr=1
for i in range(n):
    l=list()
    while len(l)<n:
        l.append(curr)
        l.append(n*n+1-curr)
        curr+=1
    print(*l)


n=int(input())
x=[i for i in range(1,n**2+1)]
for i in range(len(x)//2):
    print(x[i],x[-i-1])


n = int(input())
for i in range(1, n+1):
    for j in range(i, (n*n) // 2 + 1, n):
        print(j, end=' ')
    for j in range(n*n-i+1, (n*n) // 2 , -n):
        print(j, end=' ')
    print()


n = int(input())
for i in range(1, n+1):
    for j in range(i, n*n+1, n):
        print(j, end=' ')
    print()


n=int(input())
for i in range(1,n**2+1):
	print(i,n**2+1-i)


n=int(input())
for i in range((n*n)//2):
	print(i+1,n*n-i)


n=int(input())
for i in range(1,n+1):
	print(i,n**2+1-i)


n=int(input());q=n*n
for i in range(1,q//2+1,n//2):
    l=[]
    for j in range(i,i+n//2):
        l.append(j)
        l.append(q-j+1)
    print(*l)


n = int(input())

total_candy= ((n**2)/2)*(2+ (n**2)-1)

x= total_candy/n

for i in range(1,(n**2)+1):
    for j in range(i+1, (n**2)+1):
        if j==x-i:
            print(i,'',j)
            break


# candy bags
# hey stalker
n=int(input())
m=n*n
d=m//n
a=1
b=m
l=[]
while(a<b):
    l.append(a)
    l.append(b)
    a=a+1
    b=b-1
    if(len(l)==d):
        print(*l)
        l.clear()


n = int(input())
for i in range(n*n//2):
    print(i+1, n*n-1)


n = int(input())
for i in range(n*n//2):
    print(i+1, n*n-i)


n=int(input())
bags=n*n
arr=[[0]*n for x in range(n)]
i=1
r=0
c=0
direction=1
while i<bags:
	if direction:
		while r<n:
			# print(r,c)
			arr[r][c]=i
			r+=1
			i+=1
		direction^=1
	else:
		while r>0:
			# print(r,c)
			arr[r-1][c]=i
			r-=1
			i+=1
		direction^=1
	c+=1
for row in arr:
	for col in row:
		print(col,end=' ')
	print()


n = int(input())
candies = list(range(1,(n)**2+1))
j = len(candies)-1
k = 0
for i in range(0,n):
    out = [0]*n
    for x in range(n//2):
        out[x] = candies[k]
        k+=1
    for x in range(n-1,n//2-1,-1):
        out[x] = candies[j]
        j-=1
    print(*out)


from sys import stdin
n=int(stdin.readline().rstrip())
s=0
l=[]
for i in range(1,n*n+1):
    l.append(i)
for i in range((n*n)//2):
    print(str(l[i])+" "+str(l[n*n-1-i]))


n = int(input())
matrix = []
turn = 1
for i in range(1,n*n+1,n):
    if turn == 1:
        matrix.append( list(range(i,i+n)) )
        turn = 0
    else:
        matrix.append( list(range(i,i+n))[::-1] )
        turn = 1
res = []
col = len(matrix[0])
row = len(matrix)
for i in range( col ):
    res.append( [ matrix[j][i] for j in range( row )] )

for row in res:
    print(*row)


class CodeforcesTask334ASolution:
    def __init__(self):
        self.result = ''
        self.n = 0

    def read_input(self):
        self.n = int(input())

    def process_task(self):
        rr = 1 + self.n ** 2
        for x in range(self.n):
            candies = []
            for y in range(self.n // 2):
                candies.append((self.n // 2) * x + y + 1)
                candies.append(rr - (self.n // 2) * x - 1 - y)
            print(" ".join([str(z) for z in candies]))

    def get_result(self):
        return self.result

if __name__ == "__main__":
    Solution = CodeforcesTask334ASolution()
    Solution.read_input()
    Solution.process_task()
    print(Solution.get_result())


n = int(input())
for i in range(0,(n*n)//2,n//2):
	for j in range(n//2):
		print(j+1+i,n*n-j-i,end=' ')
	print('\t')


import math
from collections import defaultdict, Counter, deque

INF = float('inf')

def gcd(a, b):
	while b:
		a, b = b, a%b
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while (i ** 2) <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())

	s = (n * (n ** 2  + 1) // 2)

	arr = [i for i in range(1, n ** 2 + 1)]
	pairs = []
	i = 0
	j = len(arr) - 1
	while i < j:
		pairs.append([arr[i], arr[j]])
		i += 1
		j -= 1

	i = 0
	s = n // 2
	while i < len(pairs):
		for p in (pairs[i: i + s]):
			print(*p, end=' ')
		print()
		i += s

if __name__ == "__main__":
	# t = int(input())
	t = 1
	for _ in range(t):
		main()


"""
    author - Sayan Bose
    Brooklyn 99 is love!
"""

n = int(input())
li = [i for i in range(1, n * n + 1)]
index_start, index_end = 0, n * n - 1
for i in range(n):
    for j in range(n//2):
        print(li[index_start], end=' ')
        print(li[index_end], end=' ')
        index_start += 1
        index_end -= 1
    print('')


n=int(input())
m=n*n
a=1
while m>a:
    print(a,m)
    a+=1
    m-=1


n = int(input()); a = []; b = []; k = 0
for i in range(1,n**2+1): a.append(i)
for i in range(len(a)//2):
    b.append(a[i]); b.append(a[len(a)-i-1])
for i in range(len(b)):
    print(b[i],end = " ")
    if (k+1) % n == 0 and k != 0:
        print()
    k += 1


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt,gcd

# def time_t():
#     print("Current date and time: " , datetime.datetime.now())
#     print("Current year: ", datetime.date.today().strftime("%Y"))
#     print("Month of year: ", datetime.date.today().strftime("%B"))
#     print("Week number of the year: ", datetime.date.today().strftime("%W"))
#     print("Weekday of the week: ", datetime.date.today().strftime("%w"))
#     print("Day of year: ", datetime.date.today().strftime("%j"))
#     print("Day of the month : ", datetime.date.today().strftime("%d"))
#     print("Day of week: ", datetime.date.today().strftime("%A"))

def ip(): return int(sys.stdin.readline())

def sip(): return sys.stdin.readline()

def mip(): return map(int,sys.stdin.readline().split())

def mips(): return map(str,sys.stdin.readline().split())

def lip(): return list(map(int,sys.stdin.readline().split()))

def matip(n,m):
    lst=[]
    for i in range(n):
        arr = lip()
        lst.append(arr)
    return lst

def factors(n): # find the factors of a number
    return list(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))

def minJumps(arr, n): #to reach from 0 to n-1 in the array in minimum steps
    jumps = [0 for i in range(n)]
    if (n == 0) or (arr[0] == 0):
        return float('inf')
    jumps[0] = 0
    for i in range(1, n):
        jumps[i] = float('inf')
        for j in range(i):
            if (i <= j + arr[j]) and (jumps[j] != float('inf')):
                jumps[i] = min(jumps[i], jumps[j] + 1)
                break
    return jumps[n-1]

def dic(arr): # converting list into dict of count
    return Counter(arr)

def check_prime(n):
    if n<2:
        return False
    for i in range(2,int(n**(0.5))+1,2):
        if n%i==0:
            return False
    return True

# --------------------------------------------------------- #
# sys.stdin = open('input.txt','r')
# sys.stdout = open('output.txt','w')
# --------------------------------------------------------- #

n = ip()
z = n*n
count = 1
for i in range(n):
    arr = []
    for i in range(n//2):
        arr.append(count)
        arr.append(z)
        count+=1
        z-=1
    print(*arr)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt,gcd

# def time_t():
#     print("Current date and time: " , datetime.datetime.now())
#     print("Current year: ", datetime.date.today().strftime("%Y"))
#     print("Month of year: ", datetime.date.today().strftime("%B"))
#     print("Week number of the year: ", datetime.date.today().strftime("%W"))
#     print("Weekday of the week: ", datetime.date.today().strftime("%w"))
#     print("Day of year: ", datetime.date.today().strftime("%j"))
#     print("Day of the month : ", datetime.date.today().strftime("%d"))
#     print("Day of week: ", datetime.date.today().strftime("%A"))

def ip(): return int(sys.stdin.readline())

def sip(): return sys.stdin.readline()

def mip(): return map(int,sys.stdin.readline().split())

def mips(): return map(str,sys.stdin.readline().split())

def lip(): return list(map(int,sys.stdin.readline().split()))

def matip(n,m):
    lst=[]
    for i in range(n):
        arr = lip()
        lst.append(arr)
    return lst

def factors(n): # find the factors of a number
    return list(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))

def minJumps(arr, n): #to reach from 0 to n-1 in the array in minimum steps
    jumps = [0 for i in range(n)]
    if (n == 0) or (arr[0] == 0):
        return float('inf')
    jumps[0] = 0
    for i in range(1, n):
        jumps[i] = float('inf')
        for j in range(i):
            if (i <= j + arr[j]) and (jumps[j] != float('inf')):
                jumps[i] = min(jumps[i], jumps[j] + 1)
                break
    return jumps[n-1]

def dic(arr): # converting list into dict of count
    return Counter(arr)

def check_prime(n):
    if n<2:
        return False
    for i in range(2,int(n**(0.5))+1,2):
        if n%i==0:
            return False
    return True

# --------------------------------------------------------- #
# sys.stdin = open('input.txt','r')
# sys.stdout = open('output.txt','w')
# --------------------------------------------------------- #

n = ip()
count = 1
for i in range(n):
    for j in range(n):
        print(count, end = ' ')
        count+=1
    print()


n = int(input())
a = [1]*(n+10)
s = (n(n**2+1))//2
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            if(i+j+k==s and (a[i] and a[j] and a[k])):
                print(i,j,k)


n = int(input())
for i in range((n*n)//2):
    print(i+1,n*n-i)


k=int(input());a=1;b=k**2
for i in range(k):
    print(a,b);a+=1;b-=1


n=int(input())
d=[i for i in range(1,pow(n,2)+1)]
total=(pow(n,2)+1)*n//2
for i in range(n-1):
    t=0
    ans=[]
    while(t<n-1):
        if t%2==0 :
            ans.append(d.pop(0))
        else:
            ans.append(d.pop())
        t+=1
    z=sum(ans)
    ans.append(total-z)
    d.remove(total-z)
    print(*ans)
print(*d)


n = int(input())
p1 = 1
p2 = n*n
for i in range(n):
    for j in range(int(n//2)):
        print(p1,end=" ")
        print(p2,end = " ")
        p1+=1
        p2-=1
    print()


n = int(input())

k = n*n
i = 1
while i != k:
    print(f'{i} {n}')
    i += 1
    k -= 1


n = int(input())

k = n*n
i = 1
while i < k:
    print(f'{i} {k}')
    i += 1
    k -= 1


N = int(input())
if N % 2 == 0:
    bags = [[] for i in range(N)]
    mid = (N * N) // 2
    for i in range(mid):
        bags[i % N].append(mid + i + 1)
        bags[i % N].append(mid - i)
    for bag in bags:
        print(*bag)
else:
    count = (N - 1) // 2
    mid = (N * N + 1) // 2
    LHS = (N + 1) // 2
    RHS = N - LHS
    S = ((N + 1) * (2*N + 1)) // 6
    bags = [[] for i in range(count)]
    for i in range(count):
        LS = LHS * (((mid - i - 1) + (mid - i - 1 - (N - 1) * (LHS - 1))) // 2)
        for j in range(LHS):
            bags[i].append(mid - i - 1 - (N - 1) * j)
        for j in range(RHS//2):
            bags[i].append(N*N - i, S - LS - N * N + i)
    print(bags)


n = int(input())
x = 1
y = 2 * n
for i in range(n):
    print(x, y)
    x += 1
    y -= 1


n = int(input())
x = 1
y = n * n
s = ""
for i in range(n):
    for j in range(n // 2):
        s += str(x) + " " + str(y) + " "
        x += 1
        y -= 1
    print(s)
    s = ""


#https://codeforces.com/problemset/problem/334/A
n=int(input())
l=list(range(1,n**2+1))
s,e=0,n**2-1
for _ in range(n):
	print(*l[s:s+n//2],*l[e-n//2+1:e+1])
	s+=(n//2)
	e-=(n//2)


n = int(input())
i = 1
j = n**2
for k in range(n):
    print(i,j)
    i+=1
    j-=1

'''
n = int(input())
a = list(map(int,input().split()))
b = a.copy()
c = a.copy()
b.remove(max(b))
c.remove(min(c))

print(min(max(b)-min(b),max(c)-min(c)))

'''


n = int(input())
i = 1
j = n**2
for k in range(n):
    for y in range(n//2):
        print(i,j,end=" ")
        i+=1
        j-=1
    print()

'''
n = int(input())
a = list(map(int,input().split()))
b = a.copy()
c = a.copy()
b.remove(max(b))
c.remove(min(c))

print(min(max(b)-min(b),max(c)-min(c)))

'''


n=int(input())
a=[int (i) for i in range(1,2*n+1)]
i=0
j=len(a)-1
while(j>i):
    print(a[i],a[j])
    j-=1
    i+=1


n=int(input());q=n*n
for i in range(1,q//2+1,n//2):
    l=[]
    for j in range(i,i+n//2):
        l.append(j)
        l.append(q-j+1)
    print(*l)


n = int(input())
square = n*n
for i in range(n):
    print(str(i+1)+' '+str(square-i))


n = int(input())
offset = int(n/2)
list = []
front = 1
last = n*n

for i in range(n):
    for j in range(offset):
        print(front,end=' ')
        front+=1
    for j in range(offset):
        print(last,end=' ')
        last-=1
    print()


from sys import stdin
input = stdin.readline

n = int(input())
l = sorted(list(map(int, input().split()))).
x1, x2 = [], []
for i in l:
    if x1[-1] == i and x2[-1] == i:
        print('NO')
        exit()
    if x1[-1] == i:
        x2.append(i)
    else:
        x1.append(i)
x2 = x2[::-1]
print('YES')
print(len(x1))
print(*x1)
print(len(x2))
print(*x2)


from sys import stdin
input = stdin.readline

n = int(input())
l = sorted(list(map(int, input().split())))
x1, x2 = [], []
for i in l:
    if len(x2) and len(x2) and x1[-1] == i and x2[-1] == i:
        print('NO')
        exit()
    if len(x1) and x1[-1] == i:
        x2.append(i)
    else:
        x1.append(i)
x2 = x2[::-1]
print('YES')
print(len(x1))
print(*x1)
print(len(x2))
print(*x2)


n = int(input())
l = sorted(list(map(int, input().split())))
for i in l:
    if l.count(i) > 2:
        print('NO')
        exit()
x1 = []
x2 = []
for i in l:
    if i not in x1:
        x1.append(i)
    else:
        x2.append(i)
x2 = x2[::-1]
print('YES')
print(len(x1))
print(*x1)
print(len(x2))
print(*x2)


from sys import stdin
input = stdin.readline

n = int(input())
l = sorted(list(map(int, input().split())))
for i in l:
    if l.count(i) > 2:
        print('NO')
        exit()
x1 = []
x2 = []
for i in l:
    if i not in x1:
        x1.append(i)
    else:
        x2.append(i)
x2 = x2[::-1]
print('YES')
print(len(x1))
print(*x1)
print(len(x2))
print(*x2)


"""609C"""
# import math
# import sys
def  main():
	n = int(input())
	a = list(map(int,input().split()))
	d = {}
	for i in range(n):
		if d.get(a[i])==None:
			d[a[i]]=1
		else:
			d[a[i]]+=1
	arr = []
	arr2 = []
	for x in d:
		if d[x]>=3:
			print("NO")
			return
		elif d[x]>1:
			# d[x]-=1
			arr.append(x)
		arr2.append(x)
	arr.sort()
	arr2.sort(reverse=True)
	print("YES")
	print(len(arr))
	for x in arr:
		print(x,end=' ')
	print()
	print(len(arr2))
	for x in arr2:
		print(x,end=' ')
	print()

	return

main()
# def test():
# 	t= int(input())
# 	while t:
# 		main()
# 		t-=1
# test()


"""609C"""
# import math
# import sys
def  main():
	n = int(input())
	a = list(map(int,input().split()))
	d = {}
	for i in range(n):
		if d.get(a[i])==None:
			d[a[i]]=1
		else:
			d[a[i]]+=1
	arr = []
	arr2 = []
	for x in d:
		if d[x]>=3:
			print("NO")
			return
		elif d[x]>1:
			# d[x]-=1
			arr.append(x)
		arr2.append(x)
	arr.sort()
	arr2.sort(reverse=True)
	print(len(arr))
	for x in arr:
		print(x,end=' ')
	print()
	print(len(arr2))
	for x in arr2:
		print(x,end=' ')
	print()

	return

main()
# def test():
# 	t= int(input())
# 	while t:
# 		main()
# 		t-=1
# test()


n = int(input())
l = sorted(list(map(int, input().split())))
if n != 1:
    l1 = []
    l2 = []
    ok = True
    l1.append(l[0])

    for i in range(1, n):
        if l[i - 1] != l[i]:
            l1.append(l[i])
        else:
            l2.append(l[i])

    for i in range(1, len(l2)):
        if l[i - 1] == l[i]:
            ok = False;
            break;

    if not ok:
        print("NO")
    else:
        print("YES")
        print(len(l1))
        print(*l1)
        print(len(l2))
        print(*l2[::-1])
else:
    print("YES")
    print(1)
    print(*l)
    print(0)
    print()


n = int(input())
l = sorted(list(map(int, input().split())))
if n != 1:
    l1 = []
    l2 = []
    ok = True
    l1.append(l[0])

    for i in range(1, n):
        if l[i - 1] != l[i]:
            l1.append(l[i])
        else:
            l2.append(l[i])

    for i in range(1, len(l2)):
        if l2[i - 1] == l2[i]:
            ok = False;
            break;

    if not ok:
        print("NO")
    else:
        print("YES")
        print(len(l1))
        print(*l1)
        print(len(l2))
        print(*l2[::-1])
else:
    print("YES")
    print(1)
    print(*l)
    print(0)
    print()


n = int(input())
l = sorted(list(map(int, input().split())))
l1 = []
l2 = []
ok = True
if l[0] == l[1]:
    l2.append(l[0])
else:
    l1.append(l[0])
for i in range(1, n):
    if l[i - 1] != l[i]:
        l1.append(l[i])
    else:
        l2.append(l[i])
for i in range(1, len(l2)):
    if l[i - 1] == l[i]:
        ok = False;
        break;

if not ok:
    print("NO")
else:
    print("YES")
    print(len(l1))
    print(*l1)
    print(len(l2))
    print(*l2[::-1])


n = int(input())
l = sorted(list(map(int, input().split())))
l1 = []
l2 = []
ok = True
if l[0] == l[1]:
    l2.append(l[0])
else:
    l1.append(l[0])
for i in range(1, n):
    if l[i - 1] != l[i]:
        l1.append(l[i])
    else:
        l2.append(l[i])
for i in range(len(l2)):
    if l[i - 1] == l[i]:
        ok = False;
        break;

if not ok:
    print("NO")
else:
    print("YES")
    print(len(l1))
    print(*l1)
    print(len(l2))
    print(*l2[::-1])


n = int(input())
z = tuple(map(int, input().split()))
a = set()
b = set()
for x in z:
    if x not in a:
        a.add(x)
    elif x not in b:
        b.add(x)
    else:
        print("NO")
        exit()
print("YES")
print(len(b))
print(*sorted(b))
print(len(a))
print(*sorted(a, reverse= True))


from collections import Counter
n = int(input())
a = sorted(list(map(int, input().split())))
c = Counter(a)
for value, key in c.items():
    if key > 2:
        print('NO')
        exit()

inc = list(set(a))
for i in inc:
    if i in a:
        a.remove(i)
inc.reverse()
print('YES')
print(len(a))
print(*a)
print(len(inc))
print(*inc)


n = int(input())
l1 = [int(x) for x in input().split()]
l2 = l1.copy()
l2.sort()
targ = l2[0]
i=1
first=[targ]
l2[0]=-1
while i<len(l2):
    if l2[i]>targ:
        first.append(l2[i])
        targ = l2[i]
        l2[i]=-1
    i+=1
l2 = [x for x in l2 if x!=-1]
if l2:

    targ = l2[0]
    i=1
    second=[targ]
    l2[0]=-1
    while i<len(l2):
        if l2[i]>targ:
            second.append(l2[i])
            targ = l2[i]
            l2[i]=-1
        i+=1
    l2 = [x for x in l2 if x!=-1]
    if not l2:
        print("YES")
        print(len(first))
        print(*first)
        print(len(second))
        second.reverse()
        print(*second)
    else:
        print("NO")

    #print(first,second)
else:
    print("YES")
    print(len(first))
    print(*first)
    print(0)
    print()


n = int(input())
l1 = [int(x) for x in input().split()]
l2 = l1.copy()
l2.sort()
targ = l2[0]
i=1
first=[targ]
l2[0]=-1
while i<len(l2):
    if l2[i]>targ:
        first.append(l2[i])
        targ = l2[i]
        l2[i]=-1
    i+=1
l2 = [x for x in l2 if x!=-1]
targ = l2[0]
i=1
second=[targ]
l2[0]=-1
while i<len(l2):
    if l2[i]>targ:
        second.append(l2[i])
        targ = l2[i]
        l2[i]=-1
    i+=1
l2 = [x for x in l2 if x!=-1]
#print(l2)
if len(l2):
    print("NO")
else:
    print("YES")
    print(len(first))
    print(*first)
    print(len(second))
    second.reverse()
    print(*second)

#print(first,second)


n = int(input())
l1 = [int(x) for x in input().split()]
l2 = l1.copy()
l2.sort()
targ = l2[0]
i=1
first=[targ]
l2[0]=-1
while i<len(l2):
    if l2[i]>targ:
        first.append(l2[i])
        targ = l2[i]
        l2[i]=-1
    i+=1
l2 = [x for x in l2 if x!=-1]
targ = l2[0]
i=1
second=[targ]
l2[0]=-1
while i<len(l2):
    if l2[i]>targ:
        second.append(l2[i])
        targ = l2[i]
        l2[i]=-1
    i+=1
l2 = [x for x in l2 if x!=-1]
#print(l2)
if len(l2):
    print("NO")
else:
    print("YES")
    print(len(first))
    print(*first)
    print(len(second))
    print(*second)

#print(first,second)


from sys  import stdin,stdout
from collections import Counter
st=lambda:list(stdin.readline().strip())
li=lambda:list(map(int,stdin.readline().split()))
mp=lambda:map(int,stdin.readline().split())
inp=lambda:int(stdin.readline())
pr=lambda n: stdout.write(str(n)+"\n")

mod=1000000007
def solve():
    n=inp()
    l=li()
    d=Counter(l)
    for i in d:
        if d[i]>2:
            pr('NO')
            return
    l.sort()
    x=[]
    y=[]
    for i in range(n):
        if i&1:
            x.append(l[i])
        else:
            y.append(l[i])
    print('YES')
    print(len(x))
    print(*x)
    print(len(y))
    print(*y[::-1])

for _ in range(1):
    solve()


n = int(input())
arr = [int(x) for x in input().split()]
dic1 = {}
dic2 = {}

temp = 0
for i in arr:
    if(i not in dic1):
        dic1[i]=1
    else:
        if(i not in dic2):
            dic2[i] = 1
        else:
            print("NO")
            temp = 1
            break

if(temp ==0):
    print("YES")
    print(len(dic1))
    if(len(dic2) == 0):
        print(" ", end = " ")
    dic1 = sorted(dic1)
    for i in dic1:
        print(i,end = " ")

    dic2 = sorted(dic2)
    print(" ")
    print(len(dic2))
    if(len(dic2) == 0):
        print(" ")
    dic2 = dic2[::-1]
    for i in dic2:
        print(i, end = " ")


n = int(input())
arr = [int(x) for x in input().split()]
dic1 = {}
dic2 = {}

temp = 0
for i in arr:
    if(i not in dic1):
        dic1[i]=1
    else:
        if(i not in dic2):
            dic2[i] = 1
        else:
            print("NO")
            temp = 1
            break

if(temp ==0):
    print("YES")
    print(len(dic1))
    if(len(dic2) == 0):
        print(" ", end = " ")
    dic1 = sorted(dic1)
    for i in dic1:
        print(i,end = " ")

    dic2 = sorted(dic2)
    print(" ")
    print(len(dic2))
    if(len(dic2) == 0):
        print(" ")
    for i in dic2:
        print(i, end = " ")


n = int(input())
arr = [int(x) for x in input().split()]
dic1 = {}
dic2 = {}

temp = 0
for i in arr:
    if(i not in dic1):
        dic1[i]=1
    else:
        if(i not in dic2):
            dic2[i] = 1
        else:
            print("NO")
            temp = 1
            break

if(temp ==0):
    print("YES")
    print(len(dic1))
    if(len(dic2) == 0):
        print(" ")
    print(sorted(dic1))

    dic2 = sorted(dic2)
    print(len(dic2))
    if(len(dic2) == 0):
        print(" ")
    print(dic2[::-1])


n = int(input())
l = list([int(x) for x in input().split()])

l.sort()
tmp = set(l)

il = []
dl = []

for i in tmp:
    il.append(i)
    l.remove(i)

tmp = set(l)
for i in tmp:
    dl.append(i)
    l.remove(i)

dl.reverse()

if(len(l) != 0):
    print('NO')
else:
    print('YES')
    print(len(il))
    print(*il)
    print(len(dl))
    print(*dl)


from collections import defaultdict
import sys
n = int(input())
l = list([int(x) for x in input().split()])

il = []
dl = []

count = defaultdict(int)

for i in range(n):
    if(count[l[i]] == 2):
        print('NO')
        sys.exit()
    elif(count[l[i]] == 0):
        il.append(l[i])
    elif(count[l[i]] == 1):
        dl.append(l[i])
    count[l[i]] += 1
il.sort()
dl.sort(reverse=True)

print('YES')
print(len(il))
print(*il)
print(len(dl))
print(*dl)


n = int(input())
arr = list(map(int, input().split()))
counter = dict()
for i in arr:
    if i in counter:
        counter[i]+= 1
    else:
        counter[i] = 1
if any(j for j in counter.values() if j>2):
    print('NO')
else:
    arr1 = [i for i in counter]
    arr2 = [i for i in counter if counter[i]>1]
    arr1.sort()
    arr2 = sorted(arr2, reverse = True)
    print('YES')
    print(len(arr1))
    print(*arr1)
    print(len(arr2))
    print(*arr2)


import sys
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)
str = 0
for i in range(1, n):
	if l[i] == l[i - 1]:
		str += 1
	if str > 1:
		print("NO")
		sys.exit(0)
	if l[i] != l[i - 1]:
		str = 0
occ = [0] * n
new = l[0]
occ[0] = 1
le = 1
for i in range(1, n):
	if l[i] > new:
		new = l[i]
		occ[i] = 1
		le += 1
print(le)
for i in range(n):
	if occ[i] == 1:
		print(l[i], end = " ")
print( "")
print(n - le, end = "\n")
for i in range(n):
	if occ[n - i - 1] == 0:
		print(l[n - i - 1], end = " ")


import sys
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)
str = 0
for i in range(1, n):
	if l[i] == l[i - 1]:
		str += 1
	if str > 1:
		print("NO")
		sys.exit(0)
	if l[i] != l[i - 1]:
		str = 0
occ = [0] * n
new = l[0]
le = 0
for i in range(1, n):
	if l[i] > new:
		new = l[i]
		occ[i] = 1
		le += 1
print(le)
for i in range(n):
	if occ[i] == 1:
		print(l[i], end = " ")
print( "")
print(n - le, end = "\n")
for i in range(n):
	if occ[n - i - 1] == 0:
		print(l[n - i - 1], end = " ")


import sys
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)
str = 0
for i in range(1, n):
	if l[i] == l[i - 1]:
		str += 1
	if str > 1:
		print("NO")
		sys.exit(0)
	if l[i] != l[i - 1]:
		str = 0
occ = [0] * n
new = l[0]
occ[0] = 1
le = 1
for i in range(1, n):
	if l[i] > new:
		new = l[i]
		occ[i] = 1
		le += 1
print("YES")
print(le)
for i in range(n):
	if occ[i] == 1:
		print(l[i], end = " ")
print( "")
print(n - le, end = "\n")
if n - le == 0:
	print("")
for i in range(n):
	if occ[n - i - 1] == 0:
		print(l[n - i - 1], end = " ")


import sys
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)
str = 0
for i in range(1, n):
	if l[i] == l[i - 1]:
		str += 1
	if str > 1:
		print("NO")
		sys.exit(0)
	if l[i] != l[i - 1]:
		str = 0
occ = [0] * n
new = l[0]
occ[0] = 1
le = 1
for i in range(1, n):
	if l[i] > new:
		new = l[i]
		occ[i] = 1
		le += 1
print(le)
for i in range(n):
	if occ[i] == 1:
		print(l[i], end = " ")
print( "")
print(n - le, end = "\n")
if n - le == 0:
	print("")
for i in range(n):
	if occ[n - i - 1] == 0:
		print(l[n - i - 1], end = " ")