0 or 1 Swap

AtCoder
IDabc135_b
Time2000ms
Memory256MB
Difficulty
We have a sequence $p$ = {$p_1,\ p_2,\ ...,\ p_N$} which is a permutation of {$1,\ 2,\ ...,\ N$}. You can perform the following operation at most once: choose integers $i$ and $j$ $(1 \leq i < j \leq N)$, and swap $p_i$ and $p_j$. Note that you can also choose not to perform it. Print `YES` if you can sort $p$ in ascending order in this way, and `NO` otherwise. ## Constraints * All values in input are integers. * $2 \leq N \leq 50$ * $p$ is a permutation of {$1,\ 2,\ ...,\ N$}. ## Input Input is given from Standard Input in the following format: $N$ $p_1$ $p_2$ $...$ $p_N$ [samples]
Samples
Input #1
5
5 2 3 4 1
Output #1
YES

You can sort $p$ in ascending order by swapping $p_1$ and $p_5$.
Input #2
5
2 4 3 5 1
Output #2
NO

In this case, swapping any two elements does not sort $p$ in ascending order.
Input #3
7
1 2 3 4 5 6 7
Output #3
YES

$p$ is already sorted in ascending order, so no operation is needed.
API Response (JSON)
{
  "problem": {
    "name": "0 or 1 Swap",
    "description": {
      "content": "We have a sequence $p$ = {$p_1,\\ p_2,\\ ...,\\ p_N$} which is a permutation of {$1,\\ 2,\\ ...,\\ N$}. You can perform the following operation at most once: choose integers $i$ and $j$ $(1 \\leq i < j \\leq ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc135_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have a sequence $p$ = {$p_1,\\ p_2,\\ ...,\\ p_N$} which is a permutation of {$1,\\ 2,\\ ...,\\ N$}.\nYou can perform the following operation at most once: choose integers $i$ and $j$ $(1 \\leq i < j \\leq ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments