Problem:
D - カーペット
総合研究7号館の引越しに伴い，研究室にカーペットを敷くことになった．
    この問題では研究室を上から見たときの床を，二次元平面上の多角形とみなす．
    床の形状を表す要素数
N
の数列
\{a_i\}
が与えられる．
R_i
を，左下の座標が
(i,0)
で右上の座標が
(i+1,a_i)
である各辺がx軸またはy軸に平行な長方形の境界及び内部領域とする．
    このとき，床を表す多角形は
R_1 ∪ R_2 ∪ R_3 ∪ … ∪ R_N
によって表される．
    
    カーペットは長方形であればどんな大きさのものを何枚でも用意することができる．
    以下の条件を満たすようにカーペットを配置し，研究室の床を全て覆いつくしたい．
カーペットは研究室からはみ出してはいけない．
カーペットはいくらでも重ねて敷くことが可能である．このとき，カーペットの厚さは無視する．
カーペットを切り離して利用することはできない．
カーペットは各辺がx軸またはy軸に平行になるように配置しなければならない．
研究室の床を覆い尽くすために必要なカーペットの最小数を求めよ．
図D-1. 入力例1の床
図D-2. 入力例2の床
入力形式
入力は以下の形式で与えられる．
N
a_1
…
a_N
出力形式
研究室の床を覆い尽くすために必要なカーペットの最小数を１行に出力せよ．
制約
1 \leq N \leq 2 \times 10^5
1 \leq a_i \leq 10^9
入力値はすべて整数である．
入出力例
入力例1
3
1 2 1
出力例1
2
入力例2
10
1 2 2 1 3 4 3 1 2 2
出力例2
5

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main(){
  int n;
  cin >> n;
  if(n==1){
    cout << 1 << endl;
    return 0;
  }
  int cnt=0;
  int a,ca=0;
  stack<int> sk;
  for(int i=0;i<=n;i++){
    if(i<n) cin >> a;
    else a=0;
    if(ca<a){ 
      ca=a;
      sk.push(a);
    }
    else if(ca>a){
      ca=a;
      cnt++;
      sk.pop();
      while(!sk.empty()&&(sk.top()>a)){
        cnt++;
        sk.pop();
      }
      if(sk.empty()||(sk.top()<a)) sk.push(a);
      
    }
  }
  cout << cnt << endl;
  
  
}
accuracy: 1
time_ms: 40
memory_kb: 4180
final_rank: 6

code_snippet: #include <vector>
#include <iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		while (!v.empty() && v.back() > a[i]) {
			v.pop_back();
		}
		ans += int(v.empty() || v.back() < a[i]);
		v.push_back(a[i]);
	}
	cout << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 4824
final_rank: 8

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
 
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
 
#define MOD 1000000007
 
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
const double EPS = 1e-8, PI = acos(-1);
const double pi = 3.141592653589793238462643383279;
//ここから編集    
typedef string::const_iterator State;
ll GCD(ll a, ll b){
  return (b==0)?a:GCD(b, a%b);
}
ll LCM(ll a, ll b){
  return a/GCD(a, b) * b;
}
template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< 998244353 >;
template< typename T >
struct Combination {
  vector< T > _fact, _rfact, _inv;
 
  Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) {
    _fact[0] = _rfact[sz] = _inv[0] = 1;
    for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[sz] /= _fact[sz];
    for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
 
  inline T fact(int k) const { return _fact[k]; }
 
  inline T rfact(int k) const { return _rfact[k]; }
 
  inline T inv(int k) const { return _inv[k]; }
 
  T P(int n, int r) const {
    if(r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }
 
  T C(int p, int q) const {
    if(q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
 
  T H(int n, int r) const {
    if(n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};
 
ll modpow(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  if(x == 0) return 0;
  while(n) {
    if(n&1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
} 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}
template<typename T> 
struct BIT{
  int N;
  std::vector<T> node;
  BIT(){}
  BIT(int n){
    N = n;
    node.resize(N+10);
  }
  void build(int n) {
    N = n;
    node.resize(N+10);
  }
  /* a: 1-indexed */
  void add(int a, T x){
    for(int i=a; i<(int)node.size(); i += i & -i) node[i] += x;
  }

  /* [1, a] */
  T sum(int a){
    T res = 0;
    for(int x=a; x>0; x -= x & -x) res += node[x];
    return res;
  }

  /* [l, r] */
  T rangesum(int l, int r){
    return sum(r) - sum(l-1);
  }

  /* 
    a1+a2+...+aw >= valとなるような最小のwを返す
    @verify https://codeforces.com/contest/992/problem/E
  */
  int lower_bound(T val) {
    if(val < 0) return 0;

    int res = 0;
    int n = 1; 
    while (n < N) n *= 2;

    T tv=0;
    for (int k = n; k > 0; k /= 2) {
      if(res + k < N && node[res + k] < val){
        val -= node[res+k];
        res += k;
      }
    }
    return res+1; 
  }
};
struct UnionFind{
  std::vector<int> par;
  std::vector<int> siz;

  UnionFind(int sz_): par(sz_), siz(sz_) {
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  void init(int sz_){
    par.resize(sz_);
    siz.resize(sz_);
    for(int i=0; i<sz_; ++i) par[i] = i, siz[i] = 1;
  }

  int root(int x){
    if(x == par[x]) return x;
    return par[x] = root(par[x]);
  }

  bool merge(int x, int y){
    x = root(x), y = root(y);
    if(x == y) return false;
    if(siz[x] < siz[y]) std::swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(int x, int y){
    return root(x) == root(y);
  }

  int size(int x){
    return siz[root(x)];
  }
};
struct RollingHash{

    using ull = unsigned long long;
    const ull mod = (1ULL << 61) - 1;
    const ull MASK30 = (1ULL << 30) - 1;
    const ull MASK31 = (1ULL << 31) - 1;

    const ull MASK61 = mod;

    ull base;
    int n;
    vector<ull> hash, pow;

    RollingHash(const string &s)
    {
        random_device rnd;
        mt19937_64 mt(rnd());
        base = 1001;
        
        n = (int)s.size();
        hash.assign(n+1, 0);
        pow.assign(n+1, 1);
        
        for(int i=0; i<n; i++){
            hash[i+1] = calc_mod(mul(hash[i], base) + s[i]);
            pow[i+1] = calc_mod(mul(pow[i], base));
        }
    }

    ull calc_mod(ull x){
        ull xu = x >> 61;
        ull xd = x & MASK61;
        ull res = xu + xd;
        if(res >= mod) res -= mod;
        return res;
    }

    ull mul(ull a, ull b){
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        ull midu = mid >> 30;
        ull midd = mid & MASK30;
        return calc_mod(au * bu * 2 + midu + (midd << 31) + ad * bd);
    }

    //[l,r)のハッシュ値
    inline ull get(int l, int r){
        ull res = calc_mod(hash[r] + mod*3-mul(hash[l], pow[r-l]));
        return res;
    }
    //string tのハッシュ値
    inline ull get(string t){
        ull res = 0;
        for(int i=0; i<t.size(); i++){
            res = calc_mod(mul(res, base)+t[i]);
        }
        return res;
    }
    //string s中のtの数をカウント
    inline int count(string t) {
        if(t.size() > n) return 0;
        auto hs = get(t);
        int res = 0;
        for(int i=0; i<n-t.size()+1; i++){
            if(get(i, i+t.size()) == hs) res++; 
        }
        return res;
    }

    /* 
        concat 
        @verify https://codeforces.com/problemset/problem/514/C
    */
    inline ull concat(ull h1, ull h2, int h2len){
      return calc_mod(h2 + mul(h1, pow[h2len]));
    }

    // LCPを求める S[a:] T[b:]
    inline int LCP(int a, int b){
        int len = min((int)hash.size()-a, (int)hash.size()-b);
        
        int lb = -1, ub = len;
        while(ub-lb>1){
            int mid = (lb+ub)/2;

            if(get(a, a+mid) == get(b, b+mid)) lb = mid;
            else ub = mid;
        }
        return lb;
    }
};

int main() {  
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  
  int n; cin >> n;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];
  ll ans = 0;
  stack<int> st;
  for(int i=0; i<n; i++) {
    while(!st.empty() && st.top() > a[i]) {
      st.pop();
      ans++;
    }
    if(st.empty() || st.top() < a[i]) st.push(a[i]);
  }
  cout << ans + st.size() << endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5320
final_rank: 4

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    priority_queue<int> used;
    used.push(0);
    int ans = 0;
    for(int i=0; i<n; i++){
        while(used.top() > a[i]){
            used.pop();
        }
        if(a[i] > used.top()){
            used.push(a[i]);
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 4620
final_rank: 12

code_snippet: #include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    priority_queue<int> pq;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        while (!pq.empty() && pq.top() > a[i]) pq.pop();
        if (pq.empty() || pq.top() != a[i]) {
            pq.emplace(a[i]);
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 4520
final_rank: 14

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<iomanip>
#include<stack>

using namespace std;

#define debug(x) cout<< #x <<" : "<< x << endl;
#define repi(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define int long long

const int INF = (1<<30);
const int MOD = (int)1e9 + 7;

signed main(){
    int n;
    cin>>n;
    int a[200000];
    int mn=INF;
    int ans=0;
    stack<int> s;
    rep(i,n){
        cin>>a[i];
        if(!s.empty() ){
            while(s.top() > a[i]){
                s.pop();
                ans++;
                if(s.empty()) break;
            }
        }
        if(s.empty() ) s.push(a[i]);
        else if(s.top() != a[i]) s.push(a[i]);
    }
    ans+=s.size();
    cout<<ans<<endl;
  
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 6040
final_rank: 13

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
  int ans=0;
  vector<int> a(1,0);
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int d;
    cin >> d;
    if(a.back() < d){
      a.push_back(d);
      ++ans;
    }else{
      while(a.back() > d) a.pop_back();
      if(a.back()!=d){
        a.push_back(d);
        ++ans;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3744
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  int n;
  F f;
  T ti;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(F f,T ti):f(f),ti(ti){}
  void init(int n_){
    n=1;
    while(n<n_) n<<=1;
    dat.assign(n<<1,ti);
  }
  void build(const vector<T> &v){
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  void set_val(int k,T x){
    dat[k+=n]=x;
    while(k>>=1)
      dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
  }
  T query(int a,int b){
    T vl=ti,vr=ti;
    for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,dat[l++]);
      if(r&1) vr=f(dat[--r],vr);
    }
    return f(vl,vr);
  }
  template<typename C>
  int find(int st,C &check,T &acc,int k,int l,int r){
    if(l+1==r){
      acc=f(acc,dat[k]);
      return check(acc)?k-n:-1;
    }
    int m=(l+r)>>1;
    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);
    if(st<=l&&!check(f(acc,dat[k]))){
      acc=f(acc,dat[k]);
      return -1;
    }
    int vl=find(st,check,acc,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(st,check,acc,(k<<1)|1,m,r);
  }
  template<typename C>
  int find(int st,C &check){
    T acc=ti;
    return find(st,check,acc,1,0,n);
  }
};
//END CUT HERE
signed AOJ_DSL2A(){
  int n,q;
  scanf("%d %d",&n,&q);
  auto f=[](int a,int b){return min(a,b);};
  SegmentTree<int> rmq(f,INT_MAX);
  rmq.init(n);

  for(int i=0;i<q;i++){
    int c,x,y;
    scanf("%d %d %d",&c,&x,&y);
    if(c) printf("%d\n",rmq.query(x,y+1));
    else rmq.set_val(x,y);
  }
  return 0;
}
/*
  verified on 2019/06/26
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A&lang=jp
*/

signed ARC038_C(){
  int n;
  scanf("%d",&n);
  vector<int> cs(n),as(n);
  for(int i=1;i<n;i++) scanf("%d %d",&cs[i],&as[i]);

  const int INF = 1e9;
  auto f=[](int a,int b){return min(a,b);};
  SegmentTree<int> seg(f,INF);
  seg.build(vector<int>(n,-1));

  vector<int> dp(n);
  dp[0]=0;
  seg.set_val(0,0);
  for(int i=1;i<n;i++){
    auto check=[&](int x){return x<i-cs[i];};
    dp[i]=seg.find(0,check);
    seg.set_val(dp[i],max(seg.query(dp[i],dp[i]+1),i));
  }

  int ans=0;
  for(int i=1;i<n;i++)
    if(as[i]&1) ans^=dp[i];

  puts(ans?"First":"Second");
  return 0;
}
/*
  verified on 2019/06/26
  https://atcoder.jp/contests/arc038/tasks/arc038_c
*/

signed KUPC2013_D(){
  int n;
  scanf("%d",&n);
  vector<int> as(n+2,0);
  for(int i=1;i<=n;i++) scanf("%d",&as[i]);

  const int INF = 1.1e9;
  auto f=[](int a,int b){return min(a,b);};
  SegmentTree<int> seg(f,INF);
  seg.build(as);

  using P = pair<int, int>;
  set<P> sp;
  for(int k=0;k<2;k++){
    for(int i=1;i<=n;i++){
      auto check=[&](int x){return x<as[i];};
      int l=seg.find(i,check);
      sp.emplace(k?n+2-l:l,as[i]);
    }
    reverse(as.begin(),as.end());
    seg.build(as);
  }

  printf("%d\n",(int)sp.size()/2);
  return 0;
}

/*
  verified on 2019/06/26
  https://atcoder.jp/contests/kupc2013/tasks/kupc2013_d
*/

signed main(){
  //AOJ_DSL2A();
  //ARC038_C();
  KUPC2013_D();
  return 0;
}
accuracy: 1
time_ms: 150
memory_kb: 24508
final_rank: 17

code_snippet: #include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<stack>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, a, b = 0, ans = 0;
	stack<int> sta;
	
	cin>>N;
	
	sta.push(0);
	
	for(int i = 0; i < N; i++){
		cin>>a;
		while(sta.top() > a) sta.pop();
		
		if(sta.top() < a){
			ans++;
			sta.push(a);
		} 
	}
	
	cout<<ans<<endl;
	
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4364
final_rank: 1

code_snippet: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

signed main(){
  int n;
  cin>>n;
  int a[n];
  r(i,n) cin>>a[i];
  stack<int>st;
  st.push(a[0]);

  int sum=0;

  for(int i=1;i<n;i++){
    int x=a[i];
    while(!st.empty() && st.top()>x){
      int t=st.top();st.pop();
      while(!st.empty() && st.top()==t){
	st.pop();
      }
      sum++;
    }
    st.push(x);
  }

  set<int>S;
  while(!st.empty()) S.insert(st.top()),st.pop();

  cout<<S.size()+sum<<endl;
}
accuracy: 1
time_ms: 50
memory_kb: 13104
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define FOR( i, m, n ) for( int i = m; i < n; i++ )
#define REP( i, n ) for( int i = 0; i < n; i++ )
#define ALL( x ) x.begin(), x.end()


int main() {
  int N; cin >> N;
  vector<int> a( N );
  map<int, int> mp;
  REP( i, N ){
    cin >> a[i];
    mp[a[i]] = a[i];
  }

  int ans = mp.size();
  REP( i, N - 1 ){
    if( a[i] < a[i + 1] ){
      if( mp[a[i + 1]] != a[i + 1] ){
	ans++;
	mp[a[i + 1]] = a[i + 1];
      }
    }else if( a[i] > a[i + 1] ) {
      mp[a[i]] = a[i + 1];
    }
  }
  
  cout << ans << endl;
  
}
accuracy: 0.43333333333333335
time_ms: 100
memory_kb: 12780
final_rank: 19

code_snippet: #include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

signed main(){
  int n;
  cin>>n;
  int a[n];
  r(i,n) cin>>a[i];
  stack<int>st;
  st.push(a[0]);

  int sum=0;

  for(int i=1;i<n;i++){
    int x=a[i];
    if(!st.empty() && st.top()>x){
      int t=st.top();st.pop();
      while(!st.empty() && st.top()==t){
	st.pop();
      }
      sum++;
    }
    st.push(x);
  }

  set<int>S;
  while(!st.empty()) S.insert(st.top()),st.pop();

  cout<<S.size()+sum<<endl;
}
accuracy: 0.43333333333333335
time_ms: 50
memory_kb: 13228
final_rank: 18

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<iomanip>
#include<map>

using namespace std;

#define debug(x) cout<< #x <<" : "<< x << endl;
#define repi(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define int long long

const int INF = (1<<30);
const int MOD = (int)1e9 + 7;

signed main(){
    int n;
    cin>>n;
    int a[200000];
    int mn=INF;
    int ans=0;
    rep(i,n){
        cin>>a[i];
        mn=min(a[i],mn);
    }
    vector<int> mnpn;
    mnpn.push_back(-1);
    rep(i,n){
        if(a[i]==mn) mnpn.push_back(i);
    }
     mnpn.push_back(n);
    map<int,int> p;
    rep(i,mnpn.size()-1 ){
        repi(j,mnpn[i]+1,mnpn[i+1]){
            p[a[j]]++;
        }
        int m=p.size();
        ans+=m;
        p.clear();
    }
    cout<<ans+1<<endl;
    return 0;
}
accuracy: 0.43333333333333335
time_ms: 90
memory_kb: 17080
final_rank: 20

code_snippet: #include<bits/stdc++.h>
#define LL long long
#define REP(i, n) for(int i=0;i<(n);++i)
#define REPA(i, n) for(int i=1;i<(n);++i)
#define lp(i, n) for(int i=-;i<(n);++i)
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define DEKAI ((int)1e9+7)
#define ALL(x) (x).begin(), (x).end()
#define BIT(x) (1<<(x))
#define foreach(i, n) for(auto &i:(n))
using namespace std;

int main(){
    int ans=0;
    vector<int> line(1, 0);
    int N;
    cin >> N;
    REP(i, N){
        int d;
        cin >> d;
        if(line.back() < d){
            line.push_back(d);
            ++ans;
        }else{
            while(line.back() > d)line.pop_back();
            if(line.back()!=d){
                line.push_back(d);
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 3912
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
using ll = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  ll n;
  cin>>n;
  vector<ll> A(n);
  for(auto &I:A){cin>>I;}
  priority_queue<ll> S;
  ll ans=0;
  for(auto &I:A){
    while(!S.empty() && S.top()>I){S.pop();}
    if(S.empty() || I!=S.top()){ans++; S.push(I);}
  }
  cout<<ans<<endl;
  

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 6444
final_rank: 5

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;

    vector<int> a(n + 1);
    a[0] = -1;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i];
    }

    int ans = 0;
    vector<int> v;
    for(int i = 1 ; i <= n ; ++i){
        if(a[i - 1] < a[i]){
            ++ans;
        }else if(a[i - 1] > a[i]){
            auto it = lower_bound(v.begin(), v.end(), a[i]);
            if(*it != a[i]){
                ++ans;
            }
            v.resize(it - v.begin());
        }
        v.emplace_back(a[i]);
    }

    cout << ans << endl;
}
accuracy: 1
time_ms: 50
memory_kb: 4644
final_rank: 10

code_snippet: #include<algorithm>
#include<climits>
#include<cmath>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<int> a(n + 1);
    a[0] = -1;
    reps(i, n){
        cin >> a[i];
    }

    int ans = 0;
    vector<int> v;
    reps(i, n){
        if(a[i - 1] < a[i]){
            ++ans;
        }else if(a[i - 1] > a[i]){
            auto it = lower_bound(v.begin(), v.end(), a[i]);
            if(*it != a[i]){
                ++ans;
            }
            v.resize(it - v.begin());
        }
        v.emplace_back(a[i]);
    }

    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4620
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

stack<int> st;
int n, a, cnt = 0;

int main() {
  int i;
  cin >> n;
  st.push(0);
  for(i = 0; i < n; ++i) {
    cin >> a;
    while(st.top() > a) st.pop();
    if(st.top() < a) {
      ++cnt;
      st.push(a);
    }
  }
  cout << cnt << endl;
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3468
final_rank: 7

code_snippet: #include<iostream>
#include<cstdio>
#include<stack>

using namespace std;

int n,a[300000],s[300000];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	int cnt=0,sn=0;
	for(int i=0;i<n;i++){
		if(sn==0 || s[sn-1]<a[i]){
			s[sn++]=a[i];
			cnt++;
		}else if(s[sn-1]==a[i])continue;
		else{
			while(sn>0 && s[sn-1]>a[i])sn--;
			if(sn==0 || s[sn-1]<a[i]){
				s[sn++]=a[i];
				cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4716
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll N;
ll a[200010];
map<ll,bool> aru;

int main(){
  cin>>N;
  rep(i,N)cin>>a[i];
  stack<ll> st;
  ll res=0;
  rep(i,N){
    if(!aru[a[i]])res++;
    while(st.size()>0&&st.top()>a[i]){
      aru[st.top()]=false;
      st.pop();
    }
    aru[a[i]]=true;
    st.push(a[i]);
  }
  cout<<res<<endl;
  return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 18664
final_rank: 16