/**
* author: Binoy Barman
* created: 2025-04-07 12:36:40
**/
#include<bits/stdc++.h>
#ifdef LOCAL
#include "algo/debug.h"
#else
#define dbg(...) 42
#endif
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = 2e9;
#define int long long
#define nl '\n'
#define all(v) v.begin(), v.end()
#define clg(x) (32 - __builtin_clz(x))
#define Testcase_Handler int tts, tc = 0; cin >> tts; hell: while(tc++ < tts)
#define uniq(v) sort(all(v)), v.resize(distance(v.begin(), unique(v.begin(), v.end())))
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> istream& operator>>(istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename A, typename B> istream& operator>>(istream& in, pair<A, B>& p) {in >> p.first >> p.second; return in;};
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {bool first = true;for(auto &x : a) {if(!first) out << ' ';first = false;out << x;}return out;};
namespace Dark_Lord_Binoy {
inline void init() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
}
const int N = 1e5 + 9;
long long a[N];
class PersistentSegTree {
private:
struct Node {
int val;
Node *lc, *rc;
Node() : val(0) { lc = rc = NULL; }
Node(int _val) : val(_val) { lc = rc = NULL; }
} *ver[N];
inline int combine(int a, int b) {
return a + b;
}
inline void pull(Node *n) {
n->val = n->lc->val + n->rc->val;
}
Node* build(int b, int e) {
if(b == e) {
Node *n = new Node(); // in leaf
return n;
}
Node *n = new Node();
int mid = (b + e) >> 1;
n->lc = build(b, mid);
n->rc = build(mid + 1, e);
pull(n);
return n;
}
Node* update(Node *n, int b, int e, int i, int v) {
if(b == e) {
Node *cn = new Node(n->val + v); // new leaf
return cn;
}
Node *cn = new Node();
int mid = (b + e) >> 1;
if(i <= mid) {
cn->lc = update(n->lc, b, mid, i, v);
cn->rc = n->rc;
} else {
cn->lc = n->lc;
cn->rc = update(n->rc, mid + 1, e, i, v);
}
pull(cn);
return cn;
}
int query1(Node *R, Node *L, int b, int e, int k) {
if(b == e) return b;
int mid = (b + e) >> 1;
int leftval = R->lc->val - L->lc->val;
if(k <= leftval) {
return query1(R->lc, L->lc, b, mid, k);
} else {
return query1(R->rc, L->rc, mid + 1, e, k - leftval);
}
}
int query2(Node *R, Node *L, int b, int e, int i, int j) {
if(i > e || b > j) return 0; //return null
if (i <= b && e <= j) return R->val - L->val;
int mid = (b + e) >> 1;
return combine(query2(R->lc, L->lc, b, mid, i, j), query2(R->rc, L->rc, mid + 1, e, i, j));
}
const int tL, tR; // total [1, n]
vector<Node *> nodes; // store all created nodes, to delete
public:
PersistentSegTree(int b, int e) : tL(b), tR(e) { ver[0] = build(b, e); }
~PersistentSegTree() {}
// takes current version, generates new version from prev for current prefix, pos: freq+=v
void point_upd(int cur_ver, int pos, int v) {
ver[cur_ver] = update(ver[cur_ver - 1], tL, tR, pos, v);
}
// takes r and (l-1)th version nodes, finds k-th minimum in range [l, r]
int find_kth(int r_ver, int l_ver, int k) {
return query1(ver[r_ver], ver[l_ver], tL, tR, k);
}
// takes r and (l-1)th version nodes, finds number of elements in range [i, j]
int find_elements(int r_ver, int l_ver, int i, int j) {
return query2(ver[r_ver], ver[l_ver], tL, tR, i, j);
}
};
int32_t main() {
Dark_Lord_Binoy::init();
int n;
cin >> n;
PersistentSegTree t(0, n - 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
t.point_upd(i, a[i], 1);
}
int ans = 0;
for (int i = 1; i <= n; i++) {
int l = t.find_elements(i - 1, 0, 0, a[i]);
int r = t.find_elements(n, i, a[i], n - 1);
if(l >= a[i] || r >= a[i]) {
ans++;
}
}
cout << ans << nl;
dbg(_Time_);
return 0;
}