Under construction

Still being built. Things may change

Formally, You Choose Three Integers

Time limit2sMemory limit512 MB

Summary
Decide whether array a can be turned into array b by repeatedly cyclically shifting an even-length contiguous block by an even number of positions.
Level

Hard8 of 10

Topics
Math, Array, Combinatorics, Sorting
Solved
No attempts yet

Problem

You are given two arrays aa and bb of the same length nn.

You may perform the following operation on aa zero or more times:

Choose a contiguous subarray of even length and cyclically shift it by an even number of positions. Formally, you choose three integers i,j,ki, j, k (0≤i<j<k≤n0 \leq i < j < k \leq n, j−ij - i is even, k−ik - i is even) and aa becomes a0:i+aj:k+ai:j+ak:na_{0:i} + a_{j:k} + a_{i:j} + a_{k:n}, where al:ra_{l:r} denotes a slice with Python indexing. Precisely, it contains the elements with indices in the range [l,r)[l,r) in 0-indexing and (l,r](l,r] in 1-indexing.

Is it possible to transform aa into bb?

Input

The first line contains a single integer nn (1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5), the length of aa and bb.

The second line contains nn integers aia_i (1≤ai≤n1 \leq a_i \leq n), the elements of aa.

The third line contains nn integers bib_i (1≤bi≤n1 \leq b_i \leq n), the elements of bb.

Output

Print 1 if it is possible to transform ss into tt, and 0 otherwise.

Examples3

  1. Example 1

    Input
    3
    1 2 1
    1 1 2
    
    Expected output
    0
    
  2. Example 2

    Input
    4
    1 2 3 4
    3 4 1 2
    
    Expected output
    1
    
  3. Example 3

    Input
    4
    1 2 3 4
    1 4 3 2
    
    Expected output
    0