

Time Limit: 2 sec / Memory Limit: 1024 MiB
問題文
長さ N の数列 A = (A_1, A_2, \ldots, A_N), B = (B_1, B_2, \ldots, B_N) が与えられます。
数列 A に以下の操作をちょうど 2 回行います。
- 1 \leq i < N なる整数 i を選び、A_i の値と A_{i + 1} の値を入れ替える
ちょうど 2 回の操作後に A = B となることがあるか判定してください。
制約
- 2 \leq N \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq N
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N
出力
ちょうど 2 回の操作後に A = B となることがあるならば Yes
を、そうでないならば No
を出力せよ。
入力例 1
5 1 3 5 5 2 3 1 5 2 5
出力例 1
Yes
以下のようにすることでちょうど 2 回の操作後に A = B とすることができます。
- i = 1 を選ぶ。A_1 の値と A_2 の値を入れ替える。A = (3, 1, 5, 5, 2) となる。
- i = 4 を選ぶ。A_4 の値と A_5 の値を入れ替える。A = (3, 1, 5, 2, 5) となる。
入力例 2
3 2 2 2 3 3 3
出力例 2
No
Problem Statement
You are given length-N sequences A = (A_1, A_2, \ldots, A_N) and B = (B_1, B_2, \ldots, B_N).
You will apply the following operation against the sequence A exactly twice.
- Choose an integer i with 1 \leq i < N, and swap the values of A_i and A_{i + 1}.
Determine if you can make A = B by operating exactly twice.
Constraints
- 2 \leq N \leq 2 \times 10^5
- 1 \leq A_i, B_i \leq N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N B_1 B_2 \ldots B_N
Output
Print Yes
if you can make A = B by operating exactly twice, and No
otherwise.
Sample Input 1
5 1 3 5 5 2 3 1 5 2 5
Sample Output 1
Yes
You can make A = B by operating exactly twice as follows:
- Choose i = 1. Swap the values of A_1 and A_2 to make A = (3, 1, 5, 5, 2).
- Choose i = 4. Swap the values of A_4 and A_5 to make A = (3, 1, 5, 2, 5).
Sample Input 2
3 2 2 2 3 3 3
Sample Output 2
No