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: Wrong Answer)

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

public class Program
{
    private int N;
    private int[] A, B;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.IntArray();
        B = sc.IntArray();

        /*
         * A,Bをソート
         * A[i] > B[i]のやつがあれば No
         * 置換ループが2つ以上ならYes
         * 閉じたループN未満 探す
         */

        var tmpA = A.ToArray();
        var tmpB = B.ToArray();
        Array.Sort(tmpA);
        Array.Sort(tmpB);
        for (int i = 0; i < N; i++)
        {
            if (tmpA[i] > tmpB[i])
            {
                Console.WriteLine("No");
                return;
            }
        }

        Tuple<int, int>[] tmp = new Tuple<int, int>[N];
        for (int i = 0; i < N; i++)
        {
            tmp[i] = new Tuple<int, int>(A[i], B[i]);
        }

        Array.Sort(tmp, (a, b) => a.Item2.CompareTo(b.Item2));

        for (int i = 0; i < N; i++)
        {
            A[i] = tmp[i].Item1;
            B[i] = tmp[i].Item2;
        }


        var map = new Dictionary<int, int>();
        for (int i = 0; i < N; i++)
        {
            map[A[i]] = i;
        }

        Array.Sort(A);

        int index = map[A[0]];
        int cnt = 1;
        int[] f = new int[N];
        f[0] = 1;
        while (f[index] == 0)
        {
            cnt++;
            f[index] = cnt;
            index = map[A[index]];
        }

        Console.WriteLine(cnt - f[index] + 1 < N ? "Yes" : "No");
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}