Problem:
Problem E: Piano
Problem
がっちょ君はピアノを弾こうとしている。ピアノは右側にある鍵盤ほど高い音が出る。がっちょ君はある楽譜を持っており、その楽譜に従って弾く。
楽譜には、ある時刻にどの鍵盤を弾くべきかを示す音符が時系列順に記載されている。この楽譜には和音(複数の鍵盤を押したときに出る音)は現れず、音の長さも考えないことにする。
がっちょ君はピアノを弾くとき、以下のルールに従う。
片手のみで弾く
指一本で鍵盤ひとつを弾く
最初の音はどの指でも弾ける
直前の音より高い音を弾くとき、直前の音を弾いた指よりもひとつ以上右にある指を使う
直前の音より低い音を弾くとき、直前の音を弾いた指よりもひとつ以上左にある指を使う
直前の音と同じ高さの音を弾くとき、直前の音を弾いた指と同じ指を使う
がっちょ君が使う楽譜が与えられるので、ルールに従ってその楽譜を演奏しきるには、演奏する方の腕に最小何本の指が必要かを求めよ。ただし、必要な指は6本以上になることがあることに注意せよ。
Input
入力は以下の形式で与えられる。
N
a
1
a
2
...
a
N
1行目に、楽譜に書かれている音符の総数を表す整数
N
が与えられる。
続く2行目から
N
+1行目までに、時刻
i
(1 ≤
i
≤
N
)に弾くべき鍵盤が最も左の鍵盤から何番目かを表す整数
a
i
が与えられる。
Constraints
入力は以下の条件を満たす。
1 ≤
N
≤ 10
5
0 ≤
a
i
≤ 10
9
Output
がっちょ君が上記ルールに従って弾くために必要な最小の指の本数を1行に出力する。
Sample Input 1
3
2
5
1
Sample Output 1
2
この場合、図1の①、②	、③	の順で鍵盤を弾く。指が2本あると、左側の指で鍵盤2を、右側の指で鍵盤5を、また左側の指で鍵盤1を弾くことができる。
図1: Sample1 の図解
Sample Input 2
5
4
5
2
1
3
Sample Output 2
3
Sample Input 3
3
4
4
4
Sample Output 3
1

Submitted solutions:

code_snippet: #include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <algorithm>
#include <stack>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <list>
#include <bitset>
#include <complex>
#include <iomanip>
#include <cassert>
/*-----------------------*/
#define int long long
#define INF 0x3f3f3f3f
#define INF2 0x7f7f7f7f
using namespace std;

/*-----------------------*/
using namespace std;


map<int, int> vis;

signed main() {

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


    int n; scanf("%lld", &n);
    int most_left = 0;
    int most_right = 0;
    int cur_pos = 0;
    int last_num = -1;
    while(n--){
        int num; scanf("%lld", &num);




        if((last_num != -1)){

            if(last_num > num){
                if(vis.count(num)) cur_pos = vis[num];
                else cur_pos--;
                most_left = min(most_left, cur_pos);
            }else if(last_num < num){
                if(vis.count(num)) cur_pos = vis[num];
                else cur_pos++;
                most_right = max(most_right, cur_pos);
            }


        }


        vis[num] = cur_pos;
        last_num = num;

    }


    printf("%lld\n", most_right - most_left+1);




    return 0;


}
accuracy: 0.14285714285714285
time_ms: 20
memory_kb: 7272
final_rank: 18

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

int n;
vector<int> a;

int main() {
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    if (!(int)a.size() || a.back() != x) a.push_back(x);
  }
  n = a.size();
  int res = 1;
  for (int i = 0; i < n - 1;) {
    int sig = a[i] < a[i + 1], now = 1;
    while (i + 1 < n && sig == (a[i] < a[i + 1])) ++i, ++now;
    res = max(res, now);
  }
  cout << res << endl;
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3736
final_rank: 6

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

int n;
vector<int> a;

int main() {
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    if (!(int)a.size() || a.back() != x) a.push_back(x);
  }
  n = a.size();
  int ma = 0, mi = 0, now = 0;
  for (int i = 1; i < n; ++i) {
    now += (a[i] < a[i - 1]) ? 1 : -1;
    ma = max(now, ma);
    mi = min(now, mi);
  }
  cout << ma - mi + 1 << endl;
  return 0;
}
accuracy: 0.14285714285714285
time_ms: 10
memory_kb: 3492
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n;
    cin >>n;
    vector<int> a(n);
    rep(i,n) cin >>a[i];

    auto itr = unique(all(a));
    a.resize(distance(a.begin(),itr));
    n = a.size();

    vector<int> d(n-1);
    rep(i,n-1) d[i] = (a[i]<a[i+1]);

    int ans = 1;
    int s = 0;
    while(s<n-1){
        int idx = s;
        while(idx<n-1 && d[s]==d[idx]) ++idx;
        ans = max(ans, idx-s+1);
        s = idx;
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3544
final_rank: 5

code_snippet: #include <stdio.h>

int main(void) {
  long long n, nowmax = 0, max = 0, min = 0, i, nowmin = 0, now = 0;
  scanf("%lld", &n);
  int a, bef;
  for(i = 0; i < n; ++i) {
    scanf("%d", &a);
    if(i) {
      if(bef > a) {
        nowmin = min, nowmax--;
        if(nowmin > nowmax) nowmin = nowmax, min = nowmin;
      } else if(bef < a) {
        nowmin++, nowmax = max;
        if(nowmin > nowmax) nowmax = nowmin, max = nowmax;
      }
    }
    bef = a;
  }
  printf("%lld\n", max - min + 1);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2748
final_rank: 1

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
#define Seg_Max_N (1<<18) 

using Value = int;
const Value ini = -1e9;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return max(l,r);
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};


int solve(vector<int>b) {
	int num = 0;
	int ans=0;
	int pre = -1;
	for (auto a : b) {
		if (a > pre) {
			num++;
			ans=max(ans,num);
			pre = a;
		}
		else if (a == pre) {

		}
		else {
			pre = a;
			num = 1;
		}
	}
	return ans;
}
template<typename T> struct Compress {
	map<T, int>mp;
	map<int, T>revmp;

	Compress(vector<T>vs) {
		setmp(vs);
	}

	Compress() :mp(), revmp() {

	}
	void setmp(vector<T>vs) {
		sort(vs.begin(), vs.end());
		vs.erase(unique(vs.begin(), vs.end()), vs.end());
		for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
			mp[vs[i]] = i;
			revmp[i] = vs[i];
		}
	}
};
int main() {
	int N;cin>>N;
	vector<int>v(N);
	for (int i = 0; i < v.size(); ++i) {
		cin>>v[i];
	}
	Compress<int>comp(v);
	for (auto&a : v) {
		a=comp.mp[a];
	}
	int ans1=solve(v);

	for(auto&a:v){
		a=N-a;
	}
	int ans2=solve(v);
	cout<<max(ans1,ans2)<<endl;
	
	return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 13232
final_rank: 12

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
#define Seg_Max_N (1<<18) 

using Value = int;
const Value ini = -1e9;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return max(l,r);
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};


int solve(vector<int>a) {
	segtree seg(1e5+1);
	for (int i = 0; i < a.size(); ++i) {
		if (i == 0) {
			seg.update(a[i],1);
		}
		else {
			int k=seg.query(0,a[i]);
			seg.update(a[i],max(seg.query(a[i],a[i]+1),max(1,k+1)));
		}
	}
	return seg.query(0,1e5+1);
}
template<typename T> struct Compress {
	map<T, int>mp;
	map<int, T>revmp;

	Compress(vector<T>vs) {
		setmp(vs);
	}

	Compress() :mp(), revmp() {

	}
	void setmp(vector<T>vs) {
		sort(vs.begin(), vs.end());
		vs.erase(unique(vs.begin(), vs.end()), vs.end());
		for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
			mp[vs[i]] = i;
			revmp[i] = vs[i];
		}
	}
};
int main() {
	int N;cin>>N;
	vector<int>v(N);
	for (int i = 0; i < v.size(); ++i) {
		int a;cin>>v[i];
	}
	Compress<int>comp(v);
	for (auto&a : v) {
		a=comp.mp[a];
	}
	int ans1=solve(v);
	for (auto&a : v) {
		a=N-a;
	}
	int ans2=solve(v);
	cout<<max(ans1,ans2)<<endl;

	return 0;
}
accuracy: 0.14285714285714285
time_ms: 90
memory_kb: 11088
final_rank: 20

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
#define Seg_Max_N (1<<18) 

using Value = int;
const Value ini = -1e9;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return max(l,r);
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};


int solve(vector<int>a) {
	segtree seg(1e5+1);
	for (int i = 0; i < a.size(); ++i) {
		if (i == 0) {
			seg.update(a[i],1);
		}
		else {
			int k=seg.query(0,a[i]);
			seg.update(a[i],max(1,k+1));
		}
	}
	return seg.query(0,1e5+1);
}
template<typename T> struct Compress {
	map<T, int>mp;
	map<int, T>revmp;

	Compress(vector<T>vs) {
		setmp(vs);
	}

	Compress() :mp(), revmp() {

	}
	void setmp(vector<T>vs) {
		sort(vs.begin(), vs.end());
		vs.erase(unique(vs.begin(), vs.end()), vs.end());
		for (int i = 0; i < static_cast<int>(vs.size()); ++i) {
			mp[vs[i]] = i;
			revmp[i] = vs[i];
		}
	}
};
int main() {
	int N;cin>>N;
	vector<int>v(N);
	for (int i = 0; i < v.size(); ++i) {
		int a;cin>>v[i];
	}
	Compress<int>comp(v);
	for (auto&a : v) {
		a=comp.mp[a];
	}
	int ans1=solve(v);
	for (auto&a : v) {
		a=N-a;
	}
	int ans2=solve(v);
	cout<<max(ans1,ans2)<<endl;

	return 0;
}
accuracy: 0.14285714285714285
time_ms: 70
memory_kb: 11036
final_rank: 19

code_snippet: #include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int a[1000005];
int len_p[100005];
int len_m[100005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n-1;i++){
		if(a[i]>a[i+1])len_m[i]++;
		if(a[i]<a[i+1])len_p[i]++;
	}
	for(int i=n-1;i>=0;i--){
		if(len_m[i]>0){
			len_m[i]+=len_m[i+1];
		}
		if(len_p[i]>0){
			len_p[i]+=len_p[i+1];
		}
		if(len_m[i]==0 && len_p[i]==0){
			len_m[i]+=len_m[i+1];
			len_p[i]+=len_p[i+1];
		}
	}
	int res=0;
	for(int i=0;i<n;i++){
		res=max(res,len_p[i]+len_m[i]);
	}
	printf("%d\n",res+1);
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4352
final_rank: 4

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

int main(){
  int ans=1, N,a,b;
  string s="";
  cin>>N>>a;
  for(int i=1;i<N;i++){
    cin>>b;
    if(a<b)s.push_back('<');
    if(a>b)s.push_back('>');
    a=b;
  }
  int cnt=0;
  for(int i=0;i<(int)s.size();i++){
    if(i>0&&s[i-1]==s[i]){
      cnt++;
    }else{
      cnt=1;
    }
    ans=max(ans,cnt+1);
  }
  cout<<ans<<endl;
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3340
final_rank: 7

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

int main(){
  int ans=1, N,a,b;
  string s="";
  cin>>N>>a;
  for(int i=1;i<N;i++){
    cin>>b;
    if(a<b)s.push_back('<');
    if(a>b)s.push_back('>');
    a=b;
  }
  int cnt=1;
  for(int i=1;i<(int)s.size();i++){
    if(s[i-1]==s[i]){
      cnt++;
    }else{
      cnt=1;
    }
    ans=max(ans,cnt+1);
  }
  cout<<ans<<endl;
  return 0;
}
accuracy: 0.5
time_ms: 20
memory_kb: 3304
final_rank: 14

code_snippet: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,l=1,r=1,ans=1,a[100001];
main(){
  cin>>n;
  r(i,n)cin>>a[i];
  r(i,n-1){
    if(a[i]<a[i+1])l++,r=1;
    if(a[i]>a[i+1])r++,l=1;
    ans=max(ans,max(l,r));
  }
  cout<<ans<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3476
final_rank: 8

code_snippet: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,l=1,r=1,ans,a[100001];
main(){
  cin>>n;
  r(i,n)cin>>a[i];
  r(i,n-1){
    if(a[i]<a[i+1])l++,r=1;
    if(a[i]>a[i+1])r++,l=1;
    ans=max(ans,max(l,r));
  }
  cout<<ans<<endl;
}
accuracy: 0.6428571428571429
time_ms: 20
memory_kb: 3344
final_rank: 13

code_snippet: #include <bits/stdc++.h>
 
using namespace std;
 
 
int main()
{
  int N, A[100000];
 
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
 
 
  auto check = [&](int size)
  {
    int left = 0, right = size - 1;
    int flag = -1;
    for(int i = 1; i < N; i++) {
      if(A[i - 1] < A[i]) {
        ++left;
        ++right;
        right = size - 1;
      } else if(A[i] < A[i - 1]) {
        left = 0;
        --right;
      }
      if(left > right) return (false);
    }
    return (true);
  };
 
  int ok = 1 << 30, ng = 0;
  while(ok - ng > 1) {
    int mid = (ok + ng) >> 1;
    if(check(mid)) ok = mid;
    else ng = mid;
  }
 
  cout << ok << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 3480
final_rank: 11

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){

	int N;
	scanf("%d",&N);

	if(N == 1){
		printf("1\n");
		return 0;
	}

	int max_diff = 0;

	int near_bottom = 0,near_top = 0;

	int pre,tmp;
	scanf("%d",&pre);

	int value = 0;

	for(int i = 1; i < N; i++){
		scanf("%d",&tmp);

		if(tmp == pre){
			//Do nothing
		}else if(tmp > pre){

			value++;
			near_top = value;

			max_diff = max(max_diff,value-near_bottom);

		}else{
			value--;
			near_bottom = value;

			max_diff = max(max_diff,near_top-value);
		}
		pre = tmp;
	}

	printf("%d\n",max_diff+1);

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

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int N;
	scanf("%d",&N);

	int maximum = 0,minimum = 0;

	int pre,tmp;
	scanf("%d",&pre);

	int value = 0;

	for(int i = 1; i < N; i++){
		scanf("%d",&tmp);
		if(tmp == pre){
			//Do nothing
		}else if(tmp > pre){
			value++;
			maximum = max(maximum,value);
		}else{
			value--;
			minimum = min(minimum,value);
		}
		pre = tmp;
	}

	printf("%d\n",maximum-minimum+1);

	return 0;
}
accuracy: 0.14285714285714285
time_ms: 10
memory_kb: 3160
final_rank: 15

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

int main() {
  int n,k=1;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++) scanf("%d",&a[i]);
  while(k<n&&a[k-1]==a[k]) k++;
  if(n==k) {
    cout << 1 << endl;
    return 0;
  }
  int f=a[k-1]<a[k],x=2;
  int ans=x;
  for(int i=k+1; i<n; i++) {
    while(i<n&&a[i-1]==a[i]) i++;
    if(i==n) break;
    if(!f&&a[i-1]>a[i]||f&&a[i-1]<a[i]) x++;
    else {
      f^=1;
      x=2;
    }
    ans=max(ans,x);
  }
  cout << ans << endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3524
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF (1LL << 30)
using namespace std;
typedef long long ll;

ll N, A[100000];

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i];

  ll d = 0, ans = 1, cnt = 0;
  REP(i, 1, N) {
    if(A[i - 1] == A[i]) continue;
    if(A[i - 1] < A[i]) {
      if(d == 1) cnt++;
      else cnt = 2, d = 1;
    }
    if(A[i - 1] > A[i]) {
      if(d == -1) cnt++;
      else cnt = 2, d = -1;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 3876
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF (1LL << 30)
using namespace std;
typedef long long ll;

ll N, A[100000];

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i];

  vector<ll> dp1(N, INF);
  REP(i, 0, N) *lower_bound(dp1.begin(), dp1.end(), A[i]) = A[i];

  ll p = *max_element(A, A + N);
  REP(i, 0, N) A[i] = p - A[i];

  vector<ll> dp2(N, INF);
  REP(i, 0, N) *lower_bound(dp2.begin(), dp2.end(), A[i]) = A[i];

  cout << max(lower_bound(dp1.begin(), dp1.end(), INF) - dp1.begin(), lower_bound(dp2.begin(), dp2.end(), INF) - dp2.begin()) << endl;
}
accuracy: 0.14285714285714285
time_ms: 20
memory_kb: 3984
final_rank: 17

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

int main() {
	long long N, a[1000000], d = 0,ans1=0,ans2=0;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
	}
	for (int i = 2; i <= N; i++) {
		if (a[i] > a[i - 1]) {
			d++;
			if (d >= ans1) {
				ans1 = d;
			}
		}
		if (a[i] < a[i - 1]) {
			d = 0;
		}
	}
		d = 0;
		for (int i = 2; i <= N; i++) {
			if (a[i] < a[i - 1]) {
				d++;
				if (d >= ans2) {
					ans2 = d;
				}
			}
			if (a[i] > a[i - 1]) {
				d = 0;
			}
		}
		cout << max(ans1, ans2) + 1<< endl;
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3832
final_rank: 9