func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     char c;     bool nega = 0;     while ((!isdigit(c = getchar())) && (c !=  - ))       ;     if (c ==  - ) {       nega = 1;       c = getchar();     }     x = c - 48;     while (isdigit(c = getchar())) x = x * 10 + c - 48;     if (nega) x = -x;   }   template <typename T>   inline void writep(T x) {     if (x > 9) writep(x / 10);     putchar(x % 10 + 48);   }   template <typename T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     writep(x);   }   template <typename T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   int n, h[300003], dp[300003];   set<int> st[300003];   vector<pair<int, int> > ve;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int i, j;     cin >> n;     for (i = 0; i < n; i++) cin >> h[i];     pair<int, int> t;     ve.push_back({0, h[0]});     for (i = 1; i < n; i++) {       t = ve.back();       while (h[i] <= t.second) {         st[t.first].insert(i);         ve.pop_back();         if (ve.empty()) break;         t = ve.back();       }       ve.push_back({i, h[i]});     }     ve.clear();     ve.push_back({0, h[0]});     for (i = 1; i < n; i++) {       t = ve.back();       while (h[i] >= t.second) {         st[t.first].insert(i);         ve.pop_back();         if (ve.empty()) break;         t = ve.back();       }       ve.push_back({i, h[i]});     }     ve.clear();     ve.push_back({n - 1, h[n - 1]});     for (i = n - 2; i >= 0; i--) {       t = ve.back();       while (h[i] >= t.second) {         st[i].insert(t.first);         ve.pop_back();         if (ve.empty()) break;         t = ve.back();       }       ve.push_back({i, h[i]});     }     ve.clear();     ve.push_back({n - 1, h[n - 1]});     for (i = n - 2; i >= 0; i--) {       t = ve.back();       while (h[i] <= t.second) {         st[i].insert(t.first);         ve.pop_back();         if (ve.empty()) break;         t = ve.back();       }       ve.push_back({i, h[i]});     }     dp[n - 1] = 0;     set<int>::iterator it;     for (i = n - 2; i >= 0; i--) {       dp[i] = 0x3f3f3f3f;       for (it = st[i].begin(); it != st[i].end(); it++) {         dp[i] = ((dp[i]) < (dp[*it] + 1) ? (dp[i]) : (dp[*it] + 1));       }     }     cout << dp[0] << endl;     return 0;   }   