import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Q136D implements Runnable {
    int[] x = new int[8];
    int[] y = new int[8];

    private void solve() throws IOException {
        for (int i = 0; i < 8; i++) {
            x[i] = nextInt();
            y[i] = nextInt();
        }
        for (int i = 15; i < (1 << 8); i++) {
            BigInteger bits = BigInteger.valueOf(i);
            if (bits.bitCount() == 4) {
                int pc = 0;
                int zc = 0;
                int[] p = new int[4];
                int[] z = new int[4];
                for (int s = 0; s < 8; s++) {
                    if (bits.testBit(s)) p[pc++] = s;
                    else z[zc++] = s;
                }

                if (isPR(p) && isPR(z)) {
                    int[] res = null;
                    int[] res2 = null;
                    if (isSQ(p)) {
                        res = p;
                        res2 = z;
                    } else if (isSQ(z)) {
                        res = z;
                        res2 = p;
                    }

                    if (res != null) {
                        writer.println("YES");
                        for (int q = 0; q < 4; q++) {
                            writer.print(res[q] + 1);
                            if (q < 3) writer.print(" ");
                        }
                        writer.println();
                        for (int q = 0; q < 4; q++) {
                            writer.print(res2[q] + 1);
                            if (q < 3) writer.print(" ");
                        }
                        return;
                    }
                }
            }
        }
        writer.print("NO");
    }

    private boolean isSQ(int[] p) {
        return isSQ(p, 1, 2, 3, 4) ||
                isSQ(p, 1, 2, 4, 3) ||
                isSQ(p, 1, 3, 2, 4);
    }

    private boolean isSQ(int[] p, int x1, int x2, int x3, int x4) {
        double d12 = dist(p, x1, x2);
        double d23 = dist(p, x2, x3);
        double d34 = dist(p, x3, x4);
        double d14 = dist(p, x1, x4);
        if (eq(d12, d23) && eq(d23, d34) && eq(d34, d14) && eq(d14, d12)) {
            if (eq(dot(p, x2, x1, x3) / (d12 * d23), 0) &&
                    eq(dot(p, x3, x2, x4) / (d23 * d34), 0) &&
                    eq(dot(p, x4, x3, x1) / (d34 * d14), 0) &&
                    eq(dot(p, x1, x4, x2) / (d14 * d12), 0)) {
                return true;
            }
        }
        return false;
    }

    private boolean isPR(int[] p) {
        return isPR(p, 1, 2, 3, 4) ||
                isPR(p, 1, 2, 4, 3) ||
                isPR(p, 1, 3, 2, 4);
    }

    double dist(int[] p, int x1, int x2) {
        int xx = x[p[x1-1]] - x[p[x2-1]];
        int yy = y[p[x1-1]] - y[p[x2-1]];
        return Math.sqrt(xx * xx + yy * yy);
    }

    private boolean isPR(int[] p, int x1, int x2, int x3, int x4) {
        double d12 = dist(p, x1, x2);
        double d23 = dist(p, x2, x3);
        double d34 = dist(p, x3, x4);
        double d14 = dist(p, x1, x4);
        if (eq(d12, d34) && eq(d23, d14)) {
            if (eq(dot(p, x2, x1, x3) / (d12 * d23), 0) &&
                    eq(dot(p, x3, x2, x4) / (d23 * d34), 0) &&
                    eq(dot(p, x4, x3, x1) / (d34 * d14), 0) &&
                    eq(dot(p, x1, x4, x2) / (d14 * d12), 0)) {
                return true;
            }
        }
        return false;
    }

    private boolean eq(double x1, double x2) {
        return Math.abs(x1 - x2) < 0.0000001;
    }

    //|A||B|Cos(θ)
    //Compute the dot product AB ⋅ BC
    int dot(int[] p, int x1, int x2, int x3) {
        int[] AB = new int[2];
        int[] BC = new int[2];
        AB[0] = x[p[x2-1]] - x[p[x1-1]];
        AB[1] = y[p[x2-1]] - y[p[x1-1]];
        BC[0] = x[p[x3-1]] - x[p[x1-1]];
        BC[1] = y[p[x3-1]] - y[p[x1-1]];
        int dot = AB[0] * BC[0] + AB[1] * BC[1];
        return dot;

        /*
*
AB[0] = B[0] - A[0];
AB[1] = B[1] - A[1];
AC[0] = C[0] - A[0];
AC[1] = C[1] - A[1];
int cross = AB[0] * AC[1] - AB[1] * AC[0];*/
    }

    public static void main(String[] args) {
        new Q136D().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            boolean oj = System.getProperty("ONLINE_JUDGE") != null;
            reader = oj ? new BufferedReader(new InputStreamReader(System.in)) :
                    new BufferedReader(new FileReader(new File("input.txt")));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            long start = System.currentTimeMillis();
            solve();
            reader.close();
            if (!oj) writer.print("\nTime: " + (System.currentTimeMillis() - start) + "\n");
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


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

public class Main {
	boolean eof;

	public String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "-1";
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(nextToken());
	}

	public static int comp(double a, double b) {
		double eps = 1e-9;
		if (Math.abs(a - b) < eps)
			return 0;
		else if (a - b > eps)
			return 1;
		else
			return -1;
	}

	class Point implements Comparable<Point> {
		int x, y, id;

		Point(int x, int y, int id) {
			this.x = x;
			this.y = y;
			this.id = id;
		}

		public int compareTo(Point p) {
			if (polarAngle() > p.polarAngle()) {
				return 1;
			} else {
				return -1;
			}
		}

		public double polarAngle() {
			double a = Math.atan2(y, x);
			if (a < 0) {
				a += 2 * Math.PI;
			}
			return a;
		}

		public double dotProduct(Point v) {
			return x * v.x + y * v.y;
		}

		public double crossProduct(Point v) {
			return x * v.y - y * v.x;
		}

		public Point vector(Point p) {
			return new Point(p.x - x, p.y - y, 0);
		}

		public double distance(Point p) {
			return Math.sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
		}
	}

	boolean sq(int [] b){
		for (int i = 0; i < 4; ++i){
			if (a[b[i]].vector(a[b[(i - 1 + 4) % 4]]).dotProduct(a[b[i]].vector(a[b[(i + 1) % 4]])) != 0
					&& comp(a[b[i]].distance(a[b[(i + 1) % 4]]),
					a[b[(i + 1) % 4]].distance(a[b[(i + 2) % 4]])) == 0){
				return false;
			}
		}
		return a[b[0]].vector(a[b[1]]).crossProduct(a[b[0]].vector(a[b[3]])) != 0;
	}

	boolean rect(int [] b){
		for (int i = 0; i < 4; ++i){
			if (a[b[i]].vector(a[b[(i - 1 + 4) % 4]]).dotProduct(a[b[i]].vector(a[b[(i + 1) % 4]])) != 0){
				return false;
			}
		}
		return a[b[0]].vector(a[b[1]]).crossProduct(a[b[0]].vector(a[b[3]])) != 0;
	}

	boolean ok(int[] o) {
		boolean[] us = new boolean[8];

		for (int i = 0; i < 4; ++i) {
			us[o[i]] = true;
		}

		int[] b = new int[4];
		int k = 0;
		for (int i = 0; i < 8; ++i) {
			if (!us[i]) {
				b[k++] = i;
			}
		}
		if (sq(o) && rect(b)) {
			out.println("YES");
			for (int i = 0; i < 4; ++i) {
				out.print((a[o[i]].id + 1) + " ");
			}
			out.println();
			for (int i = 0; i < 4; ++i) {
				out.print((a[b[i]].id + 1) + " ");
			}
			return true;
		}
		return false;
	}

	Point[] a;

	void solve() {
		a = new Point[8];
		int min = 0;
		for (int i = 0; i < 8; ++i) {
			a[i] = new Point(nextInt(), nextInt(), i);
			if (a[i].y < min) {
				min = a[i].y;
			}
		}

		for (int i = 0; i < 8; ++i) {
			a[i].y += -min;
		}
		Arrays.sort(a);

		for (int i = 0; i < 5; ++i) {
			for (int j = i + 1; j < 6; ++j) {
				for (int k = j + 1; k < 7; ++k) {
					for (int l = k + 1; l < 8; ++l) {
						int[] o = new int[4];
						o[0] = i;
						o[1] = j;
						o[2] = k;
						o[3] = l;
						if (ok(o)) {
							return;
						}
					}
				}
			}
		}
		out.print("NO");
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));

			// br = new BufferedReader(new FileReader("input.txt"));
			// out = new PrintWriter(new FileWriter("output.txt"));
			solve();
			br.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


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

public class Main {
	boolean eof;

	public String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "-1";
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(nextToken());
	}

	public static int comp(double a, double b) {
		double eps = 1e-9;
		if (Math.abs(a - b) < eps)
			return 0;
		else if (a - b > eps)
			return 1;
		else
			return -1;
	}

	class Point implements Comparable<Point> {
		int x, y, id;

		Point(int x, int y, int id) {
			this.x = x;
			this.y = y;
			this.id = id;
		}

		public int compareTo(Point p) {
			if (polarAngle() > p.polarAngle()) {
				return 1;
			} else {
				return -1;
			}
		}

		public double polarAngle() {
			double a = Math.atan2(y, x);
			if (a < 0) {
				a += 2 * Math.PI;
			}
			return a;
		}

		public double dotProduct(Point v) {
			return x * v.x + y * v.y;
		}

		public double crossProduct(Point v) {
			return x * v.y - y * v.x;
		}

		public Point vector(Point p) {
			return new Point(p.x - x, p.y - y, 0);
		}

		public double distance(Point p) {
			return Math.sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
		}
	}

	boolean sq(int[] b) {
		for (int i = 0; i < 4; ++i) {
			if (a[b[i]].vector(a[b[(i - 1 + 4) % 4]]).dotProduct(
					a[b[i]].vector(a[b[(i + 1) % 4]])) != 0
					&& comp(a[b[i]].distance(a[b[(i + 1) % 4]]),
							a[b[(i + 1) % 4]].distance(a[b[(i + 2) % 4]])) == 0) {
				return false;
			}
		}
		return a[b[0]].vector(a[b[1]]).crossProduct(a[b[0]].vector(a[b[3]])) != 0;
	}

	boolean rect(int[] b) {
		for (int i = 0; i < 4; ++i) {
			if (a[b[i]].vector(a[b[(i - 1 + 4) % 4]]).dotProduct(
					a[b[i]].vector(a[b[(i + 1) % 4]])) != 0) {
				return false;
			}
		}
		return a[b[0]].vector(a[b[1]]).crossProduct(a[b[0]].vector(a[b[3]])) != 0;
	}

	boolean ok(int[] o) {
		boolean[] us = new boolean[8];

		for (int i = 0; i < 4; ++i) {
			us[o[i]] = true;
		}

		int[] b = new int[4];
		int k = 0;
		for (int i = 0; i < 8; ++i) {
			if (!us[i]) {
				b[k++] = i;
			}
		}
		if (sq(o) && rect(b)) {
			out.println("YES");
			for (int i = 0; i < 4; ++i) {
				out.print((a[o[i]].id + 1) + " ");
			}
			out.println();
			for (int i = 0; i < 4; ++i) {
				out.print((a[b[i]].id + 1) + " ");
			}
			return true;
		}
		return false;
	}

	Point[] a;

	void solve() {
		a = new Point[8];
		int min = 0;
		for (int i = 0; i < 8; ++i) {
			a[i] = new Point(nextInt(), nextInt(), i);
			if (a[i].y < min) {
				min = a[i].y;
			}
		}

		for (int i = 0; i < 8; ++i) {
			a[i].y += -min;
		}

		for (int i = 0; i < 8; ++i) {
			for (int j = 0; j < 8 && i != j; ++j) {
				for (int k = 0; k < 8 && i != k && k != j; ++k) {
					for (int l = 0; l < 8 && i != l && j != l && k != l; ++l) {
						int[] o = new int[4];
						o[0] = i;
						o[1] = j;
						o[2] = k;
						o[3] = l;
						if (ok(o)) {
							return;
						}
					}
				}
			}
		}
		out.print("NO");
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));

			//br = new BufferedReader(new FileReader("input.txt"));
			//out = new PrintWriter(new FileWriter("output.txt"));
			solve();
			br.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


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

public class Main {
	boolean eof;

	public String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "-1";
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(nextToken());
	}

	public static int comp(double a, double b) {
		double eps = 1e-9;
		if (Math.abs(a - b) < eps)
			return 0;
		else if (a - b > eps)
			return 1;
		else
			return -1;
	}

	static class Point implements Comparable<Point> {
		static Point NULL = new Point(0, 0, 0);
		int x, y, id;

		Point(int x, int y, int id) {
			this.x = x;
			this.y = y;
			this.id = id;
		}

		public int compareTo(Point p) {
			if (polarAngle() > p.polarAngle() ||
					polarAngle() == p.polarAngle() &&
					distance(NULL) > p.distance(NULL)) {
				return 1;
			} else {
				return -1;
			}
		}

		public double polarAngle() {
			double a = Math.atan2(y, x);
			if (a < 0) {
				a += 2 * Math.PI;
			}
			return a;
		}

		public double dotProduct(Point v) {
			return x * v.x + y * v.y;
		}

		public double crossProduct(Point v) {
			return x * v.y - y * v.x;
		}

		public Point vector(Point p) {
			return new Point(p.x - x, p.y - y, 0);
		}

		public double distance(Point p) {
			return Math.sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
		}
	}

	boolean sq(int[] b) {
		for (int i = 0; i < 4; ++i) {
			if (a[b[i]].vector(a[b[(i - 1 + 4) % 4]]).dotProduct(
					a[b[i]].vector(a[b[(i + 1) % 4]])) != 0
					&& comp(a[b[i]].distance(a[b[(i + 1) % 4]]),
							a[b[(i + 1) % 4]].distance(a[b[(i + 2) % 4]])) == 0) {
				return false;
			}
		}
		return a[b[0]].vector(a[b[1]]).crossProduct(a[b[0]].vector(a[b[3]])) != 0;
	}

	boolean rect(int[] b) {
		for (int i = 0; i < 4; ++i) {
			if (a[b[i]].vector(a[b[(i - 1 + 4) % 4]]).dotProduct(
					a[b[i]].vector(a[b[(i + 1) % 4]])) != 0) {
				return false;
			}
		}
		return a[b[0]].vector(a[b[1]]).crossProduct(a[b[0]].vector(a[b[3]])) != 0;
	}

	boolean ok(int[] o) {
		boolean[] us = new boolean[8];

		for (int i = 0; i < 4; ++i) {
			us[o[i]] = true;
		}

		int[] b = new int[4];
		int t = 0;
		for (int i = 0; i < 8; ++i) {
			if (!us[i]) {
				b[t++] = i;
			}
		}
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4; ++j) {
				if (j != i) {
					for (int k = 0; k < 4; ++k) {
						if (k != i && k != j) {
							for (int l = 0; l < 4; ++l) {
								if (i != l && j != l && k != l) {
									int[] o1 = new int[4];
									o1[0] = b[i];
									o1[1] = b[j];
									o1[2] = b[k];
									o1[3] = b[l];

									if (sq(o) && rect(o1)) {
										out.println("YES");
										for (int u = 0; u < 4; ++u) {
											out.print((a[o[u]].id + 1) + " ");
										}
										out.println();
										for (int u = 0; u < 4; ++u) {
											out.print((a[o1[u]].id + 1) + " ");
										}
										return true;
									}
								}
							}
						}
					}
				}
			}
		}

		return false;
	}

	Point[] a;

	void solve() {
		a = new Point[8];
		int min = 0;
		for (int i = 0; i < 8; ++i) {
			a[i] = new Point(nextInt(), nextInt(), i);
			if (a[i].y < min) {
				min = a[i].y;
			}
		}

		for (int i = 0; i < 8; ++i) {
			a[i].y += -min;
		}

		for (int i = 0; i < 8; ++i) {
			for (int j = 0; j < 8; ++j) {
				if (j != i) {
					for (int k = 0; k < 8; ++k) {
						if (k != i && k != j) {
							for (int l = 0; l < 8; ++l) {
								if (i != l && j != l && k != l) {
									int[] o = new int[4];
									o[0] = i;
									o[1] = j;
									o[2] = k;
									o[3] = l;
									if (ok(o)) {
										return;
									}
								}
							}
						}
					}
				}
			}
		}
		out.print("NO");
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));

			//br = new BufferedReader(new FileReader("input.txt"));
			//out = new PrintWriter(new FileWriter("output.txt"));
			solve();
			br.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


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

public class Main {
	boolean eof;

	public String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return "-1";
			}
		}
		return st.nextToken();
	}

	public int nextInt() {
		return Integer.parseInt(nextToken());
	}

	public static int comp(double a, double b) {
		double eps = 1e-9;
		if (Math.abs(a - b) < eps)
			return 0;
		else if (a - b > eps)
			return 1;
		else
			return -1;
	}

	static class Point implements Comparable<Point> {
		static Point NULL = new Point(0, 0, 0);
		int x, y, id;

		Point(int x, int y, int id) {
			this.x = x;
			this.y = y;
			this.id = id;
		}

		public int compareTo(Point p) {
			if (polarAngle() > p.polarAngle() ||
					polarAngle() == p.polarAngle() &&
					distance(NULL) > p.distance(NULL)) {
				return 1;
			} else {
				return -1;
			}
		}

		public double polarAngle() {
			double a = Math.atan2(y, x);
			if (a < 0) {
				a += 2 * Math.PI;
			}
			return a;
		}

		public double dotProduct(Point v) {
			return x * v.x + y * v.y;
		}

		public double crossProduct(Point v) {
			return x * v.y - y * v.x;
		}

		public Point vector(Point p) {
			return new Point(p.x - x, p.y - y, 0);
		}

		public double distance(Point p) {
			return Math.sqrt((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y));
		}
	}

	boolean sq(int[] b) {
		for (int i = 0; i < 4; ++i) {
			if (a[b[i]].vector(a[b[(i - 1 + 4) % 4]]).dotProduct(
					a[b[i]].vector(a[b[(i + 1) % 4]])) != 0
					|| comp(a[b[i]].distance(a[b[(i + 1) % 4]]),
							a[b[(i + 1) % 4]].distance(a[b[(i + 2) % 4]])) != 0) {
				return false;
			}
		}
		return a[b[0]].vector(a[b[1]]).crossProduct(a[b[0]].vector(a[b[3]])) != 0;
	}

	boolean rect(int[] b) {
		for (int i = 0; i < 4; ++i) {
			if (a[b[i]].vector(a[b[(i - 1 + 4) % 4]]).dotProduct(
					a[b[i]].vector(a[b[(i + 1) % 4]])) != 0) {
				return false;
			}
		}
		return a[b[0]].vector(a[b[1]]).crossProduct(a[b[0]].vector(a[b[3]])) != 0;
	}

	boolean ok(int[] o) {
		boolean[] us = new boolean[8];

		for (int i = 0; i < 4; ++i) {
			us[o[i]] = true;
		}

		int[] b = new int[4];
		int t = 0;
		for (int i = 0; i < 8; ++i) {
			if (!us[i]) {
				b[t++] = i;
			}
		}
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4; ++j) {
				if (j != i) {
					for (int k = 0; k < 4; ++k) {
						if (k != i && k != j) {
							for (int l = 0; l < 4; ++l) {
								if (i != l && j != l && k != l) {
									int[] o1 = new int[4];
									o1[0] = b[i];
									o1[1] = b[j];
									o1[2] = b[k];
									o1[3] = b[l];

									if (sq(o) && rect(o1)) {
										out.println("YES");
										for (int u = 0; u < 4; ++u) {
											out.print((a[o[u]].id + 1) + " ");
										}
										out.println();
										for (int u = 0; u < 4; ++u) {
											out.print((a[o1[u]].id + 1) + " ");
										}
										return true;
									}
								}
							}
						}
					}
				}
			}
		}

		return false;
	}

	Point[] a;

	void solve() {
		a = new Point[8];
		int min = 0;
		for (int i = 0; i < 8; ++i) {
			a[i] = new Point(nextInt(), nextInt(), i);
			if (a[i].y < min) {
				min = a[i].y;
			}
		}

		for (int i = 0; i < 8; ++i) {
			a[i].y += -min;
		}

		for (int i = 0; i < 8; ++i) {
			for (int j = 0; j < 8; ++j) {
				if (j != i) {
					for (int k = 0; k < 8; ++k) {
						if (k != i && k != j) {
							for (int l = 0; l < 8; ++l) {
								if (i != l && j != l && k != l) {
									int[] o = new int[4];
									o[0] = i;
									o[1] = j;
									o[2] = k;
									o[3] = l;
									if (ok(o)) {
										return;
									}
								}
							}
						}
					}
				}
			}
		}
		out.print("NO");
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;

	void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new OutputStreamWriter(System.out));

			//br = new BufferedReader(new FileReader("input.txt"));
			//out = new PrintWriter(new FileWriter("output.txt"));
			solve();
			br.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


import java.awt.Point;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class D97 {

	static boolean test = false;
	Point[] pts = null;
	boolean solved = false;
	private void solve() throws Throwable {
		pts = new Point[8];
		for (int i = 0; i < 8; i++) {
			pts[i] = new Point(iread(), iread());
		}
		go(new int[8], 0);
		if(!solved){
			System.out.println("NO");
		}
	}

	private void go(int[] is, int pos) {
		if(solved){
			return;
		}

		if(pos == 8){
			//test the solution
			List<Point> squareList = new ArrayList<Point>();
			List<Point> rectList = new ArrayList<Point>();

			for (int i = 0; i < is.length; i++) {
				if(is[i] == 1){
					squareList.add(pts[i]);
				} else {
					rectList.add(pts[i]);
				}
			}

			if(squareList.size() != 4){
				return;
			}

			if(isSquare(squareList) && isRect(rectList)){
				solved = true;
				//print
				String s1 = "";
				String s2 = "";

				for (int i = 0; i < is.length; i++) {
					if(is[i] == 1){
						s1 += (i+1) + "";
						if(i < is.length-1){
							s1 += " ";
						}
					}
					if(is[i] == 0){
						s2 += (i+1) + "";
						if(i < is.length-1){
							s2 += " ";
						}
					}
				}
				System.out.println("YES");
				System.out.println(s1);
				System.out.println(s2);
				return;
			}

		} else {
			is[pos] = 0;
			go(is, pos+1);
			is[pos] = 1;
			go(is, pos+1);
			is[pos] = 0;
		}
	}

	private boolean isRect(List<Point> rectList) {

		int zeros = 0;

		for (int i = 0; i < rectList.size(); i++) {
			for (int j = i+1; j < rectList.size(); j++) {
				Point point = rectList.get(i);
				Point point2 = rectList.get(j);
				for (int k = 0; k < rectList.size(); k++) {
					if(k == j || k == i){
						continue;
					}
					Point base = rectList.get(k);
					double x1 = point.getX() - base.getX();
					double x2 = point2.getX() - base.getX();
					double y1 = point.getY() - base.getY();
					double y2 = point2.getY() - base.getY();
					if(Math.abs(x1*x2 + y1*y2) < 0.0000001){
						zeros ++;
					}
				}
			}
		}

		return zeros == 4;
	}

	private boolean isSquare(List<Point> squareList) {
		List<Double> d = new ArrayList<Double>();

		for (int i = 0; i < squareList.size(); i++) {
			for (int j = i+1; j < squareList.size(); j++) {
				d.add(dist(squareList.get(i), squareList.get(j)));
			}
		}
		Collections.sort(d);
		if(same(d.get(0), d.get(1)) && same(d.get(0), d.get(2))&& same(d.get(0), d.get(3))&& same(d.get(4), d.get(5))){
			return true;
		}

		return false;
	}

	private boolean same(Double double1, Double double2) {
		if(Math.abs(double1 - double2) <= 0.0000001){
			return true;
		}
		return false;
	}

	private Double dist(Point point, Point point2) {
		return (point.getX() - point2.getX())*(point.getX() - point2.getX()) + (point.getY() - point2.getY())*(point.getY() - point2.getY());
	}

	public int iread() throws Exception {
		return Integer.parseInt(wread());
	}

	public double dread() throws Exception {
		return Double.parseDouble(wread());
	}

	public long lread() throws Exception {
		return Long.parseLong(wread());
	}

	public String wread() throws IOException {
		StringBuilder b = new StringBuilder();
		int c;
		c = in.read();
		while (c >= 0 && c <= ' ')
			c = in.read();
		if (c < 0)
			return "";
		while (c > ' ') {
			b.append((char) c);
			c = in.read();
		}
		return b.toString();
	}

	public static void main(String[] args) throws Throwable {
		new D97().solve();
		out.close();
	}

	public D97() throws Throwable {
		if (test) {
			in = new BufferedReader(new FileReader(new File(testDataFile)));
		} else {
			new BufferedReader(inp);
		}
	}

	static InputStreamReader inp = new InputStreamReader(System.in);
	static BufferedReader in = new BufferedReader(inp);
	static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));

	static String testDataFile = "testdata.txt";
	BufferedReader reader = null;
}


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class D {

        final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null;
        BufferedReader in;
        PrintWriter out;
        StringTokenizer tok = new StringTokenizer("");

        void init() throws FileNotFoundException{
                if (ONLINE_JUDGE){
                        in = new BufferedReader(new InputStreamReader(System.in));
                        out = new PrintWriter(System.out);
                }else{
                        in = new BufferedReader(new FileReader("input.txt"));
                        out = new PrintWriter("output.txt");
                }
        }

        String readString() throws IOException{
                while(!tok.hasMoreTokens()){
                        tok = new StringTokenizer(in.readLine());
                }
                return tok.nextToken();
        }

        int readInt() throws IOException{
                return Integer.parseInt(readString());
        }

        long readLong() throws IOException{
                return Long.parseLong(readString());
        }

        double readDouble() throws IOException{
                return Double.parseDouble(readString());
        }

        public static void main(String[] args){
                new D().run();
        }

        public void run(){
                try{
                        long t1 = System.currentTimeMillis();
                        init();
                        solve();
                        out.close();
                        long t2 = System.currentTimeMillis();
                        System.err.println("Time = "+(t2-t1));
                }catch (Exception e){
                        e.printStackTrace(System.err);
                        System.exit(-1);
                }
        }

        void solve() throws IOException{
        	int n = 8;
        	int[][] a = new int[n][2];
        	for(int i = 0; i < n; i++){
        		a[i][0] = readInt();
        		a[i][1] = readInt();
        	}
        	for(int i = 0; i < (1 << n); i++){

        		ArrayList<Integer> sq = new ArrayList<Integer>();
        		ArrayList<Integer> rec = new ArrayList<Integer>();
        		for(int j = 0; j < n; j++){
        			if((i & (1 << j)) == 0)rec.add(j);
        			else sq.add(j);
        		}
        		double eps = pow(0.1, 9);
        		if(sq.size() != rec.size()) continue;
        		double[][] m = new double[4][4];
        		for(int j = 0; j < 4; j++)
        			for(int k = j+1; k < 4; k++){
        				long x1 = a[sq.get(j)][0];
        				long y1 = a[sq.get(j)][1];
        				long x2 = a[sq.get(k)][0];
        				long y2 = a[sq.get(k)][1];
        				m[j][k] = m[k][j] = distance(x1, y1, x2, y2);
        			}
        		boolean checkSq = true;
        		if(abs(m[0][1] - m[2][3]) < eps  && abs(m[0][2] - m[1][3]) < eps && abs(m[0][3] - m[1][2]) < eps){
        			double min = m[0][1];
        			for(int j = 2; j < 4; j++){
        				if(m[0][j] < min) min = m[0][j];
        			}
        			for(int j = 2; j < 4; j++){
        				if(abs(m[0][j] - min) < eps) continue;
        				if(abs(m[0][j] - min * sqrt(2)) < eps) continue;
        				checkSq = false;
        			}
        		}
        		else{
        			checkSq = false;
        		}
        		if(!checkSq) continue;
        		if(i == 15){
        			int crw = 0;
        		}
        		boolean checkRec = true;
        		for(int j = 0; j < 4; j++){
        			boolean check1 = false;
        			for(int k = 0; k < 4; k++){
        				for(int l = 0; l < 4; l++){
        					if(j == k || j == l || k == l) continue;
        					int x1 = a[rec.get(j)][0];
        					int x2 = a[rec.get(k)][0];
        					int x3 = a[rec.get(l)][0];
        					int y1 = a[rec.get(j)][1];
        					int y2 = a[rec.get(k)][1];
        					int y3 = a[rec.get(l)][1];
        					if(scalar(x1,y1,x2,y2,x1,y1,x3,y3) < eps)
        						check1 = true;
        				}
        			}
        			if(!check1) checkRec = false;
        		}
        		if(checkRec){
        			out.println("YES");
        			for(int j = 0; j < 4; j++){
        				out.print((sq.get(j)+1)+ " ");
        			}
        			out.println();
        			for(int j = 0; j < 4; j++){
        				out.print((rec.get(j)+1)+ " ");
        			}
        			return;
        		}

        	}
        	out.println("NO");
        }

        double scalar(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4){
        	return (x1-x2)*(x3-x4) + (y1-y2)*(y3-y4);
        }

        int[] zFunction(char[] s){
        	int[] z = new int[s.length];
        	z[0] = 0;
        	for (int i=1, l=0, r=0; i<s.length; ++i) {
        		if (i <= r)
        			z[i] = min (r-i+1, z[i-l]);
        		while (i+z[i] < s.length && s[z[i]] == s[i+z[i]])
        			++z[i];
        		if (i+z[i]-1 > r){
        			l = i;
        			r = i+z[i]-1;
        		}
        	}
        	return z;
        }

        int[] prefixFunction(char[] s){
        	int[] pr = new int[s.length];
        	for (int i = 1; i< s.length; ++i) {
        		int j = pr[i-1];
        		while (j > 0 && s[i] != s[j])
        			j = pr[j-1];
        		if (s[i] == s[j])  ++j;
        		pr[i] = j;
        	}
        	return pr;
        }

        int ModExp(int a, int n, int mod){
        	int res = 1;
        	while (n!=0)
        		if ((n & 1) != 0) {
        			res = (res*a)%mod;
        			--n;
        		}
        		else {
        			a = (a*a)%mod;
        			n >>= 1;
        		}
        	return res;
        }

        static class Utils {

                private Utils() {}

                public static void mergeSort(int[] a) {
                        mergeSort(a, 0, a.length - 1);
                }

                private static void mergeSort(int[] a, int leftIndex, int rightIndex) {
                        final int MAGIC_VALUE = 50;
                        if (leftIndex < rightIndex) {
                                if (rightIndex - leftIndex <= MAGIC_VALUE) {
                                        insertionSort(a, leftIndex, rightIndex);
                                } else {
                                        int middleIndex = (leftIndex + rightIndex) / 2;
                                        mergeSort(a, leftIndex, middleIndex);
                                        mergeSort(a, middleIndex + 1, rightIndex);
                                        merge(a, leftIndex, middleIndex, rightIndex);
                                }
                        }
                }

                private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
                        int length1 = middleIndex - leftIndex + 1;
                        int length2 = rightIndex - middleIndex;
                        int[] leftArray = new int[length1];
                        int[] rightArray = new int[length2];
                        System.arraycopy(a, leftIndex, leftArray, 0, length1);
                        System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
                        for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
                                if (i == length1) {
                                        a[k] = rightArray[j++];
                                } else if (j == length2) {
                                        a[k] = leftArray[i++];
                                } else {
                                        a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
                                }
                        }
                }

                private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
                        for (int i = leftIndex + 1; i <= rightIndex; i++) {
                                int current = a[i];
                                int j = i - 1;
                                while (j >= leftIndex && a[j] > current) {
                                        a[j + 1] = a[j];
                                        j--;
                                }
                                a[j + 1] = current;
                        }
                }
        }

        boolean isPrime(int a){
        	for(int i = 2; i <= sqrt(a); i++)
        		if(a % i == 0) return false;
        	return true;
        }

        static double distance(long x1, long y1, long x2, long y2){
        	return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        }

        static long gcd(long a, long b){
        	if(min(a,b) == 0) return max(a,b);
        	return gcd(max(a, b) % min(a,b), min(a,b));
        }

        static long lcm(long a, long b){
        	return a * b /gcd(a, b);
        }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;

public class D implements Runnable{

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        new D().run();
    }

    Scanner Reader;
    PrintWriter Writer;
    Point[] p = new Point[8];

    public class Point{
        int x,y;
        Point(int x, int y){
            this.x=x;
            this.y=y;
        }
    }

    private int getBit(int i, int x){
        return (x>>i)&1;
    }

    private boolean checkSquare(Point[] p){
        if ((p[0].x-p[1].x)*(p[2].x-p[3].x) + (p[0].y-p[1].y)*(p[2].y-p[3].y) == 0){
            if (checkRec(p))
                return true;
            }
        Point tg = p[0];
        p[0]=p[2];
        p[2]=tg;
        if ((p[0].x-p[1].x)*(p[2].x-p[3].x) + (p[0].y-p[1].y)*(p[2].y-p[3].y) == 0){
            if (checkRec(p))
                return true;
            }
        tg = p[1];
        p[1]=p[2];
        p[2]=tg;
        if ((p[0].x-p[1].x)*(p[2].x-p[3].x) + (p[0].y-p[1].y)*(p[2].y-p[3].y) == 0){
            if (checkRec(p))
                return true;
            }
        return false;
    }

    private boolean checkRec(Point[] p){
        if ((p[0].x-p[2].x)*(p[1].x-p[2].x) + (p[0].y-p[2].y)*(p[1].y-p[2].y) == 0
                && (p[0].x-p[3].x)*(p[1].x-p[3].x) + (p[0].y-p[3].y)*(p[1].y-p[3].y) == 0){
            if (p[0].x+p[1].x==p[2].x+p[3].x && p[0].y+p[1].y==p[2].y+p[3].y)
                return true;
            }
        Point tg = p[0];
        p[0]=p[2];
        p[2]=tg;
        if ((p[0].x-p[2].x)*(p[1].x-p[2].x) + (p[0].y-p[2].y)*(p[1].y-p[2].y) == 0
                && (p[0].x-p[3].x)*(p[1].x-p[3].x) + (p[0].y-p[3].y)*(p[1].y-p[3].y) == 0){
            if (p[0].x+p[1].x==p[2].x+p[3].x && p[0].y+p[1].y==p[2].y+p[3].y)
                return true;
            }
        tg = p[1];
        p[1]=p[2];
        p[2]=tg;
        if ((p[0].x-p[2].x)*(p[1].x-p[2].x) + (p[0].y-p[2].y)*(p[1].y-p[2].y) == 0
                && (p[0].x-p[3].x)*(p[1].x-p[3].x) + (p[0].y-p[3].y)*(p[1].y-p[3].y) == 0){
            if (p[0].x+p[1].x==p[2].x+p[3].x && p[0].y+p[1].y==p[2].y+p[3].y)
                return true;
            }
        return false;
    }

    public void display(Point[] k){
        for (int i=0; i<k.length; i++)
            Writer.println(k[i].x+" "+k[i].y);
    }

    public void solve() throws IOException{
        for(int i=0; i<8; i++){
            int x=Reader.nextInt();
            int y=Reader.nextInt();
            p[i] = new Point(x,y);
            //Writer.println(x+" "+y);
        }

        boolean ok=false;
        for(int i=0; i<(1<<8); i++){
            int sum=0;
            for(int j=0; j<8; j++)
                sum+= getBit(j,i);
            if (sum!=4) continue;

            Point[] Square = new Point[4];
            int Sn=-1;
            for(int j=0; j<8; j++)
                if (getBit(j,i)==0){
                    Sn++;
                    Square[Sn]=p[j];
                }
            if (!checkSquare(Square)) continue;

            Point[] Rec = new Point[4];
            int Rn=-1;
            for(int j=0; j<8; j++)
                if (getBit(j,i)==1){
                    Rn++;
                    Rec[Rn]=p[j];
                }
            if (!checkRec(Rec)) continue;
            Writer.println("YES");
            for(int j=0; j<8; j++)
                if (getBit(j,i)==0){
                    if (j<7) Writer.print((j+1)+" ");
                    else Writer.println((j+1));
                }
            for(int j=0; j<8; j++)
                if (getBit(j,i)==1){
                    if (j<7) Writer.print((j+1)+" ");
                    else Writer.println((j+1));
                }
            ok=true;
            break;
            }
        if (!ok) Writer.println("NO");
        }

    public void run(){
        try{
            Reader = new Scanner(new InputStreamReader(System.in));
            Writer = new PrintWriter(System.out);
            solve();

            Reader.close();
            Writer.close();
        } catch (Exception e){
            System.out.println(e.getMessage());
        }
    }

}


import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        new Main();

    }

    Scanner sc;
    PrintWriter pw;

    public Main() {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);

        solve();
        sc.close();
        pw.close();
    }

    static class Point {
        int x;
        int y;

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

        Point(Point p, Point q) {
            this.x = q.x - p.x;
            this.y = q.y - p.y;
        }

        int length() {
            return (x * x + y * y);
        }

        static int dot(Point p, Point q) {
            return p.x * q.x + p.y * q.y;
        }

        @Override
        public String toString() {
            // TODO Auto-generated method stub
            return "(" + x + "; " + y + ")";
        }

        static boolean isRect(Point a, Point b, Point c, Point d) {
            return dot(a, b) == 0 && dot(b, c) == 0 && dot(c, d) == 0;
        }

        static boolean isSquare(Point a, Point b, Point c, Point d) {
            return isRect(a, b, c, d) && (a.length() == b.length())
                    && (b.length() == c.length()) && (c.length() == d.length());
        }
    }

    boolean bruteRect(Point[] p) {
        boolean result = false;

        for (int a = 0; a < 4; a++) {

            for (int b = 0; b < 4; b++) {
                if (a == b)
                    continue;
                for (int c = 0; c < 4; c++) {
                    if (b == c)
                        continue;
                    for (int d = 0; d < 4; d++) {
                        if (c == d)
                            continue;
                        result |= Point.isRect(new Point(p[a], p[b]),
                                new Point(p[b], p[c]), new Point(p[c], p[d]),
                                new Point(p[d], p[a]));
                        if (result)
                            return result;
                    }
                }

            }
        }

        return result;
    }

    boolean bruteSquare(Point[] p) {
        boolean result = false;

        for (int a = 0; a < 4; a++) {

            for (int b = 0; b < 4; b++) {
                if (a == b)
                    continue;
                for (int c = 0; c < 4; c++) {
                    if (b == c)
                        continue;
                    for (int d = 0; d < 4; d++) {
                        if (c == d)
                            continue;
                        result |= Point.isSquare(new Point(p[a], p[b]),
                                new Point(p[b], p[c]), new Point(p[c], p[d]),
                                new Point(p[d], p[a]));
                        if (result)
                            return result;
                    }
                }

            }
        }

        return result;
    }

    boolean[] subset = new boolean[8];
    Point[] rectPoints = new Point[4];
    Point[] squarePoints = new Point[4];
    final int N = 8;
    Point[] p = new Point[N];

    void rec(int i, int size) {

        if (size == 4 && i == 8) {
            int rectCount = 0;
            int squareCount = 0;
            for (int j = 0; j < 8; j++) {
                if (subset[j]) {
                    squarePoints[squareCount++] = p[j];
                } else {
                    rectPoints[rectCount++] = p[j];
                }
            }

            if (bruteRect(rectPoints) && bruteSquare(squarePoints)) {
                pw.println("YES");
                for (int j = 0; j < 8; j++) {
                    if (subset[j]) {
                        pw.print((j + 1) + " ");
                    }
                }
                pw.println();
                for (int j = 0; j < 8; j++) {
                    if (!subset[j]) {
                        pw.print((j + 1) + " ");
                    }
                }
                pw.println();
                pw.flush();
                pw.close();
                System.exit(0);
            }

        }
        if (size > 4 || i == 8)
            return;

        subset[i] = false;
        rec(i + 1, size);
        subset[i] = true;
        rec(i + 1, size + 1);
    }

    void solve() {

        for (int i = 0; i < N; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            p[i] = new Point(x, y);
        }

        rec(0, 0);

        pw.println("NO");
        pw.flush();
    }
}


import java.util.Scanner;

public class D136 {
    public static final int N = 8;
    public static final double eps = 1e-9;
    static int[] perm;
    static boolean[] used;
    static Point[] points;
    static class Point {
        int x;
        int y;
        public Point(int x , int y) {
            this.x = x;
            this.y = y;
        }
        public double dist(Point p) {
            return Math.sqrt((this.x - p.x) * (this.x - p.x) + (this.y - p.y) * (this.y - p.y));
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        points = new Point[N];
        for (int i = 0 ; i < N ; i++) {
            points[i] = new Point(in.nextInt() , in.nextInt());
        }
        used = new boolean[N];
        perm = new int[N];
        put(0);
        System.out.println("NO");
    }
    public static void put(int already) {
        if (already == N) {
            if (isSolution()) {
                System.out.println("YES");
                for (int i = 0 ; i < 4 ; i++)
                    System.out.print((perm[i] + 1) + " ");
                System.out.println("");
                for (int i = 0 ; i < 4 ; i++) {
                    System.out.print((perm[i + 4] + 1) + " ");
                }
                System.exit(0);
            }
        } else {
            for (int i = 0 ; i < N ; i++)
                if (!used[i]) {
                    perm[already] = i;
                    used[i] = true;
                    put(already + 1);
                    used[i] = false;
                }
        }
    }
    public static boolean isSolution() {
        double d1 = points[perm[0]].dist(points[perm[1]]);
        double d2 = points[perm[1]].dist(points[perm[2]]);
        double d3 = points[perm[2]].dist(points[perm[3]]);
        double d4 = points[perm[3]].dist(points[perm[0]]);
        boolean isSquare = (Math.abs(d1 - d2) < eps && Math.abs(d2 - d3) < eps && Math.abs(d3 - d4) < eps && d1 > 0);
        d1 = points[perm[4]].dist(points[perm[5]]);
        d2 = points[perm[5]].dist(points[perm[6]]);
        d3 = points[perm[6]].dist(points[perm[7]]);
        d4 = points[perm[7]].dist(points[perm[4]]);
        boolean isRectangle = (Math.abs(d1 - d3) < eps && Math.abs(d2 - d4) < eps && d1 > 0 && d2 > 0);
        return isSquare && isRectangle;
    }
}


import java.util.Scanner;

public class D136 {

    public static final int N = 8;
    public static final double eps = 1e-9;
    static int[] perm;
    static boolean[] used;
    static Point[] points;

    static class Point {

        int x;
        int y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public double dist(Point p) {
            return Math.sqrt((this.x - p.x) * (this.x - p.x) + (this.y - p.y) * (this.y - p.y));
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        points = new Point[N];
        for (int i = 0; i < N; i++) {
            points[i] = new Point(in.nextInt(), in.nextInt());
        }
        used = new boolean[N];
        perm = new int[N];
        put(0);
        System.out.println("NO");
    }

    public static void put(int already) {
        if (already == N) {
            if (isSolution()) {
                System.out.println("YES");
                for (int i = 0; i < 4; i++) {
                    System.out.print((perm[i] + 1) + " ");
                }
                System.out.println("");
                for (int i = 0; i < 4; i++) {
                    System.out.print((perm[i + 4] + 1) + " ");
                }
                System.exit(0);
            }
        } else {
            for (int i = 0; i < N; i++) {
                if (!used[i]) {
                    perm[already] = i;
                    used[i] = true;
                    put(already + 1);
                    used[i] = false;
                }
            }
        }
    }

    public static boolean isSolution() {
        double d1 = points[perm[0]].dist(points[perm[1]]);
        double d2 = points[perm[1]].dist(points[perm[2]]);
        double d3 = points[perm[2]].dist(points[perm[3]]);
        double d4 = points[perm[3]].dist(points[perm[0]]);
        boolean isSquare = (Math.abs(d1 - d2) < eps && Math.abs(d2 - d3) < eps && Math.abs(d3 - d4) < eps && d1 > 0);
        boolean ang1 = isRightAngle(getVector(points[perm[0]], points[perm[1]]), getVector(points[perm[0]], points[perm[3]]));
        boolean ang2 = isRightAngle(getVector(points[perm[1]], points[perm[0]]), getVector(points[perm[1]], points[perm[2]]));
        boolean ang3 = isRightAngle(getVector(points[perm[2]], points[perm[1]]), getVector(points[perm[2]], points[perm[3]]));
        boolean ang4 = isRightAngle(getVector(points[perm[3]], points[perm[2]]), getVector(points[perm[3]], points[perm[0]]));
        isSquare = isSquare && ang1 && ang2 && ang3 && ang4;
        d1 = points[perm[4]].dist(points[perm[5]]);
        d2 = points[perm[5]].dist(points[perm[6]]);
        d3 = points[perm[6]].dist(points[perm[7]]);
        d4 = points[perm[7]].dist(points[perm[4]]);
        boolean isRectangle = (Math.abs(d1 - d3) < eps && Math.abs(d2 - d4) < eps && d1 > 0 && d2 > 0);
        ang1 = isRightAngle(getVector(points[perm[4]], points[perm[5]]), getVector(points[perm[4]], points[perm[7]]));
        ang2 = isRightAngle(getVector(points[perm[5]], points[perm[4]]), getVector(points[perm[5]], points[perm[6]]));
        ang3 = isRightAngle(getVector(points[perm[6]], points[perm[5]]), getVector(points[perm[6]], points[perm[7]]));
        ang4 = isRightAngle(getVector(points[perm[7]], points[perm[6]]), getVector(points[perm[7]], points[perm[4]]));
        isRectangle = isRectangle && ang1 && ang2 && ang3 && ang4;
        return isSquare && isRectangle;
    }

    public static Point getVector(Point a, Point b) {
        Point c = new Point(b.x - a.x, b.y - a.y);
        return c;
    }

    public static boolean isRightAngle(Point a, Point b) {
        Point zero = new Point(0, 0);
        double p = a.x * b.x + a.y * b.y;
        double q = zero.dist(a) * zero.dist(b);
        double angle = Math.acos(p / q);
        return (Math.abs(angle - Math.PI / 2) < eps);
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/29/11
 * Time: 7:56 PM
 * To ch ange this template use File | Settings | File Templates.
 */
public class TaskD {

    int[] x;
    int[] y;

    boolean isValid(int mask) {
        int[] squarex = new int[4];
        int[] squarey = new int[4];
        int[] recx = new int[4];
        int[] recy = new int[4];

        int ia = 0, ib = 0;
        for (int i = 0; i < 8; i++) {
            if ((mask & (1 << i)) > 0) {
                squarex[ia++] = x[i];
                squarey[ia++] = y[i];
            } else {
                recx[ib++] = x[i];
                recy[ib++] = y[i];
            }
        }

        boolean isSquare = true, isRec = true;
        int[][] xdiff = new int[4][4];
        int[][] ydiff = new int[4][4];
        int[][] dist = new int[4][4];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                xdiff[i][j] = squarex[i] - squarex[j];
                ydiff[i][j] = squarey[i] - squarey[j];
                dist[i][j] = xdiff[i][j] * xdiff[i][j] + ydiff[i][j] * ydiff[i][j];
            }
        }

        for (int i = 0; i < 4 && isSquare; i++) {
            int minDistance = Integer.MAX_VALUE;
            for (int j = 0; j < 4; j++) {
                if (j == i) continue;
                minDistance = Math.min(minDistance, dist[i][j]);
            }

            ArrayList<Integer> ix = new ArrayList<Integer>();
            for (int j = 0; j < 4; j++) {
                if (j == i) continue;
                if (dist[i][j] == minDistance) ix.add(j);
            }

            if (ix.size() == 2) {
                if (ydiff[i][ix.get(0)] * ydiff[i][ix.get(1)] + xdiff[i][ix.get(0)] * xdiff[i][ix.get(1)] == 0) {

                } else {
                    isSquare = false;
                }
            } else {
                isSquare = false;
            }
        }

        xdiff = new int[4][4];
        ydiff = new int[4][4];
        dist = new int[4][4];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                xdiff[i][j] = recx[i] - recx[j];
                ydiff[i][j] = recy[i] - recy[j];
                dist[i][j] = xdiff[i][j] * xdiff[i][j] + ydiff[i][j] * ydiff[i][j];
            }
        }

        for (int i = 0; i < 4 && isRec; i++) {
            int maxDistance = Integer.MIN_VALUE;
            for (int j = 0; j < 4; j++) {
                if (j == i) continue;
                maxDistance = Math.max(maxDistance, dist[i][j]);
            }

            ArrayList<Integer> ix = new ArrayList<Integer>();
            for (int j = 0; j < 4; j++) {
                if (j == i) continue;
                if (dist[i][j] != maxDistance) ix.add(j);
            }

            if (ix.size() == 2) {
                if (ydiff[i][ix.get(0)] * ydiff[i][ix.get(1)] + xdiff[i][ix.get(0)] * xdiff[i][ix.get(1)] == 0) {

                } else {
                    isRec = false;
                }
            } else {
                isRec = false;
            }
        }

        return isSquare && isRec;
    }

    void run() {
        x = new int[8];
        y = new int[8];
        for (int i = 0; i < 8; i++) {
            x[i] = nextInt();
            y[i] = nextInt();
        }

        int mask = -1;
        for (int i = 0; i < (1 << 8) && mask == -1; i++) {
            if (Integer.bitCount(i) == 4) {
                if (isValid(i)) mask = i;
            }
        }

        if (mask > 0) {
            System.out.println("YES");
            List<Integer> squarePoints = new ArrayList<Integer>();
            List<Integer> rectanglePoints = new ArrayList<Integer>();
            for (int i = 0; i < 8; i++) {
                if ((mask & (1 << i)) > 0) squarePoints.add(i);
                else rectanglePoints.add(i);
            }

            for (int a : squarePoints) System.out.print(a + " ");
            System.out.println();
            for (int a : rectanglePoints) System.out.print(a + " ");
            System.out.println();
        } else {
            System.out.println("NO");
        }

    }

    int nextInt() {
        try {
            int c = System.in.read();
            if (c == -1) return c;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1) return c;
            }
            if (c == '-') return -nextInt();
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

    long nextLong() {
        try {
            int c = System.in.read();
            if (c == -1) return -1;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1) return -1;
            }
            if (c == '-') return -nextLong();
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String next() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (Character.isWhitespace(c))
                c = System.in.read();
            do {
                res.append((char) c);
            } while (!Character.isWhitespace(c = System.in.read()));
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }

    String nextLine() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (c == '\r' || c == '\n')
                c = System.in.read();
            do {
                res.append((char) c);
                c = System.in.read();
            } while (c != '\r' && c != '\n');
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }

    public static void main(String[] args) {
        new TaskD().run();
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/29/11
 * Time: 7:56 PM
 * To ch ange this template use File | Settings | File Templates.
 */
public class TaskD {

    int[] x;
    int[] y;

    boolean isValid(int mask) {
        int[] squarex = new int[4];
        int[] squarey = new int[4];
        int[] recx = new int[4];
        int[] recy = new int[4];

        int ia = 0, ib = 0;
        for (int i = 0; i < 8; i++) {
            if ((mask & (1 << i)) > 0) {
                squarex[ia] = x[i];
                squarey[ia++] = y[i];
            } else {
                recx[ib] = x[i];
                recy[ib++] = y[i];
            }
        }

        boolean isSquare = true, isRec = true;
        int[][] xdiff = new int[4][4];
        int[][] ydiff = new int[4][4];
        int[][] dist = new int[4][4];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                xdiff[i][j] = squarex[i] - squarex[j];
                ydiff[i][j] = squarey[i] - squarey[j];
                dist[i][j] = xdiff[i][j] * xdiff[i][j] + ydiff[i][j] * ydiff[i][j];
            }
        }

        for (int i = 0; i < 4 && isSquare; i++) {
            int minDistance = Integer.MAX_VALUE;
            for (int j = 0; j < 4; j++) {
                if (j == i) continue;
                minDistance = Math.min(minDistance, dist[i][j]);
            }

            ArrayList<Integer> ix = new ArrayList<Integer>();
            for (int j = 0; j < 4; j++) {
                if (j == i) continue;
                if (dist[i][j] == minDistance) ix.add(j);
            }

            if (ix.size() == 2) {
                if (ydiff[i][ix.get(0)] * ydiff[i][ix.get(1)] + xdiff[i][ix.get(0)] * xdiff[i][ix.get(1)] == 0) {

                } else {
                    isSquare = false;
                }
            } else {
                isSquare = false;
            }
        }

        xdiff = new int[4][4];
        ydiff = new int[4][4];
        dist = new int[4][4];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                xdiff[i][j] = recx[i] - recx[j];
                ydiff[i][j] = recy[i] - recy[j];
                dist[i][j] = xdiff[i][j] * xdiff[i][j] + ydiff[i][j] * ydiff[i][j];
            }
        }

        for (int i = 0; i < 4 && isRec; i++) {
            int maxDistance = Integer.MIN_VALUE;
            for (int j = 0; j < 4; j++) {
                if (j == i) continue;
                maxDistance = Math.max(maxDistance, dist[i][j]);
            }

            ArrayList<Integer> ix = new ArrayList<Integer>();
            for (int j = 0; j < 4; j++) {
                if (j == i) continue;
                if (dist[i][j] != maxDistance) ix.add(j);
            }

            if (ix.size() == 2) {
                if (ydiff[i][ix.get(0)] * ydiff[i][ix.get(1)] + xdiff[i][ix.get(0)] * xdiff[i][ix.get(1)] == 0) {

                } else {
                    isRec = false;
                }
            } else {
                isRec = false;
            }
        }

        return isSquare && isRec;
    }

    void run() {
        x = new int[8];
        y = new int[8];
        for (int i = 0; i < 8; i++) {
            x[i] = nextInt();
            y[i] = nextInt();
        }

        int mask = -1;
        for (int i = 0; i < (1 << 8) && mask == -1; i++) {
            if (Integer.bitCount(i) == 4) {
                if (isValid(i)) mask = i;
            }
        }

        if (mask > 0) {
            System.out.println("YES");
            List<Integer> squarePoints = new ArrayList<Integer>();
            List<Integer> rectanglePoints = new ArrayList<Integer>();
            for (int i = 0; i < 8; i++) {
                if ((mask & (1 << i)) > 0) squarePoints.add(i);
                else rectanglePoints.add(i);
            }

            for (int a : squarePoints) System.out.print(a + 1 + " ");
            System.out.println();
            for (int a : rectanglePoints) System.out.print(a + 1 + " ");
            System.out.println();
        } else {
            System.out.println("NO");
        }

    }

    int nextInt() {
        try {
            int c = System.in.read();
            if (c == -1) return c;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1) return c;
            }
            if (c == '-') return -nextInt();
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

    long nextLong() {
        try {
            int c = System.in.read();
            if (c == -1) return -1;
            while (c != '-' && (c < '0' || '9' < c)) {
                c = System.in.read();
                if (c == -1) return -1;
            }
            if (c == '-') return -nextLong();
            long res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = System.in.read();
            } while ('0' <= c && c <= '9');
            return res;
        } catch (Exception e) {
            return -1;
        }
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String next() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (Character.isWhitespace(c))
                c = System.in.read();
            do {
                res.append((char) c);
            } while (!Character.isWhitespace(c = System.in.read()));
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }

    String nextLine() {
        try {
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while (c == '\r' || c == '\n')
                c = System.in.read();
            do {
                res.append((char) c);
                c = System.in.read();
            } while (c != '\r' && c != '\n');
            return res.toString();
        } catch (Exception e) {
            return null;
        }
    }

    public static void main(String[] args) {
        new TaskD().run();
    }
}


import java.util.*;
import java.io.PrintWriter;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class D97 {
	static Scanner in = new Scanner(System.in);
	static PrintWriter w = new PrintWriter(System.out, true);

	static int ni() {
		return in.nextInt();
	}

	static String nl() {
		return in.nextLine();
	}

	static void pl(int v) {
		w.println(v);
	}

	static void pl(long v) {
		w.println(v);
	}

	static void pl(Object v) {
		w.println(v);
	}
	static int[][] p;
	public static void main(String[] args) {
		p = new int[8][];
		for(int i = 0; i < 8; i++) p[i] = new int[] {ni(), ni()};
		int set = (1 << 4) - 1;
		int limit = (1 << 8);

		while (set < limit) {
			int t1, t2;
			if (abs(t1=det(set))==1 && abs(t2=det(~set)) == 1 && !(t1==-1 && t2==-1)) {
				pl("YES");
				int ts = set;
				Integer[] s = new Integer[4];
				int sc = 0;
			    for (int j = 0; j < 8; j++) {
			    	if (((ts>>j)&1)==1) {
			    		s[sc] = j;
			    		sc++;
			    	}
			    }
			    for (Integer i : s) w.print(i+1+" ");
			    w.println();
			    ts = ~set;
			    sc = 0;
			    for (int j = 0; j < 8; j++) {
			    	if (((ts>>j)&1)==1) {
			    		s[sc] = j;
			    		sc++;
			    	}
			    }
			    for (Integer i : s) w.print(i+1+" ");
			    w.println();
			    return;
			}

		    // Gosper's hack:
		    int c = set & -set;
		    int r = set + c;
		    set = (((r^set) >>> 2) / c) | r;
		}
		pl("NO");
	}

	static int det(int set) {
		int[][] ps = new int[4][];
		Integer[] s = new Integer[4];
		int sc = 0;
	    for (int j = 0; j < 8; j++) {
	    	if (((set>>j)&1)==1) {
	    		s[sc] = j;
	    		ps[sc] = p[j];
	    		sc++;
	    	}
	    }
	    sort(s, new Comparator<Integer>() {

			@Override
			public int compare(Integer i, Integer j) {
				return p[i][0]-p[j][0];
			}

	    });

	    if (p[s[1]][0]!=p[s[0]][0]) {
	    	int d1 = p[s[1]][0] - p[s[0]][0];
	    	int d2 = p[s[1]][1] - p[s[0]][1];
	    	int d3 = p[s[3]][0] - p[s[2]][0];
	    	int d4 = p[s[3]][1] - p[s[2]][1];
	    	int d5 = p[s[3]][0] - p[s[1]][0];
	    	int d6 = p[s[3]][1] - p[s[1]][1];
	    	int d7 = p[s[2]][0] - p[s[0]][0];
	    	int d8 = p[s[2]][1] - p[s[0]][1];

	    	if (d1*d8-d2*d7==0) return 0;

	    	if (d1 == d3 && d2 == d4 && d5 == d7 && d6 == d8) {
	    		if ((d2==d5&& d1 ==-d6) || (d2==-d5&& d1 ==d6)) return 1;
	    		if (d2*d6 == -d1*d5) return -1;
	    	}
	    	return 0;
	    } else{
	    	if (p[s[0]][1]>p[s[1]][1]) {
	    		int t = s[0];
	    		s[0] = s[1];
	    		s[1] = t;
	    	}
	    	if (p[s[2]][1]>p[s[3]][1]) {
	    		int t = s[2];
	    		s[2] = s[3];
	    		s[3] = t;
	    	}
	    	int d1 = p[s[1]][0] - p[s[0]][0];
	    	int d2 = p[s[1]][1] - p[s[0]][1];
	    	int d3 = p[s[3]][0] - p[s[2]][0];
	    	int d4 = p[s[3]][1] - p[s[2]][1];
	    	int d5 = p[s[3]][0] - p[s[1]][0];
	    	int d6 = p[s[3]][1] - p[s[1]][1];
	    	int d7 = p[s[2]][0] - p[s[0]][0];
	    	int d8 = p[s[2]][1] - p[s[0]][1];

	    	if (d1*d8-d2*d7==0) return 0;

	    	if (d1 == d3 && d2 == d4 && d5 == d7 && d6 == d8) {
	    		if ((d2==d5&& d1 ==-d6) || (d2==-d5&& d1 ==d6)) return 1;
	    		if (d2*d6 == -d1*d5) return -1;
	    	}
	    	return 0;
	    }
	}

}


import java.util.*;
import java.io.PrintWriter;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class D97 {
	static Scanner in = new Scanner(System.in);
	static PrintWriter w = new PrintWriter(System.out, true);

	static int ni() {
		return in.nextInt();
	}

	static String nl() {
		return in.nextLine();
	}

	static void pl(int v) {
		w.println(v);
	}

	static void pl(long v) {
		w.println(v);
	}

	static void pl(Object v) {
		w.println(v);
	}
	static int[][] p;
	public static void main(String[] args) {
		p = new int[8][];
		for(int i = 0; i < 8; i++) p[i] = new int[] {ni(), ni()};
		int set = (1 << 4) - 1;
		int limit = (1 << 8);

		while (set < limit) {
			int t1, t2;
			if (abs(t1=det(set))==1 && abs(t2=det(~set)) == 1 && !(t1==-1 && t2==-1)) {
				pl("YES");
				int ts = (t1 == 1) ? set : ~set;
				Integer[] s = new Integer[4];
				int sc = 0;
			    for (int j = 0; j < 8; j++) {
			    	if (((ts>>j)&1)==1) {
			    		s[sc] = j;
			    		sc++;
			    	}
			    }
			    for (Integer i : s) w.print(i+1+" ");
			    w.println();
			    ts = ~ts;
			    sc = 0;
			    for (int j = 0; j < 8; j++) {
			    	if (((ts>>j)&1)==1) {
			    		s[sc] = j;
			    		sc++;
			    	}
			    }
			    for (Integer i : s) w.print(i+1+" ");
			    w.println();
			    return;
			}

		    // Gosper's hack:
		    int c = set & -set;
		    int r = set + c;
		    set = (((r^set) >>> 2) / c) | r;
		}
		pl("NO");
	}

	static int det(int set) {
		int[][] ps = new int[4][];
		Integer[] s = new Integer[4];
		int sc = 0;
	    for (int j = 0; j < 8; j++) {
	    	if (((set>>j)&1)==1) {
	    		s[sc] = j;
	    		ps[sc] = p[j];
	    		sc++;
	    	}
	    }
	    sort(s, new Comparator<Integer>() {

			@Override
			public int compare(Integer i, Integer j) {
				return p[i][0]-p[j][0];
			}

	    });

	    if (p[s[1]][0]!=p[s[0]][0]) {
	    	int d1 = p[s[1]][0] - p[s[0]][0];
	    	int d2 = p[s[1]][1] - p[s[0]][1];
	    	int d3 = p[s[3]][0] - p[s[2]][0];
	    	int d4 = p[s[3]][1] - p[s[2]][1];
	    	int d5 = p[s[3]][0] - p[s[1]][0];
	    	int d6 = p[s[3]][1] - p[s[1]][1];
	    	int d7 = p[s[2]][0] - p[s[0]][0];
	    	int d8 = p[s[2]][1] - p[s[0]][1];

	    	if (d1*d8-d2*d7==0) return 0;

	    	if (d1 == d3 && d2 == d4 && d5 == d7 && d6 == d8) {
	    		if ((d2==d5&& d1 ==-d6) || (d2==-d5&& d1 ==d6)) return 1;
	    		if (d2*d6 == -d1*d5) return -1;
	    	}
	    	return 0;
	    } else{
	    	if (p[s[0]][1]>p[s[1]][1]) {
	    		int t = s[0];
	    		s[0] = s[1];
	    		s[1] = t;
	    	}
	    	if (p[s[2]][1]>p[s[3]][1]) {
	    		int t = s[2];
	    		s[2] = s[3];
	    		s[3] = t;
	    	}
	    	int d1 = p[s[1]][0] - p[s[0]][0];
	    	int d2 = p[s[1]][1] - p[s[0]][1];
	    	int d3 = p[s[3]][0] - p[s[2]][0];
	    	int d4 = p[s[3]][1] - p[s[2]][1];
	    	int d5 = p[s[3]][0] - p[s[1]][0];
	    	int d6 = p[s[3]][1] - p[s[1]][1];
	    	int d7 = p[s[2]][0] - p[s[0]][0];
	    	int d8 = p[s[2]][1] - p[s[0]][1];

	    	if (d1*d8-d2*d7==0) return 0;

	    	if (d1 == d3 && d2 == d4 && d5 == d7 && d6 == d8) {
	    		if ((d2==d5&& d1 ==-d6) || (d2==-d5&& d1 ==d6)) return 1;
	    		if (d2*d6 == -d1*d5) return -1;
	    	}
	    	return 0;
	    }
	}

}


#include <bits/stdc++.h>

using namespace std;

bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second < b.second);
}

int main(){
	int n;
	cin>>n;
	int array[n][2];
	vector <pair <int,int>> q;
	for(int i=0;i<n;i++){
		cin>>array[i][0]>>array[i][1];
	}
	for(int j=2; j<=30; j++){
		if(array[0][0]%j==0){
			q.push_back(make_pair(j,0));
			while(array[0][0]%j==0){
				array[0][0]/=j;
			}
			if(array[0][1]%j==0){
			    while(array[0][1]%j==0){
				    array[0][1]/=j;
			    }
		    }
		}
		else{
			if(array[0][1]%j==0){
				q.push_back(make_pair(j,0));
				while(array[0][1]%j==0){
					array[0][1]/=j;
				}
				if(array[0][0]%j==0){
				    while(array[0][0]%j==0){
					    array[0][0]/=j;
				    }
		    	}
			}
		}

	}

	for(int l=1; l<n ;l++){
		for(int m=0; m<q.size(); m++){
			if(array[l][0]%q[m].first==0||array[l][1]%q[m].first==0){
				q[m].second++;
			}
		}
	}

	sort(q.begin(), q.end(), sortbysec);
	if(q[q.size()-1].second==n-1){
		cout<<q[q.size()-1].first<<endl;
	}
	else{
		cout<<"-1"<<endl;
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

void divisores(int a);
void sionovrga();

int n;
vector <pair <int,int> > aarray;
vector <int> divi;
set<int> st;

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int a,b;
	cin>>n;
	for(int i=0; i<n ;i++){
		cin>>a>>b;
		aarray.push_back(make_pair(a,b));
	}
	sort(aarray.rbegin(), aarray.rend());
	divisores(aarray[0].first);
	sionovrga();
	divisores(aarray[0].second);
	sionovrga();
	cout<<"-1"<<endl;
	return 0;
}

void divisores(int a){
	aarray.clear();
	for(int i=1; i<sqrt(a)+1; i++){
		if(a%i==0) {
		 	divi.push_back(i);
		 	if(a/i!=i){
				divi.push_back(a/i);
			}
	    }
	}
	sort(divi.begin(), divi.end());
}

void sionovrga(){

	for(int i=0; i<divi.size() ; i++){
		if(divi[i] == 1)
      continue;
		int cont=0;
		int dd = divi[i];

    if(st.count(dd) == 1)
      continue;
    st.insert(dd);
		for(int j=0; j<n ; j++){
			if(aarray[j].first%divi[i]==0 || aarray[j].second%divi[i]==0){
				cont++;
			}
			else{
				break;
			}
		}
		if(cont==n){
			cout<<divi[i]<<endl;
			exit(0);
		}

	}
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n,mayor,a,b;
	cin>>n;
	int divisor=0;
	vector<pair <int,int> >array;
	vector <int> q;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		array.push_back(make_pair(a,b));
	}
	sort(array.rbegin(), array.rend());

    long long int aa=(array[0].first)*(array[0].second);

		for(int j=2; j<=sqrt(aa)+1; j++){
		if(array[0].first%j==0){
			q.push_back(j);
			while(array[0].first%j==0){
				array[0].first/=j;
			}
			if(array[0].second%j==0){
			    while(array[0].second%j==0){
				    array[0].second/=j;
			    }
		    }
		}
		else{
			if(array[0].second%j==0){
				q.push_back(j);
				while(array[0].second%j==0){
					array[0].second/=j;
				}
				if(array[0].first%j==0){
				    while(array[0].first%j==0){
					    array[0].first/=j;
				    }
		    	}
			}
		}

	}

   	for(int i=0;i<q.size();i++){

  		for(int s=1; s<n;s++){

        	if(array[s].first%q[i]==0||array[s].second % q[i]==0){
                divisor++;
            }
        }
            if(divisor==n-1){
                cout<<q[i]<<endl;
                exit(0);
            }
            divisor=0;
        }
        cout<<-1<<endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

void divisores(int a);
void sionovrga();

int n;
vector <pair <int,int> > aarray;
vector <int> divi;

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int a,b;
	cin>>n;
	for(int i=0; i<n ;i++){
		cin>>a>>b;
		aarray.push_back(make_pair(a,b));
	}
	sort(aarray.rbegin(), aarray.rend());
	divisores(aarray[0].first);
	sionovrga();
	divisores(aarray[0].second);
	sionovrga();
	cout<<"-1"<<endl;
	return 0;
}

void divisores(int a){
	for(int i=2; i<sqrt(a)+1; i++){
		if(a%i==0) {
		 	divi.push_back(i);
		 	if(a/i!=i){
				divi.push_back(a/i);
			}
	    }
	}
	sort(divi.begin(), divi.end());
}

void sionovrga(){

	for(int i=0; i<divi.size() ; i++){
		int cont=0;
		for(int j=0; j<n ; j++){
			if(aarray[j].first%divi[i]==0 || aarray[j].second%divi[i]==0){
				cont++;
			}
			else{
				break;
			}
		}
		if(cont==n){
			cout<<divi[i]<<endl;
			exit(0);
		}

	}
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n,mayor,a,b;
	cin>>n;
	int divisor=0;
	vector<pair <int,int> >array;
	vector <int> q;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		array.push_back(make_pair(a,b));
	}
	sort(array.rbegin(), array.rend());

		for(int j=2; j<=sqrt((array[0].first))+1; j++){
		if(array[0].first%j==0){
			q.push_back(j);
			while(array[0].first%j==0){
				array[0].first/=j;
			}
			if(array[0].second%j==0){
			    while(array[0].second%j==0){
				    array[0].second/=j;
			    }
		    }
		}
		else{
			if(array[0].second%j==0){
				q.push_back(j);
				while(array[0].second%j==0){
					array[0].second/=j;
				}
				if(array[0].first%j==0){
				    while(array[0].first%j==0){
					    array[0].first/=j;
				    }
		    	}
			}
		}

	}
		for(int j=2; j<=sqrt((array[0].second))+1; j++){
		if(array[0].first%j==0){
			q.push_back(j);
			while(array[0].first%j==0){
				array[0].first/=j;
			}
			if(array[0].second%j==0){
			    while(array[0].second%j==0){
				    array[0].second/=j;
			    }
		    }
		}
		else{
			if(array[0].second%j==0){
				q.push_back(j);
				while(array[0].second%j==0){
					array[0].second/=j;
				}
				if(array[0].first%j==0){
				    while(array[0].first%j==0){
					    array[0].first/=j;
				    }
		    	}
			}
		}

	}

   	for(int i=0;i<q.size();i++){

  		for(int s=1; s<n;s++){

        	if(array[s].first%q[i]==0||array[s].second % q[i]==0){
                divisor++;
            }
        }
            if(divisor==n-1){
                cout<<q[i]<<endl;
                exit(0);
            }
            divisor=0;
        }
        cout<<-1<<endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

void divisores(int a);
void sionovrga();

int n;
vector <pair <int,int> > aarray;
vector <int> divi;

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int a,b;
	cin>>n;
	for(int i=0; i<n ;i++){
		cin>>a>>b;
		aarray.push_back(make_pair(a,b));
	}
	sort(aarray.rbegin(), aarray.rend());
	divisores(aarray[0].first);
	sionovrga();
	divisores(aarray[0].second);
	sionovrga();
	cout<<"-1"<<endl;
	return 0;
}

void divisores(int a){
	for(int i=2; i<sqrt(a)+1; i++){
		if(a%i==0) {
		 	divi.push_back(i);
		 	if(a/i!=i){
				divi.push_back(a/i);
			}
	    }
	}
}

void sionovrga(){

	for(int i=0; i<divi.size() ; i++){
		int cont=0;
		for(int j=0; j<n ; j++){
			if(aarray[j].first%divi[i]==0 || aarray[j].second%divi[i]==0){
				cont++;
			}
			else{
				break;
			}
		}
		if(cont==n){
			cout<<divi[i]<<endl;
			exit(0);
		}

	}
}


#include<bits/stdc++.h>

using namespace std;

void divisores(int a);
void sionovrga();

int n;
vector <pair <int,int> > aarray;
vector <int> divi;

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int a,b;
	cin>>n;
	for(int i=0; i<n ;i++){
		cin>>a>>b;
		aarray.push_back(make_pair(a,b));
	}
	sort(aarray.rbegin(), aarray.rend());
	divisores(aarray[0].first);
	sionovrga();
	divisores(aarray[0].second);
	sionovrga();
	cout<<"-1"<<endl;
	return 0;
}

void divisores(int a){
	aarray.clear();
	for(int i=2; i<sqrt(a)+1; i++){
		if(a%i==0) {
		 	divi.push_back(i);
		 	if(a/i!=i){
				divi.push_back(a/i);
			}
	    }
	}
	sort(divi.begin(), divi.end());
}

void sionovrga(){

	for(int i=0; i<divi.size() ; i++){
		int cont=0;
		for(int j=0; j<n ; j++){
			if(aarray[j].first%divi[i]==0 || aarray[j].second%divi[i]==0){
				cont++;
			}
			else{
				break;
			}
		}
		if(cont==n){
			cout<<divi[i]<<endl;
			exit(0);
		}

	}
}


#include <bits/stdc++.h>

using namespace std;

int const N = 2e5 + 1;
int n;
pair<int, int> a[N];
vector<int> d;
set<int> st;

void calc_div(int x) {
  d.clear();
  int sqrtx = sqrt(x) + 1;
  for(int i = 1; i <= sqrtx; ++i) {
    if(x % i == 0) {
      d.push_back(i);

      if(x / i != i)
        d.push_back(x / i);
    }
  }
}

void solve() {
  for(int i = 0, cur, dd; i < d.size(); ++i) {
    if(d[i] == 1)
      continue;
    cur = 0;
    dd = d[i];

    if(st.count(dd) == 1)
      continue;
    st.insert(dd);

    for(int j = 1; j < n; ++j)
      if(a[j].first % dd == 0 || a[j].second % dd == 0)
        ++cur;
      else
        break;

    if(cur == n - 1) {
      printf("%d\n", dd);
      exit(0);
    }
  }
}

int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; ++i)
    scanf("%d %d", &a[i].first, &a[i].second);

  sort(a, a + n);
  reverse(a, a + n);

  calc_div(a[0].first);
  solve();

  calc_div(a[0].second);
  solve();

  puts("-1");

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second < b.second);
}

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n,mayor,a,b;
	cin>>n;
	vector <pair <int,int>> array;
	vector <pair <int,int>> q;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		array.push_back(make_pair(a,b));
	}
	sort(q.begin(), q.end(), sortbysec);

	if(array[n-1].first>=array[n-1].second){
		mayor=array[n-1].first;
	}
	else{
		mayor=array[n-1].second;
	}

	for(int j=2; j<=sqrt(mayor); j++){
		if(array[n-1].first%j==0){
			q.push_back(make_pair(j,0));
			while(array[n-1].first%j==0){
				array[n-1].first/=j;
			}
			if(array[n-1].second%j==0){
			    while(array[n-1].second%j==0){
				    array[n-1].second/=j;
			    }
		    }
		}
		else{
			if(array[n-1].second%j==0){
				q.push_back(make_pair(j,0));
				while(array[n-1].second%j==0){
					array[n-1].second/=j;
				}
				if(array[n-1].first%j==0){
				    while(array[n-1].first%j==0){
					    array[n-1].first/=j;
				    }
		    	}
			}
		}

	}

	for(int l=0; l<n-1 ;l++){
		for(int m=0; m<q.size(); m++){
			if(array[l].first%q[m].first==0||array[l].second%q[m].first==0){
				q[m].second++;
			}
		}
	}

	sort(q.begin(), q.end(), sortbysec);
	if(q[q.size()-1].second==n-1){
		cout<<q[q.size()-1].first<<endl;
	}
	else{
		cout<<"-1"<<endl;
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

void divisores(int a);
void sionovrga();

int n;
vector <pair <int,int> > aarray;
vector <int> divi;
set<int> st;

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int a,b;
	cin>>n;
	for(int i=0; i<n ;i++){
		cin>>a>>b;
		aarray.push_back(make_pair(a,b));
	}
	sort(aarray.rbegin(), aarray.rend());
	divisores(aarray[0].first);
	sionovrga();
	divisores(aarray[0].second);
	sionovrga();
	cout<<"-1"<<endl;
	return 0;
}

void divisores(int a){
	aarray.clear();
	for(int i=2; i<sqrt(a)+1; i++){
		if(a%i==0) {
		 	divi.push_back(i);
		 	if(a/i!=i){
				divi.push_back(a/i);
			}
	    }
	}
	sort(divi.begin(), divi.end());
}

void sionovrga(){

	for(int i=0; i<divi.size() ; i++){
		int cont=0;
		int dd = divi[i];

    if(st.count(dd) == 1)
      continue;
    st.insert(dd);
		for(int j=0; j<n ; j++){
			if(aarray[j].first%divi[i]==0 || aarray[j].second%divi[i]==0){
				cont++;
			}
			else{
				break;
			}
		}
		if(cont==n){
			cout<<divi[i]<<endl;
			exit(0);
		}

	}
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll n;
pair<ll,ll> nums[150001];

bool is_div(ll d, ll num) {
  return num%d==0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;

  for (ll i=0; i<n; i++) {
    ll a,b; cin >> a >> b;
    nums[i]=make_pair(a,b);
  }

  ll end=-1;
  for (ll i=0; i<n; i++) {
    ll a=nums[i].first; ll b=nums[i].second;
    ll bigger=max(a,b);
    if (end==-1 || bigger<end) end=bigger;
  }

  for (ll d=2; d<=end; d++) {
    bool fail=false;
    for (ll i=0; i<n; i++) {
      ll a=nums[i].first; ll b=nums[i].second;
      if (!is_div(d,a) && !is_div(d,b)) {
	fail=true; break;
      }
    }
    if (!fail) {
      cout << d << "\n";
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

pair<ll,ll> nums[150001];
unordered_set<ll> primes[150001];

bool is_div(ll d, ll num) {
  return num%d==0;
}

void add_primes(unordered_set<ll> &p, ll num) {
  while (num%2==0) {
    p.insert(2);
    num/=2;
  }
  for (ll i=3; i<= (ll) sqrt(num); i+=2) {
    while (num%i==0) {
      p.insert(i); num/=i;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;

  for (ll i=0; i<n; i++) {
    ll a,b; cin >> a >> b;
    nums[i]=make_pair(a,b);
  }

  ll end=-1;
  for (ll i=0; i<n; i++) {
    ll a=nums[i].first; ll b=nums[i].second;
    ll bigger=max(a,b);
    if (end==-1 || bigger<end) end=bigger;
  }

  for (ll i=0; i<n; i++) {
    ll a=nums[i].first; ll b=nums[i].second;
    add_primes(primes[i],a);
    add_primes(primes[i],b);
  }

  for (auto &p: primes[0]) {
    bool fail=false;
    for (ll i=1; i<n; i++) {
      if (primes[i].find(p)==primes[i].end()) {
	fail=true; break;
      }
    }
    if (!fail) {
      cout << p << "\n";
      return 0;
    }
  }

  cout << "-1\n";
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll n;
ll A[150001],B[150001];

void add_primes(unordered_set<ll> &p, ll num) {
  // for (ll i=2; i<= (ll) sqrt(num); i++) {
  //   if (num%i==0) p.insert(i);
  // }
  while (num%2==0) {
    p.insert(2);
    num/=2;
  }
  for (ll i=3; i<= (ll) sqrt(num); i+=2) {
    while (num%i==0) {
      p.insert(i); num/=i;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;

  for (ll i=0; i<n; i++) {
    ll a,b; cin >> a >> b;
    A[i]=a; B[i]=b;
  }

  for (ll i=0; i<150001; i++) {
    A[i]=0; B[i]=0;
  }

  unordered_set<ll> primes;
  add_primes(primes,A[0]);
  add_primes(primes,B[0]);

  for (auto &p: primes) {
    if (p==1) continue;
    bool flag=true;
    for (ll i=1; i<n; i++) {
      bool checka=(A[i]%p==0);
      bool checkb=(B[i]%p==0);
      if(!checka && !checkb) {
	flag=false; break;
      }
    }
    if (flag) {
	cout << p << endl;
	return 0;
      }
  }

  cout << "-1\n";
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll n;
pair<ll,ll> nums[150001];

bool is_div(ll d, ll num) {
  return num%d==0;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;

  for (ll i=0; i<n; i++) {
    ll a,b; cin >> a >> b;
    nums[i]=make_pair(a,b);
  }

  ll end=-1;
  for (ll i=0; i<n; i++) {
    ll a=nums[i].first; ll b=nums[i].second;
    ll bigger=max(a,b);
    if (end==-1 || bigger<end) end=bigger;
  }

  bool div2=true;
  for (ll i=0; i<n; i++) {
    ll a=nums[i].first; ll b=nums[i].second;
    if (a%2!=0 && b%2!=0) { div2=false; break; }
  }
  if (div2) {
    cout << 2 << "\n"; return 0;
  }

  for (ll d=3; d<=end; d+=2) {
    bool fail=false;
    for (ll i=0; i<n; i++) {
      ll a=nums[i].first; ll b=nums[i].second;
      if (!is_div(d,a) && !is_div(d,b)) {
	fail=true; break;
      }
    }
    if (!fail) {
      cout << d << "\n";
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }

const int maxn=(int)4e5+5;

int n;

void fac(int x, set<int>& factors) {
  for (int p=2; p*p<=x; p++) {
    if (x%p) continue;
    factors.insert(p);
    while (x%p==0) x=x/p;
  }
  if (x>1) factors.insert(x);
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  //cout << fixed << setprecision(6);
  cin>>n;

  int x,y; cin>>x>>y;
  set<int> factors;
  fac(x,factors);
  fac(y,factors);

  for (int i=2; i<=n; i++) {
    int x,y;
    cin>>x>>y;
    set<int> tmp;

    for (auto p: factors) {
      if (x%p == 0 || y%p == 0) tmp.insert(p);
    }

    factors = tmp;
  }

  if (factors.size() == 0) out(-1);

  cout<<*factors.rbegin()<<endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

pair<ll,ll> nums[150001];
unordered_set<ll> primes[150001];

bool is_div(ll d, ll num) {
  return num%d==0;
}

void add_primes(unordered_set<ll> &p, ll num) {
  // for (ll i=2; i<= (ll) sqrt(num); i++) {
  //   if (num%i==0) p.insert(i);
  // }
  while (num%2==0) {
    p.insert(2);
    num/=2;
  }
  for (ll i=3; i<= (ll) sqrt(num); i+=2) {
    while (num%i==0) {
      p.insert(i); num/=i;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;

  // for (ll i=0; i<n; i++) {
  //   ll a,b; cin >> a >> b;
  //   nums[i]=make_pair(a,b);
  // }

  // ll end=-1;
  // for (ll i=0; i<n; i++) {
  //   ll a=nums[i].first; ll b=nums[i].second;
  //   ll bigger=max(a,b);
  //   if (end==-1 || bigger<end) end=bigger;
  // }

  for (ll i=0; i<n; i++) {
    ll a,b;
    cin >> a >> b;
    // ll a=nums[i].first; ll b=nums[i].second;
    add_primes(primes[i],a);
    add_primes(primes[i],b);
  }

  for (auto &p: primes[0]) {
    bool fail=false;
    for (ll i=1; i<n; i++) {
      if (primes[i].find(p)==primes[i].end()) {
	fail=true; break;
      }
    }
    if (!fail) {
      cout << p << "\n";
      return 0;
    }
  }

  cout << "-1\n";
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

pair<ll,ll> nums[150001];
unordered_set<ll> primes[150001];

bool is_div(ll d, ll num) {
  return num%d==0;
}

void add_primes(unordered_set<ll> &p, ll num) {
  for (ll i=2; i<= (ll) sqrt(num); i++) {
    if (num%i==0) p.insert(i);
  }
  // while (num%2==0) {
  //   p.insert(2);
  //   num/=2;
  // }
  // for (ll i=3; i<= (ll) sqrt(num); i+=2) {
  //   while (num%i==0) {
  //     p.insert(i); num/=i;
  //   }
  // }
}

int main() {
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;

  for (ll i=0; i<n; i++) {
    ll a,b; cin >> a >> b;
    nums[i]=make_pair(a,b);
  }

  ll end=-1;
  for (ll i=0; i<n; i++) {
    ll a=nums[i].first; ll b=nums[i].second;
    ll bigger=max(a,b);
    if (end==-1 || bigger<end) end=bigger;
  }

  for (ll i=0; i<n; i++) {
    ll a=nums[i].first; ll b=nums[i].second;
    add_primes(primes[i],a);
    add_primes(primes[i],b);
  }

  for (auto &p: primes[0]) {
    bool fail=false;
    for (ll i=1; i<n; i++) {
      if (primes[i].find(p)==primes[i].end()) {
	fail=true; break;
      }
    }
    if (!fail) {
      cout << p << "\n";
      return 0;
    }
  }

  cout << "-1\n";
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll n;
ll A[150001],B[150001];

void add_primes(unordered_set<ll> &p, ll num) {
  // for (ll i=2; i<= (ll) sqrt(num); i++) {
  //   if (num%i==0) p.insert(i);
  // }
  while (num%2==0) {
    p.insert(2);
    num/=2;
  }
  for (ll i=3; i<= (ll) sqrt(num); i+=2) {
    while (num%i==0) {
      p.insert(i); num/=i;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;

  for (ll i=0; i<150001; i++) {
    A[i]=0; B[i]=0;
  }

  for (ll i=0; i<n; i++) {
    ll a,b; cin >> a >> b;
    A[i]=a; B[i]=b;
  }

  unordered_set<ll> primes;
  add_primes(primes,A[0]);
  add_primes(primes,B[0]);

  for (auto &p: primes) {
    if (p==1) continue;
    bool flag=true;
    for (ll i=1; i<n; i++) {
      bool checka=(A[i]%p==0);
      bool checkb=(B[i]%p==0);
      if(!checka && !checkb) {
	flag=false; break;
      }
    }
    if (flag) {
	cout << p << endl;
	return 0;
      }
  }

  cout << "-1\n";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }

const int maxn=(int)4e5+5;

int n;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  //cout << fixed << setprecision(6);
  cin>>n;

  int x,y; cin>>x>>y;
  set<int> factors = {x,y};
  for (int p=2; p*p <= x; p++) {
    if (x%p) continue;
    factors.insert(p);
    factors.insert(x/p);
  }
  for (int p=2; p*p <= y; p++) {
    if (y%p) continue;
    factors.insert(p);
    factors.insert(y/p);
  }

  for (int i=2; i<=n; i++) {
    int x,y;
    cin>>x>>y;
    set<int> tmp;

    for (auto p: factors) {
      if (x%p == 0 || y%p == 0) tmp.insert(p);
    }

    factors = tmp;
  }

  if (factors.size() == 0) out(-1);

  cout<<*factors.rbegin()<<endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll n;
ll A[150001],B[150001];

void add_primes(unordered_set<ll> &p, ll num) {
  // for (ll i=2; i<= (ll) sqrt(num); i++) {
  //   if (num%i==0) p.insert(i);
  // }
  while (num%2==0) {
    p.insert(2);
    num/=2;
  }
  for (ll i=3; i<= (ll) sqrt(num); i+=2) {
    while (num%i==0) {
      p.insert(i); num/=i;
    }
  }
  if (num>2) p.insert(num);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;

  for (ll i=0; i<150001; i++) {
    A[i]=0; B[i]=0;
  }

  for (ll i=0; i<n; i++) {
    ll a,b; cin >> a >> b;
    A[i]=a; B[i]=b;
  }

  unordered_set<ll> primes;
  add_primes(primes,A[0]);
  add_primes(primes,B[0]);

  for (auto &p: primes) {
    if (p==1) continue;
    bool flag=true;
    for (ll i=1; i<n; i++) {
      bool checka=(A[i]%p==0);
      bool checkb=(B[i]%p==0);
      if(!checka && !checkb) {
	flag=false; break;
      }
    }
    if (flag) {
	cout << p << endl;
	return 0;
      }
  }

  cout << "-1\n";
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll n;
ll A[150001],B[150001];

void add_primes(unordered_set<ll> &p, ll num) {
  // for (ll i=2; i<= (ll) sqrt(num); i++) {
  //   if (num%i==0) p.insert(i);
  // }
  while (num%2==0) {
    p.insert(2);
    num/=2;
  }
  for (ll i=3; i<= (ll) sqrt(num); i+=2) {
    while (num%i==0) {
      p.insert(i); num/=i;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;

  for (ll i=0; i<n; i++) {
    ll a,b; cin >> a >> b;
    A[i]=a; B[i]=b;
  }

  unordered_set<ll> primes;
  add_primes(primes,A[0]);
  add_primes(primes,B[0]);

  for (auto &p: primes) {
    bool flag=true;
    for (ll i=1; i<n; i++) {
      bool checka=(A[i]%p==0);
      bool checkb=(B[i]%p==0);
      if(!checka && !checkb) {
	flag=false; break;
      }
    }
    if (flag) {
	cout << p << endl;
	return 0;
      }
  }

  cout << "-1\n";
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll n;
ll A[150001],B[150001];

void add_primes(unordered_set<ll> &p, ll num) {
  while (num%2==0) {
    p.insert(2);
    num/=2;
  }
  for (ll i=3; i<= (ll) sqrt(num); i+=2) {
    while (num%i==0) {
      p.insert(i); num/=i;
    }
  }
  if (num>2) p.insert(num);
}

int main() {
  //ios_base::sync_with_stdio(false);
  cin >> n;

  for (ll i=0; i<150001; i++) {
    A[i]=0; B[i]=0;
  }

  for (ll i=0; i<n; i++) {
    ll a,b; cin >> a >> b;
    A[i]=a; B[i]=b;
  }

  unordered_set<ll> primes;
  add_primes(primes,A[0]);
  add_primes(primes,B[0]);

  for (auto &p: primes) {
    if (p==1) continue;
    bool flag=true;
    for (ll i=1; i<n; i++) {
      bool checka=(A[i]%p==0);
      bool checkb=(B[i]%p==0);
      if(!checka && !checkb) {
	flag=false; break;
      }
    }
    if (flag) {
	cout << p << endl;
	return 0;
      }
  }

  cout << "-1\n";
  return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>

#define forn(i,a,b) for(int i = a; i < b; i++)
#define ll long long
#define fr first
#define sc second
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main()
{
    ll n;
    cin >> n;
    ll a[n], b[n];
    ll m = 2*((ll)1e9);
    ll m1 = 2*((ll)1e9);
    forn(i,0,n)
    {
        cin >> a[i] >> b[i];
        m = min(m, a[i]);
        m1 = min(m1, b[i]);
    }
    forn(i,0,n)
    a[i] = a[i]*b[i]/__gcd(a[i],b[i]);
    ll g = a[0];
    forn(i,0,n)
    g = __gcd(a[i],g);
    if(g == 1)
    {
        cout << -1;
        return 0;
    }
    ll g1 = __gcd(m,g);
    ll g2 = __gcd(m1,g);
    if(g != 1)
        cout << g1;
    else
        cout << g2;
    return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>

#define forn(i,a,b) for(int i = a; i < b; i++)
#define ll long long
#define fr first
#define sc second
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main()
{
    ll n;
    cin >> n;
    ll a[n], b[n];
    ll m = 2*((ll)1e9);
    forn(i,0,n)
    {
        cin >> a[i] >> b[i];
        m = min(m, min(a[i],b[i]));
    }
    forn(i,0,n)
    a[i] = a[i]*b[i]/__gcd(a[i],b[i]);
    ll g = a[0];
    forn(i,0,n)
    g = __gcd(a[i],g);
    g = __gcd(m,g);
    if(g > 1) cout << g;
    else cout << -1;
    return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>

#define forn(i,a,b) for(ull i = a; i < b; i++)
#define ll long long
#define ull unsigned long long
#define fr first
#define sc second
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

ull prime(ll n)
{
    if(n%2 == 0) return 2;

    forn(i,3,sqrt(n)+1)
    {
        if(n%i == 0) return i;
    }
    return 1;
}

int main()
{
    ull n;
    cin >> n;
    ll a[n], b[n];
    forn(i,0,n)
    cin >> a[i] >> b[i];
    forn(i,0,n)
    a[i] = a[i]*b[i]/__gcd(a[i],b[i]);
    ll g = a[0];
    forn(i,0,n)
    g = __gcd(a[i],g);
    if(g == 1)
    {
        cout << -1;
        return 0;
    }
    forn(i,0,n)
    {
        ll mm = __gcd(g, a[i]);
        if(mm > 1)
        {
            g = mm;
        }
        else
        {
            g = __gcd(g, b[i]);
        }
    }
    cout << g;
    return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>

#define forn(i,a,b) for(ull i = a; i < b; i++)
#define ll long long
#define ull unsigned long long
#define fr first
#define sc second
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

ull prime(ull n)
{
    if(n%2 == 0) return 2;

    forn(i,3,sqrt(n)+1)
    {
        if(n%i == 0) return i;
    }
    return 1;
}

int main()
{
    ull n;
    cin >> n;
    ull a[n], b[n];
    forn(i,0,n)
    cin >> a[i] >> b[i];
    forn(i,0,n)
    a[i] = a[i]*b[i]/__gcd(a[i],b[i]);
    ull g = a[0];
    forn(i,0,n)
    g = __gcd(a[i],g);
    if(g == 1)
    {
        cout << -1;
        return 0;
    }
    ull fg = prime(g);
    if(fg == 1ull)
    {
        forn(i,0,n) cout << a[i] << " ";
        cout << g << endl;
        return 0;
    }
    cout << fg;
    return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>

#define forn(i,a,b) for(int i = a; i < b; i++)
#define ll long long
#define fr first
#define sc second
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

ll prime(ll n)
{
    if(n%2 == 0) return 2;

    forn(i,3,sqrt(n)+1)
    {
        if(n%i == 0) return i;
    }
    return 1;
}

int main()
{
    ll n;
    cin >> n;
    ll a[n], b[n];
    ll m = 2*((ll)1e9);
    ll m1 = 2*((ll)1e9);
    forn(i,0,n)
    {
        cin >> a[i] >> b[i];
        m = min(m, a[i]);
        m1 = min(m1, b[i]);
    }
    forn(i,0,n)
    a[i] = a[i]*b[i]/__gcd(a[i],b[i]);
    ll g = a[0];
    forn(i,0,n)
    g = __gcd(a[i],g);
    if(g == 1)
    {
        cout << -1;
        return 0;
    }
    cout << prime(g);
    return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>

#define forn(i,a,b) for(ull i = a; i < b; i++)
#define ll long long
#define ull unsigned long long
#define fr first
#define sc second
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

ull prime(ll n)
{
    if(n%2 == 0) return 2;

    forn(i,3,sqrt(n)+1)
    {
        if(n%i == 0) return i;
    }
    return 1;
}

int main()
{
    ull n;
    cin >> n;
    ll a[n], b[n];
    forn(i,0,n)
    cin >> a[i] >> b[i];
    ll g = 0;
    forn(i,0,n)
    g = __gcd(a[i]*b[i], g);
    if(g == 1)
    {
        cout << -1;
        return 0;
    }
    forn(i,0,n)
    {
        ll mm = __gcd(g, a[i]);
        if(mm > 1)
        {
            g = mm;
        }
        else
        {
            g = __gcd(g, b[i]);
        }
    }
    cout << g;
    return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>

#define forn(i,a,b) for(ull i = a; i < b; i++)
#define ll long long
#define ull unsigned long long
#define fr first
#define sc second
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

ull prime(ull n)
{
    if(n%2 == 0) return 2;

    forn(i,3,sqrt(n)+1)
    {
        if(n%i == 0) return i;
    }
    return 1;
}

int main()
{
    ull n;
    cin >> n;
    ull a[n], b[n];
    forn(i,0,n)
    cin >> a[i] >> b[i];
    forn(i,0,n)
    a[i] = a[i]*b[i]/__gcd(a[i],b[i]);
    ull g = a[0];
    forn(i,0,n)
    g = __gcd(a[i],g);
    if(g == 1)
    {
        cout << -1;
        return 0;
    }
    cout << prime(g);
    return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>

#define forn(i,a,b) for(int i = a; i < b; i++)
#define ll long long
#define fr first
#define sc second
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main()
{
    ll n;
    cin >> n;
    ll a[n], b[n];
    ll m = a[0];
    forn(i,0,n)
    {
        cin >> a[i] >> b[i];
        m = min(m, min(a[i],b[i]));
    }
    forn(i,0,n)
    a[i] = a[i]*b[i]/__gcd(a[i],b[i]);
    ll g = a[0];
    forn(i,0,n)
    g = __gcd(a[i],g);
    g = __gcd(m,g);
    if(g > 1) cout << g;
    else cout << -1;
    return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>

#define forn(i,a,b) for(ull i = a; i < b; i++)
#define ll long long
#define ull unsigned long long
#define fr first
#define sc second
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

ull prime(ll n)
{
    if(n%2 == 0) return 2;

    forn(i,3,sqrt(n)+1)
    {
        if(n%i == 0) return i;
    }
    return 1;
}

int main()
{
    ull n;
    cin >> n;
    ll a[n], b[n];
    forn(i,0,n)
    cin >> a[i] >> b[i];
    forn(i,0,n)
    a[i] = a[i]*b[i]/__gcd(a[i],b[i]);
    ll g = a[0];
    forn(i,0,n)
    g = __gcd(a[i],g);
    if(g == 1)
    {
        cout << -1;
        return 0;
    }
    ull fg = prime(g);
    if(fg == 1ull)
    {
        forn(i,0,n) if(a[i] < 0) cout << a[i] << " ";
        cout << g << endl;
        return 0;
    }
    cout << fg;
    return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>

#define forn(i,a,b) for(int i = a; i < b; i++)
#define ll long long
#define fr first
#define sc second
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main()
{
    ll n;
    cin >> n;
    ll a[n], b[n];
    forn(i,0,n)
    cin >> a[i] >> b[i];
    forn(i,0,n)
    a[i] = a[i]*b[i]/__gcd(a[i],b[i]);
    ll g = a[0];
    forn(i,0,n)
    g = __gcd(a[i],g);
    if(g > 1) cout << g;
    else cout << -1;
    return 0;
}


#include <iostream>
#include <queue>
#include <algorithm>

#define forn(i,a,b) for(int i = a; i < b; i++)
#define ll long long
#define ull unsigned long long
#define fr first
#define sc second
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

ull prime(ull n)
{
    if(n%2 == 0) return 2;

    forn(i,3,sqrt(n)+1)
    {
        if(n%i == 0) return i;
    }
    return 1;
}

int main()
{
    ull n;
    cin >> n;
    ull a[n], b[n];
    forn(i,0,n)
    a[i] = a[i]*b[i]/__gcd(a[i],b[i]);
    ull g = a[0];
    forn(i,0,n)
    g = __gcd(a[i],g);
    if(g == 1)
    {
        cout << -1;
        return 0;
    }
    cout << prime(g);
    return 0;
}