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:
N=int(input())
p=list(map(int,input().split()))
s=sorted(p)
flag=0
for i in range(N):
  for j in range(i+1,N):
    tmp=p
    tmp[i],tmp[j]=tmp[j],tmp[i]
    if tmp==s:
      flag=1
print('NYOE S'[flag::2])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
count=0
for i in range(n):
  if l[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()))
s = sorted(p)
count = 0

for i, j in zip(p, s):
    if i != j:
        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()))
s = sorted(p)
count = 0

for i, j in zip(p, s):
    if i != j:
        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()))
s = sorted(p)
count = 0

for i, j in zip(p, s):
    if i != j:
        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()))
c = 0
for i in range(N):
    d = int(p[i] != i + 1)
    c = c + d
if c == 0 or c == 2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
count=0
for i in range(1,n+1):
            if i !=l[i-1]:
                        count+=1
                     
if count<=1:
            print('Yes')
else:
            print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
count=0
for i in range(n):
            if i !=l[i-1]:
                        count+=1
                     
if count<=1:
            print('Yes')
else:
            print('No')

Submission status: Wrong Answer

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

if p == list(range(1, N+1)):
    print('YES')
else:
    for i, n in enumerate(p):
        if n != i+1:
            break
    j = p[p.index(i+1)]
    p[p.index(i+1)] = n
    p[i] = j
    if p == list(range(1, N+1)):
        print('Yes')
    else:
        print('NO')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

v = sum(1 for i,j in zip(range(1, N+1), p) if i!=j)
print("Yes" if v<=2 else "No")

Submission status: Wrong Answer

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

for a in range(N):
    if list[a] != list_sort[a]:
        count += 1


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

Submission status: Wrong Answer

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

for a in range(1, N):
    if list[a-1] > list[a]:
        count += 1


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

Submission status: Wrong Answer

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

for a in range(1, N):
    if list[a-1] > list[a]:
        count += 1


if count == 1 or count == 0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
import sys
a=list(input())
b=a
b.sort()
c=0
for i in range(N):
  if a[i]!=b[i]:
    c+=1
    if c>=2:
      d='NO'
      sys.exit()
print('YES')

Submission status: Wrong Answer

Solution code:
N=int(input())
import sys
a=list(input())
b=a
b.sort()
c=0
for i in range(N):
  if a[i]!=b[i]:
    c+=1
    if c>=2:
      d='No'
      sys.exit()
print('Yes')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0
for i in range(len(pl)-1):
    if pl[i] != pl[i+1]-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
q = sorted(p)


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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
p = input().split()
p = [int(num) for num in p]
q = sorted(p)
if p == q:
  print("Yes")
else:
  t = 0
  for i in range(N):
    if p[i] != q[i]:
      t += 1
  if t == 2:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = input().split()
p = [int(num) for num in p]
if p == sorted(p):
  print("Yes")
else:
  q = sorted(p)
  t = 0
  for i in range(N):
    if p[i] == q[i]:
      t += 1
  if t == 2:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = input().split()
p = [int(num) for num in p]
if p == sorted(p):
  print("Yes")
else:
  t = 0
  for i in range(N):
    for j in range(N):
      pi, pj = p[i], p[j]
      p[i], p[j] = pj, pi
      if p == sorted(p):
        t += 1
      else:
        continue
  if t == 0:
    print("No")
  else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = input().split()
p = [int(num) for num in p]
if p == sorted(p):
  print("Yes")
else:
  t = 0
  for i in range(N-1):
    if p[i+1] == p[i] + 1:
      continue
    else:
      t += 1
    print(t)
  if t == 2 or t == 3 or t == 4:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = input().split()
p = [int(num) for num in p]
if p == sorted(p):
  print("Yes")
else:
  t = 0
  for i in range(N-1):
    if p[i+1] == p[i] + 1:
      continue
    else:
      t += 1
    print(t)
  if t == 3 or t == 4:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = input().split()
p = [int(num) for num in p]
if p == sorted(p):
  print("Yes")
else:
  t = 0
  for i in range(N-1):
    if p[i+1] == p[i] + 1:
      continue
    else:
      t += 1
    print(t)
  if t >= 2:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = input().split()
p = [int(num) for num in p]
if p == sorted(p):
  print("Yes")
else:
  t = 0
  for i in range(N-1):
    if p[i+1] == p[i] + 1:
      continue
    else:
      t += 1
  if t == 2:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
p = input().split()
p = [int(num) for num in p]
if p == sorted(p):
  print("Yes")
else:
  t = 0
  for i in range(N-1):
    if p[i+1] == p[i] + 1:
      t += 1
    else:
      continue
  if t == 2:
    print("Yes")
  else:
    print("No")

Submission status: Wrong Answer

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

q = sorted(p)
ans = 0
for _p, _q in zip(p, q):
    if _p != _q:
        ans += 1

print("Yes" if ans <= 2 else "No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
*p,=map(int,input().split())
wng=0
a=sorted(p)
for i in range(n):
	if a[i] != p[i]:
		wng += 1
print('No' if wng >2 else 'Yes')

Submission status: Wrong Answer

Solution code:
from copy import copy
n=int(input())
*a,=map(int,input().split())
f=[i for i in range(1,n+1)]
for i in range(n):
	x=copy(a)
	for j in range(i):
		x[i],x[j]= x[j],x[i]
		if x == f:
			print('Yes')
			exit(0)
print('No')

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

num = 0
for i in range(len(p)-1):
  if p[i+1] - p[i] < 0:
    num += 1
if num < 3:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

Q=[i for i in range(1,N+1)]

count=0
for i in range(N):
  if P[i]!=Q[i]:
    count+=1
if count>=3:
  print("No")
else:print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = [int(i) for i in input().split()]
x = p.copy()
x.sort()
pma = max(p)
pmi = min(p)
p[0] = pmi
p[-1] = pma
if x == p:
    print('YES')
else:
    print("NO")

Submission status: Wrong Answer

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

P=sorted(A)
cnt=0

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

print("YES" if cnt <= 1 else "NO")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
ll=sorted(l)
cnt=0
for l1,l2 in zip(l,ll):
  if l1 != l2:
    cnt+=1
    
print("Yes" if cnt <= 2 else "No")

Submission status: Wrong Answer

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

sorted_p = sorted(p_i)
count = 0

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

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

Submission status: Wrong Answer

Solution code:

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

srt = sorted(a)

res = "Yes"
cnt = 0
for c,s in zip(a,srt):
    if c != s:
        cnt += 1 
    if cnt > 2:
        res = "No"
        break
print(res)

Submission status: Wrong Answer

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

count=0
for i in range(len(p)):
    if p[i]!=pp[i]:
        count+=1
if count==2 or count==0:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#135 b 昇降順だ
n=int(input())
p=list(map(int,input().split()))
ans="NO"
cnt=0
for i in range(n):
    if p[i]!=(i+1):
        cnt+=1
if cnt==2:
    ans="YES"
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0
for i in range(N-1):
    if P[i] - P[i + 1] == 1:
        cnt += 1
if cnt == 0 or cnt == 2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())

lstI = list(map(int, input().split()))
sortedList = sorted(lstI)

count = 0
for i in range(0, len(lstI)):
    if lstI[i] != sortedList[i]:
        count += 1

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

Submission status: Wrong Answer

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

l=list(range(1,n+1))
cnt=0

for i in range(n):
    if l[i]!=int(p[i]):
        cnt+=1
print(cnt)
if cnt<=2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

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

l=list(range(1,n+1))
cnt=0

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

Submission status: Wrong Answer

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

l=list(range(n,0,-1))
cnt=0

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int, input().split()))
la = list(range(1,N+1))
cnt1 = 0
cnt2 = 0
while cnt1 < N-1:
    if P[cnt1] == la[cnt1]:
        cnt2 += 1
    cnt1 += 1
if cnt2 >= N-2:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int, input().split()))
la = list(range(1,N+1))
cnt1 = 0
cnt2 = 0
while cnt1 < N-1:
    if P[cnt1] == la[cnt1]:
        cnt2 += 1
    cnt1 += 1
if cnt2 >= N-2:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=sorted(A)
count=0
for i in range(N):
    if A[i]!=B[i]:
        count+=1
if count<=2:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    num_list = list(map(int,input().split()))

    count = 0

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
S = list(map(int,input().split()))
B = list(reversed(S))
B.sort()
count = 0
for i in range(len(S)):
    if S[i] != B[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(input().split())
T = sorted(S)
count = 0
for i in range(N):
  if S[i]!=T[i]:
    count += 1
if count ==2 or count == 0:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

def solve():
  # 昇順にソートしたリストを生成
  p_sorted = sorted(p, reverse=False)
  cnt = 0
  for i in range(0, n):
    if p[i] != p_sorted[i]:
      cnt += 1

    if cnt >= 3:
      print("No")
      return

  print("Yes")
  return


if __name__ == "__main__":
  solve()

Submission status: Wrong Answer

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


if __name__=="__main__":
    main()

Submission status: Wrong Answer

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


if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(map(int, input().split()))
Q = sorted(P)
 
flag = True
buf = 0
for i, p in enumerate(P):
    if buf > p:
        flag = False
        break
    buf = p

P[i], P[p-1] = P[p-1], P[i]

if P == Q:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
print("YES")

Submission status: Wrong Answer

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

flag = True
buf = 0
for p in P:
    if buf > p:
        flag = False
        break
    buf = p

if flag:
    print("YES")

else:
    for i in range(N):
        if P[i] == 1:
            break
    
    P[i], P[0] = P[0], P[i]

    flag = True
    buf = 0
    for p in P:
        if buf > p:
            flag = False
            break
        buf = p

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

Submission status: Wrong Answer

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

if P == P_sorted:
    print("YES")
else:
    i = P.index(1)
    P[0], P[i] = P[i], P[0]

    if P == P_sorted:
        print("YES")
    else:
        print("NO")

Submission status: Wrong Answer

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

i = P.index(1)
P[0], P[i] = P[i], P[0]

if P == P_sorted:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
n = int(input())
p = input().split()
q = sorted(p)

cnt = 0
for i, j in zip(p, q):
  if i != j: cnt+=1
    
if cnt == 2 or cnt == 0:
  print("YES")
else:
  print("NO")

Submission status: Wrong Answer

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

count = 0
for p, s in zip(P, sorted(P)):
  if p != s:
    count += 1

ans = 'YES' if count <= 2 else 'No'
print(ans)

Submission status: Wrong Answer

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

a = range(1, n+1)
count = n

for i in range(n):
  if p[i]==a[i]:
    n -= 1

if n==2 or n==0:
  print("Yes")
else:
  print("No")

Submission status: Wrong Answer

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

    cnt = 0
    for i in range(n):
        if p[i] != i+1:
            cnt += 1
        if cnt > 2:
            break
    if cnt == 0 or cnt == 2:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = read().decode('utf8').split()
P_N = sorted(P)

# print(list(x != y for x, y in zip(P, P_N)))

S = sum(x != y for x, y in zip(P, P_N))
# print(S)
print('YES' if S == 0 or S == 2 else 'NO')

Submission status: Wrong Answer

Solution code:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = read().split()
P_N = sorted(P)

# print(list(x != y for x, y in zip(P, P_N)))

S = sum(x != y for x, y in zip(P, P_N))
# print(S)
print('YES' if S == 0 or S == 2 else 'NO')

Submission status: Wrong Answer

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

count=0

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

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

Submission status: Wrong Answer

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

for i in range(n):
    buf=i+1
    if buf != p[i]:
        p[p.index(buf)]=p[i]
        p[i]=buf
        break

if pp==p:
    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+1):
    if i == p[i-1]:
        c += 1
if c == 0 or c == 2:
    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+1):
    if i == p[1]:
        c += 1
if c == 0 or c == 2:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

for i in range(n):
    p[i]-=1
cnt=0
ans="Yes"
for i,p_i in enumerate(p):
    if i==p_i:
        continue
    cnt+=1
    if cnt>1:
        ans="No"
        break
    for j,p_j in enumerate(p):
        if i==p_j:
            p[j]=p_i
            p[i]=p_j
            break

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
is_fail = False
switched = False
for i in range(N):
    if A[i] == i+1:
        continue
    elif A[A[i]-1] == i+1 and not switched:
        switched = True
    else:
        is_fail = True
        break

if not is_fail:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
is_fail = False

for i in range(N):
    if A[i] != i+1 and A[A[i]-1] != i+1:
        is_fail = True
        break

if not is_fail:
    print("YES")
else:
    print("NO")

Submission status: Wrong Answer

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

    diff = 0
    for i in range(N):
        if (i+1) != p[i]:
            diff += 1
    if (diff == 2) | (diff == 0):
        return "Yes"
    return "No"
if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

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

p_sorted = sorted(p)

ans = 0

for i in range(n):
  if p_sorted[i] != p[i]:
    ans += 1
  else:
    pass

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main(li):
    count = 0
    for i in range(len(li)):
        if li[i] != i + 1:
            count += 1
    if count in [0,2]:
      return True
    else:
      return False
 
 
if __name__ == '__main__':
    li = list(map(int, input().split()))
    if main(li):
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
def main(nums, count):
    down_list = []
    for i in range(len(nums)-1):
        if nums[i] > nums[i + 1]:
            down_list.append(i)
    if len(down_list) > 2:
        return False
    elif len(down_list) == 2:
        if count >= 1:
            return False

        nums[down_list[0]], nums[down_list[1]
                                 ] = nums[down_list[1]], nums[down_list[0]]
        count += 1
        main(nums, count)
    else:
        return True


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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

SortedP = P.copy()
SortedP.sort()
count=0
for i in range(N):
    if(P[i]!=SortedP[i]):
        count = count + 1
    if(count>2):
        print("NO")
        break
else:print("Yes")

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = 0
for k in range(1,n+1):
    if k >= 1 and k <= 9:
        cnt += 1
    elif k >= 100 and k <= 999:
        cnt += 1
    elif k >= 10000 and k <= 99999:
        cnt += 1
print(cnt)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

c = 0
for i in range(N-1):
    if not P[i+1] - P[i] == 1:
        c += 1

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

Submission status: Wrong Answer

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

for i in range(len(p)):
    for j in range(i+1, len(p)):
        if p[i] > p[j]:
            tmp = min(tmp, p[j])
    if tmp != 100:
        p[i], p[j] = p[j], p[i]
        break
if p == sorted(p):
    print('YES')
else:
    print('NO')