The life goes up and down, just like nice sequences. Sequence t_1, t_2, ..., t_{n} is called nice if the following two conditions are satisfied:   t_{i} < t_{i} + 1 for each odd i < n;  t_{i} > t_{i} + 1 for each even i < n. 
For example, sequences (2, 8), (1, 5, 1) and (2, 5, 1, 100, 99, 120) are nice, while (1, 1), (1, 2, 3) and (2, 5, 3, 2) are not.
Bear Limak has a sequence of positive integers t_1, t_2, ..., t_{n}. This sequence is not nice now and Limak wants to fix it by a single swap. He is going to choose two indices i < j and swap elements t_{i} and t_{j} in order to get a nice sequence. Count the number of ways to do so. Two ways are considered different if indices of elements chosen for a swap are different.
-----Input-----
The first line of the input contains one integer n (2 ≤ n ≤ 150 000) — the length of the sequence.
The second line contains n integers t_1, t_2, ..., t_{n} (1 ≤ t_{i} ≤ 150 000) — the initial sequence. It's guaranteed that the given sequence is not nice.
-----Output-----
Print the number of ways to swap two elements exactly once in order to get a nice sequence.
-----Examples-----
Input
5
2 8 4 7 7
Output
2
Input
4
200 150 100 50
Output
1
Input
10
3 2 1 4 1 4 1 4 1 4
Output
8
Input
9
1 2 3 4 5 6 7 8 9
Output
0
-----Note-----
In the first sample, there are two ways to get a nice sequence with one swap:   Swap t_2 = 8 with t_4 = 7.  Swap t_1 = 2 with t_5 = 7. 
In the second sample, there is only one way — Limak should swap t_1 = 200 with t_4 = 50.
def get_bit(diff, i):
    return 1 if ((i%2==1 and diff<=0) or (i%2==0 and diff>=0)) else 0

def swap_(i, j, a):
    temp  = a[i]
    a[i]  = a[j]
    a[j]  = temp
    
def swap(i, j, n, a, mask, S):
    change = 0
    swap_(i, j, a)
    set_index = set([i, j])
    
    if i<n-1:
        set_index.add(i+1)
    
    if j<n-1:
        set_index.add(j+1)
    
    for index in set_index:
        if index > 0:
            diff    = a[index] - a[index-1] 
            bit_    = get_bit(diff, index)
            change += bit_ - mask[index]
        
    swap_(i, j, a)    
    if S + change == 0:
        return 1
    return 0    

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

diff  = [-1] + [x-y for x, y in zip(a[1:], a[:-1])]
mask  = [get_bit(diff[i], i) for i in range(n)] 

S = sum(mask)
first = -1
for i, x in enumerate(mask):
    if x == 1:
        first = i
        break
        
cnt = 0
for second in range(n):
    if swap(first, second, n, a, mask, S) == 1:
        cnt += 1
    
    if first != 0 and swap(first-1, second, n, a, mask, S) == 1:
        cnt += 1
    
if first!=0 and swap(first-1, first, n, a, mask, S) == 1:
    cnt-=1
    
print(cnt)    

#9
#1 2 3 4 5 6 7 8 9

#10
#3 2 1 4 1 4 1 4 1 4

#4
#200 150 100 50

#5
#2 8 4 7 7

def get_bit(diff, i):
    return 1 if ((i%2==1 and diff<=0) or (i%2==0 and diff>=0)) else 0

def swap_(i, j, a):
    temp  = a[i]
    a[i]  = a[j]
    a[j]  = temp
    
def swap(i, j, n, a, mask, S):
    change = 0
    swap_(i, j, a)
    set_index = set([i, j])
    
    if i<n-1:
        set_index.add(i+1)
    
    if j<n-1:
        set_index.add(j+1)
    
    for index in set_index:
        if index > 0:
            diff    = a[index] - a[index-1] 
            bit_    = get_bit(diff, index)
            change += bit_ - mask[index]
        
    swap_(i, j, a)    
    if S + change == 0:
        return 1
    return 0    

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

diff  = [-1] + [x-y for x, y in zip(a[1:], a[:-1])]
mask  = [get_bit(diff[i], i) for i in range(n)] 

S = sum(mask)
first = -1
for i, x in enumerate(mask):
    if x == 1:
        first = i
        break
        
cnt = 0
for second in range(n):
    if swap(first, second, n, a, mask, S) == 1:
        cnt += 1
    
    if first != 0 and swap(first-1, second, n, a, mask, S) == 1:
        cnt += 1
    
if first!=0 and swap(first-1, first, n, a, mask, S) == 1:
    cnt-=1
    
print(cnt)    

#9
#1 2 3 4 5 6 7 8 9

#10
#3 2 1 4 1 4 1 4 1 4

#4
#200 150 100 50

#5
#2 8 4 7 7
