Problem:
Problem B: Mountain Climbing
Problem
なりよし君は山登りの計画を立てています。計画はとても大切です。高原・盆地が多いのか、峰・窪地が多いのか、山腹があるのか、状況によって用意する荷物も変わってきます。
なりよし君が持っている登山ガイドブックには、今回登山に利用する道の一定の距離毎の標高がスタート地点からゴール地点まで順に書かれています。
ガイドブックに書かれている標高をスタート地点からゴール地点まで順に
a
1
,
a
2
,
a
3
, ...,
a
N
とし、高原、盆地、山腹、峰、窪地を次のように定義します:
高原
a
i-1
<
a
i
=
a
i+1
= ... =
a
j
>
a
j+1
(
1
<
i
<
j
<
N
)
盆地
a
i-1
>
a
i
=
a
i+1
= ... =
a
j
<
a
j+1
(
1
<
i
<
j
<
N
)
山腹
a
i-1
<
a
i
=
a
i+1
= ... =
a
j
<
a
j+1
(
1
<
i
<
j
<
N
)
もしくは
a
i-1
>
a
i
=
a
i+1
= ... =
a
j
>
a
j+1
(
1
<
i
<
j
<
N
)
峰
a
i-1
<
a
i
>
a
i+1
(
1
<
i
<
N
)
窪地
a
i-1
>
a
i
<
a
i+1
(
1
<
i
<
N
)
高原
盆地
山腹
山腹
峰
窪地
あなたは、なりよし君の為に、高原・盆地・山腹・峰・窪地、それぞれの数を計算するプログラムを書くことにしました。
Input
入力は次のような形式で与えられる:
N
a
1
a
2
a
3
...
a
N
N
は与えられる標高の数を表す整数である。
a
i
は標高を表す整数である( 1 ≤ i ≤
N
)。それぞれ空白区切りで与えられる。
Constraints
入力は以下の条件を満たす。
1 ≤
N
≤ 100000
-100000 ≤
a
i
≤ 100000
Output
高原の数、盆地の数、山腹、峰、窪地の数を順番に空白区切りで一行に出力せよ。
Sample Input 1
5 1 2 3 4 3
Sample Output 1
0 0 0 1 0
Sample Input 2
12 10 5 15 15 20 20 12 12 8 3 3 5
Sample Output 2
1 1 2 0 1

Submitted solutions:

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

vector<pair<char,int>> runlength(vector<char> vs){
	vector<pair<char,int>> res;
	for(auto v:vs){
		if(res.empty() || res.back().first!=v) res.emplace_back(v,0);
		res.back().second++;
	}
	return res;
}

int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(auto &A:a)cin>>A;

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

	auto vs=runlength(less_greater);

	vector<int> ans(5,0);
	// kougen
	for(int i=1;i<(int)vs.size()-1;i++){
		if(vs[i-1].first=='<' && vs[i].first=='=' && vs[i+1].first=='>'){
			ans[0]++;
		}
	}

	// bonti
	for(int i=1;i<(int)vs.size()-1;i++){
		if(vs[i-1].first=='>' && vs[i].first=='=' && vs[i+1].first=='<'){
			ans[1]++;
		}
	}

	// sanpuku
	for(int i=1;i<(int)vs.size()-1;i++){
		if(vs[i-1].first==vs[i+1].first && vs[i].first=='='){
			ans[2]++;
		}
	}

	// mine
	for(int i=0;i<(int)vs.size()-1;i++){
		if(vs[i].first=='<' && vs[i+1].first=='>'){
			ans[3]++;
		}
	}

	// kuboti
	for(int i=0;i<(int)vs.size()-1;i++){
		if(vs[i].first=='>' && vs[i+1].first=='<'){
			ans[4]++;
		}
	}

	
	for(int i=0;i<(int)ans.size();i++){
		if(i) cout<<" ";
		cout<<ans[i];
	}
	cout<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4680
final_rank: 13

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

llong n;
vector<llong> a;
vector<pair<llong, llong>> p;

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

    p.emplace_back(a[0], 1);
    for (int i = 1; i < n; i++) {
        if (p.back().first == a[i]) p.back().second++;
        else p.emplace_back(a[i], 1);
    }

    llong kougen, bonti, sanpuku, mine, kuboti;
    kougen = bonti = sanpuku = mine = kuboti = 0;

    for (int i = 1; i < (int)p.size() - 1; i++) {
        if (p[i - 1].first < p[i].first && p[i].first > p[i + 1].first) {
            if (p[i].second == 1) mine++;
            else kougen++;
        }
        else if (p[i - 1].first > p[i].first && p[i].first < p[i + 1].first) {
            if (p[i].second == 1) kuboti++;
            else bonti++;
        }
        else if (p[i].second > 1) {
            sanpuku++;
        }
    }

    printf("%lld %lld %lld %lld %lld\n", kougen, bonti, sanpuku, mine, kuboti);

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5704
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  vector<int> b;
  for (int i = 0; i < N; i++){
    b.push_back(a[i]);
    if (i >= 2){
      if (b[b.size() - 3] == b[b.size() - 2] && b[b.size() - 2] == b[b.size() - 1]){
        b.pop_back();
      }
    }
  }
  int M = b.size();
  array<int, 5> cnt{0, 0, 0, 0, 0};
  for (int i = 0; i < M - 3; i++){
    if (b[i] < b[i + 1] && b[i + 1] == b[i + 2] && b[i + 2] > b[i + 3]){
      cnt[0]++;
    }
    if (b[i] > b[i + 1] && b[i + 1] == b[i + 2] && b[i + 2] < b[i + 3]){
      cnt[1]++;
    }
    if (b[i] < b[i + 1] && b[i + 1] == b[i + 2] && b[i + 2] < b[i + 3]){
      cnt[2]++;
    }
    if (b[i] > b[i + 1] && b[i + 1] == b[i + 2] && b[i + 2] > b[i + 3]){
      cnt[2]++;
    }
  }
  for (int i = 0; i < M - 2; i++){
    if (b[i] < b[i + 1] && b[i + 1] > b[i + 2]){
      cnt[3]++;
    }
    if (b[i] > b[i + 1] && b[i + 1] < b[i + 2]){
      cnt[4]++;
    }
  }
  cout << cnt[0] << ' ' << cnt[1] << ' ' << cnt[2] << ' ' << cnt[3] << ' ' << cnt[4] << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3828
final_rank: 10

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

using namespace std;

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

    vector<int> height{-100001};
    vector<int> count{0};

    int a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        if (a != height.back()) {
            height.push_back(a);
            count.push_back(1);
        } else {
            *(count.end() - 1) = count.back() + 1;
        }
    }

    int ans[5]{};

    if (height.size() > 3) {
        for (int i = 2; i < height.size() - 1; i++) {
            if (height[i - 1] < height[i] && height[i] > height[i + 1] && count[i] > 1) {
                //高原
                ans[0]++;
            } else if (height[i - 1] > height[i] && height[i] < height[i + 1] && count[i] > 1) {
                //盆地
                ans[1]++;
            } else if (height[i - 1] < height[i] && height[i] < height[i + 1] && count[i] > 1) {
                //山腹(登り)
                ans[2]++;
            } else if (height[i - 1] > height[i] && height[i] > height[i + 1] && count[i] > 1) {
                //山腹(降り)
                ans[2]++;
            } else if (height[i - 1] < height[i] && height[i] > height[i + 1] && count[i] == 1) {
                //峰
                ans[3]++;
            } else if (height[i - 1] > height[i] && height[i] < height[i + 1] && count[i] == 1) {
                //窪地
                ans[4]++;
            }
        }
    }

    cout << ans[0];
    for (int i = 1; i < 5; i++) {
        cout << " " << ans[i];
    }
    cout << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3832
final_rank: 11

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


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

	int kougen = 0, bonti = 0, sanhuku = 0, mine = 0, kuboti = 0;
	for (int i = 1; i < N - 1; i++) {
		if (a[i - 1]<a[i] && a[i]>a[i + 1])mine++;
		if (a[i - 1] > a[i] && a[i] < a[i + 1])kuboti++;
	}
	for (int i = 1; i < N - 1; i++) {
		if (a[i - 1] != a[i] && a[i] == a[i + 1]) {
			int j = i + 1;
			while (j < N - 1 && a[j] == a[j + 1]) {
				j++;
			}
			if (j == N - 1)break;
			if (a[i - 1] < a[i]) {
				(a[j] < a[j + 1] ? sanhuku : kougen)++;
			}
			else {
				(a[j] > a[j + 1] ? sanhuku : bonti)++;
			}
			i = j;
		}
	}
	cout << kougen << " " << bonti << " " << sanhuku << " " << mine << " " << kuboti << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3088
final_rank: 6

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n), x(n-1);
    for(int i = 0; i < n; i++)  cin >> v[i];
    for(int i = 0; i < n-1; i++)    x[i] = v[i+1]-v[i];
    int a = 0, b = 0, c = 0, d = 0, e = 0;
    for(int i = 1; i < n-1; i++){
        if(x[i-1] < 0 && x[i] > 0)  e++;
        if(x[i-1] > 0 && x[i] < 0)  d++;
    }
    int cur = 0;
    while(cur < n-1 && x[cur] == 0)  cur++;

    while(cur < n-1){
        if(x[cur] != 0){
            cur++;
            continue;
        }
        int next = cur;
        while(next < n-1 && x[next] == 0)  next++;
        if(next == n-1) break;
        if(x[cur-1] < 0 && x[next] > 0)         b++;
        else if(x[cur-1] > 0 && x[next] < 0)    a++;
        else                                    c++;
        cur = next;
    }
    printf("%d %d %d %d %d\n", a, b, c, d, e);
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3556
final_rank: 9

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 check = [&](int l, int r){
        if(l==r){
            if(a[l-1]<a[l] && a[l]>a[l+1]) return 3;
            if(a[l-1]>a[l] && a[l]<a[l+1]) return 4;
            return -1;
        }

        if(a[l-1]<a[l] && a[r]>a[r+1]) return 0;
        if(a[l-1]>a[l] && a[r]<a[r+1]) return 1;
        if(a[l-1]<a[l] && a[r]<a[r+1]) return 2;
        if(a[l-1]>a[l] && a[r]>a[r+1]) return 2;
        return -1;
    };

    int ct[5]={};

    int i=1;
    while(i<n-1){
        int j = i;
        while(j<n-1 && a[i]==a[j]) ++j;
        --j;

        int res = check(i,j);
        if(res != -1) ++ct[res];

        i = j+1;
    }

    rep(z,5) cout << ct[z] << " \n"[z==4];
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3116
final_rank: 8

code_snippet: #include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;


struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main() {
	int N;cin>>N;
	vector<int>hs(N);
	for(int i=0;i<N;++i)cin>>hs[i];
	vector<int>ds(N-1);
	for(int i=0;i<N-1;++i)ds[i]=hs[i+1]-hs[i];

	vector<int>nextds;
	bool flag=true;
	for (int i = 0; i < N - 1; ++i) {
		if(ds[i])nextds.push_back(ds[i]>0?1:-1);
		else {
			if (!flag) {

			}
			else {
				nextds.push_back(ds[i]);
			}
		}
		flag=ds[i];
	}
	vector<int>anss(5);
	for (int i = 0; i < int(nextds.size()) - 1; ++i) {
		if(nextds[i]==0)continue;
		else {
			if (nextds[i] < 0) {
				if (nextds[i + 1] == 0) {
					if(i+2==nextds.size())continue;
					else {
						if (nextds[i + 2] < 0) {
							anss[2]++;
						}
						else {
							assert(nextds[i+2]>0);
							anss[1]++;
						}
					}

				}
				else {
					if(nextds[i+1]>0)anss[4]++;
				}
			}
			else {
				if (nextds[i + 1] == 0) {
					if (i + 2 == nextds.size())continue;
					else {
						if (nextds[i + 2] < 0) {
							anss[0]++;
						}
						else {
							assert(nextds[i + 2]>0);
							anss[2]++;
						}
					}
				}
				else {
					if (nextds[i + 1]<0)anss[3]++;
				}
			}
		}
	}
	for (int i = 0; i < 5; ++i) {
		cout<<anss[i];
		if(i==4)cout<<endl;
		else cout<<" ";
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4324
final_rank: 12

code_snippet: #include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;


struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main() {
	int N;cin>>N;
	vector<int>hs(N);
	for(int i=0;i<N;++i)cin>>hs[i];
	vector<int>ds(N-1);
	for(int i=0;i<N-1;++i)ds[i]=hs[i+1]-hs[i];

	vector<int>nextds;
	bool flag=true;
	for (int i = 0; i < N - 1; ++i) {
		if(ds[i])nextds.push_back(ds[i]>0?1:-1);
		else {
			if (!flag) {

			}
			else {
				nextds.push_back(ds[i]);
			}
		}
		flag=ds[i];
	}
	vector<int>anss(5);
	for (int i = 0; i < nextds.size() - 1; ++i) {
		if(nextds[i]==0)continue;
		else {
			if (nextds[i] < 0) {
				if (nextds[i + 1] == 0) {
					if(i+2==nextds.size())continue;
					else {
						if (nextds[i + 2] < 0) {
							anss[2]++;
						}
						else {
							assert(nextds[i+2]>0);
							anss[1]++;
						}
					}

				}
				else {
					if(nextds[i+1]>0)anss[4]++;
				}
			}
			else {
				if (nextds[i + 1] == 0) {
					if (i + 2 == nextds.size())continue;
					else {
						if (nextds[i + 2] < 0) {
							anss[0]++;
						}
						else {
							assert(nextds[i + 2]>0);
							anss[2]++;
						}
					}
				}
				else {
					if (nextds[i + 1]<0)anss[3]++;
				}
			}
		}
	}
	for (int i = 0; i < 5; ++i) {
		cout<<anss[i];
		if(i==4)cout<<endl;
		else cout<<" ";
	}
	return 0;
}
accuracy: 0.8809523809523809
time_ms: 10
memory_kb: 4324
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int INF=1<<29;
 
int main() {
  int n,d[5];
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  for(int i=0; i<n-2; i++) {
    if(a[i]==a[i+1] && a[i]==a[i+2]) a[i]=INF;
  }
  a.erase(remove(a.begin(),a.end(),INF),a.end());
  memset(d,0,sizeof(d));
  for(int i=2; i<a.size(); i++) {
    if(i>=3 && a[i-2]==a[i-1]) {
      if(a[i-2]>a[i-3]) {
        if(a[i]<a[i-1]) d[0]++;
        else if(a[i]>a[i-1]) d[2]++;
      } else {
        if(a[i]>a[i-1]) d[1]++;
        else if(a[i]<a[i-1]) d[2]++;
      }
    }
    if(a[i-1]>a[i-2] && a[i]<a[i-1]) d[3]++;
    if(a[i-1]<a[i-2] && a[i]>a[i-1]) d[4]++;
  }
  for(int i=0; i<5; i++) {
    if(i) cout << " ";
    cout << d[i];
  }
  cout << endl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3108
final_rank: 7

code_snippet: /*
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

/* main */

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

  int ko = 0, bo = 0, sa = 0, mi = 0, ku = 0;
  int pa = as[0];
  bool pl = false;

  for (int i = 0; i < n - 1; i++) {
    if (as[i] == as[i + 1]) pl = true;
    else {
      if (as[i] > as[i + 1]) {
	if (pa < as[i]) {
	  if (pl) ko++;
	  else mi++;
	}
	else if (pa > as[i] && pl) sa++;
      }
      else {
	if (pa > as[i]) {
	  if (pl) bo++;
	  else ku++;
	}
	else if (pa < as[i] && pl) sa++;
      }
      pa = as[i];
      pl = false;
    }
  }

  printf("%d %d %d %d %d\n", ko, bo, sa, mi, ku);
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1532
final_rank: 2

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

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

    vector<int> res(5);
    vector<int> num(2);
    num[0] = v[0];
    num[1] = v[1];
    for (int i = 2; i < n; i++) {
        int crl = num.size()-1;
        if (num[crl] == v[i]) {
            if (num[crl] != num[crl-1]) num.push_back(v[i]);
        } else if (num[crl] == num[crl-1]) {
            num.push_back(v[i]);
        } else if (num[crl] > num[crl-1]) {
            if (num[crl] < v[i]) num[crl] = v[i];
            else num.push_back(v[i]);
        } else if (num[crl] < num[crl-1]) {
            if (num[crl] > v[i]) num[crl] = v[i];
            else num.push_back(v[i]);
        } 
    }

    for (int i = 0; i < num.size()-2; i++) {
        if (num[i] > num[i+1] && num[i+1] < num[i+2]) {
            res[4]++;
        } else if (num[i] < num[i+1] && num[i+1] > num[i+2]) {
            res[3]++;
        } else if (i && i + 2 < num.size() && num[i] == num[i+1]) {
            if (num[i-1] < num[i] && num[i+1] > num[i+2]) {
                res[0]++; 
            } else if (num[i-1] > num[i] && num[i+1] < num[i+2]) {
                res[1]++;
            } else {
                res[2]++;
            }
        }
    }

    cout << res[0];
    for (int i = 1; i < res.size(); i++) {
        cout << " " << res[i];
    } cout << endl;

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 2068
final_rank: 18

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int a[100000],b[100000],x[5];
int main(){
	int N;
	cin>>N;
	rep(i,N) cin>>a[i];
	rep(i,N-1){
		if(a[i]<a[i+1]) b[i]=1;
		else if(a[i]==a[i+1]) b[i]=0;
		else b[i]=-1;
	}
	int p=10;
	rep(i,N-2){
		if(b[i]==b[i+1]){
			if(b[i]!=0) p=b[i];
			continue;
		}
		if(b[i]==1&&b[i+1]==-1) x[3]++;
		else if(b[i]==-1&&b[i+1]==1) x[4]++;
		else if(b[i]==0){
			if(p==10) continue;
			if(p==b[i+1]) x[2]++;
			else if(p==1) x[0]++;
			else x[1]++;
		}
		if(b[i]!=0) p=b[i];
	}
	rep(i,4) cout<<x[i]<<" ";
	cout<<x[4]<<endl;
}
accuracy: 1
time_ms: 20
memory_kb: 1944
final_rank: 17

code_snippet: #include <iostream>
#include <cstdio>
#define REP(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,a) REP(i,0,a)
using namespace std;

int N,kou,bon,hara,mine,kubo;
int a[100010];

int main(void){
    cin >> N;
    rep(i,N) cin >> a[i];
    int flat = 0, bef = a[0];
    REP(i,1,N) {
        if (a[i-1] == a[i])
            ++flat;
        else if (a[i-1] < a[i]) {
            if (flat > 0) {
                if (bef < a[i-1]) ++hara;
                if (bef > a[i-1]) ++bon;
                flat = 0;
            } else {
                if (bef > a[i-1]) ++kubo;
            }
            bef = a[i-1];
        } else {
            if (flat > 0) {
                if (bef < a[i-1]) ++kou;
                if (bef > a[i-1]) ++hara;
                flat = 0;
            } else {
                if (bef < a[i-1]) ++mine;
            }
            bef = a[i-1];
        }
    }
    printf("%d %d %d %d %d\n", kou, bon, hara, mine, kubo);
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1536
final_rank: 3

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int main(){
	
	int n, p1 = inf, p2 = inf, cnt = 0;
	cin >> n;
	vi a(n), ans(5);
	rep(i, n){
		cin >> a[i];
		if(p1 != inf && p2 != inf){
			if(cnt && p2 < p1 && p1 > a[i]) ans[0]++;
			if(cnt && p2 > p1 && p1 < a[i]) ans[1]++;
			if(cnt && p2 < p1 && p1 < a[i]) ans[2]++;
			if(cnt && p2 > p1 && p1 > a[i]) ans[2]++;
			if(!cnt && p2 < p1 && p1 > a[i]) ans[3]++;
			if(!cnt && p2 > p1 && p1 < a[i]) ans[4]++;
		}
		
		if(p1 != a[i]){
			p2 = p1; p1 = a[i];
			cnt = 0;
		}
		else cnt++;
	}
	cout << ans[0] << " " << ans[1] << " " << ans[2] << " " << ans[3] << " " << ans[4] << endl;
	

	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1532
final_rank: 16

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

const int INF = 1e+9;

int main() {
	int n, a, bp, p, kogen = 0, bonti = 0, sanpuku = 0, mine = 0, kuboti = 0;
	cin >> n;
	cin >> bp >> p;
	if(n == 1 || n == 2){
		for(int i = 0; i < 5; ++i){
			if(i)
				cout << " ";
			cout << "0";
		}
		cout << endl;
		return 0;
	}
	bool flag = false;
	for(int i = 2; i < n; ++i){
		scanf("%d", &a);
		if(p == a && bp != p){
			flag = true;
			continue;
		}
		if(flag){
			if(bp < p && p > a)
				kogen++;
			else if(bp > p && p < a)
				bonti++;
			else
				sanpuku++;
			flag = false;
		}
		else if(bp > p && p < a)
			kuboti++;
		else if(bp < p && p > a)
			mine++;
		bp = p;
		p = a;
	}
	cout << kogen << " " << bonti << " " << sanpuku << " " << mine << " " << kuboti << endl;
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1248
final_rank: 15

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

const int INF = 1e+9;

int main() {
	int n, a, bp, p, kogen = 0, bonti = 0, sanpuku = 0, mine = 0, kuboti = 0;
	cin >> n;
	cin >> bp >> p;
	if(n == 1 || n == 2){
		for(int i = 0; i < 5; ++i){
			if(i)
				cout << " ";
			cout << "0";
		}
		return 0;
	}
	bool flag = false;
	for(int i = 2; i < n; ++i){
		scanf("%d", &a);
		if(p == a && bp != p){
			flag = true;
			continue;
		}
		if(flag){
			if(bp < p && p > a)
				kogen++;
			else if(bp > p && p < a)
				bonti++;
			else
				sanpuku++;
			flag = false;
		}
		else if(bp > p && p < a)
			kuboti++;
		else if(bp < p && p > a)
			mine++;
		bp = p;
		p = a;
	}
	cout << kogen << " " << bonti << " " << sanpuku << " " << mine << " " << kuboti << endl;
	return 0;
}
accuracy: 0.8809523809523809
time_ms: 10
memory_kb: 1252
final_rank: 19

code_snippet: #include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main() {
    int n;
    int a[200000];
    cin>>n;
    rep(i,n){
        cin>>a[i];
    }
    vector<int> field;
    
    int now=-1;
    for(int i=1;i< n;i++){
        if(((a[i-1]> a[i] && now==0) ||
            (a[i-1]< a[i] && now==1) ||
            (a[i-1]==a[i] && now==2) )&& i!=n-1){
            //??????????????????
        }
        else{
            if(now!=-1)field.pb(now);
            if(a[i-1]> a[i])now=0;
            if(a[i-1]< a[i])now=1;
            if(a[i-1]==a[i])now=2;
        }
    }
    field.pb(now);

    int ans[5]={};
    for(int i=2;i<field.size();i++){
        if(field[i-2]==1 && field[i-1]==2 && field[i]==0 )ans[0]++;
        if(field[i-2]==0 && field[i-1]==2 && field[i]==1 )ans[1]++;
        if((field[i-2]==1 && field[i-1]==2 && field[i]==1 ) || (field[i-2]==0 && field[i-1]==2 && field[i]==0 ))ans[2]++;
    }
    
    for(int i=1;i<field.size();i++){
        if(field[i-1]==1 && field[i]==0 )ans[3]++;
        if(field[i-1]==0 && field[i]==1 )ans[4]++;
    }
    
    
    cout<<ans[0]<<" "<<ans[1]<<" "<<ans[2]<<" "<<ans[3]<<" "<<ans[4]<<endl;
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2072
final_rank: 5

code_snippet: #include <iostream>
using namespace std;

int main() {

  long long int n;
  cin >> n;

  long long int ans[5] = {};

  bool f = false;
  long long int b;
  long long int c = 0;

  for ( long long int i = 0; i < n; i++ ) {

    long long int in;
    cin >> in;

    if ( i > 0 ) {
      if ( b == in ) {
	if ( c > 0 ) {
	  f = true;
	}else if ( c < 0 ) {
	  f = true;
	}
      }else if ( b > in ) {
	if ( c > 0 ) {
	  if ( f == true ) {
	    ans[0]++;
	  }else {
	    ans[3]++;
	  }
	}
	if ( c < 0 && f == true ) {
	  ans[2]++;
	}
	f = false;
	c = -1;
      }else {
	if ( c < 0 ) {
	  if ( f == true ) {
	    ans[1]++;
	  }else {
	    ans[4]++;
	  }
	}
	if ( c > 0 && f == true ) {
	  ans[2]++;
	}
	f = false;
	c = 1;
      }
    }
    b = in;

  }

  cout << ans[0] << " " << ans[1] << " " << ans[2] << " " << ans[3] << " " << ans[4] << endl;

  return 0;

}
accuracy: 1
time_ms: 10
memory_kb: 1164
final_rank: 1

code_snippet: #include<stdio.h>
int n, c1, c2, c3, c4, c5;
int w[101000][2], cnt;
int main(){
	int i, a, t = 0, tp;
	scanf("%d", &n);
	for (i = 1; i <= n; i++){
		scanf("%d", &a);
		if (i != 1 && tp != a){
			cnt++;
			w[cnt][0] = tp;
			w[cnt][1] = t;
			t = 0;
		}
		tp = a;
		t++;
	}
	cnt++;
	w[cnt][0] = tp;
	w[cnt][1] = t;
	for (i = 2; i < cnt; i++){
		if (w[i - 1][0] < w[i][0]){
			if (w[i][0] < w[i + 1][0]){
				if (w[i][1] > 1)c3++;
			}
			else{
				if (w[i][1] > 1)c1++;
				else c4++;
			}
		}
		else{
			if (w[i][0] > w[i + 1][0]){
				if (w[i][1] > 1)c3++;
			}
			else{
				if (w[i][1] > 1)c2++;
				else c5++;
			}
		}
	}
	printf("%d %d %d %d %d\n", c1, c2, c3, c4, c5);
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1772
final_rank: 4