import java.util.*;
import java.lang.*;
import java.io.*;
public class Solution {
    public static void main(String[] args) {
        InputReader fi = new InputReader(System.in);

        int n, m, i;
        n = fi.nextInt();
        m = fi.nextInt();
        long[] tom = new long[n];
        long[] monster = new long[m];
        for (i = 0; i < n; i++) {
            tom[i] = fi.nextInt();
        }

        for (i = 0; i < m; i++) {
            monster[i] = fi.nextInt();
        }
        long ans = Integer.MAX_VALUE;
        long temp=Integer.MIN_VALUE;

        int index=0;

            for (int k = 0; k < n; k++) {

                for (int j = 0; j < m; j++) {

                    long e=tom[k]*monster[j];
                    if (e > temp){
                        temp=e;
                        index=k;
                    }

                }

            }
            //System.out.println(" temp " +temp + " index " +index);

            temp=Integer.MIN_VALUE;
            for (i=0;i<n;i++){
                for (int j=0; j<m ;j++){
                    if (i!=index)
                    temp=Math.max(temp,tom[i]*monster[j]);
                }
            }

        System.out.println(temp);
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[8192];
    private int curChar, snumChars;
    private SpaceCharFilter filter;

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

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

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

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

    public int[] nextIntArray(int n) {
        int a[] = new int[n+1];
        for (int i = 1; i <= n; i++)
            a[i] = nextInt();
        return a;
    }

    public String readString() {
        int c = snext();
        while (isSpaceChar(c))
            c = snext();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = snext();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

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


import java.util.*;
import java.lang.*;
import java.io.*;
public class Solution {
    public static void main(String[] args) {
        InputReader fi = new InputReader(System.in);

        int n, m, i;
        n = fi.nextInt();
        m = fi.nextInt();
        long[] tom = new long[n];
        long[] monster = new long[m];
        for (i = 0; i < n; i++) {
            tom[i] = fi.nextLong();
        }

        for (i = 0; i < m; i++) {
            monster[i] = fi.nextLong();
        }
        long ans = Integer.MAX_VALUE;
        long temp=Integer.MIN_VALUE;
        for (i = 0; i < n; i++) {

            temp=Integer.MIN_VALUE;
            for (int k = 0; k < n; k++) {

                    if(k==i)
                        continue;
                for (int j = 0; j < m; j++) {

                        temp=Math.max(temp,tom[k]*monster[j]);

                }
            }

            ans=Math.min(ans,temp);

        }
        System.out.println(ans);
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[8192];
    private int curChar, snumChars;
    private SpaceCharFilter filter;

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

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

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

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

    public int[] nextIntArray(int n) {
        int a[] = new int[n+1];
        for (int i = 1; i <= n; i++)
            a[i] = nextInt();
        return a;
    }

    public String readString() {
        int c = snext();
        while (isSpaceChar(c))
            c = snext();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = snext();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

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


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

public class cf133{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] aa = new int[n];
		int[] bb = new int[m];

		for(int i=0;i<n;i++){
           aa[i] = sc.nextInt();
		}

		for(int i=0;i<m;i++){
           bb[i] = sc.nextInt();
		}
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        Arrays.sort(aa);
        Arrays.sort(bb);

        long a1 = aa[0];
        long a2 = aa[aa.length-1];
        long b1 = bb[0];
        long b2 = bb[bb.length-1];

        long max1 = Math.max(a1*1L*b1,a1*1L*b2);
        long max2 = Math.max(a2*1L*b1,a2*1L*b2);
        long cul = 0;
        if(max1>max2){
           cul = aa[0];
        }
        else{
           cul = aa[aa.length-1];
        }
        ArrayList<Long> ans = new ArrayList<>();
		long ansmax = Long.MIN_VALUE;
		for(int i=0;i<n;i++){
			if(aa[i]==cul){
               continue;
			}
            for(int j=0;j<m;j++){
               Long num = (aa[i]*1L*bb[j]);
              // System.out.println(num);
               ansmax = Math.max(ansmax,num);
              // ans.add(num);
            }
		}

		//Collections.sort(ans);
		//long res = ans.get(aa.size()-1);
		System.out.println(ansmax);

	}
}


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

public class cf133{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] aa = new int[n];
		int[] bb = new int[m];

		for(int i=0;i<n;i++){
           aa[i] = sc.nextInt();
		}

		for(int i=0;i<m;i++){
           bb[i] = sc.nextInt();
		}
        Long maxx = Long.MIN_VALUE;
		long ind = 0;
		for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(maxx<aa[i]*1L*bb[j]){
                   maxx = aa[i]*1L*bb[j];
                   ind = aa[i];
                }
            }
		}
        // int max = Integer.MIN_VALUE;
        // int min = Integer.MAX_VALUE;
        // Arrays.sort(aa);
        // Arrays.sort(bb);

        // long a1 = aa[0];
        // long a2 = aa[aa.length-1];
        // long b1 = bb[0];
        // long b2 = bb[bb.length-1];

        // long max1 = Math.max(a1*1L*b1,a1*1L*b2);
        // long max2 = Math.max(a2*1L*b1,a2*1L*b2);
        // long cul = 0;
        // if(max1>max2){
        //    cul = aa[0];
        // }
        // else{
        //    cul = aa[aa.length-1];
        // }
        ArrayList<Long> ans = new ArrayList<>();
		long ansmax = Long.MIN_VALUE;
		for(int i=0;i<n;i++){
			if(aa[i]==ind){
              continue;
			}
            for(int j=0;j<m;j++){
               Long num = (aa[i]*1L*bb[j]);
               //
               ansmax = Math.max(ansmax,num);

               //ans.add(num);
            }
		}

//		Collections.sort(ans);
		//long res = ans.get(aa.size()-1);
		System.out.println(ansmax);

	}
}


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

public class cf133{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] aa = new int[n];
		int[] bb = new int[m];

		for(int i=0;i<n;i++){
           aa[i] = sc.nextInt();
		}

		for(int i=0;i<m;i++){
           bb[i] = sc.nextInt();
		}
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        ArrayList<Long> ans = new ArrayList<>();
		for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
               long num = aa[i]*bb[j];
               ans.add(num);
            }
		}

		Collections.sort(ans);
		System.out.println(ans.get(ans.size()-2));

	}
}


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

public class cf133{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] aa = new int[n];
		int[] bb = new int[m];

		for(int i=0;i<n;i++){
           aa[i] = sc.nextInt();
		}

		for(int i=0;i<m;i++){
           bb[i] = sc.nextInt();
		}
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        Arrays.sort(aa);
        Arrays.sort(bb);

        long a1 = aa[0];
        long a2 = aa[aa.length-1];
        long b1 = bb[0];
        long b2 = bb[bb.length-1];

        long max1 = Math.max(a1*1L*b1,a1*1L*b2);
        long max2 = Math.max(a2*1L*b1,a2*1L*b2);

        if(max1>max2){
           aa[0] = 0;
        }
        else{
           aa[aa.length-1]=0;
        }
        ArrayList<Long> ans = new ArrayList<>();
		long ansmax = Long.MIN_VALUE;
		for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
               long num = aa[i]*bb[j];
               ansmax = Math.max(ansmax,num);
              // ans.add(num);
            }
		}

		//Collections.sort(ans);
		//long res = ans.get(aa.size()-1);
		System.out.println(ansmax);

	}
}


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

public class cf133{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] aa = new int[n];
		int[] bb = new int[m];

		for(int i=0;i<n;i++){
           aa[i] = sc.nextInt();
		}

		for(int i=0;i<m;i++){
           bb[i] = sc.nextInt();
		}
        // int max = Integer.MIN_VALUE;
        // int min = Integer.MAX_VALUE;
        // Arrays.sort(aa);
        // Arrays.sort(bb);

        // long a1 = aa[0];
        // long a2 = aa[aa.length-1];
        // long b1 = bb[0];
        // long b2 = bb[bb.length-1];

        // long max1 = Math.max(a1*1L*b1,a1*1L*b2);
        // long max2 = Math.max(a2*1L*b1,a2*1L*b2);
        // long cul = 0;
        // if(max1>max2){
        //    cul = aa[0];
        // }
        // else{
        //    cul = aa[aa.length-1];
        // }
        ArrayList<Long> ans = new ArrayList<>();
		long ansmax = Long.MIN_VALUE;
		for(int i=0;i<n;i++){
			// if(aa[i]==cul){
   //             continue;
			// }
            for(int j=0;j<m;j++){
               Long num = (aa[i]*1L*bb[j]);
              // System.out.println(num);
               ansmax = Math.max(ansmax,num);
               if(!ans.contains(num)){
                  ans.add(num);
               }
               //ans.add(num);
            }
		}

		//Collections.sort(ans);
		//long res = ans.get(aa.size()-1);
		System.out.println(ans.get(ans.size()-1));

	}
}


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

public class cf133{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] aa = new int[n];
		int[] bb = new int[m];

		for(int i=0;i<n;i++){
           aa[i] = sc.nextInt();
		}

		for(int i=0;i<m;i++){
           bb[i] = sc.nextInt();
		}
        // int max = Integer.MIN_VALUE;
        // int min = Integer.MAX_VALUE;
        // Arrays.sort(aa);
        // Arrays.sort(bb);

        // long a1 = aa[0];
        // long a2 = aa[aa.length-1];
        // long b1 = bb[0];
        // long b2 = bb[bb.length-1];

        // long max1 = Math.max(a1*1L*b1,a1*1L*b2);
        // long max2 = Math.max(a2*1L*b1,a2*1L*b2);
        // long cul = 0;
        // if(max1>max2){
        //    cul = aa[0];
        // }
        // else{
        //    cul = aa[aa.length-1];
        // }
        ArrayList<Long> ans = new ArrayList<>();
		long ansmax = Long.MIN_VALUE;
		for(int i=0;i<n;i++){
			// if(aa[i]==cul){
   //             continue;
			// }
            for(int j=0;j<m;j++){
               Long num = (aa[i]*1L*bb[j]);
              // System.out.println(num);
               ansmax = Math.max(ansmax,num);
               if(!ans.contains(num)){
                  ans.add(num);
               }
               //ans.add(num);
            }
		}

		Collections.sort(ans);
		//long res = ans.get(aa.size()-1);
		System.out.println(ans.get(ans.size()-2));

	}
}


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

public class cf133{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] aa = new int[n];
		int[] bb = new int[m];

		for(int i=0;i<n;i++){
           aa[i] = sc.nextInt();
		}

		for(int i=0;i<m;i++){
           bb[i] = sc.nextInt();
		}
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        ArrayList<Long> ans = new ArrayList<>();
		for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
               long num = aa[i]*bb[j];
               ans.add(num);
            }
		}

		Collections.sort(ans);
		//long res = ans.get(aa.size()-1);
		for(int i=ans.size()-2;i>=0;i--){
           if(ans.get(i)<ans.get(i+1)){
             System.out.println(ans.get(i));
             break;
           }
		}

	}
}


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

public class cf133{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] aa = new int[n];
		int[] bb = new int[m];

		for(int i=0;i<n;i++){
           aa[i] = sc.nextInt();
		}

		for(int i=0;i<m;i++){
           bb[i] = sc.nextInt();
		}
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        Arrays.sort(aa);
        Arrays.sort(bb);

        long a1 = aa[0];
        long a2 = aa[aa.length-1];
        long b1 = bb[0];
        long b2 = bb[bb.length-1];

        long max1 = Math.max(a1*1L*b1,a1*1L*b2);
        long max2 = Math.max(a2*1L*b1,a2*1L*b2);

        if(max1>max2){
           for(int i=0;i<aa.length;i++){
               if(aa[i]==aa[0]){
               	  aa[i]=0;
               }
           }

        }
        else{
           for(int i=0;i<aa.length;i++){
               if(aa[i]==aa[aa.length-1]){
                  aa[i]=0;
               }
           }
        }
        ArrayList<Long> ans = new ArrayList<>();
		long ansmax = Long.MIN_VALUE;
		for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
               long num = aa[i]*bb[j];
               ansmax = Math.max(ansmax,num);
              // ans.add(num);
            }
		}

		//Collections.sort(ans);
		//long res = ans.get(aa.size()-1);
		System.out.println(ansmax);

	}
}


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

public class cf133{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] aa = new int[n];
		int[] bb = new int[m];

		for(int i=0;i<n;i++){
           aa[i] = sc.nextInt();
		}

		for(int i=0;i<m;i++){
           bb[i] = sc.nextInt();
		}
        Long maxx = Long.MIN_VALUE;
		long ind = 0;
		for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(maxx<aa[i]*1L*bb[j]){
                   maxx = aa[i]*1L*bb[j];
                   ind = i;
                }
            }
		}
        // int max = Integer.MIN_VALUE;
        // int min = Integer.MAX_VALUE;
        // Arrays.sort(aa);
        // Arrays.sort(bb);

        // long a1 = aa[0];
        // long a2 = aa[aa.length-1];
        // long b1 = bb[0];
        // long b2 = bb[bb.length-1];

        // long max1 = Math.max(a1*1L*b1,a1*1L*b2);
        // long max2 = Math.max(a2*1L*b1,a2*1L*b2);
        // long cul = 0;
        // if(max1>max2){
        //    cul = aa[0];
        // }
        // else{
        //    cul = aa[aa.length-1];
        // }
        ArrayList<Long> ans = new ArrayList<>();
		long ansmax = Long.MIN_VALUE;
		for(int i=0;i<n;i++){
			if(i==ind){
              continue;
			}
            for(int j=0;j<m;j++){
               Long num = (aa[i]*1L*bb[j]);
               //
               ansmax = Math.max(ansmax,num);

               //ans.add(num);
            }
		}

//		Collections.sort(ans);
		//long res = ans.get(aa.size()-1);
		System.out.println(ansmax);

	}
}


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

public class cf133{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] aa = new int[n];
		int[] bb = new int[m];

		for(int i=0;i<n;i++){
           aa[i] = sc.nextInt();
		}

		for(int i=0;i<m;i++){
           bb[i] = sc.nextInt();
		}
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        Arrays.sort(aa);
        Arrays.sort(bb);

        long a1 = aa[0];
        long a2 = aa[aa.length-1];
        long b1 = bb[0];
        long b2 = bb[bb.length-1];

        long max1 = Math.max(a1*1L*b1,a1*1L*b2);
        long max2 = Math.max(a2*1L*b1,a2*1L*b2);

        if(max1>max2){
           for(int i=0;i<aa.length;i++){
               if(aa[i]==aa[0]){
               	  aa[i]=0;
               }
           }

        }
        else{
           for(int i=0;i<aa.length;i++){
               if(aa[i]==aa[aa.length-1]){
                  aa[i]=0;
               }
           }
        }
        ArrayList<Long> ans = new ArrayList<>();
		long ansmax = Long.MIN_VALUE;
		for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
               Long num = (aa[i]*1L*bb[j]);
               //System.out.println(num);
               ansmax = Math.max(ansmax,num);
              // ans.add(num);
            }
		}

		//Collections.sort(ans);
		//long res = ans.get(aa.size()-1);
		System.out.println(ansmax);

	}
}


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

public class cf133{
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] aa = new int[n];
		int[] bb = new int[m];

		for(int i=0;i<n;i++){
           aa[i] = sc.nextInt();
		}

		for(int i=0;i<m;i++){
           bb[i] = sc.nextInt();
		}
        Long maxx = Long.MIN_VALUE;
		long ind = 0;
		for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(maxx<aa[i]*1L*bb[j]){
                   maxx = aa[i]*1L*bb[j];
                   ind = aa[i];
                }
            }
		}
        // int max = Integer.MIN_VALUE;
        // int min = Integer.MAX_VALUE;
        // Arrays.sort(aa);
        // Arrays.sort(bb);

        // long a1 = aa[0];
        // long a2 = aa[aa.length-1];
        // long b1 = bb[0];
        // long b2 = bb[bb.length-1];

        // long max1 = Math.max(a1*1L*b1,a1*1L*b2);
        // long max2 = Math.max(a2*1L*b1,a2*1L*b2);
        // long cul = 0;
        // if(max1>max2){
        //    cul = aa[0];
        // }
        // else{
        //    cul = aa[aa.length-1];
        // }
        ArrayList<Long> ans = new ArrayList<>();
		long ansmax = Long.MIN_VALUE;
		for(int i=0;i<n;i++){
			if(aa[i]==ind){
              continue;
			}
            for(int j=0;j<m;j++){
               Long num = (aa[i]*1L*bb[j]);
               //
               ansmax = Math.max(ansmax,num);
               if(!ans.contains(num)){
                  //System.out.println(num);
                  ans.add(num);
               }
               //ans.add(num);
            }
		}

		Collections.sort(ans);
		//long res = ans.get(aa.size()-1);
		System.out.println(ans.get(ans.size()-1));

	}
}


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

public class A4 {
public static void main(String[] args) throws Exception {
	STDIN scan = new STDIN();
	int n = scan.nextInt(),m = scan.nextInt();
	long[] arr =new long[n];
	long[] arr2 = new long[m];
	long max = Long.MIN_VALUE;
	int ind1 = 0;
	for(int i = 0 ; i < n ; i++){
		arr[i] = scan.nextInt();
		if(arr[i]>max){max = arr[i];
		ind1= i;
		}
	}
	arr[ind1] = Long.MIN_VALUE;
	max = Long.MIN_VALUE;
	for(int i = 0 ; i < n ; i++){
		if(arr[i]>max){max = arr[i];
		ind1= i;
		}
	}
	long res = max;
	max = Long.MIN_VALUE;
	int ind2 = 0;
	for(int i = 0 ; i < m ; i++){
		arr2[i] = scan.nextInt();
		if(arr2[i]>max)max=arr2[i];
	}
	res*=max;
	System.out.println(res);

}
static class STDIN {
	BufferedReader br;
	StringTokenizer st;

	public STDIN() {
		br = new BufferedReader(new InputStreamReader(System.in));
		st = null;
	}

	boolean hasNext() throws Exception {
		if (!st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.hasMoreTokens();
	}

	int nextInt() throws Exception {
		return Integer.parseInt(next());
	}

	long nextLong() throws Exception {
		return Long.parseLong(next());
	}

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

	String next() throws Exception {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	String nextLine() throws Exception {
		return br.readLine();
	}
}
}


import java.util.Arrays;
import java.util.Scanner;

public class C1 {
public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int m = scan.nextInt();
	long[] arr = new long[n];
	long[] arr2 =new long[m];
	for (int i = 0; i < arr.length; i++) {
		arr[i] = scan.nextLong();
	}
	for (int i = 0; i < arr2.length; i++) {
		arr2[i] = scan.nextLong();
	}
	Arrays.sort(arr);
	Arrays.sort(arr2);
	System.out.println((long)arr[n-2]*arr2[m-1]);
}
}


import java.util.Scanner;

public class CP {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), m = scan.nextInt();
		int[] arr1 = new int[n], arr2 = new int[m];
		for (int i = 0; i < n; i++) {
			arr1[i] = scan.nextInt();
		}
		for (int i = 0; i < m; i++) {
			arr2[i] = scan.nextInt();
		}
		long min = Integer.MAX_VALUE;
		for (int h = 0; h < n; h++) {
			long max = Integer.MIN_VALUE;

			for (int i = 0; i < n; i++) {
				if (i != h) {
					for (int j = 0; j < m; j++) {
						max = Math.max(max, arr1[i] * 1L * arr2[j]);
					}
				}
			}
			min = Math.min(min, max);
		}
		System.out.println(min);
	}
}


import java.util.Scanner;

public class CP {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt(), m = scan.nextInt();
		int[] arr1 = new int[n], arr2 = new int[m];
		for (int i = 0; i < n; i++) {
			arr1[i] = scan.nextInt();
		}
		for (int i = 0; i < m; i++) {
			arr2[i] = scan.nextInt();
		}
		long min = Long.MAX_VALUE;
		for (int h = 0; h < n; h++) {
			long max = Long.MIN_VALUE;

			for (int i = 0; i < n; i++) {
				if (i != h) {
					for (int j = 0; j < m; j++) {
						max = Math.max(max, arr1[i] * 1L * arr2[j]);
					}
				}
			}
			min = Math.min(min, max);
		}
		System.out.println(min);
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class C1 {
public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int m = scan.nextInt();
	int[] arr = new int[n];
	int[] arr2 =new int[m];
	for (int i = 0; i < arr.length; i++) {
		arr[i] = scan.nextInt();
	}
	for (int i = 0; i < arr2.length; i++) {
		arr2[i] = scan.nextInt();
	}
	Arrays.sort(arr);
	Arrays.sort(arr2);
	System.out.println((long)arr[n-2]*arr2[m-1]);
}
}


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

public class A4 {
public static void main(String[] args) throws Exception {
	STDIN scan = new STDIN();
	int n = scan.nextInt(),m = scan.nextInt();
	long[] arr =new long[n];
	long[] arr2 = new long[m];
	long max = Long.MIN_VALUE;
	int ind1 = 0;
	for(int i = 0 ; i < n ; i++){
		arr[i] = scan.nextInt();
		if(arr[i]>max){max = arr[i];
		ind1= i;
		}
	}
	arr[ind1] = Long.MIN_VALUE;
	max = Long.MIN_VALUE;
	for(int i = 0 ; i < n ; i++){
		if(arr[i]>max){max = arr[i];
		ind1= i;
		}
	}
	long res = max;
	max = Integer.MIN_VALUE;
	int ind2 = 0;
	for(int i = 0 ; i < m ; i++){
		arr2[i] = scan.nextInt();
		if(arr2[i]>max)max=arr2[i];
	}
	res*=max;
	System.out.println(res);

}
static class STDIN {
	BufferedReader br;
	StringTokenizer st;

	public STDIN() {
		br = new BufferedReader(new InputStreamReader(System.in));
		st = null;
	}

	boolean hasNext() throws Exception {
		if (!st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.hasMoreTokens();
	}

	int nextInt() throws Exception {
		return Integer.parseInt(next());
	}

	long nextLong() throws Exception {
		return Long.parseLong(next());
	}

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

	String next() throws Exception {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	String nextLine() throws Exception {
		return br.readLine();
	}
}
}


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

public class A4 {
public static void main(String[] args) throws Exception {
	STDIN scan = new STDIN();
	int n = scan.nextInt(),m = scan.nextInt();
	int[] arr =new int[n];
	int[] arr2 = new int[m];
	int max = Integer.MIN_VALUE;
	int ind1 = 0;
	for(int i = 0 ; i < n ; i++){
		arr[i] = scan.nextInt();
		if(arr[i]>max){max = arr[i];
		ind1= i;
		}
	}
	arr[ind1] = Integer.MIN_VALUE;
	max = Integer.MIN_VALUE;
	for(int i = 0 ; i < n ; i++){
		if(arr[i]>max){max = arr[i];
		ind1= i;
		}
	}
	long res = max;
	max = Integer.MIN_VALUE;
	int ind2 = 0;
	for(int i = 0 ; i < m ; i++){
		arr2[i] = scan.nextInt();
		if(arr2[i]>max)max=arr2[i];
	}
	res*=max;
	System.out.println(res);

}
static class STDIN {
	BufferedReader br;
	StringTokenizer st;

	public STDIN() {
		br = new BufferedReader(new InputStreamReader(System.in));
		st = null;
	}

	boolean hasNext() throws Exception {
		if (!st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.hasMoreTokens();
	}

	int nextInt() throws Exception {
		return Integer.parseInt(next());
	}

	long nextLong() throws Exception {
		return Long.parseLong(next());
	}

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

	String next() throws Exception {
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

	String nextLine() throws Exception {
		return br.readLine();
	}
}
}


import java.util.Scanner;
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        int n1 = scan.nextInt(), n2 = scan.nextInt();

        long[] arr1 = new long[n1], arr2 = new long[n2];

        for(int i = 0 ; i < n1 ; i++)arr1[i] = scan.nextLong();
        for(int i = 0 ; i < n2 ; i++)arr2[i] = scan.nextLong();

        Arrays.sort(arr1);
        Arrays.sort(arr2);

        long ans = 0;

        for(int i = 0 ; i < arr1.length -1; i++){
            for(int j = 0 ; j < arr2.length ; j++){
                ans = Math.max((long)arr1[i]*arr2[j],ans);
            }
        }

        System.out.println(ans);
    }
}


import java.util.Scanner;
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        int n1 = scan.nextInt(), n2 = scan.nextInt();

        long[] arr1 = new long[n1], arr2 = new long[n2];

        for(int i = 0 ; i < n1 ; i++)arr1[i] = scan.nextLong();
        for(int i = 0 ; i < n2 ; i++)arr2[i] = scan.nextLong();

        long ans = Long.MIN_VALUE;

        for(int i = 0 ; i < arr1.length; i++){
            for(int j = 0 ; j < arr2.length ; j++){
                ans = Math.max((long)arr1[i]*arr2[j],ans);
            }
        }

        System.out.println(ans);
    }
}


import java.util.Scanner;
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        int n1 = scan.nextInt(), n2 = scan.nextInt();

        long[] arr1 = new long[n1], arr2 = new long[n2];

        for(int i = 0 ; i < n1 ; i++)arr1[i] = scan.nextLong();
        for(int i = 0 ; i < n2 ; i++)arr2[i] = scan.nextLong();

        Arrays.sort(arr1);
        Arrays.sort(arr2);

        long ans = Long.MIN_VALUE;

        for(int i = 0 ; i < arr1.length -1; i++){
            for(int j = 0 ; j < arr2.length ; j++){
                ans = Math.max((long)arr1[i]*arr2[j],ans);
            }
        }

        System.out.println(ans);
    }
}


import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] A = new long[n];
		long[] B = new long[m];
		for(int i=0;i<n;i++){
			A[i] = sc.nextLong();
		}
		for(int i=0;i<m;B[i++]=sc.nextLong());
		Arrays.sort(A);
		Arrays.sort(B);
		/*if((A[0]*B[0]) > (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[1]*B[0]), (A[n-1]*B[m-1])));
		}else if ((A[0]*B[0]) < (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[0]*B[0]), (A[n-2]*B[m-1])));
		}else{
			System.out.println((A[0]*B[0]));
		}*/
		long second = 0, first = 0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				long res = A[i]*B[j];
				if(res >= first){
					second = first;
					first = res;
				}
			}
		}
		System.out.println(second);

	}

}


import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] A = new long[n];
		long[] B = new long[m];
		for(int i=0;i<n;i++){
			A[i] = sc.nextLong();
		}
		for(int i=0;i<m;B[i++]=sc.nextLong());
		Arrays.sort(A);
		Arrays.sort(B);
		if((A[0]*B[0]) > (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[1]*B[0]), (A[n-1]*B[m-1])));
		}else if ((A[0]*B[0]) < (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[0]*B[0]), (A[n-2]*B[m-1])));
		}else{
			System.out.println((A[0]*B[0]));
		}

	}

}


import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] A = new long[n];
		long[] B = new long[m];
		for(int i=0;i<n;i++){
			A[i] = sc.nextLong();
		}
		for(int i=0;i<m;B[i++]=sc.nextLong());
		Arrays.sort(A);
		Arrays.sort(B);
		/*if((A[0]*B[0]) > (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[1]*B[0]), (A[n-1]*B[m-1])));
		}else if ((A[0]*B[0]) < (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[0]*B[0]), (A[n-2]*B[m-1])));
		}else{
			System.out.println((A[0]*B[0]));
		}*/
		long second = 0, first = 0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				long res = A[i]*B[j];
				if(res > first){
					second = first;
					first = res;
				}
			}
		}
		System.out.println(second);

	}

}


import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] A = new long[n];
		long[] B = new long[m];
		for(int i=0;i<n;i++){
			A[i] = sc.nextLong();
		}
		for(int i=0;i<m;B[i++]=sc.nextLong());
		Arrays.sort(A);
		Arrays.sort(B);
		/*if((A[0]*B[0]) > (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[1]*B[0]), (A[n-1]*B[m-1])));
		}else if ((A[0]*B[0]) < (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[0]*B[0]), (A[n-2]*B[m-1])));
		}else{
			System.out.println((A[0]*B[0]));
		}*/
		long second = A[0]*B[0], first = A[0]*B[0];
		int first_i=0,second_i=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				long res = A[i]*B[j];
				if(res >= first){
					if(first_i == i){
						first = res;
						first_i = i;
					}else{
						second = first;
						first = res;
						second_i = first_i;
						first_i = i;
					}

				}
			}
		}
		//System.out.println(first);
		System.out.println(second);

	}

}


import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] A = new long[n];
		long[] B = new long[m];
		for(int i=0;i<n;i++){
			A[i] = sc.nextLong();
		}
		for(int i=0;i<m;B[i++]=sc.nextLong());
		Arrays.sort(A);
		Arrays.sort(B);
		/*if((A[0]*B[0]) > (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[1]*B[0]), (A[n-1]*B[m-1])));
		}else if ((A[0]*B[0]) < (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[0]*B[0]), (A[n-2]*B[m-1])));
		}else{
			System.out.println((A[0]*B[0]));
		}*/
		long max = Long.MIN_VALUE;
		int idx = 0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				long res = A[i]*B[j];
				if(res > max){
					idx = i;
					max = res;
				}
			}
		}
		max = Long.MIN_VALUE;
		for(int i=0;i<n;i++){
			if(idx == i){
				continue;
			}
			for(int j=0;j<m;j++){
				long res = A[i]*B[j];
				if(res > max){
					max = res;
				}
			}
		}
		System.out.println(max);

	}

}


import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] A = new long[n];
		long[] B = new long[m];
		for(int i=0;i<n;i++){
			A[i] = sc.nextLong();
		}
		for(int i=0;i<m;B[i++]=sc.nextLong());
		Arrays.sort(A);
		Arrays.sort(B);
		/*if((A[0]*B[0]) > (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[1]*B[0]), (A[n-1]*B[m-1])));
		}else if ((A[0]*B[0]) < (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[0]*B[0]), (A[n-2]*B[m-1])));
		}else{
			System.out.println((A[0]*B[0]));
		}*/
		long second = A[0]*B[0], first = A[0]*B[0];
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				long res = A[i]*B[j];
				if(res >= first){
					second = first;
					first = res;
				}
			}
		}
		System.out.println(second);

	}

}


import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] A = new long[n];
		long[] B = new long[m];
		for(int i=0;i<n;i++){
			A[i] = sc.nextLong();
		}
		for(int i=0;i<m;B[i++]=sc.nextLong());
		Arrays.sort(A);
		Arrays.sort(B);
		/*if((A[0]*B[0]) > (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[1]*B[0]), (A[n-1]*B[m-1])));
		}else if ((A[0]*B[0]) < (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[0]*B[0]), (A[n-2]*B[m-1])));
		}else{
			System.out.println((A[0]*B[0]));
		}*/
		long max = A[0]*B[0];
		int idx = 0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				long res = A[i]*B[j];
				if(res > max){
					idx = i;
					max = res;
				}
			}
		}
		max = A[0]*B[0];
		for(int i=0;i<n;i++){
			if(idx == i){
				continue;
			}
			for(int j=0;j<m;j++){
				long res = A[i]*B[j];
				if(res > max){
					max = res;
				}
			}
		}
		System.out.println(max);

	}

}


import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long[] A = new long[n];
		long[] B = new long[m];
		for(int i=0;i<n;i++){
			A[i] = sc.nextLong();
		}
		for(int i=0;i<m;B[i++]=sc.nextLong());
		Arrays.sort(A);
		Arrays.sort(B);
		/*if((A[0]*B[0]) > (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[1]*B[0]), (A[n-1]*B[m-1])));
		}else if ((A[0]*B[0]) < (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[0]*B[0]), (A[n-2]*B[m-1])));
		}else{
			System.out.println((A[0]*B[0]));
		}*/
		long second = A[0]*B[0], first = A[0]*B[0];
		int first_i=0,second_i=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				long res = A[i]*B[j];
				if(res >= first){
					if(first_i == i){
						first = res;
						first_i = i;
					}else{
						second = first;
						first = res;
						second_i = first_i;
						first_i = i;
					}

				}
			}
		}
		System.out.println(first);
		System.out.println(second);

	}

}


import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] A = new int[n];
		int[] B = new int[m];
		for(int i=0;i<n;i++){
			A[i] = sc.nextInt();
		}
		for(int i=0;i<m;B[i++]=sc.nextInt());
		Arrays.sort(A);
		Arrays.sort(B);
		if((A[0]*B[0]) > (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[1]*B[0]), (A[n-1]*B[m-1])));
		}else if ((A[0]*B[0]) < (A[n-1]*B[m-1])){
			System.out.println(Math.max((A[0]*B[0]), (A[n-2]*B[m-1])));
		}else{
			System.out.println((A[0]*B[0]));
		}

	}

}


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

public final class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());

        st =new StringTokenizer(br.readLine());
        long[] nVals = new long[n];
        int nIndex = 0;

        while(st.hasMoreTokens()){
            long a = Long.parseLong(st.nextToken());
            nVals[nIndex++] = a;
        }

        Arrays.sort(nVals);

        st = new StringTokenizer(br.readLine());

        long[] mVals = new long[m];
        int mIndex = 0;
        while(st.hasMoreTokens()){
            long b = Long.parseLong(st.nextToken());
            mVals[mIndex++] = b;
        }

        long highestValByHidingLargest = Long.MIN_VALUE;
        highestValByHidingLargest = Math.max(nVals[n-2] * mVals[m-1], nVals[n-2]*mVals[0]);
        highestValByHidingLargest = Math.max(highestValByHidingLargest, Math.max(nVals[0]*mVals[0], nVals[0]*mVals[m-1]));

        long highestValsByHidingSmallest = Long.MIN_VALUE;
        highestValsByHidingSmallest = Math.max(nVals[1]*mVals[0], nVals[1] * mVals[m-1]);
        highestValsByHidingSmallest = Math.max(highestValsByHidingSmallest, Math.max(nVals[n-1]*mVals[0], nVals[n-1]*mVals[m-1]));

        System.out.println(Math.min(highestValByHidingLargest, highestValsByHidingSmallest));
    }

}


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

public final class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());

        st =new StringTokenizer(br.readLine());
        long[] nVals = new long[n];
        int nIndex = 0;

        while(st.hasMoreTokens()){
            long a = Long.parseLong(st.nextToken());
            nVals[nIndex++] = a;
        }

        Arrays.sort(nVals);

        st = new StringTokenizer(br.readLine());

        long[] mVals = new long[m];
        int mIndex = 0;
        while(st.hasMoreTokens()){
            long b = Long.parseLong(st.nextToken());
            mVals[mIndex++] = b;
        }

        Arrays.sort(mVals);

        long highestValByHidingLargest = Long.MIN_VALUE;
        highestValByHidingLargest = Math.max(nVals[n-2] * mVals[m-1], nVals[n-2]*mVals[0]);
        highestValByHidingLargest = Math.max(highestValByHidingLargest, Math.max(nVals[0]*mVals[0], nVals[0]*mVals[m-1]));

        long highestValsByHidingSmallest = Long.MIN_VALUE;
        highestValsByHidingSmallest = Math.max(nVals[1]*mVals[0], nVals[1] * mVals[m-1]);
        highestValsByHidingSmallest = Math.max(highestValsByHidingSmallest, Math.max(nVals[n-1]*mVals[0], nVals[n-1]*mVals[m-1]));

        System.out.println(Math.min(highestValByHidingLargest, highestValsByHidingSmallest));
    }

}


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

public final class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());

        st =new StringTokenizer(br.readLine());
        long[] nVals = new long[n];
        int nIndex = 0;

        while(st.hasMoreTokens()){
            long a = Long.parseLong(st.nextToken());
            nVals[nIndex++] = a;
        }

        Arrays.sort(nVals);

        st = new StringTokenizer(br.readLine());

        if(nVals[n-1] < 0){
            long nMin = Long.MAX_VALUE;

            while(st.hasMoreTokens()){
                long b = Long.parseLong(st.nextToken());
                nMin = Math.max(nMin, b);
            }

            System.out.println(nMin * nVals[n-2]);

            return;
        }

        long mMax = Long.MIN_VALUE;

        while(st.hasMoreTokens()){
            long b = Long.parseLong(st.nextToken());
            mMax = Math.max(mMax, b);
        }

        System.out.println(mMax * nVals[n-2]);
    }

}


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

public final class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());

        st =new StringTokenizer(br.readLine());
        long[] nVals = new long[n];
        int nIndex = 0;

        while(st.hasMoreTokens()){
            long a = Long.parseLong(st.nextToken());
            nVals[nIndex++] = a;
        }

        Arrays.sort(nVals);

        st = new StringTokenizer(br.readLine());

        long mMax = Long.MIN_VALUE;

        while(st.hasMoreTokens()){
            long b = Long.parseLong(st.nextToken());
            mMax = Math.max(mMax, b);
        }

        System.out.println(mMax * nVals[n-2]);
    }

}


import java.util.*;
public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int n = scanner.nextInt();
    	int m = scanner.nextInt();
    	long[] data1 = new long[n];
    	long[] data2 = new long[m];
    	long[] max = new long[n];
    	for(int i=0;i<n;i++){
    		max[i] = (long) -10e20;
    	}
    	int l =0;
    	for(int i=0;i<n;i++){
    		data1[i] = Long.valueOf(scanner.next());
    	}
    	for(int i=0;i<m;i++){
    		data2[i] = Long.valueOf(scanner.next());
    	}
    	for(int k=0;k<n;k++){
        	for(int i=0;i<n;i++){
        		if(i!=k){
            		for(int j=0;j<m;j++){
            			max[k] = max[k]>data1[i]*data2[j]?max[k]:data1[i]*data2[j];
            		}
        		}
        	}
    	}
    	Arrays.sort(max);
    	System.out.println(max[0]);
    }
}


import java.util.*;
public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int n = scanner.nextInt();
    	int m = scanner.nextInt();
    	int[] data1 = new int[n];
    	int[] data2 = new int[m];
    	long[] data3 = new long[n*m];
    	int l =0;
    	for(int i=0;i<n;i++){
    		data1[i] = scanner.nextInt();
    	}
    	for(int i=0;i<m;i++){
    		data2[i] = scanner.nextInt();
    	}
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++){
    			data3[l++] = (long)(data1[i])*(long)(data2[j]);
    		}
    	}
    	Arrays.sort(data3);
    	System.out.println(data3[l-2]);

    }
}


import java.util.*;
public class TestMain {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int n = scanner.nextInt();
    	int m = scanner.nextInt();
    	long[] data1 = new long[n];
    	long[] data2 = new long[m];
    	int l =0;
    	for(int i=0;i<n;i++){
    		data1[i] = Long.valueOf(scanner.next());
    	}
    	for(int i=0;i<m;i++){
    		data2[i] = Long.valueOf(scanner.next());
    	}
    	Arrays.sort(data1);
    	Arrays.sort(data2);
    	System.out.println(data1[n-2]*data2[m-1]);

    }
}


import java.util.*;
public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int n = scanner.nextInt();
    	int m = scanner.nextInt();
    	long[] data1 = new long[n];
    	long[] data2 = new long[m];
    	int l =0;
    	for(int i=0;i<n;i++){
    		data1[i] = Long.valueOf(scanner.next());
    	}
    	for(int i=0;i<m;i++){
    		data2[i] = Long.valueOf(scanner.next());
    	}
    	Arrays.sort(data1);
    	Arrays.sort(data2);
    	System.out.println(data1[n-2]*data2[m-1]);

    }
}


import java.util.*;
public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int n = scanner.nextInt();
    	int m = scanner.nextInt();
    	long[] data1 = new long[n];
    	long[] data2 = new long[m];
    	long[] data3 = new long[(n-1)*m];
    	int l =0;
    	for(int i=0;i<n;i++){
    		data1[i] = Long.valueOf(scanner.next());
    	}
    	for(int i=0;i<m;i++){
    		data2[i] = Long.valueOf(scanner.next());
    	}
    	Arrays.sort(data1);
    	for(int i=0;i<n-1;i++){
    		for(int j=0;j<m;j++){
    			data3[l++] = data1[i]*data2[j];
    		}
    	}
    	Arrays.sort(data3);
    	System.out.println(data3[l-1]);

    }
}


import java.util.*;
public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int n = scanner.nextInt();
    	int m = scanner.nextInt();
    	long[] data1 = new long[n];
    	long[] data2 = new long[m];
    	int l =0;
    	for(int i=0;i<n;i++){
    		data1[i] = scanner.nextInt();
    	}
    	for(int i=0;i<m;i++){
    		data2[i] = scanner.nextInt();
    	}
    	Arrays.sort(data1);
    	Arrays.sort(data2);
    	System.out.println(data1[n-2]*data2[m-1]);

    }
}


import java.util.*;
public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int n = scanner.nextInt();
    	int m = scanner.nextInt();
    	long[] data1 = new long[n];
    	long[] data2 = new long[m];
    	long[] max = new long[n];
    	for(int i=0;i<n;i++){
    		max[i] = (long) -10e9;
    	}
    	int l =0;
    	for(int i=0;i<n;i++){
    		data1[i] = Long.valueOf(scanner.next());
    	}
    	for(int i=0;i<m;i++){
    		data2[i] = Long.valueOf(scanner.next());
    	}
    	for(int k=0;k<n;k++){
        	for(int i=0;i<n;i++){
        		if(i!=k){
            		for(int j=0;j<m;j++){
            			max[k] = max[k]>data1[i]*data2[j]?max[k]:data1[i]*data2[j];
            		}
        		}
        	}
    	}
    	Arrays.sort(max);
    	System.out.println(max[0]);
    }
}


import java.util.*;
public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int n = scanner.nextInt();
    	int m = scanner.nextInt();
    	long[] data1 = new long[n];
    	long[] data2 = new long[m];
    	long[] max = new long[n];
    	int l =0;
    	for(int i=0;i<n;i++){
    		data1[i] = Long.valueOf(scanner.next());
    	}
    	for(int i=0;i<m;i++){
    		data2[i] = Long.valueOf(scanner.next());
    	}
    	for(int k=0;k<n;k++){
        	for(int i=0;i<n;i++){
        		if(i!=k){
            		for(int j=0;j<m;j++){
            			max[k] = max[k]>data1[i]*data2[j]?max[k]:data1[i]*data2[j];
            		}
        		}
        	}
    	}
    	Arrays.sort(max);
    	System.out.println(max[0]);
    }
}


import java.util.*;
public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int n = scanner.nextInt();
    	int m = scanner.nextInt();
    	int[] data1 = new int[n];
    	int[] data2 = new int[m];
    	long[] data3 = new long[51];
    	int l=0;
    	int k = 0;
    	for(int i=0;i<n;i++){
    		data1[i] = scanner.nextInt();
    	}
    	for(int i=0;i<m;i++){
    		data2[i] = scanner.nextInt();
    	}
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++){
    			data3[l++] = data1[i]*data2[j];
    		}
    	}
    	Arrays.sort(data3,0,l);
    	System.out.println(data3[l-2]);

    }
}


import java.util.*;
public class Main {
    public static void main(String[] args) {
    	Scanner scanner = new Scanner(System.in);
    	int n = scanner.nextInt();
    	int m = scanner.nextInt();
    	long[] data1 = new long[n];
    	long[] data2 = new long[m];
    	long[] data3 = new long[n*m];
    	int l =0;
    	for(int i=0;i<n;i++){
    		data1[i] = Long.valueOf(scanner.next());
    	}
    	for(int i=0;i<m;i++){
    		data2[i] = Long.valueOf(scanner.next());
    	}
    	for(int i=0;i<n;i++){
    		for(int j=0;j<m;j++){
    			data3[l++] = data1[i]*data2[j];
    		}
    	}
    	Arrays.sort(data3);
    	System.out.println(data3[l-2]);

    }
}


//package CodeForces;

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

public class Main {

    public class Haha {
        /*                     _____                                                             ___
                /\      /\    |     | |   |    /\       /\      /\       /\      /\       /\    |   \     محمد أبوحسن*
               /  \    /  \   |     | |___|   /__\     /  \    /  \     /  \    /  \     /__\   |    \
              /    \  /    \  |     | |   |  /    \   /    \  /    \   /    \  /    \   /    \  |    /
             /      \/      \ |_____| |   | /      \ /      \/      \ /      \/      \ /      \ |___/
         */
    }

    public static class MyScanner {

        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static class MyPair {

        int x;
        int y;

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

    public static int Fibonacci(int n) {
        int[] a = new int[n + 1];
        a[0] = 0;
        a[1] = 1;
        for (int i = 2; i < a.length; i++) {
            a[i] = a[i - 1] + a[i - 2];
        }
        return a[n];
    }

    public static boolean isprime(int n) {
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0) {
                return true;
            }
        }
        return false;
    }

    public static int[] addarr(int[] a, int n) {
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if(a[i] > max){
                max = a[i];
                indmax = i;
            }
        }
        return a;
    }

    public static int fact(int n){
        int fact = 1;
        for(int i = 1; i <= n; i++)
            fact *= i;
        return fact;
    }

    public static long sumDigit(long n){
        int a = 0;
        while(n != 0){
            a += n%10;
            n /= 10;
        }
        return a;
    }

    public static int indmax  = -1;
    public static MyScanner sc = new MyScanner();
    public static int MOD = 1000000007;
    // __builtin_popcountll(n) <-- c++ // binary count(1) ex. 8 --> 0100 --> 1
    HashSet<Integer> set = new HashSet<>();
    HashMap<Integer, Integer> map = new HashMap<>();
    Random r = new Random();
    ArrayList<Integer> l = new ArrayList<>();

    public static void main(String[] args) {
        int n = sc.nextInt(),m = sc.nextInt(), c = -1;
        long max = Long.MIN_VALUE;
        int[] a = new int[n];
        int[] b = new int[m];
        addarr(a, n);
        c = indmax;
        addarr(b, m);
        for (int i = 0; i < n; i++) {
            if(i == c) continue;
            for (int j = 0; j < m; j++){
                long r = a[i]*1L*b[j];
                if(r > max)
                    max = r;
            }
        }
        System.out.println(max);
    }
}


//package CodeForces;

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

public class Main {

    public class Haha {
        /*                     _____                                                             ___
                /\      /\    |     | |   |    /\       /\      /\       /\      /\       /\    |   \     محمد أبوحسن*
               /  \    /  \   |     | |___|   /__\     /  \    /  \     /  \    /  \     /__\   |    \
              /    \  /    \  |     | |   |  /    \   /    \  /    \   /    \  /    \   /    \  |    /
             /      \/      \ |_____| |   | /      \ /      \/      \ /      \/      \ /      \ |___/
         */
    }

    public static class MyScanner {

        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static class MyPair {

        int x;
        int y;

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

    public static int Fibonacci(int n) {
        int[] a = new int[n + 1];
        a[0] = 0;
        a[1] = 1;
        for (int i = 2; i < a.length; i++) {
            a[i] = a[i - 1] + a[i - 2];
        }
        return a[n];
    }

    public static boolean isprime(int n) {
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0) {
                return true;
            }
        }
        return false;
    }

    public static int[] addarr(int[] a, int n) {
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            if(a[i] > max){
                max = a[i];
                indmax = i;
            }
        }
        return a;
    }

    public static int fact(int n){
        int fact = 1;
        for(int i = 1; i <= n; i++)
            fact *= i;
        return fact;
    }

    public static long sumDigit(long n){
        int a = 0;
        while(n != 0){
            a += n%10;
            n /= 10;
        }
        return a;
    }

    public static int indmax  = -1;
    public static MyScanner sc = new MyScanner();
    public static int MOD = 1000000007;
    // __builtin_popcountll(n) <-- c++ // binary count(1) ex. 8 --> 0100 --> 1
    HashSet<Integer> set = new HashSet<>();
    HashMap<Integer, Integer> map = new HashMap<>();
    Random r = new Random();
    ArrayList<Integer> l = new ArrayList<>();

    public static void main(String[] args) {
        int n = sc.nextInt(),m = sc.nextInt(), c = -1;
        long max = Long.MIN_VALUE;
        int[] a = new int[n];
        int[] b = new int[m];
        addarr(a, n);
        c = indmax;
        addarr(b, m);
        for (int i = 0; i < n; i++) {
            if(i == c) continue;
            for (int j = 0; j < m; j++){
                long r = a[i]*1L*b[i];
                if(r > max)
                    max = r;
            }
        }
        System.out.println(max);
    }
}


//package CodeForces;

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

public class Main {

    public class Haha {
        /*                     _____                                                             ___
                /\      /\    |     | |   |    /\       /\      /\       /\      /\       /\    |   \     محمد أبوحسن*
               /  \    /  \   |     | |___|   /__\     /  \    /  \     /  \    /  \     /__\   |    \
              /    \  /    \  |     | |   |  /    \   /    \  /    \   /    \  /    \   /    \  |    /
             /      \/      \ |_____| |   | /      \ /      \/      \ /      \/      \ /      \ |___/
         */
    }

    public static class MyScanner {

        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static class MyPair {

        int x;
        int y;

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

    public static int Fibonacci(int n) {
        int[] a = new int[n + 1];
        a[0] = 0;
        a[1] = 1;
        for (int i = 2; i < a.length; i++) {
            a[i] = a[i - 1] + a[i - 2];
        }
        return a[n];
    }

    public static boolean isprime(int n) {
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0) {
                return true;
            }
        }
        return false;
    }

    public static int[] addarr(int[] a, int n) {
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        return a;
    }

    public static int fact(int n){
        int fact = 1;
        for(int i = 1; i <= n; i++)
            fact *= i;
        return fact;
    }

    public static long sumDigit(long n){
        int a = 0;
        while(n != 0){
            a += n%10;
            n /= 10;
        }
        return a;
    }

    public static MyScanner sc = new MyScanner();
    public static int MOD = 1000000007;
    // __builtin_popcountll(n) <-- c++ // binary count(1) ex. 8 --> 0100 --> 1
    HashSet<Integer> set = new HashSet<>();
    HashMap<Integer, Integer> map = new HashMap<>();
    Random r = new Random();
    ArrayList<Integer> l = new ArrayList<>();

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[m];
        addarr(a, n);
        addarr(b, m);
        Arrays.sort(a);
        Arrays.sort(b);
        System.out.println(a[n-2]*b[m-1]);
    }
}


//package CodeForces;

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

public class Main {

    public class Haha {
        /*                     _____                                                             ___
                /\      /\    |     | |   |    /\       /\      /\       /\      /\       /\    |   \     محمد أبوحسن*
               /  \    /  \   |     | |___|   /__\     /  \    /  \     /  \    /  \     /__\   |    \
              /    \  /    \  |     | |   |  /    \   /    \  /    \   /    \  /    \   /    \  |    /
             /      \/      \ |_____| |   | /      \ /      \/      \ /      \/      \ /      \ |___/
         */
    }

    public static class MyScanner {

        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static class MyPair {

        int x;
        int y;

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

    public static int Fibonacci(int n) {
        int[] a = new int[n + 1];
        a[0] = 0;
        a[1] = 1;
        for (int i = 2; i < a.length; i++) {
            a[i] = a[i - 1] + a[i - 2];
        }
        return a[n];
    }

    public static boolean isprime(int n) {
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0) {
                return true;
            }
        }
        return false;
    }

    public static int[] addarr(int[] a, int n) {
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            a[i] = Math.abs(sc.nextInt());
            if(a[i] > max){
                max = a[i];
                indmax = i;
            }
        }
        return a;
    }

    public static int fact(int n){
        int fact = 1;
        for(int i = 1; i <= n; i++)
            fact *= i;
        return fact;
    }

    public static long sumDigit(long n){
        int a = 0;
        while(n != 0){
            a += n%10;
            n /= 10;
        }
        return a;
    }

    public static int indmax  = -1;
    public static MyScanner sc = new MyScanner();
    public static int MOD = 1000000007;
    // __builtin_popcountll(n) <-- c++ // binary count(1) ex. 8 --> 0100 --> 1
    HashSet<Integer> set = new HashSet<>();
    HashMap<Integer, Integer> map = new HashMap<>();
    Random r = new Random();
    ArrayList<Integer> l = new ArrayList<>();

    public static void main(String[] args) {
        int n = sc.nextInt(),m = sc.nextInt(), c = -1;
        long max = Long.MIN_VALUE;
        int[] a = new int[n];
        int[] b = new int[m];
        addarr(a, n);
        c = indmax;
        addarr(b, m);
        for (int i = 0; i < n; i++) {
            if(i == c) continue;
            for (int j = 0; j < m; j++)
                if((long)a[i]*b[j] > max){
                    max = (long)a[i]*b[j];
                    //System.out.println(a[i] + "    " + b[j]);
                }
        }
        System.out.println(max);
    }
}


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

const int mx = 200111;
const int mod = 1000000007;

const int N = 5e5 + 10;
vector<int>vec[mx];
bool vis[3000];
int cnt;
void dfs(int nd){
    vis[nd]=1;
    cnt++;
    for(int v:vec[nd]){
        if(vis[v]==0)dfs(v);
    }
}
int n;
int main(){
   // freopen("in.txt","r",stdin);
//    freopen("in.txt","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int p;
            cin>>p;
            if(p)
            vec[i].pb(j);
        }
    }
    for(int i=1;i<=n;i++){
        memset(vis,0,sizeof(vis));
        cnt = 0;
        dfs(i);
        if(cnt!=n){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


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

const int mx = 200111;
const int mod = 1000000007;

const int N = 5e5 + 10;

int h,w;
vector<int>vec[mx];
vector<int>rev_vec[mx],rem;
int n,k;
int vis[mx];
int in[mx];

int temp;
stack<int>stk;
void dfs(int node){
    vis[node]=1;
    int sz=vec[node].size();
    for(int i=0;i<sz;i++){
        int v=vec[node][i];
        if(vis[v]==0)dfs(v);
    }
    stk.push(node);
}
void dfs1(int node){
    vis[node]=1;
    temp++;
    int sz=rev_vec[node].size();
    for(int i=0;i<sz;i++){
        int v=rev_vec[node][i];
        if(vis[v]==0)dfs1(v);
    }
}
int main(){
   // freopen("in.txt","r",stdin);
//    freopen("in.txt","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int p;
            cin>>p;
            if(p){
                vec[i].pb(j);
                rev_vec[j].pb(i);
            }
        }
    }
    dfs(1);
    int cnt1=0;
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            cnt1++;
        }
    }
    memset(vis,0,sizeof(vis));
    dfs1(1);
    int cnt2=0;
    for(int i=1;i<=n;i++){
        if(vis[i]==0){
            cnt2++;
        }
    }
    cout<<( (cnt1==n && cnt2==n)?"YES":"NO")<<endl;
    return 0;
}


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

const int mx = 200111;
const int mod = 1000000007;

const int N = 5e5 + 10;

int h,w;
vector<int>vec[mx];
vector<int>rev_vec[mx],rem;
int n,k;
int vis[mx];
int in[mx];

int temp;
stack<int>stk;
void dfs(int node){
    vis[node]=1;
    int sz=vec[node].size();
    for(int i=0;i<sz;i++){
        int v=vec[node][i];
        if(vis[v]==0)dfs(v);
    }
    stk.push(node);
}
void dfs1(int node){
    vis[node]=1;
    temp++;
    int sz=rev_vec[node].size();
    for(int i=0;i<sz;i++){
        int v=rev_vec[node][i];
        if(vis[v]==0)dfs1(v);
    }
}
int main(){
   // freopen("in.txt","r",stdin);
//    freopen("in.txt","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int p;
            cin>>p;
            if(p){
                vec[i].pb(j);
                rev_vec[j].pb(i);
            }
        }
    }
    dfs(1);
    int cnt1=0;
    for(int i=1;i<=n;i++){
        if(vis[i]){
            cnt1++;
        }
    }
    memset(vis,0,sizeof(vis));
    dfs1(1);
    int cnt2=0;
    for(int i=1;i<=n;i++){
        if(vis[i]){
            cnt2++;
        }
    }
    cout<<( (cnt1==n && cnt2==n)?"YES":"NO")<<endl;
    return 0;
}


//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <stdio.h>
#include <bits/stdc++.h>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

inline void setmin(int &x, int y) { if (y < x) x = y; }
inline void setmax(int &x, int y) { if (y > x) x = y; }
inline void setmin(ll &x, ll y) { if (y < x) x = y; }
inline void setmax(ll &x, ll y) { if (y > x) x = y; }

const int N = 2000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

vector<int> dx = {0, 0, -1, 1};
vector<int> dy = {-1, 1, 0, 0};

int n;
int g[N][N], gr[N][N];
bool used[N];
vector<int> order;

void dfs(int u)
{
    used[u] = true;
    rep(v, 0, n)
        if (g[u][v] && !used[v])
            dfs(v);
    order.push_back(u);
}

int dfs1(int u)
{
    used[u] = true;
    int cnt = 1;
    rep(v, 0, n)
        if (gr[u][v] && !used[v])
            cnt += dfs1(v);
    return cnt;
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    cin >> n;
    rep(i, 0, n)
    {
        rep(j, 0, n)
        {
            cin >> g[i][j];
            setmin(g[i][j], 1);
        }
    }
    rep(i, 0, n)
        rep(j, 0, n)
            gr[i][j] = g[j][i];
    rep(i, 0, n)
        if (!used[i])
            dfs(i);
    fill(used, used + n, false);
    cout << (dfs1(order.back()) == n ? "YES\n" : "NO\n");
    return 0;
}


//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <stdio.h>
#include <bits/stdc++.h>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

inline void setmin(int &x, int y) { if (y < x) x = y; }
inline void setmax(int &x, int y) { if (y > x) x = y; }
inline void setmin(ll &x, ll y) { if (y < x) x = y; }
inline void setmax(ll &x, ll y) { if (y > x) x = y; }

const int N = 2000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int n;
int g[N][N], gr[N][N];
bool used[N];
vector<int> order;

void dfs(int u)
{
    used[u] = true;
    rep(v, 0, n)
        if (g[u][v] && !used[v])
            dfs(v);
    order.push_back(u);
}

int dfs1(int u)
{
    used[u] = true;
    int cnt = 1;
    rep(v, 0, n)
        if (gr[u][v] && !used[v])
            cnt += dfs1(v);
    return cnt;
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.precision(20);
    //cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    scanf("%d", &n);
    rep(i, 0, n)
    {
        rep(j, 0, n)
        {
            scanf("%d", &g[i][j]);
            setmin(g[i][j], 1);
        }
    }
    rep(i, 0, n)
        rep(j, 0, n)
            gr[i][j] = g[j][i];
    rep(i, 0, n)
        if (!used[i])
            dfs(i);
    fill(used, used + n, false);
    cout << (dfs1(order.back()) == n ? "YES\n" : "NO\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define NFOR(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); --i)
#define rep(i, a) for (ll i = 0; i < a; i++)
#define endl "\n"
#define fi first
#define se second
#define MOD 1000000007
#define inf 1e12
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

void solve() {
	ll n;
	cin>>n;
	ll A[n][n];

	rep(i,n) {
		rep(j,n) {
			cin>>A[i][j];
			if (A[i][j]) A[i][j] = 1;
		}
	}

	rep (k, n) {
		rep (i, n) {
			rep (j, n) {
				if (A[i][k] and A[k][j])
					A[i][j] = 1;
			}
		}
	}

	rep (i, n)
		rep (j, n)
			if (!A[i][j]) {
				cout << "NO\n";
				return;
			}
	cout << "YES\n";
}

int main()
{
    fastio;
    ll t  = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define NFOR(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); --i)
#define rep(i, a) for (ll i = 0; i < a; i++)
#define endl "\n"
#define fi first
#define se second
#define MOD 1000000007
#define inf 1e12
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

vl adj[2002];
vector<bool> vis(2002, false);

void dfs(ll v, stack<ll> &S)
{
	// pr(v);
	vis[v] = true;
	for (auto &u : adj[v]) {
		if (not vis[u])
			dfs(u, S);
	}
	S.push(v);
}

void solve() {
	ll n;
	cin>>n;
	ll temp;

	rep(i,n) {
		rep(j,n) {
			cin>>temp;
			if (temp) {
				adj[i].pb(j);
			}
		}
		// pr(i,adj[i]);
	}

	// sort by finish times
	stack<ll> S;
	rep(i, n)
		if (not vis[i])
			dfs(i, S);

	// rev graph
	vl adj2[2002];
	rep (i, n) {
		for (auto &j : adj[i])
			adj2[j].pb(i);
	}

	rep (i, n) {
		adj[i] = adj2[i];
		// pr(i,adj[i]);
	}

	vis = vector<bool>(2002,false);
	ll ctr = 0;
	// dfs on G' acc to finish times
	while (not S.empty()) {
		ll s = S.top(); S.pop();
		// pr(s);
		if (not vis[s]) {
			ctr++;
			if (ctr == 2) {
				cout << "NO\n";
				return;
			}
			dfs(s, S);
		}
	}

	cout << "YES\n";
}

int main()
{
    fastio;
    ll t  = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define NFOR(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); --i)
#define rep(i, a) for (ll i = 0; i < a; i++)
#define endl "\n"
#define fi first
#define se second
#define MOD 1000000007
#define inf 1e12
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

vl adj[2002];
vector<bool> vis(2002, false);

void dfs(ll v)
{
	vis[v] = true;
	for (auto &u : adj[v]) {
		if (not vis[u])
			dfs(u);
	}
}

void solve() {
	ll n;
	cin>>n;
	ll temp;

	rep(i,n) {
		rep(j,n) {
			cin>>temp;
			if (temp) {
				adj[i].pb(j);
			}
		}
	}

	rep (i, n) {
		dfs(i);
		rep (i, n) {
			if (not vis[i]) {
				cout << "NO\n";
				return;
			}
			vis[i] = false;
		}
	}
	cout << "YES\n";
}

int main()
{
    fastio;
    ll t  = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


///not today

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

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef pair<long long, long long> pll;

#define SZ(x) (int)(x).size()
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
//#define int long long
#define accept_sho ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define lc (v << 1)
#define rc ((v << 1)| 1)
#define mid ((R + L) >> 1)

int n;
const int maxn = 2002;
bool a[maxn][maxn], mrk[maxn];
queue <int> b;

void bfs(int x){
      b.push(x);
      mrk[x] = true;
      while(SZ(b)){
            int v = b.front();
            b.pop();
            for(int u = 0; u < n; u ++){
                  if(a[v][u] && !mrk[u]){
                        mrk[u] = true;
                        b.push(u);
                  }
            }
      }
      return;
}

int32_t main(){
      accept_sho
      cin >>n;
      for(int i = 0; i < n; i ++){
            for(int j = 0; j < n; j ++){
                  int x;
                  cin >>x;
                  if(x)
                        a[i][j] = 1;
            }
      }
      bfs(0);
      for(int i = 0; i < n; i ++){
            if(!mrk[i])
                  return cout <<"NO" <<'\n', false;
            mrk[i] = false;
      }
      bfs(1);
      for(int i = 0; i < n; i ++){
            if(!mrk[i])
                  return cout <<"NO" <<'\n', false;
      }
      cout <<"YES" <<'\n';
      return false;
}


///not today

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

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef pair<long long, long long> pll;

#define SZ(x) (int)(x).size()
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
//#define int long long
#define accept_sho ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define lc (v << 1)
#define rc ((v << 1)| 1)
#define mid ((R + L) >> 1)

int n;
const int maxn = 2002;
bool a[maxn][maxn], mrk[maxn];
queue <int> b;

void bfs(int x){
      b.push(x);
      mrk[x] = true;
      while(SZ(b)){
            int v = b.front();
            b.pop();
            for(int u = 0; u < n; u ++){
                  if(a[v][u] && !mrk[u]){
                        mrk[u] = true;
                        b.push(u);
                  }
            }
      }
      return;
}

int32_t main(){
      cin >>n;
      for(int i = 0; i < n; i ++){
            for(int j = 0; j < n; j ++){
                  int x;
                  cin >>x;
                  if(x)
                        a[i][j] = 1;
            }
      }
      bfs(0);
      for(int i = 0; i < n; i ++){
            if(!mrk[i])
                  return cout <<"NO" <<'\n', false;
            mrk[i] = false;
      }
      bfs(1);
      for(int i = 0; i < n; i ++){
            if(!mrk[i])
                  return cout <<"NO" <<'\n', false;
      }
      cout <<"YES" <<'\n';
      return false;
}


///not today

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

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef pair<long long, long long> pll;

#define SZ(x) (int)(x).size()
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
//#define int long long
#define accept_sho ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define lc (v << 1)
#define rc ((v << 1)| 1)
#define mid ((R + L) >> 1)

int n;
const int maxn = 2002;
bool a[maxn][maxn], mrk[maxn];
queue <int> b;

void bfs(int x){
      b.push(x);
      mrk[x] = true;
      while(SZ(b)){
            int v = b.front();
            b.pop();
            for(int u = 0; u < n; u ++){
                  if(a[v][u] && !mrk[u]){
                        mrk[u] = true;
                        b.push(u);
                  }
            }
      }
      return;
}

int32_t main(){
      accept_sho
      cin >>n;
      for(int i = 0; i < n; i ++){
            for(int j = 0; j < n; j ++){
                  int x;
                  cin >>x;
                  if(x)
                        a[i][j] = 1;
            }
      }
      if(n == 1)
            return cout <<"YES" <<'\n', false;
      bfs(0);
      for(int i = 0; i < n; i ++){
            for(int j = 0; j < i; j ++)
                  swap(a[i][j], a[j][i]);
      }
      for(int i = 0; i < n; i ++){
            if(!mrk[i])
                  return cout <<"NO" <<'\n', false;
            mrk[i] = false;
      }
      bfs(0);
      for(int i = 0; i < n; i ++){
            if(!mrk[i])
                  return cout <<"NO" <<'\n', false;
      }
      cout <<"YES" <<'\n';
      return false;
}


#include<cstdio>
#include<iostream>
#define N 10008
#define M 4000008
using namespace std;
int n,m,ans,cnt,ecnt,dfn[N],low[N],h[N],next[M],to[M],top,s[N];
bool in[N],vis[N];
void add(int x,int y)
{
	next[++ecnt]=h[x];
	to[ecnt]=y;
	h[x]=ecnt;
}
void tarjan(int x)
{
	dfn[x]=low[x]=++cnt;
	s[++top]=x;
	in[x]=true;
	vis[x]=true;
	for(int p=h[x];p;p=next[p])
	{
		int u=to[p];
		if(!vis[u])
		{
			tarjan(u);
			low[x]=min(low[x],low[u]);
		}
		else
		if(in[u])low[x]=min(low[x],dfn[u]);
	}
	if(dfn[x]==low[x])
	{
		int tot=0;
		while(s[top+1]!=x)
		{
			in[s[top]]=false;
			top--;
			tot++;
		}
		if(tot>1)ans++;
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
        {
            int x;
		    scanf("%d",&x);
		    if(i!=j&&x)add(i,j);
        }
    }
	for(int i=1;i<=n;i++)
	    if(!dfn[i])tarjan(i);
	if(ans==1)return puts("YES");
    else return puts("NO");
}


#include<cstdio>
#include<iostream>
#define N 10008
#define M 4000008
using namespace std;
bool flag=false;
int n,m,ans,cnt,ecnt,dfn[N],low[N],h[N],nxt[M],to[M],top,s[N];
bool in[N],vis[N];
void add(int x,int y)
{
	nxt[++ecnt]=h[x];
	to[ecnt]=y;
	h[x]=ecnt;
}
void tarjan(int x)
{
	dfn[x]=low[x]=++cnt;
	s[++top]=x;
	in[x]=true;
	vis[x]=true;
	for(int p=h[x];p;p=nxt[p])
	{
		int u=to[p];
		if(!vis[u])
		{
			tarjan(u);
			low[x]=min(low[x],low[u]);
		}
		else
		if(in[u])low[x]=min(low[x],dfn[u]);
	}
	if(dfn[x]==low[x])
	{
		int tot=0;
		while(s[top+1]!=x)
		{
			in[s[top]]=false;
			top--;
			tot++;
		}
		ans++;
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
        {
            int x;
		    scanf("%d",&x);
		    if(i!=j&&x)add(i,j);
        }
    }
	for(int i=1;i<=n;i++)
	    if(!dfn[i])tarjan(i);
	if(ans==1)return puts("YES"),0;
    else return puts("NO"),0;
}


#include<cstdio>
#include<iostream>
#define N 10008
#define M 4000008
using namespace std;
bool flag=false;
int n,m,ans,cnt,ecnt,dfn[N],low[N],h[N],nxt[M],to[M],top,s[N];
bool in[N],vis[N];
void add(int x,int y)
{
	nxt[++ecnt]=h[x];
	to[ecnt]=y;
	h[x]=ecnt;
}
void tarjan(int x)
{
	dfn[x]=low[x]=++cnt;
	s[++top]=x;
	in[x]=true;
	vis[x]=true;
	for(int p=h[x];p;p=nxt[p])
	{
		int u=to[p];
		if(!vis[u])
		{
			tarjan(u);
			low[x]=min(low[x],low[u]);
		}
		else
		if(in[u])low[x]=min(low[x],dfn[u]);
	}
	if(dfn[x]==low[x])
	{
		int tot=0;
		while(s[top+1]!=x)
		{
			in[s[top]]=false;
			top--;
			tot++;
		}
		if(tot==1)flag=true;
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
        {
            int x;
		    scanf("%d",&x);
		    if(i!=j&&x)add(i,j);
        }
    }
	for(int i=1;i<=n;i++)
	    if(!dfn[i])tarjan(i);
	if(!flag)return puts("YES"),0;
    else return puts("NO"),0;
}


#include<cstdio>
#include<iostream>
#define N 10008
#define M 4000008
using namespace std;
int n,m,ans,cnt,ecnt,dfn[N],low[N],h[N],nxt[M],to[M],top,s[N];
bool in[N],vis[N];
void add(int x,int y)
{
	nxt[++ecnt]=h[x];
	to[ecnt]=y;
	h[x]=ecnt;
}
void tarjan(int x)
{
	dfn[x]=low[x]=++cnt;
	s[++top]=x;
	in[x]=true;
	vis[x]=true;
	for(int p=h[x];p;p=nxt[p])
	{
		int u=to[p];
		if(!vis[u])
		{
			tarjan(u);
			low[x]=min(low[x],low[u]);
		}
		else
		if(in[u])low[x]=min(low[x],dfn[u]);
	}
	if(dfn[x]==low[x])
	{
		int tot=0;
		while(s[top+1]!=x)
		{
			in[s[top]]=false;
			top--;
			tot++;
		}
		if(tot>1)ans++;
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
        {
            int x;
		    scanf("%d",&x);
		    if(i!=j&&x)add(i,j);
        }
    }
	for(int i=1;i<=n;i++)
	    if(!dfn[i])tarjan(i);
	if(ans==1)return puts("YES");
    else return puts("NO");
}


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

int n,x;
vector<int> adj[2003];
vector<int> rdj[2003];
bool vstd[2003];
bool islp[2003];
int cnt=0;
int rnt=0;

void dfs1(int x){
    cnt++;
    vstd[x] = 1;
    for(int i=0;i<adj[x].size();i++){
        if(!vstd[adj[x][i]])dfs1(adj[x][i]);
    }
}

void dfs2(int x){
    rnt++;
    vstd[x] = 1;
    for(int i=0;i<rdj[x].size();i++){
        if(!vstd[rdj[x][i]])dfs2(rdj[x][i]);
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
                cin>>x;
                if(x>0){
                    adj[i].push_back(j);
                    rdj[j].push_back(i);
                    islp[i]=(i==j);
                }
        }
    }

    for(int i=1;i<=n;i++){
        if(islp[i]){
            memset(vstd,0,sizeof vstd);
            cnt =0;
            dfs1(i);
            memset(vstd,0,sizeof vstd);
            rnt =0;
            dfs2(i);
            //cout<<i<<" "<<cnt<<" "<<rnt<<endl;
            if(cnt == n && rnt == n){
                cout<<"YES";
                return 0;
            }
        }
    }

    cout<<"NO";

    return 0;
}


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

bool r[2003];
bool c[2003];
bool l[2003];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int x;
            cin>>x;
            if(!x){
                r[i]=c[j]=1;
                l[i]=(i==j);
            }
        }
    }
    for(int i=0;i<n;i++){
        if(!l[i]){
            if(!r[i] && !c[i]){
                cout<<"YES";
                return 0;
            }
        }
    }
    cout<<"NO";
    return 0;
}


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

int n,x;
vector<int> adj[2003];
vector<int> rdj[2003];
bool vstd[2003];
int cnt=0;
int rnt=0;

void dfs1(int x){
    cnt++;
    vstd[x] = 1;
    for(int i=0;i<adj[x].size();i++){
        if(!vstd[adj[x][i]])dfs1(adj[x][i]);
    }
}

void dfs2(int x){
    rnt++;
    vstd[x] = 1;
    for(int i=0;i<rdj[x].size();i++){
        if(!vstd[rdj[x][i]])dfs2(rdj[x][i]);
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
                cin>>x;
                if(x>0){
                    adj[i].push_back(j);
                    rdj[j].push_back(i);
                }
        }
    }

    dfs1(1);
    memset(vstd,0,sizeof vstd);
    dfs2(1);
    if(cnt == n && rnt == n){
        cout<<"YES";
        return 0;
    }

    cout<<"NO";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
vector <bool>vist;
vector <vector <int> >g;
vector <vector <int> >v;

void dfs(int u){
	if(vist[u])return;
	vist[u]=true;
	for(int i=0;i<g[u].size();++i){
		dfs(g[u][i]);
	}
}

void dfs2(int u){
	if(vist[u])return;
	vist[u]=true;
	for(int i=0;i<v[u].size();++i){
		dfs(v[u][i]);
	}
}

int main(){
	int p;
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	g=vector <vector <int> >(n);
	v=vector <vector <int> >(n);
	int a;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			cin >> a;
			if(a){
				if(i==j) p=i;
				g[i].push_back(j);
				v[j].push_back(i);
			}

		}
	}
	vist=vector <bool>(n,false);
	dfs(p);
	for(int i=0;i<n;++i){
		if(!vist[i]){
			cout << "NO" << endl;
			return 0;
		}
	}
	vist=vector <bool>(n,false);
	dfs2(p);
	for(int i=0;i<n;++i){
		if(!vist[i]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


#include <bits/stdc++.h>

using namespace std;

int n;
vector <bool>vist;
vector <vector <int> >g;
vector <vector <int> >v;

void dfs(int u){
	if(vist[u])return;
	vist[u]=true;
	for(int i=0;i<g[u].size();++i){
		dfs(g[u][i]);
	}
}

void dfs2(int u){
	if(vist[u])return;
	vist[u]=true;
	for(int i=0;i<v[u].size();++i){
		dfs2(v[u][i]);
	}
}

int main(){
	int p;
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	g=vector <vector <int> >(n);
	v=vector <vector <int> >(n);
	int a;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			cin >> a;
			if(a){
				if(i==j) p=i;
				g[i].push_back(j);
				v[j].push_back(i);
			}

		}
	}
	vist=vector <bool>(n,false);
	dfs(p);
	for(int i=0;i<n;++i){
		if(!vist[i]){
			cout << "NO" << endl;
			return 0;
		}
	}
	for(int i=0;i<n;++i) vist[i]=false;
	dfs2(p);
	for(int i=0;i<n;++i){
		if(!vist[i]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


#include <bits/stdc++.h>

using namespace std;

int n;
stack<int>s;
vector <bool>vist;
vector <vector <int> >g;
vector <vector <int> >v;

void dfs(int u){
	if(vist[u])return;
	vist[u]=true;
	for(int i=0;i<g[u].size();++i){
		dfs(g[u][i]);
	}
	s.push(u);
}

void dfs2(int u){
	if(vist[u])return;
	vist[u]=true;
	for(int i=0;i<v[u].size();++i){
		dfs(v[u][i]);
	}
	s.push(u);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	g=vector <vector <int> >(n);
	v=vector <vector <int> >(n);
	int a;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			cin >> a;
			if(a){
				g[i].push_back(j);
				v[j].push_back(i);
			}

		}
	}
	vist=vector <bool>(n,false);
	for(int i=0;i<n;++i){
		dfs(i);
	}
	vist=vector <bool>(n,false);
	a=s.top();
	dfs2(a);
	for(int i=0;i<n;++i){
		if(!vist[i]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


#include <bits/stdc++.h>

using namespace std;

int n;
stack<int>s;
vector <bool>vist;
vector <vector <int> >g;
vector <vector <int> >v;

void dfs(int u){
	if(vist[u])return;
	vist[u]=true;
	for(int i=0;i<g[u].size();++i){
		dfs(g[u][i]);
	}
	s.push(u);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	g=vector <vector <int> >(n);
	v=vector <vector <int> >(n);
	int a;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			cin >> a;
			if(a){
				g[i].push_back(j);
				v[j].push_back(i);
			}

		}
	}
	vist=vector <bool>(n,false);
	for(int i=0;i<n;++i){
		dfs(i);
	}
	vist=vector <bool>(n,false);
	a=s.top();
	dfs(a);
	for(int i=0;i<n;++i){
		if(!vist[i]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


/*     !ya khoda!     */
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define ld long double

#define pp push
#define po pop()
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
#define I insert
#define E erase

#define F first
#define S second

#define mkp make_pair
#define pll pair<ll,ll>
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define all(a) a.begin(),a.end()

#define coutghat(x)      cout<<tolower(x);
#define coutashar(x,d)   cout<<fixed<<setprecision(x)<<(ld)d
#define IOS ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)
//#define poow(a,b,M)   b?(poow((a*a)%M,b/2)%M * (b&1?a))%M:1 ;
/*==========================================================================*/
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll poow(ll x,ll n,ll Mod=1e9+7) { return (n==0?1:poow(x*x%Mod,n/2)*(n&1?x:1)%Mod); }
//#pragma optimize O3
// 107,109, 211,223, 307, 401,409, 503,509, 601,607, 701,709, 809, 907, 1009
/*==========================================================================*/
const int N=1e5+100 , M=1e3+100 , LG=23 , base=2;
const int MOD=1e9+7 , mod=1e9+9;
const ll  INF=1e9   , inf=1e18 , super_inf=~0ull/4;
ll n=N,f[N],sfr[N] , x,y;
/*==========================================================================*/
ll tav(ll a,ll b)
{
    if(b==0)   return 1;
    ll ans=tav(a,b/2)%MOD;
    ans=(ans*ans)%MOD;
    if(b&1)    ans*=a , ans%MOD;
    return ans%MOD;
}
/*==========================================================================*/
int main()
{
    IOS;
    cin>>x>>y;
    f[1]=1 , sfr[1]=1;
    for(int i=2;i<n;i++)   f[i]=f[i-1]*i , f[i]%=MOD;
    for(int i=2;i<n;i++)   sfr[i] = (sfr[i-1] * tav(i,MOD-2))%MOD;
    cout<< (f[x]*sfr[x-y]*sfr[y])%MOD;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,a[2010][2010] , vis[2010][5];
vector<int>g[2010][5];
void dfs(int v,int p)
{   vis[v][p]=1;
    for(int i=0;i<g[v][p].size();i++)   if(!vis[g[v][p][i]][p])   dfs(g[v][p][i],p);
}
int main()
{   cin>>n;
    for(int i=0;i<n;i++)   for(int j=0;j<n;j++)
        {   cin>>a[i][j];
            if(a[i][j]>0) g[i][0].push_back(j) , g[j][1].push_back(i);  }
    dfs(0,0) , dfs(0,1);
    for(int i=0;i<n;i++)   if(!vis[i][0] || !vis[i][1])   return cout<<"NO" , 0;
    return cout<<"YES" , 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,a[2010][2010] , vis[2010][5];
vector<int>g[2010][5];
void dfs(int v,int p)
{   vis[v][p]=1;
    for(int i=0;i<g[v][p].size();i++)   if(!vis[g[v][p][i]][p])   dfs(g[v][p][i],p);
}
int main()
{   ios_base::sync_with_stdio(false) , cin.tie(0) , cout.tie(0);   cin>>n;
    for(int i=0;i<n;i++)   for(int j=0;j<n;j++)
        {   cin>>a[i][j];
            if(a[i][j]>0) g[i][0].push_back(j) , g[j][1].push_back(i);  }
    dfs(0,0) , dfs(0,1);
    for(int i=0;i<n;i++)   if(!vis[i][0] || !vis[i][1])   return cout<<"NO" , 0;
    return cout<<"YES" , 0;
}