#K86597. Permutation Check

    ID: 36899 Type: Default 1000ms 256MiB

Permutation Check

Permutation Check

You are given an integer \( n \) and a list of \( n \) integers. Your task is to determine whether the list is a permutation of the first \( n \) natural numbers, i.e. whether it contains all the integers from 1 to \( n \) exactly once.

A permutation means that after sorting the list, it should be equal to \( [1, 2, \ldots, n] \). For example, if \( n = 5 \) and the list is [3, 1, 2, 5, 4], then the answer is YES because it is a valid permutation. Otherwise, the answer is NO.

Input/Output specifications:

  • Input: Read from standard input (stdin).
  • Output: Write your answer to standard output (stdout).

inputFormat

The input consists of two lines:

  • The first line contains an integer \( n \) (\( 1 \le n \le 10^5 \)), representing the number of elements.
  • The second line contains \( n \) space-separated integers.

outputFormat

Output a single line containing YES if the list is a permutation of the first \( n \) natural numbers, and NO otherwise.

## sample
5
3 1 2 5 4
YES