Problem:


Score : 200 points

Problem Statement

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

Output

Print YES if you can sort p in ascending order in the way stated in the problem statement, and NO otherwise.

Sample Input 1

5
5 2 3 4 1

Sample Output 1

YES

You can sort p in ascending order by swapping p_1 and p_5.

Sample Input 2

5
2 4 3 5 1

Sample Output 2

NO

In this case, swapping any two elements does not sort p in ascending order.

Sample Input 3

7
1 2 3 4 5 6 7

Sample Output 3

YES

p is already sorted in ascending order, so no operation is needed.



Sample input:
5
5 2 3 4 1


Sample output:
YES

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(str,input().split()))
p_sort = sorted(p)
count = 0
for i,j in zip(p,p_sort):
  if p[i] != p[j]:
    count += 1
if count == 0 or count == 2:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
def main():
    a, b = map(int, input().split())
    diff = abs(max(b, a) - min(a, b))
    if diff % 2 != 0:
        print("IMPOSSIBLE")
    else:
        bigger = max(a, b)
        ans = bigger - (diff//2)
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N=int(input())
l=list(map(int,input().split()))
a=l.sort()
count=0
for i in range(0,len(l)):
  if l[i]==a[i]:
    count+=1
if count >= N-2:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
N=list(input())
for i,j in range(N):
  N[i],N[j]=N[j],N[i]
  if N==N.sort():
    print("YES")
    break
else:
  print("NO")

Submission status: Runtime Error

Solution code:
N=list(input())
for i,j in range(N):
  N2=N[i],N[j]=N[j],N[i]
  if N2==N.sort():
    print("YES")
    break
else:
  print("NO")

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int(input().split())))
m=sorted(l)
cnt=0
for i in range(n):
  if l[i]!=m[i]:
    cnt+=1
  if cnt>=3:
    print("NO")
else:print("YES")

Submission status: Runtime Error

Solution code:
=int(input())
P=list(map(int,input().split()))
count=0
if P[0]!=1:
    count=count+1
elif P[N-1
       ]!=N:
    count=count+1
for i in range(N-1):
    if P[i]+1!=P[i+1]:
        count=count+1
if count<5:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
n = int(input())
plst = list(map(int,input().split()))
plst_sort = sorted(plst)
cnt = 0
for i in range(N):
    if plst[i] != plst_sort[i]:
        cnt += 1
if cnt == 2 or cnt == 0:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
n=int(input())
a+=list(map(int,input().split()))
c=0
for i in range(n-1):
  if a[i]!=i+1:
    c+=1
print("YES" if c<3 else "NO")

Submission status: Runtime Error

Solution code:
n=int(input())
a+=list(map(int,input().split()))
for i in range(n-1):
  if a[i]!=i+1:
    c+=1
print("YES" if c<3 else "NO")

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
c=0
idx = list()
for i in range(n-1):
  if a[i]>a[i+1]:
    idx.append(i)
    c+=1
print("YES" if c<2 or c==2 and a[idx[0]-1]<a[idx[1]+1]<a[idx[0]+1] and a[idx[1]]<a[idx[0]]<a[idx[1]+2] else "NO")

Submission status: Runtime Error

Solution code:
input()
p = list(map(int, input().split()))
for i, p_ in enumerate(p):
  a += (p_ != (i + 1))
print('YNEOS'[a > 2 :: 2])

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
def check(L):
  for i in range(1, len(L)):
    if L[i] < L[i - 1]:
      return False
  return True
for i in range(n):
  for j in range(i + 1, n):
    if check(A[0:i] + [A[j]] + A[i+1:j] + [A[i]] + A[j+1:]):
      print('YES')
      return
print('NO')

Submission status: Runtime Error

Solution code:
    #include<bits/stdc++.h>
    using namespace std;
     
    int n,a;
     
    int main(){
      cin>>n;
      vector<int>v1(n,0);
      vector<int>v2(n,0);
      for (int i=0; i<n; i++){
        cin>>v1[i];
        v2[i]=i+1;
      }
      for (int i=0; i<n; i++){
        if (v1[i]!=v2[i]){
          a++;
        }
      }
      if (a<3){
        cout<<"YES";
      }
      else{
        cout<<"NO";
      }
    }

Submission status: Runtime Error

Solution code:
n = int(input())
s = map(int, input().split())

count = 0
for i in range(n-1):
  if s[i] > s[i+1]:
    count += 1

print("YES" if count < 3 else "NO")

Submission status: Runtime Error

Solution code:
n = int(input())
s = input()

count = 0
for i in range(n-1):
  if int(s[i]) > int(s[i+1]):
    count += 1

print("YES" if count < 3 else "NO")

Submission status: Runtime Error

Solution code:
# import itertools
# import math

import sys
input = sys.stdin.readline


def solve(N, P):
    NN = sorted(N)
    cnt = 0
    for l1, l2 in zip(N, NN):
        if l1 != l2:
            cnt += 1

    return 'YES' if cnt <= 2 else 'NO'


N = int(input())
# S = input()
# A, B = map(int, input().split())
P = list(map(int, input().split()))

# P = []
# S = []
# for i in range(N):
#     pp, ss = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(solve(N, P))

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
m=sum([i!=l[i] for i in range(1,n+1)])
print("YES" if m==0 or m==2 else "NO")

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int, input().split()))
q = sorted(p.copy())
counter = 0

for i in range(N):
    if p[i] != q[i]:
        counter += 1

if counter == 2 or counter == 0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int, input().split()))
q = sorted(p.copy())

counter = 0

for i in range(N):
    if p[i] != q[i]:
        counter += 1

if counter == 2:
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
N = int(input())
P = list(map(int, input().split()))

ans = 0

for i in range(n):
  if P[i] != i + 1:
    ans += 1
if ans <= 2:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
n=int(input())
p=[int(x) for x in input().split()]
pp=[int(x+1) for x in range(n)]

count=0

for i in range(n):
    if p[i]!=pp[i]:
        count+=1

if count <= 2
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(1, N+1):
    if i == p[i]:
        c += 1
if c == 0 or c == 2:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
total = int(input())
sort_list = list(map(int, input().split()))

total_count = 0
for x in range(0, total+1):
  s_1 = sort_list[x]
  counter = 0
  for y in range(x+1, total+1):
    if s_1 > y:
      counter += 1
      total_count += 1
  if counter > 1:
    print("NO")
    break

if total_count <= 1:
  print("OK")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n):
  if p[i]=i+1:
    cnt += 1
if cnt < n-2:
  print("No")
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
N = int(input())
P = list(map(int(),input().split()))
cnt = 0
for i in range(N):
    if P[i]!=i+1:
        cnt+=1
if cnt<=2:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
count=0
for i in range(1,6):
    if l[i-1]!=i:
        count+=1
print("YES" if count==0 or count==2 else "NO")

Submission status: Runtime Error

Solution code:
def main(li):
    count = 0
    for i in range(len(li)):
        if li[i] != i + 1:
            count += 1
    if count == 2 or count == 0:
      return True
   	else:
      return False


if __name__ == '__main__':
    li = list(map(int, input().split()))
    if main(li):
        print('YES')
    else:
        print('NO')

Submission status: Runtime Error

Solution code:
N = int(input())
li = list(map(int, input().split()))
tmp = list()
ans = 'Yes'
for i in range(1, N):
    if li[i-1] > li[i]:
        tmp.append(li[i-1])
if len(tmp) != 2:
    ans == 'No'
else:
    t = li[tmp[0]]
    li[li.index(tmp[0])] = li[li.index(tmp[1])+1]
    li[li.index(tmp[1])+1] = t
    for i in range(N):
        if li[i-1] > li[i]:
            ans = 'No'
print(ans)

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    p = [*map(int, input().split())]

    c = 0
    for i in range(n):
        if (i + 1) != p[i]:
            c += 1
    if c <= 2:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input())
lst=list(map(int,input().split()))
cnt=0
for i in range(5):
  if lst[i]!=i+1:
    cnt+=1
print("YES" if cnt<=2 else "NO")

Submission status: Runtime Error

Solution code:
n=int(input())
P=list(map(int,input().split()))
t=len(P)
m=0
for i in range(t):
  if P[i]!=P.index(i+1)+1:
    m+=1
if m=2:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:

N = int(input())
p_list = list(map(int,input().split()))

if sorted(p_list) == p_list:
    print("YES")
    sys.exit()

sum = 0
    
for i,j in zip(p_list,sorted(p_list)):
    if i != j:
        sum += 1

if sum == 2:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
N=int(input())
p=list(map(int,input().split()))
false_num=0
for i in range(N-1):
    if p[i]+1==p[i+1]:
        continue
    else:
        false_num+=1

if false_num=0 or 2:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
n = input()
p = list(map(int, input().split()))

dif = []
for i in range(1,n+1):
  if p[i-1] != i:
    dif.append(i)

if len(dif) == 0 or len(dif) == 2:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
n = input()
p = [int(input()) for i in range(3)]

dif = []
for i in range(1,n+1):
  if p[i-1] != i:
    dif.append(1)

if len(dif) == 0 or len(dif) == 2:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
n = input()
p = [int(input()) for i in range(3)]

dif = []
for i in range(n):
  if p[i]!= i:
    dif.append(1)

if len(dif) == 0 or len(dif) == 2:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
 N, *p = map(int, open(0).read().split())

if sum(p[i] != i + 1 for i in range(N)) <= 2:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
n=int(input())
p=[int(i) for i in input().split()]
n1=[i for i in range(1,n+1)]
for i in n1:
  for k in n1:
    n1=n1.replace(i,k)
    if n1==p:
      print('YES')
      exit()
else:
  print('NO')

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int, input().split()))
for i in range(N):
    for j in range(i + 1, N):
        if p[j - 1] < p[i] < p[j + 1] and p[i - 1] < p[j] < p[i + 1]:
            print("YES")
            exit()
        else:
            continue
print("NO")

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int, input().split()))
for i in range(N):
    for j in range(i + 1, N):
        if p[j - 1] < p[i] < p[j + 1] and p[i - 1] < p[j] < p[i + 1]:
            print("YES")
        else:
            continue
print("NO")

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int, input().split()))
for i in range(N):
    for j in range(i + 1, N):
        if p[j - 1] < p[i] < p[j + 1] and p[i - 1] < p[j] < p[i + 1]:
            print("YES")
        else:
            print("NO")

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
cnt = 0

for i, j in enumerate(A)
  if i + 1 != j:
    cnt +=1
if cnt <= 2:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
n = int(input())
s = list(map(int, input().split()))
l = sort(s)
cnt = 0
for i in range(len(s)):
    if s[i] != l[i]:
        cnt += 1

print('NO' if cnt > 2 else 'YES')

Submission status: Runtime Error

Solution code:
n=int(input())
seqs =list(map(int,input().split()))
count = 0
for i in range(1,n+1):
    if i != seqs[i]:
        count += 1
if count <= 2:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
N = int(input())
li_p = list(map(int, input().split()))
li = set(li_p)
li_a = []
li_b = []
for i in range(N):
  if li_p[i] != li[i]:
    li_a.append(li_p[i])
    li_b.append(li[i])
    if len(li_a) == 2:
      if li_a[0] == li_b[1]:
        print("YES")
      else:
        print("NO")
    elif len(li_a) > 2:
      print("NO")
    elif len(li_a) == 0:
      print("YES")

Submission status: Runtime Error

Solution code:
n = int(input())
p = list(map(int, input().split()))

swap = False
for i in range(n):
  if p[i] != i+1:
    if swap == False and p[p[i]-1] == i+1:
      swap = True
      p[p[i]-1] = p[i]
    else:
      print('NO')
      sys.exit()

print('YES')

Submission status: Runtime Error

Solution code:
n,d=map(int,input().split())
a=(2*d)+1
if n%a==0:
  print(int(n/a))
else:
  print((n//a)+1)

Submission status: Runtime Error

Solution code:
n,d=map(int,input().split())
a=(2*d)+1
if n%a==0:
  print(int(n/a))
else:
  print(int(n//a)+1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))

ch = 1
for i in range(n):
    if(a[i] != i+1):
        if(a[a[i]]!=i+1):
            ch = 0
            
if(ch == 0):
    print("NO")
else:
    print("YES")

Submission status: Runtime Error

Solution code:
N = int(input())
p = [int(i) for i in input().split()]
check = 0
pp = sorted(p)
for i in range(N):
    if p[i] != p[i + 1]:
        check += 1

if check == 2:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(N):
  if p[i] != i+1:
    count ++
if count >=3:
  print("NO")
else:
  print("YES")

Submission status: Runtime Error

Solution code:
n = int(input())
arr = []
c=0
for i in range(0,n):
	if arr[i]!= i+1 :
		c+=1
          
if c > 2:
	print('NO')
else:
	print('YES')

Submission status: Runtime Error

Solution code:
N = input()
P = list(map(int, input().split()))
sort_P = sorted(P)
new_P = []
for idx, p in enumerate(P):
    new_P.append(sort_P[idx] - p)
new_new_P = set(new_P)
new_new_P.remove(0)
if len(new_new_P) > 2:
    print("NO")
else:
    print("YES")

Submission status: Runtime Error

Solution code:
a=int(input())
b=list(map(int,input().split()))
count=0
for i,j in enumerte(a,1):
  if i != j:
    count +=1

if count <= 2:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
n = int(input())
p = list(map(int,input().split()))
q = sort(p)
for i in range(1,n):
    if p[i]  != q[i]:
        a += 1
if a  <= 2:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
n=int(input())
p=list(map(int,input().split()))
count=0
for i in range:
    if p[i]==i+1:
        count+=1

if count==2 or count==0:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int,input().split()))

o=1
e=0
for i in p:
  if i != o:
    e +=1
  o +=1
if e=0 or e=2:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int,input().split()))

o=1
e=0
for i in range(N):
  if i != o:
    o +=1
    e  +=1

if e=0 or e=2:
  print(YES)
else:
  print(NO)

Submission status: Runtime Error

Solution code:
N=int(input())
p=list(map(int,input().split()))
co=0
ans='YES'
for i in range(N):
  if p[i]!=i+1:
    co+=1
if co<=1:
  break
else:
  ans='NO'
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
P = [map(int,input().split())]
C = sort(P)
D = ' '
if P == C:
    print('YES')
    break
elif P != C:
for i in range(N):
  for a in range(N):
    P[i] = P[a]
    if P == C:
      D = 'YES'
      print(D)
      break
    else:
      D = 'NO'
print(D)

Submission status: Runtime Error

Solution code:
N = int(input())
P = [map(int,input().split())]
C = sort(P)
D = ' '
if P == C:
    print('YES')
    break
elif P != C
for i in range(N):
  for a in range(N):
    P[i] = P[a]
    if P == C:
      D = 'YES'
      print(D)
      break
    else:
      D = 'NO'
print(D)

Submission status: Runtime Error

Solution code:
#135 0 or 1 Swap
N=int(input())
P=map(int,input().split())
c=0
for i in range(1,N):
    if P[i-1]>P[i]:
        c+=1
print('YES' if c==0 or c==2 else 'NO')

Submission status: Runtime Error

Solution code:
n = 7
a_list = list(map(int, input().split()))
false_count = 0
for index in range(a_list):
  if index + 1 != a_list[index]:
    false_count += 1
if false_count in [0, 2]:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split())

ans = 0
for i in range(len(a)):
  if i != a[i]-1:
    ans += 1
    
if ans <= 2:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split())

ans = 0
for i in a:
  if i != a[i]-1:
    ans += 1
    
if ans <= 2:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split())

ans = 0
for i in a:
  if i != a[i]:
    ans += 1
    
if ans <= 2:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
n,*p = map(int,open().read().split())
ans = 0
for i in range(n):
    if i+1 != p[i]:
        ans += 1
print('YES' if ans == 2 else 'NO')

Submission status: Runtime Error

Solution code:
n,*p = map(int,open('abc135.txt').read().split())
ans = 0
for i in range(n):
    if i+1 != p[i]:
        if i+1 == p[p[i]-1]:
            ans += 1

print('YES' if ans == 0 or 2 else 'NO')

Submission status: Runtime Error

Solution code:
n,*p = map(int,open('abc135.txt').read().split())
ans = 0
for i in range(n):
    if i+1 != p[i]:
        if i+1 == p[p[i]-1]:
            ans += 1

print('Yes' if ans == 0 or 2 else 'No')

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<int> p(n);
	rep(i,n) cin>>p[i],p[i]--;
	int cnt=0;
	rep(i,n)if(p[i]!=i)cnt++;
	cout<<(cnt==2?"YES":"NO")<<endl;
	return 0;
}

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int,input().split()))
count = 0
for i in range(N-1):
	if  p[i + 1] - p[i] != 1:
      count += 1
if count <= 2:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
N=int(input())
list1=list(map(int,input().split()))
list2=[]
for i in range(1,N):
  list2.append(i)
a=N
for j in range(0,N-1):
  if list1[j]==list[j]:
    a=a-1
if a>2:
  print("NO")
else:
  print("YES")

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int, input().split()))

q = 0
for i in range(len(p)):
  if A[i] != i+1:
    q += 1

if q <= 2:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
N=int(inpuit())

p=list(map(int,input().split()))
sort=list(range(1,N+1))
count=[p[i]==sort[i] for i in range(N)].count(True)
if count > 2:
    print("NO")
else:
    print("YES")

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int,input().split()))

ans = 0

for i in range(N):
	if p[N] == (N+1) :
		ans += 1

if ans == N or N-2:
	print('YES')
else :
	print('NO')

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int,input().split()))
 
ans = 0
q =p.sorted(0
 
for i in range(N):
	if p[i] != q[i] :
		ans += 1
 
if ans == 0:
	print('Yes')
elif ans == 2:
  	print('Yes')
else :
	print('No')

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int,input().split()))
 
ans = 0
 
for i in range(N+1):
	if p[i] != (i+1) :
		ans += 1
 
if ans == 0:
	print('Yes')
elif ans == 2:
  	print('Yes')
else :
	print('No')

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int,input().split()))

ans = 0

for i in range(N-1):
	if p[i] == i :
		ans += 1

if ans == N or N-2:
	print('Yes')
else :
	priint('No')

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int,input().split()))

ans = 0

for i in range(N):
	if p[i] == i :
		ans += 1

if ans == N or N-2:
	print('Yes')
else :
	priint('No')

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


def main():
    n = I()
    num = LI()
    for i in range(n):
        for j in range(n):
            tmp[i], tmp[j] = tmp[j], tmp[i]
            if tmp == sorted(num):
                return 'YES'
    return 'NO'


print(main())

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


def main():
    n = I()
    num = LI()



    for i in range(n):
        for j in range(n):
            tmp = num.copy()
            tmp[i], tmp[j] = tmp[j], tmp[i]
            if tmp == sorted(num):
                return 'YES'
    return 'NO'



print(main())

Submission status: Runtime Error

Solution code:
res = 0
a_sort = sorted(a)
 
for i in range(n):
    if a_sort[i] == a[i]:
        res += 1
 
if res >= n - 2:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
res = 0
a_sort = sorted(a)

for i in range(n):
    if a_sort[i] != a[i]:
        res += 1

if res > 2:
    print("NO")
else:
    print("YES")

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int count= 0;
  
  vector<int> p(N);
  for (int i=1 ;i < N ;i++) {
    cin >> p[i];
    if (p[i-1]+1 != p[i]) {
      count++;
      }
    }
  
  if (count == 0 || count ==2){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int count= 0;
  
  vector<int> p(N);
  for (int i=1 ;i < N ;i++) {
    cin >> p[i];
    if (p[i-1]+1 != p[i+1]) {
      count++;
      }
    }
  
  if (count == 0 || count ==2){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}

Submission status: Runtime Error

Solution code:
n = int(input())
li = list(map(int,input()))
count = 0
for i in range(n):
  if(li[i] != i+1):
    count += 1
if(count == 0 or count == 2):
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().strip().split()))
count = 0
for i in range(N):
  if not i == A[i]:
    count+=1
    if A[i]+A[N-i]==N+1:
      continue
    if count >=3:
      break
      print("NO")
    print("YES")

Submission status: Runtime Error

Solution code:
n=int(input())
model=[]
for i in range(n):
  model.append(i+1)
p=list(map(int,input().split()))
cnt=0
for j in p:
  if j != model[j]:
    cnt+=1
if cnt=<2:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
N=int(input())
num = list(map(int,input().split()))

num_sort = num.sorted()
ans = 0

for i in range(N):
  if num[i] == num_sorted[i]:
    continue
  else:
    ans += 1
    
if ans <= 2:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
n = int(input())
p = list(map(int, input().split()))
sorted_p = sorted(p)
cnt = 0
for a, b in p, sorted_p:
    if a != b:
        cnt += 1
if cnt > 2:
    print("NO")
else:
    print("YES")

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int,input().split()))

q = []
for x in range(N):
    q.append(x+1)

i = 0
c = 0
ans = "NO"
while(i < N):
    if p[i] != q[i]:
        c += 1
    if c > 2:
        break
    i += 1

if (c == 2) && (c == 0):
    ans = "YES"

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
r=list(map(int,input().split()))
a=sorted(r)

r="".join(r)
a="".join(a)

count=0
i=0
while i<len(r):
  if r[i]!=r[i]:count+=1
    
print("Yes" if count<=2 else "No")

Submission status: Runtime Error

Solution code:
cnt = 0
n = int(input())
p = list(map(int, input().split())
for i in range(n):
  if int(i) + 1 != p[i] :
    cnt += 1
    if cnt >= 3:
      break
if cnt <= 2 :
  print("YES")
else :
   print("NO")

Submission status: Runtime Error

Solution code:
cnt = 0
n = int(input())
p = list(map(int, input().split())
for i in range(1, n + 1):
  if int(i) != p[i - 1] :
    cnt += 1
    if cnt >= 2:
      break
if cnt <= 1 :
  print("YES")
else :
   print("NO")

Submission status: Runtime Error

Solution code:
cnt = 0
n = int(input())
for i in range(1, n + 1):
  p = int(input())
  if int(i) != p :
    cnt += 1
    if cnt >= 2:
      break
if cnt <= 1 :
  print("YES")
else :
   print("NO")

Submission status: Runtime Error

Solution code:
cnt = 0
n = int(input())
for i int range(1, n + 1):
  p = int(input())
  if int(i) != p :
    cnt += 1
    if cnt >= 2:
      break
if cnt <= 1 :
  print("YES")
else :
   print("NO")

Submission status: Runtime Error

Solution code:
cnt = 0
n = int(input())
for i int rangr(1, n + 1):
  p = int(input())
  if int(i) != p :
    cnt += 1
    if cnt >= 2:
      break
if cnt <= 1 :
  print("YES")
else :
   print("NO")

Submission status: Runtime Error

Solution code:
cnt = 0
n = int(input())
for i int rangr(1, n + 1):
  p = map(int, input().split())
  if int(i) != p :
    cnt += 1
    if cnt >= 2:
      break
if cnt <= 1 :
  print("YES")
else :
   print("NO")

Submission status: Runtime Error

Solution code:
cnt = 0
n = int(input())
for i int rangr(1, n + 1):
  p = map(int, input().split()
  if int(i) != p :
    cnt += 1
    if cnt >= 2:
      break
if cnt <= 1 :
  print("YES")
else :
   print("NO")

Submission status: Runtime Error

Solution code:
cnt = 0
n = int(input())
for i int rangr(1, n + 1):
  p = map(int, input().split()
  if int(i) != p :
    cnt += 1
    if cnt >= 2:
      break
if cnt <= 1 :
  print("YES")
else :
   print("NO)

Submission status: Runtime Error

Solution code:
N = int(input())
lst = list(map(int, input().split()))
cnt = 0
for i in lst:
    if lst[i]-1 != i:
        cnt += 1
if cnt > 2:
    print('NO')
else:
    print('YES')

Submission status: Runtime Error

Solution code:
n = int(input())
p = list(map(int,input().split()))
N = list(range(1,n+1))
for i in N:
  if N[i-1] != p[i-1]:
    j = i
    break
if N[p[i-1]] == p[i-1]:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
n = int(input())
p = list(map(int,input().split()))
N = list(range(1,n+1))
for i in N:
  if N[i-1] != p[i-1]:
    break
if N[p[i-1]] == p[i-1]:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
n = int(input())
p = list(map(int,input().split()))
N = list(range(1,n+1))
for i in N:
  if N[i-1] != p[i-1]:
    break
if N[i-1] == p[N[i-1]]:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
n=int(input())
p=list(map(int, input().split()))
ans=list(range(n) + 1)

ans_mix=[]
is_possible = False

if p==ans:
    is_possible = True

for i in range(0, n-1):
    for j in range(1, n):
        a=ans.copy()
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if a==p:
            is_possible = True

if is_possible:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
n=int(input())
p=list(map(int, input().split()))
ans=list(range(N) + 1)

ans_mix=[]
is_possible = False
for i in range(0, n-1):
    for j in range(1, n):
        a=ans.copy()
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if a==p:
            is_possible = True
            
if is_possible:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
N=int(input())
p=np.array(list(map(int, input().split())))
q=np.arange(N)+1

temp=np.sum(p==q)
if temp==0 or temp==2:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
n = int(input())
p = map(int, input().split())

for i in range(1, n+1):
  if p[i-1] != i:
    count += 1
    
if count == 0 or count == 2:
  print("YES")
else:
  print("No")

Submission status: Runtime Error

Solution code:

N = int(input())
pi = list(map(int, input().split()))
#print(pi)

pis = sorted(pi)
#print(pis)

count = 0

for i in range(5):
    if pi[i] != pis [i]:
        count += 1

if count <= 2:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
totl=0
for i in range(n-1):
  if a[i]+a[i+1]<b[i]:
    totl+=a[i]+a[i+1]
    a[i]=0
    a[i+1]=0
  else:
    totl+=b[i]
    if a[i]<b[i]:
      a[i]=0
      a[i+1]-=b[i]-a[i]
    else:
      a[i]-=b[i]
    

print(totl)

Submission status: Runtime Error

Solution code:
n=int(input())
p=list(map(int,input().split()))
q=[]
for i in range(n-1):
  q.append(p[i+1]-p[i])
cnt=q.count(1)
if cnt=>3:
  print('NO')
else:
  print('YES')

Submission status: Runtime Error

Solution code:
5
2 4 3 5 15
2 4 3 5 1