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())
count = 0
intput = int(input().split())
for i in Range(n):
    if input[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().split()))
for i in range(n):
  for j in range(i+1,n):
    a[i],a[j]=a[j],a[i]
    for k in range(n-1):
      if a[k]>a[k+1]:
        a[i],a[j]=a[j],a[i]
        break
    else:
      i,j=n,n
if i==n:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
def main37():
    num = int(input())
    data = input().split()
    retu = []
    for i in range(num):
        retu.append(int(data[i]))
    kari = list(retu)
    kari.sort()
    kosu = 0
    for i in range(num):
        if retu[i] != kosu[i]:
            kosu = kosu + 1
    if kosu == 2 or kosu == 0:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main37()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
          	return -1
    return 1

f=0
for i in range(n):
    for j in range(i):
      	tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
  	print('YES')
else:
    print('NO')

Submission status: Runtime Error

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

def shou(a):
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
          	return -1
    return 1

f=0
for i in range(n):
    for j in range(i):
      	tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
        if shou(a)==1:
            f=1
        tmp=a[i]
        a[i]=a[j]
        a[j]=tmp
if f>0:
  	print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
N = int(i)
inp = [int(i) for i in raw_input().split()]

sorted_inp = sorted(inp)

diff = 0

for i in range(len(inp)):
  if inp[i] != sorted_inp[i]:
    diff += 1

if diff ==  or diff==2:
  print "YES"
else:
  print "NO"

Submission status: Runtime Error

Solution code:
inp = [int(i) for i in raw_input().split()]

sorted_inp = sorted(inp)

diff = 0

for i in range(len(inp)):
  if inp[i] != sorted_inp[i]:
    diff += 1

if diff ==  or diff==2:
  print "YES"
else:
  print "NO"

Submission status: Runtime Error

Solution code:
inp = [int(i) for i in raw_input().split()]

sorted_inp = sorted(inp)

diff = 0

for i in range(len(inp)):
	if inp[i] != sorted_inp[i]:
      diff += 1

if diff ==  or diff==2:
  print "YES"
else:
  print "NO"

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def check(a):
  for i in range(1,len(n)):
    if a[i-1]>a[i]:
      return False
  return True
n=int(input())
a=list(map(int,input().split()))
if check(a):
  print('YES')
  exit()
for i in range(n):
  for j in range(n):
    if i==j:
      continue
    a[i],a[j]=a[j],a[i]
    if check(a):
      print('YES')
      exit()
    a[i],a[j]=a[j],a[i]
print('NO')

Submission status: Runtime Error

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

if outoforder <=1:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
7
1 2 3 4 5 6 7

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
p = input()
p = p.split(' ')
p = [int(p[i]) for i in range(len(p))]
a = p
for i in range(len(p)-1):
    if(p[i+1]!=p[i]+1):
        if p[i+1]>p[i]:
            pos = p.index(p[i]+1)
            p[i+1], p[pos] = p[pos], p[i+1]
        if p[i+1]<p[i]:
            pos = p.index(p[i+1]-1)
            p[i], p[pos] = p[pos], p[i]
        break
if p!=sorted(a):
    print('NO')
else:
    print('YES')

Submission status: Runtime Error

Solution code:
n = int(input())
p = input()
p = p.split(' ')
p = [int(p[i]) for i in range(len(p))]
for i in range(len(p)-1):
    if(p[i+1]!=p[i]+1):
        if p[i+1]>p[i]:
            pos = p.index(p[i]+1)
            p[i+1], p[pos] = p[pos], p[i+1]
        if p[i+1]<p[i]:
            pos = p.index(p[i+1]-1)
            p[i], p[pos] = p[pos], p[i]
        break
k = 0
for i in range(len(p)-1):
    if p[i+1]!=p[i]+1:
        k = k+1
if k == 0:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
N = int(input())
P = [int(i) for i in input().split()]

permulated = len(1 for k, p in enumerate(P, 1) if p != k)
print('YES' if permulated <= 2 else 'NO')

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]!=i+1
      count=count+1
if count<2:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
x=int(input())
a=list(map(int,input().split()))
c=0
f=1
for i in range(1,a+1):
  if(a[i-1]==i):
    c+=1
  if(c>2):
    print("NO")
    f=0
    break
if(f==1):
  print("YES")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
k = 0
lis = list(range(1, N+1))
for i in range(1, N+1):
  a = int(input())
  if a == lis[i]:
    k += 10
  else:
    k += 0
    
if k >= 10 * (N-2):
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
n=int(input())
P=map(int,input().split())
p=list(P)
d=[]
D=[]
s=0

for i in range(0,n-1):
    if s==3:
        print('NO')
        break
    elif p[i]<=p[i+1]:
        continue
    else:
        if s==0:
            D.append(p[i])
            d.append(i)
            s=1
        else:
            D.append(p[i+1])
            d.append(i+1)
            s=s+1


if s==0 or s==1:
    print('YES')
elif (n==d[1]) and p[d[1]-1]<=D[0]:
    print('YES')
elif (0==d[0]) and D[1]<=p[d[0]+1]:
    print('YES')
elif (p[d[0]-1]<=D[1]<=p[d[0]+1]) and (p[d[1]-1]<=D[0]<=p[d[1]+1]):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
N = int(input())
k = 10
lis = list(range(1, N+1))
for i in range(1, N+1):
  a = int(input())
  if a == lis[i]:
    k += 10
  else:
    k += 0
    
if k >= 10 * (N-2):
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
cnt = 0
for i in range(len(a)):
    if l == sorted(l):
        break
    for j in range(len(a)-1, i, -1):
        if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]
        cnt += 1

print("YES" if cnt < 2 else "NO")

Submission status: Runtime Error

Solution code:
def check_list_sorted(N, p_list):
    cnt = 0
    for i in range(N-1):
        if p_list[i] < p_list[i+1]:
            cnt += 1
    if cnt == N-1:
        return True
    else:
        return False

def swap_list(N, p_list):
    for i in range(N-1):
        if p_list[i] > p_list[i+1]:
            if i == 0 and p_list[i+1] == 1:
                idx = 1
            else:
                idx = p_list.index(p_list[i+1]-1)
            p_list[i], p_list[idx] = p_list[idx], p_list[i]
            break
    return p_list

N = int(input())
p_list = list(map(int, input().split()))
if check_list_sorted(N, p_list):
    print("YES")
else:
    new_p_list = swap_list(N, p_list)
    if check_list_sorted(N, new_p_list):
        print("YES")
    else:
        print("NO")

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().rstrip().split()))
f=1
a=0
y=0
for i in range(1,n+1):
    if(l[i]==i):
        f=1
    else:
        a=l[i]
        if((l[a]==i)and(y==0)):
            l[a]=a
            l[i]=i
            f=1
            y=1
        else:
            f=0
            break
if(f==1):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
def check_list_sorted(N, p_list):
    cnt = 0
    for i in range(N-1):
        if p_list[i] < p_list[i+1]:
            cnt += 1
    if cnt == N-1:
        return True
    else:
        return False

def swap_list(N, p_list):
    for i in range(N-1):
        if p_list[i] > p_list[i+1]:
            if i == 0 and N == 2:
                idx = 1
            else:
                idx = p_list.index(p_list[i+1]-1)
            p_list[i], p_list[idx] = p_list[idx], p_list[i]
            break
    return p_list

N = int(input())
p_list = list(map(int, input().split()))
if check_list_sorted(N, p_list):
    print("YES")
else:
    new_p_list = swap_list(N, p_list)
    if check_list_sorted(N, new_p_list):
        print("YES")
    else:
        print("NO")

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().rstrip().split()))
f=1
a=0
y=0
for i in range(1,n+1):
    if(l[i]==i):
        f=1
    elif(l[i]!=i):
        a=l[i]
        if((l[a]==i)and(y==0)):
            l[a]=a
            l[i]=i
            f=1
            y=1
        else:
            f=0
            break
    else:
        pass
if(f==1):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
def check_list_sorted(N, p_list):
    cnt = 0
    for i in range(N-1):
        if p_list[i] < p_list[i+1]:
            cnt += 1
    if cnt == N-1:
        return True
    else:
        return False

def swap_list(N, p_list):
    for i in range(N-1):
        if p_list[i] > p_list[i+1]:
            if i != 0 and N != 2:
                idx = p_list.index(p_list[i+1]-1)
            else:
                idx = 1
            p_list[i], p_list[idx] = p_list[idx], p_list[i]
            break
    return p_list

N = int(input())
p_list = list(map(int, input().split()))
if check_list_sorted(N, p_list):
    print("YES")
else:
    new_p_list = swap_list(N, p_list)
    if check_list_sorted(N, new_p_list):
        print("YES")
    else:
        print("NO")

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().rstrip().split()))
f=1
a=0
for i in range(1,n+1):
    if(l[i]==i):
        f=1
    elif(l[i]!=i):
        a=l[i]
        if(l[a]==i):
            l[a]=a
            l[i]=i
            f=1
        else:
            f=0
            break
    else:
        f=0
if(f==1):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().rstrip().split()))
f=1
a=0
for i in range(1,n+1):
    if(l[i+1]>l[i]):
        f=1
    elif(l[i+1]<l[i]):
        a=l[i]
        if(l[a]==i):
            l[a]=a
            l[i]=i
            f=1
        else:
            f=0
            break
    else:
        f=0
if(f==1):
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

Solution code:
arr = []
num = 0
N = int(input())
for i in range(N):
  arr.append(int(input()))
  
for n in range(N):
  if n < (N - 1):
    if arr[n] > arr[n + 1]:
      num += 1
    
if num >= 2:
  print("NO")
else:
  print("YES")

Submission status: Runtime Error

Solution code:
def check_list_sorted(N, p_list):
    cnt = 0
    for i in range(N-1):
        if p_list[i] < p_list[i+1]:
            cnt += 1
    if cnt == N-1:
        return True
    else:
        return False

def swap_list(N, p_list):
    for i in range(N-1):
        if p_list[i] > p_list[i+1]:
            idx = p_list.index(p_list[i+1]-1)
            p_list[i], p_list[idx] = p_list[idx], p_list[i]
            break
    return p_list

N = int(input())
p_list = list(map(int, input().split()))
if check_list_sorted(N, p_list):
    print("YES")
else:
    new_p_list = swap_list(N, p_list)
    if check_list_sorted(N, new_p_list):
        print("YES")
    else:
        print("NO")

Submission status: Runtime Error

Solution code:
arr = []
num = 0
N = int(input())
for i in range(N):
  arr.append(int(input()))
  
for n in range(N):
  if arr[n] > arr[n + 1]:
    num += 1
    
if num >= 2:
  print("NO")
else:
  print("YES")

Submission status: Runtime Error

Solution code:
n, *a = map(int, input().split())
li = []
sorted_a = sorted(a)
for i in range(n):
    if sorted_a[i] != a[i]:
        cnt +=1
        li.append(i)
        


def hantei(n, a, li):
    if len(li) >= 3:
        return('NO')

    elif len(li) <= 1:
        return('YES')

    else:
        a[li[0]], a[li[1]] = a[li[1]], a[li[0]]
        for i in range(n):
            if sorted_a[i] != a[i]:
                return('NO')
        return('YES')

    
print(hantei(n, a, li))

Submission status: Runtime Error

Solution code:
n = int(input())

l = input()

inputs_list = list(map(int, l))

Submission status: Runtime Error

Solution code:
#! /usr/bin/python
# -*- encoding: utf-8 -*-

import sys

if __name__ == '__main__':
    inputN = int(input())
    inputList = list(map(int, input().split()))
    #
    flag = False
    before = 0
    for k in range(inputN):
        if before >= inputList[k]:
            flag = True
        before = inputList[k]
    
    #
    if not flag:
        sys.stdout.write("YES")
        sys.exit()
    
    #  
    for i in range(inputN):
        for j in range(inputN):
            if i != j:
                changeList = inputList[:]
                swap = changeList[i]
                changeList[i] = changeList[j]
                changeList[j] = swap
          
                #
                flag = False
                before = 0
                for k in range(inputN):
                    if before >= changeList[k]:
                        flag = True
                    before = changeList[k]
          
                #
                if not flag:
                    sys.stdout.write("YES")
                    sys.exit()


sys.stdout.write("NO")

Submission status: Runtime Error

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

if p == p2:
    print('YES')
else:
    for i in range(1,n-1):
        if p[i] == p2[n-i]:
            p3 = p.remove(p[i],p[n-1])
            p4 = sorted(p3)
            if p3 == p4:
                print('YES')
            else:
                print('NO')
        else:
            print('NO')

Submission status: Runtime Error

Solution code:
i1 = int(input())
i2 = input().split(' ')

f = true
fi = 0

for i in range(i1):
  if i2[i] < i2[i+1]:
    fi += 1

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

Submission status: Runtime Error

Solution code:
n = int(input())

inputs_list = list(map(int, input()))

correct_list = []
for i in range(n):
    correct_list.append(i+1)
    
if inputs_list == correct_list:
    print('YES')

Submission status: Runtime Error

Solution code:
n = int(input())

inputs_list = list(map,int, input())

correct_list = []
for i in range(n):
    correct_list.append(i+1)
    
if inputs_list == correct_list:
    print('YES')

Submission status: Runtime Error

Solution code:
n = int(input())
p = [int(input()) for i in range(n)]
count =0
for s,t in enumerate(p):
	print(s,t)
	if s !=(t-1):
		count+=1
if count == 2 or count == 0:
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

Solution code:
n = int(input())
p = [int(input(i)) for i in range(n)]
count =0
for s,t in enumerate(p):
	print(s,t)
	if s !=(t-1):
		count+=1
if count == 2 or count == 0:
	print("YES")
else:
	print("NO")

Submission status: Runtime Error

Solution code:
#! /usr/bin/python
# -*- encoding: utf-8 -*-

import sys

if __name__ == '__main__':
    inputN = int(input())
    inputList = list(map(int, input().split()))
    #
    flag = False
    before = 0
    for k in range(inputN):
        if before >= inputList[k]:
            flag = True
        before = inputList[k]
    
    #
    if not flag:
        print("YES")
        sys.exit()
    
    #  
    for i in range(inputN):
        for j in range(inputN):
            if i != j:
                changeList = inputList[:]
                swap = changeList[i]
                changeList[i] = changeList[j]
                changeList[j] = swap
          
                #
                flag = False
                before = 0
                for k in range(inputN):
                    if before >= changeList[k]:
                        flag = True
                    before = changeList[k]
          
                #
                if not flag:
                    print("YES")
                    sys.exit()


print("NO")

Submission status: Runtime Error

Solution code:
n = int(input())
listP = list(map(int,input().split()))
listI = []
flg = 0
for i in range(n-1) :
    if listP[i] > listP[i+1]:
        listI.append(i)
        flg+=1
if flg == 0 :
    print('YES')
elif 1 <= flg and flg <= 2 :
    tmp = listP[listI[0]]
    listP[listI[0]] = listP[listI[1]]
    listP[listI[1]] = tmp
    flg = 0
    for i in (0, n - 2) :
        if listP[i] > listP[i+1]:
            flg += 1
    if flg == 0 :
        print('YES')
    else :
        print('NO')    
else :
    print('NO')

Submission status: Runtime Error

Solution code:
n = int(input())

inputs_list = [input()]

corrct_list = []
for i in range(n):
    correct_lists.append(i+1)
    
if inputs_list == correct_list:
    print('YES')

Submission status: Runtime Error

Solution code:
n, *a = map(int, input().split())
li = []
sorted_a = sorted(a)
for i in range(n):
    if sorted_a[i] != a[i]:
        cnt +=1
        li.append(i)
        


def hantei(n, a, li):
    if len(li) >= 3:
        return('NO')

    elif len(li) <= 1:
        return('YES')

    else:
        a[li[0]], a[li[1]] = a[li[1]], a[li[0]]
        print(li)
        for i in range(n):
            if sorted_a[i] != a[i]:
                return('NO')
        return('YES')

    
print(hantei(n, a, li))

Submission status: Runtime Error

Solution code:
n = int(input())

inputs_list = input()

corrct_list = []
for i in range(n):
    correct_lists.append(i+1)
    
if inputs_list == correct_list:
    print('YES')

Submission status: Runtime Error

Solution code:
n=int(input())
P=map(int,input().split())
p=list(P)
d=[]
D=[]
s=0

for i in range(0,n-1):
    if s==3:
        print('NO')
        break
    elif p[i]<=p[i+1]:
        continue
    else:
        if s==0:
            D.append(p[i])
            d.append(i)
            s=1
        else:
            D.append(p[i+1])
            d.append(i+1)
            s=s+1


if s==0:
    print('YES')
elif (n==d[1]) and p[d[1]-1]<=D[0]:
    print('YES')
elif (0==d[0]) and D[1]<=p[d[0]+1]:
    print('YES')
elif (p[d[0]-1]<=D[1]<=p[d[0]+1]) and (p[d[1]-1]<=D[0]<=p[d[1]+1]):
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
n = int(input())

inputs_list = []
for i in range(0,n):
    num = int(input())
    inputs_list.append(num)

corrct_list = []
for i in range(n):
    correct_lists.append(i+1)
    
if inputs_list == correct_list:
    print('YES')

Submission status: Runtime Error

Solution code:
import sys
n = int(sys.stdin.readline())
p = [int(i) for i in sys.stdin.readline().split()]

if p == sorted(p):
    print('YES')
elif len(p) == 2:
    print('YES')
else:
    swap_index = []
    for i, v in enumerate(p[:-1]):
        if v > p[i + 1]:
            if len(swap_index) == 0:
                swap_index.append(i)
            else:
                swap_index.append(i + 1)
                break
    if len(swap_index) == 1:
        print('NO')
    p[swap_index[0]], p[swap_index[1]] = p[swap_index[1]], p[swap_index[0]]

    if p == sorted(p):
        print('YES')
    else:
        print('NO')

Submission status: Runtime Error

Solution code:
import itertools
N = int(input())
A = [int(x) for x in input().split()]
B = list(range(1,N+1))

def test(i,j):
  AA = A.copy()
  AA[i], AA[j] = AA[j], AA[i]
  return AA == B

bl = (A == B)
for i,j in itertools.combinations(range(N)):
  if test(i,j):
    bl = True
answer = 'YES' if bl else 'NO'
print(answer)

Submission status: Runtime Error

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

if P[0] < P[N-1] and P[N-1] > P[2] and P[N-2] > P[0]:
  print("NO")
else:
  print("YES")

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python

N = input()

n = int(N)

list1 = list(range(n))

for i in range(n) :
	list1[i] = list1[i] + 1

#print(list1)

list2 = []

for i in range(n) :
	list2.append(input())

list2 = [int(n) for n in list2]

#print(list2)

judge = 0

for i in range(n) : 
	if list1[i] != list2[i] :
		judge = judge + 1

if judge <= 2 :
	print('YES')

else :
	print('NO')

Submission status: Runtime Error

Solution code:
import sys
n = int(sys.stdin.readline())
p = [int(i) for i in sys.stdin.readline().split()]

if p == sorted(p):
    print('YES')
elif: len(p) == 2:
    print('YES')
else:
    swap_index = []
    for i, v in enumerate(p[:-1]):
        if v > p[i + 1]:
            if len(swap_index) == 0:
                swap_index.append(i)
            else:
                swap_index.append(i + 1)
                break
    if len(swap_index) == 1:
        print('NO')
    p[swap_index[0]], p[swap_index[1]] = p[swap_index[1]], p[swap_index[0]]

    if p == sorted(p):
        print('YES')
    else:
        print('NO')

Submission status: Runtime Error

Solution code:
N=int(input())
p=list(map(int,input().split()))
A=p.copy()
A.sort()
if p==A:
  print("YES")
else:
  i=p.index(max(p))
  min1=p[N-1]
  for j in range(N-2,0,-1):
    if p[j]<min1:
      min1=p[j]
      min_index=j
  p[i],p[min_index]=p[min_index],p[i]
  if p==A:
    print("YES")
  else:
    print("NO")

Submission status: Runtime Error

Solution code:
N = int(input())
P = input().split()
P = [int(s) for s in P]
T = range(1, N+1)
count=[]
for i in range(N):
  if P[i] != T[i]:
    count.append(i)
if len(count) != 2 and len(count) != 0:
  print("NO")
else:
  P[count[0]], P[count[1]] = P[count[1]], P[count[0]]
  if list(T) == P:
    print("YES")
  else:
    print("NO")

Submission status: Runtime Error

Solution code:
N = int(input())
s = list(map(int, input().split())
new_s = sorted(s)
count = 0

for i in range(N):
    if s[i]-new_s[i]!=0:
        count += 1

if count>2:
    print('NO')
else:
    print('YES')

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
P = list(map(int,input().split()))
A = []
for i in range(N-1):
    if P[i]>P[i+1]:
        A.append([(P[i],i),(P[i+1],i+1)])
l = len(A)
if l > 2:
    print("NO")
elif l == 0:
    print("YES")
else:
    a = max(A[0])
    b = min(A[1])
    P[a[1]],P[b[1]] = b[0],a[0]
    #print(P)
    for j in range(N-1):
        if P[j] > P[j+1]:
            print("NO")
            break
    if j == N-2:
        print("YES")

Submission status: Runtime Error

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

number=[1]
for i in range(2,n):
    number.append(i)
    
for i in range (n-1):
    if bara[i] != number[i]:
        count+=1

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;

int main () {
    int n, t, c = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> t;
        if (i != t) c++;
    }
    cout << (c <= 2 ? "YES" : "NO") << endl;
}

Submission status: Runtime Error

Solution code:

N = int(input())

A = list(map(int, input().split()))

dis = True
count = 0
for i in range(0, N-1):
    if A[i] > A[i+1]:
        count += 1
        dis = False
        if count == 1:
            tmp1 = i
        elif count == 2:
            tmp2 = i+1

if dis == False:
    tmp = A[tmp1]
    A[tmp1] = A[tmp2]
    A[tmp2] = tmp

    count = 0
    for i in range(0, N - 1):
        if A[i] > A[i + 1]:
            count += 1
            dis = False
            if count == 1:
                tmp1 = i
            elif count == 2:
                tmp2 = i + 1
    if count == 0:
        dis = True

if dis == True:
    print('YES')
else:
    print('NO')

Submission status: Runtime Error

Solution code:
import copy

N = int(input()) 
s = list(map(int, input().split()))
s2 = copy.copy(s)
s.sort(reverse=True)
n = 0
for i in range(0, len(x)):
    if x[i] - x2[i] != 0:
        n+=1
if n == 2:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

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

c=0
for i in range(1,n):
    if p[i-1]>p[i]:
        c=c+1

if c<=1:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

count = 0
index = []

for i in range(n-1):
  if p[i] < p[i+1]:
    pass
  else:
    count += 1
    index.append(i)

if count == 0:
  print('YES')
elif count == 2:
  print('NO')
else:
  p[index[0]], p[index[1] + 1] = p[index[1] + 1], p[index[0]]
  sorted_p = sorted(p)
  if p == sorted_p:
    print('YES')
  else:
    print('NO')

Submission status: Runtime Error

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

c=0:
for i in range(1,n):
    if p[i-1]>p[i]:
        c=c+1

if c<=1:
    print("YES")
else:
    print("NO")

Submission status: Runtime Error

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

list2 = []
for i in range(1,N + 1):
    list2.append(i)

if list1 == list2:
    print("YES")
    sys.exit()
for i in range(0,N):
    if list1[i] != i+1:
        if i+1 == list1[list1[i]-1]:
            list1[list1[i]-1] = list1[i]
            list1[i] = i+1
            

        if list1 == list2:
            print("YES")
            sys.exit()
        else:
            print("NO")
            sys.exit()

Submission status: Runtime Error

Solution code:
n = int(input())
P = [int(input()) for a in range(n)]
sorted = sorted(P)
count = 0

for i in range(n):
  if P[i] == sorted[i]:
    count += 1

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

Submission status: Runtime Error

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

number=[1]
for i in range(2,n):
  List.append(i)
    
for i in range n-1:
  if bara[i] != number[i]:
    count+=1

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

Submission status: Runtime Error

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

number=[1]
for i in range(2,):
  List.append(i)
    
for i in range n-1:
  if bara[i] != number[i]:
    count+=1

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

Submission status: Runtime Error

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

number=[1]
for i in range(2,):
  List.append(i)
    
for i in range n-1:
  if bara[i]==number[i]:
    count+=1

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

Submission status: Runtime Error

Solution code:
import sys
n = int(sys.stdin.readline())
p = [int(i) for i in sys.stdin.readline().split()]

if p == sorted(p):
    print('YES')
else:
    swap_index = []
    for i, v in enumerate(p[:-1]):
        if v > p[i + 1]:
            if len(swap_index) == 0:
                swap_index.append(i)
            else:
                swap_index.append(i + 1)
                break
    if len(swap_index) == 1:
        print('NO')
    p[swap_index[0]], p[swap_index[1]] = p[swap_index[1]], p[swap_index[0]]

    if p == sorted(p):
        print('YES')
    else:
        print('NO')

Submission status: Runtime Error

Solution code:
cnt = int(input())
lst = list(map(int,input().split()))
lst2 = [i for i in range(cnt)]
null_lst = []

for j in range(cnt):
  if lst[i] != lst2[i]:
    null_lst += lst[i]

if len(null_lst) % 2 == 0:
  print('YES')
else:
  print('NO')

Submission status: Runtime Error

Solution code:
n, *a = map(int, input().split())
cnt = 0
li = []


def hantei(s):
    for i in range(n-1):
        if s[i] > s[i+1]:
            return False
    return True
    

for i in range(n-1):
    if a[i] > a[i+1]:
        li.append(i+1)


if len(li) < 2:
    print('YES')

elif len(li) >= 2:
    a[li[0]], a[li[1]] = a[li[1]], a[li[0]]
    if hantei(a):
        print('YES')
    else:
        print('NO')

Submission status: Runtime Error

Solution code:
N=int(input())
P=[int(input()) for i in range(N)]

if P[0] > P[N-1] and P[N-1] < P[2] and P[3] < P[0]:
  print("YES")
else:
  print("NO")

Submission status: Runtime Error

Solution code:
n = int(input())
P = [int(input()) for _ in range(n)]
sorted = sorted(P)
count = 0

for i in range(n):
  if P[i] == sorted[i]:
    count += 1

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

Submission status: Runtime Error

Solution code:
#B
import numpy as np
import sys

n = int(input())
p = np.array(list(map(int, input().split())))
p_s = np.array(sort(p))

if all(p==p_s):
    print("YES")
else:
    diff = p_s - p
    diff_index = np.where(diff!=0)
    #print(diff_index[0][1])
    if len(diff_index[0]) != 2:
        print("NO")
    else:
        p0 = p[diff_index[0][0]]
        p[diff_index[0][0]] = p[diff_index[0][1]]
        p[diff_index[0][1]] = p0
        if all(p == p_s):
            print("YES")
        else:
            print("NO")