#include <stdio.h>
int n, a[200010], b[200010];
int main() {
scanf("%d", &n);
for(int i=0; i<n; i++) scanf("%d", &a[i]);
for(int j=0; j<n; j++) scanf("%d", &b[j]);
int aidx=0, bidx=0, aemp=-1, bemp=-1;
while(aidx<n||bidx<n) {
if(a[aidx]==b[bidx]) {
aidx++;
bidx++;
continue;
}
if(bemp==-1 && a[aidx]==b[bidx+1]) {
bemp=b[bidx++];
}
else if(aemp==-1 && a[aidx+1]==b[bidx]) {
aemp=a[aidx++];
}
else {
printf("No");
return 0;
}
}
if(aemp==bemp) printf("Yes");
else printf("No");
}
To embed this project on your website, copy the following code and paste it into your website's HTML: