Problem:
日本沈没 (Japan Sinks)
問題文
日本列島は細長い列島である．日本列島は平行な境界線により
N
個の区画に分けられている．区画には端から順に
1
から
N
の番号が付けられている．区画
i
(
1 ≦ i ≦ N
) の高さは
A_i
である．
日本列島は海に囲まれており，海面の高さは場所によらず一定である．高さが海面の高さより高い区画を
陸地
と呼ぶ．
陸地が連続している部分のことを
島
と呼ぶ．より正確に書くと以下の通りである．整数
l
,
r
(
1 ≦ l ≦ r ≦ N
) について，日本列島のうち区画
l
，区画
l+1
，
...
，区画
r
からなる部分を
領域
[
l, r
] という．以下の条件を満たす領域 [
l, r
] を島という：
区画
l
，区画
l+1
，
...
，区画
r
はすべて陸地である．
l>1
ならば区画
l-1
は陸地ではない．
r<N
ならば区画
r+1
は陸地ではない．
海面の上昇により，日本列島は少しずつ沈没している．現在の海面の高さは
0
であるが，これは時間が経つにつれて徐々に上がり，ついには日本全体が海になってしまう．
JOI 君は，海面の高さが上昇すると，日本の島の数が増減することに気付いた．現在から，日本に陸地がなくなるまでの間 (現在も含む) における，島の数の最大値を求めたい．
制約
1 ≦ N ≦ 100000 (= 10^5)
0 ≦ A_i ≦ 1000000000 (= 10^9)
(
1 ≦ i ≦ N
)
入力・出力
入力
入力は以下の形式で標準入力から与えられる．
N
A_1
A_2
...
A_N
出力
現在から，日本に陸地がなくなるまでの間 (現在も含む) における，島の数の最大値を 1 行で出力せよ．
入出力例
入力例 1
6
0 1 2 1 3 2
出力例 1
2
海面の高さが
0
以上
1
未満のとき，区画
2, 3, 4, 5, 6
が陸地である．領域 [
2, 6
] が唯一の島なので，島の数は
1
である．
海面の高さが
1
以上
2
未満のとき，区画
3, 5, 6
が陸地である．領域 [
3, 3
] と領域 [
5, 6
] が島なので，島の数は
2
である．
海面の高さが
2
以上
3
未満のとき，区画
5
のみが陸地である．領域 [
5, 5
] が唯一の島なので，島の数は
1
である．
海面の高さが
3
になると，陸地はなくなり，島の数は
0
になる．
よって島の数の最大値は
2
なので，
2
を出力する．
入力例 2
6
3 2 3 0 2 0
出力例 2
2
海面の高さが
0
以上
2
未満のとき，区画
1, 2, 3, 5
が陸地である．領域 [
1, 3
] と領域 [
5, 5
] が島なので，島の数は
2
である．
海面の高さが
2
以上
3
未満のとき，区画
1, 3
が陸地である．領域 [
1, 1
] と領域 [
3, 3
] が島なので，島の数は
2
である．
海面の高さが
3
になると，陸地はなくなり，島の数は
0
になる．
よって島の数の最大値は
2
なので，
2
を出力する．
入力例 3
10
4 1 2 1 2 3 5 4 3 2
出力例 3
3
情報オリンピック日本委員会作 『第 18 回日本情報オリンピック JOI 2018/2019 予選競技課題』

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P ,ll> P3;
typedef pair<P ,P> PP;
const ll MOD = 998244353;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

struct UnionFindTree{
    int N;
    vector<int> par, rank, siz;

    void init(int n){
        N = n;
        par.resize(N);
        rank.resize(N, 0);
        siz.resize(N, 1);
        for(int i=0;i<N;i++){
            par[i] = i;
        }
    }
    int find(int i){
        if(par[i] == i) return i;
        else return par[i] = find(par[i]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x==y) return ;
        if(rank[x] < rank[y]) swap(x, y);
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        siz[x] += siz[y];
    }
    bool is_same(int x, int y){
        return find(x) == find(y);
    }
    int size(int x){
        x = find(x);
        return siz[x];
    }
};

ll n, a[MAX_N], ans = 0, cnt = 0;
bool used[MAX_N]{};

int main() {
    vector<pair<ll,ll> > v;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        v.push_back({a[i], i+1});
    }
    v.push_back({-IINF/2,n+1});
    sort(v.rbegin(), v.rend());
    //UnionFindTree g;
    //g.init(n+5);
    for(int i=0;i<n;i++){
        if(v[i].first == 0) break;
        ll id = v[i].second;
        used[id] = true;
        cnt++;
        if(used[id] && used[id-1]){
            //g.unite(id, id-1);
            cnt--;
        }
        if(used[id] && used[id+1]){
            //g.unite(id, id+1);
            cnt--;
        }
        if(v[i].first > v[i+1].first){
            ans = max(ans, cnt);
        }
    }
    
    cout << ans << endl;

    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 5780
final_rank: 11

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
struct k{
    int num, index;
};
bool cmp(k a, k b){
    return a.index<b.index;
}
k k[100002]={};
bool f[100002]={};
int n, m=1, ans=1, e=1;
int main(){
   scanf("%d", &n);
   for(int i=1; i<=n; i++){
       scanf("%d", &k[i].index);
       if(k[i].index) e=0;
       k[i].num=i;
   }
   if(e){
       printf("0\n");
       return 0;
   }
   f[0]=1;
   f[n+1]=1;
   sort(k+1, k+n+1, cmp);
   for(int i=1; i<=n;){
       int save=k[i].index;
       while(k[i].index==save&&i<=n){
           f[k[i].num]=1;
           if(f[k[i].num-1]==0&&f[k[i].num+1]==0) m++;
           if(f[k[i].num-1]==1&&f[k[i].num+1]==1) m--;
           i++;
       }
       ans=max(ans, m);
   }
   printf("%d\n", ans);
}
accuracy: 1
time_ms: 10
memory_kb: 3864
final_rank: 1

code_snippet: #include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifdef BACKER
        freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    #endif

    int n;
    cin >> n;
    vector<pair<int, int>> pos;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        if (a > 0) pos.push_back({a, i});
    }
    sort(pos.begin(), pos.end(), greater<pair<int, int>>());
    int tmp = 0, ans = 0;
    vector<bool> is_land(n + 3, 0);
    for (int i = 0; i < pos.size(); i++) {
        auto [h, ind] = pos[i];
        is_land[ind] = 1;
        tmp++;
        if (is_land[ind - 1]) tmp--;
        if (is_land[ind + 1]) tmp--;
        if (h != pos[i + 1].first || i == pos.size() - 1) ans = max(ans, tmp);
    }
    cout << ans << "\n";
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4140
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;

const ll N = 1e5 + 9;

ll n, i, a[N];
bool check[N];
vector<ll>vt;
vector<ll>vec[N];

int main()
{
#define TN ""
    if (fopen(TN ".inp", "r"))
    {
        freopen(TN ".inp", "r", stdin);
        freopen(TN ".out", "w", stdout);
    }
    cin.tie(0)->sync_with_stdio(0);

    cin >> n ;

    ll dem = 0;
    check[0] = 1, check[n + 1] = 1;
    for( i = 1; i <= n; i ++ ){
        cin >> a[i];
        if(a[i] == 0)
            check[i] = 1;
        else
            vt.pb(a[i]);
    }
    if( n == 1 )
    {
        cout << (a[1] > 0) << "\n";
        return 0;
    }
    if(vt.size() == 0)
    {
        cout << 0 << "\n";
        return 0;
    }
   dem = 0;
for( i = 1; i <= n; i ++ )
{
    if(check[i - 1] == 1 && check[i] == 0)
        dem ++;
}
    ll maxn = dem;

    sort(all(vt));
    for( i = 1; i <= n; i ++ )
    {
        if(a[i] == 0) continue;
        ll id = lower_bound(all(vt), a[i]) - vt.begin();
        vec[id].pb(i);
    }
    ll ans = maxn;
    for( i = 0; i < vt.size(); i ++ )
    {
        if( i != 0 && vt[i] == vt[i - 1])
            continue;
            if(vec[i].size()){
            for(auto x : vec[i])
            {
                check[x] = 1;
                if(check[x - 1] || check[x + 1] ){
                    if(check[x - 1]  && check[x + 1])
                    maxn --;
                }
                else
                maxn ++;
            }
            }
            ans = max(ans , maxn);
    }
    cout << ans << "\n";
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 10356
final_rank: 15

code_snippet: #include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;

const ll N = 1e5 + 9;

ll n, i, a[N];
bool check[N];
vector<ll>vt;
vector<ll>vec[N];

int main()
{
#define TN ""
    if (fopen(TN ".inp", "r"))
    {
        freopen(TN ".inp", "r", stdin);
        freopen(TN ".out", "w", stdout);
    }
    cin.tie(0)->sync_with_stdio(0);

    cin >> n ;

    ll dem = 0;
    check[0] = 1, check[n + 1] = 1;
    for( i = 1; i <= n; i ++ ){
        cin >> a[i];
        if(a[i] == 0)
            check[i] = 1;
        else
            vt.pb(a[i]);
    }
    if( n == 1 )
    {
        cout << (a[1] > 0) << "\n";
        return 0;
    }
    if(vt.size() == 0)
    {
        cout << 0 << "\n";
        return 0;
    }
   dem = 0;
for( i = 1; i <= n; i ++ )
{
    if(check[i - 1] == 1 && check[i] == 0)
        dem ++;
}
    ll maxn = dem;
vt.pb(0);
    sort(all(vt));
    for( i = 1; i <= n; i ++ )
    {
        if(a[i] == 0) continue;
        ll id = lower_bound(all(vt), a[i]) - vt.begin();
        vec[id].pb(i);
    }
    ll ans = maxn;
    for( i = 1; i < vt.size(); i ++ )
    {
      if(vt[i] == vt[i - 1]) continue;
            for(auto x : vec[i])
            {
                check[x] = 1;
                if(check[x - 1] || check[x + 1] ){
                    if(check[x - 1]  && check[x + 1])
                    maxn --;
                }
                else
                maxn ++;
            }
            ans = max(ans , maxn);
    }
    cout << ans << "\n";
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 10300
final_rank: 14

code_snippet: #line 1 "/opt/library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using i64 = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;

template <class T>
constexpr T infty = 0;
template <>
constexpr int infty<int> = 1'000'001'000;
template <>
constexpr ll infty<ll> = ll(infty<int>) * infty<int> * 2;
template <>
constexpr u32 infty<u32> = infty<int>;
template <>
constexpr u64 infty<u64> = infty<ll>;
template <>
constexpr i128 infty<i128> = i128(infty<ll>) * infty<ll>;
template <>
constexpr double infty<double> = infty<ll>;
template <>
constexpr long double infty<long double> = infty<ll>;
#define inf infty<ll>

using pi = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vc<T>>;
template <class T>
using vvvc = vector<vvc<T>>;
template <class T>
using vvvvc = vector<vvvc<T>>;
template <class T>
using vvvvvc = vector<vvvvc<T>>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

#define vv(type, name, h, ...) \
  vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...)   \
  vector<vector<vector<type>>> name( \
      h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
#define vvvv(type, name, a, b, c, ...)       \
  vector<vector<vector<vector<type>>>> name( \
      a, vector<vector<vector<type>>>(       \
             b, vector<vector<type>>(c, vector<type>(__VA_ARGS__))))

#define rep1(a) for (ll _ = 0; _ < (ll)(a); ++_)
#define rep2(i, a) for (ll i = 0; i < (ll)(a); ++i)
#define rep3(i, a, b) for (ll i = a; i < (ll)(b); ++i)
#define rep4(i, a, b, c) for (ll i = a; i < (ll)(b); i += (c))
#define rrep1(a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep2(i, a) for (ll i = (a)-1; i >= (ll)(0); --i)
#define rrep3(i, a, b) for (ll i = (b)-1; i >= (ll)(a); --i)
#define rrep4(i, a, b, c) for (ll i = (b)-1; i >= (ll)(a); i -= (c))
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)

#define all(x) (x).begin(),(x).end()
#define len(x) (ll)(x.size())
#define elif else if
#define bit(x, i) (((x)>>(i))&1)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second

#define stoi stoll
#define abs llabs

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define UNIQUE(x) \
  sort(all(x)), x.erase(unique(all(x)), x.end()), x.shrink_to_fit()

ll popcnt(ll x) { return __builtin_popcountll(x); }
ll popcnt(u64 x) { return __builtin_popcountll(x); }
ll popcnt_mod_2(ll x) { return __builtin_parityll(x); }
ll popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
ll topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
ll lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
ll lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}

template<typename T> T SUM(const vector<T> &A) {
  T s = 0; for (auto &&a: A) s += a;
  return s;
}

template <typename T>
T POP(queue<T> &que) {
  T a = que.front();
  que.pop();
  return a;
}
template <typename T>
T POP(deque<T> &que) {
  T a = que.front();
  que.pop_front();
  return a;
}
template <typename T>
T POP(pq<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(pqg<T> &que) {
  T a = que.top();
  que.pop();
  return a;
}
template <typename T>
T POP(vc<T> &que) {
  T a = que.back();
  que.pop_back();
  return a;
}

template <typename F>
ll binary_search(F check, ll ok, ll ng, bool check_ok = true) {
  if (check_ok) assert(check(ok));
  while (abs(ok - ng) > 1) {
    auto x = (ng + ok) / 2;
    (check(x) ? ok : ng) = x;
  }
  return ok;
}
template <typename F>
f128 binary_search_real(F check, f128 ok, f128 ng, ll iter = 100) {
  rep(iter) {
    f128 x = (ok + ng) / 2;
    (check(x) ? ok : ng) = x;
  }
  return (ok + ng) / 2;
}

// ? は -1
vc<int> s_to_vi(const string &S, char first_char) {
  vc<int> A(S.size());
  rep(i, S.size()) { A[i] = (S[i] != '?' ? S[i] - first_char : -1); }
  return A;
}

template <typename T, typename U>
vc<T> cumsum(vc<U> &A, ll off = 1) {
  ll N = A.size();
  vc<T> B(N + 1);
  rep(i, N) { B[i + 1] = B[i] + A[i]; }
  if (off == 0) B.erase(B.begin());
  return B;
}

// stable sort
template <typename T>
vi argsort(const vector<T> &A) {
  vi ids(len(A));
  iota(all(ids), 0);
  sort(all(ids),
       [&](ll i, ll j) { return (A[i] == A[j] ? i < j : A[i] < A[j]); });
  return ids;
}

// A[I[0]], A[I[1]], ...
template <typename T>
vc<T> rearrange(const vc<T> &A, const vi &I) {
  vc<T> B(len(I));
  rep(i, len(I)) B[i] = A[I[i]];
  return B;
}

template<typename T> inline bool chmax(T &a, T b) {return ((a<b)?(a=b,true):(false));}
template<typename T> inline bool chmin(T &a, T b) {return ((a>b)?(a=b,true):(false));}

inline void wt(const char c) { cout << c; }
inline void wt(const string s) { cout << s; }
inline void wt(const char *s) { cout << s; }

template <typename T>
void wt_integer(T x) {
  if (x < 0) { cout << (i64)(x); }
  else { cout << (u64)(x); }
}
template <typename T>
void wt_real(T x) {
  cout << fixed << setprecision(15) << (long double)(x);
}

inline void wt(int x) { wt_integer(x); }
inline void wt(ll x) { wt_integer(x); }
inline void wt(i128 x) { wt_integer(x); }
inline void wt(u32 x) { wt_integer(x); }
inline void wt(u64 x) { wt_integer(x); }
inline void wt(u128 x) { wt_integer(x); }
inline void wt(double x) { wt_real(x); }
inline void wt(long double x) { wt_real(x); }
inline void wt(f128 x) { wt_real(x); }

template <class T, class U>
void wt(const pair<T, U> val) {
  wt(val.first); wt(' '); wt(val.second);
}
template <size_t N = 0, typename T>
void wt_tuple(const T t) {
  if constexpr (N < std::tuple_size<T>::value) {
    if constexpr (N > 0) { wt(' '); }
    const auto x = std::get<N>(t);
    wt(x);
    wt_tuple<N + 1>(t);
  }
}
template <class... T>
void wt(tuple<T...> tpl) {
  wt_tuple(tpl);
}
template <class T, size_t S>
void wt(const array<T, S> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}
template <class T>
void wt(const vector<T> val) {
  auto n = val.size();
  for (size_t i = 0; i < n; i++) {
    if (i) wt(' ');
    wt(val[i]);
  }
}

void print() { wt('\n'); }
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
  wt(head);
  if (sizeof...(Tail)) wt(' ');
  print(forward<Tail>(tail)...);
}

void YES(bool t = 1) { print(t ? "YES" : "NO"); }
void NO(bool t = 1) { YES(!t); }
void Yes(bool t = 1) { print(t ? "Yes" : "No"); }
void No(bool t = 1) { Yes(!t); }
void yes(bool t = 1) { print(t ? "yes" : "no"); }
void no(bool t = 1) { yes(!t); }
void onez(bool t = 1) { print(t ? 1 : 0); }
#define endl '\n'
#define dump(x) {cerr << #x " = " << x << '\n';}
#line 2 "main.cpp"

int solve();
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  while (!solve()) {break;}
  return 0;
}

int solve() {
  ll N;
  cin >> N;
  vi A(N+2);
  vc<pi> B(N+2);
  B[0] = mp(-1, -1);
  B[N+1] = mp(inf, inf);
  rep(i, 1, N+1) {
    cin >> A[i];
    B[i] = mp(A[i], i);
  }
  sort(all(B));
  ll lands = 0;
  vc<bool> is_land(N+2, false);
  rep(i, 1, N+1) {
    if (A[i] >= 1) {
      is_land[i] = true;
      if (A[i-1] <= 0) {
       lands++;
      }
    }
  }
  ll ans = lands;
  rep(i, 1, N+1) {
    while (i < N+1) {
      auto [h, j] = B[i];
      if (h == 0) break;
      is_land[j] = false;
      if (is_land[j-1] and is_land[j+1]) {
        lands++;
      } elif (!is_land[j-1] and !is_land[j+1]) {
        lands--;
      }
      if (h != B[i+1].fi) {
        break;
      } else {
        i++;
      }
    }
    chmax(ans, lands);
  }
  print(ans);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5456
final_rank: 9

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	unsigned int N, i, cur, max;
	cin >> N;
	vector<unsigned int> A(N);
	vector<pair<unsigned int, unsigned int>> _A(N);
	for (i = 0; i != N; ++i)
		cin >> A[i], _A[i] = { A[i], i };
	stable_sort(_A.begin(), _A.end());

	if (A[0] == 0) cur = 0;
	else cur = 1;
	for (i = 1; i != N; ++i)
		if (A[i] != 0 && A[i - 1] == 0) ++cur;

	max = cur;
	for (i = 0; i != N && _A[i].first == 0; ++i);
	while (i != N)
	{
		do
		{
			if (_A[i].second != 0 && A[_A[i].second - 1] != 0)
			{
				if (_A[i].second != N - 1 && A[_A[i].second + 1] != 0)
					++cur;
			}
			else
			{
				if (_A[i].second == N - 1 || A[_A[i].second + 1] == 0)
					--cur;
			}

			A[_A[i].second] = 0;
			++i;
		} while (i != N && _A[i].first == _A[i - 1].first);

		if (cur > max) max = cur;
	}

	cout << max << '\n';
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5196
final_rank: 8

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cassert>
#include <chrono>
#include <random>
#include <set>
#include <utility>
#include <array>
#include <bitset>
#include <unordered_set>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    vector<pair<int,int>> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        v[i] = {a[i], i};
    }
    sort(v.rbegin(), v.rend());
    vector<bool> used(n);
    int res = 0;
    int cnt = 0;
    for (int i = 0; i < n; ) {
        if (v[i].first == 0) break;
        int h = v[i].first;
        while (i < n and v[i].first == h) {
            int pos = v[i].second;
            cnt += 1; i += 1;
            used[pos] = true;
            if (pos and used[pos-1]) {
                cnt -= 1;
            }
            if (pos+1 < n and used[pos+1]) {
                cnt -= 1;
            }
        }
        res = max(res, cnt);
    }
    cout << res << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4392
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
bool land[100005];
int main(){
    cin.tie(0) -> sync_with_stdio(0);
    cout.tie(0) -> sync_with_stdio(0);
    int n;
    cin >> n;
    pair<int, int> a[n+1];
    for(int i = 0; i < n; i++){
        int inp;
        cin >> inp;
        if(inp > 0) land[i+1] = 1;
        a[i] = {inp, i+1};
    }
    a[n] = {0, -1};
    sort(a, a+n);
    int cnt = 0;
    bool kt = false;
    for(int i = 1; i <= n+1; i++){
        if(land[i] && kt == false)
        {
        cnt++; 
        kt = true;
        }
        if(!land[i] && kt == true) kt = false;
    }
    int cnt1 = cnt;
    int lastlev = -1;
    for(int i = 0; i <= n; i++){
        if(a[i].st == 0) continue;
        if(lastlev != a[i].st){cnt = max(cnt1, cnt); lastlev = a[i].st;}
        land[a[i].nd] = 0;
        if(land[a[i].nd-1] == 1 && land[a[i].nd+1] == 1) cnt1++;
        if(land[a[i].nd-1] == 0 && land[a[i].nd+1] == 0) cnt1--;
    }
    cout << cnt << '\n';
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4316
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
bool cmp(pair<int,int> u1,pair<int,int> u2){
	if (u1.first==u2.first){
		return (u1.second<u2.second);
	}
	return (u1.first<u2.first);
}
bool cmp1(pair<int,int> u1,pair<int,int> u2){
	if (u1.second==u2.second){
		return (u1.first<u2.first);
	}
	return (u1.second<u2.second);
}
int main(){
	int n;cin>>n;pair<int,int> a[n+2]={};vector<int> v;map<int,int> mp1,mp;
	for (int i=1;i<=n;i++){
		cin>>a[i].first;a[i].second=i;
		v.push_back(a[i].first);
	}
	v.push_back(0);
	sort(v.begin(),v.end());
	sort(a+1,a+n+1,cmp);
//	for (int i=1;i<=n;i++) cout<<a[i].first<<" "<<a[i].second<<endl;
	int d=n,ans=0,cnt=0;
	for (int i=v.size()-1;i>=0;i--){
		while (d>=1){
			if (a[d].first>v[i]){
				cnt++;
//				if ()
				mp1[a[d].second]=1;
				if (mp1[a[d].second-1]==1) cnt--;
				if (mp1[a[d].second+1]==1) cnt--;
				d--;
			}
			else break;
		}
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 70
memory_kb: 8940
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
int i,j,n,res=0,ans=0,x;
int a[100005] ;
pair<int,int> st[100005] ;
//vector<pair<int,int>> vt[100005] ;
int main(){
    if(fopen("test.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin >> n ;
    for(i=1;i<=n;i++){
        cin >> a[i] ;
        st[i]={a[i],i} ;
    }
    sort(st+1,st+n+1) ;
    for(i=1;i<=n;i++){
        if(a[i]!=0 && a[i+1]==0) res++ ;
    }
    ans=res ;
    for(i=1;i<=n;i++){
        if(st[i].first==0) continue ;
        j=st[i].second ;
        x=st[i].first ;
        if(j>1 && j<n && x<a[j-1] && x<=a[j+1]) res++ ;
        if(a[j-1]<x && a[j+1]<x) res-- ;
        if(x!=st[i+1].first) ans=max(ans,res) ;
        a[j]=0;
    }
    cout << ans << '\n' ;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4312
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define dl double
#define st first
#define nd second
#define II pair <int, int>

using namespace std;

const int N = 5 + 5e4;
const int inf = 7 + 1e9;

int main() {
#define TASKNAME ""
    ios_base :: sync_with_stdio (0);
    cin.tie (0);
    if ( fopen( TASKNAME".inp", "r" ) ) {
        freopen (TASKNAME".inp", "r", stdin);
        freopen (TASKNAME".out", "w", stdout);
    }
    int n;
    cin >> n;
    vector <II> a(n + 1);
    vector <int> vis(n + 2, 0);
    int cnt = 0;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i].st;
        a[i].nd = i;
        if (a[i].st) {
            vis[i] = 1;
            if (!a[i - 1].st)
                cnt ++;
        }
    }
    sort(a.begin() + 1, a.end());
    int ans = cnt;
    for (int i = 1; i <= n; ) {
        int j = i;
        while (j <= n && a[j].st == a[i].st) {
            if (a[i].st) {
                int pos = a[j].nd;
                if (!vis[pos - 1] && !vis[pos + 1])
                    cnt --;
                else if (vis[pos - 1] && vis[pos + 1])
                    cnt ++;
                vis[pos] = 0;
            }
            j ++;
        }
        ans = max(ans, cnt);
        i = j;
    }
    cout << ans << '\n';
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4388
final_rank: 5

code_snippet: #include <bits/stdc++.h>
#define th1 first
#define th2 second
#define ll long long
#define lb long double
#define _(k) ((k)&(-(k)))
#define ii pair<int,int>
#define pb push_back
using namespace std;

const int N = 5+1e5;
const int INF = 0x3f3f3f3f;
int n, a[N], vis[N];
vector<int> q[N];

int main() {
    ios_base::sync_with_stdio (0);   cin.tie (0);
    #define TASKNAME "a"
    if (fopen(TASKNAME".inp", "r")) {
        freopen(TASKNAME".inp", "r", stdin) ;
        freopen(TASKNAME".out", "w", stdout) ;
    }

    cin >> n;
    vector<int> g;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        g.push_back(a[i]);
    }

    g.push_back(0);
    a[0] = 0, a[++n] = 0;

    sort(g.begin(), g.end());
    g.resize(unique(g.begin(),g.end()) - g.begin());

    for (int i = 0; i <= n; i++) {
        a[i] = upper_bound(g.begin(),g.end(),a[i]) - g.begin();
        q[a[i]].push_back(i);
    }

    int ans = 0, cnt = 0;
    for (int h = 1; h <= g.size(); h++) {
        for (int v: q[h]) {
            vis[v] = 1;
            if (!vis[v + 1] && !vis[v - 1])
                cnt += 1;
            else if (vis[v + 1] + vis[v - 1] == 2)
                cnt -= 1;
        }
        ans = max(ans, cnt - 1);
    }

    cout << ans << '\n';
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 9800
final_rank: 12

code_snippet: #include <bits/stdc++.h>
#define SZ(x) (int)(x.size())
using namespace std;

signed main() {
    #define TASKNAME ""
    if(fopen(TASKNAME".inp", "r")) {
        freopen(TASKNAME".inp", "r", stdin);
        freopen(TASKNAME".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<pair<int, int>> p;
    for(int i = 1; i <= n; i ++) {
        cin >> a[i];
        p.push_back({a[i], i});
    }   
    sort(p.begin(), p.end());
    reverse(p.begin(), p.end());
    vector<int> used(n + 3, 0);
    int answer = 0;
    int cur = 0;
    for(int i = 0, j = 0; i < SZ(p); i = j + 1) {
        for(j = i; j + 1 < SZ(p) && p[j + 1].first == p[i].first; ) j ++ ;
        if(p[i].first == 0) continue ;
        for(int k = i; k <= j; k ++) {
            int pos = p[k].second;
            if(used[pos - 1] == 1) cur -- ;
            if(used[pos + 1] == 1) cur -- ;
            cur ++ ;
            used[pos] = 1;
        }
        answer = max(answer, cur);
    }
    cout << answer << "\n";
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4792
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> Pi;
int main(){
    int n, a;
    vector<Pi> vec;
    bool flo[100010]={};
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a;
        if(a>0) vec.push_back(Pi(a, i));
    }
    int si = vec.size();
    if(si>0){
        sort(vec.begin(), vec.end());
        reverse(vec.begin(), vec.end());
    }
    int cnt=0, ma=1;
    for(int i=0;i<si;i++){
        Pi pi = vec[i];
        flo[pi.second] = true;
        cnt++;
        if(flo[pi.second-1]) cnt--;
        if(flo[pi.second+1]) cnt--;
        if(i==si-1 || pi.first!=vec[i+1].first) ma = max(ma, cnt);
    }
    if(si<1) ma = 0;
    cout << ma << endl;
    return(0);
}
accuracy: 1
time_ms: 30
memory_kb: 3992
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vvvvll = vector<vvvll>;
using vvvvvll = vector<vvvvll>;
using vvvvvvll = vector<vvvvvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vvvvb = vector<vvvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vvvvd = vector<vvvd>;
using vvvvvd = vector<vvvvd>;
#define all(A) A.begin(),A.end()
#define ALL(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;


template<class T>
bool chmax(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

template<class T>
bool chmin(T& p, T q, bool C = 1) {
    if (C == 0 && p == q) {
        return 1;
    }
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    if (a == 0)return b;
    if (b == 0)return a;
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}
ll sqrtz(ll N) {
    ll L = 0;
    ll R = sqrt(N) + 10000;
    while (abs(R - L) > 1) {
        ll mid = (R + L) / 2;
        if (mid * mid <= N)L = mid;
        else R = mid;
    }
    return L;

}

vector<ll> fact, factinv, inv;
const ll mod = 1e9 + 7;
void prenCkModp(ll n) {
    fact.resize(n + 5);
    factinv.resize(n + 5);
    inv.resize(n + 5);
    fact[0] = fact[1] = 1;
    factinv[0] = factinv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < n + 5; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
        inv[i] = (mod - (inv[mod % i] * (mod / i)) % mod) % mod;
        factinv[i] = (factinv[i - 1] * inv[i]) % mod;
    }

}

ll nCk(ll n, ll k) {
    if (n < k || k < 0) return 0;
    return (fact[n] * ((factinv[k] * factinv[n - k]) % mod)) % mod;
}


vvll mul(vvll A, vvll B) {
    ll N = A.size();
    vvll res(N, vll(N, 0));
    rep(i, N)rep(j, N)rep(k, N)res[i][j] = (res[i][j] + A[i][k] * B[k][j]) % 17;
    return res;
}


/*
区間をsetで管理するテク
区間は半開区間で持たせる[L,R)
*/
template<class T>
struct rangeset{
    set<pair<T,T>> S;
    T INF;

    

    rangeset(){
        INF=2e18;;
        S.insert({INF,INF});
        S.insert({-INF,-INF});
    }
    bool iscovered(T L,T R){
        //assert(L<=R);
        auto itr=S.lower_bound({L+1,L+1});
        itr=prev(itr);
        auto st=*itr;
        return (itr->first<=L&&R<=itr->second);
    }
    bool iscovered(T x){
        return iscovered(x,x+1);
    }
    pair<T,T> covered(T L,T R){
        //assert(L<=R);
        auto itr=S.lower_bound({L+1,L+1});
        itr--;
        auto st=*itr;
        if(itr->first<=L&&R<=itr->second){
            return st;
        }
        else{
            return {INF,INF};
        }
    }
    pair<T,T> covered(T x){
        return covered(x,x+1);
    }
    T insert(T L,T R){
        if(iscovered(L,R))return T(0);
        auto itr=S.lower_bound({L+1,L+1});
        itr=prev(itr);
        T res=T(0);
        auto st=*itr;
        if(itr->first<=L&&L<=itr->second){
            L=st.first;
            res-=itr->second-itr->first;
            itr=S.erase(itr);
        }
        else itr=next(itr);
        while(R>itr->second){
            res-=itr->second-itr->first;
            itr=S.erase(itr);
        }
        if(itr->first<=R&&R<=itr->second){
            res-=itr->second-itr->first;
            R=itr->second;
            itr=S.erase(itr);
        }
        S.insert({L,R});
        res+=R-L;
        return res;
    }
    T insert(T x){
        return insert(x,x+1);
    }

    T erase(T L,T R){
        auto itr=S.lower_bound({L+1,L+1});
        itr=prev(itr);
        T res=T(0);
        auto st=*itr;
        if(itr->first<=L&&R<=itr->second){
            if(itr->first<L)S.insert({itr->first,L});
            if(R<itr->second)S.insert({R,itr->second});
            S.erase(itr);
            return R-L;
        }
        if(itr->first<=L&&L<itr->second){
            res+=itr->second-L;
            if(itr->first<L)S.insert({itr->first,L});
            itr=S.erase(itr);
        }
        else itr=next(itr);

        while(itr->second<=R){
            res+=itr->second-itr->first;
            itr=S.erase(itr);
        }

        if(itr->first<R&&R<=itr->second){
            res+=R-itr->first;
            if(R<itr->second)S.insert({R,itr->second});
            S.erase(itr);
        }
        return res;
    }
    T erase(T x){
        return erase(x,x+1);
    }
};


int main() {

    
    ll N;
    cin>>N;
    map<ll,vll> M;
    rep(i,N){
        ll A;
        cin>>A;
        M[-A].push_back(i);
    }
    if(M.count(0)&&M.size()==1){
        cout<<0<<endl;
        return 0;
    }
    rangeset<ll> S;
    ll an=1;
    for(auto m:M){
        for(auto x:m.second){
            S.insert(x);
        }
        chmax(an,ll(S.S.size()-2));
        //cout<<S.S.size()<<endl;
    }
    cout<<an<<endl;
}
accuracy: 1
time_ms: 80
memory_kb: 15836
final_rank: 20

code_snippet: //#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using QP = priority_queue<T,vector<T>,greater<T>>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T1,typename T2,typename T3>void anss(T1 x,T2 y,T3 z){ans(x!=y,x,z);};  
template<typename T>void debug(const T &v,ll h,ll w,string sv=" "){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout<<sv<<v[i][j];cout<<endl;}};
template<typename T>void debug(const T &v,ll n,string sv=" "){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout<<sv<<v[i];cout<<endl;};
template<typename T>void debug(const vector<T>&v){debug(v,v.size());}
template<typename T>void debug(const vector<vector<T>>&v){for(auto &vv:v)debug(vv,vv.size());}
template<typename T>void debug(stack<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(queue<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(deque<T> st){while(!st.empty()){cout<<st.front()<<" ";st.pop_front();}cout<<endl;}
template<typename T>void debug(PQ<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(QP<T> st){while(!st.empty()){cout<<st.top()<<" ";st.pop();}cout<<endl;}
template<typename T>void debug(const set<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T>void debug(const multiset<T>&v){for(auto z:v)cout<<z<<" ";cout<<endl;}
template<typename T,size_t size>void debug(const array<T, size> &a){for(auto z:a)cout<<z<<" ";cout<<endl;}
template<typename T,typename V>void debug(const map<T,V>&v){for(auto z:v)cout<<"["<<z.first<<"]="<<z.second<<",";cout<<endl;}
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
template<typename T>void rearrange(vector<int>&ord, vector<T>&v){
  auto tmp = v;
  for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
}
template<typename Head, typename... Tail>void rearrange(vector<int>&ord,Head&& head, Tail&&... tail){
  rearrange(ord, head);
  rearrange(ord, tail...);
}
template<typename T> vector<int> ascend(const vector<T>&v){
  vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int i,int j){return make_pair(v[i],i)<make_pair(v[j],j);});
  return ord;
}
template<typename T> vector<int> descend(const vector<T>&v){
  vector<int>ord(v.size());iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),[&](int i,int j){return make_pair(v[i],-i)>make_pair(v[j],-j);});
  return ord;
}
template<typename T> vector<T> inv_perm(const vector<T>&ord){
  vector<T>inv(ord.size());
  for(int i=0;i<ord.size();i++)inv[ord[i]] = i;
  return inv;
}
ll FLOOR(ll n,ll div){assert(div>0);return n>=0?n/div:(n-div+1)/div;}
ll CEIL(ll n,ll div){assert(div>0);return n>=0?(n+div-1)/div:n/div;}
ll digitsum(ll n){ll ret=0;while(n){ret+=n%10;n/=10;}return ret;}
ll modulo(ll n,ll d){return (n%d+d)%d;};
template<typename T>T min(const vector<T>&v){return *min_element(v.begin(),v.end());}
template<typename T>T max(const vector<T>&v){return *max_element(v.begin(),v.end());}
template<typename T>T acc(const vector<T>&v){return accumulate(v.begin(),v.end(),T(0));};
template<typename T>T reverse(const T &v){return T(v.rbegin(),v.rend());};
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};
template<typename T>T poll(queue<T> &q){auto ret=q.front();q.pop();return ret;};
template<typename T>T poll(priority_queue<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(QP<T> &q){auto ret=q.top();q.pop();return ret;};
template<typename T>T poll(stack<T> &s){auto ret=s.top();s.pop();return ret;};
ll MULT(ll x,ll y){if(LLONG_MAX/x<=y)return LLONG_MAX;return x*y;}
ll POW2(ll x, ll k){ll ret=1,mul=x;while(k){if(mul==LLONG_MAX)return LLONG_MAX;if(k&1)ret=MULT(ret,mul);mul=MULT(mul,mul);k>>=1;}return ret;}
ll POW(ll x, ll k){ll ret=1;for(int i=0;i<k;i++){if(LLONG_MAX/x<=ret)return LLONG_MAX;ret*=x;}return ret;}
template< typename T = int >
struct edge {
  int to;
  T cost;
  int id;
  edge():id(-1){};
  edge(int to, T cost = 1, int id = -1):to(to), cost(cost), id(id){}
  operator int() const { return to; }
};

template<typename T>
using Graph = vector<vector<edge<T>>>;
template<typename T>
Graph<T>revgraph(const Graph<T> &g){
  Graph<T>ret(g.size());
  for(int i=0;i<g.size();i++){
    for(auto e:g[i]){
      int to = e.to;
      e.to = i;
      ret[to].push_back(e);
    }
  }
  return ret;
}
template<typename T>
Graph<T> readGraph(int n,int m,int indexed=1,bool directed=false,bool weighted=false){
  Graph<T> ret(n);
  for(int es = 0; es < m; es++){
    int u,v;
    T w=1;
    cin>>u>>v;u-=indexed,v-=indexed;
    if(weighted)cin>>w;
    ret[u].emplace_back(v,w,es);
    if(!directed)ret[v].emplace_back(u,w,es);
  }
  return ret;
}
template<typename T>
Graph<T> readParent(int n,int indexed=1,bool directed=true){
  Graph<T>ret(n);
  for(int i=1;i<n;i++){
    int p;cin>>p;
    p-=indexed;
    ret[p].emplace_back(i);
    if(!directed)ret[i].emplace_back(p);
  }
  return ret;
}
template<typename T>
struct BIT{
  ll n;
  ll k=1;
  vector<T>data;
  BIT() = default;
  BIT(ll size):n(size){
    data.assign(n,0);
    while(k*2<=n)k*=2;
  }
  void add(ll a,T w){
    for(ll i=a+1;i<=n;i+=i&-i)data[i-1]+=w;
  }
  T sum(ll a){//[0,a)
	  if(a<=0)return 0;
    T ret = 0;
    for(ll i=a;i>0;i-=i&-i)ret+=data[i-1];
    return ret;
  }
  //[a,b)
  T sum(ll a,ll b){return a>=b?0:sum(b)-sum(a);}
  T operator[](ll pos){
    return sum(pos,pos+1);
  }
  ll lower_bound(ll x){
    ll ret=0;    
    for(ll i=k;i>0;i/=2){
      if(ret+i<=n&&data[ret+i-1]<x){
        x-=data[ret+i-1];
        ret+=i;
      }
    }
    return ret;
  }
  ll lower_first(ll x){
    return lower_bound(sum(n)-x+1);
  }
  void print(){
    for(ll i=0;i<n;i++){
      if(i!=0)cout<<" ";
      cout<<(*this)[i];
    }
    cout<<endl;
  }
};
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
	ll n;cin>>n;
	vector<ll>a(n+2,0);
	rep(i,0,n)cin>>a[i+1];
	map<ll,ll>mp;
	rep(i,0,n+1){
		mp[min(a[i],a[i+1])]++;
		mp[max(a[i],a[i+1])]--;
	}
	ll ret=0;
	ll now=0;
	for(auto z:mp){
		now+=z.se;
		chmax(ret,now);
	}
	//debug(mp);
	cout<<ret/2<<endl;
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 10212
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#include <bitset>
#include <map>
#include <unordered_map>
#include <set>

using namespace std;

#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 1000000007;
const ll inf = 1e9;
const ll INF = 1e18;

void pline(vector<ll> lis){
    rep(i,0,lis.size()){
        printf ("%lld",lis[i]);
        if (i != lis.size()-1) printf(" ");
        else printf("\n");
    }
}

void pline(vector<pair<ll,ll>> lis){
    rep(i,0,lis.size()){
        printf ("/%lld,%lld/",lis[i].first,lis[i].second);
        if (i != lis.size()-1) printf(" ");
        else printf("\n");
    }
}

/*
void pmap(map<ll,mint>& lis){
    for (auto p : lis){
        printf ("%lld:%lld ,",p.first,p.second.val());
    }
    printf ("\n");
}*/


int main(){

    //ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);

    ll N;
    cin >> N;

    vector<ll> A(N+1,0);

    rep(i,0,N) cin >> A[i+1];

    //pline(A);

    vector<pair<ll,ll>> lis;

    rep(i,0,A.size()-1){
        if (A[i] < A[i+1]){
            lis.push_back(make_pair(A[i],1));
            lis.push_back(make_pair(A[i+1],-1));
        }
    }



    sort(lis.begin(),lis.end());
    //reverse(lis.begin(),lis.end());

    ll ans = 0;
    ll now = 0;

    for (auto tup : lis){
        now += tup.second;
        ans = max(ans , now);
        //cout << tup.first << " " << tup.second << " " << now << endl; 
    }

    cout << ans << endl;

}

/*

-1
0 X X 5 X
X 5 X X 0

*/
accuracy: 1
time_ms: 30
memory_kb: 9400
final_rank: 16

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0655.cc: 日本沈没 (Japan Sinks)
 */

#include<cstdio>
#include<set>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;
typedef set<pii> spii;

/* global variables */

int as[MAX_N], uas[MAX_N];
pii ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d", as + i);
    uas[i] = as[i];
    ps[i] = pii(as[i], i);
  }

  sort(uas, uas + n);
  int m = unique(uas, uas + n) - uas;

  if (m == 1) {
    printf("%d\n", (uas[0] == 0) ? 0 : 1);
    return 0;
  }

  sort(ps, ps + n);

  spii gs;
  gs.insert(pii(n, 0));
  int maxc = 1;

  for (int i = 0, j = 0; i < m; i++) {
    while (j < n && uas[i] == ps[j].first) {
      int k = ps[j++].second;
      spii::iterator sit = gs.lower_bound(pii(k, k));
      if (sit != gs.end()) {
	int l = sit->second, r = sit->first;
	gs.erase(sit);

	if (l < k) gs.insert(pii(k, l));
	if (k + 1 < r) gs.insert(pii(r, k + 1));
      }
    }

    maxc = max(maxc, (int)gs.size());

    //printf("%d:", uas[i]);
    //for (auto g: gs) printf(" %d,%d", g.second, g.first);
    //putchar('\n');
  }

  printf("%d\n", maxc);
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 6676
final_rank: 13

code_snippet: #define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<random>
#include<bitset>
#include<cassert>
using namespace std;
typedef long long ll;
const int mod=998244353;
const int dx[]={1,0,0,-1},dy[]={0,1,-1,0};
vector<int>rev[100001];
//UnionFind.txt
//UF
//ベースは蟻本
class UnionFind{
	int n,cnt;
	vector<int>par,rank,sz;
	vector<bool>ver;
public:
	UnionFind(int n_)
		:n(n_),cnt(0),par(n_),rank(n_),sz(n_,1),ver(n_){
		iota(par.begin(),par.end(),0);
	}
	//xの根
	int find(int x){
		if(par[x]==x)
			return x;
		return par[x]=find(par[x]);
	}
	//xとyを併合
	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y)
			return;
		cnt--;
		if(rank[x]<rank[y]){
			par[x]=y;
			sz[y]+=sz[x];
		}else{
			par[y]=x;
			if(rank[x]==rank[y])
				rank[x]++;
			sz[x]+=sz[y];
		}
	}
	//xとyが同じところにあるか
	bool same(int x,int y){
		return find(x)==find(y);
	}
	//xの大きさ
	int size(int x){
		x=find(x);
		return sz[x];
	}
	void verify(int x){
		if(ver[x])
			return;
		ver[x]=1;
		cnt++;
	}
	int size(){
		return cnt;
	}
};
int main(){
	static int n,a[100000];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	vector<int>unzip(a,a+n);
	unzip.push_back(0);
	sort(unzip.begin(),unzip.end());
	unzip.erase(unique(unzip.begin(),unzip.end()),unzip.end());
	map<int,int>zip;
	for(int i=0;i<unzip.size();i++)
		zip[unzip[i]]=i;
	for(int i=0;i<n;i++)
		a[i]=zip[a[i]];
	for(int i=0;i<n;i++)
		rev[a[i]].push_back(i);
	int ans=0;
	UnionFind uf(n);
	for(int tmp=n;tmp>=1;tmp--){
		set<int>conn;
		for(auto x:rev[tmp]){
			uf.verify(x);
			if(x-1>=0&&a[x-1]>=tmp)
				conn.insert(x-1);
			if(x+1<n&&a[x+1]>=tmp)
				conn.insert(x);
		}
		for(auto x:conn)
			uf.unite(x,x+1);
		ans=max(ans,uf.size());
	}
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 60
memory_kb: 15280
final_rank: 19