def main(): import sys input = sys.stdin.read().split() n = int(input[0]) a = list(map(int, input[1:n+1])) valid = 0 for i in range(n): for j in range(i+1, n): # Check all triplets affected by i and j # Create a copy to test the swap a_swapped = a.copy() a_swapped[i], a_swapped[j] = a_swapped[j], a_swapped[i] # Check all triplets is_valid = True for k in range(n-2): x, y, z = a_swapped[k], a_swapped[k+1], a_swapped[k+2] if y != max(x, y, z) and y != min(x, y, z): is_valid = False break if is_valid: valid += 1 print(valid) if __name__ == "__main__": main()