We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Security
  3. Functions
  4. Security Involution

Security Involution

Problem
Submissions
Leaderboard
Discussions
  1. Prepare
  2. Security
  3. Functions
  4. Security Involution
Exit Full Screen View
  • Problem
  • Submissions
  • Leaderboard
  • Discussions

Consider a function where is any set, and is a bijection.

Now, if then is called an involution. In other words, a function is called an involution if

In this task you're given a permutation .

Determine whether is an involution or not.

Constraints

Input Format

There are lines in the input.
The first line contains a single positive integer .
The second line contains space separated integers, the values of , respectively.

Output Format

Output "YES" if is an involution. Otherwise, output "NO".

Sample Input

2
2 1

Sample Output

YES

Explanation

Since, and and .

Hence, is an involution.

  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy