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

class Program
{
    static void Main()
    {
        n = int.Parse(Console.ReadLine());
        var q = Console.ReadLine().Split().Select(int.Parse).ToArray();
        m = int.Parse(Console.ReadLine());
        var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
        if (m == 1)
        {
            Console.WriteLine("Yes");
            return;
        }
        chgp = new List<int>();
        chgq = new List<int>();
        int c = chkrun(p, out chgp);
        chkrun(q, out chgq);
        if (c > 2 || c == 2 && (q[0] < q[1]) != (p[0] < p[1]))
        {
            Console.WriteLine("No");
            return;
        }
        if (c == 0)
        {
            Console.WriteLine(sol1(q, p) ? "Yes" : "No");
        }
        if (c == 1)
        {
            Console.WriteLine(sol2(q, p) ? "Yes" : "No");
        }
        if (c == 2)
        {
            Console.WriteLine(sol3(q, p) ? "Yes" : "No");
        }
    }
    static int n, m;
    static int[] revlr(int[] a)
    {
        var ret = new int[a.Length];
        for (int i = 0; i < a.Length; i++)
        {
            ret[i] = a[a.Length - 1 - i];
        }
        return ret;
    }
    static int[] revud(int[] a)
    {
        var ret = new int[a.Length];
        for (int i = 0; i < a.Length; i++)
        {
            ret[i] = a.Length - a[i] + 1;
        }
        return ret;
    }
    static bool sol1(int[] q, int[] p)
    {
        int c = 0;
        if (p[0] > p[1])
        {
            q = revlr(q);
            p = revlr(p);
        }
        var dp = new int[n];
        for (int i = 0; i < n; i++)
        {
            dp[i] = (int)1e9;
        }
        for (int i = 0; i < n; i++)
        {
            int j = lowerbound(dp, q[i]);
            dp[j] = q[i];
        }
        c = lowerbound(dp, (int)1e9 - 10);
        if (c >= m)
        {
            return true;

        }
        return false;
    }
    static bool sol2(int[] q, int[] p)
    {
        if (p[0] > p[1])
        {
            p = revud(p);
            q = revud(q);
        }
        if (q[0] > q[1])
        {
            p = revlr(p);
            q = revlr(q);
        }
        var sp1 = new Stack<int>();
        var sp2 = new Stack<int>();
        var sq1 = new Stack<int>();
        var sq2 = new Stack<int>();
        for (int i = 0; i <= chgp[0]; i++)
        {
            sp1.Push(p[i]);
        }
        for (int i = m - 1; i > chgp[0] ; i--)
        {
            sp2.Push(p[i]);
        }
        for (int i = 0; i <= chgq[0]; i++)
        {
            sq1.Push(q[i]);
        }
        for (int i = chgq[1]; i > chgq[0] ; i--)
        {
            sq2.Push(q[i]);
        }
        while (sp1.Count + sp2.Count > 0)
        {
            int p1 = 0, p2 = 0;
            if (sp2.Count == 0)
            {
                p1 = sp1.Pop();
                p2 = -1;
            }
            if (sp1.Count == 0)
            {
                p2 = sp2.Pop();
                p1 = -1;
            }
            if (p1 > p2)
            {
                if (sq1.Count == 0)
                {
                    return false;
                }
                int use = sq1.Pop();
                while (sq2.Count > 0)
                {
                    int aa = sq2.Pop();
                    if (aa < use)
                    {
                        sq2.Push(aa);
                        break;
                    }
                }
            }
            else
            {
                if (sq2.Count == 0)
                {
                    return false;
                }
                int use = sq2.Pop();
                while (sq1.Count > 0)
                {
                    int aa = sq1.Pop();
                    if (aa < use)
                    {
                        sq1.Push(aa);
                        break;
                    }
                }
            }
        }
        return true;
    }
    static bool sol3(int[] q, int[] p)
    {
        if (q[0] > q[1])
        {
            p = revlr(p);
            q = revlr(q);
        }
        var sp1 = new Stack<int>();
        var sp2 = new Stack<int>();
        var sp3 = new Stack<int>();
        var sq1 = new Stack<int>();
        var sq2 = new Stack<int>();
        var sq3 = new Stack<int>();
        for (int i = 0; i <= chgp[0]; i++)
        {
            sp1.Push(p[i]);
        }
        for (int i = chgp[1] - 1; i > chgp[0] ; i--)
        {
            sp2.Push(p[i]);
        }
        for (int i = chgp[1]; i < m; i++)
        {
            sp3.Push(p[i]);
        }
        for (int i = 0; i <= chgq[0]; i++)
        {
            sq1.Push(q[i]);
        }
        for (int i = chgq[1] - 1; i > chgq[0] ; i--)
        {
            sq2.Push(q[i]);
        }
        for (int i = chgq[1]; i < n; i++)
        {
            sq3.Push(q[i]);
        }
        while (sp1.Count + sp2.Count + sp3.Count > 0)
        {
            int p1 = -1, p2 = -1, p3 = -1;
            if (sp1.Count > 0)
            {
                p1 = sp1.Pop();
            }
            if (sp2.Count > 0)
            {
                p2 = sp2.Pop();
            }
            if (sp3.Count > 0)
            {
                p3 = sp3.Pop();
            }
            if (p1 > p2 && p1 > p3)
            {
                if (sq1.Count == 0)
                {
                    return false;
                }
                int use = sq1.Pop();
                while (sq2.Count > 0)
                {
                    int aa = sq2.Pop();
                    if (aa < use)
                    {
                        sq2.Push(aa);
                        break;
                    }
                }
                while (sq3.Count > 0)
                {
                    int aa = sq3.Pop();
                    if (aa < use)
                    {
                        sq3.Push(aa);
                        break;
                    }
                }
            }
            else if (p2 > p1 && p2 > p3)
            {
                if (sq2.Count == 0)
                {
                    return false;
                }
                int use = sq2.Pop();
                while (sq1.Count > 0)
                {
                    int aa = sq1.Pop();
                    if (aa < use)
                    {
                        sq1.Push(aa);
                        break;
                    }
                }
                while (sq3.Count > 0)
                {
                    int aa = sq3.Pop();
                    if (aa < use)
                    {
                        sq3.Push(aa);
                        break;
                    }
                }
            }
            else
            {
                if (sq3.Count == 0)
                {
                    return false;
                }
                int use = sq3.Pop();
                while (sq1.Count > 0)
                {
                    int aa = sq1.Pop();
                    if (aa < use)
                    {
                        sq1.Push(aa);
                        break;
                    }
                }
                while (sq2.Count > 0)
                {
                    int aa = sq2.Pop();
                    if (aa < use)
                    {
                        sq2.Push(aa);
                        break;
                    }
                }
            }
        }
        return true;
    }
    static int lowerbound(int[] a, int n)
    {
        int l = 0, r = a.Length - 1;
        while (l < r)
        {
            int m = (l + r) / 2;
            if (a[m] < n)
            {
                if (a[m + 1] >= n) return m + 1;
                l = m + 1;
            }
            else
                r = m - 1;
        }
        if (a[l] < n) return l + 1;
        return l;
    }
    static List<int> chgp, chgq;
    static int chkrun(int[] p, out List<int> l)
    {
        int c = 0;
        l = new List<int>();
        for (int i = 1; i < p.Length - 1; i++)
        {
            if (p[i - 1] < p[i] && p[i] > p[i + 1])
            {
                l.Add(i);
                ++c;
            }
            if (p[i - 1] > p[i] && p[i] < p[i + 1])
            {
                l.Add(i);
                ++c;
            }
        }
        return c;
    }
}

Measured memory_bytes: 23812