using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeForces
{
    class R191MemSql_A
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int[] x1 = new int[n];
            int[] x2 = new int[n];
            int[] y1 = new int[n];
            int[] y2 = new int[n];
            int area = 0;
            int maxx = -1, minx = 35000, maxy = -1, miny = 35000;
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split();
                x1[i] = int.Parse(s[0]);
                y1[i] = int.Parse(s[1]);
                x2[i] = int.Parse(s[2]);
                y2[i] = int.Parse(s[3]);
                area += (x2[i] - x1[i]) * (y2[i] - y1[i]);
                maxx = Math.Max(maxx, x2[i]);
                maxy = Math.Max(maxy, y2[i]);
                minx = Math.Min(minx, x1[i]);
                miny = Math.Min(miny, y1[i]);
            }

            if (area == (maxx - minx) * (maxy - miny)
                && (maxx - minx) == (maxy - miny))
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;

namespace codeforces
{
    class rect
    {
        public Tuple<int, int> leftbottom;
        public Tuple<int, int> righttop;
        public rect(int x1, int y1, int x2, int y2)
        {
            leftbottom = new Tuple<int, int>(x1, y1);
            righttop = new Tuple<int, int>(x2, y2);
        }
    }
    public class A
    {
        public static int Main()
        {

            int n;

            n = int.Parse(System.Console.ReadLine());
            List<rect> rtlist = new List<rect>();
            SortedSet<int> xs = new SortedSet<int>();
            SortedSet<int> ys = new SortedSet<int>();
            for (int i = 0; i < n; i++)
            {
                string line= System.Console.ReadLine();
                string[] ints = line.Split(new char[1]{' '});
                int[] x = new int[4];
                for (int j = 0; j < 4; j++)
                    x[j] = int.Parse(ints[j]);
                rect rt = new rect(x[0], x[1], x[2], x[3]);
                xs.Add(x[0]);
                xs.Add(x[2]);
                ys.Add(x[1]);
                ys.Add(x[3]);
                rtlist.Add(rt);

            }
            if ((xs.Max - xs.Min) != (ys.Max - ys.Min))
            {
                System.Console.WriteLine("NO");
                return 0;
            }
            Dictionary<Tuple<int,int>,int> dic = new Dictionary<Tuple<int,int>,int>();

            for (int i = 0; i < n; i++)
            {
                rect rt = rtlist[i];
                var valuex = xs.GetViewBetween(rt.leftbottom.Item1, rt.righttop.Item1);
                var valuey = ys.GetViewBetween(rt.leftbottom.Item2, rt.righttop.Item2);
                foreach(int x in valuex)
                {
                    foreach (int y in valuey)
                    {
                        Tuple<int, int> tu = new Tuple<int, int>(x, y);
                        int v = 4;
                        if ((x == rt.leftbottom.Item1) || (x == rt.righttop.Item1))
                            v /= 2;
                        if ((y== rt.leftbottom.Item2) || (y == rt.righttop.Item2))
                            v /= 2;
                        if (dic.ContainsKey(tu))
                            dic[tu] += v;
                        else
                            dic[tu] = v;

                    }
                }
            }
            foreach(var x in dic)
            {
                var k = x.Key;
                var v = x.Value;
                if ((k.Item1 == xs.Max) || (k.Item1 == xs.Min))
                    v *= 2;
                if ((k.Item2 == ys.Max) || (k.Item2 == ys.Min))
                    v *= 2;
                if (v != 4)
                {
                    System.Console.WriteLine("NO");
                    return 0;
                }
            }
            System.Console.WriteLine("YES");
            return 0;

        }
    }
}

using System;
using System.Linq;
using System.Text;

namespace CodeForces.Solutions.c325_memsql_1
{
	public class Program1
	{
		public static void Main()
		{
			checked
			{
				var n = int.Parse(Console.ReadLine());
				var rects = Enumerable.Range(0, n)
					.Select(i => Console.ReadLine().Split(' ').Select(long.Parse).ToArray())
					.ToArray();

				var s = rects.Select(a => (a[2] - a[0])*(a[3] - a[1])).Sum();
				var minX = rects.Min(a => a[0]);
				var maxX = rects.Max(a => a[2]);
				var minY = rects.Min(a => a[1]);
				var maxY = rects.Max(a => a[3]);

				var dx = (maxX - minX);
				var dy = (maxY - minY);
				Console.WriteLine(s == dx*dy && dx == dy ? "YES" : "NO");
			}
		}

	}
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Square_and_Rectangles
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve() ? "YES" : "NO");
            writer.Flush();
        }

        private static bool Solve()
        {
            int n = Next();

            var nn = new Rec[n];
            var xx = new List<int>();
            var yy = new List<int>();
            for (int i = 0; i < n; i++)
            {
                nn[i] = new Rec(Next(), Next(), Next(), Next());

                xx.Add(nn[i].x1);
                xx.Add(nn[i].x2);

                yy.Add(nn[i].y1);
                yy.Add(nn[i].y2);
            }

            xx.Sort();
            yy.Sort();

            if (xx[xx.Count - 1] - xx[0] != yy[yy.Count - 1] - yy[0])
            {
                return false;
            }

            var x = new List<int> {xx[0]};
            for (int i = 1; i < xx.Count; i++)
            {
                if (xx[i] != xx[i - 1])
                    x.Add(xx[i]);
            }
            var y = new List<int> {yy[0]};
            for (int i = 1; i < yy.Count; i++)
            {
                if (yy[i] != yy[i - 1])
                    y.Add(yy[i]);
            }
            foreach (Rec rec in nn)
            {
                rec.x1 = x.BinarySearch(rec.x1);
                rec.x2 = x.BinarySearch(rec.x2);
                rec.y1 = y.BinarySearch(rec.y1);
                rec.y2 = y.BinarySearch(rec.y2);
            }

            var nm = new int[x.Count,y.Count];
            foreach (Rec rec in nn)
            {
                for (int i = rec.x1 + 1; i <= rec.x2; i++)
                {
                    for (int j = rec.y1 + 1; j <= rec.y2; j++)
                    {
                        nm[i, j] = 1;
                    }
                }
            }

            for (int i = 1; i < x.Count; i++)
            {
                for (int j = 1; j < y.Count; j++)
                {
                    if (nm[i, j] == 0)
                        return false;
                }
            }

            return true;
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }

        #region Nested type: Rec

        private class Rec
        {
            public int x1;
            public int x2;
            public int y1;
            public int y2;

            public Rec(int x1, int y1, int x2, int y2)
            {
                this.x1 = x1;
                this.x2 = x2;
                this.y1 = y1;
                this.y2 = y2;
            }
        }

        #endregion
    }
}

using System;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Globalization;
using System.Collections.Generic;
using System.Threading;
using kp.Algo;

namespace CodeForces
{
	internal class Solution
	{
		const int StackSize = 20 * 1024 * 1024;

		private void Solve()
		{
			int n = NextInt();
			int[] x1 = new int[n], x2 = new int[n], y1 = new int[n], y2 = new int[n];
			long sq = 0;
			int minX = int.MaxValue, maxX = int.MinValue, minY = int.MaxValue, maxY = int.MinValue;
			for ( int i = 0; i < n; ++i )
			{
				x1[i] = NextInt();
				y1[i] = NextInt();
				x2[i] = NextInt();
				y2[i] = NextInt();
				sq += (long)( x2[i] - x1[i] ) * ( y2[i] - y1[i] );
				minX = Math.Min( minX, x1[i] );
				maxX = Math.Max( maxX, x2[i] );
				minY = Math.Min( minY, y1[i] );
				maxY = Math.Max( maxY, y2[i] );
			}

			bool res = false;
			if ( maxX - minX == maxY - minY )
			{
				if ( sq == (long)( maxX - minX ) * ( maxX - minX ) )
				{
					res = true;
				}
			}

			Out.WriteLine( res ? "YES" : "NO" );
		}

		#region Local wireup

		public int[] NextIntArray( int size )
		{
			var res = new int[size];
			for ( int i = 0; i < size; ++i ) res[i] = NextInt();
			return res;
		}

		public long[] NextLongArray( int size )
		{
			var res = new long[size];
			for ( int i = 0; i < size; ++i ) res[i] = NextLong();
			return res;
		}

		public double[] NextDoubleArray( int size )
		{
			var res = new double[size];
			for ( int i = 0; i < size; ++i ) res[i] = NextDouble();
			return res;
		}

		public int NextInt()
		{
			return _in.NextInt();
		}

		public long NextLong()
		{
			return _in.NextLong();
		}

		public string NextLine()
		{
			return _in.NextLine();
		}

		public double NextDouble()
		{
			return _in.NextDouble();
		}

		readonly Scanner _in = new Scanner();
		static readonly TextWriter Out = Console.Out;

		void Start()
		{
#if !ONLINE_JUDGE
			var timer = new Stopwatch();
			timer.Start();
#endif
			var t = new Thread( Solve, StackSize );
			t.Start();
			t.Join();
#if !ONLINE_JUDGE
			timer.Stop();
			Console.WriteLine( string.Format( CultureInfo.InvariantCulture, "Done in {0} seconds.\nPress <Enter> to exit.", timer.ElapsedMilliseconds / 1000.0 ) );
			Console.ReadLine();
#endif
		}

		static void Main()
		{
			new Solution().Start();
		}

		class Scanner : IDisposable
		{
			#region Fields

			readonly TextReader _reader;
			readonly int _bufferSize;
			readonly bool _closeReader;
			readonly char[] _buffer;
			int _length, _pos;

			#endregion

			#region .ctors

			public Scanner( TextReader reader, int bufferSize, bool closeReader )
			{
				_reader = reader;
				_bufferSize = bufferSize;
				_closeReader = closeReader;
				_buffer = new char[_bufferSize];
				FillBuffer( false );
			}

			public Scanner( TextReader reader, bool closeReader ) : this( reader, 1 << 16, closeReader ) { }

			public Scanner( string fileName ) : this( new StreamReader( fileName, Encoding.Default ), true ) { }

#if ONLINE_JUDGE
			public Scanner() : this( Console.In, false ) { }
#else
			public Scanner() : this( "input.txt" ) { }
#endif

			#endregion

			#region IDisposable Members

			public void Dispose()
			{
				if ( _closeReader )
				{
					_reader.Close();
				}
			}

			#endregion

			#region Properties

			public bool Eof
			{
				get
				{
					if ( _pos < _length ) return false;
					FillBuffer( false );
					return _pos >= _length;
				}
			}

			#endregion

			#region Methods

			private char NextChar()
			{
				if ( _pos < _length ) return _buffer[_pos++];
				FillBuffer( true );
				return _buffer[_pos++];
			}

			private char PeekNextChar()
			{
				if ( _pos < _length ) return _buffer[_pos];
				FillBuffer( true );
				return _buffer[_pos];
			}

			private void FillBuffer( bool throwOnEof )
			{
				_length = _reader.Read( _buffer, 0, _bufferSize );
				if ( throwOnEof && Eof )
				{
					throw new IOException( "Can't read beyond the end of file" );
				}
				_pos = 0;
			}

			public int NextInt()
			{
				var neg = false;
				int res = 0;
				SkipWhitespaces();
				if ( !Eof && PeekNextChar() == '-' )
				{
					neg = true;
					_pos++;
				}
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					var c = NextChar();
					if ( c < '0' || c > '9' ) throw new ArgumentException( "Illegal character" );
					res = 10 * res + c - '0';
				}
				return neg ? -res : res;
			}

			public long NextLong()
			{
				var neg = false;
				long res = 0;
				SkipWhitespaces();
				if ( !Eof && PeekNextChar() == '-' )
				{
					neg = true;
					_pos++;
				}
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					var c = NextChar();
					if ( c < '0' || c > '9' ) throw new ArgumentException( "Illegal character" );
					res = 10 * res + c - '0';
				}
				return neg ? -res : res;
			}

			public string NextLine()
			{
				SkipUntilNextLine();
				if ( Eof ) return "";
				var builder = new StringBuilder();
				while ( !Eof && !IsEndOfLine( PeekNextChar() ) )
				{
					builder.Append( NextChar() );
				}
				return builder.ToString();
			}

			public double NextDouble()
			{
				SkipWhitespaces();
				var builder = new StringBuilder();
				while ( !Eof && !IsWhitespace( PeekNextChar() ) )
				{
					builder.Append( NextChar() );
				}
				return double.Parse( builder.ToString(), CultureInfo.InvariantCulture );
			}

			private void SkipWhitespaces()
			{
				while ( !Eof && IsWhitespace( PeekNextChar() ) )
				{
					++_pos;
				}
			}

			private void SkipUntilNextLine()
			{
				while ( !Eof && IsEndOfLine( PeekNextChar() ) )
				{
					++_pos;
				}
			}

			private static bool IsWhitespace( char c )
			{
				return c == ' ' || c == '\t' || c == '\n' || c == '\r';
			}

			private static bool IsEndOfLine( char c )
			{
				return c == '\n' || c == '\r';
			}

			#endregion
		}

		#endregion
	}
}

namespace kp.Algo { }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
//using System.Numerics;

class Program
{
    static TextReader reader;
    static TextWriter writer;
    static Program()
    {
#if ONLINE_JUDGE
        reader = Console.In;
        writer = Console.Out;
#else
        reader = new StreamReader("input.txt");
        writer = new StreamWriter("output.txt");
#endif
    }
    static long gcd(long a, long b)
    {
        return (b != 0) ? gcd(b, a % b) : a;
    }
    static void swap(ref int a, ref int b)
    {
        int t = a;
        a = b;
        b = t;
    }
    static long pow(long a, long x, long mod)
    {
        long res = 1;
        while (x > 0)
        {
            if ((x & 1) == 1)
            {
                res = (res * a) % mod;
                --x;
            }
            else
            {
                a = (a * a) % mod;
                x >>= 1;
            }
        }
        return res;
    }
    static void _a()
    {
        int n = int.Parse(reader.ReadLine());
        int xmin = 31400, xmax = 0, ymin = 31400, ymax = 0;
        long square = 0;
        for (int i = 0; i < n; ++i)
        {
            string[] s = reader.ReadLine().Split();
            int x1 = int.Parse(s[0]), y1 = int.Parse(s[1]), x2 = int.Parse(s[2]), y2 = int.Parse(s[3]);
            xmin = Math.Min(xmin, x1);
            ymin = Math.Min(ymin, y1);
            xmax = Math.Max(xmax, x2);
            ymax = Math.Max(ymax, y2);
            square += (x2 - x1) * (y2 - y1);
        }
        if ((xmax - xmin) == (ymax - ymin) && square == (xmax - xmin) * (ymax - ymin))
            writer.Write("YES");
        else
            writer.Write("NO");
    }
    static void _b()
    {

    }
    static void _c()
    {

    }
    static void _d()
    {

    }
    static void Main(string[] args)
    {
        _a();
        reader.Close();
        writer.Close();
    }
}

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;

namespace Codeforces
{
    internal static class Program
    {
        private const string TEST = "A1";

        private static void Solve()
        {
            var n = ReadInt();
            var s = 0;
            int minX1 = int.MaxValue, maxX2 = int.MinValue, minY1 = int.MaxValue, maxY2 = int.MinValue;
            for (int i = 0; i < n; i++)
            {
                int x1, y1, x2, y2;
                Read(out x1, out y1, out x2, out y2);
                minX1 = Math.Min(minX1, x1);
                minY1 = Math.Min(minY1, y1);
                maxX2 = Math.Max(maxX2, x2);
                maxY2 = Math.Max(maxY2, y2);
                s += (x2 - x1)*(y2 - y1);
            }
            var isQ = maxX2 - minX1 == maxY2 - minY1;
            WriteLine(s==(maxX2-minX1)*(maxY2-minY1) && isQ ? "YES":"NO");
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(String.Format(@"..\..\..\..\Tests\{0}.in", TEST)));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        private static int[] SortIndexs<T>(this IEnumerable<T> source) where T : IComparable
        {
            var array = source == null ? new List<T>() : source.ToList();
            var n = array.Count;
            var res = Enumerable.Range(0, n).ToArray();
            Array.Sort(res, (a, b) => array[a].CompareTo(array[b]));
            return res;
        }

        #region Reader

        private static string Read()
        {
            return Console.ReadLine();
        }

        private static void Read<T>(out T a1, out T a2)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
        }

        private static void Read<T>(out T a1, out T a2, out T a3)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
            a3 = (T)Convert.ChangeType(input[2], typeof(T));
        }

        private static void Read<T>(out T a1, out T a2, out T a3, out T a4)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
            a3 = (T)Convert.ChangeType(input[2], typeof(T));
            a4 = (T)Convert.ChangeType(input[3], typeof(T));
        }

        private static void Read<T>(out T a1, out T a2, out T a3, out T a4, out T a5)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
            a3 = (T)Convert.ChangeType(input[2], typeof(T));
            a4 = (T)Convert.ChangeType(input[3], typeof(T));
            a5 = (T)Convert.ChangeType(input[4], typeof(T));
        }

        private static void Read<T>(out T a1, out T a2, out T a3, out T a4, out T a5, out T a6)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
            a3 = (T)Convert.ChangeType(input[2], typeof(T));
            a4 = (T)Convert.ChangeType(input[3], typeof(T));
            a5 = (T)Convert.ChangeType(input[4], typeof(T));
            a6 = (T)Convert.ChangeType(input[5], typeof(T));
        }

        private static int ReadInt()
        {
            return Int32.Parse(Read());
        }

        private static long ReadLong()
        {
            return long.Parse(Read());
        }

        private static double ReadDouble()
        {
            return double.Parse(Read(), CultureInfo.InvariantCulture);
        }

        private static T Read<T>()
        {
            return (T)Convert.ChangeType(Read(), typeof(T));
        }

        private static string[] ReadArray()
        {
            var readLine = Console.ReadLine();
            if (readLine != null)
                return readLine.Split(' ');

            throw new ArgumentException();
        }

        private static List<int> ReadIntArray()
        {
            return ReadArray().Select(Int32.Parse).ToList();
        }

        private static List<long> ReadLongArray()
        {
            return ReadArray().Select(long.Parse).ToList();
        }

        private static List<double> ReadDoubleArray()
        {
            return ReadArray().Select(d => double.Parse(d, CultureInfo.InvariantCulture)).ToList();
        }

        private static List<T> ReadArray<T>()
        {
            return ReadArray().Select(x => (T)Convert.ChangeType(x, typeof(T))).ToList();
        }

        private static void WriteLine(double value)
        {
            Console.WriteLine(value.ToString(CultureInfo.InvariantCulture));
        }

        private static void WriteLine(double value, string stringFormat)
        {
            Console.WriteLine(value.ToString(stringFormat, CultureInfo.InvariantCulture));
        }

        private static void WriteLine<T>(T value)
        {
            Console.WriteLine(value);
        }

        private static void Write(double value)
        {
            Console.Write(value.ToString(CultureInfo.InvariantCulture));
        }

        private static void Write(double value, string stringFormat)
        {
            Console.Write(value.ToString(stringFormat, CultureInfo.InvariantCulture));
        }

        private static void Write<T>(T value)
        {
            Console.Write(value);
        }

        #endregion
    }
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PA
{
    class Program
    {
        private static int _n = 0, _maxX = int.MinValue, _minX = int.MaxValue, _maxY = int.MinValue, _minY = int.MaxValue;
        private static List<Rectangle> _rectangles;

        private static void ReadInput(string filepath)
        {
            try
            {
                string line;
                //using(StreamReader sr = new StreamReader(filepath))
                //{
                    line  = /*sr.ReadLine();*/Console.ReadLine();
                    if(!int.TryParse(line, out _n))
                    {
                        throw new ArgumentException("bad input file format");
                    }

                    int[] tempCoords = new int[4];
                    for(int i = 0; i < _n; i++)
                    {
                        line = /*sr.ReadLine();*/Console.ReadLine();

                        if(!string.IsNullOrEmpty(line.Trim()))
                        {
                            string[] coords = line.Split(' ');

                            if(coords.Length != 4)
                            {
                                throw new ArgumentException("bad input file format");
                            }

                            for(int j = 0; j < 4; j++)
                            {
                                if(!int.TryParse(coords[j], out tempCoords[j]))
                                {
                                    throw new ArgumentException("bad input file format");
                                }
                            }

                            if(_maxX < tempCoords[2])
                                _maxX = tempCoords[2];

                            if(_minX > tempCoords[0])
                                _minX = tempCoords[0];

                            if(_maxY < tempCoords[3])
                                _maxY = tempCoords[3];

                            if(_minY > tempCoords[1])
                                _minY = tempCoords[1];

                            _rectangles.Add(new Rectangle
                                {
                                    X0 = tempCoords[0],
                                    Y0 = tempCoords[1],
                                    X1 = tempCoords[2],
                                    Y1 = tempCoords[3]
                                });
                        }
                    }
                //}

            }
            catch (Exception ex)
            {
                Console.WriteLine("Can't read input data!");
                Console.WriteLine(ex.Message);
            }
        }

        private static bool FindSquares()
        {
            if (_maxX - _minX != _maxY - _minY)
                return false;

            double maxArea = (_maxX - _minX) * (_maxY - _minY);
            double area = .0;

            for (int i = 0; i < _n; i++)
            {
                area += (_rectangles[i].X1 - _rectangles[i].X0) * (_rectangles[i].Y1 - _rectangles[i].Y0);
            }

            if (area == maxArea)
            {
                return true;
            }

            return false;
        }

        static void Main(string[] args)
        {
            try
            {
                if (null == _rectangles)
                {
                    _rectangles = new List<Rectangle>();
                }

                ReadInput("D:/Problems/PA/PA/inputNO.txt");

                var state = FindSquares();

                if (state)
                    Console.WriteLine("YES");
                else
                    Console.WriteLine("NO");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: ");
                Console.WriteLine(ex.Message);
            }

        }

        private class Rectangle
        {
            private int _x0;

            /// <summary>
            /// left
            /// </summary>
            public int X0
            {
                get { return _x0; }
                set { _x0 = value; }
            }

            private int _y0;

            /// <summary>
            /// bottom
            /// </summary>
            public int Y0
            {
                get { return _y0; }
                set { _y0 = value; }
            }

            private int _x1;
            /// <summary>
            /// right
            /// </summary>
            public int X1
            {
                get { return _x1; }
                set { _x1 = value; }
            }

            private int _y1;
            /// <summary>
            /// top
            /// </summary>
            public int Y1
            {
                get { return _y1; }
                set { _y1 = value; }
            }

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt16(Console.ReadLine());
            int ymin, ymax,x1,y1,x2,y2;
            int xmin = ymin = 32100;
            int xmax = ymax = -32100;
            long S = 0;
            string[] temp = new string[4];

            for (int i = 0; i < n; ++i)
            {
                temp=Console.ReadLine().Split(new char[]{' '});
                x1 = Convert.ToInt16(temp[0]);
                y1 = Convert.ToInt16(temp[1]);
                x2 = Convert.ToInt16(temp[2]);
                y2 = Convert.ToInt16(temp[3]);
                S += (x2 - x1) * (y2 - y1);
                if (xmin > x1) xmin = x1;
                if (xmin > x2) xmin = x2;
                if (ymin > y1) ymin = y1;
                if (ymin > y2) ymin = y2;
                if (xmax < x1) xmax = x1;
                if (xmax < x2) xmax = x2;
                if (ymax < y1) ymax = y1;
                if (ymax < y2) ymax = y2;
            }

            if (S == (xmax - xmin) * (ymax - ymin) && (xmax-xmin == ymax - ymin)) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }
    }
}

using System;
using System.Linq;

class Program
{
    static void Main()
    {
        string str = Console.ReadLine();
        int n = int.Parse(str);

        var squares = new int[n, 4];

        int minX = -1, maxX = -1, minY = -1, maxY = -1;

        for (int i = 0; i < n; i++)
        {
            str = Console.ReadLine();
            var q = str.Split(new char[] {' '});

            squares[i, 0] = int.Parse(q[0]);
            squares[i, 1] = int.Parse(q[1]);
            squares[i, 2] = int.Parse(q[2]);
            squares[i, 3] = int.Parse(q[3]);

            if (i == 0)
            {
                minX = squares[i, 0];
                minY = squares[i, 1];
                maxX = squares[i, 2];
                maxY = squares[i, 3];
            }

            if (minX > squares[i, 0]) minX = squares[i, 0];
            if (minY > squares[i, 1]) minY = squares[i, 1];
            if (maxX < squares[i, 2]) maxX = squares[i, 2];
            if (maxY < squares[i, 3]) maxY = squares[i, 3];
            // Console.WriteLine(str);
        }

        if (maxX - minX != maxY - minY)
        {
            Console.WriteLine("NO");
            return;
        }

        int square1 = (maxX - minX) * (maxY - minY);
        int square2 = 0;

        for (int i = 0; i < n; i++)
        {
            square2 += (squares[i, 2] - squares[i, 0]) * (squares[i, 3] - squares[i, 1]);
        }

        if (square1 != square2)
        {
            // Console.WriteLine("NO 2 1: {0} 2: {1}", square1, square2);
            Console.WriteLine("NO");
            return;
        }

        Console.WriteLine("YES");
    }
}

using System;
using System.Linq;
class Demo
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int S = 0;
        int minx = 31401, miny = 31401, maxx = 0, maxy = 0;
        while (n-- > 0)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            S += (a[2] - a[0]) * (a[3] - a[1]);
            if (a[0] < minx) minx = a[0];
            if (a[1] < miny) miny = a[1];
            if (a[2] > maxx) maxx = a[2];
            if (a[3] > maxy) maxy = a[3];
        }
        string ans = maxx - minx == maxy - miny && Math.Pow(maxx - minx, 2) == S ? "YES" : "NO";
        Console.WriteLine(ans);
    }
}

#define Online

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.IO;

namespace CF
{
    delegate double F(double x);
    delegate decimal Fdec(decimal x);

    partial class Program
    {

        static void Main(string[] args)
        {

#if FileIO
            StreamReader sr = new StreamReader("input.txt");
            StreamWriter sw = new StreamWriter("output.txt");
            Console.SetIn(sr);
            Console.SetOut(sw);
#endif

            A();

#if Online
            Console.ReadLine();
#endif

#if FileIO
            sr.Close();
            sw.Close();
#endif
        }

        static void A()
        {
            int n = ReadInt();
            int minx = int.MaxValue;
            int maxx = int.MinValue;
            int miny = int.MaxValue;
            int maxy = int.MinValue;
            int S=0;
            for (int i = 0; i < n; i++)
            {
                ReadArray(' ');
                int x1=NextInt();
                int y1=NextInt();
                int x2=NextInt();
                int y2=NextInt();
                minx = Math.Min(minx, x1);
                miny = Math.Min(miny, y1);
                maxx = Math.Max(maxx, x2);
                maxy = Math.Max(maxy, y2);
                S+=(x2-x1)*(y2-y1);
            }
            if (maxx - minx == maxy - miny && S == (maxx - minx) * (maxy - miny)) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }

        static void B()
        {
        }

        static void C()
        {

        }

        static void D()
        {

        }

        static void E()
        {

        }

        static void TestGen()
        {

        }

    }

    public static class MyMath
    {
        public static long BinPow(long a, long n, long mod)
        {
            long res = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    res = (res * a) % mod;
                }
                a = (a * a) % mod;
                n >>= 1;
            }
            return res;
        }

        public static long GCD(long a, long b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static int GCD(int a, int b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static long LCM(long a, long b)
        {
            return (a * b) / GCD(a, b);
        }

        public static int LCM(int a, int b)
        {
            return (a * b) / GCD(a, b);
        }
    }

    static class ArrayUtils
    {
        public static int BinarySearch(int[] a, int val)
        {
            int left = 0;
            int right = a.Length - 1;
            int mid;

            while (left < right)
            {
                mid = left + ((right - left) >> 1);
                if (val <= a[mid])
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }

            if (a[left] == val)
                return left;
            else
                return -1;
        }

        public static double Bisection(F f, double left, double right, double eps)
        {
            double mid;
            while (right - left > eps)
            {
                mid = left + ((right - left) / 2d);
                if (Math.Sign(f(mid)) != Math.Sign(f(left)))
                    right = mid;
                else
                    left = mid;
            }
            return (left + right) / 2d;
        }

        public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)
        {
            decimal m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3m;
                m2 = r - (r - l) / 3m;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static double TernarySearch(F f, double eps, double l, double r, bool isMax)
        {
            double m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3d;
                m2 = r - (r - l) / 3d;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R, Comparison<T> comp)
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (comp(L[i], R[j]) <= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R, comp);
            Merge_Sort(A, q + 1, r, L, R, comp);
            Merge(A, p, q, r, L, R, comp);
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable<T>
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (L[i].CompareTo(R[j]) >= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R);
            Merge_Sort(A, q + 1, r, L, R);
            Merge(A, p, q, r, L, R);
        }

        public static void Merge_Sort1<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            int k = 1;
            while (k < r - p + 1)
            {
                int i = 0;
                while (i < r)
                {
                    int _r = Math.Min(i + 2 * k - 1, r);
                    int q = Math.Min(i + k - 1, r);
                    Merge(A, i, q, _r, L, R);
                    i += 2 * k;
                }
                k <<= 1;
            }
        }

        public static void Merge_Sort1<T>(T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
        {
            int k = 1;
            while (k < r - p + 1)
            {
                int i = 0;
                while (i < r)
                {
                    int _r = Math.Min(i + 2 * k - 1, r);
                    int q = Math.Min(i + k - 1, r);
                    Merge(A, i, q, _r, L, R, comp);
                    i += 2 * k;
                }
                k <<= 1;
            }
        }

        static void Shake<T>(T[] a)
        {
            Random rnd = new Random(Environment.TickCount);
            T temp;
            int b, c;
            for (int i = 0; i < a.Length; i++)
            {
                b = rnd.Next(0, a.Length);
                c = rnd.Next(0, a.Length);
                temp = a[b];
                a[b] = a[c];
                a[c] = temp;
            }
        }
    }

    partial class Program
    {
        static string[] tokens;
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static int NextInt()
        {
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            return tokens[cur_token++];
        }

        static string ReadLine()
        {
            return Console.ReadLine();
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    void calc()
    {
        Scanner cin = new Scanner();
        int n = cin.nextInt();
        int[] x1 = new int[n];
        int[] x2 = new int[n];
        int[] y1 = new int[n];
        int[] y2 = new int[n];
        int x1min = 99999;
        int x2max = 0;
        int y1min = 99999;
        int y2max = 0;

        long sum = 0;

        for (int i = 0; i < n; i++)
        {
            x1[i] = cin.nextInt();
            y1[i] = cin.nextInt();
            x2[i] = cin.nextInt();
            y2[i] = cin.nextInt();
            x1min = Math.Min(x1min, x1[i]);
            x2max = Math.Max(x2max, x2[i]);
            y1min = Math.Min(y1min, y1[i]);
            y2max = Math.Max(y2max, y2[i]);
            sum += (x2[i] - x1[i]) * (y2[i] - y1[i]);
        }
        if (x2max - x1min == y2max - y1min && (long)(x2max - x1min) * (y2max - y1min) == sum)
        {
            Console.WriteLine("YES");
        }
        else Console.WriteLine("NO");
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }
}

using System;

    class Program
    {
        static void Main()
        {
            int x1,x2,y1,y2,xl,xp,yn,yv;
            int n = Convert.ToInt32(Console.ReadLine())-1;

            string[] s = Console.ReadLine().Split(' ');
                x1 = xl= Convert.ToInt32(s[0]);
                y1 = yn =Convert.ToInt32(s[1]);
                x2 = xp= Convert.ToInt32(s[2]);
                y2 = yv =Convert.ToInt32(s[3]);
                int p = (x2 - x1) * (y2 - y1);

            for (; n > 0; n--) {
                s = Console.ReadLine().Split(' ');
                x1 = Convert.ToInt32(s[0]);
                y1 = Convert.ToInt32(s[1]);
                x2 = Convert.ToInt32(s[2]);
                y2 = Convert.ToInt32(s[3]);
                if (x1 < xl) xl = x1;
                if (y1 < yn) yn = y1;
                if (x2 > xp) xp = x2;
                if (y2 > yv) yv = y2;
                p += (x2 - x1) * (y2 - y1);
            }

            if (p == (xp - xl) * (yv - yn) && xp-xl==yv-yn) Console.WriteLine("YES");
            else Console.WriteLine("NO");

        }
    }

using System;
using System.Linq;
using System.Text;

namespace CodeForces.Solutions.c325_memsql_1
{
	public class Program1
	{
		public static void Main()
		{
			checked
			{
				var n = int.Parse(Console.ReadLine());
				var rects = Enumerable.Range(0, n)
					.Select(i => Console.ReadLine().Split(' ').Select(long.Parse).ToArray())
					.ToArray();

				var s = rects.Select(a => (a[2] - a[0])*(a[3] - a[1])).Sum();
				var minX = rects.Min(a => a[0]);
				var maxX = rects.Max(a => a[2]);
				var minY = rects.Min(a => a[1]);
				var maxY = rects.Max(a => a[3]);

				Console.WriteLine(s == (maxX - minX)*(maxY - minY) ? "YES" : "NO");
			}
		}

	}
}

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PA
{
    class Program
    {
        private static int _n = 0, _maxX = int.MinValue, _minX = int.MaxValue, _maxY = int.MinValue, _minY = int.MaxValue;
        private static List<Rectangle> _rectangles;

        private static void ReadInput(string filepath)
        {
            try
            {
                string line;
                using(StreamReader sr = new StreamReader(filepath))
                {
                    line  = /*sr.ReadLine();*/Console.ReadLine();
                    if(!int.TryParse(line, out _n))
                    {
                        throw new ArgumentException("bad input file format");
                    }

                    int[] tempCoords = new int[4];
                    for(int i = 0; i < _n; i++)
                    {
                        line = /*sr.ReadLine();*/Console.ReadLine();

                        if(!string.IsNullOrEmpty(line.Trim()))
                        {
                            string[] coords = line.Split(' ');

                            if(coords.Length != 4)
                            {
                                throw new ArgumentException("bad input file format");
                            }

                            for(int j = 0; j < 4; j++)
                            {
                                if(!int.TryParse(coords[j], out tempCoords[j]))
                                {
                                    throw new ArgumentException("bad input file format");
                                }
                            }

                            if(_maxX < tempCoords[2])
                                _maxX = tempCoords[2];

                            if(_minX > tempCoords[0])
                                _minX = tempCoords[0];

                            if(_maxY < tempCoords[3])
                                _maxY = tempCoords[3];

                            if(_minY > tempCoords[1])
                                _minY = tempCoords[1];

                            _rectangles.Add(new Rectangle
                                {
                                    X0 = tempCoords[0],
                                    Y0 = tempCoords[1],
                                    X1 = tempCoords[2],
                                    Y1 = tempCoords[3]
                                });
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("Can't read input data!");
                Console.WriteLine(ex.Message);
            }
        }

        private static bool FindSquares()
        {
            if (_maxX - _minX != _maxY - _minY)
                return false;

            double maxArea = (_maxX - _minX) * (_maxY - _minY);
            double area = .0;

            for (int i = 0; i < _n; i++)
            {
                area += (_rectangles[i].X1 - _rectangles[i].X0) * (_rectangles[i].Y1 - _rectangles[i].Y0);
            }

            if (area == maxArea)
            {
                return true;
            }

            return false;
        }

        static void Main(string[] args)
        {
            if (null == _rectangles)
            {
                _rectangles = new List<Rectangle>();
            }

            ReadInput("D:/Problems/PA/PA/inputNO.txt");

            var state = FindSquares();

            if (state)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

        }

        private class Rectangle
        {
            private int _x0;

            /// <summary>
            /// left
            /// </summary>
            public int X0
            {
                get { return _x0; }
                set { _x0 = value; }
            }

            private int _y0;

            /// <summary>
            /// bottom
            /// </summary>
            public int Y0
            {
                get { return _y0; }
                set { _y0 = value; }
            }

            private int _x1;
            /// <summary>
            /// right
            /// </summary>
            public int X1
            {
                get { return _x1; }
                set { _x1 = value; }
            }

            private int _y1;
            /// <summary>
            /// top
            /// </summary>
            public int Y1
            {
                get { return _y1; }
                set { _y1 = value; }
            }

        }
    }
}

#define Online

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.IO;

namespace CF
{
    delegate double F(double x);
    delegate decimal Fdec(decimal x);

    partial class Program
    {

        static int n;
        static Rect[] r;
        static bool[] u;
        static int[] x = new int[31401];
        struct Rect
        {
            public int x1;
            public int y1;
            public int x2;
            public int y2;
        }

        static void Main(string[] args)
        {

#if FileIO
            StreamReader sr = new StreamReader("input.txt");
            StreamWriter sw = new StreamWriter("output.txt");
            Console.SetIn(sr);
            Console.SetOut(sw);
#endif

            A();

#if Online
            Console.ReadLine();
#endif

#if FileIO
            sr.Close();
            sw.Close();
#endif
        }

        static void A()
        {
            n = ReadInt();
            r = new Rect[n];
            u = new bool[n];
            for (int i = 0; i < n; i++)
            {
                ReadArray(' ');
                r[i].x1 = NextInt();
                r[i].y1 = NextInt();
                r[i].x2 = NextInt();
                r[i].y2 = NextInt();
            }
            if (dfs(1, 0) || dfs(2, 0) || dfs(3, 0) || dfs(4, 0) || dfs(5, 0)) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }

        static void B()
        {
        }

        static void C()
        {

        }

        static void D()
        {

        }

        static void E()
        {

        }

        static void TestGen()
        {

        }

        static bool dfs(int z, int k)
        {
            if (k == z)
            {
                Clear();
                for (int i = 0; i < n; i++)
                {
                    if (!u[i]) continue;
                    for (int j = r[i].x1; j < r[i].x2; j++)
                    {
                        x[j] += r[i].y2 - r[i].y1;
                    }
                }

                for (int i = 0, j = 0; i < 31401; i++)
                {
                    if (x[i] > 0)
                    {
                        int val = x[i];
                        for (j = i; ; )
                        {
                            if (j < 31401 && x[j + 1] == val)
                            {
                                j++;
                            }
                            else
                            {
                                if (j == 31400) break;
                                if (x[j + 1] != 0) return false;
                                else break;

                            }
                        }
                        if (val == j - i + 1)
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                }
            }
            for (int i = 0; i < n; i++)
            {
                if (!u[i])
                {
                    u[i] = true;
                    if (dfs(z, k + 1)) return true;
                    u[i] = false;
                }
            }
            return false;
        }

        static void Clear()
        {
            for (int i = 0; i < 31401; i++)
            {
                x[i] = 0;
            }
        }
    }

    public static class MyMath
    {
        public static long BinPow(long a, long n, long mod)
        {
            long res = 1;
            while (n > 0)
            {
                if ((n & 1) == 1)
                {
                    res = (res * a) % mod;
                }
                a = (a * a) % mod;
                n >>= 1;
            }
            return res;
        }

        public static long GCD(long a, long b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static int GCD(int a, int b)
        {
            while (b != 0) b = a % (a = b);
            return a;
        }

        public static long LCM(long a, long b)
        {
            return (a * b) / GCD(a, b);
        }

        public static int LCM(int a, int b)
        {
            return (a * b) / GCD(a, b);
        }
    }

    static class ArrayUtils
    {
        public static int BinarySearch(int[] a, int val)
        {
            int left = 0;
            int right = a.Length - 1;
            int mid;

            while (left < right)
            {
                mid = left + ((right - left) >> 1);
                if (val <= a[mid])
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }

            if (a[left] == val)
                return left;
            else
                return -1;
        }

        public static double Bisection(F f, double left, double right, double eps)
        {
            double mid;
            while (right - left > eps)
            {
                mid = left + ((right - left) / 2d);
                if (Math.Sign(f(mid)) != Math.Sign(f(left)))
                    right = mid;
                else
                    left = mid;
            }
            return (left + right) / 2d;
        }

        public static decimal TernarySearchDec(Fdec f, decimal eps, decimal l, decimal r, bool isMax)
        {
            decimal m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3m;
                m2 = r - (r - l) / 3m;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static double TernarySearch(F f, double eps, double l, double r, bool isMax)
        {
            double m1, m2;
            while (r - l > eps)
            {
                m1 = l + (r - l) / 3d;
                m2 = r - (r - l) / 3d;
                if (f(m1) < f(m2))
                    if (isMax)
                        l = m1;
                    else
                        r = m2;
                else
                    if (isMax)
                        r = m2;
                    else
                        l = m1;
            }
            return r;
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R, Comparison<T> comp)
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (comp(L[i], R[j]) <= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R, comp);
            Merge_Sort(A, q + 1, r, L, R, comp);
            Merge(A, p, q, r, L, R, comp);
        }

        public static void Merge<T>(T[] A, int p, int q, int r, T[] L, T[] R) where T : IComparable<T>
        {
            for (int i = p; i <= q; i++)
                L[i] = A[i];
            for (int i = q + 1; i <= r; i++)
                R[i] = A[i];

            for (int k = p, i = p, j = q + 1; k <= r; k++)
            {
                if (i > q)
                {
                    for (; k <= r; k++, j++)
                        A[k] = R[j];
                    return;
                }
                if (j > r)
                {
                    for (; k <= r; k++, i++)
                        A[k] = L[i];
                    return;
                }
                if (L[i].CompareTo(R[j]) >= 0)
                {
                    A[k] = L[i];
                    i++;
                }
                else
                {
                    A[k] = R[j];
                    j++;
                }
            }
        }

        public static void Merge_Sort<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            if (p >= r) return;
            int q = p + ((r - p) >> 1);
            Merge_Sort(A, p, q, L, R);
            Merge_Sort(A, q + 1, r, L, R);
            Merge(A, p, q, r, L, R);
        }

        public static void Merge_Sort1<T>(T[] A, int p, int r, T[] L, T[] R) where T : IComparable<T>
        {
            int k = 1;
            while (k < r - p + 1)
            {
                int i = 0;
                while (i < r)
                {
                    int _r = Math.Min(i + 2 * k - 1, r);
                    int q = Math.Min(i + k - 1, r);
                    Merge(A, i, q, _r, L, R);
                    i += 2 * k;
                }
                k <<= 1;
            }
        }

        public static void Merge_Sort1<T>(T[] A, int p, int r, T[] L, T[] R, Comparison<T> comp)
        {
            int k = 1;
            while (k < r - p + 1)
            {
                int i = 0;
                while (i < r)
                {
                    int _r = Math.Min(i + 2 * k - 1, r);
                    int q = Math.Min(i + k - 1, r);
                    Merge(A, i, q, _r, L, R, comp);
                    i += 2 * k;
                }
                k <<= 1;
            }
        }

        static void Shake<T>(T[] a)
        {
            Random rnd = new Random(Environment.TickCount);
            T temp;
            int b, c;
            for (int i = 0; i < a.Length; i++)
            {
                b = rnd.Next(0, a.Length);
                c = rnd.Next(0, a.Length);
                temp = a[b];
                a[b] = a[c];
                a[c] = temp;
            }
        }
    }

    partial class Program
    {
        static string[] tokens;
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static int NextInt()
        {
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            return tokens[cur_token++];
        }

        static string ReadLine()
        {
            return Console.ReadLine();
        }
    }
}

using System;

    class Program
    {
        static void Main()
        {
            int x1,x2,y1,y2,xl,xp,yn,yv;
            int n = Convert.ToInt32(Console.ReadLine())-1;

            string[] s = Console.ReadLine().Split(' ');
                x1 = xl= Convert.ToInt32(s[0]);
                y1 = yn =Convert.ToInt32(s[1]);
                x2 = xp= Convert.ToInt32(s[2]);
                y2 = yv =Convert.ToInt32(s[3]);
                int p = (x2 - x1) * (y2 - y1);

            for (; n > 0; n--) {
                s = Console.ReadLine().Split(' ');
                x1 = Convert.ToInt32(s[0]);
                y1 = Convert.ToInt32(s[1]);
                x2 = Convert.ToInt32(s[2]);
                y2 = Convert.ToInt32(s[3]);
                if (x1 < xl) xl = x1;
                if (y1 < yn) yn = y1;
                if (x2 > xp) xp = x2;
                if (y2 > yv) yv = y2;
                p += (x2 - x1) * (y2 - y1);
            }

            if (p == (xp - xl) * (yv - yn)) Console.WriteLine("YES");
            else Console.WriteLine("NO");

        }
    }

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;

namespace Codeforces
{
    internal static class Program
    {
        private const string TEST = "A1";

        private static void Solve()
        {
            var n = ReadInt();
            var s = 0;
            int minX1 = int.MaxValue, maxX2 = int.MinValue, minY1 = int.MaxValue, maxY2 = int.MinValue;
            for (int i = 0; i < n; i++)
            {
                int x1, y1, x2, y2;
                Read(out x1, out y1, out x2, out y2);
                minX1 = Math.Min(minX1, x1);
                minY1 = Math.Min(minY1, y1);
                maxX2 = Math.Max(maxX2, x2);
                maxY2 = Math.Max(maxY2, y2);
                s += (x2 - x1)*(y2 - y1);
            }
            WriteLine(s==(maxX2-minX1)*(maxY2-minY1)? "YES":"NO");
        }

        private static void Main()
        {
            if (Debugger.IsAttached)
            {
                Console.SetIn(new StreamReader(String.Format(@"..\..\..\..\Tests\{0}.in", TEST)));
            }

            Solve();

            if (Debugger.IsAttached)
            {
                Console.In.Close();
                Console.SetIn(new StreamReader(Console.OpenStandardInput()));
                Console.ReadLine();
            }
        }

        private static int[] SortIndexs<T>(this IEnumerable<T> source) where T : IComparable
        {
            var array = source == null ? new List<T>() : source.ToList();
            var n = array.Count;
            var res = Enumerable.Range(0, n).ToArray();
            Array.Sort(res, (a, b) => array[a].CompareTo(array[b]));
            return res;
        }

        #region Reader

        private static string Read()
        {
            return Console.ReadLine();
        }

        private static void Read<T>(out T a1, out T a2)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
        }

        private static void Read<T>(out T a1, out T a2, out T a3)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
            a3 = (T)Convert.ChangeType(input[2], typeof(T));
        }

        private static void Read<T>(out T a1, out T a2, out T a3, out T a4)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
            a3 = (T)Convert.ChangeType(input[2], typeof(T));
            a4 = (T)Convert.ChangeType(input[3], typeof(T));
        }

        private static void Read<T>(out T a1, out T a2, out T a3, out T a4, out T a5)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
            a3 = (T)Convert.ChangeType(input[2], typeof(T));
            a4 = (T)Convert.ChangeType(input[3], typeof(T));
            a5 = (T)Convert.ChangeType(input[4], typeof(T));
        }

        private static void Read<T>(out T a1, out T a2, out T a3, out T a4, out T a5, out T a6)
        {
            var input = ReadArray();
            a1 = (T)Convert.ChangeType(input[0], typeof(T));
            a2 = (T)Convert.ChangeType(input[1], typeof(T));
            a3 = (T)Convert.ChangeType(input[2], typeof(T));
            a4 = (T)Convert.ChangeType(input[3], typeof(T));
            a5 = (T)Convert.ChangeType(input[4], typeof(T));
            a6 = (T)Convert.ChangeType(input[5], typeof(T));
        }

        private static int ReadInt()
        {
            return Int32.Parse(Read());
        }

        private static long ReadLong()
        {
            return long.Parse(Read());
        }

        private static double ReadDouble()
        {
            return double.Parse(Read(), CultureInfo.InvariantCulture);
        }

        private static T Read<T>()
        {
            return (T)Convert.ChangeType(Read(), typeof(T));
        }

        private static string[] ReadArray()
        {
            var readLine = Console.ReadLine();
            if (readLine != null)
                return readLine.Split(' ');

            throw new ArgumentException();
        }

        private static List<int> ReadIntArray()
        {
            return ReadArray().Select(Int32.Parse).ToList();
        }

        private static List<long> ReadLongArray()
        {
            return ReadArray().Select(long.Parse).ToList();
        }

        private static List<double> ReadDoubleArray()
        {
            return ReadArray().Select(d => double.Parse(d, CultureInfo.InvariantCulture)).ToList();
        }

        private static List<T> ReadArray<T>()
        {
            return ReadArray().Select(x => (T)Convert.ChangeType(x, typeof(T))).ToList();
        }

        private static void WriteLine(double value)
        {
            Console.WriteLine(value.ToString(CultureInfo.InvariantCulture));
        }

        private static void WriteLine(double value, string stringFormat)
        {
            Console.WriteLine(value.ToString(stringFormat, CultureInfo.InvariantCulture));
        }

        private static void WriteLine<T>(T value)
        {
            Console.WriteLine(value);
        }

        private static void Write(double value)
        {
            Console.Write(value.ToString(CultureInfo.InvariantCulture));
        }

        private static void Write(double value, string stringFormat)
        {
            Console.Write(value.ToString(stringFormat, CultureInfo.InvariantCulture));
        }

        private static void Write<T>(T value)
        {
            Console.Write(value);
        }

        #endregion
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt16(Console.ReadLine());
            int ymin, ymax,x1,y1,x2,y2;
            int xmin = ymin = 32100;
            int xmax = ymax = -32100;
            long S = 0;
            string[] temp = new string[4];

            for (int i = 0; i < n; ++i)
            {
                temp=Console.ReadLine().Split(new char[]{' '});
                x1 = Convert.ToInt16(temp[0]);
                y1 = Convert.ToInt16(temp[1]);
                x2 = Convert.ToInt16(temp[2]);
                y2 = Convert.ToInt16(temp[3]);
                S += (x2 - x1) * (y2 - y1);
                if (xmin > x1) xmin = x1;
                if (xmin > x2) xmin = x2;
                if (ymin > y1) ymin = y1;
                if (ymin > y2) ymin = y2;
                if (xmax < x1) xmax = x1;
                if (xmax < x2) xmax = x2;
                if (ymax < y1) ymax = y1;
                if (ymax < y2) ymax = y2;
            }

            if (S == (xmax - xmin) * (ymax - ymin)) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }
    }
}

using System;
using System.Linq;
class Demo
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int S = 0;
        int minx = 31401, miny = 31401, maxx = 0, maxy = 0;
        while (n-- > 0)
        {
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            S += (a[2] - a[0]) * (a[3] - a[1]);
            if (a[0] < minx) { minx = a[0]; miny = a[1]; }
            if (a[1] < miny) { minx = a[0]; miny = a[1]; }
            if (a[2] > maxx) { maxx = a[2]; maxy = a[3]; }
            if (a[3] > maxy) { maxx = a[2]; maxy = a[3]; }
        }
        string ans = maxx - minx == maxy - miny && Math.Pow(maxx - minx, 2) == S ? "YES" : "NO";
        Console.WriteLine(ans);
    }
}