Skip to content

Instantly share code, notes, and snippets.

@ianmuge
Last active June 5, 2020 09:50
Show Gist options
  • Save ianmuge/4375cec0dec7d44514dc43b1575e8670 to your computer and use it in GitHub Desktop.
Save ianmuge/4375cec0dec7d44514dc43b1575e8670 to your computer and use it in GitHub Desktop.
import sys
line = sys.stdin.readline()
N=line
smooth="YES"
arr=(sys.stdin.readline()).split(" ")
for key,val in enumerate(arr):
if key==0:
continue
val=int(val)
prev=int(arr[key-1])
if abs(val-prev)<=1:
continue
else:
smooth="NO"
break
print(smooth)

An array of integers a is called smooth if the absolute value of the difference between any two adjacent elements is less than or equal to 1. You are given an array a. Check whether it is smooth and output "YES" if it is, or "NO" if it is not (quotes for clarity only).

The first line of the input contains an integer N - the number of elements in the array. 1 <= N <= 10. The second line of the input contains N integers - the elements of the array, separated with single spaces. 1 <= ai <= 10.

Example

input

5 3 4 4 5 4

output

YES

input

4 1 1 8 2

output

NO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment