Triple Shift

AtCoder
IDarc136_b
Time2000ms
Memory256MB
Difficulty
You are given integer sequences of length $N$ each: $A=(A_1,A_2,\cdots,A_N)$ and $B=(B_1,B_2,\cdots,B_N)$. You can repeat the following operation any number of times. * Choose an integer $i$ ($1 \leq i \leq N-2$) and let $x,y,z$ be the current values of $A_i,A_{i+1},A_{i+2}$, respectively. Then, replace the values of $A_i,A_{i+1},A_{i+2}$ with $z,x,y$, respectively. Determine whether it is possible to make $A$ equal $B$. ## Constraints * $3 \leq N \leq 5000$ * $1 \leq A_i,B_i \leq 5000$ * All values in input are integers. ## Input Input is given from Standard Input in the following format: $N$ $A_1$ $A_2$ $\cdots$ $A_N$ $B_1$ $B_2$ $\cdots$ $B_N$ [samples]
Samples
Input #1
4
3 1 4 5
4 1 5 3
Output #1
Yes

We should do the following.

*   Initially, we have $A=(3,1,4,5)$.
*   Do the operation with $i=1$, making $A=(4,3,1,5)$.
*   Do the operation with $i=2$, making $A=(4,5,3,1)$.
*   Do the operation with $i=2$, making $A=(4,1,5,3)$.
Input #2
3
1 2 2
2 1 2
Output #2
Yes
Input #3
3
1 2 3
2 3 4
Output #3
No
API Response (JSON)
{
  "problem": {
    "name": "Triple Shift",
    "description": {
      "content": "You are given integer sequences of length $N$ each: $A=(A_1,A_2,\\cdots,A_N)$ and $B=(B_1,B_2,\\cdots,B_N)$. You can repeat the following operation any number of times. *   Choose an integer $i$ ($1 \\l",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc136_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given integer sequences of length $N$ each: $A=(A_1,A_2,\\cdots,A_N)$ and $B=(B_1,B_2,\\cdots,B_N)$.\nYou can repeat the following operation any number of times.\n\n*   Choose an integer $i$ ($1 \\l...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments