#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 10000000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int q[100001],p[100001];
bool flag;
int dp[100001][2];
vector<int> g[3];
vector<int> pg[3];
int dp2[100001];
bool checked[2][100001];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&q[i]);
	}
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		scanf("%d",&p[i]);
	}
	if(p[0]>p[1])flag=true;
	else flag=false;
	int cnt=1;
	for(int i=1;i<m-1;i++){
		bool next=false;
		if(p[i]>p[i+1])next=true;
		if(next!=flag)cnt++;
		flag=next;
	}
	if(cnt>3){
		printf("No\n");
		return 0;
	}else if(cnt==1){
		if(p[0]<p[1]){
			fill(dp2,dp2+n,INF);
			for(int i=0;i<n;i++){
				*lower_bound(dp2,dp2+n,q[i])=q[i];
			}
			int val=lower_bound(dp2,dp2+n,INF)-dp2;
			printf("%s\n",val>=m?"Yes":"No");
		}else{
			fill(dp2,dp2+n,INF);
			for(int i=0;i<n;i++){
				*lower_bound(dp2,dp2+n,INF-1-q[i])=INF-1-q[i];
			}
			int val=lower_bound(dp2,dp2+n,INF)-dp2;
			printf("%s\n",val>=m?"Yes":"No");
		}
	}else if(cnt==2){
		g[0].push_back(q[0]);
		g[0].push_back(q[1]);
		bool qdown=false;
		flag=false;
		if(q[0]>q[1]){
			qdown=true;
			flag=true;
		}
		int nc=0;
		for(int i=1;i<n-1;i++){
			bool next=false;
			if(q[i]>q[i+1])next=true;
			if(next==flag){
				g[nc].push_back(q[i+1]);
			}else{
				nc++;
				g[nc].push_back(q[i]);
				g[nc].push_back(q[i+1]);
			}
			flag=next;
		}

		pg[0].push_back(p[0]);
		pg[0].push_back(p[1]);
		bool pdown=false;
		flag=false;
		if(p[0]>p[1]){
			pdown=true;
			flag=true;
		}
		nc=0;
		for(int i=1;i<m-1;i++){
			bool next=false;
			if(p[i]>p[i+1])next=true;
			if(next==flag){
				pg[nc].push_back(p[i+1]);
			}else{
				nc++;
				pg[nc].push_back(p[i]);
				pg[nc].push_back(p[i+1]);
			}
			flag=next;
		}
		flag=false;
		int side=0;
		if(pdown!=qdown)side=1;
		sort(pg[0].begin(),pg[0].end());
		sort(pg[1].begin(),pg[1].end());
		sort(g[side].begin(),g[side].end());
		sort(g[1+side].begin(),g[1+side].end());
		int ql1=0,ql2=0,pl1=0,pl2=0;
		int nval=-1;
		memset(checked,false,sizeof(checked));
		while(pl1<pg[0].size() || pl2<pg[1].size()){
			int val=-1,which=-1;
			if(pl1==pg[0].size())val=pg[1][pl2],which=1;
			else if(pl2==pg[1].size())val=pg[0][pl1],which=0;
			else{
				if(pg[0][pl1]<pg[1][pl2]){
					val=pg[0][pl1];
					which=0;
				}else{
					val=pg[1][pl2];
					which=1;
				}
			}
			if(!checked[1][val]){
				checked[1][val]=true;
				if(which==0){
					while(1){
						if(ql1==g[side].size()){
							printf("No\n");
							return 0;
						}
						int val2=g[side][ql1];
						if(nval<val2 && !checked[0][val2]){
							nval=val2;
							checked[0][val2]=true;
							break;
						}
						ql1++;
					}
				}else{
					while(1){
						if(ql2==g[side+1].size()){
							printf("No\n");
							return 0;
						}
						int val2=g[side+1][ql2];
						if(nval<val2 && !checked[0][val2]){
							nval=val2;
							checked[0][val2]=true;
							break;
						}
						ql2++;
					}
				}
			}
			if(which==0)pl1++;
			else pl2++;
		}
		printf("Yes\n");
		return 0;
	}else if(cnt==3){
		g[0].push_back(q[0]);
		g[0].push_back(q[1]);
		bool qdown=false;
		flag=false;
		if(q[0]>q[1]){
			qdown=true;
			flag=true;
		}
		int nc=0;
		for(int i=1;i<n-1;i++){
			bool next=false;
			if(q[i]>q[i+1])next=true;
			if(next==flag){
				g[nc].push_back(q[i+1]);
			}else{
				nc++;
				g[nc].push_back(q[i]);
				g[nc].push_back(q[i+1]);
			}
			flag=next;
		}

		pg[0].push_back(p[0]);
		pg[0].push_back(p[1]);
		bool pdown=false;
		flag=false;
		if(p[0]>p[1]){
			pdown=true;
			flag=true;
		}
		nc=0;
		for(int i=1;i<m-1;i++){
			bool next=false;
			if(p[i]>p[i+1])next=true;
			if(next==flag){
				pg[nc].push_back(p[i+1]);
			}else{
				nc++;
				pg[nc].push_back(p[i]);
				pg[nc].push_back(p[i+1]);
			}
			flag=next;
		}
		flag=false;
		if(pdown!=qdown){
			printf("No\n");
			return 0;
		}

		for(int i=0;i<3;i++){
			sort(pg[i].begin(),pg[i].end());
			sort(g[i].begin(),g[i].end());
		}
		int ql[3],pl[3];
		int nval=-1;
		memset(ql,0,sizeof(ql));
		memset(pl,0,sizeof(pl));
		memset(checked,false,sizeof(checked));
		while(pl[0]<pg[0].size() || pl[1]<pg[1].size() || pl[2]<pg[2].size()){
			int val=11451419,which=-1;
			int valc[3];
			for(int i=0;i<3;i++){
				if(pl[i]!=pg[i].size())valc[i]=pg[i][pl[i]];
				else valc[i]=11451419;
			}
			for(int i=0;i<3;i++){
				if(val>valc[i]){
					val=valc[i];
					which=i;
				}
			}
			if(!checked[1][val]){
				checked[1][val]=true;
				while(1){
					if(ql[which]==g[which].size()){
						printf("No\n");
						return 0;
					}
					int val2=g[which][ql[which]];
					if(nval<val2 && !checked[0][val2]){
						nval=val2;
						checked[0][val2]=true;
						break;
					}
					ql[which]++;
				}
			}
			pl[which]++;
		}
		printf("Yes\n");
		return 0;
	}
	return 0;
}

Measured memory_bytes: 4944