#K41162. Are Arrays Equal?

    ID: 26805 Type: Default 1000ms 256MiB

Are Arrays Equal?

Are Arrays Equal?

You are given two arrays a and b of integers, both containing n elements. Your task is to determine if array a can be rearranged (permuted) so that it becomes exactly the same as array b.

In other words, decide whether the two arrays are equal as multisets. Formally, you need to check if:

[ sorted(a) = sorted(b) ]

If the condition holds, output YES. Otherwise, output NO.

Input/Output format: Your solution should read input from standard input and write output to standard output.

inputFormat

The input consists of three lines:

  • The first line contains an integer n \( (1 \leq n \leq 10^5) \) representing the number of elements in each of the arrays.
  • The second line contains n space-separated integers, representing the elements of array a.
  • The third line contains n space-separated integers, representing the elements of array b.

outputFormat

Output a single line containing YES if array a can be rearranged to match array b, and NO otherwise.

## sample
5
1 2 3 4 5
5 4 3 2 1
YES