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:
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(N: int, p: "List[int]"):

    if check(p):
        print("YES")
        return

    p1 = p.copy()
    if p[0] > p[1] and p[N-2] > p[N-1]:
        p1[0] = p[N-1]
        p1[N-1] = p[0]

    if check(p1):
        print("YES")
        return

    p2 = p.copy()
    current = p[0]
    for i in range(1, len(p)):
        if current > p[i]:
            p2[i-1] = p[i]
            p2[i] = p[i-1]

    if check(p2):
        print("YES")
        return
    else:
        print("NO")

def check(p):
    current = p[0]
    for i in range(1, len(p)):
        if current > p[i]:
            return False

    return True

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, p)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
x = input().rstrip().split()

cnt = 0
for i in range(N):
  for j in range(i+1,N):
    if x[i] > x[j]:
      cnt += 1
      
if cnt < 2:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
P = list(map(int,input().split()))
a = np.array([i for i in range(1,n+1)])
ans = P-a
if np.sum(ans)==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()))
	
  sorted_list = sorted(input_line)
  
  i = 0
  flag = 0
  x = -1
  for l in input_line:
    if i == int(n / 2):
      break
    elif flag == 2:
      break
    elif (l + input_line[x]) != (n + 1):
      flag += 1
    x -= 1
    i += 1
  
  if flag != 2:
    print("YES")
  else:
    print("NO")




if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
A =[int(i) for i in input().split()]
B =sorted(A)
count = 0
for i in range(len(B)):
    if A[i]!=B[i]:
        count +=1
if count>2:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
data = list(map(int, input().split()))
s_data = copy.deepcopy(data)
s_data.sort()
c = 0
for i in range(n):
    if data[i] != s_data[i]:
        c += 1

if c == 2:
    # 入れ替えたときちゃんと合うか
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str

def solve(N: int, p: "List[int]"):

    if check(p):
        print("YES")
        return

    p1 = p.copy()
    if p[0] > p[1] and p[N-2] > p[N-1]:
        p1[0] = p[N-1]
        p1[N-1] = p[0]

    if check(p1):
        print("YES")
        return

    p2 = p.copy()
    current = p[0]
    for i in range(1, len(p)):
        if current > p[i]:
            p2[i-1] = p[i]
            p2[i] = p[i]

    if check(p2):
        print("YES")
        return
    else:
        print("NO")









def check(p):
    current = p[0]
    for i in range(1, len(p)):
        if current > p[i]:
            return False

    return True







# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, p)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#B
n = int(input())
p = list(map(int, input().split()))
cnt = 0
flg = 0
tmp1,tmp2 = 0,0
for i in range(0,n-1):
    if p[i] > p[i+1]:
        if tmp1 == 0:
            tmp1, tmp2 = p[i], p[i+1]
        else:
            if cnt == 1:
                flg = 1
                break
            elif p[i+1]<tmp2 and p[i]<tmp1:
                cnt = 1
            else:
                flg = 1
                cnt = 1
                break
if flg == 0:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

if not tmp:
    print('YES')
elif len(tmp) == 2:
    print(tmp)
    p[tmp[0]], p[tmp[1]] = p[tmp[1]], p[tmp[0]]
    tmp = [i for i in range(N) if P[i] - p[i] != 0]
    if tmp:
        print('NO')
    else:
        print('YES')
else:
    print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0

p_sort = sorted(p)

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
N = list(map(int, input().split()))
cnt = 0
for i in range(1, len(N)):
    tmp = N[i] 
    if tmp < N[i-1]:
        j = i
        while True:
            N[j] = N[j-1]
            j -= 1
            if j == 0 or tmp >= N[j-1]:
                break
        N[j] = tmp
        if j != i:
          cnt+=1
if cnt <= 1:
  print("YES")
else:
  print("NO")
#print(N)
#print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

N = int(input())
ppp = list(map(int, input().split()))
ppp_sorted = sorted(ppp)

len_ppp = len(ppp)

if ppp == ppp_sorted:
    print('YES')
    exit()

for i in range(len_ppp):
    ppp_copy = deepcopy(ppp)
    ppp_copy[i], ppp_copy[-i-1] = ppp_copy[-i-1], ppp_copy[i]
    if ppp_copy == ppp_sorted:
        print('YES')
        exit()

print('NO')

Submission status: Wrong Answer

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

a=0
for i in range(n):
    if p[i]==q[i]:
        a+=1
    else:
        a+=0

if a==n or a==n-2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
lst2 = sorted(lst)
if lst==lst2:
  print("YES")
else:
  tmp = 0

  for i in range(n):
    if lst[i]!=lst2[i]:
      tmp+=1
      
  if tmp != 1:
    print("NO")
  else:
    print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())

li = list(map(int,input().split()))
count = 0
judge = True

for i in range(N-1):
    if (li[i] > li[i+1]):
        swp = li[i]
        index_swp = li.index(min(li[i+1:]))
        li[i] = min(li[i+1:])
        li[index_swp] = swp
        count = count + 1
        if(count > 1):
            judge = False
            break
    

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

Submission status: Wrong Answer

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

p[p.index(min(p))], p[p.index(max(p))] = p[p.index(max(p))], p[p.index(min(p))]

print("YES") if sorted(p2) == p else print("NO")

Submission status: Wrong Answer

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

print(p,q)

a=0
for i in range(n):
    if p[i]==q[i]:
        a+=1
    else:
        a+=0

if a==n or a==n-2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
ps=list(int(i) for i in input().split())  

pf=ps[0]
flag=0
for i in ps[1:]:
    if pf>i:
        flag+=1
        if flag>=2:
            print("NO")
            break
    pf=i
if flag<2:
 print("YES")

Submission status: Wrong Answer

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


wrong_p = []
wrong_idx = []
for i in range(N-1):
    if ps[i] > ps[i+1]:
        if len(wrong_p) > 0:
            wrong_p.append(ps[i+1])
            wrong_idx.append(i+1)
        else:
            wrong_p.append(ps[i])
            wrong_idx.append(i)
    if len(wrong_p) > 2:
        print("No")
        exit()

# print(wrong_p)
# print(wrong_idx)

if len(wrong_p) == 0:
    print("YES")
    exit()
if len(wrong_p) == 1:
    if wrong_idx[0] == N-2:
        print("YES")
    else:
        print("NO")
    exit()
if len(wrong_p) == 2:
    ps[wrong_idx[0]] = wrong_p[1]
    ps[wrong_idx[1]] = wrong_p[0]
    # print(ps)
    for i in range(N-1):
        if ps[i] > ps[i+1]:
            print("NO")
            exit()
    print("YES")

Submission status: Wrong Answer

Solution code:
N = int(input())

li = list(map(int,input().split()))
count = 0
judge = True

for i in range(N-1):
    if (li[i] > li[i+1]):
        swp = li[i]
        index_swp = li.index(min(li[i+1:]))
        li[i] = min(li[i+1:])
        li[index_swp] = swp
        count = count + 1
        if(count > 1):
            judge = False
            break
    

if(judge):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())

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

if p[0] == max(p) and p[len(p) - 1] == min(p):
    print('YES')
elif p[0] == min(p) and p[len(p) - 1] == max(p):
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
data = list(map(int, input().split()))
s_data = copy.deepcopy(data)
s_data.sort()
s_data.reverse()
c = 0
for i in range(n):
    if data[i] != s_data[i]:
        c += 1

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

Submission status: Wrong Answer

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

N = int(input())
p = [int(i) for i in input().split()]
q = [i+1 for i in range(N)]

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

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

Submission status: Wrong Answer

Solution code:
def check(i,j,number_list):
    number=[]
    for k in number_list:
        number.append(k)
    k=number[i]
    number[i]=number[j]
    number[j]=k
    flag=1
    for l in range(len(number_list)):
        if (int(number[l])==(l+1)):
            continue
        else:
            flag=0
            break
    return flag
N=int(input())
in_number_list=input().split(" ")
number_list=[]

for i in in_number_list:
    number_list.append(int(i))

flag=0
for i in range(N):
    for j in range(i,N):
        a=check(i,j,number_list)
        if(a==1):
            print("YES")
            flag=1
            break
if(flag==0):
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int, input().split()))
cnt = 0

for i in range(len(L)):
    if L[i] != i+1:
        cnt += 1
    print(L[i])
    print(i+1)
if cnt >= 3:
    print('NO')
else:
    print('YES')

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
P = list(map(int, input().split()))
X = copy.copy(P)
Y = copy.copy(P)
X.sort()

def f(P):
    for i in range(N):
        for j in range(N):
            P = copy.copy(Y)
            P[i],P[j] = P[j],P[i]

            if X == P:
                return "Yes"
    return "NO"

ans = f(P)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(N):
    if p[i] == i + 1:
        continue
    p[p[i] - 1] = p[i]
    p[i] = i + 1
    c += 1
    if c > 1:
        print('No')
        exit()
print('YES')

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
lst = list(map(int, input().split()))
lst2 = sorted(lst)
sum = 0
for i in range(N):
  if (lst[i] != lst2[i]):
    sum += 1
if (sum == 0 and sum == 2):
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
list = []
list = input().split()

list_up = []
for i in range(1,n+1):
    list_up += str(i)

x = 0

for i in range(n):
    if list[i] != list_up[i]:
        x += 1

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

Submission status: Wrong Answer

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

dic = {}
for i in range(n-1):
    a = p[i+1]-p[i]
    if a in dic and a != 1:
        dic[a] += 1
    elif a not in dic and a != 1:
        dic[a] = 1

flag = False
for i in dic.values():
    if i == 2 and len(dic) == 2:
        flag = True
        break
    else:
        continue

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

Submission status: Wrong Answer

Solution code:
#B
n = int(input())
p = list(map(int, input().split()))
cnt = 0
tmp1,tmp2 = 0,0
for i in range(0,n-1):
    if p[i] > p[i+1]:
        if tmp1 == 0:
            tmp1, tmp2 = p[i], p[i+1]
        else:
            if cnt == 1:
                break
            elif p[i+1]<tmp2 and p[i]<tmp1:
                cnt = 1
            else:
                cnt = 1
                break
if cnt == 0:
    print('YES')
else:
    print('NO')

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
count = 0 # swap count
ans = 0
for i in range(len(p)):
    if p[i] != q[i]:
        if count:
            ans = 1
            break
        elif i:
            if p[i] == q[j]:
                count += 1
            else:
                ans = 1
                break
if ans == 1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

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

len_ppp = len(ppp)

if ppp == ppp_sorted:
    print('YES')
    exit()

for i in range(len_ppp):
    ppp[i], ppp[-i-1] = ppp[-i-1], ppp[i]
    if ppp == ppp_sorted:
        print('YES')
        exit()

print('NO')

Submission status: Wrong Answer

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

for i in range(n):
    if i+1 != p[i]:
        count += 1
        k = p.index(i+1)
        k = p.pop(k)
        p.insert(i,k)
        if count == 1:
            break

if sorted_p == p:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
lst = list(map(int, input().split()))
lst2 = sorted(lst)
sum = 0
for i in range(N):
  if (lst[i] != lst2[i]):
    sum += 1
if (sum == 2):
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

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

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

if ma>=2:
    print("NO")
else:
    print("YES")

Submission status: Wrong Answer

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

a = range(1, N+1)

cnt = 0
for i in range(N):
  if a[i]!=p[i]:
    cnt += 1

if cnt==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:
def check(i,j,number_list):
    number=[]
    for k in number_list:
        number.append(k)
    k=number[i]
    number[i]=number[j]
    number[j]=k
    flag=1
    for l in range(len(number_list)):
        if (int(number[l])==(l+1)):
            continue
        else:
            flag=0
            break
    return flag
N=int(input())
in_number_list=input().split(" ")
number_list=[]

for i in in_number_list:
    number_list.append(int(i))

flag=0
for i in range(N):
    for j in range(i+1,N):
        a=check(i,j,number_list)
        if(a==1):
            print("YES")
            flag=1
            break
if(flag==0):
    print("NO")

Submission status: Wrong Answer

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

d = []

for i in range(N):
  d.append(p[i]-P[i])
  
D = d[:]
while 0 in D:
  D.remove(0)
  
if max(d) == 0:
  print('YES')
elif len(D) == 2:
  if D[0] == (-D[1]):
    print('YES')
  else:
    print('NO')

Submission status: Wrong Answer

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

pn_1 = pn[0]
cnt = 0
for i in range(1,n):
    if pn_1 + 1 != pn[i]:
        if cnt <= 2:
            cnt += 1
        else:
            cnt = 3
            break
    pn_1 = pn[i]

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

Submission status: Wrong Answer

Solution code:
N=int(input())
p=list(map(int,input().split()))
ps=sorted(p,reverse=True)
cnt=0
for i in range(N):
    if p[i]==ps[i]:
        cnt+=1

if cnt==2 or cnt==N-2 or cnt==N:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

mis_match = sum([ 1 for s in p if not p.index(s) == s+1])

judge="NO"
if mis_match in [0,2]:
    judge="YES"
print(judge)

Submission status: Wrong Answer

Solution code:
N = int(input())
p = [int(x) for x in input().split()]
a = sorted(p)
print(p)
print(a)
c = 0
for i in range(N):
  if p[i] != a[i]:
    c += 1
if c <= 2 :
  print("YES")
if c > 2:
  print("NO")

Submission status: Wrong Answer

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

flag=0
save=0
for i in range(N-1):
  if flag==0 and P[i]>P[i+1]:
    save=i
    flag=1
  if flag==1 and P[i]>P[i+1]:
    tmp=P[i]
    P[i]=P[save]
    P[save]=tmp
    break

flag=0
for i in range(N-1):
  if P[i]>P[i+1]:
    print('NO')
    flag=1
    break

if flag!=1:
  print('YES')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
p = list(map(int, input().split()))
nl = [i for i in range(1, n+1)]
ans = True
difcnt = 0
for i in range(n):
    if i % 2 == 0 and p[i] % 2 == 0:
        ans = False
    if i % 2 == 1 and p[i] % 2 == 1:
        ans = False
    if p[i] != nl[i]:
        difcnt += 1

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

Submission status: Wrong Answer

Solution code:
N=int(input())

p=input().split()
q=[]
q=sorted(p)
#print(p,q)
count=0
for i in range(N):
    if p[i]!=q[i]:
        count+=1

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

Submission status: Wrong Answer

Solution code:
N=int(input())
P=list(map(int, input().split()))
Q=P[:]
Q.sort()
print(P)
print(Q)

not_equal_count=0
for i in range(N):
  if P[i] != Q[i]:
    not_equal_count += 1
if not_equal_count in [0, 2]:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
n = int(input())
p_list = list(map(int, input().split()))

count = 0
for i in range(n):
    if p_list[i] != (i+1):
        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()))

def isSort(l):
    for i in range(len(l)-1):
        if l[i] > l[i+1]:
            return False
    return True

cnt = 0
t1 = -1
for i in range(N-1):
    if p[i] > p[i+1]:
        t1 = i
        break

if t1 >= 0:
    t2 = -1
    for i in range(t1+1, N):
        if p[i] > p[t1]:
            t2 = i - 1
    if t2 == -1:
        t2 = N-1
    p[t1], p[t2] = p[t2], p[t1]
    if isSort(p):
        print('YES')
    else:
        print('NO')
else:
    print('YES')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

len_ppp = len(ppp)

if ppp == ppp_sorted:
    print('YES')
    exit()

for i in range(len_ppp//2+1):
    ppp[i], ppp[-i-1] = ppp[-i-1], ppp[i]
    if ppp == ppp_sorted:
        print('YES')
        exit()

print('NO')

Submission status: Wrong Answer

Solution code:
# ' 'dで区切ってprintする方法
# print(*a, sep=' ')

import math

n = int, input()

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

reverse = 0
former = 0

for num in p:
    if former > num:
        reverse += 1
    former = num
    if reverse > 1:
        print('NO')
        exit()
print('YES')

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 % 2 == 0:
  print('YES')
else:
  print('NO')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
count = 0
a = sorted(a)
b = []
c = [] 

for i in range(len(a)):
    if a[i]!=i+1:
        count = count + 1
        b.append(i+1)
        c.append(a[i])
        
if count == 0:
    print('YES')
elif count ==2 and b[0]== c[1] and c[0] ==b[1]:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
import copy

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

flag = 0


# 操作不要の場合
if p_list == sorted(p_list):
  print("YES")
  flag = 1
  
# 1回だけ操作
for i in range(N):
  for j in range(i, N):
    # print(i, j)
    new_p_list = copy.deepcopy(p_list)
    tmp = new_p_list[j]
    new_p_list[j] = new_p_list[i]
    new_p_list[i] = tmp
    # print(new_p_list)
    # print(sorted(p_list))
    if new_p_list == sorted(p_list):
      print("YES")
      flag = 1
      
if flag == 0:
  print("NO")

Submission status: Wrong Answer

Solution code:
a=int(input())
l=list(map(int,input().split()))
ok=False
for i in range(len(l)-1):
    if sorted(l) == l:
        print("YES")
        break
    for j in range(i+1,len(l)):
        aux=l[i]
        l[i]=l[j]
        l[j]=aux
        if sorted(l) == l:
            ok=True
        else:
            aux = l[j]
            l[j] = l[i]
            l[i] = aux
    if ok == True:
        print("YES")
        break
if ok ==False:print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int, input().split()))
c = 0
for i in range(N):
    if p[i] == i + 1:
        continue
    p[p[i] - 1] = p[i]
    p[i] = i
    c += 1
    if c > 1:
        print('No')
        exit()
print('YES')

Submission status: Wrong Answer

Solution code:
n = int(input())

a = []
a_li = input().split()

for i in range(n):
    a.append(int(a_li[i]))
    
ans = "YES"
cnt = 0

for i in range(n):
    if a[i] != i+1:
        if a[a[i]-1] != i+1:
            cnt += 1
    if cnt >= 2:
        ans = "NO"
        break
    
print(ans)

Submission status: Wrong Answer

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

count = 0

for i in range(n):
  if ls[i] == i+1:
    continue
  else:
    count +=1
    if count >=2:
      break
    if ls[ls[i]-1]==i+1:
      ls[ls[i]-1] = ls[i]
      ls[i] = i+1

    else:
      count+=1
print(ls)
if count>=2:
  print("NO")
else:
  print("YES")

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
a = list(map(int, input().split()))
a_sorted = sorted(a)
cant = True
for i in range(n):
	if a == a_sorted:
		cant = False
		break
	a_c = copy.copy(a)
	for j in range(n):
		if i <= j:
			continue
		a_c[i],a_c[j] = a_c[j],a_c[i]
		if a_c == a_sorted:
			cant = False

if cant:
	print("NO")
else:
	print("YES")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(str, input().split()))
p_sort = sorted(p)
flag = False

for i in range(n):
    for j in range(n):
        p_tmp = p[:]
        tmp = p_tmp[i]
        p_tmp[i] = p_tmp[j]
        p_tmp[j] = tmp
        for k in range(n):
            if "".join(p_tmp) == "".join(p_sort):
                flag = True
        if flag:
            break
    if flag:
        break

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

Submission status: Wrong Answer

Solution code:
n=int(input())
p=list(map(int,input().split()))
ct=0
ct2=0
out=[]
for i in range(n-1):
    if p[i]>p[i+1]:
        ct+=1
        out.append(i)
if ct>2:print('NO')
elif ct<2:print('YES')
else:
    p[out[0]],p[out[1]+1]=p[out[1]+1],p[out[0]]
    for i in range(n-1):
        if p[i]>p[i+1]:
            ct2+=1
    if ct2==0:print('YES')
    else:print('NO')

Submission status: Wrong Answer

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

n = int(input())
t = input().split()
p = []
for i in t:
    p.append(int(i))

q = sorted(p)
c = 0
for i,j in enumerate(p):
    if p[i] != q[i]:
        c += 1
if c == 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
a=int(input())
l=list(map(int,input().split()))
ok=False
for i in range(len(l)-1):
    if sorted(l) == l:
        print("YES")
        break
    for j in range(i+1,len(l)):
        aux=l[i]
        l[i]=l[j]
        l[j]=aux
        if sorted(l) == l:
            ok=True
        else:
            aux = l[j]
            l[j] = l[i]
            l[i] = aux
    if ok == True:
        print("YES")
        break

Submission status: Wrong Answer

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

up = sorted(p)
cntup = 0
for i in range(n):
  if(up[i] == p[i]):
    cntup += 1


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

Submission status: Wrong Answer

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

cnt = 0

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


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

Submission status: Wrong Answer

Solution code:
A =input().split()
B =sorted(A)
count = 0
for i in range(len(B)):
    if A[i]!=B[i]:
        count +=1
if count>2:
    print('NO')
else:
    print('YES')

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

Submission status: Wrong Answer

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

up = 0
down = 0

mode = 0

for i in range(n-1):
    if p[i] <= p[i+1]:
        if not mode == 1:
            up += 1
            mode = 1
    else:
        if not mode == -1:
            down += 1
            mode = -1

    #print(mode,up,down)




if up == 1:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
from sys import stdin

readline = stdin.readline


def main():
    n, *p = map(int, open(0).read().split())
    count = 0
    if p.sort() == p:
        print('YES')
        return
    for a, b in zip(p, p[1:]):
        if a > b:
            count += 1
            if a > n:
                count += 1
            n = a
    print('YES' if count <= 2 else 'NO')


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

N_J=list(range(1,N+1))
ans='NO'
for i in range(N):
    for j in range(N):
        P_temp=P.copy()
        p_i=P[i]
        p_j=P[j]

        P_temp[i]=p_j
        P_temp[j]=p_i
        
        if P==N_J:
            ans='YES'
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int, input().split()))
count = 0
#print(p)

q = sorted(p)
#print(q)

for i in range(N):
  if p[i] != q[i]:
    count += 1
    
if count <= 1:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(_) for _ in input().split()]
flg = False
flg1 = True
for i in range(n):
    for j in range(n):
        flg1 = True
        q = p[:]
        q[i]=p[j]
        q[j]=p[i]
        for k in range(n):
            for l in range(n):
                if k < l and q[k]>q[l]:
                    flg1 = False
                    break
                if l==n-1 and k==n-1 and flg1:
                    flg = True
        
if flg:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

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):
      if A[k]!= B[k]:
        break
    else:
      print('YES')
      exit()
    A[i],A[j]= A[j],A[i]
        
print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())

S = input()
S = S.split()

P = list(map(int, S))

P_sort = sorted(P)
count = 0


for i in range(len(P)):
    if P_sort[i] != P[i]:
        count = count + 1

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

Submission status: Wrong Answer

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