#include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#include <fstream>
#include <cassert>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include <sys/resource.h>
using namespace std;
using namespace __gnu_pbds;
#ifdef loc
template<class T, class U> ostream &operator<<
(ostream &out,
const pair<T, U> &a) {
out << "[" << a.first << " " << a.second << "]";
return out;
}
template<class T>
ostream &operator<<(ostream &out,
const vector<T> &a) {
out << "[ ";
for(auto &it : a) {
out << it << " ";
}
out << "]";
return out;
}
template<class T> ostream &operator<<(ostream &out, const set<T> &a) {
out << "[ ";
for(auto &it : a) {
out << it << " ";
}
out << "]";
return out;
}
template<class T>
ostream &operator<<(ostream &out,
const multiset<T> &a) {
out << "[ ";
for(auto &it : a) {
out << it << " ";
}
out << "]";
return out;
}
template<class T, class U>
ostream &operator<<(ostream &out,
const map<T, U> &a) {
for(auto &it : a) {
out << it.first << " -> " << it.second << " | ";
}
return out;
}
template<class T, class U>
ostream &operator<<(ostream &out,
const multimap<T, U> &a) {
for(auto &it : a) {
out << it.first << " -> " << it.second << " | ";
}
return out;
}
#define pra(a, n) cerr << #a << " : "; for(int i = 0; i <= n; ++i) cerr << a[i] << " "; cerr << endl;
#define praa(a, n, m) cerr << #a << " : " << endl; for(int i = 0; i <= n; ++i) { for(int j = 0; j <= m; ++j) cerr << a[i][j] << " "; cerr << endl; }
#define pr(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define prl() cerr << __LINE__ << ": " << __PRETTY_FUNCTION__ << endl;
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1,
Args &&... args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names,
comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#define gc getchar
#else
#define pr(...)
#define pra(a, n)
#define praa(a, n, m)
#define prl()
#define gc getchar
#define endl '\n'
#endif
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<pair<int, int>>> vvpii;
typedef vector<ll> vl;
typedef vector<vector<ll>>vvl;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<pair<ll, ll>>> vvpll;
template<typename T, typename U> static void amin(
T &x, U y) {
if(y < x) {
x = y;
}
}
template<typename T, typename U> static void amax(
T &x, U y) {
if(x < y) {
x = y;
}
}
#define inc_stack_limit const rlim_t kStackSize = 64 * 1024 * 1024; struct rlimit rl; rl.rlim_cur = kStackSize; setrlimit(RLIMIT_STACK, &rl);
#define sz(a) int((a).size())
#define all(a) (a).begin(),(a).end()
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define rep(i, s, n) for(int i = s; i <= (n); ++i)
#define rev(i, n, s) for(int i = (n); i >= s; --i)
#define fore(x, a) for(auto &&x : a)
#define fill(a, x) memset((a), (x), sizeof(a))
const double eps = 1e-6;
#define tcase int __T; cin >> __T; rep(Tc, 1, __T)
#define ass(n, l, r) assert(n >= l and n <= r)
#define mod 1000000007
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
typedef long long llint;
inline int add(int a, int b, int m = mod) {
a += b;
if(a >= m) {
a -= m;
}
if(a < 0) {
a += m;
}
return a;
}
inline int mul(int a, int b, int m = mod) {
int ret = (int)(((ll)a * (ll)b) % m);
if(ret < 0) {
ret += m;
}
return ret;
}
ll po(ll a, ll b, ll m = mod) {
ll res = 1;
a %= m;
//assert(b >= 0);
for(; b; b >>= 1) {
if(b & 1) {
res = (res * a) % m;
}
a = (a * a) % m;
}
return res;
}
inline int ri() {
int c = gc();
int ret = 0;
while(c < '0' || c > '9') {
c = gc();
}
while(c >= '0' && c <= '9') {
ret = 10 * ret + c - 48;
c = gc();
}
return ret;
}
#define N 200005
//actual code starts here:
int a[N];
bool b[N];
int main() {
boost;
int n;
cin >> n;
rep(i, 1, n) {
cin >> a[i];
}
int mx = 0;
int mn = a[1];
rep(i, 2, n) {
mx = max(mx, a[i] - mn);
mn = min(mn, a[i]);
}
int nm = a[1];
rep(i, 2, n) {
if(a[i] - nm == mx) {
b[i] = 1;
}
nm = min(nm, a[i]);
}
ll pr = -mod;
int four = 0;
int ans = 0;
rev(i, n, 1) {
if(b[i]) {
if(a[i] > pr) {
four = 0;
pr = a[i];
}
four++;
}
if(pr - a[i] == mx) {
if(four) {
ans++;
four--;
}
}
}
cout << ans << endl;
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxsaXN0PgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8ZGVxdWU+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8Yml0c2V0PgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPG51bWVyaWM+CiNpbmNsdWRlIDx1dGlsaXR5PgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI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