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: Wrong Answer

Solution code:
import numpy as np
def acinput():
    return list(map(int,input().split(" ")))


N=int(input())
p=acinput()

flg="YES"
bflg=False

count=0
for i in range(N-1):
    if p[i]!=(i+1):
        for j in range(i+1,N):
            if p[j]!=(j+1):
                if (p[i]==j+1) & (p[j]==i+1):
                    p[i]=j+1
                    p[j]=i+1
                    count+=1
    if bflg:
        break

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

Submission status: Wrong Answer

Solution code:
n = int(input())

inputs_list = input()

print(inputs_list[1])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())

inputs_list = input()

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
p_lis = list(map(int, input().split()))
org = list(range(1, n+1, 1))

c = 0
for i in range(n):
      if p_lis[i]== org[i]:
            pass
      else:
            c += 1
if c >3:
      print("NO")
else:
      print("YES")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = []

a = input().split()

b = sorted(a)
if a == b:
    print('YES')
else:
    for i in range(N):
        if int(a[i]) != i+1:
            s = int(a[i])
            a[i], a[s-1] = a[s-1], a[i]
            break
    if a == b:
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
l1 = [int(i) for i in input().split()]
l2 = list(range(1, n + 1))
j = c = 0
flag = 0
while j < n:
    if l1[j] != l2[j]:
        c += 1
        if c > 2:
            print("NO")
            flag = 1
            break
if flag == 0:
    print("YES")

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
import itertools
def main():
    input = sys.stdin.readline

    N = int(input())
    P = list(map(int, input().split()))
    P = np.array(P)

    ans = np.arange(start=1, step=1, stop=N)
    if np.all(P == ans):
        print('YES')
    else:
        dels_comb = list(itertools.combinations(P,2))

        length = len(dels_comb)
        for i in range(length):
            dels = dels_comb [i]
            a, b = dels
            _P = P[(P != a) & (P != b)]
            _ans = ans[(ans != a) & (ans != b)]

            if np.all(_P == _ans):
                print('YES')
                break
            if i + 1 == length:
                print('NO')
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#a,b = map(int,input().sprit())
n = int(input())
p = list(map(int,input().split()))
q = sorted(p)
j = 0 # index
mismatch_c = 0 # mismatch count
ans = 0
for i in range(len(p)):
    if p[i] != q[i]:
        if mismatch_c == 0:
            j = i
            mismatch_c += 1
        elif mismatch_c == 1:
            if p[i] == q[j]:
                mismatch_c += 1
                ans = 1
            else:
                break
        else:
            ans = 0
            break
if ans == 0:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int, input().split()))
numOfOpe = 0
for i in range(N-1):
    if P[i+1] - P[i] != 1: numOfOpe += 1
    if P[i] - P[i+1] == 1: numOfOpe -= 1 
    if numOfOpe > 2: break

if numOfOpe <= 2: print("YES")
elif numOfOpe > 2: print("NO")

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
p = [int(i) for i in input().split()]
ps = sorted(p)
x = [p[i]-ps[i] for i in range(len(p))]
c = collections.Counter(x)
if len(c) == 1 or len(c) == 3 and sum(x) == 0:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
  n = int(input())
  input_line = list(map(int, input().split()))
  
  flag = 0
  i = 0
  for x in input_line:
    if flag > 2:
      break
    elif (i + 1) == len(input_line):
      break
    elif (input_line[i + 1] - input_line[i]) != 1:
      flag += 1
    i += 1
    
  if flag < 3:
    print("YES")
  else:
    print("NO")




if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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



ans=0
i=0
i2=0
d=0
while i!=n-1:
    if s[i]>s[i+1]:
        i2=i+2
        ans+=1
        while i2!=n:

            if s[i+1]>s[i2] :
          
                d=s[i]
                s[i]=s[i2]
                s[i2]=d

            i2+=1
    i+=1

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
a = input().split()
ans = "NO"
b = copy.deepcopy(a)
if b == sorted(a):
    ans = "YES"
else:
    for i in range(0, N-1):
        if ans == "YES":
            break
        for j in range(i, N):
            b = copy.deepcopy(a)
            temp = b[i]
            b[i] = b[j]
            b[j] = temp
            if b == sorted(a):
                ans = "YES"
                break
print(ans)

Submission status: Wrong Answer

Solution code:
num = input()
input_list = [int(i) for i in input().split()] 
sorted_list = sorted(input_list)

count = 0
for input, sort in zip(input_list, sorted_list):
  if input != sort:
    count += 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split(" ")))
count = 0
minp = p.pop()
for pi in p:
  if minp > pi:
    minp = pi
    count +=1
if count==1:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = []

a = input().split()

b = sorted(a)
if a == b:
    print('YES')
else:
    for i in range(N):
        if a[i] != i+1:
            s = int(a[i])
            a[i], a[s-1] = a[s-1], a[i]
            break
    if a == b:
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

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

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

count = 0
big_index = [] # 昇順できないデータを入れておく
for i in range(N-1):
    if pn[i] > pn[i+1]:
        count += 1
        big_index.append(i)
if count == 2:
    #入れ替えのための一時保存場所
    switch = pn[big_index[0]]
    pn[big_index[0]] = pn[big_index[1]+1]
    pn[big_index[1]+1] = switch
    #もう一回チェックする
    count_swap = 0
    for i in range(N-1):
        if pn[i] > pn[i+1]:
            count_swap += 1
    if count_swap == 0:
        print('YES')
    else:
        print('NO')
elif count <= 1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
intlist = input().split(" ")
count = 0
sortedlist = sorted(intlist)
match = list()

for i in range(0,n):
	if(intlist[i] == sortedlist[i]):
		match.append(0)
	else:
		match.append(1)

if(sum(match) > 2):
	print("NO")
else:
	print("YES")

Submission status: Wrong Answer

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

for i in range(len(l)-1):
    mi = l[i:].index(min(l[i:]))
    l[i], l[i+mi] = l[i+mi], l[i]
    cnt += 1
    if l == sorted(l):
        break
        
print("YES" if cnt < 2 else "NO")

Submission status: Wrong Answer

Solution code:
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 ==1:
    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")
for i in range(1):
    print(i)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
p_lis = np.array(list(map(int, input().split())))
org = np.array(range(1, n+1, 1))
diff = org - p_lis

if len(set(diff))==2:
      print("NO")
elif len(set(diff))<= 3:
      print("YES")
else:
      print("NO")

Submission status: Wrong Answer

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


flag1 = True

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

if count == 0 or count == 2:
    flag1 = True
else:
    flag1 = False

flag2 = True
down_i = []
down_count = 0
for i in range(n-1):
    if p[i] > p[i+1]:
        down_i.append([i,p[i],p[i+1]])
        down_count += 1

if down_count <= 1:
    flag2 = True
else:
    if down_count == 2:
        p[down_i[0][0]] = down_i[1][2]
        p[down_i[1][0]+1] = down_i[0][1]

        #print(p)

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

        if c <= 0:
            flag2 = True
        else:
            flag2 = False
    else:
        flag2 = False


if flag1 and flag2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
a = input().split()
ans = "NO"
b = copy.deepcopy(a)
if b == sorted(a):
    ans = "YES"
else:
    for i in range(0, N):
        if ans =="YES":
            break
        for j in range(i, N-1):
            b = copy.deepcopy(a)
            temp = b[i]
            b[i] = b[j]
            b[j] = temp
            if b == sorted(a):
                print("YES")
                ans = "YES"
                break
print(ans)

Submission status: Wrong Answer

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

flag = []
for i in range(N-1):
  if P[i] > P[i+1]:
    flag.append(i)

if len(flag) > 2:
  print('NO')
if len(flag) == 2:
  A = P[flag[0]]
  B = P[flag[1]+1]
  P[flag[0]] = B
  P[flag[1]+1] = A
  for i in range(N-1):
    if P[i] > P[i+1]:
      print('NO')
      exit()
  print('YES')
  exit()
if len(flag) == 1:
  A = P[flag[0]]
  B = P[flag[0]+1]
  P[flag[0]] = B
  P[flag[0]+1] = A
  for i in range(N-1):
    if P[i] > P[i+1]:
      print('NO')
      exit()
  print('YES')
  exit()
else:
  print('YES')

Submission status: Wrong Answer

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



ans=0
i=0
i2=0
d=0
while i!=n-1:
    if s[i]>s[i+1]:
        i2=i+2
        while i2!=n:

            if s[i+1]>=s[i2] :
                ans += 1
                d=s[i]
                s[i]=s[i2]
                s[i2]=d

            i2+=1
    i+=1

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

Submission status: Wrong Answer

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

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

bl = (A == B)
for i in range(N-1):
  if test(i):
    bl = True
answer = 'YES' if bl else 'NO'
print(answer)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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



ans=0
i=0
i2=0
d=0
while i!=n-1:
    if s[i]>s[i+1]:
        i2=i+2
        while i2!=n:

            if s[i+1]>=s[i2] :
                ans += 1
                d=s[i]
                s[i]=s[i2]
                s[i2]=d

            i2+=1
    i+=1
print(s)
if ans<=1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

if ans != "YES":
    for i in range(N-1):
        for j in range(i+1,N-1):
            pcopy = p.copy()
            pcopy[i],pcopy[j] = pcopy[j],pcopy[i]
            flg = True
            for k in range(N-1):
                if pcopy[k] > pcopy[k+1]:
                    flg = False
            if flg:
                ans ="YES"
                break        

print(ans)

Submission status: Wrong Answer

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

count = 0
    
for i in range (n-1):
    if bara[i] != number[i]:
        count += 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
plist = []
p = input().split()
plist.extend(p)

for m in range(n):
  plist[m] = int(plist[m])
  
salist = []
for j in range(n-1):
  sa = plist[j]-plist[j+1]
  salist.append(sa)

fugolist = []
for k in range(n-1):
  if salist[k]>0:
    fugolist.append(1)
  elif salist[k] == 0:
    fugolist.append(0)
  else:
    fugolist.append(-1)
flag = 0  
if fugolist[0] == fugolist[-1]:
  for l in range(1,n-2):
    if fugolist[l] == fugolist[l+1]:
      flag += 1
else:
  flag += 0

if flag == 0:
  print("NO")
else:
  print("YES")

Submission status: Wrong Answer

Solution code:
N=int(input())
p=list(map(int,input().split()))
answer = []
diff = 0
diff_1 = -1
diff_2 = -1

index = 0

for i in p:
    if index == 0:
        index += 1
        continue
    
    if p[index] < p[index-1]:
        if diff >= 2:
            print ("NO")
            exit()
        diff += 1

        if diff_1 == -1:
            diff_1 = index-1
        else:
            diff_2 = index-2

    index += 1

if diff_1 == -1:
    print("YES")
    exit()

if diff_1 != -1 and diff_2 == -1:
    print("NO")
    exit()

diff_1_1 = p[diff_1]
p[diff_1] = p[diff_2]
p[diff_2] = diff_1_1

index = 0
for i in p:
    if index == 0:
        index += 1
        continue
    
    if p[index] < p[index-1]:
        print ("NO")    
        exit()

    index += 1

print("YES")

Submission status: Wrong Answer

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

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

count = 0
big_index = [] # 昇順できないデータを入れておく
for i in range(N-1):
    if pn[i] > pn[i+1]:
        count += 1
        big_index.append(i)
if count == 2:
    #入れ替えのための一時保存場所
    switch = pn[big_index[0]]
    pn[big_index[0]] = pn[big_index[1]+1]
    pn[big_index[1]+1] = switch
    #もう一回チェックする
    count_swap = 0
    for i in range(N-1):
        if pn[i] > pn[i+1]:
            count_swap += 1
        if count == 0:
            print('YES')
        else:
            print('NO')
elif count <= 1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

for i in range(N-1):
    for j in range(i+1,N-1):
        pcopy = p.copy()
        pcopy[i],pcopy[j] = pcopy[j],pcopy[i]
        flg = True
        for k in range(N-1):
            if pcopy[k] < pcopy[k+1]:
                flg = False
        if flg:
            ans ="YES"
            break        

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
l = list(map(int, input().split()))

flg = 0
for i in range(N):
    if i+1 != l[i]:
        flg += 1
        print(l[i]-1)
        l[l[i]-1] = l[i]
    if flg >= 2:
        print('NO')
        sys.exit()
print('YES')

Submission status: Wrong Answer

Solution code:

n = int(input())
p = list(map(int, input().strip().split()))


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

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

Submission status: Wrong Answer

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

if count == 0 or count == 1:
  print("YES")
elif count >= 3:
  print("NO")
else:
  count = 0
  list2 = []
  for i in range(N-1):
    if list1[i] > list1[i+1]:
      list2.append(i)
  a = list1[list2[0]] 
  b = list1[list2[1] + 1]
  list1[list2[0]] =b
  list1[list2[1] + 1] =a
  for i in range(N-1):
    if list1[i] > list1[i+1]:
      count += 1
  if count == 0:
    print("YES")
  else:
    print("NO")

Submission status: Wrong Answer

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]
  min_index=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: Wrong Answer

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



ans=0
i=0
i2=0
d=0
while i!=n-1:
    if s[i]>s[i+1]:
        i2=i
        while i2!=n:
            ans += 1
            if s[i+1]>=s[i2] and s[i2-1]<s[i]:
                d=s[i]
                s[i]=s[i2]
                s[i2]=d

            i2+=1
    i+=1
if ans<=1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

count = 0

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

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

Submission status: Wrong Answer

Solution code:
N= int(input())
p_list = [i for i in map(int,input().split())]
#print(p_list)
a_list = p_list.copy()
b_list = p_list.copy()
#print(a_list)
a_list.sort()
b_list.sort()
#print(a_list)
if p_list == a_list:
  print('YES')
  exit()
max = p_list.index(max(p_list))
min = p_list.index(min(p_list))
x = p_list[min]
p_list[min] = p_list[max]
p_list[max] = x
if p_list == b_list:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
N= int(input())
p_list = [i for i in map(int,input().split())]
#print(p_list)
a_list = p_list.copy()
b_list = p_list.copy()
#print(a_list)
a_list.sort()
b_list.sort()
#print(a_list)
if p_list == a_list:
  print('YES')
  exit()
max = p_list.index(max(p_list))
min = p_list.index(min(p_list))
x = p_list[min]
p_list[min] = p_list[max]
p_list[max] = x
if p_list == b_list:
  print('Yes')
else:
  print('No')

Submission status: Wrong Answer

Solution code:
puts = input()
Data = puts.split()
offset = 0

for i in range(len(Data)):
	if (i+1 != int(Data[i])):
		if offset != 2:
			offset +=1
		else:
			print('NO')
			exit()

print('YES')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    if (a + b) % 2:
        print("IMPOSSIBLE")
        return
    print((a + b) // 2)
    return

#B
def B():
    n = II()
    p = LI()
    for j in range(n-1):
        if p[j] > p[j + 1]:
            break
        else:
            print("YES")
            return
    for i in range(n):
        for k in range(i+1, n):
            pi = p[::1]
            pi[i], pi[k] = pi[k], pi[i]
            for j in range(n-1):
                if pi[j] > pi[j + 1]:
                    break
            else:
                print("YES")
                return
    print("NO")
    return

#C
def C():
    n = II()
    a = LI()
    b = LI()
    ans = 0
    for i in range(n):
        if a[i] >= b[i]:
            ans += b[i]
            continue
        ans += a[i]
        b[i] -= a[i]
        if a[i + 1] >= b[i]:
            ans += b[i]
            a[i + 1] -= b[i]
            continue
        ans += a[i + 1]
        a[i + 1] = 0
    print(ans)
    return

#D
def D():
    s = S()
    s = s[::-1]
    dp = [[0] * 13 for _ in range(len(s))]
    remain = 1
    if s[0] == "?":
        for i in range(10):
            dp[0][i] = 1
    else:
        dp[0][int(s[0])] = 1
    for i in range(1, len(s)):
        remain = (remain * 10) % 13
        dpi = dp[i]
        dpi1 = dp[i-1]
        if s[i] == "?":
            for k in range(10):
                for j in range(13):
                    dpi[(j + remain * k) % 13] += dpi1[j]
                    dpi[(j + remain * k) % 13] %= mod
        else:
            for j in range(13):
                dpi[(j + remain * int(s[i])) % 13] += dpi1[j]
    print(dp[-1][5])
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	# = list(input())
	#A,B = map(int, input().split(" "))
	PP = list(map(int, input().split(" ")))

	#P = copy.deepcopy(PP)

	flg = True
	for k,val in enumerate(PP):
		if k == 0:
			continue
		if PP[k-1] <= val:
			pass
		else:
			flg = False

		if flg == True:
			print("YES")
			sys.exit()

	tmp = []
	for i in range(N):
		for j in range(i+1, N):
			P = copy.deepcopy(PP)
			tmp = P[j]
			P[i] = P[j]
			P[j] = tmp

		flg = True
		for k,val in enumerate(P):
			if k == 0:
				continue
			if P[k-1] <= val:
				pass
			else:
				flg = False

		if flg == True:
			print("YES")
			sys.exit()

	print("NO")


if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
  n = int(input())
  input_line = list(map(int, input().split()))
	
  sorted_list = sorted(input_line)
  
  if input_line == sorted_list:
    print("YES")
    sys.exit()
    
  flag = 0
  buf1 = 0
  i = 0
  x = -1
  for l in input_line:
    buf = input_line[:]
    if i == int(n / 2):
      flag = 2
      break
    buf1 = buf[i]
    buf[i] = input_line[x]
    buf[x] = buf1
    if buf == sorted_list:
      flag = 1
      break
    i += 1
    x -= 1
  
  if (flag == 1):
    print("YES")
  else:
    print("NO")




if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
x = int(input())
li = list(map(int,input().split()))#listp
li_o = list(range(1,x))

a = 0
for i in range(x-1):
	
	b = 0
	#print (li[i])
    
	if int(li[i]) == int(li_o[i]):
		b=b+1
	else:
		a=a+1
	#print(a)
	#print('endofloop')
    
#print(a)

if a < 2:
	print('YES')
else:
	print('NO')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys, math, bisect, random, itertools
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    if (a + b) % 2:
        print("IMPOSSIBLE")
        return
    print((a + b) // 2)
    return

#B
def B():
    n = II()
    p = LI()
    for i in range(n):
        for k in range(i+1, n):
            pi = p[::1]
            pi[i], pi[k] = pi[k], pi[i]
            for j in range(n-1):
                if pi[j] > pi[j + 1]:
                    break
            else:
                print("YES")
                return
    print("NO")
    return

#C
def C():
    n = II()
    a = LI()
    b = LI()
    ans = 0
    for i in range(n):
        if a[i] >= b[i]:
            ans += b[i]
            continue
        ans += a[i]
        b[i] -= a[i]
        if a[i + 1] >= b[i]:
            ans += b[i]
            a[i + 1] -= b[i]
            continue
        ans += a[i + 1]
        a[i + 1] = 0
    print(ans)
    return

#D
def D():
    s = S()
    s = s[::-1]
    dp = [[0] * 13 for _ in range(len(s))]
    remain = 1
    if s[0] == "?":
        for i in range(10):
            dp[0][i] = 1
    else:
        dp[0][int(s[0])] = 1
    for i in range(1, len(s)):
        remain = (remain * 10) % 13
        dpi = dp[i]
        dpi1 = dp[i-1]
        if s[i] == "?":
            for k in range(10):
                for j in range(13):
                    dpi[(j + remain * k) % 13] += dpi1[j]
                    dpi[(j + remain * k) % 13] %= mod
        else:
            for j in range(13):
                dpi[(j + remain * int(s[i])) % 13] += dpi1[j]
    print(dp[-1][5])
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
N=int(input())
nums = [int(e) for e in input().split()]
def swap(x,y):
    temp=x
    x=y
    y=temp
    return x,y

nums=np.array(nums)
temp=np.copy(nums)
j=0
for j in range(0,N-1):
    if temp[j]>temp[j+1]:
        break
    else:
        pass
if j==N-2:
    print("YES")
    sys.exit()
    

def compare(k):
    global N
    global nums
    temp=np.copy(nums)
    for i in range(0,N-1):
        swap(temp[k],temp[i+1])
        j=0
        for j in range(0,N-1):
            if temp[j]>temp[j+1]:
                break
            else:
                pass
        if j==N-2:
            print("YES")
            return
    if k==N-1:
        print("NO")
        return
    compare(k+1)
compare(0)

Submission status: Wrong Answer

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

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

count = 0
big_index = [] # 昇順できないデータを入れておく
for i in range(N-1):
    if pn[i] > pn[i+1]:
        count += 1
        big_index.append(i)
if count == 2:
    #入れ替えのための一時保存場所
    switch = pn[big_index[0]]
    pn[big_index[0]] = pn[big_index[1]+1]
    pn[big_index[1]+1] = switch
    #入れ替えて条件満たすか見る
    if (pn[big_index[0]] < pn[big_index[0]+1]) and (pn[big_index[1]] < pn[big_index[1]+1]):
        print('YES')
    else:
        print('NO')
elif count <= 1:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

print("YES")