#include <iostream>
using namespace std;
int main()
{
int n; cin >> n;
int arr1[n];
for ( int i = 0 ; i < n ; i ++ )
{
cin >> arr1[i];
}
int m; cin >> m;
int arr2[m];
for ( int i = 0 ; i < m ; i ++ )
{
cin >> arr2[i];
}
int nana , nunu , nini;
nana = 0;
nini = 0;
while ( nana < n + 1 )
{
nunu = 0;
nini = nana;
while ( nunu < m )
{
if ( arr1[nini] == arr2[nunu] )
{
nunu ++;
if ( nini == n - 1 )
{
nini = 0;
}
else
{
nini ++;
}
}
else
{
break;
}
if ( nunu == m )
{
cout << "Yes";
nana = n + n;
break;
}
}
nana ++;
}
if ( nana == n + 1 )
{
cout << "No";
}
return 0;
}