import std.stdio;
import std.algorithm;

int[] readArray(int n) {
	int[] a = new int[n - 1];
	int start = -1;
	
	for (int i = 0, j = 0; i < n; i++) {
		int x;
		
		scanf("%d", &x);
		
		if (x == 1) {
			start = j;
		}
		
		if (x != 0) {
			a[j++] = x;
		}
		
	}
	
	int[] res = new int[n - 1];
	
	for (int i = 0, j = start; i < n - 1; i++, j = (j + 1) % (n - 1))
		res[i] = a[j];
	
	return res;
}

void main()
{
	int n;
	
	scanf("%d", &n);
	
	int[] a = readArray(n);
	int[] b = readArray(n);
	
	if (equal(a, b))
		printf("YES\n");
	else
		printf("NO\n");
}
