Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- N = int(input())
- A = list(map(int, input().split()))
- B = []
- T = []
- res = 'YES'
- n = 1
- while len(A) != 0:
- if n in A:
- k = A.index(n)
- B.append(n)
- N = A[:k + 1]
- for i in N:
- A.remove(i)
- T += N[:k]
- n += 1
- else:
- k = T.index(n)
- if k != len(T) - 1:
- res = 'NO'
- break
- else:
- T.pop()
- B.append(n)
- n += 1
- if res == 'YES' and T == sorted(T, reverse = True):
- res = 'YES'
- else:
- res = 'NO'
- print(res)
Advertisement
Add Comment
Please, Sign In to add comment