def longest_subseq_with_diff_one(arr, n):
	 
	dp = [1 for i in range(n)] 
	for i in range(n): 
		for j in range(i): 
			if ((arr[i] == arr[j]+1) or (arr[i] == arr[j]-1)): 
				dp[i] = max(dp[i], dp[j]+1) 
	result = 1
	for i in range(n): 
		if (result < dp[i]): 
			result = dp[i] 
	return result
def longest_subseq_with_diff_one(arr, n):
    dp = [1 for i2 in range(n)]
    for i2 in range(n):
        for j in range(i2):
            if (arr[i2] == arr[j] + 1) or (arr[i2] == arr[j] - 1):
               
                dp[i2] = max(dp[i2], dp[j] + 1)
    result = 1
    for i2 in range(n):
        if result < dp[i2]:
            result = dp[i2]
    return result