using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("5");
WillReturn.Add("1 3 5 5 2");
WillReturn.Add("3 1 5 2 5");
//Yes
}
else if (InputPattern == "Input2") {
WillReturn.Add("3");
WillReturn.Add("2 2 2");
WillReturn.Add("3 3 3");
//No
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
int[] AArr = InputList[1].Split(' ').Select(pX => int.Parse(pX)).ToArray();
int[] BArr = InputList[2].Split(' ').Select(pX => int.Parse(pX)).ToArray();
int UB = AArr.GetUpperBound(0);
bool HasSameNum = false;
for (int I = 0; I <= UB - 1; I++) {
if (AArr[I] == AArr[I + 1]) {
HasSameNum = true;
}
}
int ChangeCnt = 0;
for (int I = 0; I <= UB; I++) {
if (AArr[I] != BArr[I]) {
// 次の文字から移動
if (I + 1 > UB) {
Console.WriteLine("No");
return;
}
if (AArr[I + 1] == BArr[I]) {
ValMove(AArr, I, I + 1);
ChangeCnt++;
continue;
}
// 次の次の文字から移動
if (I + 2 > UB) {
Console.WriteLine("No");
return;
}
if (AArr[I + 2] == BArr[I]) {
ValMove(AArr, I + 1, I + 2);
ValMove(AArr, I, I + 1);
ChangeCnt += 2;
continue;
}
}
}
for (int I = 0; I <= UB - 1; I++) {
if (AArr[I] == AArr[I + 1]) {
HasSameNum = true;
}
}
if (ChangeCnt > 2) {
Console.WriteLine("No");
return;
}
if (AArr.SequenceEqual(BArr)) {
if (ChangeCnt == 1) {
if (HasSameNum) {
Console.WriteLine("Yes");
}
else {
Console.WriteLine("No");
}
return;
}
else {
Console.WriteLine("Yes");
}
}
else {
Console.WriteLine("No");
}
}
// 配列と添字2つを引数として、入れ替える
static void ValMove(int[] pArr, int pInd1, int pInd2)
{
int Val1 = pArr[pInd1];
int Val2 = pArr[pInd2];
pArr[pInd1] = Val2;
pArr[pInd2] = Val1;
}
}