#include <iostream>
using namespace std;
int main()
{
    int n , m;
    cin >> n;
    int arr1[n];
    for ( int i = 0 ; i < n ; i ++ )
    {
        cin >> arr1[i];
    }

    cin >> m;
    int arr2[m];
    for ( int i = 0 ; i < m ; i ++ )
    {
        cin >> arr2[i];
    }

    int i = 0;
    int j = 0;
    int counter = 0;
    while ( i < n )
    {
        if ( i == n - 1 )
        {
            i = 0;
        }

        else 
        {
            i ++;
        }

        if ( arr1[i] == arr2[j] && j < m )
        {
            j ++;
            counter ++;
        }

        else if ( j == m || ( arr1[i] =! arr2[j] && j < m ))
        {
            break;
        }
    }

    if ( counter == m )
    {
        cout << "Yes";
    }

    else
    {
        cout << "No";
    }



    return 0;
}