Problem:
Score : 600 points

Problem Statement

Given are two integer sequences of N elements each: A_1,...,A_N and B_1,...,B_N.
Determine if it is possible to do the following operation at most N-2 times (possibly zero) so that, for every integer i from 1 to N, A_i \leq B_i holds:

Choose two distinct integers x and y between 1 and N (inclusive), and swap the values of A_x and A_y.

Constraints

2 \leq N \leq 10^5

1 \leq A_i,B_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N
B_1 B_2 ... B_N

Output

If the objective is achievable, print Yes; if it is not, print No.

Sample Input 1

3
1 3 2
1 2 3

Sample Output 1

Yes

We should swap the values of A_2 and A_3.

Sample Input 2

3
1 2 3
2 2 2

Sample Output 2

No

Sample Input 3

6
3 1 2 6 3 4
2 2 8 3 4 3

Sample Output 3

Yes

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest._600problems
{
    class Nikkei_2019_Qual_C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] aArray = ReadInts();
            int[] bArray = ReadInts();
            int[][] aSorted = new int[n][];
            int[][] bSorted = new int[n][];
            for(int i = 0; i < n; i++)
            {
                aSorted[i] = new int[2] { aArray[i], i };
                bSorted[i] = new int[2] { bArray[i], i };
            }
            Array.Sort(aSorted, (a, b) => a[0] - b[0]);
            Array.Sort(bSorted, (a, b) => a[0] - b[0]);
            for(int i = 0; i < n; i++)
            {
                if (aSorted[i][0] > bSorted[i][0])
                {
                    WriteLine("No");
                    return;
                }
            }

            for (int i = 0; i < n; i++)
            {
                if (aSorted[i][1] == bSorted[i][1])
                {
                    WriteLine("Yes");
                    return;
                }
            }

            for (int i = 0; i < n - 1; i++)
            {
                if (aSorted[i + 1][0] <= bSorted[i][0])
                {
                    WriteLine("Yes");
                    return;
                }
            }

            int[][] sets = new int[n][];
            var zipped = new Dictionary<int, int>();
            for (int i = 0; i < n; i++)
            {
                sets[i] = new int[2] { aArray[i], bArray[i] };
                zipped.Add(aSorted[i][0], i);
            }
            Array.Sort(sets, (a, b) => a[1] - b[1]);

            int cnt = 0;
            for (int i = 0; i < n - 1; i++)
            {
                if (aSorted[i][1] != bSorted[i][1])
                {
                    cnt++;
                    int to = aSorted[i][1];
                    aArray[to] = aArray[bSorted[i][1]];
                    int index = zipped[aArray[bSorted[i][1]]];
                    aSorted[index][1] = to;
                }
            }
            WriteLine(cnt == n - 1 ? "No" : "Yes");
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}