1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>  // std::cout
#include <algorithm> // std::sort
#include <vector>    // std::vector
#include <set>
#include <cmath>
#include <string>
#include <map>
#include <cassert>
#include <functional>
#include <tuple>
#include <numeric>
#include <queue>
#include <list>
#include <cassert>

using namespace std;

#define MAXN 50002
#define MAXA 1000000000

int n, t[MAXN];

int getSgn(int a)
{
  if (a > 0)
    return 1;
  if (a < 0)
    return -1;
  return 0;
}

int changesWhenFirstSgn(int firstSgn)
{
  int res = 0, prevT = t[0];
  for (int i = 1, perfectSgn = firstSgn; i < n; ++i, perfectSgn *= -1)
  {
    bool differentSgn = perfectSgn != getSgn(t[i] - prevT);
    res += differentSgn ? 1 : 0;
    prevT = differentSgn ? perfectSgn * MAXA : t[i];
  }
  return res;
}

int main()
{
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &t[i]);
  printf("%d", min(changesWhenFirstSgn(1), changesWhenFirstSgn(-1)));
  return 0;
}