func_code_string: #include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   const long long maxn = 4e5 + 1e2;   struct Node {     long long pos, val;   };   long long l[maxn], r[maxn];   long long n, m;   long long a[maxn];   Node s[maxn];   long long top;   long long ans;   long long pos[maxn];   bool in(long long x, long long l, long long r) { return (x >= l) && (x <= r); }   signed main() {     n = read();     for (long long i = 1; i <= n; i++) a[i] = read(), pos[a[i]] = i;     l[1] = 1;     top = 1;     s[1].val = a[1];     s[1].pos = 1;     for (long long i = 2; i <= n; i++) {       while (top >= 1 && s[top].val <= a[i]) top--;       if (!top)         l[i] = 1;       else         l[i] = s[top].pos + 1;       s[++top].val = a[i];       s[top].pos = i;     }     r[n] = n;     top = 1;     s[1].val = a[n];     s[1].pos = n;     for (long long i = n - 1; i >= 1; i--) {       while (top >= 1 && s[top].val < a[i]) top--;       if (!top)         r[i] = n;       else         r[i] = s[top].pos - 1;       s[++top].val = a[i];       s[top].pos = i;     }     for (long long i = 1; i <= n; i++) {       long long mx = a[i];       if (i - l[i] < r[i] - i) {         for (long long j = l[i]; j < i; j++) {           if (in(pos[mx - a[j]], i, r[i])) ans++;         }       } else {         for (long long j = i + 1; j <= r[i]; j++) {           if (in(pos[mx - a[j]], l[i], i)) ans++;         }       }     }     cout << ans;     return 0;   }   